function getParams(){
		var url="/AIR/CALENDAR/components/ajax.mjs";
		var frm=document.searchform;
		var om=frm.smonth.value;
		var oy=frm.syear.value;
		var d=new Date();
		var day="01";
		if(Current_Month==om){day=d.getDate();}
		Make_Calendar(oy,om);
		document.when.month.selectedIndex=om;
		om=parseInt(om)+1;
		if (om == "1") {
			 Days_in_Month[1] = ((oy % 400 == 0) || ((oy[0] % 4 == 0) && (oy[0] % 100 !=0))) ? 29 : 28;
		}
		if(om<10){om= "0" + om};
		var edate=oy + "-" + om + "-" + Days_in_Month[om-1];
		var sdate=oy + "-" + om + "-" + "01";
		var origin=document.searchform.origin.value;
		var dest=document.searchform.destination.value
		 url +="?sdate=" + escape(sdate) + "&edate=" + escape(edate) + "&origin=" + origin + "&destination=" + dest;
		ajaxRequest(url);
}

function ajaxRequest(url) {
	http.open("GET",url)
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function handleHttpResponse() {
//flush old array
cArr = new Array();
cheapFare=0;
if (http.readyState == 4) {
		if(http.status==200) {
			var response=http.responseText.replace("<!---->","");
			response=response.replace("<!--01-->","");
			if(response==''){oSrchide()}	
		  eval(response);
		}
}
/* to get Selected Airline */
		var el=document.airlineFilter.elements;
		var airlineCode='';
		for (var i=1; i<el.length; i++){
			if (el[i].checked){
				airlineCode = airlineCode +'|'+el[i].value;
			}
		}
writeCalendar(airlineCode);
}
/* To Make HTTP Object*/
function getHTTPObject() {
      var  http_request = false;
	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	  return http_request;
}
var http = getHTTPObject(); // We create the HTTP Object
/*==============================================================================================
	Push Fare in Calendar 
/*==============================================================================================*/
var date=new Date();var D=date.getDate();if(D<10){D="0"+D;}var M=date.getMonth();if(M<10){M="0"+M;}var Y=date.getFullYear();var cArr=new Array();var oDate;var oDiff;var oDiv;var cheapFare;var jcheapFare = 0;
function writeCalendar(code){
	cArr.sort(sortcArr, sortcArr);var isfareExist='';
	month=document.when.month.value;
	year=document.when.year.value;
	//alert(oDifference(new Date('2008',"0","16"),new Date(Y,M,D)))
	//Cheapest Fare
	jcheapFare = 0;
    	for(var j=0;j<cArr.length-1;j++){
               	var jDate=cArr[j].j.split("-");
                jDiff=oDifference(new Date(jDate[0],jDate[1]-1,jDate[2]),new Date(Y,M,D));
               	if(code.indexOf(cArr[j].f)!= -1){
                	cArr[j].s=true;
                }else{
                        cArr[j].s=false
                }
        	if(code.indexOf(cArr[j].f)!= -1 && cArr[j].s){
			if (jDiff>=-1){
				if(jcheapFare==0)
				 	jcheapFare = Math.round(cArr[j].e);
				if(Math.round(jcheapFare) > Math.round(cArr[j].e)){
					jcheapFare = Math.round(cArr[j].e);
				}
			}
               	}
	}
	//End Cheapest Fare
	for(var i=0;i<cArr.length-1;i++){
			isfareExist=document.getElementById(cArr[i].j).innerHTML;
			oDate=cArr[i].j.split("-");
			oDiff=oDifference(new Date(oDate[0],oDate[1]-1,oDate[2]),new Date(Y,M,D));
			if(code.indexOf(cArr[i].f)!= -1){
				cArr[i].s=true;
			}else{
			cArr[i].s=false
			}
			oDiv=document.getElementById(cArr[i].j);
//			alert(isfareExist+"::"+img)
			//if(isfareExist==img && cArr[i].s){
			if((isfareExist.indexOf('ajaxupdater.gif')!= -1) && cArr[i].s){
				if (oDiff>=-1){
					// cheapest fare hightlight start
					if(Math.round(jcheapFare)==Math.round(cArr[i].e)){
						var tmpid = 'highlight'+cArr[i].j;
						document.getElementById(tmpid).className='calfonthighlt';
					}
					// cheapest fare hightlight end
					oDiv.innerHTML='<div onMouseover=showDetails("'+i+'","'+cArr[i].j+'",true)>'+FormatNumber(Math.round(cArr[i].e))+'</div><div class="airlinename">'+cArr[i].k+'</div>';	
				}
			}
	//oSrchide();
	
	}
// code for calling ajax updater function start here
	FillByQuestionMark(year,month)
// code for calling ajax updater function start here
}


function oSrchide(){
var oSrc=document.getElementsByTagName("img");

	for(var j=0;j<=oSrc.length-1;j++){
		if(oSrc[j].className=='hidethis'){oSrc[j].className='hide'}
	}

}
/*==============================================================================================
	Airline Fitler
/*==============================================================================================*/
var ac='';
function objFilter(fName,isall){
	var e=document.forms[""+fName].elements;var ac='';
	
	if(!isall){e[0].checked=false}
	for (var i=1; i<e.length; i++){
			if(isall){
				e[i].checked=true;
			}
			if (e[i].checked){
				ac = ac +'|'+e[i].value;
			}
	}
	Make_Calendar(document.searchform.syear.value,document.searchform.smonth.value);
writeCalendar(ac)
}

function showDetails(index,cDiv,flag){
	
	var Div=	document.getElementById('showDetails');
	var str;

	var msg="Click to Search Flight For this day";
	if(flag){
	str='<div class="divlinkmain2"><div class="monnmsm6">'+cArr[index].k+'</div><div class="monnmsm5">'+cArr[index].a+'-'+cArr[index].b+'</div><div class="monnmsm5">Base Fare - Rs.'+FormatNumber(Math.round(cArr[index].c))+'<div class="monnmsm5">Taxes & Fees- Rs. '+FormatNumber(Math.round(cArr[index].d))+'</div><div class="monnmsm6">Total - Rs.   '+FormatNumber(Math.round(cArr[index].e))+'</div></div>';
	}else{
	str='<div class="divlinkmain2"><div class="monnmsm6"><br/><br/>'+msg+'</div><div class="monnmsm5"></div><div class="monnmsm5"></div><div class="monnmsm6"></div><div class="monnmsm7"></div></div>';
	}
	Div.innerHTML=str;
	Div.style.display='';
	Div.style.top=getTop(cDiv) +'px';
	Div.style.left=getLeft(cDiv) +'px';
}
function hideDetails (div){
	document.getElementById(div).style.display='none';
}
// get x and y postion for calender x
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;
}
  //end

// code for ajax updater start here

function FillByQuestionMark(Year, Month) {

   var First_Date = new Date(Year, Month, 1);
   var Heading = Header(Year, Month);
   var First_Day = First_Date.getDay() + 1;
   if (((Days_in_Month[Month] == 31) && (First_Day >= 6)) ||
       ((Days_in_Month[Month] == 30) && (First_Day == 7))) {
      var Rows = 6;
   }
   else if ((Days_in_Month[Month] == 28) && (First_Day == 1)) {
      var Rows = 4;
   } else {
      var Rows = 5;
   }
   var Day_Counter = 1;
   var Loop_Counter = 1;
   for (var j = 1; j <= Rows; j++) {
         for (var i = 1; i < 8; i++) {   
		 if ((Loop_Counter >= First_Day) && (Day_Counter <= Days_in_Month[Month])) {
             if(Day_Counter<10){Day_Counter='0'+Day_Counter;}
			 var Id_Month=parseInt(document.searchform.smonth.value)+1;
			 if(Id_Month<10){Id_Month='0'+Id_Month;}
			if ((Day_Counter == Today) && (Year == Current_Year) && (Month == Current_Month)) {
			//img src
				
			} else {
				var did = Year+'-'+Id_Month+'-'+Day_Counter;
				isfareExist=document.getElementById(did).innerHTML;
				oDiv=document.getElementById(did);
				if(isfareExist.indexOf('ajaxupdater.gif')!= -1 && cArr.length>1){
					oDiv.innerHTML='<div>?</div>';
				}
         	}
            Day_Counter++;    
         }
         Loop_Counter++;
      }
   }
}
// code for ajax updater end here



// submit form 

function showBlockDetails(cDiv)
{
	//onclick="submit('$cal_depart','$cal_return','$cal_ddate','$adt','$chd','$inf');"
	var bDiv=document.getElementById('showBlockDetails');
	var dep=document.searchform.origin.value;
	var arp=document.searchform.destination.value;
	var departDate=cDiv.split("-")
	//var url="/YT/wait_pages/waitpage_b.html?felxisearch=&type=O&origin="+dep+"&destination="+arp+"&ddate="+departDate[2]+"/"+departDate[1]+"/"+departDate[0]+"&class=ECO";
	

	var details='<div class="mainblock" style="Z-INDEX:103;"><table width="190" border="0" cellspacing="0" cellpadding="0"><tr><td></td><td colspan="2" class="topbg"><table width="180" border="0" align="right" cellpadding="0" cellspacing="0"><tr><td width="15">&nbsp;</td><td width="151" class="number">Passenger Details </td><td width="24"><a href=javascript:hideDetails("showBlockDetails");><img src="/images/AIR/calshop/closesign.gif" border="0" width="14" height="25" /></a></td></tr></table></td></tr><tr><td width="21" align="right" valign="top" style="padding-top:30px"><img src="/images/AIR/calshop/arrow.gif" width="20" height="25" /></td><td width="6" style="background-color:#ffffff;"><img src="/images/AIR/calshop/leftline.gif" width="1" height="131" /></td><td width="185" class="leftright"><form name="passDetails" action="/YT/wait_pages/waitpage_b.html" method="POST" name="form1" onsubmit="return isValidFlight()" style="margin:0px;"><input type=hidden name="felxisearch" value=""><input type=hidden name="type" value="O"><input type=hidden name="origin" value='+dep+'><input type=hidden name="destination" value='+arp+'><input type=hidden name="ddate" value='+departDate[2]+"/"+departDate[1]+"/"+departDate[0]+'><input type=hidden name="class" value="ECO"><table width="100%" height="131" border="0" align="left" cellpadding="0" cellspacing="0" style="background-color:#ffffff;"><tr><td width="60%" class="bodytext">Adults</td><td width="80" align="left"><select name="ADT" class="blockinput" id="adt"><option value="1">1 </option><option value="2">2 </option><option value="3">3 </option><option value="4">4 </option><option value="5">5 </option><option value="6">6 </option></select></td></tr><tr><td class="bodytext">Children (2-11) </td><td align="left"><select name="CHD" class="blockinput"><option value="0">0 </option><option value="1">1 </option><option value="2">2 </option><option value="3">3 </option><option value="4">4 </option></select></td></tr><tr><td class="bodytext">Infant (Under 2) </td><td align="left"><select name="INF" id="INF" class="blockinput"><option value="0">0 </option><option value="1">1 </option><option value="2">2 </option><option value="3">3 </option></select></td></tr><tr><td colspan="2" align="center" class="findflight"><input type="image" src="/images/AIR/calshop/findflight.gif" onclick=hideDetails("showBlockDetails"); /></td></tr></table></form></td></tr><tr><td colspan="3" valign="top"><img src="/images/AIR/calshop/bottomline.gif" width="211" height="5" /></td></tr></table></div>';
	
	
	bDiv.innerHTML=details;
	bDiv.style.display='';
	bDiv.style.top=getTop(cDiv) +'px';
	bDiv.style.left=getLeft(cDiv) +'px';
	
}
/* get param from home page */

function setDefaults() {
	var getURL =document.URL;
	if (getURL.indexOf('?')!= -1){
		getURL=getURL.split("&")
		gmonth=getURL[3].split("=");
		gorigin=getURL[1].split("=")
		gdest=getURL[2].split("=")
		gm=gmonth[1].split('-')
		document.searchform.month.value=gmonth[1]
		document.when.month.value=gm[1]-1;
		document.when.year.value=gm[0]
		document.searchform.smonth.value=gm[1]-1;
		document.searchform.syear.value=gm[0]
		document.searchform.origin.value=gorigin[1]
		document.searchform.destination.value=gdest[1]
	}
}

function isValidFlight()
{
	var CHD=document.passDetails.CHD.value;
	var ADT=document.passDetails.ADT.value;
	var INF=document.passDetails.INF.value;
	
	var totPax=parseInt(ADT)+parseInt(CHD);
	
	if(totPax>9)
	{
	alert("You are allowed a maximum of 9 passengers per Flight booking online.\nIf your group is larger than this, please call our call center.");
	return false;
	}
	if(INF>ADT)
	{
	alert("Total number of infant can't be greater than adult");
	return false;
	}

	else{return true;}
}

