/**
  BROWSER DETECTION CONDITIONS
  Conditions for client's browser type sniffing using DOM's properties.
  USAGE: check the boolean status of variables ie, w3c and ns
  @return Internet Explorer = ie:true OR Netscape Navigator = ns:true OR W3C-compliant = w3c:true
*/
var ns=(document.layers)?true:false;
var ie=(document.all)?true:false;
var w3c=(document.getElementById)?true:false;
if(ns)
  alert("ATTENZIONE!!!\nIl Suo Browser e' AMPIAMENTE OBSOLETO.\nPotrebbero verificarsi seri problemi di visualizzazione delle pagine continuando ad utilizzarlo.\n\nSi raccomandano i seguenti Browser maggiormente conformi agli standard W3C:\n\n- Mozilla Firefox Ver. >= 2.x\n- Microsoft Internet Explorer Ver. >= 6.0");

function sendAJAXCall(scriptPath,callMethod,postData,postbackFunction) {
  var new_req;
  
	if(window.XMLHttpRequest)
    new_req=new XMLHttpRequest();
  else if(window.ActiveXObject)
    new_req=new ActiveXObject("Microsoft.XMLHTTP");
  
	new_req.open(callMethod,scriptPath,true);
	new_req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	new_req.setRequestHeader('Content-length',postData.length);
	new_req.setRequestHeader('Connection','close');
	new_req.onreadystatechange=postbackFunction;
	new_req.send(postData);
	
	return new_req;
} // End of sendAJAXCall() function

function captureAJAXPostback(ajaxReqObj) {
  var tmp='';
  
  if(ajaxReqObj!=null) {
    if(ajaxReqObj.readyState==4) {
      if(ajaxReqObj.status==200)
    		tmp=ajaxReqObj.responseText;
    }
  }
  return tmp;
} // End of captureAJAXPostback() function

function showsondaggio() {
	var risultati=document.getElementsByClassName('risultato');
	
	for(i=0;i<risultati.length;i++) {
   	if(risultati[i].style.display=='block')
  		risultati[i].style.display='none';
  	else
  		risultati[i].style.display='block';
  }
}

function jplayer_play_video(file) {
	if(navigator.userAgent.indexOf("MSIE")!=-1) {
		document.getElementById('homebanner').style.diplay='none'
		document.getElementById('homebanner').style.visibility='hidden'
		document.getElementById('videoplayer').style.visibility='visible';
		PLAYER.controls.stop();
		PLAYER.URL = file;
		PLAYER.controls.play();
	}
	else
		window.open(file);
}

function jplayer_play() {
  PLAYER.controls.play();  
}

var paused = false;
function jplayer_pause() {
  
  if(paused == true) {
   PLAYER.controls.play();
   paused = false;
  }
  else {  
    PLAYER.controls.pause();
    paused = true;
  }
}
function jplayer_stop() {
	PLAYER.controls.stop();
}

function myparseInt(s) {
	while ((s.charAt(0) == '0') && (s.length > 1))
		s = s.substring(1, s.length);
	return(parseInt(s));
}

function checkCF(cf) {
  var validi,i,s,set1,set2,setpari,setdisp;
  
  if(cf=='')
    return '';
  cf=cf.toUpperCase();
  if(cf.length!=16)
  	return false;
  validi="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  for(i=0;i<16;i++) {
      if(validi.indexOf(cf.charAt(i))==-1)
	    	return false;
  }
  set1="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  set2="ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
  setpari="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  setdisp="BAKPLCQDREVOSFTGUHMINJWZYX";
  s=0;
  for(i=1;i<=13;i+=2)
    s+=setpari.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
  for(i=0;i<=14;i+=2)
    s+=setdisp.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
  if(s%26!=cf.charCodeAt(15)-'A'.charCodeAt(0))
    return false;
  
 	return true;
}

function checkVAT(pi) {
  var validi="0123456789";
  
  if(pi.length!=11)
  	return false;
  for(i=0;i<11;i++) {
    if( validi.indexOf(pi.charAt(i))==-1)
      return false;
  }
  s=0;
  for(i=0;i<=9;i+=2)
    s+=pi.charCodeAt(i)-'0'.charCodeAt(0);
  for(i=1;i<=9;i+=2) {
    c=2*(pi.charCodeAt(i)-'0'.charCodeAt(0));
    if(c>9)
      c=c-9;
    s+=c;
  }
  if((10-s%10)%10!=pi.charCodeAt(10)-'0'.charCodeAt(0))
    return false;
  
  return true ;
}

function CheckDate(s,empty) {
	if(s == "")
		return(empty == 1) ;
	if(s.length != 10)
		return(false) ;
	if((s.substring(2,3) != "/") || (s.substring(5,6) != "/"))
		return(false) ;
	g = myparseInt(s.substring(0,2)) ;
	m = myparseInt(s.substring(3,5)) ;
	a = myparseInt(s.substring(6,10)) ;
	//alert(g+"/"+m+"/"+a) ;
	if(isNaN(g) || isNaN(m) || isNaN(a))
		return(false) ;
	if((g < 1) || (m < 1) || (a < 0))
		return(false) ;
	switch(m) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if(g > 31)
				return(false) ;
			return(true) ;
		case 4:
		case 6:
		case 9:
		case 11:
			if(g > 30)
				return(false) ;
			return(true) ;
		case 2:
			if(a % 4) {
				if(g > 28)
					return(false) ;
			}
			else {
				if(g > 29)
					return(false) ;
			}
			return(true) ;

		default:
			return(false) ;
	}
	return(true) ;
}

function CheckTime(s,empty) {
	if(s == "")
		return(empty == 1) ;
	if(s.length != 5)
		return(false) ;
	if(s.substring(2,3) != ":")
		return(false) ;
	h = myparseInt(s.substring(0,2)) ;
	m = myparseInt(s.substring(3,5)) ;
	if(isNaN(h) || isNaN(m))
		return(false) ;
	if((h < 0) || (m < 0))
		return(false) ;
	if((h > 23) || (m > 59))
		return(false) ;
	return(true) ;
}

function CheckHM(hs,ms) {
	if(hs == "")
		hs = 0 ;
	if(ms == "")
		ms = 0 ;
	h = myparseInt(hs) ;
	m = myparseInt(ms) ;
	if(isNaN(h) || isNaN(m))
		return(false) ;
	if((h < 0) || (m < 0))
		return(false) ;
	if((m > 59))
		return(false) ;
	return(true) ;
}

function CheckFloat(s,empty) {
	if(s == "")
		return(empty == 1) ;
	dot = false ;
	for(i = 0 ; i < s.length ; i++)
	{
		if(s.charAt(i) == '.')
		{
			if((dot == true) || (i == s.length-1))
				return(false) ;
			dot = true ;
		}
		else if((s.charAt(i) < '0') || (s.charAt(i) > '9'))
			return(false) ;
	}
	return(true);
}

function CheckEuro(s,empty) {
	if((s == '') || (s == 0))
		return(empty == true) ;
	
	dot = false ;
	for(i = 0 ; i < s.length ; i++) {
		if(s.charAt(i) == '.') {
			if((dot == true) || (i < s.length-3) || (i == s.length-1))
				return(false) ;
			dot = true ;
		}
		else if((s.charAt(i) < '0') || (s.charAt(i) > '9'))
			return(false) ;
	}
	return(true);
}

function CheckIntegerRange(num,min,max,k) {
	if((k == 0) && (num == ''))
		return(true) ;
	if(num < min)
		return(false) ;
	if(num > max)
		return(false) ;
	return(true) ;
}

function CheckSubProdottoCode(str) {
	if(str == '')
		return(false) ;
	if(str.search('-') == str.length - 1)
		return(false) ;
	return(true) ;
}

function checkexts(str,exts) {
	str = str.split(".") ;
	str = str.pop() ;
	if(str == '')
		str = '#none' ;
	exts = "§" + exts + "§" ;
	if(exts.search("§" + str.toLowerCase() + "§") >= 0)
		return(true) ; // estenzione valida
	return(false) ; // estenzione non valida
}

function standardKeys() {	// A-Z a-z 0-9
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90))
		return ;
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function IntKeys() { // - 0-9
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if(window.event.keyCode == 45)
		return ;
	event.returnValue = false ;
}

function RicercaKeys() { // A-Z a-z 0-9 . - @ _
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90))
		return ;
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
		return ;
	if((window.event.keyCode == 46) || (window.event.keyCode == 45))
		return ;
	if((window.event.keyCode == 64) || (window.event.keyCode == 95))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function LoginKeys() { // a-z 0-9 . -
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90)) {
		window.event.keyCode += 32 ;
		return ;
	}
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
		return ;
	if((window.event.keyCode == 46) || (window.event.keyCode == 45))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function LoginKeysExt()	{ // a-z 0-9 . - _
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90)) {
		window.event.keyCode += 32 ;
		return ;
	}
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
		return ;
	if((window.event.keyCode == 46) || (window.event.keyCode == 45) || (window.event.keyCode == 95))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function UpperDigitKeys()	{ // A-Z 0-9
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90))
		return ;
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122)) {
		window.event.keyCode -= 32 ;
		return ;
	}
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function UpperAlphaKeys(str) { // A-Z
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90))
		return ;
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122)) {
		window.event.keyCode -= 32 ;
		return ;
	}
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function EmailKeys() { // a-z 0-9 . -
	if((window.event.keyCode >= 48) && (window.event.keyCode < 58))
		return ;
	if((window.event.keyCode >= 65) && (window.event.keyCode <= 90)) {
		window.event.keyCode += 32 ;
		return ;
	}
	if((window.event.keyCode >= 97) && (window.event.keyCode <= 122))
		return ;
	if((window.event.keyCode == 46) || (window.event.keyCode == 45))
		return ;
	if((window.event.keyCode == 64) || (window.event.keyCode == 95))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function DateKeys(e) { // 0-9 /
  var evtobj=(window.event)?event:e; //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
  var unicode=(evtobj.charCode)?evtobj.charCode:evtobj.keyCode;
	if((unicode>=48) && (unicode<=57))
		return;
	if(((unicode==45) || (unicode==46) || (unicode==47) || (unicode==58))) {
		if(evtobj.charCode) {
		  var newEvent=document.createEvent("KeyboardEvent");
      newEvent.initKeyEvent("keypress",true,true,document.defaultView,evtobj.ctrlKey,evtobj.altKey,evtobj.shiftKey,evtobj.metaKey,0,47);
      evtobj.preventDefault();
      evtobj.target.dispatchEvent(newEvent);
    }
    else
      evtobj.keyCode=47;
		return;
	}
	if((unicode==8) || (unicode==13))
		return;
	return false;
}

function TimeKeys()	{ // 0-9 :
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode == 45) || (window.event.keyCode == 46) || (window.event.keyCode == 47) || (window.event.keyCode == 58)) {
		window.event.keyCode = 58 ;
		return ;
	}
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function FloatKeys() { // 0-9 .
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode == 46) || (window.event.keyCode == 44)) {
		window.event.keyCode = 46 ;
		return ;
	}
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function EuroKeys(str) { // 0-9 .
	if((window.event.keyCode == 46) || (window.event.keyCode == 44))
		window.event.keyCode = 46 ;
	if(str.indexOf('.') > -1 && window.event.keyCode == 46)
		event.returnValue = false ;
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if(window.event.keyCode == 46)
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function DigitKeys() { // 0-9
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
		return ;
	if((window.event.keyCode == 8) || (window.event.keyCode == 13))
		return ;
	event.returnValue = false ;
}

function genericSearchKeys() { // diverso da:  _ %
	if((window.event.keyCode != 95) && (window.event.keyCode != 37))
		return ;
	event.returnValue = false ;
}

function NoQuotesKeys()	{ // Non "
	if(window.event.keyCode != 34)
		return ;
	event.returnValue = false ;
}

function checkEmail(s_email) {
	var i=s_email.indexOf(' ',0);
	while(i>-1) {
		s_email = s_email.substring(0,i) + 
			s_email.substring((i + 1),s_email.length);
		i = s_email.indexOf(' ',0);
	}
	if((s_email.length<6) || (s_email.indexOf('@',0)<1) ||
	   (s_email.lastIndexOf('@')!=s_email.indexOf('@',0)) || (s_email.lastIndexOf('@')>(s_email.length-5)) ||
	   (s_email.lastIndexOf('.')>(s_email.length-3)) || (s_email.lastIndexOf('.')<(s_email.length-7)) ||
	   (s_email.indexOf('..',0)>-1) || (s_email.indexOf('@.',0)>-1) ||
	   (s_email.indexOf('.@',0)>-1) || (s_email.indexOf(',',0)>-1))
		return false;
	return true;
} // End of checkEmail() function

// by eZ -- cerca il value in una combo e lo pone selected
function searchIn (combo,value) {
	for (var i = 0; i < combo.length; i++)
		if (combo.options[i].value == value) {
			combo.selectedIndex = i;
			return true;
		}
	return false;
}

function openbigpopup(loc) {
	window.open(loc,"popup","location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,status=yes,width="+screen.width+",height="+screen.height+",left=0,top=0") ;
}

function getBrowserWidth(){
  if (window.innerWidth){
  return window.innerWidth;} 
  else if (document.documentElement && document.documentElement.clientWidth != 0){
  return document.documentElement.clientWidth; }
  else if (document.body){return document.body.clientWidth;} 
  return 0;
} 

function dynamicLayout(){
  var browserWidth = getBrowserWidth();

  if (browserWidth <= 1024){
  changeLayout("stretto");
  }
  if (browserWidth > 1100){
  changeLayout("largo");
  }
} 

function changeLayout(description){
   var i, a;
    if (document.getElementsByTagName)
     a = document.getElementsByTagName('link');
  else if (document.all)
     a = document.all.tags('link');
   for(i=0; i<a.length; i++){
    a[i].disabled = true;
	   if(a[i].getAttribute("title") == description){
	    a[i].disabled = false;
	    }
	   else if(a[i].getAttribute("title") != "default"){
	    a[i].disabled = true;
	    }
   }
}

function loadswf(swf,w,h){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"");
  document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"");
	document.write("width=\""+w+"\" height=\""+h+"\">");
  document.write("<param name='movie' value='"+swf+"' />\n");
  document.write("<param name='quality' value='high' />\n");
  document.write("<embed src=\""+swf+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+w+"\" height=\""+h+"\"></embed>");
  document.write("</object>\n");
}

function loadwmf() {
  document.write('<object title="" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="PLAYER" type="video/x-ms-wmv" data="0.wmf" width="320" height="240">');
  document.write('<param name="src" value="0.wmf" />');
  document.write('<param name="url" value="0.wmf" />');
  document.write('<param NAME="SendPlayStateChangeEvents" VALUE="True">');
  document.write('<param NAME="AutoStart" VALUE="False">');
  document.write('<param name="uiMode" value="none">');
  document.write('<param NAME="enableContextMenu" value="False" />  	');
  document.write('<param name="PlayCount" value="1">');
  document.write('<param name="stretchToFit" value="False" />');
  document.write('<param name="TransparentatStart" value="True">');
  document.write('<param name="AnimationatStart" value="True">');
  document.write('<param name="ShowControls" value="0">');
  document.write('<param name="allowScriptAccess" value="sameDomain">');
  document.write('</object>');
}

function conferma(url) {
	var answer = confirm("Si è sicuri di voler uscire?")
	if (answer){
		window.location = url;
		return true;
	}
	else{
		return false;
	}
}
