/* Form airport lookup functionality start here */
var keyArray = new Array();
var valArray = new Array();
var stnCodeNames=new Array();
var load= new Image();
load.src="/images/indian-railways/loading.gif";

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}
var searchKey = getXmlHttpRequestObject();

function apLookup(){
	this.aArr=new Array();
}
apLookup.prototype.assignArray=function(apL){
	this.aArr=apL;
};

/* Code for ajax Call */
apLookup.prototype.ajaxRequest=function(key,input,div,country,match,show,len){
	if (searchKey.readyState == 4 || searchKey.readyState == 0) {
		searchKey.open("GET", '/indian-railways/train_stations.mjs?stn_code='+key+'&match_type='+match, true);
		searchKey.onreadystatechange = function(){
				if (searchKey.readyState == 4) {
					eval(searchKey.responseText)
					if(searchKey.responseText != null){ put(key.toLowerCase(),searchKey.responseText);}
					this.showLookup=new apSearch(stnCodeNames,input,div,country,match,show,len)
					this.showLookup.onTextChange(false)
				}
		}
		searchKey.send(null);
	}		
}

apSearch.prototype.keyUp=function(oEvent){
	var sKey=escape(this.apSearch.oText.value);
	this.ajax=new apLookup();
	oEvent=oEvent || window.event;
	var iKeyCode=oEvent.keyCode;
	if(iKeyCode==8 || iKeyCode==46){ this.apSearch.onTextChange(false);  }
	else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)){}
	else{
		if(sKey.length==3){
			var value = get(sKey.toLowerCase());
			if(value == null){
				this.apSearch.oText.className = 'loading';
				this.ajax.ajaxRequest(sKey,this.apSearch.oText,this.apSearch.oDiv,this.apSearch.oCountery,this.apSearch.oMatch,this.apSearch.show,this.apSearch.olen)
			}else{
				stnCodeNames=new Array();
				eval(value)
				this.showLookup=new apSearch(stnCodeNames,this.apSearch.oText,this.apSearch.oDiv,this.apSearch.oCountery,this.apSearch.oMatch,this.apSearch.show,this.apSearch.olen);
	            this.showLookup.onTextChange(false);
			}
		}else if(sKey.length>3){
			this.showLookup=new apSearch(stnCodeNames,this.apSearch.oText,this.apSearch.oDiv,this.apSearch.oCountery,this.apSearch.oMatch,this.apSearch.show,this.apSearch.olen);
			this.showLookup.onTextChange(false);
		}
		//this.apSearch.onTextChange(true); /* with apSearch */
		this.apSearch.oDiv.style.display='block';
	}
};

apLookup.prototype.getMatches=function(str,apL,show,type,len){
	if(!len){len=5}
	var ctr=0;
	var lookup='';
	for(var i in this.aArr){
			lookup=this.aArr[i].STC+" "+this.aArr[i].ST;
			if(lookup.toLowerCase().indexOf(str.toLowerCase()) != -1){
				var displayName=this.aArr[i].ST;
				var val = displayName;
				var displayCode=this.aArr[i].STC;
				var cval = displayCode;
				var sInp = str;
				var st = val.toLowerCase().indexOf(sInp.toLowerCase() );
				var output = val.substring(0,st)+""+val.substring(st, st+sInp.length) +""+val.substring(st+sInp.length)+"~"+cval;
				apL.push(output);
				ctr++;
			}
			if(ctr>12) break;		
	 }
	 var isAll=false
	 for(var j in apL){
		if(apL[j].toString().toLowerCase().indexOf('All Stations')!=-1 && !isAll){
		isAll=true;
		var tmpAllap=apL[j]
		delete apL[j];
		apL.unshift(tmpAllap);

		}
	}

	if(apL.length > len){
		document.getElementById('Class').style.display='none';
		document.getElementById('paxbox').style.display='none';
	}else{
		document.getElementById('Class').style.display='';
		document.getElementById('paxbox').style.display='';
	}

	if((searchKey.readyState == 4 && searchKey.responseText==99) || (stnCodeNames.length>0 && apL.length==0 && searchKey.readyState == 4)){
		apL.push("")
	}
};

function apSearch(aArr,oText,oDiv,country_code,match_type,show,len){
	this.oText=oText;
	this.oDiv=oDiv;
	this.oCountery=country_code
	this.oMatch=match_type
	this.show=show;
	this.olen=len;
	this.cur=-1;
	this.db=new apLookup();
	this.db.assignArray(aArr);
	this.oDiv.style.top=getTop(this.oText) +'px';
	this.oDiv.style.left=getLeft(oText) +'px';
	oText.onkeyup=this.keyUp;
	oText.onkeydown=this.keyDown;
	oText.apSearch=this;
	oText.onblur=this.hideairport;
}

function click(e){
	alert(e.button)
}

apSearch.prototype.hideairport=function(){
	this.apSearch.oDiv.style.visibility="hidden";
	document.getElementById('Class').style.display='';
	document.getElementById('paxbox').style.display='';
};


apSearch.prototype.selectText=function(iStart,iEnd){
	if(this.oText.createTextRange) /* For IE */	{
		var oRange=this.oText.createTextRange();
		oRange.moveStart("character",iStart);
		oRange.moveEnd("character",iEnd-this.oText.value.length);
		oRange.select();
	}
	else if(this.oText.setSelectionRange) /* For Mozilla */{
		this.oText.setSelectionRange(iStart,iEnd);
	}
	this.oText.focus();
};

apSearch.prototype.textComplete=function(sFirstMatch){
	if(this.oText.createTextRange || this.oText.setSelectionRange){
		var iStart=this.oText.value.length;
		this.selectText(iStart,sFirstMatch.length);
	}
};

apSearch.prototype.keyDown=function(oEvent){
	oEvent=window.event || oEvent;
	iKeyCode=oEvent.keyCode;
	switch(iKeyCode){
		case 9: //Tab key
			this.apSearch.tabNext();
			break;
		case 13: //Return key
			this.apSearch.returnthis();
			return false;
			break;
		case 27: //Esc key
			this.apSearch.escapethis();
			break;
		case 38: //Up arrow
			this.apSearch.moveUp();
			break;
		case 40: //Down arrow
			this.apSearch.moveDown();
			break;
		}
};

var scode= document.getElementById('railbookingform').src_stn_code;
var dcode= document.getElementById('railbookingform').dest_stn_code;

	apSearch.prototype.tabNext=function(){
	if(this.oDiv.childNodes.length>0 && this.cur<(this.oDiv.childNodes.length-1)){
		++this.cur;
		for(var i=0; i<this.oDiv.childNodes.length; i++){
			if(i==this.cur){
				if(this.cur==0){
					this.oText.value=this.oDiv.childNodes[i].innerHTML.stripHTML();
					for (var j=0; j<stnCodeNames.length; j++){
						if(this.oDiv.childNodes[i].innerHTML == stnCodeNames[j].ST){
							if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[i].STC;}
						}
					}
				}else{
					this.oText.value=this.oDiv.childNodes[i-1].innerHTML.stripHTML();
					for (var j=0; j<stnCodeNames.length; j++){
						if(this.oDiv.childNodes[i-1].innerHTML == stnCodeNames[j].ST){
							if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[j].STC;}
						}
					}
				}
				this.oDiv.innerHTML="";
				this.oDiv.style.visibility="visible";
			}else{}
		}
	}
};

apSearch.prototype.moveDown=function(){
	if(this.oDiv.childNodes.length>0 && this.cur<(this.oDiv.childNodes.length-1)){
		++this.cur;
		for(var i=0;i<this.oDiv.childNodes.length;i++){
			if(i==this.cur){
				this.oDiv.childNodes[i].className="over";
				this.oText.value=this.oDiv.childNodes[i].innerHTML.stripHTML();
				for (var j=0; j<stnCodeNames.length; j++){
					if(this.oDiv.childNodes[i].innerHTML == stnCodeNames[j].ST){
						if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[j].STC;}
					}
				}
			}else{
				this.oDiv.childNodes[i].className="";
			}
		}
	}
};

apSearch.prototype.moveUp=function(){
	if(this.oDiv.childNodes.length>0 && this.cur>0){
		--this.cur;
		for(var i=0;i<this.oDiv.childNodes.length;i++){
			if(i==this.cur){
				this.oDiv.childNodes[i].className="over";
				this.oText.value=this.oDiv.childNodes[i].innerHTML.stripHTML();
				for (var j=0; j<stnCodeNames.length; j++){
					if(this.oDiv.childNodes[i].innerHTML == stnCodeNames[j].ST){
						if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[j].STC;}
					}
				}
			}else{
				this.oDiv.childNodes[i].className="";
			}
		}
	}
};


apSearch.prototype.escapethis = function (){
		document.getElementById('Class').style.display='';
		document.getElementById('paxbox').style.display='';
		this.oText.value="";
		this.oDiv.innerHTML="";
		this.oDiv.style.visibility="hidden";
};

apSearch.prototype.returnthis = function (){
	if(this.oDiv.childNodes.length>0 && this.cur<(this.oDiv.childNodes.length-1)){
		++this.cur;
		for(var i=0; i<this.oDiv.childNodes.length; i++){
			if(i==this.cur){
				if(this.cur==0){
					this.oText.value=this.oDiv.childNodes[i].innerHTML.stripHTML();
					for (var j=0; j<stnCodeNames.length; j++){
						if(this.oDiv.childNodes[i].innerHTML == stnCodeNames[j].ST){
							if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[j].STC;}
						}
					}
				}else{
					this.oText.value=this.oDiv.childNodes[i-1].innerHTML.stripHTML();
					for (var j=0; j<stnCodeNames.length; j++){
						if(this.oDiv.childNodes[i-1].innerHTML == stnCodeNames[j].ST){
							if(this.oText.id=='origin'){scode.value = stnCodeNames[j].STC;}else{dcode.value = stnCodeNames[j].STC;}
						}
					}

				}
				this.oDiv.innerHTML="";
				this.oDiv.style.visibility="hidden";
				if(this.oText.id=='origin') document.getElementById('destination').focus();
				document.getElementById('Class').style.display='';
				document.getElementById('paxbox').style.display='';
			}else{
				//this.oDiv.childNodes[i].className="";
			}
		}
	}
};

apSearch.prototype.positionairport=function(){
	var oNode=this.oText;
	var x=0,y=oNode.offsetHeight;
	while(oNode.offsetParent && oNode.offsetParent.tagName.toUpperCase() != 'BODY'){
		x+=oNode.offsetLeft;
		y+=oNode.offsetTop;
		oNode=oNode.offsetParent;
	}
	x+=oNode.offsetLeft;
	y+=oNode.offsetTop;
	this.oDiv.style.top=y+"px";
	this.oDiv.style.left=x+"px";
};

apSearch.prototype.onTextChange=function(bTextComplete){
	var txt=this.oText.value;
	var oThis=this;
	this.cur=-1;
	if(txt.length<3){ 
		document.getElementById('Class').style.display=''; 
		document.getElementById('paxbox').style.display='';
	}

	if(txt.length >= 3){
		while(this.oDiv.hasChildNodes())
		this.oDiv.removeChild(this.oDiv.firstChild);

		var aStr=new Array();
		var stns = new Array();
		this.db.getMatches(txt,aStr,this.show,this.oText,this.olen)
		var tmpStr = new Array();
		for(x=0; x<aStr.length; x++){
			tmpStr.push(aStr[x]);
			for(y=x+1; y<aStr.length; y++){
				if(aStr[x] == aStr[y]) tmpStr.pop();
			}
		}
		aStr=tmpStr;
		if(!aStr.length) {this.hideairport; return;}
		if(bTextComplete) this.textComplete(aStr[0]);
		this.positionairport();
		for(i in aStr){
			var oNew=document.createElement('div');
			this.oDiv.appendChild(oNew);
			oNew.onmouseover=
			oNew.onmouseout=
			oNew.onmousedown=function(oEvent){
				oEvent=window.event || oEvent;
				oSrcDiv=oEvent.target || oEvent.srcElement;
				if(oEvent.type=="mousedown"){
					oThis.oText.value=this.innerHTML.stripHTML();
					for (j in aStr){
						stns = aStr[j].split('~');
						if(stns[0].toString().toLowerCase()==this.innerHTML.toString().toLowerCase()){
							if(oThis.oText.id=='origin'){ scode.value = stns[1];}else{dcode.value = stns[1];}
						}
					}
					if(oThis.oText.id=='origin') document.getElementById('destination').focus();
				}
				else if(oEvent.type=="mouseover"){
					this.className="over";
				}
				else if(oEvent.type=="mouseout"){
					this.className="";
				}
				else{
					this.oText.focus();
				}
			};
			var stnStr = aStr[i].split('~');
			oNew.innerHTML=stnStr[0]; 
			//Remvoe Junk Data for Prototype.js used on flex searc page 
			if(oNew.innerHTML.substring(0,8)=="function"){
			this.oDiv.removeChild(oNew);
			};
		}
		this.oText.className='';
		this.oDiv.style.visibility="visible";
	}else{
		this.oDiv.innerHTML="";
		this.oDiv.style.visibility="hidden";
		document.getElementById('Class').style.display='';
		document.getElementById('paxbox').style.display='';
	}
};

String.prototype.stripHTML = function()
{
	  var matchTag = /<(?:.|\s)*?>/g;
	  return this.replace(matchTag, "");
};

function getLeft(obj)
{
	if ('string' == typeof obj)
	obj = document.getElementById(obj);
	var x = 0;
	while (obj != null)
	{
	x += obj.offsetLeft;
	obj = obj.offsetParent;
	}
	return x-580;
}

function getTop(obj){
	if ('string' == typeof obj)
	obj = document.getElementById(obj);
	var y = 0;
	while (obj != null)
	{
	y += obj.offsetTop;
	obj = obj.offsetParent;
	}
	return y-485;
}

function findIt( key ){
	var result = (-1);
	for( var i = 0; i < this.keyArray.length; i++ ){
		if( this.keyArray[ i ] == key ){
			result = i;
			break;
		}
	}
	return result;
}

function put( key, val ){
	var elementIndex = this.findIt( key );

	if( elementIndex == (-1) ){
		this.keyArray.push( key );
		this.valArray.push( val );
	}
	else{
		this.valArray[ elementIndex ] = val;
	}
}

function get( key ){
	var result = null;
	var elementIndex = this.findIt( key );

	if( elementIndex != (-1) ){
		result = this.valArray[ elementIndex ];
	}

	return result;
}


/* Form airport lookup functionality end here */

var dtCh= "/";
var minYear=1900;
var maxYear=2100;


function isValidateTrain(formName,obDate){
	var a=document.forms[""+formName].origin.value;
	var d =document.forms[""+formName].destination.value;

	var aStName = a.split('-');
	var dStName = d.split('-');
	var ADT=document.forms[""+formName].adt.value;
	var CHD=document.forms[""+formName].chd.value;
	var SCM=document.forms[""+formName].srctzn.value;
	var SCW=document.forms[""+formName].srctnw.value;
	var cl = document.forms[""+formName].Class;
	var tk =document.forms[""+formName].dest_stn_code.value;

	var errorStr='<ul>';
	var fieldStr='';
	var isError=0;

	var totPax=parseInt(ADT)+parseInt(CHD)+parseInt(SCM)+parseInt(SCW);
	var isvalidD= isDate(obDate)
	if(!isvalidD) return false;

	var obDate=obDate.split('/');
	var obDay=obDate[0];
	var obYear=obDate[2];
	var obMonth=(obDate[1]-1);
	var objDt=daysElapsed(new Date(obYear,obMonth,obDay),new Date());
	var curDate = new Date();
	var curDt = curDate.getDate(); 
	var curMt = curDate.getMonth(); 
	
	if(objDt>2 && document.forms[""+formName].tquota.checked){
		errorStr += '<li>For Tatkal bookings the date of journey should be within 2 days from today.</li>';
		document.getElementById('tquota_l').style.color='#FF0000';
		document.forms[""+formName].tquota.checked=false;
		isError=1;
	}else if((document.forms[""+formName].tquota.checked) && (cl.value=='1A' || cl.value=='FC' || cl.value=='2S')){
		errorStr += '<li>Tatkal booking is not allowed for '+cl.options[cl.selectedIndex].text+'</li>';
		document.getElementById('tquota_l').style.color='#FF0000';
		document.forms[""+formName].tquota.checked=false;
		isError=1;
	}else{
		if(document.forms[""+formName].tquota.checked){document.forms[""+formName].quota.value='CK';}
		else{document.forms[""+formName].quota.value='GN';}
	}

	var today=new Date();
	var D=today.getDate();if(D<10){D="0"+D;}
	var M=today.getMonth();if(M<10){M="0"+M;}
	var Y=today.getFullYear();

	if(a==''){
		errorStr += '<li>Please select the departure station.</li>';
		document.getElementById('origin_l').style.color='#FF0000';
		isError=1;
	}else{document.getElementById('origin_l').style.color='#1A93A5';}

	if(d==''){
		errorStr += '<li>Please select the destination station.</li>';
		document.getElementById('destination_l').style.color='#FF0000';
		isError=1;
	}else{document.getElementById('destination_l').style.color='#1A93A5';}


	if(a!='' && a.length<3){
		errorStr += '<li>Please select the origin station name/code.</li>';
		document.getElementById('origin').style.color='#FF0000';
		isError=1;
	}

	if(d!='' && d.length<3){
		errorStr += '<li>Please select the destination station name/code.</li>';
		document.getElementById('destination').style.color='#FF0000';
		isError=1;
	}

	if(a!=''){
		if(a.toLowerCase().indexOf('all stations') != -1){}
		else if(a.toLowerCase().indexOf('(') != -1){}
		else{ document.forms[""+formName].src_stn_code.value=a; }
	}

	if(d!=''){
		if(d.toLowerCase().indexOf('all stations') != -1){}
		else if(d.toLowerCase().indexOf('(') != -1){}
		else{ document.forms[""+formName].dest_stn_code.value=d; }
	}

	var ac=document.forms[""+formName].src_stn_code.value;
	var dc =document.forms[""+formName].dest_stn_code.value;
	var paxtoggle = false;
	if( (a!='' && d!='') && (d==a || dc==ac || aStName[0] == dStName[0]) ){
		errorStr += '<li>Please select a destination that is different from the departure station.</li>';
		document.getElementById('destination_l').style.color='#FF0000';
		isError=1;
	}

	if(document.forms[""+formName].Class.value==''){
		errorStr += '<li>Please select the seating class.</li>';
		document.getElementById('Class_l').style.color='#FF0000';
		isError=1;
	}else{document.getElementById('Class_l').style.color='#1A93A5';}

	if(objDt<0 || objDt>90){
		errorStr += '<li>Please select a valid departure date that is within 90 days of today.</li>';
		document.getElementById('tddate_l').style.color='#FF0000';
		isError=1;
	}else{document.getElementById('tddate_l').style.color='#1A93A5';}

	if(totPax<1){
		errorStr += '<li>Please specify the passenger details.</li>';
		document.getElementById('adtlabel').style.color='#FF0000';
		document.getElementById('chdlabel').style.color='#FF0000';
		document.getElementById('scmlabel').style.color='#FF0000';
		document.getElementById('scwlabel').style.color='#FF0000';
		paxtoggle = true;
		isError=1;
	}else{
		document.getElementById('adtlabel').style.color='#1A93A5';
		document.getElementById('chdlabel').style.color='#1A93A5';
		document.getElementById('scmlabel').style.color='#1A93A5';
		document.getElementById('scwlabel').style.color='#1A93A5';
	}

	if(totPax>6){
		errorStr += '<li>You can book tickets for a maximum of 6 passengers. If your group size is more, please break-up the booking into two.</li>';
		document.getElementById('adtlabel').style.color='#FF0000';
		document.getElementById('chdlabel').style.color='#FF0000';
		document.getElementById('scmlabel').style.color='#FF0000';
		document.getElementById('scwlabel').style.color='#FF0000';
		isError=1;
	}else{
		if(!paxtoggle) {
			document.getElementById('adtlabel').style.color='#1A93A5';
			document.getElementById('chdlabel').style.color='#1A93A5';
			document.getElementById('scmlabel').style.color='#1A93A5';
			document.getElementById('scwlabel').style.color='#1A93A5';
		}
	}

	errorStr += '</ul>'
	if(isError>0){
		inlineMsg('errormsg',fieldStr,errorStr,2);
		return false;
	}else{
		document.forms[""+formName].origin.value = aStName[0].replace(/^\s+|\s+$/g,"");
		document.forms[""+formName].destination.value = dStName[0].replace(/^\s+|\s+$/g,"");
		return true; 
	}
}

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")
		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
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var 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){
	 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 daysElapsed(date1,date2){
 var difference =
        Date.UTC(date1.getYear(),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(date2.getYear(),date2.getMonth(),date2.getDate(),0,0,0);
   return  difference=(difference)/(1000*60*60*24);
}


// START OF ERROR MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 10;

function inlineMsg(target,formelements,errorString,autohide) {
	var msg;
	var msgcontent;
	msg = document.getElementById('errormsg');
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;

	msgcontent = document.getElementById('errormsgcontent');
	msgcontent.innerHTML = errorString;
	msg.style.display = 'block';
	var msgheight = msg.offsetHeight;
	var targetdiv = document.getElementById(target);
	clearInterval(msg.timer);
	msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
	if(!autohide) autohide = MSGHIDE;  
	window.setTimeout("hideMsg()", (autohide * 20000));
}

function hideMsg(msg) {
  var msg = document.getElementById('errormsg');
  if(!msg.timer) msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
}

function fadeMsg(flag) {
  if(flag == null) flag = 1;
  var msg = document.getElementById('errormsg');
  var value;
  if(flag == 1) value = msg.alpha + MSGSPEED;
  else value = msg.alpha - MSGSPEED;

  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';

  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}


function hidethis(event){
	var key=0;
	if (!event) var event = window.event;
	if(!event.which) key = event.keyCode;
	else key = event.which;
	if(key==9) {
		document.getElementById('YTContainer').style.display='none';
		document.getElementById('pax2').style.display='';
		document.getElementById('pax3').style.display='';
		document.getElementById('pax4').style.display='';
	}
}



function enterAlpha(e)
{
	var key=0;
	if (!e) var e = window.event;
	// e gives access to the event in all browsers
	if(!e.which) key = e.keyCode; // This is used store the keycode(IE Only) 
	else key = e.which; // This is used store the keycode(Netscape Only)
     if((key>=65)&&(key<=90)||(key>=97)&&(key<=122)||key==8||key==9||key==32)
     {
        key=key;
        return true;
     }
     else
     {
       key=0;
       return false;
     }
}

function keyPressHandler(e) {
      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc)
         alert("You had escaped the process. Please refresh the window and try again...")
}
