function showPopupVideo(url){
	window.open(url,"VideoPopup","menubar=no,toolbar=no,location=no,scrollbars=no,status=no,width=400,height=320,false");
}


/*
	Visualizza il form di ricerca avanzata nel form
*/
function showAdvSearch()
{
	if (document.getElementById("ricercaAvanzata").style.display=="none"){
		document.getElementById("ricercaAvanzata").style.display="";
		document.getElementById("flagadv").value=1;	
	}else{
		document.getElementById("flagadv").value=0;	
		document.getElementById("ricercaAvanzata").style.display="none";
	} 
}

/*
	Decodifica URL
*/
function URLDecode(encoded)
{
	var HEXCHARS = "0123456789ABCDEFabcdef"; 
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) 
	{
		var ch = encoded.charAt(i);
		if (ch == "+") 
		{
			plaintext += " ";
			i++;
		} 
		else if (ch == "%") 
		{
			if (i < (encoded.length-2) && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) 
			{
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else 
			{
				alert( 'Escape errato ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else 
		{
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
}


function doArchiveAdvSearch(catid,errMsg)
{
/*
	var title = document.getElementById("advSearch_Title").value,
	      abst = document.getElementById("advSearch_Abstract").value,
	      text = document.getElementById("advSearch_Text").value;
	
	if ((!title) && (!abst) && (!text)) alert(URLDecode(errMsg));
	else
	{
		if (!title) title = "$$$";
		if (!abst) abst = "$$$";
		if (!text) text = "$$$";
		document.location.href = "?cat=" + catid + "&advSearch=" + title + ":" + abst + ":" + text;
	}
*/
}


function doArchiveSimpleSearch(catid,errMsg)
{
	var text = document.getElementById("simpleSearchText").value;
	
	if (!text) alert(URLDecode(errMsg));
	else
	document.location.href = "?cat=" + catid + "&simpleSearch=" + text;
}


//Annullo l'invio dei form alla pressione del Return
function noenter() 
{
	return !(window.event && window.event.keyCode == 13); 
}


function showPrintable(catid,lang)
{
	var qs;
	var temp=new String();
	temp=document.location.href;
	qs=temp.split("?")[temp.split("?").length-1];
	window.open("showPrintablePage.php?catid=" + catid + "&lang=" + lang + "&" + qs,"stampa","width=600, height=500, resizable=false, scrollbars=yes, menubar=yes, toolbar=yes, location=no, status=yes");
}

function showImagePopup(id,width,height)
{
	window.open("utils/viewImagePage.php?cat=RepositoryImmagini&id="+id,"imagePopup","menubar=yes,toolbar=no,location=no,scrollbars=no,status=yes,width="+width+",height="+(height-20),false);
}

function showPopup(url,width,height)
{
	window.open(url,"imagePopup","menubar=no,toolbar=no,location=no,scrollbars=no,status=no,width="+width+",height="+height,false);
}

function openWindow(url,wname,width,height)
{
//	window.open(url,wname,"menubar=no,toolbar=no,location=no,scrollbars=no,status=no,innerwidth="+width+",innerheight="+height,false);
	window.open(url,wname,"menubar=no,toolbar=no,location=no,scrollbars=no,status=no,width="+width+",height="+height,false);
}


function checkFormSearchAndSubmit(frm, msg)
{
	
	//var data1 = parseFloat(frm.adv_data_da_aaaa.value+frm.adv_data_da_mm.value+frm.adv_data_da_gg.value);
	//var data2 = parseFloat(frm.adv_data_a_aaaa.value+frm.adv_data_a_mm.value+frm.adv_data_a_gg.value);
	var data1 = new Date(frm.adv_data_da_aaaa.value, frm.adv_data_da_mm.value, frm.adv_data_da_gg.value);
	var data2 = new Date(frm.adv_data_a_aaaa.value, frm.adv_data_a_mm.value, frm.adv_data_a_gg.value);
	
	if (data2<data1)
	{
		alert(msg);
	}
	else
		{
			frm.submit();
		}	
}
/*
	Aggiunta di un Utente
*/
function addUserSLSubmitForm(lang)
{
	
	var 
	email = document.userSLAddForm.email.value,
	name = document.userSLAddForm.name.value,
	surname = document.userSLAddForm.surname.value,
	company = document.userSLAddForm.company.value,
	telephone = document.userSLAddForm.telephone.value,	
	cell = document.userSLAddForm.cell.value,	
	role = document.userSLAddForm.role.value,
	errMsg = "";
	
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
        errMsg = errMsg + " - Per favore inserisci un indirizzo E-mail corretto!\n";
  	}
  		
  	//Verifico contenuti textBox obbligatorie
	if (name == "") errMsg = errMsg + " - Specificare un nome valido!\n";
	if (surname == "") errMsg = errMsg + " - Specificare un cognome valido!\n";

	
  	if(telephone != "") {
  		if (isNaN(telephone)) {
 	  		errMsg = errMsg + " - Per favore inserisci un numero di telefono corretto!\n";
		}
	}
	
  	if(cell != "") {
  		if (isNaN(cell)) {
 	  		errMsg = errMsg + " - Per favore inserisci un numero mobile corretto!\n";
		}
	}
	
	if (errMsg != "") {
		alert (errMsg);
		return false;
	}
	
	return true;
}

function checkPWD(lang){
	var pwdold = document.changepwd.pwdold.value;
	var pwdnew = document.changepwd.pwdnew.value;
	var pwdnew_repeat = document.changepwd.pwdnew_repeat.value;
	errMsg = "";
	
	if(pwdold.length != 6 || pwdnew.length != 6 || pwdnew_repeat.length != 6){
		if(lang == "IT")
			errMsg = "Le password devono essere di 6 caratteri";	
		 else 
			errMsg = "errore ing";
		
		alert (errMsg);
		return false;
	}
	
	return true;
}

function checkLOGIN(lang){
	var pwd = document.login.pwd.value;
	var email = document.login.email.value;
	errMsg = "";
	
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
        if(lang == "IT")
			errMsg = errMsg + " - Per favore inserisci un indirizzo E-mail corretto!\n";
		 else 
			errMsg = errMsg + " - EN Per favore inserisci un indirizzo E-mail corretto!\n";
  	}
  	
	if(pwd.length != 6){
		if(lang == "IT")
			errMsg = errMsg + "- La password deve essere di 6 caratteri";	
		 else 
			errMsg = errMsg + "- EN La password deve essere di 6 caratteri";
	}
	
	if (errMsg != "") {
		alert (errMsg);
		return false;
	}
	
	return true;
}

function checkricordaPWD(lang){
	var emailuno = document.ricordapwd.emailuno.value;
	var emaildue = document.ricordapwd.emaildue.value;

	errMsg = "";
	
	if(emailuno.equals(emaildue)){
		if(lang == "IT")
			errMsg = "Le email digitate sono differenti";	
		 else 
			errMsg = "errore ing  --- Le email digitate sono differenti";
		
		alert (errMsg);
		return false;
	}
	
	return true;
}

