/*=============== Date Format================================*/
/*Date Format*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}
/*=============== Date Format================================*/
/*Call Web Service Zone*/
/*===== Parameter for call web service ==========*/

//var Origin='';
var Dest='';

var Origin='';
var Distination='';
var IsLoadFromFile=false;
var currentdate='';

var ServiceDate = '20090501';
var isCheckServiceDate=false;

/*var Cdate = new Date()
var mm=Cdate.getMonth();
var dd=Cdate.getDate();
var yy =Cdate.getUTCFullYear();

if(dd.toString().length<2){dd="0"+dd.toStrng();}
if(mm.toString().length<2){mm="0"+mm.toString();}
*/
//var DateFroms = yy.toString()+mm.toString()+dd.toString();
//var dtFlightFrom=''//'20081002'//DateFroms;
//alert(DateFroms)
/*
Object table 
- Generate Table Rows
- Generate Table Cells
*/


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 CallWs(parameter,controls)
{
var xmlHttp = CreateAjaxControl();
var ControlName= controls;
//For my local client
//var WS_URL="http://tossapon/FlightsSchedules/AAS/AASSchedule.aspx";

//for flywithstyle
var WS_URL=window.location.href.replace(window.location.href.split('/')[window.location.href.split('/').length-1],'AASSchedule.aspx');

WS_URL=WS_URL+parameter;




var objControls =  document.getElementById(ControlName);
//if(controls=="dvTable")objControls.innerHTML="<img src='loading.gif' border=0 />";
//alert(controls);
//if(objControls.innerHTML!=""){objControls.innerHTML="<img src='loading.gif' border=0 />";}

//objControls.innerHTML="<img src='loading.gif' border=0 />";

//alert(WS_URL)
	if(xmlHttp!=null)
	{ 
	if(controls=="dvTable")objControls.innerHTML='';
		xmlHttp.onreadystatechange=function(controls)
		{
			if(xmlHttp.readyState==4)
			{		
			
				//var objControls =  document.getElementById(ControlName);
				objControls.innerHTML='';
						
				if(xmlHttp.responseText=="")
				{
				     var dvCurrenDate = document.getElementById("dvCurrenDate");
					dvCurrenDate.innerHTML="This below schedule for "+mydateformat(currentdate)+"";
					objControls.innerHTML="<br /><div class='schedule_not_found'>Schedule date not found</div>";
					//var dvTable=document.getElementById("dvTable");
					//dvTable.innerHTML="";
				}	
				else
				{
					if(objControls.id=="dvTable"){objControls.innerHTML="";}
					
				   var dvCurrenDate = document.getElementById("dvCurrenDate");
					 dvCurrenDate.innerHTML="This below schedule for "+mydateformat(currentdate)+"";
					 
					
		
					 
					// alert(currentdate);
					 
					var content = xmlHttp.responseText				
					objControls.innerHTML=content;
					//alert(content);
					if(ControlName=="dvHeader")
					{

					    var  objH=document.getElementById("hddinitDate");
					     if(objH!=null)
					     {
					         schedules(CurrentRoute,"",objH.value.split(',')[0],objH.value.split(',')[1],0);
					     }
					}
				}			
					
				
										
			}
		}		
		//alert(WS_URL);
		xmlHttp.open("GET",WS_URL,true);
		xmlHttp.send(null);
	}
}

function initpage()
{

	//dvFullRoute
	//Origin='';
	//Dest='';
	//schedules(0,'','','',0)
	//CallWs("?act=Header&ORG=&DEST=&DateFrom&DateTo","dvHeader");
	//CallWs("?act=Table&ORG=&DEST=&DateFrom&DateTo","dvTable");
    //startList();    
}
//alert(window.location.search.split('&')[0].split('=')[0].replace('?','').toUpperCase());
//First time from parameter...

function schedules(Currentid,FullName,DateFrom,DateTo,isVisible){

var tmpFile = '';
var xmlFooter='';//'Van2Vic1.xml';
var xslFooter='';//'Van2Vic1.xsl';
CurrentRoute=Currentid;
/*if(IsLoadFromFile==true){
return 0;
}
else{
if(isVisible==2) IsLoadFromFile=true;
isVisible=1;
}*/


var  submenu = document.getElementById("submenu");

if(submenu!=null){}
	if(isVisible==1){submenu.className='';}

isCheckServiceDate=false;
 switch(Currentid)
 {
	case 0:Origin='ACI';Distination='GCI'; tmpFile='Van2Vic1';FullName='Alderney to Guernsey';break;
	case 1:Origin='ACI';Distination='SOU'; FullName='Alderney to Southampton '; tmpFile='Rich2Vic1';break;
	case 2:Origin='BRS';Distination='GCI'; FullName='Bristol to Guernsey'; tmpFile='Sech2Nana1'; break;
	case 3:Origin='DNR';Distination='GCI'; FullName='Dinard to Guernsey '; tmpFile='Sech2jer1';break;
	
	case 4:Origin='GCI';Distination='ACI'; FullName='Guernsey to Alderney '; tmpFile='Sech2Rich1'; break;
	case 5:Origin='GCI';Distination='JER'; FullName='Guernsey to Jersey '; tmpFile='';break;
	case 6:Origin='GCI';Distination='BRS'; FullName='Guernsey to Bristol '; tmpFile='Nana2Rich1';break;
	case 7:Origin='GCI';Distination='DNR'; FullName='Guernsey to Dinard '; tmpFile='Van2Nana1';break;
	
	case 8:Origin='GCI';Distination='STN'; FullName='Guernsey to London Stansted '; tmpFile='Sech2Rich1'; break;
	case 9:Origin='GCI';Distination='MAN'; FullName='Guernsey to Manchester '; tmpFile='';break;
	case 10:Origin='GCI';Distination='LGW'; FullName='Guernsey to London Gatwick';  tmpFile='Nana2Rich1';break;
	case 11:Origin='JER';Distination='GCI'; FullName='Jersey to Guernsey '; tmpFile='Van2Nana1';break;
	
	
	case 12:Origin='LGW';Distination='GCI';FullName='London Gatwick to Guernsey '; tmpFile='Sech2Rich1'; break;
	case 13:Origin='STN';Distination='GCI';FullName='London Stansted to Guernsey '; tmpFile='';break;
	case 14:Origin='MAN';Distination='GCI';FullName='Manchester to Guernsey '; tmpFile='Nana2Rich1';break;
	case 15:Origin='SOU';Distination='ACI';FullName='Southampton to Alderney '; tmpFile='Van2Nana1';break;
	//new update
	case 16:Origin='EMA';Distination='GCI';FullName='East Midlands to Guernsey '; tmpFile='Sech2Rich1';isCheckServiceDate=true; break;
	case 17:Origin='GCI';Distination='EMA';FullName='Guernsey to East Midlands '; tmpFile='';isCheckServiceDate=true;break;
	case 18:Origin='STN';Distination='JER';FullName='London Stansted to Jersey '; tmpFile='Nana2Rich1';isCheckServiceDate=true;break;
	case 19:Origin='JER';Distination='STN';FullName='Jersey to London Stansted '; tmpFile='Van2Nana1';isCheckServiceDate=true;break;
	case 20:Origin='GCI';Distination='GNB';FullName='Guernsey to Grenoble'; tmpFile='';break;
	case 21:Origin='GNB';Distination='GCI';FullName='Grenoble to Guernsey'; tmpFile='';break;
	
	
	
	//default:Origin='ACI';Distination='GCI';FullName='Alderney to Guernsey'; tmpFile='Van2Nana1';break;
 }

//var ServiceDate = '20090501';
//var isCheckServiceDate=false;

//alert(Origin+','+Distination);
    ///alert(currentdate);

	 var dvFullRoute = document.getElementById("dvFullRoute");
			dvFullRoute.innerHTML="<IMG src='images/I/yellowHeader.gif' border=0 />"+FullName;
			
			
			if(isCheckServiceDate==true) 
					{
						var CurrDate = new Date();
						var txtDate = dateFormat(CurrDate,"yyyy")+dateFormat(CurrDate,"mm")+dateFormat(CurrDate,"dd");

						if( parseInt(txtDate) < parseInt(ServiceDate))
						{
						   dvFullRoute.innerHTML=dvFullRoute.innerHTML+" "+"<font style='FONT-SIZE: 11px; FONT-WEIGHT: normal ; COLOR: red; FONT-FAMILY: Tahoma, Arial, sans-serif, verdana'> Service starts on 01 May 09</font>";
						}
					}
			
			
			//dvFullRoute.innerHTML+="<br /><div class='schedule_showbelow'>This below schedule for </div>"
     var tdCheckIn=document.getElementById("tdCheckIn");
  
		//check date 
		//var ServiceDate = '20090501';
		//var isCheckServiceDate=false;
	
	
		 tdCheckIn.innerHTML="Check-in 30 minutes minimum. ";
     var dvTable=document.getElementById("dvTable");
		 dvTable.innerHTML="";

/*if((Origin!='')&&(Distination!='')&&(DateFrom=='')&&(DateFrom==''))
{	
	CallWs("?act=Header&ORG="+Origin+"&DEST="+Distination+"&DateFrom&DateTo","dvHeader");   	 
}*/
/*if((Origin!='')&&(Distination!='')&&(DateFrom!='')&&(DateTo!=''))
{
	//alert("?act=Table&ORG="+Origin+"&DEST="+Distination+"&DateFrom="+DateFrom+"&DateTo="+DateTo);

	CallWs("?act=Table&ORG="+Origin+"&DEST="+Distination+"&DateFrom="+DateFrom+"&DateTo="+DateTo,"dvTable");	
}*/
 
//var hdd_defCell=document.getElementById("hdd_defCell");
//alert(hdd_defCell);
initialcalendar();
	
}
var objHoldSel=null;
//============ Header Action ========================//

function DateHeaderOver(obj){
 obj.className="DateHeaderMouseOver";

}
function DateHeaderOut(obj){
 obj.className='DateHeader';
}
function DateHeaderOut2(){

event.srcElement.className='DateHeader';
}
function HoldingDate(obj){
if(objHoldSel!=null){
objHoldSel.className='DateHeader';
objHoldSel.onmouseout=DateHeaderOut2;
}

obj.className='DateHeaderMouseOver';
objHoldSel=obj;
obj.onmouseout=function(){};
}
function myholding(obj){
}


function FindByDate(DateFrom,DateTo,obj){

var tblHeader=document.getElementById("tblHeader");
if(tblHeader!=null)
{

 if(tblHeader.rows.length>0)
 {
  if(tblHeader.rows[0].cells[0].className=="DateHeaderMouseOver")
  {
     tblHeader.rows[0].cells[0].className="DateHeader";
     tblHeader.rows[0].cells[0].onmouseout=DateHeaderOut2;
     //alert(tblHeader.rows[0].cells[0].className);
  }
 }
}

HoldingDate(obj);
CallWs("?act=Table&ORG="+Origin+"&DEST="+Distination+"&DateFrom="+DateFrom+"&DateTo="+DateTo,"dvTable");	
//alert(DateFrom+","+DateTo);
var dvTable=document.getElementById("dvTable");
					dvTable.innerHTML="";
}
function mydateformat(tcurrentdate){
//20080423
//alert(currentdate);
//tcurrentdate="20081108"
 var yy=parseInt(tcurrentdate.substring(0,4));
 var mm=parseInt(tcurrentdate.substring(4,6));
 var dd=parseInt(tcurrentdate.substring(6,8));

 
 //alert(parseInt(tcurrentdate.substring(4,6))); 
 //alert(tcurrentdate);
 
 if(tcurrentdate.substring(4,6).substring(0,1)==0)mm=parseInt(tcurrentdate.substring(5,6))
 if(tcurrentdate.substring(6,8).substring(0,1)==0)dd=parseInt(tcurrentdate.substring(7,8))
 
 var mymonth = parseInt(mm);
 mymonth=mymonth-1;
 if(mymonth<0)mymonth=0;
 //alert(dd+","+mm+","+yy);
 //alert(mymonth)
 
  
 var TRdate = new Date(yy,mymonth,dd);
 
 
 return "<b>"+dateFormat(TRdate,"mmm")+" "+dateFormat(TRdate,"dd")+", "+dateFormat(TRdate,"yyyy")+"</b>";  
 //dateFormat(now, "dddd, mmmm d, yyyy, h:MM:ss TT");
 //return(dd+"/"+mm+"/"+yy);
}

//============Munu Script============================//
function startList() 
{

	if (document.getElementById)
		{
			navRoot = document.getElementById("nav");
			for (i=0; i<navRoot.childNodes.length; i++){
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI" && node.childNodes.length > 2){
					node.onmouseover=function()
					{
						this.className+="over";
						if (navigator.userAgent.indexOf("MSIE")  > 0 ){
							var menuPos = new Position(this);
							var parentPos = new Position(this.childNodes(2));
							var PopupIFrameId = document.getElementById('MenuIFrame');
							SetElementProperty(PopupIFrameId, 'left',menuPos.GetElementLeft() + 'px');
							SetElementProperty(PopupIFrameId, 'top', menuPos.GetElementBottom() + 'px');
							SetElementProperty(PopupIFrameId, 'width',parentPos.GetElementWidth()  + 'px');
							SetElementProperty(PopupIFrameId, 'height',parentPos.GetElementHeight() + 'px');
							SetElementProperty(PopupIFrameId, 'display', 'block');
						}
					}
				   node.onmouseout=function() {
					this.className=this.className.replace("over", "");
					if (navigator.userAgent.indexOf("MSIE")  > 0 ){
						var PopupIFrameId = document.getElementById('MenuIFrame');
						SetElementProperty(PopupIFrameId, 'display', 'none');
					}
				}
			}
		}
	}
}
//window.onload=startList;

function SetElementProperty(elemId, property, value)
	{
		var elem = null;

		if(typeof(elemId) == "object")
			elem = elemId;
		else
			elem = document.getElementById(elemId);
			
		if((elem != null) && (elem.style != null))
		{
			elem = elem.style;
			elem[property] = value;
		}
}

function Position(object)
{
	var m_elem = object;

	this.GetElementWidth = GetElementWidth;
	function GetElementWidth()
	{
		var elem;
		if(typeof(m_elem) == "object")
		{
			elem = m_elem;
		}
		else
		{
			elem = document.getElementById(m_elem);
		}
		return parseInt(elem.offsetWidth);
	}

	this.GetElementHeight = GetElementHeight;
	function GetElementHeight()
	{
		var elem;
		if(typeof(m_elem) == "object")
		{
			elem = m_elem;
		}
		else
		{
			elem = document.getElementById(m_elem);
		}
		return parseInt(elem.offsetHeight);
	}

	this.GetElementLeft = GetElementLeft;
	function GetElementLeft()
	{
		var x = 0;
		var elem;		
		if(typeof(m_elem) == "object")
			elem = m_elem;
		else
			elem = document.getElementById(m_elem);
			
		while (elem != null)
		{
			x += elem.offsetLeft;
			elem = elem.offsetParent;
		}
		return parseInt(x);
	}
	
	this.GetElementRight = GetElementRight;
	function GetElementRight()
	{
		return GetElementLeft(m_elem) + GetElementWidth(m_elem);
	}

	this.GetElementTop = GetElementTop;
	function GetElementTop()
	{
		var y = 0;
		var elem;
		if(typeof(m_elem) == "object")
		{
			elem = m_elem;
		}
		else
		{
			elem = document.getElementById(m_elem);
		}
		while (elem != null)
		{
			y+= elem.offsetTop;
			elem = elem.offsetParent;
		}
		return parseInt(y);
	}

	this.GetElementBottom = GetElementBottom;
	function GetElementBottom()
	{
	    return GetElementTop(m_elem) + GetElementHeight(m_elem);
	}
}


//==============End Menu================================//
