function pop (url,w,h,s,f) {
LeftPosition =(screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
window.open(url,'new','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+s+',fullscreen='+f+'')
}


function popUrl (url,w,h,s) {
LeftPosition =(screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
window.open(url+'?ids='+s+'','new','width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,fullscreen=no')
}

function showLay(layId) {

eval("styleUsed=document.getElementById('tab"+layId+"').style.display;");

if (styleUsed=="none") { 
eval("document.getElementById('lnk"+layId+"').className='titvitOn';"); 
eval("document.getElementById('tab"+layId+"').style.display='block';"); 
} 
else { 
eval("document.getElementById('lnk"+layId+"').className='titvit';"); 
eval("document.getElementById('tab"+layId+"').style.display='none';"); 

}

}


function popImage(imageURL,imageTitle){
//really not important (the first two should be small for Opera's sake)
PositionX = 200;
PositionY = 200;
defaultWidth  = 200;
defaultHeight = 100;

//kinda important
var AutoClose = true;

	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() { \n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n  '+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight;}\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		//'var scW = 500;\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		//'if( !window.opera) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }alert(scW );\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/200)+30,Math.round((scH-oH)/200)+40); };\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' ':'')+' bgcolor="black">'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		//'<img src="/cont/resizeimg.aspx?i='+imageURL+'&e=jpg&w=190" alt="Loading image ..." title="" onload="resizeWinTo();">'+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}


function FormatDate(DateToFormat,FormatAs){
  if(DateToFormat==""){return"";}
  if(!FormatAs){FormatAs="dd/mm/yyyy";}
  var strReturnDate;
  FormatAs = FormatAs.toLowerCase();
  DateToFormat = DateToFormat.toLowerCase();
  var arrDate
  var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  var strMONTH;
  var Separator;
  while(DateToFormat.indexOf("st")>-1){
  DateToFormat = DateToFormat.replace("st","");
  }
  while(DateToFormat.indexOf("nd")>-1){
  DateToFormat = DateToFormat.replace("nd","");
  }
  while(DateToFormat.indexOf("rd")>-1){
  DateToFormat = DateToFormat.replace("rd","");
  }
  while(DateToFormat.indexOf("th")>-1){
  DateToFormat = DateToFormat.replace("th","");
  }
  if(DateToFormat.indexOf(".")>-1){
  Separator = ".";
  }
  if(DateToFormat.indexOf("-")>-1){
  Separator = "-";
  }
  if(DateToFormat.indexOf("/")>-1){
  Separator = "/";
  }
  if(DateToFormat.indexOf(" ")>-1){
  Separator = " ";
  }
  arrDate = DateToFormat.split(Separator);
  DateToFormat = "";
  for(var iSD = 0;iSD < arrDate.length;iSD++){
  if(arrDate[iSD]!=""){
  DateToFormat += arrDate[iSD] + Separator;
  }
  }
  DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
  arrDate = DateToFormat.split(Separator);
  if(arrDate.length < 3){
  return "";
  }
  var DAY = arrDate[0];
  var MONTH = arrDate[1];
  var YEAR = arrDate[2];
  if(parseFloat(arrDate[1]) > 12){
  DAY = arrDate[1];
  MONTH = arrDate[0];
  }
  if(parseFloat(DAY) && DAY.toString().length==4){
  YEAR = arrDate[0];
  DAY = arrDate[2];
  MONTH = arrDate[1];
  }
  for(var iSD = 0;iSD < arrMonths.length;iSD++){
  var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
  var MonthPosition = DateToFormat.indexOf(ShortMonth);
  if(MonthPosition > -1){
  MONTH = iSD + 1;
  if(MonthPosition == 0){
  DAY = arrDate[1];
  YEAR = arrDate[2];
  }
  break;
  }
  }
  var strTemp = YEAR.toString();
  if(strTemp.length==2){
  if(parseFloat(YEAR)>40){
  YEAR = "19" + YEAR;
  }
  else{
  YEAR = "20" + YEAR;
  }
  }
  if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
  MONTH = "0" + MONTH;
  }
  if(parseInt(DAY)< 10 && DAY.toString().length < 2){
  DAY = "0" + DAY;
  }
  switch (FormatAs){
  case "dd/mm/yyyy":
  return DAY + "/" + MONTH + "/" + YEAR;
  case "mm/dd/yyyy":
  return MONTH + "/" + DAY + "/" + YEAR;
  case "dd/mmm/yyyy":
  return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
  case "mmm/dd/yyyy":
  return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
  case "dd/mmmm/yyyy":
  return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
  case "mmmm/dd/yyyy":
  return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
  }
  return DAY + "/" + strMONTH + "/" + YEAR;;
}

function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}


function emailCheck (emailStr) {
  var emailPat=/^(.+)@(.+)$/
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  var validChars="\[^\\s" + specialChars + "\]"
  var quotedUser="(\"[^\"]*\")"
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  var atom=validChars + '+'
  var word="(" + atom + "|" + quotedUser + ")"
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) {
	return false
  }
  var user=matchArray[1]
  var domain=matchArray[2]
  if (user.match(userPat)==null) {
  return false
  }
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		return false
	    }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   return false
}
if (len<2) {
return false
}
return true;
}

function alert_quiz()
{
alert('Attenzione per poter accedere al questionario occorre avere visualizzato tutto il modulo');
}

function alert_quiz_suspended()
{
alert('Gentili utenti,\na causa di aggiornamenti sulla piattaforma, il questionario non è al momento disponibile.\nRiceverete opportuna comunicazione non appena possibile.\nDesideriamo scusarci per il disagio.\nCordiali saluti.');
}

function  alert_quiz_completed()
{
alert('Gentili utente,\n Le confermiamo che il questo modulo  è già stato completato con successo.');
}



