// JavaScript Document

/*************************************************************//*FINESTRE 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 );
	if (visualizza_scroll == '') {
		visualizza_scroll = '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=yes, 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;}
}

/*************************************************************//*CAMPI FORM POPUP - FILE/*/
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_ -.!+&()=?|';
	
	if (navigator.userAgent.indexOf("Win") != -1) {
       var percorso_file = valore_campo.split("\\");
    }else if (navigator.userAgent.indexOf("Mac") != -1) {
       var percorso_file = valore_campo.split("/");
    }else if (navigator.userAgent.indexOf("Linux") != -1) {
       var percorso_file = valore_campo.split("/");
    }else{
	   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) {
	
	var elenco_estensioni_valide= '.txt,.rtf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pps,.ppsx,.pdf,.jpg,.gif,.bmp,.zip,.rar,.tif,.html,.htm,.swf,.xml,.png,.mp3,.swf,.mpeg,.mpg,.wav,.mov,.pdg,.tga,.asx,.avi,.wma';
	
	if (navigator.userAgent.indexOf("Win") != -1) {
       var percorso_file = valore_campo.split("\\");
    }else if (navigator.userAgent.indexOf("Mac") != -1) {
       var percorso_file = valore_campo.split("/");
    }else if (navigator.userAgent.indexOf("Linux") != -1) {
       var percorso_file = valore_campo.split("/");
    }else{
	   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;
}
/*************************************************************//*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 ('l_navaski', 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" : "");
}
