// tendine(cog)																--select generale
// autorizzare(cog)															--autorizzo l'uso dei dati
// testigenerali(cog)														--testigenerali
// apri(a)																	--popup
// cap(a)																	--controllo cap

// sconto,ordine,immune,fattura,datafattura,peso,marca,offerta,image,
// quantita,price,pricesn,descrizione,cliente,ragione,username,nome,cognome,
// password,sesso,indirizzo,localita,provincia,nazione,fax,telefono,
// partitaiva,listino,cellulare,professione,referente,codicefiscale,
// luogonascita,provincianascita,campomessaggio								--testi classici

// mail(a)																	--controllo email
// provinciamenu(a),nazionemenu(a),livello(a),fascia(a),figura(a),posti(a)	--tendina
// zona(a),lingue(a),anno(a,b,c),area(a),localitamenu(a),servizio(a)		--tendina
// rdbutton(a,b),rdbutton2(a,b,c),											--controllo sesso
// MM_preloadImages(),MM_swapImgRestore(),MM_findObj(n, d),MM_swapImage()   --funzioni dreamweaver

function MostraLayer(name,mode)
{
	//alert(name + " " + mode + " " + document.getElementById(name).style.zIndex);
	switch(mode)
	{
		case "false":
			document.getElementById(name).style.visibility = 'hidden';
		break;				
		case "true":
			document.getElementById(name).style.visibility = 'visible';
		break;				
	}
};

function MostraLayerControl(name,mode)
{
	//	questa funzione è personalizzata solo per le finestre singole tipo l'invio mail dalla gestione iscritti

	if(document.getElementById("finestraclose").style.visibility == 'hidden' || !document.getElementById("finestraclose").style.visibility)
	{
		switch(mode)
		{
			case "false":
				document.getElementById(name).style.visibility = 'hidden';
			break;				
			case "true":
				document.getElementById(name).style.visibility = 'visible';
			break;				
		}
	}	
};

function changespedizione()
{
	window.document.carrello.tipodispedizione.value = window.document.carrello.spedizione[window.document.carrello.spedizione.selectedIndex].text;
}

function cambiains()
{
	window.document.text.action.value = 'add';
	window.document.text.actiondef.value = '';
	window.document.text.id.value = '';
}

var globalobj;

function tipodicarico(t)
{
	switch(t)
	{
		case "ins":
			window.document.caricare.modocarica.value = t;
		break;
		case "noins":
			window.document.caricare.modocarica.value = t;
		break;
		case "upd":
			window.document.caricare.modocarica.value = t;
		break;
	}
	window.document.caricare.submit();
}

function controldel(val,id)
{
	v = window.document.getElementById('controllocancellazione').value;
	idc = window.document.getElementById('idcontrollocancellazione').value;

	if(idc==id&&v>0)
	{
			window.location = val;
	}
	else
	{
		window.document.getElementById('controllocancellazione').value = 1;
		window.document.getElementById('idcontrollocancellazione').value = id;
		alert('Se vuoi veramente cancellare ripremi "cancella" del record che ti serve');
	}
}

function supercontrollo(vars,form,lingua,layername)
{
	// i campi della form devono chiamarsi come la funzione
	var lista = vars.split(",");
	var asp = new Array();
	var finalcontrol;
	var tipocampo;
	var efficace;

	//	evitare il multiple che con il javascript non so come sistemarlo

	for(i=0; i < lista.length; i++)
	{
		try
		{

			tipocampo = eval("window.document.getElementById('" + lista[i] + "').type");

			switch(lista[i])
			{
				case "autorizzare":	asp[i] = eval("window.document." + form + "." + lista[i] + ".checked");				break;
				default:			asp[i] = eval("window.document.getElementById('" + lista[i] + "').value");		break;
			}

			switch(tipocampo)
			{
				case "checkbox":	if(lista[i]=="autorizzare")	efficace = eval("autorizzare(\"" + asp[i] + "\",\"" + lista[i] + "\",\"" + form + "\")");			
				break;
				case "radio":		efficace = eval("campiradio(\"" + asp[i] + "\",\"" + lista[i] + "\",\"" + form + "\")");		break;
				case "file":
				case "password":
				case "text":		efficace = eval("campitext(\"" + asp[i] + "\",\"" + lista[i] + "\",\"" + form + "\")");		break;
				case "hidden":		efficace = true;																		break;
				case "select":		efficace = eval("campiselect(\"" + asp[i] + "\",\"" + lista[i] + "\",\"" + form + "\")");		break;
				case "select-one":	efficace = eval("campiselect(\"" + asp[i] + "\",\"" + lista[i] + "\",\"" + form + "\")");		break;
				case "textarea":
					//	se passo tutto il contenuto della textarea, javascript si incacchia, cmq se è obbligatoria mi basta controllare che ci sia almeno 1 carattere
					//	quindi taglio la testa al toro e passo al controllo solo 1-2 chars
					efficace = eval("campitext(\"" + asp[i].substr(0,2) + "\",\"" + lista[i] + "\",\"" + form + "\")");
				break;
			}

			if(efficace==false)
			{
				finalcontrol = false;
			}
		}
		catch (e)
		{
			//alert(e.message);
		}

	}

	// così capisco che è stato fatto un submit, mi serve per il tiny del cavolo per los vuotamento remove e add
	layersubmit = true;

	if(finalcontrol==false)
	{
		switch(lingua)
		{
			case "ITA":		alert('Correggi i campi segnati in rosso');									break;
			case "DEU":		alert('Sie beheben die Felder mit dem roten Rand');					break;
			case "ENG":		alert('You correct the fields with the red edge');					break;
		}
		return(false);
	}
	else
	{

		try
		{
			// qui inizio per il loading
			if (divObj = document.getElementById("loading")) {
				window.document.getElementById('loading').style.visibility = "visible";
			}

			try
			{
				if(document.forms["0"].name==document.forms["1"].name)
				{
					var formnow = eval("document.forms[0]");
				}
				else
				{
					var formnow = eval("document." + form);
				}
			}
			catch (e)
			{
				var formnow = eval("document." + form);
			}

			stringa = "";
			stringa = formnow.action + "&";

			//	per il cavolo di duplica devo togliere di mezzo dall'action l'azione e l'id, che ho già sistemato
			//	nei campi nascosti ma sono ancora presenti nell'action vecchio
			
			var vartot = stringa.split("&");

			//	riprendo la prima parte che è l'url
			stringa = vartot[0];

			for(var i = 1; i < vartot.length-1; i++)
			{
				if(vartot[i].indexOf("azione=")<0&&vartot[i].indexOf("id=")&&0&&vartot[i]!="")
				{
					stringa += "&" + vartot[i];
				}
			}

			//	alert(stringa);

			//alert("per il duplicate, sostituire nel query string azione e id");
			//alert(window.location.href);

			var effettuarecontrollonewcode = false
			var newcodice
			var numeroElementi = eval(formnow.elements.length);

			for(var i = 0; i < numeroElementi; i++)
			{
				//alert(formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value) + " " + stringa.indexOf(formnow.elements[i].name+"="));
				//alert(stringa.indexOf(formnow.elements[i].name+"=")+formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value));

				//	faccio un controllo per vedere se l'elemento esiste già nella stringa così lo salto
				//alert(stringa.indexOf(formnow.elements[i].name+"=") + " -- " + stringa.substr(stringa.indexOf(formnow.elements[i].name+"=")-1,1));
				//if(stringa.indexOf(formnow.elements[i].name+"=")<0)
				if(stringa.indexOf(formnow.elements[i].name+"=")<0||stringa.substr(stringa.indexOf(formnow.elements[i].name+"=")-1,1)!='&')
				{
					if(i < numeroElementi)
					{
						stringa += "&";
					}

					var temp = formnow.elements[i].type;

					switch(temp)
					{
						case "checkbox":
							if(formnow.elements[i].checked==true)
							{
								stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
							}
						break;
						case "radio":
							if(formnow.elements[i].checked==true)
							{
								stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
							}
						break;
						case "textarea":
							//alert(formnow.elements[i].name);
							//alert(formnow.elements[i].value);
							try
							{
								// prima di tutto tolgo la selezione se esiste, altrimenti il tinymce rompe le palle
								//window.document.getElementById(formnow.elements[i].name).removeAllRanges();
								//alert(tinyMCE.get(formnow.elements[i].name).getContent());
								//alert(document.getElementById(formnow.elements[i].id).value);

								if(document.getElementById("nogestione").value=="1") 
								{
									stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
								}
								else
								{
									var text = encodeURIComponent(tinyMCE.get(formnow.elements[i].name).getContent());
									stringa += formnow.elements[i].name+"="+text;
								}
							}
							catch (e)
							{
								alert(e.message);
								alert("Aggiornare la pagina per risolvere il problema!");
								window.document.getElementById('loading').style.visibility = "hidden";
								return false;
								
								//	var text = formnow.elements[i].value;
								//	var text = document.getElementById("mce_29").value;
								//	text = document.getElementById('finestraextra').getElementsByTagName('testo0').value;
								//	alert(text);
								//	stringa += formnow.elements[i].name+"="+text;
								//	alert(window.document.getElementById('" + nome + "').value);
							}
							//text = text.replace("\n","#BR#");
						break;
						default:
							if(formnow.elements[i].name=="newcodiceduplica"&&formnow.elements["azione"].value=="add")
							{
								effettuarecontrollonewcode = true;
							}
							//	alert(formnow.elements[i].name + "=" + formnow.elements[i].value);

							if(formnow.elements[i].name=="querystring"&&formnow.elements["azione"].value=="mod")
							{
								//	qui se sono in mod evito di aggiungere sto cavolo di query string, altrimenti la url mi diventa troppo lunga e ajax impazzisce
								//alert('beccato');
							}
							else
							{
								stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
							}
						break;
					}
				}
				else
				{
					//	alert(formnow.elements[i].name + " Non aggiunto");
					//	alert(stringa.indexOf(formnow.elements[i].name+"="));
					//	alert(stringa.substr(stringa.indexOf(formnow.elements[i].name+"=")-1,1));
					//	alert(stringa);
					//	alert(formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value));
				}
			}

			url = stringa;

			try
			{
				var textarea_num = document.getElementsByTagName("textarea").length;
				var textarea;

				for (var i = 0; i <= textarea_num; i++)
				{
					textarea = document.getElementsByTagName("textarea")[i];

					if (textarea != null)    
					{
						tinyMCE.execCommand('mceRemoveControl', false, textarea.id);
						tinyMCEkilled = true;
					}
				}
			}
			catch (e)
			{
				//alert("--" + e.message);
			}

			if(layername!="")
			{
				CaricaPage(url,layername,'1',true);

				//ora cambio il codice, dopo che è stao fatto l'action
				if(effettuarecontrollonewcode==true)
				{
					newcodice = parseFloat(formnow.elements["codice"].value)+1;
					formnow.elements["codice"].value = newcodice

					n = formnow.elements["codice"].value;
					string = "";

					for(var a = n.length; a < 6; a++)
					{
						string += "0";
					}

					string = string + n

					formnow.elements["codice"].value = string;
				}
				return(false)
			}
			return true;
		} catch (e) 
		{
			//alert("++" + e.message);
		}
		return(false);
	}
}

function goontheform()
{
	window.document.insv.ragionesociale1.value = window.document.predisponicaricamento.ragionesociale1.value;
	window.document.insv.ragionesociale2.value = window.document.predisponicaricamento.ragionesociale2.value;
	window.document.insv.indirizzo.value = window.document.predisponicaricamento.indirizzo.value;
	window.document.insv.localita.value = window.document.predisponicaricamento.localita.value;
	window.document.insv.provincia.value = window.document.predisponicaricamento.provincia.value;
	window.document.insv.nazione.value = window.document.predisponicaricamento.nazione.value;
	window.document.insv.tipo.value = window.document.predisponicaricamento.tipo.value;
	window.document.insv.espositore.value = window.document.predisponicaricamento.espositore.value;
}

function aggiungi(){

	var asp = new Array();
	asp[0]=window.document.prodotto.varianti.selectedIndex;

	if (variantiprodotto(asp[0])!=0){
		controlloprod="si";
	}else controlloprod="no";

	if(controlloprod=="si"){
		window.document.prodotto.submit();
	}
}

function calcola(){
	var cal1=window.document.prodotto.varianti.value;
	var sp1 = new Array();
	spl = cal1.split("-");
	sp2=spl[0];
	sp3=spl[1];
	window.document.prodotto.id.value=sp2;
	window.document.prodotto.pre2.value=sp3;
}

function variantiprodotto(cog){

	if(cog==0){
		alert('Devi scegliere il prodotto che vuoi acquistare dal menù apposito');
		return (false);
	}else return(true);	

}

function contrpassword(form,testoocontrollo)
{
	var1 = eval("window.document." + form + ".password.value");
	var2 = eval("window.document." + form + ".repassword.value");
	if(var1!=var2||var1==""||var2=="")
	{
		alert(testoocontrollo)
		return false;
	}
	else	return true;
}

function campiradio(cog,nome,form)
{
	num = eval("window.document." + form + "." + nome + ".length");

	for(cix=0;cix<num;cix++)
	{
		ok = eval("window.document." + form + "." + nome + "[" + cix + "]" + ".checked");

		if(ok==true)
		{
			for(ci=0;ci<num;ci++)
			{
				eval("window.document." + form + "." + nome + "[" + ci + "]" + ".style.border = '1px solid'");
				eval("window.document." + form + "." + nome + "[" + ci + "]" + ".style.borderColor = '#000066'");
			}
			return true;
		}
	}

	for(ci=0;ci<num;ci++)
	{
		eval("window.document." + form + "." + nome + "[" + ci + "]" + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + "[" + ci + "]" + ".style.borderColor = '#FF0000'");
	}
	return false;
}

function campiselect(cog,nome,form)
{

	num = eval("window.document.getElementById('" + nome + "').selectedIndex");

	if(num==0||num==-1)
	{
		eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + ".style.borderColor = '#FF0000'");
		eval("window.document." + form + "." + nome + ".style.color = '#FFFFFF'");
		eval("window.document." + form + "." + nome + ".style.background = '#FF0000'");
		controllo = false;
	}
	else
	{
		eval("window.document.getElementById('" + nome + "').style.border = '1px solid'");
		eval("window.document.getElementById('" + nome + "').style.borderColor = '#000066'");
		eval("window.document." + form + "." + nome + ".style.color = '#000066'");
		eval("window.document." + form + "." + nome + ".style.background = '#5ABDDE'");
		controllo = true;
	}
	return controllo;
}

function campitext(cog,nome,form)
{
	if(nome.substr(0,5)=='data_')
	{
		controllo = data(cog,nome,form);
		if(controllo==false)
		{
			eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
			eval("window.document." + form + "." + nome + ".style.borderColor = '#FF0000'");
			eval("window.document." + form + "." + nome + ".value='GG/MM/AAAA'");
		}
		else
		{
			eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
			eval("window.document." + form + "." + nome + ".style.borderColor = '#000066'");
		}
	}
	else
	{
		if(cog=="")
		{
			eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
			eval("window.document." + form + "." + nome + ".style.borderColor = '#FF0000'");
			controllo = false;
		}
		else
		{
			eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
			eval("window.document." + form + "." + nome + ".style.borderColor = '#000066'");
			controllo = true;
		}
	}
	return controllo;
}

function data(cog,nome,form)
{
	if(cog.length!=10) return false;
	if(cog.substr(2,1)!="/"&&cog.substr(5,1)!="/") return false;
	if((cog.charCodeAt(0)<48||cog.charCodeAt(0)>51)||(cog.charCodeAt(1)<48||cog.charCodeAt(1)>57)||(cog.charCodeAt(3)<48||cog.charCodeAt(3)>49)||(cog.charCodeAt(4)<48||cog.charCodeAt(4)>57)||(cog.charCodeAt(6)<48||cog.charCodeAt(6)>50)||(cog.charCodeAt(7)<48||cog.charCodeAt(7)>57)||(cog.charCodeAt(8)<48||cog.charCodeAt(8)>57)||(cog.charCodeAt(9)<48||cog.charCodeAt(9)>57))
	{
		return false;
	}
	return true;
}

function autorizzare(cog,nome,form)
{
	if(cog=="true")
	{
		eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + ".style.borderColor = '#000066'");
		return(true);
	}
	else
	{
		eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + ".style.borderColor = '#FF0000'");
		alert('Per iscriverti devi lasciare il check sulla voce relativa ai dati personali');
		return (false);
	}
}

function ControllaEmail(nome){
	var valore = eval("window.document.getElementById('" + nome + "').value");
	var chioc=valore.indexOf('@');
	var punt=valore.indexOf('.');
	if(chioc>=1 && punt>=1)
	{
		eval("window.document.getElementById('" + nome + "').style.border = '1px solid'");
		eval("window.document.getElementById('" + nome + "').style.borderColor = '#000066'");
		controllo = true;
  }else{
		eval("window.document.getElementById('" + nome + "').style.border = '1px solid'");
		eval("window.document.getElementById('" + nome + "').style.borderColor = '#FF0000'");
		eval("window.document.getElementById('" + nome + "').value = ''");
		alert('Inserire un indirizzo Email valido!');
		controllo = false;
  }
  return controllo;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.img){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function fOverDisp(obj) {
	if (obj.className=='rRigaUnselDisp') {
		obj.className='rRigaMouse';
	}
}
function fOverPari(obj) {
	if (obj.className=='rRigaUnselPari') {
		obj.className='rRigaMouse';
	}
}
function fOutDisp(obj) {
	if (obj.className=='rRigaMouse') {
		obj.className='rRigaUnselDisp'
	}
}
function fOutPari(obj) {
	if (obj.className=='rRigaMouse') {
		obj.className='rRigaUnselPari'
	}
}
function fSelezionaDisp(obj) {
	if (obj.className=='rRigaSel') {
		obj.className = 'rRigaUnselDisp';
	}
	else {
		obj.className = 'rRigaSel';
	}
}
function fSelezionaPari(obj) {
	if (obj.className=='rRigaSel') {
		obj.className = 'rRigaUnselPari';
	}
	else {
		obj.className = 'rRigaSel';
	}
}

function MM_scanStyles(obj, prop) { //v8.0
  var inlineStyle = null; var ccProp = prop; var dash = ccProp.indexOf("-");
  while (dash != -1){ccProp = ccProp.substring(0, dash) + ccProp.substring(dash+1,dash+2).toUpperCase() + ccProp.substring(dash+2); dash = ccProp.indexOf("-");}
  inlineStyle = eval("obj.style." + ccProp);
  if(inlineStyle) return inlineStyle;
  var ss = document.styleSheets;
  for (var x = 0; x < ss.length; x++) { var rules = ss[x].cssRules;
	for (var y = 0; y < rules.length; y++) { var z = rules[y].style;
	  if(z[prop] && (rules[y].selectorText == '*[ID"' + obj.id + '"]')) {
        return z[prop];
  }  }  }  return "";
}

function MM_getProp(obj, prop) { //v8.0
  if (!obj) return ("");
  if (prop == "L") return obj.offsetLeft;
  else if (prop == "T") return obj.offsetTop;
  else if (prop == "W") return obj.offsetWidth;
  else if (prop == "H") return obj.offsetHeight;
  else {
    if (typeof(window.getComputedStyle) == "undefined") {
	    if (typeof(obj.currentStyle) == "undefined"){
		    if (prop == "P") return MM_scanStyles(obj,"position");
        else if (prop == "Z") return MM_scanStyles(obj,"z-index");
        else if (prop == "V") return MM_scanStyles(obj,"visibility");
	    } else {
	      if (prop == "P") return obj.currentStyle.position;
        else if (prop == "Z") return obj.currentStyle.zIndex;
        else if (prop == "V") return obj.currentStyle.visibility;
	    }
    } else {
	    if (prop == "P") return window.getComputedStyle(obj,null).getPropertyValue("position");
      else if (prop == "Z") return window.getComputedStyle(obj,null).getPropertyValue("z-index");
      else if (prop == "V") return window.getComputedStyle(obj,null).getPropertyValue("visibility");
    }
  }
}

/* PARTE AJAX */

var req;
var which;

function retrieveURL() {

	var url = "records.php?q=" + araj[0] + "&typequery=" + araj[1] + "&record=" + araj[2] + "&tab=" + araj[3] + "&titolocampi=" + araj[4] + "&campi=" + araj[5] + "&pagemod=" + araj[6] + "&pagecanc=" + araj[7] + "&esistenti=" + araj[8] + "&f_ip=" + araj[9] + "&pag=" + araj[10] + "&tit=" + araj[11];

	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
		req.onreadystatechange = processStateChange;

		try {
			req.open("GET", url, true);
		} catch (e) {
			alert(e.message);
		}
		req.send(null);

	} else if (window.ActiveXObject) { // IE

		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processStateChange;
			req.open("GET", url, true);
			req.send();
		}

	}
}

function processStateChange() {

	if (req.readyState == 4) { // Complete
		if (req.status == 200) { // OK response
			//document.getElementById("listacorpo").innerHTML = req.responseText;
		} else {
			alert("Problem: " + req.statusText);
		}
	}

}

function checkall(obj,nr,status)
{

	switch(obj)
	{
		case "chkcancall":
			if (status==true)
			{
				status = true;
			}
			else
			{
				status = false;
			}

			for (i = 0; i <= nr; i++)
			{
				eval("window.document.getElementById('chkcanc" + i + "').checked = " + status);
			}
		break;
	}

}

function cancellazione_multipla(tot,tab)
{
	link = window.document.forms['lista_records'].action.replace("&multiposition=1&azione=upd","");
	window.document.forms['lista_records'].action = link + "&multicanc=1&azione=del&totcheck=" + tot + "&tab=" + tab;
	window.document.forms['lista_records'].submit();
}

function update_multiplo(tot,tab)
{
	link = window.document.forms['lista_records'].action.replace("&multicanc=1&azione=del","");
	window.document.forms['lista_records'].action = link + "&multiposition=1&azione=upd&totcheck=" + tot + "&tab=" + tab;
	window.document.forms['lista_records'].submit();
}

var req;
var which;
var livello;
var linkfinestraform;
var linkurl;
var mytinystatus;
var myloading;

function CaricaPage(url,layer,m,layersubmit,loading)
{
	if(layersubmit!=true)
	{
		try
		{
			var textarea_num = document.getElementsByTagName("textarea").length;
			var textarea;

			for (var i = 0; i <= textarea_num; i++)
			{
				textarea = document.getElementsByTagName("textarea")[i];

				if (textarea != null)    
				{
					tinyMCE.execCommand('mceRemoveControl', false, textarea.id);
					tinyMCEkilled = true;
				}
			}
		}
		catch (e)
		{
			//alert(e.message);
		}
	}

	mytinystatus = m;
	myloading = loading;
	livello = layer
	linkurl = url;
	if(layer&&url)	retrieveURL(url,layer);
}

function retrieveURL(url,layer) {
	// qui inizio per il loading
	//rr = setTimeout("window.document.getElementById('loading').style.visibility = 'visible'",2000);

	if(myloading==true) // allora lo obbligo a nopn caricare il loading
	{
		if (divObj = document.getElementById("loading")) {
			window.document.getElementById('loading').style.visibility = "visible";
		}
	}

	if (window.XMLHttpRequest)
	{ // Non-IE browsers
		req = new XMLHttpRequest();
		req.onreadystatechange = function() { processStateChange(layer); }; ;

		try 
		{
			req.open("GET", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		} 
		catch (e) 
		{
			alert("Problema: " + e);
		}
		req.send(null);
	}
	else if (window.ActiveXObject) 
	{ // IE

		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req)
		{
			req.onreadystatechange = processStateChange(layer);
			req.open("GET", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			postcontrol = "0";
			req.send();
		}
	}
}

function processStateChange(layer)
{
	// caricato e interactive
	if (req.readyState == 3)
	{
		// qui inizio per il loading
		if (divObj = document.getElementById("loading")) {
			window.document.getElementById('loading').style.visibility = "hidden";
		}
	}

	//	completato
	if (req.readyState == 4)
	{ // Complete

		if (req.status == 200)
		{ // OK response

			try
			{
				if(livello=="finestraform")
				{
					linkfinestraform = linkurl
				}

				document.getElementById(livello).innerHTML = req.responseText;

				//document.getElementById(livello).style.zIndex = "110";
				//alert(document.getElementById("finestraform").innerHTML);
				var textarea_num = document.getElementsByTagName("textarea").length;
				var testo;

				initTinyMCE();

				for (var i = 0; i <= textarea_num-1; i++)
				{
					textarea = document.getElementsByTagName("textarea")[i];
					//tinyMCE.idCounter = 0;
					//tinyMCE.execCommand('mceAddControl', true, textarea.id);
					//tinyMCE.execCommand('mceFocus', true, textarea.id);

					tinyMCE.execInstanceCommand(textarea.id, 'mceFocus');
				}
			}
			catch(e)
			{
				//alert("juventus " + e.message);
			}		
		} 
		else 
		{

			// se il get non ha funzionato per qualsiasi motivo provo col POST
			//alert("Problem: " + req.statusText);

			var name = "";
			if(linkurl.indexOf("dizionario.php")>0)
			{
				var http = new XMLHttpRequest();
				var divise = linkurl.split("dizionario.php?");
				var url = divise[0] + "dizionario.php";
				var params = divise[1];
				http.open("POST", url, true);

				//Send the proper header information along with the request
				http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				http.setRequestHeader("Content-length", params.length);
				http.setRequestHeader("Connection", "close");

				http.onreadystatechange = function() {//Call a function when the state changes.

					if(http.readyState == 4 && http.status == 200) {
						//alert(http.responseText);
					}
				}

				http.send(params);
			}
			else
			{
				window.location.reload();
			}
		}
	}
}

function ChangeModForm(type)
{
	if(type=='mod')
	{
		document.getElementById('modform').innerHTML = "Stato di modifica";
		document.getElementById('modform').style.color = "#FF0000";
	}
	else
	{
		document.getElementById('modform').innerHTML = "Stato di aggiunta";
		document.getElementById('modform').style.color = "#229500";
	}
}

function ChangeStatusForm()
{
	//	per fare il duplica, modifico l'azione della form e svuoto l'id, se esiste
	try
	{
		window.document.getElementById('azione').value = 'add';
		try
		{
			window.document.getElementById('codice').value = window.document.getElementById('newcodiceduplica').value;
		}
		catch(e)
		{
		}
		finally
		{
			window.document.getElementById('id').value = '';
		}
	}
	catch(e)
	{
	  //alert(e.message);
	}
	finally
	{
		document.getElementById('modform').innerHTML = "Stato di aggiunta";
		document.getElementById('modform').style.color = "#229500";
	}
}

function RicaricaPaginaRecord(status)
{
	if(status==true)
	{
		window.location.reload();
	}
	window.document.getElementById('backmodify').style.visibility = "hidden";
}

function ModificaTastoChiudiGestione(status)
{
	if(status==true)
	{
		document.getElementById('tastochiudi').value = "Chiudi e Ricarica";
	}
	else
	{
		document.getElementById('tastochiudi').value = "Chiudi";
	}
}

// ECOMMERCE

function aggiungicarrello(url,id,qta)
{
	url = url.replace('#qta#',eval("window.document.getElementById('additem" + qta + "').value"));
	window.location = url

/*
	if(substitute!=true) substitute = false;
	u = eval("window.document.getElementById('additem" + campo + "').value");
	window.open(url + 'insertcarrello.php?iditem=' + prodotto + '&substitute=' + substitute + '&qta=' + u, 'AggiuntaProdotto','left=5000,top=5000,width=1,height=1,toolbar=yes, location=no,status=yes,menubar=yes,scrollbars=no,resizable=no,visible=no');
*/
	//if(substitute!=true) substitute = false;
	//u = eval("window.document.getElementById('additem" + campo + "').value");
	//window.open(window.location + 'insertcarrello.php?iditem=' + prodotto + '&substitute=' + substitute + '&qta=' + u, 'AggiuntaProdotto','left=5000,top=5000,width=1,height=1,toolbar=yes, location=no,status=yes,menubar=yes,scrollbars=no,resizable=no,visible=no');
}

function ModificaCarrello(i,articolo,ordine)
{
	qta = eval("window.document.getElementById('additem" + i + "').value");

	var locate = window.location.href;

	if(locate.indexOf("ordine/")>0)
	{
		var loc = locate.split("ordine/");
		locate = loc[0] + "ordine/" + ordine + "/" + articolo + "/" + qta + ".html";
		window.location.replace(locate);
	}
	else
	{
		window.location.replace(ordine + "/" + articolo + "/" + qta + ".html");
	}
}

function SistemaLayerScuro()
{
	if(window.innerHeight && window.scrollMaxY)
	{
		window.document.getElementById('backmodify').style.height = window.scrollMaxY + window.innerHeight + 310 + "px";
	}
	else
	{
		window.document.getElementById('backmodify').style.height = document.body.scrollHeight + document.body.offsetHeight + 10 + "px";
	}
}

function cancellariga(nr,chiedi,rinuncia)
{
	if(confirm(chiedi))
	{
		// per la cancellazione delle righe
		var locate = window.location.href;
//locate = "http://localhost/www.shoppingtherapy.it/pagina/000117/000123/ordine/2/cancellazione6.html";
		if(locate.indexOf("cancellazione")>0)
		{
			var loc = locate.split("cancellazione");
			locate = loc[0].substring(0,loc[0].length) + "cancellazione" + nr + ".html";
		}
		else
		{
			locate = locate.replace(".html","/cancellazione" + nr + ".html");
		}
		window.location = locate;
	}
	else
	{
		alert(rinuncia);
	}
} 

function GoDocumento(find,go)
{
	var locate = window.location.href;
	locate = locate.replace(find,go);
	window.location = locate;
}

function RicercaFiltra(stato) 
{ 
	var SearchRange = window.document.getElementById('records').innerHTML; 
	var nr = window.document.getElementById('numerorighe').value;
	var filtro = window.document.getElementById('filtro').value;
	var html = ""; 

	filtro = filtro.toLowerCase();

	for (i=0; i<=nr; i++) 
	{ 

		html = window.document.getElementById('riga_' + i).innerHTML; 
		html = html.toLowerCase();

		html = StripTags(html);

		if(stato!="reset")
		{
			if(html.indexOf(filtro)>0)
			{
				window.document.getElementById('riga_' + i).style.display = "block";
			}
			else
			{
				window.document.getElementById('riga_' + i).style.display = "none";		
			}
		}
		else
		{
			window.document.getElementById('riga_' + i).style.display = "block";	
		}
	}
}

function VediLingua(form,layer,button)
{ 
	try
	{
		var nr = form.contatore.value;

		for (i=0; i<=nr-1; i++) 
		{
			window.document.getElementById('areacampo' + i).style.display = "none";
			window.document.getElementById('btncampo' + i).style.backgroundColor = "#F0F0F0";
			window.document.getElementById('btncampo' + i).style.color = "#000000";
		}

		window.document.getElementById(button).style.backgroundColor = "#000000";
		window.document.getElementById(button).style.color = "#FFFFFF";
		window.document.getElementById(layer).style.display = "block";
	}
	catch (e)
	{
		//alert(e.message);
	}
}

function SvuotaSubLivelli() 
{ 
	var nr = window.document.getElementById('numerorighe').value;

	for (i=0; i<=nr; i++) 
	{
		try
		{
			document.getElementById('sublivello_' + i).innerHTML = "";
		}
		catch(e)
		{
		}
		finally
		{
		}
	}
}

function StripTags(strMod){
    if(arguments.length<3) strMod=strMod.replace(/<\/?(?!\!)[^>]*>/gi, '');
    else{
        var IsAllowed=arguments[1];
        var Specified=eval("["+arguments[2]+"]");
        if(IsAllowed){
            var strRegExp='</?(?!(' + Specified.join('|') + '))\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }else{
            var strRegExp='</?(' + Specified.join('|') + ')\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }
    }
    return strMod;
}


