

function isChar(field)
{
 var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"
 var ok = "yes";
 var temp;
 for (var i=0; i<field.value.length; i++)
 {
  temp = "" + field.value.substring(i, i+1);
  if (valid.indexOf(temp) == "-1")
     ok = "no";
 }
 if (ok == "no")
 {
  alert(msg_8072);
  field.focus();
  field.select();
 }
}

function intValidate(num){	
  
  num_Val = num.value
  var numStr = "0123456789";
  var thisChar;
  var counter = 0;
    for (var n = 0; n < num_Val.length; n++) {
      thisChar = num_Val.substring(n, n+1);
      if (numStr.indexOf(thisChar) < 0)      return false;
    }
  
   return true;
        
}

function isInt(field) {
	var fieldstr = field.value + "";
    if (fieldstr == "") return false;
	if(!intValidate(field)){
     	alert(msg_8142);
  		field.focus();
  		field.select();
		return false;    
  	}
	return true;
}

//**************************************
// FUN COMUNI da importate da marco 05-08-02

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//**************************************



// Login.htm, Scelta.htm,menuprenotazione.wm


 function controllaEnabled(campoDescr,campo,valore)
                 {
	 if(campo.value==valore)
                 {
	 campo.focus();
                 }
 }


function lang(LAN) {
	document.forms["sceltaviaggio"].LANG.value = LAN;
    gotoPage('I');
}




function submit() {		
	displayWait();	
  document.forms[0].submit();
}

function fsubmit() {	
		displayWait();
  	document.forms[0].submit();

}

function submitForm(fname) {	
	displayWait();
  	document.forms[fname].submit();

}


function gotoPage(idPage) {
	
	document.forms[0].ID.value = idPage;
	//displayWait();
  	submit();
	
}

function gotoMyPage(idPage, frm) {
	displayWait();
	document.forms[frm].ID.value = idPage;
  	document.forms[frm].submit();
}



function opencalendario(theURL,winName,features, tipoviaggio)
{
	if (tipoviaggio == "andata")
	{
		andata = true;
		opriti = new Date();
		sdata = new Date(opriti.getFullYear(), opriti.getMonth(), opriti.getDate() + 2);
		ldata = new Date(opriti.getFullYear(), opriti.getMonth(), opriti.getDate() + 2);
		
		calendario = window.open(theURL,winName,features);
	}
	else if (tipoviaggio == "ritorno")
	{
	 	var test;
		if(document.forms[0].DATA_ANDATA.value=="")
		{
		opriti = new Date();	
		 test= new Date(opriti.getFullYear(), opriti.getMonth(), opriti.getDate() + 2); 					 
               
		}
                               else
                               {
		var aaaa = document.forms[0].DATA_ANDATA.value.substring(6,10);
		var mm = document.forms[0].DATA_ANDATA.value.substring(3,5);
		var gg = document.forms[0].DATA_ANDATA.value.substring(0,2);
		test = new Date(aaaa, mm - 1, gg);
                                }
	                 
		if (!isNaN(test.getDate()))
		{
			sdata = test;
			ldata = test;
			andata = false;
			calendario = window.open(theURL,winName,features);
		}
	}
}


function openURL(theURL,winName,features)
{
	url = window.open(theURL,winName,features);
}

function restoreSelect (select, value) {
  for (i=0;select.options[i] != null;i++){
    if (select.options[i].value == value) {
      select.options[i].selected = true;
      break;
    }    
  }
}

function checkedRadio(radioObject)
{
var y=radioObject.length;
for (i=0; i<y; i++)  {
        if (radioObject[i].checked)
        return i;
  }
  return false;
}

function reset(radioObject)
{
radioObject.options[0].selected = true

}

function cleanList(listObject)
{
if (listObject == null)
return;
var y=listObject.options.length;
for (i=y-1; i>=0; i--)  {
        listObject.options[i]= null;
  }
}

function MakeArray(n) {
 this.length = n;
 for (var i=1; i<=n; i++) {
     this[i] = 0
 }
 return this;
}

function SearchArray( Obj, Obj_name, Value)
{
 for (i=1; i<= Obj.length; i++) {
     if (Obj[i][Obj_name] == Value)
        return i;
 }
 return false;
}

function copySelected(src, dst) {
  var isrc = src.selectedIndex;
  var value = src[isrc].value;
  for (var idst = 0; idst < dst.length; idst++) {
    if (dst[idst].value == value) {
      dst[idst].selected = true;
      break;
    }
  }
}

function isInList( codCat , Lista){
	var numMax=Lista.options.length;
	for(  var scorri=0; scorri <numMax; scorri++)
	 {
		 if(  Lista.options[scorri].value == codCat ) 
				return true;
	 }
	return false;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function initNumVettore( vet)
{
  for (var x=0;x<vet.length ;x++)
  	{
	   vet[x]=0;
	}
return vet;	
}
function initVettore( vet)
{
  for (var x=0;x<vet.length ;x++)
  	{
	   vet[x]='';
	}
return vet;	
}

function isDate(field)
{
 var m,y;
 Today = new Date();
 var TMonth = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
 var CurMonth = Today.getMonth();
 var Month = TMonth[CurMonth];
 var Year = Today.getFullYear();


 m=field.substring(0,2);
 y=field.substring(2,4);
 y=20+y;

if( (m==Month && y<Year) || y<Year || (m<Month && y==Year))
 {
  return false;
 }
return true;
}





function isEmail(field) 
{
    if (field.value.indexOf("@") != "-1" &&
        field.value.indexOf(".") != "-1" )
        return true;
    else return false;
}

function checkIntervalloDate(form){
	if((form.GIORNO_RITORNO.value != '0' && form.MESE_RITORNO.value == '0' )||(form.GIORNO_RITORNO.value == '0' && form.MESE_RITORNO.value != '0' )){
   		alert(msg_8238);
   		return false;
   	}
   if(form.MESE_RITORNO.value != '0'){   	
   	if ((form.MESE_RITORNO.value - form.MESE_ANDATA.value)<0){
   		alert(msg_8237);
   		return false;
   	}   	
   	if (form.MESE_RITORNO.value == form.MESE_ANDATA.value && form.GIORNO_RITORNO.value<=form.GIORNO_ANDATA.value ){   	
   		alert(msg_8237);
   		return false;
   	}
   }
   return true;
}

function checkFirstAvailDay(form, first_avail_day, first_avail_day_month){		
		
	if( ( form.MESE_ANDATA.value  > first_avail_day_month ) || (form.MESE_ANDATA.value == first_avail_day_month && form.GIORNO_ANDATA.value >= first_avail_day ) ) {		
		return true;
	}	
	alert (msg_8054 + " " + hourfromstart + " " + msg_8239);
	return false;
		
}

//visualizza il messaggio di attesa (da invocare prima di effettuare una submit)
function displayWait() {
	try {
	document.getElementById("pageDiv").style.display="none";
	document.getElementById("messageDiv").style.display="block";
	document.getElementById("spacerDiv").style.display="none";
	}
	catch (e){
	;
	}
}


/* NUOVE FUNZIONI */

//visualizza/naconde la riga di una tabella
function setTROnOff(rowId) {
    try {
		var el = document.getElementById(rowId);
		if(el.style.display == "none") {
			el.style.display = "table-row";
		} else {
			el.style.display = "none";
		}
	} catch(e) {
	;
	}
	//torna false per interrompere l'evento se invocata da un link
	return false;
}


function mkErr(el) {
	try {
	el.style.backgroundColor="#D2E2F5";
	if(!el.errIm) {
		var ei = new Image();
		ei.src=errIcon;
		el.errIm = ei;
		ei.style.position="absolute";
		ei.style.margin="2px 0px 0px 1px";
		el.parentNode.appendChild(ei);
		//el.parentNode.style.verticalAlign="middle";
		//el.parentNode.style.whiteSpace="nowrap";
	} else {
		el.errIm.style.display="inline";
	}
	} catch(e) {;}
}

function spErr() {
	try {
	this.style.backgroundColor="";
	this.errIm.style.display="none";
	} catch(e) {;}
}

//check di una data
function chkDt(el, errmsg) {
  var ok = parseDate(el);
  el.corrfun = spErr;
  el.onfocus = el.corrfun;
  if(!ok) {
    mkErr(el);
    if(errmsg) alert(errmsg);
  } else {
    spErr(el);
  }
}

function parseDate(inputObject) {
	try {
		var re = new RegExp("(\/)|( )", "g");
                inputObject.value = inputObject.value.replace(re, "-");
		var val = inputObject.value.split("-");
		var obDate = new Date(val[2], val[1]-1, val[0]);
		if(obDate.getFullYear()!=val[2]  || obDate.getMonth() != val[1]-1 || obDate.getDate() != val[0]) {
			inputObject.value="";
			return false;
		}
	} catch (e) {
		inputObject.value="";
		return false;
	}
	return true;
}


$(document).ready(function() {
	$("#helpDiv").hide().prependTo("#pageDiv").css({'z-index': '1000', 'position': 'absolute', 'left':  $("#pageDiv").position().left + 'px', 'top': '30px', 'height':  $("#pageDiv").height() + 'px', 'overflow': 'auto','background-color': '#ffffff'}).bgiframe();;
	$("div.smallHelp a").click(function() {
		if($(this).html() == "Help") {
			$(this).html("Chiudi Help");
			$("#helpDiv").width(600).height(500).slideDown("slow", function() { $(this).load($("#getHelpPage").attr('href')); });
		} else {
			$(this).html("Help");
			$("#helpDiv").slideUp("fast");
		}
		return false;
	});
});

