﻿// JScript File

    //Function creating DestinationCity from PackageMenu Control
    // Function name BuildDestinationCity()
	  var CalendarDate=0;
      var myDate;
      var WindowCalendarX=0;
      var WindowCalendarY=0;
      var AgencyStatus=false;
      var AgentPageStatus=true;
	  var TotalAddDate;
	  var mouseX=0;
		var mouseY=0;

if(navigator.appName == "Netscape")
{
	document.onmouseover=MouseXY
}
// get cursor location 
 function MouseXY(e)
 {
 	var ev=(!e)?window.event:e;//IE:Moz
	 
	mouseX=ev.pageX;//+window.pageXOffset;
	mouseY=ev.pageY;//+window.pageYOffset;
 	//alert(mouseX + "\n" + mouseY);
 }
function getCursorLocation(e)
{
	
 	if(navigator.appName == "Netscape")
	{
 	 	document.onmouseover=MouseXY
	  WindowCalendarX=mouseX;
      WindowCalendarY=mouseY;
 		return true;
	}
	
	else
 	{
		mouseX=e.clientX+(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		mouseY=e.clientY+(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)
	  WindowCalendarX=mouseX;
      WindowCalendarY=mouseY;
 		   return true;

	}
       
	   
  
       
}

    function BuildDestinationCity(DestinationCityID, FirstLevelFileName, SecondLevelFileName,AddDate)
    {
        try
        {
            //create the date
            
            if(isNaN(AddDate)!=true) { TotalAddDate=AddDate;}
             myDate = new Date(todayzDate);
            //add a day to the date
            TotalAddDate=parseInt(TotalAddDate)+parseInt(CalendarDate)
             myDate.setDate(myDate.getDate()+parseInt(TotalAddDate));
           
             var month = myDate.getMonth()+1
             var year = myDate.getYear()
             var day = myDate.getDate()
             
             if(month<=9){month="0"+month;}
             if(day<=9){day="0"+day;}
             
             NtodayzDate= day+"/"+month+"/"+year;
             adddaysDate=AddDate;
            
            //  Showing the Destination Field
            showhide(1,'ctl00_DestinationCity');
		 
            document.getElementById("City").innerHTML=Loading();
          
            Flyaways.Engine.Webservice.PackageMenuWebService.DestinationCityList(DestinationCityID,FirstLevelFileName,SecondLevelFileName,onBuildDestinationCityComplete,onStartupTimeout,onStartupError);
        }
        catch(e)
        {
            alert(e.description);
        }
    }
    
     //CallBack Function When Server Method 'DestinationList' Completes.
     function onBuildDestinationCityComplete(result) 
     {
		try
		{
            var DestinationCity=document.getElementById("ctl00_DestinationCity");
		//   DestinationCity.style.display="";
 			
			//alert(WindowCalendarX + "\n" + WindowCalendarY);
 		   // Positing the Search Box infront of the Destination List
 		     DestinationCity.style.left=parseInt(WindowCalendarX+50)+"px";
		   DestinationCity.style.top= parseInt(WindowCalendarY-50)+"px";
		     DestinationCity.style.position='absolute'; 
		     
			//   DestinationCity.style.z0index='absolute';
 		   // Populating the content 
   		   document.getElementById("City").innerHTML=result;
			
        }
        catch(e)
        {
            alert(e.description);
        }
    }
 
   
    //CallBack Function When Server Method 'DestinationList' doesn't get the webservice..
    function onStartupTimeout(result) 
    {
    		    setNull();
		    setNullCopy();
         alert("Timed out");
    }
    
    //Called when server method 'DestinationList' gets some error
     function onStartupError(result) 
    {
    		    setNull();
		    setNullCopy();

       alert("OnError - Exception");
       PrintDebugMessage(result.get_message());
       PrintDebugMessage(result.get_stackTrace());
    }

    // Select the Destination and Search the Origin 
    function DestinationSelected(DestinationName, DestinationID, SecondLevelFileName)
    {
        try
         {
         
        
                 
            //  Setting the Destination value in Text Field 
              //  var DestinationsID=document.getElementById("DestinationID");
              
              // - - updated on Nov 20.08
              var DestinationsID=document.aspnetForm.DestinationID;
                
                
                DestinationsID.value=DestinationName.replace(/%20/g,' ');
           
            //  Hiding the Destination Box 
                showhide(0,'DestinationCity');
                
            //  Showing the Orign Field    
                showhide(1,'Startingfrom');
                
                 // - - sahdev
           // document.getElementById("ArrivalDate").value=NtodayzDate;
              //document.getElementById("DestinationCityID").value=DestinationID;
           // - - updated on Nov 20.08
            document.aspnetForm.ArrivalDate.value=NtodayzDate;
             document.aspnetForm.DestinationCityID.value=DestinationID;
                
           document.getElementById("OriginCity").innerHTML=Loading();
               
            document.getElementById("OriginChangeThis").innerHTML="<a href='javascript:;' OnClick=OriginSearchBox('"+DestinationID+"','"+SecondLevelFileName+"'); class='black'>Change this?</a>";
            
            // Display the Origin City List
           Flyaways.Engine.Webservice.PackageMenuWebService.DestinationOrigionList(DestinationID,SecondLevelFileName,'OriginSelected',onDestinationSelectedComplete,onStartupTimeout,onStartupError);

        }
        
        catch(e)
        {
            alert(e.description);
        }
    }
    
    function OriginSearchBox(DestinationID,SecondLevelFileName)
    {
      try
	        {
	        
            // Showing the Orign Field
            showhide(1,'OriginCity');
            
            // Hidding the StartingOn & PAX details Field
            showhide(0,'StartingOn');
            showhide(0,'PAXDetails');

            document.getElementById("OriginCity").innerHTML=Loading();
            
            // Display the Origin City List
            Flyaways.Engine.Webservice.PackageMenuWebService.DestinationOrigionList(DestinationID,SecondLevelFileName,'OriginSelected',onDestinationSelectedComplete,onStartupTimeout,onStartupError);
            }
    catch(e)
            {
                alert(e.description);
            }
    }
     //CallBack Function When Server Method 'DestinationOrigionList' Completes.
     function onDestinationSelectedComplete(result) 
     {
	    try
	    {
    	       	   
	       // Populating the content 
	       document.getElementById("OriginCity").innerHTML=result;

        }
        catch(e)
        {
            alert(e.description);
        }
    }
    
    
    
    // Select the Destination and Search the Origin 
    function OriginSelected(OriginName, OriginID)
    {
      try
         {
        // Setting the Destination value in Text Field 
        //  var OriginsID=document.getElementById("OriginID");
         
         // - - updated on Nov 20.08
          var OriginsID=document.aspnetForm.OriginID;
         OriginsID.value=OriginName.replace(/%20/g,' ');
       
         // - - updated on Nov 20.08
         document.aspnetForm.Origin_ID.value=OriginID
        // document.aspnetForm.Origin_ID.value=OriginID
        // document.getElementById("Origin_ID").value=OriginID
       
 
        // Hiding the Origin Box 
        showhide(0,'OriginCity');
        
        // Showing the StartingOn & PAX details Field
        showhide(1,'StartingOn');
        showhide(1,'PAXDetails');
 
            var maTxtVal = new Array();
            maTxtVal = document.getElementById("ArrivalDate").value.split("/");


            var yy = parseInt(maTxtVal[2]);
            if(yy<1000){
            yy=yy+1900
            }

            document.getElementById("ArrivalDate").value = maTxtVal[0]+"/"+maTxtVal[1]+"/"+yy;
             todayzDate1=document.getElementById("ArrivalDate").value;
			
        }
        
        catch(e)
        {
            alert(e.description);
        }
    }
        
    // This Class Used to write the loading(String) animation whereever required.
    function Loading()
    {
    return "<p align='center'><br><img src='images/loading2.gif' align='absmiddle'></p>";
  // return "<table width='200' border='0' cellspacing='1' cellpadding='3'> <tr>  <td><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>  <tr> <td width='1%' valign='bottom'><img src='Images/run-curv1.gif' width='5' height='7'></td>  <td width='99%' background='Images/run-curv5.gif'>&nbsp;</td>  <td width='1%' valign='bottom'><img src='Images/run-curv2.gif' width='6' height='7'></td> </tr>  <tr> <td valign='bottom' background='Images/run-curv4.gif'>&nbsp;</td>  <td height='100' align='center' bgcolor='#CCCCCC' class='backYellow'> <img src='Images/loading.gif' width='28' height='28' align='absmiddle'><br>   l o a d i n g . . . </td>  <td valign='bottom' background='Images/run-curv3.gif'>&nbsp;</td>   </tr> <tr> <td colspan='3' valign='bottom' background='Images/run-curv6.gif'>&nbsp;</td>  </tr> </table></td></tr>  </table>";
    }
    
    // This Class Used to display the calendar
    function CalendarDisplay(Object, formField,LeftMargin,Topmargin)
    {
	      var left=parseInt(WindowCalendarX)+parseInt(LeftMargin);
	      var top= parseInt(WindowCalendarY)+parseInt(Topmargin);
	   
        var FieldName=eval("document.aspnetForm."+formField+"");
      //  alert("document.aspnetForm."+formField+"" + "," + FieldName.value+ "," +Object);
        showCalendar(Object,FieldName,'dd/mm/yyyy','en',0,left,top);
    }
    
    
    function PrintThisPage() 
    { 
       var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
           sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

       var sWinHTML = document.getElementById('PackageOptions').innerHTML; 
       
       var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write("<html><link href='css/packagesPrint.css' rel='stylesheet' type='text/css'><body>"); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('</body></html>'); 
       winprint.window.print();
       winprint.document.close(); 
       
     }


    function AgentLogin(ID)
    {
		try
		{
             //  userid=document.getElementById("userid").value;
             //  password=document.getElementById("password").value;
            DisplayID=ID;
            showhide(0,'ctl00_DestinationCity');
            setValue();
            document.getElementById("PackageOptions").innerHTML=Loading();
                
            // Display the Origin City List
            Flyaways.Engine.Webservice.PackageMenuWebService.CreateAgentWindow(onAgentLoginComplete,onStartupTimeout,onStartupError);
        }
         catch(e)
        {
            alert(e.description);
        }
    }
    
    function onAgentLoginComplete(result)
    {
		try
		{
		//alert(result);
		//document.write(result);
		   document.getElementById("PackageOptions").innerHTML=result;
		   
        }
        catch(e)
        {
            alert(e.description);
        }
    }
    
    
    
    function AgentLoginNow()
    {
		try
		{
               userid=document.getElementById("userid").value;
               password=document.getElementById("password").value;
              document.getElementById("PackageOptions").innerHTML=Loading();
                
            // Display the Origin City List
            Flyaways.Engine.Webservice.PackageMenuWebService.CheckAgentLogin(userid,password,onAgentLoginNowComplete,onStartupTimeout,onStartupError);
        }
         catch(e)
        {
            alert(e.description);
        }
    }
    
    function onAgentLoginNowComplete(result)
    {
         //document.write(result);
        if(result=="FALSE")
        {
            alert("Invalid User ID or Password. \n Please check and try again.");
            AgentLogin(DisplayID);
            AgencyStatus=false;
        }
        else
        {
            
           // alert("You've sucessfully logged in");
            AgentDetails=result.split("^");
            document.getElementById("AgentLogin").innerHTML=AgentDetails[3];
            
             showhide(1,'AgentInformation');
            document.getElementById("AgentInfo").innerHTML="Welcome " + AgentDetails[2] + " | <a href='javascript:;' onclick='Logout();' class='white' >Logout</a> &nbsp;&nbsp;";
            AgencyStatus=true;
            document.getElementById("PackageOptions").innerHTML=AgentDetails[4];
            if(AgentPageStatus)
            {
             ReBuildPkg();
            }
        }
    }
    
    function CheckAgentSession()
    {
        try
        {
             Flyaways.Engine.Webservice.PackageMenuWebService.CheckAgentSession(onCheckAgentSessionComplete,onStartupTimeout,onStartupError);
        }
       catch(e)
        {
            alert(e.description);
        }
    }
    
    function onCheckAgentSessionComplete(result)
    {
        try
        {
       // alert(result);
             AgentDetails=result.split("^");
             
             if(AgentDetails[0]=="TRUE")
             {
                 showhide(1,'AgentInformation');
                document.getElementById("AgentLogin").innerHTML=AgentDetails[4];
                document.getElementById("AgentInfo").innerHTML="Welcome " + AgentDetails[2] + " | <a href='javascript:;' onclick='Logout();' class='white' >Logout</a> &nbsp;&nbsp;";
                AgencyStatus=true;
            }
            else
            {
                 showhide(0,'AgentInformation');
                document.getElementById("AgentLogin").innerHTML=AgentDetails[1];
                document.getElementById("AgentInfo").innerHTML="";
                AgencyStatus=false;
            }
        }
       catch(e)
        {
            alert(e.description);
        }    
   }
   
   
   function Logout()
   {
    try
        {
             Flyaways.Engine.Webservice.PackageMenuWebService.LogoutAgent(onLogoutAgentComplete,onStartupTimeout,onStartupError);
        }
       catch(e)
        {
            alert(e.description);
        }
   
   }
   
   
     function onLogoutAgentComplete(result)
    {
        try
        {
                AgencyStatus=false;
               showhide(0,'AgentInformation');
               document.getElementById("AgentLogin").innerHTML=result;
               document.getElementById("AgentInfo").innerHTML="";
           
        }
       catch(e)
        {
            alert(e.description);
        }    
   }
   
   function noScrollIE()
{
document.body.scroll="no";
}
function scrollIE()
{
document.body.scroll="yes";
}
function noScrollNS()
{
document.width= window.innerWidth;
document.height=window.innerHeight;
}
function scrollNS()
{
document.width=1000;
document.height=1000;
}

function ChildWindow(num,fieldname,counter)
{
  
  num=4-parseInt(num);
 	 NewDropDown=("<select name='Child"+counter+"' class=Input>");
	 for(var h=0;h<=num;h++)
	 {
		 NewDropDown+=("<option value="+h+" >"+h+"</option>");
	 }
	 NewDropDown+=("</select>");
	 document.getElementById(""+fieldname+"").innerHTML=NewDropDown
	 
	
}

function InfantWindow(num,fieldname,counter)
{
	 num=3-parseInt(num);
 	 NewDropDown=("<select name='Infant"+counter+"' class=Input>");
	 for(var h=0;h<=num;h++)
	 {
		 NewDropDown+=("<option value="+h+" >"+h+"</option>");
	 }
	 NewDropDown+=("</select>");
	 document.getElementById(""+fieldname+"").innerHTML=NewDropDown
}


function Infant(num,fieldname,counter,Adult)
{
	 num=3-parseInt(num);
	 NewDropDown=("<select name='Infant"+counter+"' class=Input>");
	 Adult1=document.getElementById(""+Adult+"");
	 Adult=parseInt(Adult1.options[Adult1.selectedIndex].value);
	 num=Adult-parseInt(num);
	 if(num<0) { num=0; }
	 
	 for(var h=0;h<=num;h++)
	 {
		 NewDropDown+=("<option value="+h+" >"+h+"</option>");
	 }
	 NewDropDown+=("</select>");
	 
	 document.getElementById(""+fieldname+"").innerHTML=NewDropDown
}

function Child(num,fieldname,counter,Adult)
{
 num=4-parseInt(num);
  	 NewDropDown=("<select name='Child"+counter+"' class=Input>");
 	 Adult1=document.getElementById(""+Adult+"");
	 Adult=parseInt(Adult1.options[Adult1.selectedIndex].value);
	 num=Adult-parseInt(num);
	 if(num<0) { num=0; }

	 for(var h=0;h<=num;h++)
	 {
		 NewDropDown+=("<option value="+h+" >"+h+"</option>");
	 }
	 NewDropDown+=("</select>");
	 document.getElementById(""+fieldname+"").innerHTML=NewDropDown
 	
}

function DisplayMenu()
{
    //  Showing the Destination Field
        showhide(1,'ctl00_DestinationCity');
		 getCursorLocation(window.event);
        var DestinationCity=document.getElementById("ctl00_DestinationCity");
		 
        //   DestinationCity.style.display="";
       // WindowCalendarX=mouseX
      //  WindowCalendarY=mouseY

        // Positing the Search Box infront of the Destination List
        DestinationCity.style.left=parseInt(WindowCalendarX-150)+"px";
        DestinationCity.style.top= parseInt(WindowCalendarY-50)+"px";
        DestinationCity.style.position='absolute';


}

function ShowCalendar(obj)
{
        WindowCalendarX=(mouseX-150);
        WindowCalendarY=mouseY+25

		showhide(0,'Adate');
		showhide(1,'Adates');
		//CalendarDisplay(obj,'ArrivalDates','0','-5');
		displayDatePicker('ArrivalDates', false, 'dmy', '/')
}
