// JavaScript Document
////////////////////////////////////////////////////////////////////////////////////////////////// CONTENUTI ADMIN
//Selezione Multiple Selezionata
function setMultipleSelection(nameForm,nameCampo,nameCampoElenco) {
	pStrElencoId = '';
	document.forms[nameForm].elements[nameCampoElenco].value = '';
	for (i = 0; i < document.forms[nameForm].elements[nameCampo].options.length; i++){
		if (document.forms[nameForm].elements[nameCampo].options[i].selected == true) {pStrElencoId += document.forms[nameForm].elements[nameCampo].options[i].value+'|';}
	}
	if (pStrElencoId!='') {pStrElencoId = pStrElencoId.substring(0,pStrElencoId.length-1);}
	document.forms[nameForm].elements[nameCampoElenco].value = pStrElencoId;
	//alert(document.forms[nameForm].elements[nameCampoElenco].value);
}

//Controllo Valore Selezionato da Select con scelta multipla
function checkMultipleSelection(nameForm,nameCampo) {
	pValue = true;
	for (i = 0; i < document.forms[nameForm].elements[nameCampo].options.length; i++){
		if (document.forms[nameForm].elements[nameCampo].options[i].selected == true) {pValue = false;}
	}
	return pValue;
}

//Funzione di Set Check Allegati
function setStatusCheck(num,object){
	pValue = object.checked;
	arLang = new Array('EN','FR','IT','ES');
	for (i=0;i<arLang.length;i++){
		document.forms['mosForm'].elements['ALLEGATO_'+(num)+arLang[i]].checked = pValue;
	}
}

//Funzione di Autorizzazioni Utente
function setAutorizzazioniUtente(idTipoUtente,nameForm,pAction){
	//alert(idTipoUtente);
	if ((idTipoUtente==1)||(idTipoUtente==2)){
		//SuperAmministrator
		document.forms[nameForm].elements['ID_GROUP_SINGLE'].disabled = true;
		for (i = 0; i < document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options.length; i++){
			document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options[i].selected = true;
		}
		document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].disabled = true;
	}else if (idTipoUtente==3){
		//Administrator Group
		document.forms[nameForm].elements['ID_GROUP_SINGLE'].disabled = true;
		for (i = 0; i < document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options.length; i++){
			if (pAction=='INSERT'){document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options[i].selected = false;}
		}
		document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].disabled = false;
	}else if (idTipoUtente==4){
		//Registered
		document.forms[nameForm].elements['ID_GROUP_SINGLE'].disabled = false;
		for (i = 0; i < document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options.length; i++){
			document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].options[i].selected = false;
		}
		document.forms[nameForm].elements['ID_GROUP_MULTIPLE'].disabled = true;
	}
	
}

//MESSAGGIO DI CONFERMA 
function setMessageConfirm(strMessage){
	//alert(strMessage);
	if (confirm(strMessage)){
		return true;
	}else{
		return false;
	}
}

//Selezione Allegati Controllo
/*function setMultipleSelection(nameForm,nameCampo,nameCampoElenco) {
	pStrElencoId = '';
	document.forms[nameForm].elements[nameCampoElenco].value = '';
	for (i = 0; i < document.forms[nameForm].elements[nameCampo].options.length; i++){
		if (document.forms[nameForm].elements[nameCampo].options[i].selected == true) {pStrElencoId += document.forms[nameForm].elements[nameCampo].options[i].value+'|';}
	}
	if (pStrElencoId!='') {pStrElencoId = pStrElencoId.substring(0,pStrElencoId.length-1);}
	document.forms[nameForm].elements[nameCampoElenco].value = pStrElencoId;
	//alert(document.forms[nameForm].elements[nameCampoElenco].value);
}*/

////////////////////////////////////////////////////////////////////////////////////////////////// LINGUA
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_setCookie(selObj){
	//alert(selObj.options[selObj.selectedIndex].value);
	pLang = selObj.options[selObj.selectedIndex].value;
	SetCookie ('lingua', pLang);
	//window.location.href=window.location.href;
	window.location.reload();
	//alert('dasdsa');
}

function SetCookie (name, value){
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
     ((secure == true) ? "; secure" : "");
}
////////////////////////////////////////////////////////////////////////////////////////////////// HEADER
//Correzione Png Trasparanti
function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()

      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText

         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

         var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;"
             + imgStyle + ";"      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"

         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////// POPUP
function openNewWindow(url,windowW,windowH,windowName,visualizza_scroll) {
	var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
	var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
	resizable = 'yes';
	if (visualizza_scroll == '') {
		visualizza_scroll = 'no';
		resizable = 'no';
	}
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4)
		{windowH = windowH + 30; windowW = windowW + 10;}
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)>=5)
		{windowH = windowH + 29; windowW = windowW + 7;}
	var splashWin = window.open(url, windowName, 'status=no, toolbar=no, scrollbars='+visualizza_scroll+', resizable='+resizable+', width=' + windowW + ', height= ' + windowH);
	splashWin.resizeTo (Math.ceil(windowW), Math.ceil(windowH))
	splashWin.moveTo (Math.ceil(windowX), Math.ceil(windowY))
	splashWin.focus();
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4)
		{windowH = windowH - 30; windowW = windowW - 10;}
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)>=5)
		{windowH = windowH - 29; windowW = windowW - 7;}
}
////////////////////////////////////////////////////////////////////////////////////////////////// CONTROLLI CAMPI FORM
function MM_check_date(valore_campo) {
	var error = false;
	var controllo_prima_parte = 31;
	var controllo_seconda_parte = 12;
	arrayOfStrings = valore_campo.split("/");
	if (((isNaN(arrayOfStrings[0]) == true) || (arrayOfStrings[0] > controllo_prima_parte)) ||((isNaN(arrayOfStrings[1]) == true) || (arrayOfStrings[1] > controllo_seconda_parte)) || ((isNaN(arrayOfStrings[2]) == true) || (arrayOfStrings[2].length != 4)))
	{	
		error = true;
	}
	return error;
}

//CONTROLLO NOME FILE
function check_nome_file(valore_campo) {
	var elenco_caratteri_validi = 'abcdefghijklmnopqrstuvxywz01234567890_ -.!+&()=?|';
	var percorso_file = valore_campo.split("\\");
	var num_elementi = percorso_file.length;
	var nome_file_completo = percorso_file[num_elementi-1].toLowerCase();
	var nome_file = nome_file_completo.split(".");
	var num_elementi_file = nome_file.length;
	var nome_file_no_ext = "";
	var errore = false;
	if (num_elementi_file > 2) {
		errore = true;
	} else {
		nome_file_no_ext = nome_file[0];
	}
	if (errore == false) {
		for (var i=0;i<nome_file_no_ext.length;i++) {
			if (elenco_caratteri_validi.indexOf(nome_file_no_ext.substr(i,1)) < 0) {
				errore = true;
				break;
			}
		}
	}
	return errore;
}

//CONTROLLO ESTENSIONE FILE
function check_estensione_file(valore_campo,viewGallery) {
	if (viewGallery){
		var elenco_estensioni_valide= '.jpg,.gif,.bmp,.tif,.png,.tga,.tiff';
	}else{
		var elenco_estensioni_valide= '.txt,.rtf,.doc,.xls,.ppt,.pps,.pdf,.jpg,.gif,.bmp,.zip,.rar,.tif,.html,.htm,.swf,.xml,.png,.mp3,.swf,.mpeg,.mpg,.wav,.mov,.pdg,.tga,.asx,.avi,.wma';
	}
	//var elenco_estensioni_valide= '.txt,.rtf,.doc,.xls,.ppt,.pps,.pdf,.jpg,.gif,.bmp,.zip,.rar,.tif,.html,.htm,.swf,.xml,.png';
	var percorso_file = valore_campo.split("\\");

	var num_elementi = percorso_file.length;
	var nome_file_completo = percorso_file[num_elementi-1].toLowerCase();
	var nome_file = nome_file_completo.split(".");
	var num_elementi_file = nome_file.length;
	var estensione_file = "";
	var errore = false;
	if (num_elementi_file > 2) {
		errore = true;
	} else {
		estensione_file = "." + nome_file[1];
	}
	if (errore == false) {
		if (elenco_estensioni_valide.indexOf(estensione_file) < 0) {
			errore = true;
		}
	}
	return errore;
}
