// JavaScript Document

/*
<script language="javascript" type="text/javascript">
</script>

*/
// ###
var minYear=1900;
var maxYear=2100;

function frameParentFunction(x)
{
	alert(x)
}

function ConfirmPersReset(cgi_handler, msg, langnum,location)
{
//alert('in ConfirmPersReset2');
   if(msg.length==0)
   {
      switch(langnum)
      {
         case 0:
           msg="This will reset fields to factory default values. Proceed?";
           break;   
         case 1:
           msg="Esta acción regresará los campos a su valor de fábrica. Proceder?";
           break;
         default://assume english
           msg="This will reset fields to factory default values. Proceed?";
      
      }       
   }
   if (confirm(msg))
      location.href=cgi_handler;     
   
}

function isInteger(s)
{
	var i;
    for (i=0; i<s.length; i++){   
        // check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) 
           return false;
    }
    return true;
}
function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) 
		   this[i] = 30;
		if (i==2) 
		   this[i] = 29;
   } 
   return this;
}

function isTime(dtStr)
{
    if(dtStr.length==16)//no secs field, fill it in
    dtStr=dtStr+":00";
	var posTime=dtStr.indexOf(" ");	
	var pos1=dtStr.indexOf(":");
	var pos2=dtStr.indexOf(":",pos1+1);
	var strHour=dtStr.substring(posTime+1,pos1);
    var strSec=dtStr.substring(pos2+1);
    var strMinute=dtStr.substring(pos1+1,pos2);
     
   var msg0;
   var msg1;
   var msg2;
   var msg3;
   switch(0)
   {
      case 0://english
         msg0="The time format should be HH:MM:SS";
         msg1="Please enter value between 0 to 24 for the hour";
         msg2="Please enter value between 0 to 59 for the minute";
         msg3="Please enter value between 0 to 59 for the second";
     
         break;
      case 1://spanish
         msg0="El formato de hora debe ser: HH:MM:SS";
         msg1="Por favor introduzca un valor entre 0 y 24 para la hora";
         msg2="Por favor introduzca un valor entre 0 y 59 para los minutos";
         msg3="Por favor introduzca un valor entre 0 y 59 para los segundos";
         break; 
   }
	
	if (strSec.charAt(0)=="0" && strSec.length>1) 
	   strSec=strSec.substring(1);
	if (strMinute.charAt(0)=="0" && strMinute.length>1) 
	   strMinute=strMinute.substring(1);
	if (strHour.charAt(0)=="0" && strHour.length>1) 
	   strHour=strHour.substring(1);

	min=parseInt(strMinute);
	sec=parseInt(strSec);
	hour=parseInt(strHour);
	
	
	if (posTime==-1 || pos1==-1 || pos2==-1){
		alert(msg0);//alert('The time format should be HH:MM:SS');

	}		
	if (!isInteger(strHour)|| strHour.length<1 || hour<0 || hour>24)
	{
		alert(msg1);//alert("Please enter value between 0 to 24 for the hour");
		return false;
	}
	if (!isInteger(strMinute)|| strMinute.length<1 || min<0 || min>59)
	{
		alert(msg2);//alert("Please enter value between 0 to 59 for the minute");
		return false;
	}
		
	if (!isInteger(strSec)|| strSec.length<1 || sec<0 || sec>59)
	{
		alert(msg3);//alert("Please enter value between 0 to 59 for the second");
		return false;
	}
    return true;
}

function isDate(dtStr){
	var daysInMonth =DaysArray(12);
	
	var pos1=dtStr.indexOf("-");
	var pos2=dtStr.indexOf("-",pos1+3);
	var strYear=dtStr.substring(0,pos1);
	
	var strMonth=dtStr.substring(pos1+1,pos2);

	var strDay=dtStr.substring(pos2+1,pos2+3);	

   var msg0;
   var msg1;
   var msg2;
   switch(0)
   {
      case 0://english
         msg0="The date format should be : YYYY-MM-DD";
         msg1="Please enter a valid month";
         msg2="Please enter a valid day";
     
         break;
      case 1://spanish
         msg0="El formato de fecha debe ser: YYYY-MM-DD";
         msg1="Por favor introduzca un valor válido para el mes";
         msg2="Por favor introduzca un valor válido para el día";
 
         break; 
   }



	
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	

	
	for (var i = 1; i <= 3; i++) 
	{
		if (strYear.charAt(0)=="0" && strYear.length>1) 
		   strYear=strYear.substring(1);
	}	
	   
	day=parseInt(strDay);	
	year=parseInt(strYear);	
	month=parseInt(strMonth);
		
	if (pos1==-1 || pos2==-1)
	{
		alert(msg0);
		return false;
	}
	if (!isInteger(strMonth)|| strMonth.length<1 || month<1 || month>12)
	{
		alert(msg1);
		return false;
	}
	if (!isInteger(strDay)|| strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		alert(msg2);
		return false;
	}
	if (!isInteger(strYear)|| strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		switch(0)
		{
		case 0:
				alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
			break;
		case 1:
				alert("Por favor introduzca un año válido entre "+minYear+" y "+maxYear);
			break;   
		} 	
		return false;
	}
    return true;
}

var gT=null
var gP1=60
var gC1=gP1
var gD=null
var gT1=null
var gC2=null
var gcH=null
var ga=0

function ft(x) {
	return ((x<10)?"0":"")+x
}
var gf=0

function jsltff(f) {
	gf=f
}

function jsltf(t,f) {
	if (!f)f=gf
	if (f==3) {
		ap="AM";
		h=t.getHours();
		if(h>11)ap="PM";
		if(h>12)h=h-12;
		if(h==0)h=12;
		h=ft(h)+":"+ft(t.getMinutes())+":"+ft(t.getSeconds())+" "+ap
	}
	else {
		h=ft(t.getHours())+":"+ft(t.getMinutes())+":"+ft(t.getSeconds())
	}
	switch(f) {
	case 2: return ft(t.getDate())+"/"+ft(t.getMonth()+1)+"/"+t.getFullYear()+" "+h; break;
	case 3: return ft(t.getMonth()+1)+"/"+ft(t.getDate())+"/"+t.getFullYear()+" "+h; break;
	}
	return t.getFullYear()+"-"+ft(t.getMonth()+1)+"-"+ft(t.getDate())+" "+h

}

var gTF = "jslibLoop()"

function jslibLoop()
{
	t=jsltf(new Date())
	if(gT1) {gT1.innerHTML=t}
	if(!gcH||!gcH.checked){
		if (gC1==0){
			jslUpd()
			gC1=gP1
		}
		if(gC2){gC2.innerHTML=gC1}
		if(gC1>0){gC1--}
	}
	gT=setTimeout(gTF,1000)
}

var x = false

function jslInit(d,p,b,c,h,f)
{
//	document.writeln("<p>ga="+ga+"</p>")
	gD=d
	gP1=p
	gT1=b
	gC2=c
	gcH=h
	gC1=gP1
	gTF=((f&&f!="")?f:"jslibLoop()")
//	alert( "document_forms_onHoldCB= " + document_forms_onHoldCB.checked + ", x=" + x )
//	if(gcH)gcH.checked=true
	jslibLoop()
	if(gcH){
		gcH.checked=x; 	
	}
}

function jslStop()
{
	clearTimeout(gT)
}

function jslUpd(d)
{
	ga++
	x=(gcH?gcH.checked:false)
//	alert("x=" + x)
//	if (d) { d.location.reload(true) } else 
//		location.reload(true)
	if(gD)gD.location.reload(true)
//	location.refresh
	if(gcH){
		gcH.checked=x; 	
		//alert("x=" + x)
	}
}

function jslw(URL,w,h)
{
	ww=window.open(URL,"A",
		"resizable=yes,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width="+w+",height="+h)
	ww.focus()
}
function helpWin(k)
{
	jslw("help.html#"+k,500,400)
}
function showWin(u)
{
	jslw(u,700,700)
}

//
 // 2005-09-13 JOHSAR
var prevOnLoadTime = new Date();

function setPrevUnLoadTime()
{
  prevOnLoadTime = new Date();
}

function getPrevUnLoadTime()
{
  return prevOnLoadTime;
}

// NEW 2005-09-14 WED JOHSAR

var gHeadDbgF=null

var prevloadunloadDate;
prevloadunloadDate = new Date();
var prevloadunloadSec=prevloadunloadDate.getTime();

function setDBGmsg(f)
{
  gHeadDbgF = f;
}

function nowDiff() 
{
  var nowtime=new Date();
  var nowsec=nowtime.getTime();
  var difftime=(nowsec-prevloadunloadSec)/1000;
  prevloadunloadDate = nowtime; // not neccessary...
  prevloadunloadSec = nowtime.getTime();
  return difftime;
}

function OnLoadFunc()
{
  if(0==0)
    return; 
  var time = nowDiff()
  if(gHeadDbgF) {gHeadDbgF.innerHTML="loaded in " + time}

} // OnLoadFunc()

function OnUnloadFunc()
{
  if(0==0)
    return; 
  var time = nowDiff()
  if(gHeadDbgF) {gHeadDbgF.innerHTML="loading..."}
} // OnUnloadFunc()

