function newWindow(url,windowname,prop)
{
	popupWindow = open(url,windowname,prop);
	if (popupWindow.opener == null) {
		popupWindow.opener = self;
	}
}

function showProperties()
{
	if (document.getElementById("admin_propertyBox").style.visibility == "visible")
	{
		document.getElementById("admin_propertyBox").style.visibility = "hidden";
	} else {
		document.getElementById("admin_propertyBox").style.visibility = "visible";
	}
}

function showActions()
{
	if (document.getElementById("admin_actionBox").style.visibility == "visible")
	{
		document.getElementById("admin_actionBox").style.visibility = "hidden";
	} else {
		document.getElementById("admin_actionBox").style.visibility = "visible";
	}
}

function showLogs()
{
	if (document.getElementById("admin_logBox").style.visibility == "visible")
	{
		document.getElementById("admin_logBox").style.visibility = "hidden";
	} else {
		document.getElementById("admin_logBox").style.visibility = "visible";
	}
}

function showKeys()
{
	if (document.getElementById("protetta").checked)
	{
		document.getElementById("admin_licenseBox").style.display = "block";
	} else {
		document.getElementById("admin_licenseBox").style.display = "none";
	}
}



function validacampo(tipoval,valore)
{
	var strErr = "";
	var err = false;
	switch (tipoval)
	{
		case "email":
		{
			strErr = "indirizzo e-mail non corretto";
			var at="@"
			var dot="."
			var str = valore;
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   err = true;
			}	
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   err = true;
			}	
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			    err = true;
			}	
			 if (str.indexOf(at,(lat+1))!=-1){
			    err = true;
			 }	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			    err = true;
			 }
			 if (str.indexOf(dot,(lat+2))==-1){
			    err = true;
			 }			
			 if (str.indexOf(" ")!=-1){
			    err = true;
			 }
			 break;					
		}
		case "numerico":
		{
			strErr = "sono consentiti solo numeri";
			var charpos = valore.search("[^0-9]"); 
            if (valore.length > 0 &&  charpos >= 0) 
            {
            	err = true; 
             }//if 
             break; 
			break;
		}
		case "alfanumerico":
		{
			strErr = "sono consentiti solo lettere, numeri (senza spazi)";
			var charpos = valore.search("[^A-Za-z0-9]"); 
            if (valore.length > 0 &&  charpos >= 0) 
            {
            	err = true; 
             }//if 
             break;
		}
		case "alfanumerico_spazio":
		{
			strErr = "sono consentiti solo lettere, numeri e spazi";
			var charpos = valore.search("[^A-Za-z0-9 ]"); 
            if (valore.length > 0 &&  charpos >= 0) 
            {
            	err = true; 
             }//if 
             break; 
		}
		case "data":
		{
			strErr = "in questo campo deve essere inserita una data nel formato gg/mm/aaaa"
			var valid = Date.isValid(valore,"dd/MM/yyyy");
			if (!valid)
			{
				err = true;
			} 
			break;
		}
	}
	if (err)
	{
		return strErr;
	} else {
		return "";
	}
	
}

function valida(idform,srcFile)
{
	var bloccaForm = false;
	
	var xf = Sarissa.getDomDocument();
	xf.setProperty("SelectionNamespaces", "xmlns:cms='http://www.gap.it/2005/cms'");
    xf.setProperty("SelectionLanguage", "XPath");
	xf.setProperty("ValidateOnParse", "False");
	xf.async = false;
	xf.load(srcFile);
	
	var items = xf.selectNodes("cms:contactform/cms:forminfo/cms:item[not(@type='info')]");
	
	for (it=0;it<items.length;it++)
	{
		var idcampo = idform + ":" + items[it].getAttribute("id");
		var val = document.getElementById(idcampo).value
		if (items[it].getAttribute("type")!='check')
		{
			if ((items[it].getAttribute("mandatory")=='1') && (val == ""))
			{
				var divfeedback = document.getElementById("feedback_" + idcampo)
				divfeedback.innerHTML = "questo campo &egrave; obbligatorio";
				document.getElementById(idcampo).className = "NotValidInput";
				bloccaForm = true
			} else {
				if (items[it].getAttribute("validation")!='')
				{
					valErr = validacampo(items[it].getAttribute("validation"),val);
					if (valErr != "")
					{
						var divfeedback = document.getElementById("feedback_" + idcampo)
						divfeedback.innerHTML = valErr;
						document.getElementById(idcampo).className = "NotValidInput";
						bloccaForm = true;
					} else {
						var divfeedback = document.getElementById("feedback_" + idcampo)
						divfeedback.innerHTML = "";
						document.getElementById(idcampo).className = "";
					}
				} else {
					var divfeedback = document.getElementById("feedback_" + idcampo)
					divfeedback.innerHTML = "";
					document.getElementById(idcampo).className = "";
				}			
			}
		} else {
			if ((items[it].getAttribute("mandatory")=='1') && (!(document.getElementById(idcampo).checked)))
			{
				var divfeedback = document.getElementById("feedback_" + idcampo)
				divfeedback.innerHTML = "questo campo &egrave; obbligatorio";
				document.getElementById(idcampo).className = "NotValidInput";
				bloccaForm = true
			} else {
				var divfeedback = document.getElementById("feedback_" + idcampo)
				divfeedback.innerHTML = "";
				document.getElementById(idcampo).className = "";
			}
		}
	}
	if (!bloccaForm)
	{
		document.forms[idform].submit();
	}
	items = null;
	xf = null;
}