// 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)
{
	// i campi della form devono chiamarsi come la funzione
	var lista = vars.split(",");
	var asp = new Array();
	var finalcontrol;
	var tipocampo;
	var efficace;

	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":	efficace = eval("campitext(\"" + asp[i] + "\",\"" + 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
	{
		return(true);
	}
}

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 mail(cog,nome,form){
	var chioc=cog.indexOf('@');
	var punt=cog.indexOf('.');
	if(chioc>=1 && punt>=1)
	{
		eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + ".style.borderColor = '#000066'");
		controllo = true;
  }else{
		eval("window.document." + form + "." + nome + ".style.border = '1px solid'");
		eval("window.document." + form + "." + nome + ".style.borderColor = '#FF0000'");
		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 (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");
    }
  }
}