// 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 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++)
	{
		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;
		}
	}

	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
		{
			var formnow = eval("document." + form);

			stringa = "";
			stringa = eval("window.document." + form + ".action") + "&";
			stringa = eval("window.document." + form + ".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
			
			//alert(stringa);
			
			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;
					if(temp == "radio") 
					{ 
						if(formnow.elements[i].checked==true)
						{
							stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
						}
					}
					else
					{
						if(formnow.elements[i].name=="newcodiceduplica"&&formnow.elements["azione"].value=="add")
						{
							effettuarecontrollonewcode = true;
						}
						stringa += formnow.elements[i].name+"="+encodeURIComponent(formnow.elements[i].value);
					}
				}
				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;

			if(layername!="")
			{
				CaricaPage(url,layername,'1');

				//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);
		}

		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 insertQuote(type) {

	tipocampo = eval("window.document.getElementById('" + globalobj + "').type");

	if(tipocampo!="text"&&tipocampo!="textarea") return false;
	
	window.document.getElementById(globalobj).focus();
	
	//	aField è il nome dell'oggetto della form, cioè il valore dell'ggetto object che 
	//	gli viene segnato in fase di selezione dell'oggetto	
	//	form è il nome della form
	//	type è evento da eseguire

	var userAgent=navigator.userAgent;

	if (userAgent.indexOf('MSIE') == -1)
	{
		if (typeof(document["selection"]) != "undefined") {
			str = document.selection.createRange().text;
		} else if (typeof(window.document.getElementById(globalobj)["setSelectionRange"]) != "undefined") {
			start = window.document.getElementById(globalobj).selectionStart;
			end = window.document.getElementById(globalobj).selectionEnd;
			scrollPos = window.document.getElementById(globalobj).scrollTop;
			str = window.document.getElementById(globalobj).value.substring(start, end);
		}
	}
	else
	{
		if(window.document.selection && window.document.selection.createRange) {
			var str = window.document.selection.createRange().text;
		}
	}
	sel = str;

	//	dopo aver preso il testo, lo lavoro e lo ristampo
	if(type=='bold')		str = "<b>" + str + "</b>";
	if(type=='br')			str = "<br />" + str;
	if(type=='italic')		str = "<i>" + str + "</i>";
	if(type=='underline')	str = "<u>" + str + "</u>";
	if(type=='cancel')		str = "<s>" + str + "</s>";
	if(type=='link')		str = "<a href=''>" + str + "</a>";
	if(type=='linkn')		str = "<a href='' target='_newpage_'>" + str + "</a>";	
	if(type=='alignleft')	str = "<div align='left'>" + str + "</div>";
	if(type=='aligncenter')	str = "<div align='center'>" + str + "</div>";
	if(type=='alignright')	str = "<div align='right'>" + str + "</div>";
	if(type=='alignjustify')str = "<div align='justify'>" + str + "</div>";


	if (userAgent.indexOf('MSIE') == -1)
	{
		var valtot = window.document.getElementById(globalobj).value;
		valtot = valtot.replace(sel,str);
		window.document.getElementById(globalobj).value = valtot;
	}
	else
	{
		window.document.selection.createRange().text = str;
	}
}

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);
		}
		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;

function CaricaPage(url,layer,m)
{
	livello = layer
	linkurl = url;
	if(layer)	retrieveURL(url,layer);
}

function retrieveURL(url,layer) {

	if (window.XMLHttpRequest)
	{ // Non-IE browsers
		req = new XMLHttpRequest();
		req.onreadystatechange = processStateChange;

		try 
		{
			req.open("GET", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		} 
		catch (e) 
		{
			//alert(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');
			req.send();
		}
	}
}

function processStateChange(layer)
{

	if (req.readyState == 4)
	{ // Complete
		if (req.status == 200)
		{ // OK response
			if(livello=="finestraform")
			{
				linkfinestraform = linkurl
			}

			document.getElementById(livello).innerHTML = req.responseText;

			//document.getElementById(livello).style.zIndex = "110";
			//alert(document.getElementById("finestraform").innerHTML);

		} 
		else 
		{
			//alert("Problem: " + req.statusText);
		}
	}
}

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,prodotto,campo,substitute)
{
	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','width=300,height=300,toolbar=yes, location=no,status=yes,menubar=yes,scrollbars=no,resizable=no');
	window.location.reload();
}

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;
}