// JavaScript Document
function setSelected(option){
	document.form1.TXTSELECTED.value=option;
	if (option==0){
		return false
	}
	if (option==1){
		if (res()){
			if (document.form1.TIPOLOGIE.value==-1)
				return false;
		}else{
			return false;
		}
	}
	if (option==2){
		if (document.form1.TIPOLOGIE.value!=-1){
			pophome('ctrlPanel/tipologieMod.php?COD='+document.form1.TIPOLOGIE.value,400,400,'yes','yes');
		}
		return false
	}
	if (option==3){
			pophome('ctrlPanel/tipologieAdd.php',400,400,'no','no');
		return false
	}
	if (option==4){
			pophome('ctrlPanel/prodottiRic.php?CODTIPOLOGIA='+document.form1.TIPOLOGIE2.value+'&CODPRODOTTO='+document.form1.TXTRICERCAPROD.value,500,600,'no','yes');
		return false
	}
	if (option==5){
			pophome('ctrlPanel/prodottiAddFrame.php',600,700,'no','yes');
		return false
	}
	if (option==6){
			pophome('ctrlPanel/documentiRic.php?VISALL=1',500,600,'no','yes');
		return false
	}
	if (option==7){
			pophome('ctrlPanel/documentiAdd.php',500,600,'no','yes');
		return false
	}

	return true
}

function blankFormObj(option){
	if (option==0){
		document.form1.TXTRICERCAPROD.value="";
	}
	if (option==1){
		document.form1.TIPOLOGIE2.value=-1;
	}
	
}

function pophome(link,h,w,res,scroll){
	open(link,'newwindow','height='+h+',width='+w+',alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0,screenX=0,screeny=0,left=200,top=100,resizable='+res+',scrollbars ='+scroll);
}

function setModCategory(id,text){
	document.form1.TXTMODID.value=id;
	document.form1.TXTMODCATEGORIA.value=text;
}

function chkForm()
{	
	
	if (document.forms['contact'].elements['cogn'].value=='')
	{ 
		alert ("campo cognome obbligatorio");
		document.forms['contact']['cogn'].focus();
		return false;		
	}
	
	
	if (document.forms['contact']['nome'].value=='')
	{
		alert ("campo nome obbligatorio");
		document.forms['contact']['nome'].focus();
		return false;
	}
		
	if (document.forms['contact']['indirizzo'].value=='')
	{
		alert ("campo indirizzo obbligatorio");
		document.forms['contact']['indirizzo'].focus();
		return false;
	}
	//controllo della email		
	if (document.forms['contact']['mail'].value=='')
	{
		alert ("campo e-mail obbligatorio");
		document.forms['contact']['mail'].focus();
		return false;
	}
	else
	{
		emailValue=document.forms['contact']['mail'].value;
		emailHasAt=emailValue.indexOf("@");
		emailHasDot=emailValue.indexOf(".");
		if ((emailHasAt == -1)||(emailHasDot == -1))
		{
			alert ("L'indirizzo e-mail immesso non č valido");
			document.forms['contact']['mail'].focus();
			return false;
		}		
	}
	

	//controllo codice postale
	if (document.forms['contact']['cp'].value!='')
	{	
		aZipCode=document.forms['contact']['cp'].value;
		
		if (aZipCode)
		{
			numberCounter=0;
			zipCounter=0;
			foundNumber="";
			
			while (zipCounter<5)
			{
				while(numberCounter<10)
				{
					if (aZipCode.substr(zipCounter,1) == numberCounter)
					{
						foundNumber="yes";
						numberCounter=11;
					}
					else
					{
						foundNumber="no";
						
					}
					numberCounter++;
				}
		   		if(foundNumber!="yes")
		   		{
		   			zipCounter=6;
		   		}
		   		else
		   		{
		   			zipCounter++;
					numberCounter=0;			
		   		}
					
			}
		}
		if (foundNumber!="yes")
		{
			alert("Inserire un codice postale valido");
			document.forms['contact']['cp'].focus();
			return false;
		}
	}
	
	
	//controllo campo cittā	
	if (document.forms['contact']['cpCitta'].value=='')
	{
		alert ("campo cittā obbligatorio");
		document.forms['contact']['cpCitta'].focus();
		return false;
	}
	return true;		
}

function res()
{
	return confirm('Procedere con la cancellazione?');
}