
/*Call Web Service Zone*/
/*===== Parameter for call web service ==========*/
var current_cell=null;

function clearHeader(){
var TabDate = document.getElementById("TabDate");
	if(TabDate!=null)
	{
			for(var i=TabDate.rows.length-1;i>=0;i--)
			{
				TabDate.deleteRow(TabDate.rows[i])
			}
	}
}


function CreateAjaxControl()
{
var xmlHttp=null;
try
  {  
  //alert(xmlHttp)
    //Firefox, Opera 8.0+, Safari  
     xmlHttp=new XMLHttpRequest();  
     return xmlHttp;
  }
catch (e)
  {  
  try
    {    
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
      return xmlHttp;
    }
  catch (e)
    {    try
      {      
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
		return xmlHttp;
      }
    catch (e)
      {      
         alert("Your browser does not support AJAX!");      
         return null;      
      }    
    } 
  } 
}

var ControlName;
var CurrentRoute=0;


function initialcalendar()
{

 //Create Calendar 1
  CalendarCallWs("?df=1&i=1&type=datefrom","divFrom",1);  
 //Create Calendar 2
  CalendarCallWs("?df=0&i=1&type=dateto&nm=1","divTo",0);
}
function monthAct(m,y,ctrl)
{
//('5','2008','ctr_datefrom');
 //CalendarCallWs("?df=1&i=1&type=datefrom","divFrom");
 var hdd_defCell=document.getElementById("hdd_defCell");
 switch(ctrl)
 {
  case "ctr_datefrom":
		CalendarCallWs("?df=0&i=1&type=datefrom"+"&m="+m+"&y="+y,"divFrom",0);
		CalendarCallWs("?df=0&i=1&type=dateto&nm=1&m="+m+"&y="+y,"divTo",0);
		break;
  case "ctr_dateto":
		if(lessthanfrom(m,y)==true) return; 
		CalendarCallWs("?df=0&i=1&type=dateto&m="+m+"&y="+y,"divTo",0);
		break;
 }
}
function lessthanfrom(m,y)
{
//yyyymmdd
 var hdd_ctr_none="";
 var hdd_ctr_datefrom = document.getElementById("hdd_ctr_datefrom");
 var valdatefrom = hdd_ctr_datefrom.value;
 
 var mm=m.toString();
 if(m.toString().length<=1){mm="0"+m.toString();}
 //alert(parseInt(y.toString()+mm+"01"))
 //alert(valdatefrom);
 //alert(parseInt(valdatefrom)<= parseInt(y.toString()+mm+"01"))
 if(parseInt(valdatefrom)>= parseInt(y.toString()+mm+"01"))
 {
	return true;
 }
 else
 {
   return false;
 }
}

//yyyymmdd
function showschedule(ctrname,celltext,cellname)
{

//function showschedule('datefrom','20080423','ctr_datefrom_20080423')
 var hdd_defCell=document.getElementById("hdd_defCell");
 if(hdd_defCell!=null)
 {	
	var cc_Cell=document.getElementById(hdd_defCell.value);
	if(cc_Cell!=null)
	{
	  //alert(cc_Cell);
	   if(hdd_defCell.value!=cellname)
	   {
	    //alert(hdd_defCell.value)
	    
	    //New Cell Select
	    
	    //Old Cell
	    cc_Cell.className="calendar_DayStyle";
	    cc_Cell.style.backgroundColor="";	    
	    //
	    //Call Ws
	    //alert(dvTable.innerHTML);
	    //alert(Origin+","+Distination);
	    //setInterval(animation,50);
	     
	   }	   
	}
	 var selcell = document.getElementById(cellname);
	    current_cell=cellname;
	    hdd_defCell.value=cellname;
	    selcell.className="calendar_dateselect";
	   //alert(cc_Cell);
		DateFrom=celltext;
		
		currentdate=celltext;
		
		DateTo="";
		animation();
		CallWs("?act=Table&ORG="+Origin+"&DEST="+Distination+"&DateFrom="+DateFrom+"&DateTo="+DateTo,"dvTable");	
	
 }
 showBelow(celltext);

}
function showBelow(ccdate)
{
 var dvCurrenDate = document.getElementById("dvCurrenDate");
  dvCurrenDate.innerHTML="This below schedule for "+mydateformat(ccdate)+"";  
					  
}
function animation()
{
  var dvTable=document.getElementById("dvTable");	    
	    dvTable.innerHTML="<img src='loading.gif' border=0 />";
}
function CalendarCallWs(parameter,controls,isinitial)
{
var xmlHttp = CreateAjaxControl();
var ControlName= controls;
var WS_URL=window.location.href.replace(window.location.href.split('/')[window.location.href.split('/').length-1],'uxcCalendar.aspx');
WS_URL=WS_URL+parameter;

var objControls =  document.getElementById(ControlName);
//if(objControls.innerHTML!=""){objControls.innerHTML="<img src='loading.gif' border=0 />";}

	if(xmlHttp!=null)
	{ 
		xmlHttp.onreadystatechange=function(controls)
		{
			if(xmlHttp.readyState==4)
			{									
				objControls.innerHTML="";
				if(xmlHttp.responseText=="")
				{
					objControls.innerHTML="<div class='schedule_not_found'>Schedule date not found </div>";				
				}	
				else
				{
					var content = xmlHttp.responseText									
					objControls.innerHTML=content;	
					if(isinitial==1){
					 showinitial_schedule();
					}								
				}			
			}
		}		
		
		xmlHttp.open("GET",WS_URL,true);
		xmlHttp.send(null);
	}
}
function showinitial_schedule(){
var hdd_defCell=document.getElementById("hdd_defCell");
var defDay = hdd_defCell.value;
var cDefDay = defDay.split("_");
var DateFrom=cDefDay[2];
currentdate=cDefDay[2];
var DateTo=''; 
  
  CallWs("?act=Table&ORG="+Origin+"&DEST="+Distination+"&DateFrom="+DateFrom+"&DateTo="+DateTo,"dvTable");	
}


