//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


var dtCh= "/";
var minYear=1900;
var maxYear=2100;


var mmm = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

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;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

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 isDate(dtStr){

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	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 (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month " + strMonth )
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}


// Evgeni Pantchev (c) 2004


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function OnFocusTime (obj)
{
if (obj.value.length  = 5) 
	{
		obj.value =  obj.value.substring(0,2) + obj.value.substring(3)
	}

}

function ValidateTime(time) {
 	if (time.value.length == 4) 	
{
if (eval(time.value.slice(0, 2)) < 24 && eval(time.value.slice(2, 4)) < 60 )
{return true} else {time.value = '';alert("Invalid Time. Ignored!"); return false}
	}
else
{return false}
}


function OnBlurTime (obj)
{
	if (obj.value.length == 2) {obj.value = obj.value + "00"}

	if (obj.value.length  == 4 && ValidateTime(obj) )
	{
		obj.value = obj.value.substring(0, 2) + ':' +  obj.value.substring(2)
	}
	else {obj.value = '' }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


function OnFocusDate (obj)
{	
	
	if (obj.value.length  == 11) 
	{
		var mm =  obj.value.slice(3,6);
		var mm1;
		for (var i = 0; i <= 11; i++) 
			{ if (mm == mmm[i]) { mm1 = i+1}
			}
		if (mm1 < 10) { mm1 = '0' + mm1}
		obj.value =  obj.value.slice(0, 2) + mm1 + obj.value.slice(9,11)  	
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function FilterNumeric(obj) 
{
    if (window.event.keyCode < 48 || window.event.keyCode > 57)
        window.event.keyCode = 0
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function CallLookupDate(URL) 
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 113){window.open(URL, '','width=200,height=210,top=250,left=250') ;}
else {CRTAB(window.event);}

} 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function CallLookup(URL) 
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 113) {window.open(URL, '', 'width=690,height=410,top=250,left=250') ;}
else {CRTAB(window.event);}

} 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function CallLookupJob(URL) 
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 113){
window.open(URL, '','width=900,height=600,top=50,left=50,resizable=0') ;}
} 

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function OnBlurDate (obj)
{	

//	alert (daysInFebruary(2008));

	var curdate = new Date();
	var objmonth = curdate.getMonth() ;
	var objyear = curdate.getYear()	;


//~~~~~~~~~~~  dd  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	var dd	;


	if (obj.value.length  == 1 ) 
	{		
		dd = "0" + obj.value;
	}

	else
	{
		dd =  obj.value.slice(0, 2);
	}
	
	var daysInMonth = DaysArray(12);

//~~~~~~~~~~~  mmm  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	var month = objmonth

	if (obj.value.length  == 3 ) 
	{
		month = obj.value.slice(2,3);
		month = month-1
	};

	if (obj.value.length  > 3 ) 
	{
		month = obj.value.slice(2,4);
		month = month-1
	};


	var yy = new String(objyear);
	yy = yy.slice(2,4);

	if (obj.value.length  == 6 ) 
	{		
		yy =	obj.value.slice(4,6)
	};

	var yyyy ;
	if ( yy < 50 ) {yyyy = 20 + yy} else {yyyy = 19 + yy}
//	alert (yyyy +  ' days in Feb = ' +  daysInFebruary(yyyy));
	if (month==1 && dd > daysInFebruary(yyyy)) dd=0;

	if (obj.value.length  > 0  &&  month < 12 && dd > 0  && dd <= daysInMonth[month+1])
	{
		obj.value =  dd + '-' + mmm[month] + '-' + yyyy
	}
	else
	{
		if (obj.value.length > 0)
		{ alert ('Invalid Date Entered. Ignored!'); obj.value= '' }
	}


}

// -----------  callback ---------------------

   function ClientCallbackError(result, context){
      alert(result);
   }

    function ClientCallback_1(result){
        
        if (result=='(^)') {return false};
        
        result = result + '****'
        var splitString = result.split("*")        
    
        document.forms[0].elements[splitString[0] + '_textBox2'].title= splitString[1]; 
        document.forms[0].elements[splitString[0] + '_textBox2'].value = splitString[2];         
        if (splitString[2] == '<Invalid Entry>' ) {                 
        document.forms[0].elements[splitString[0] + '_textBox2'].style.background = '#FF6633' }
        else
        {document.forms[0].elements[splitString[0] + '_textBox2' ].style.background = 'white'}
        
        if (splitString[3] == 'Y') { document.forms[0].elements[splitString[0] + '_textBox1'].value = splitString[1] }
        
        //for awbprefix
        //if (splitString[0] == 'ep_JOB_AIR_ARLN_1') { document.forms[0].elements['ep_JOB_AIR_AWB_PREFX_textBox1'].value = splitString[4] }
    }
    
    function Onblr(CtrlID){
      //alert(CtrlID);
      var txt1 = CtrlID + '_textBox1';
      var txt2 = CtrlID + '_textBox2';
      
      var rez1 = document.forms[0].elements[txt1].value;
      var rez2 = document.forms[0].elements[txt2].title;
      var rez3 = document.forms[0].elements[txt2].value;
      
      if (rez3 == '<Invalid Entry>') {document.forms[0].elements[txt1].value = ''; document.forms[0].elements[txt2].value = ''; }
      if (rez1 !== rez2 && rez2 !== '') {document.forms[0].elements[txt1].value =  document.forms[0].elements[txt2].title ; }
                    
      document.forms[0].elements[txt2].style.background = 'white';
   }

// -----------  callback ---------------------
    function CRTAB(evt) {
       var keyCode = (evt) ? evt.keyCode : ((window.event) ? event.which : null);
       if(keyCode == 13){
         evt.keyCode=9;
         return true;
       }
       else return true;
     }      
     
     