function Trim(TRIM_VALUE){
	
	if(TRIM_VALUE.length < 1){
	return"";
	}

	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
	return "";
	}
	else{
	return TRIM_VALUE;
	}
} //End Function


function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
}


function Reload() 
{ 
    var parent_location = location.href; 
    if (parent_location.indexOf('force')>0) 
    { parent_location = parent_location.replace("&force=true", ""); 
        parent_location = parent_location.replace("?force=true", ""); 
    } else 
    { if (parent_location.indexOf('?')>0) 
    { parent_location = parent_location +"&force=true"; } else { parent_location = parent_location +"?force=true"; } } 
    location.href = parent_location;
}
function ChiudiERicarica() 
{ 
    var parent_location = opener.parent.location.href; 
    if (parent_location.indexOf('force')>0) 
    { parent_location = parent_location.replace("&force=true", ""); 
        parent_location = parent_location.replace("?force=true", ""); 
    } else 
    { if (parent_location.indexOf('?')>0) 
    { parent_location = parent_location +"&force=true"; } else { parent_location = parent_location +"?force=true"; } } 
    opener.parent.location.replace(parent_location); 
    window.close(); 
}




function ChiudiERicaricaSicura(sicurezza) 
{ 
	alert('ciao');
    var parent_location = opener.parent.location.href; 
    if (parent_location.indexOf('force')>0) 
    { parent_location = parent_location.replace("&force=true", ""); 
        parent_location = parent_location.replace("?force=true", ""); 
    } else 
    { if (parent_location.indexOf('?')>0) 
    { parent_location = parent_location +"&force=true"; } else { parent_location = parent_location +"?force=true"; } } 
    
    if (sicurezza) parent_location.replace("http://","https://");
    opener.parent.location.replace(parent_location); 
    window.close(); 
}

function ChiudiERicaricaDaSession() 
{ 
   /* var parent_location = opener.parent.location.href; 
    if (parent_location.indexOf('force')>0) 
    { parent_location = parent_location.replace("&force=true", ""); 
        parent_location = parent_location.replace("?force=true", ""); 
    } else 
    { if (parent_location.indexOf('?')>0) 
    { parent_location = parent_location +"&force=true"; } else { parent_location = parent_location +"?force=true"; } }
    
   
    
    if (!(parent_location.indexOf('reload')>0))
    {
		if (parent_location.indexOf('?')>0) 
		{
			parent_location = parent_location + "&reload=true";
		} else
		{
			parent_location = parent_location + "?reload=true";
		}
		
    }
	*/    
    opener.parent.form1.submit();
    //opener.parent.location.replace(parent_location); 
    window.close(); 
}


function ChiudiECarica(url)
{
	opener.parent.location.replace(url); 
	window.close(); 
}

var popUp; 
function apriLoginInterni(url)
{
	
	popUp = window.open(url, 'name',"resizable=true,statusbar=false,locationbar=false,scrollbars=true,toolbar=false, width=420, ,height=200,top=100");
	popUp.focus();
}

 
function apriRicercaCliente(url)
{
	popUp = window.open(url, 'name',"resizable=true,statusbar=false,locationbar=false,scrollbars=true,toolbar=false, width=500, ,height=600,top=100");
	popUp.focus();
}

function apriPopUp(url,pWidth,pHeight)
{
	if (popUp != null) popUp.close();
	popUp = window.open(url, 'name',"resizable=yes,status=no,locationbar=false,scrollbars=yes,toolbar=false, width=" +pWidth +" ,height=" +pHeight +",top=100,titlebar=no");
	popUp.focus();
}

function apriPopUpScroll(url,pWidth,pHeight)
{
	if (popUp != null) popUp.close();
	popUp = window.open(url, 'name',"resizable=yes,status=no,locationbar=no,scrollbars=yes,toolbar=no, width=" +pWidth +" ,height=" +pHeight +",top=100,titlebar=no");
	popUp.focus();
}

function apriPopUpStampa(url)
{
	popUp = window.open(url, 'print',"location=no,menubar=yes,height=600,width=800,resizable=true,scrollbars=yes");
	popUp.focus();
}

function apriPopUpTrack(url,pWidth,pHeight)
{
	popUp = window.open(url, 'name',"resizable=no,status=no,menubar=yes, locationbar=false,scrollbars=yes,toolbar=no, width=" +pWidth +" ,height=" +pHeight +",top=100,titlebar=no");
	popUp.focus();
}
function showHelpFrame(nomeFrame,HelpKey,width,height)
{

	frame = document.getElementById(nomeFrame);
	frame.style.display = '';
	frame.style.top = window.event.y + document.body.scrollTop;
	frame.style.left = window.event.x + document.body.scrollLeft;
	frame.style.width = width;
	frame.style.height = height;
	frame.src = '/tvweb/help/iFrameHelp.aspx?HelpKey=' + HelpKey;
	
}

function hideHelpFrame(nomeFrame)
{
	frame = document.getElementById(nomeFrame);
	frame.style.display = 'none';
}

function increaseValue(nomeTextBox)
{
	txtBox = document.getElementById(nomeTextBox);
	txtBox.value = (txtBox.value*1) + 1;
}

function decreaseValue(nomeTextBox)
{
	txtBox = document.getElementById(nomeTextBox);
	if (txtBox.value > 1)
		txtBox.value = (txtBox.value*1) - 1;
}

function checkClienteAnagraficaRegistato()
{
	if (confirm('Hai già chiesto una registrazione al sito di TerminalVideo Italia s.r.l.! Continuare?'))
	{
		if (location.href.indexOf('?')>0) 
		{ location.href = location.href +"&save_ac=true"; 
		} 
		else 
		{ location.href = location.href +"?save_ac=true"; 
		} 
		
	}
}

function getQtaByElementId(ElementId)
{
	
	return document.getElementById(ElementId).value;
}

function checkArticoloInOrdine(art_id, qta, force)
{

	var controlQta = qta;
	
	if (isNaN(qta)) 
	{ 
		alert('Attenzione: prima di aggiungere nel Carrello inserire una quantità corretta');
	} else {
		
		var ie = true;
		if (ie)
		{
			var frameControllo = document.getElementById('frmControl');
			frameControllo.src = '/tvweb/applications/controlloArticoloInOrdine.aspx?art_id=' + art_id + '&qta=' + controlQta + '&force=' + force;
		}
	}
}

function addArticoloInWishList(art_id)
{	
	var ie = true;
	if (ie)
	{
		var frameWishList = document.getElementById('frmAddWishList');
		frameWishList.src = '/tvweb/applications/addArticoloInWishList.aspx?art_id=' + art_id;
	}
}

function confirmArticoloInOrdine(art_id,qta)
{
	if (confirm('Questo articolo è già presente in un ordine o nel Carrello! Continuare l\'inserimento nel Carrello?'))
	{
		checkArticoloInOrdine(art_id,qta, true)
	} else {
		var frameControllo = document.getElementById('frmControl');
		frameControllo.src = '';
	}

}


function openParentLink(url_link)
{
	parent.location.replace(url_link);
}


function getBasketHeight(frameBasket)
{
	return 112*frameBasket.document.getElementById('itemCount').value;
}

// Sets default buttons. v.1.0
// Created by Janus Kamp Hansen - http://www.kamp-hansen.dk		
//function fnTrapKD(btnName)
//{
	
//	var btn = document.getElementById(btnName);
	//Se è ie
//	if (document.all)
//	{
//		if (event.keyCode == 13)
//		{ 
//			event.returnValue=false;
//			event.cancel = true;
//			btn.click();
//		}
//	} 	
//}
	
// Sets default buttons. v.
	// Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
	// Extended by Darrell Norton - http://dotnetjunkies.com/weblog/darrell.norton/ 
	// Available at http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=a3b93959-9b2e-428a-99d9-276f0620589d
	function fnTrapKD(btnID, event){
		
		btn = document.getElementById(btnID);
		if (document.all){
			if (event.keyCode == 13){
				event.returnValue=false;
				event.cancel = true;
				btn.click();
			}
		}
		else if (document.getElementById){
			if (event.which == 13){
				event.returnValue=false;
				event.cancel = true;
				btn.focus();
				btn.click();
			}
		}
		else if(document.layers){
			if(event.which == 13){
				event.returnValue=false;
				event.cancel = true;
				btn.focus();
				btn.click();
			}
		}
	}

//	function findObj(n, d) { 
//		var p,i,x;  
//		if(!d) 
//		d=document; 
//		if((p=n.indexOf(""?""))>0 && parent.frames.length) {
//			d=parent.frames[n.substring(p+1)].document; 
//			n=n.substring(0,p);
//		}
//		if(!(x=d[n])&&d.all) 
//			x=d.all[n]; 
//		for (i=0;!x&&i<d.forms.length;i++) 
//		x=d.forms[i][n];
//		for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
//		x=findObj(n,d.layers[i].document);
//		if(!x && d.getElementById) 
//			x=d.getElementById(n); 
//		return x;
//	}
	
	function validaTestoRicerca(text_search_name)
	{
		var campo =  document.getElementById(text_search_name);
	
		if (campo != 'undefined' && campo != null && campo != undefined)
		{
	
			if (Trim(campo.value) == '')
			{
				alert("Inserire almeno un carattere per la ricerca!");
			
				return false;
			}
		}

	}		
	
	function checkConfezione(nomeTextBox,qtaVendita)
	{
		txtBox = document.getElementById(nomeTextBox);
		var qta = (txtBox.value*1);
		var qtaResto = qta%qtaVendita;
	
		if ((qtaResto)>0)
		{
			alert("Attenzione! La confezione contiene " + qtaVendita + " pezzi.");
			txtBox.value = qta - qtaResto;
		}
	
	
	}
	
	
	function increaseValueConfezione(nomeTextBox,qtaVendita)
	{
		txtBox = document.getElementById(nomeTextBox);
		txtBox.value = (txtBox.value*1) + qtaVendita;
	}

	function decreaseValueConfezione(nomeTextBox,qtaVendita)
	{
		txtBox = document.getElementById(nomeTextBox);
		if (txtBox.value > qtaVendita)
		txtBox.value = (txtBox.value*1) - qtaVendita;
	}
	
	
	
	function _ManageOpenCloseLayer(rigaNascondere, idImmagine, hiddenValue,root,sezione, store)
	{
		var divC = document.getElementById(rigaNascondere);
		var imageC = document.getElementById(idImmagine);
		var hiddenAValue = document.getElementById(hiddenValue);
		var nomeImg = imageC.src.toLowerCase();
		var open = true;
		if (nomeImg.indexOf("elementplus.jpg") != -1)
		{
			divC.style.display = '';
			imageC.src = imageC.src.toLowerCase().replace("elementplus.jpg","elementminus.jpg");
			if (hiddenAValue != null && hiddenAValue != 'undefined')
				hiddenAValue.value = 'aperto';
		} 
		else 
		{
			open = false;
			divC.style.display = 'none';
			imageC.src = imageC.src.toLowerCase().replace("elementminus.jpg","elementplus.jpg");
			if (hiddenAValue != null && hiddenAValue != 'undefined')
				hiddenAValue.value = 'chiuso';
		}
		if (store != null && store != 'undefined' && sezione != null && sezione != 'undefined'
			&& root != null && root != 'undefined')
		{
			if (open)
				StoreOpenClose(root,sezione, 'aperto');
			else
				StoreOpenClose(root,sezione, 'chiuso');
		}
	
	}
	
	
	//**********************************************
	//			Gestione Oggetti Flash
	//**********************************************
	
	
	//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
   
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
   
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
	
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      
        ret.objAttrs[args[i]] = args[i+1];
        break;
      
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
     
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
