var areaToDisplay = new String("");
var nothing='';

function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function callprintoutwindow(poname,podetails)
      {
      var url="https://clients.enoyaone.com/shared/"+poname+".asp"
      var w="800"
      var h="800"
      var myRand=parseInt(Math.random()*99999999);  
      url=url+"?rand="+myRand;
      url=url+podetails
      var sURL = url
      var sName = "popName2"
      var sFeatures = "menubar=no,scrollbars=yes,resizable=no"
      sFeatures = sFeatures + ",width=" + w + ",height=" + h;
      var wizWin = window.open(sURL, sName, sFeatures);
      }  

function ClientLogin(LoginFrame)
{
 
 if(LoginFrame=='agt')
 	{
  agtCode=escape(document.getElementById('LoginAgtCode').value)
  agtusrname=escape(document.getElementById('LoginAgtUser').value)
 	agtusrpassword=escape(document.getElementById('LoginAgtPass').value)
  postinfo="agtCode="+agtCode+"&agtusrname="+agtusrname+"&agtusrpassword="+agtusrpassword+"&custType=2"
  }
  if(LoginFrame=='login')
 	{
  custEmail=escape(document.getElementById('LogincustEmail').value)
 	custPassword=escape(document.getElementById('LogincustPassword').value)
  postinfo="custEmail="+custEmail+"&custPassword="+custPassword+"&custType=1"
  }
  if(LoginFrame=='iti')
  {
  custEmail=escape(document.getElementById('itiemail').value)
 	custPassword=escape(document.getElementById('itipassword').value)
  postinfo="custEmail="+custEmail+"&custPassword="+custPassword+"&custType=1"
  }
 //postinfo="custEmail="+custEmail+"&custPassword="+custPassword+"&custType="+custType
 //alert(postinfo)
 areaToDisplay = LoginFrame;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 var url="includes/sys/login.asp?Setting=1"
 var myRand=parseInt(Math.random()*99999999);  
 url=url+"&rand="+myRand;
 xmlHttp.onreadystatechange=stateChanged ;
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlHttp.setRequestHeader("Content-length", 2);
 xmlHttp.setRequestHeader("Connection", "close");
 //alert(url+postinfo)
 xmlHttp.send(postinfo);

}

function Forgotpass(LoginFrame)
{
  //alert(LoginFrame)
	if(LoginFrame=='login1')
 	{
  custEmail=escape(document.getElementById('LogincustEmail').value)
 	
  postinfo="custEmail="+custEmail+"&custType=2"
  }
  
  if(LoginFrame=='login')
 	{
  custEmail=escape(document.getElementById('LogincustEmail').value)
 	postinfo="custEmail="+custEmail+"&custType=1"
  }
  
  if (LoginFrame=='iti'){
  custEmail=escape(document.getElementById('itiemail').value)
 	postinfo="custEmail="+custEmail+"&custType=1"
  }
 
 //postinfo="custEmail="+custEmail
 
 areaToDisplay = LoginFrame;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 var url="includes/sys/forgotpassword.asp?Setting=1"
 var myRand=parseInt(Math.random()*99999999);  
 url=url+"&rand="+myRand;
 xmlHttp.onreadystatechange=stateChanged ;
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlHttp.setRequestHeader("Content-length", 1);
 xmlHttp.setRequestHeader("Connection", "close");
 //alert(url+postinfo)
 xmlHttp.send(postinfo);

}

function Callhover(objid,area,fldname)
 {
 objectname=objid;
 areaToDisplay = area;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 var url="includes/destinations.asp";
  var myRand=parseInt(Math.random()*99999999);
  url=url+"?rand="+myRand+"&Fieldname="+fldname;
  
  if(fldname=='FromDST')
  	{
    //url=url+"&ExcludeDST="+document.getElementById('ToDSTid').value
    document.getElementById('ToDSTname').value='Where to';
    document.getElementById('ToDSTid').value='0'
    }  
  if(fldname=='ToDST')
  	{
    url=url+"&ExcludeDST="+document.getElementById('FromDSTid').value
    } 
  //alert (url)
  //url=url+urladditions
  //alert(url)
  xmlHttp.onreadystatechange=stateChanged ;
 	xmlHttp.open("GET",url,true);
 	xmlHttp.send(null);
 
 } 

function CallCalendar(Objid,SYear,SMonth,SDate,actiontype)
{
	objectname=Objid;
 areaToDisplay = 'Calendar';
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 SelectedReturnDate=''
 SelectedDepartureDate=''
 if (document.getElementById('DepartureDate').value!='Departure date' && actiontype!='nav' && Objid=='Departure')
 	{
  SDate=document.getElementById('DepartureDateVal').value;
  var SplitDate = document.getElementById('DepartureDateVal').value.split('/');
  SMonth=SplitDate[1]
  SYear=SplitDate[0]
  SelectedReturnDate=document.getElementById('ReturnDateVal').value
  }
 if (document.getElementById('ReturnDate').value!='Departure date' && actiontype!='nav' && Objid=='Return')
 	{
  SDate=document.getElementById('ReturnDateVal').value;
  
  SelectedDepartureDate=document.getElementById('DepartureDateVal').value
  var SplitDate = document.getElementById('DepartureDateVal').value.split('/');
  SMonth=SplitDate[1]
  SYear=SplitDate[0]
  }	
 if (document.getElementById('ReturnDate').value!='Departure date' && Objid=='Return')
  {
  SelectedDepartureDate=document.getElementById('DepartureDateVal').value
  }
 if (document.getElementById('DepartureDate').value!='Departure date' && Objid=='Departure')
  {
  SelectedReturnDate=document.getElementById('ReturnDateVal').value
  }
 var url="includes/Calendar.asp?Objid="+Objid+"&SYear="+SYear+"&SMonth="+SMonth+"&SDate="+SDate+"&SelectedDepartureDate="+SelectedDepartureDate+"&SelectedReturnDate="+SelectedReturnDate
 var myRand=parseInt(Math.random()*99999999);  
 url=url+"&rand="+myRand;
 xmlHttp.onreadystatechange=stateChanged ;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}



function stateChanged() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		switch(areaToDisplay)
			{
			case "MainWindow":
				document.getElementById('MainWindow').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow',-170,20,'reka')
			break
      case "MainWindow1":
				document.getElementById('MainWindow1').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow1',-435,20,'reka')
			break
      case "Calendar":
				document.getElementById('MainWindow').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow',-170,20,'reka')
			break
      case "iti":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          alert('Welcome back, Please fill in passengers details, update yours (if needed) and continue to payment');
  				document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          }
			break
      
      case "login":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          //alert('Welcome back!');
  				//document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          //document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          window.location="account.asp"
          }
       break
      
      case "login1":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          //alert('Welcome back!');
  				//document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          //document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          window.location="account.asp"
          }
       break
			}
		}
  }



function GetXmlHttpObject()
{ 
 var objXMLHttp=null;
 if (window.XMLHttpRequest)
 {
  objXMLHttp=new XMLHttpRequest();
 }
 else 
  if (window.ActiveXObject)
  {
   objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 return objXMLHttp;
}var areaToDisplay = new String("");
var nothing='';

function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function callprintoutwindow(poname,podetails)
      {
      var url="https://clients.enoyaone.com/shared/"+poname+".asp"
      var w="800"
      var h="800"
      var myRand=parseInt(Math.random()*99999999);  
      url=url+"?rand="+myRand;
      url=url+podetails
      var sURL = url
      var sName = "popName2"
      var sFeatures = "menubar=no,scrollbars=yes,resizable=no"
      sFeatures = sFeatures + ",width=" + w + ",height=" + h;
      var wizWin = window.open(sURL, sName, sFeatures);
      }  


function Callhover(objid,area,fldname)
 {
 objectname=objid;
 areaToDisplay = area;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 var url="includes/destinations.asp";
  var myRand=parseInt(Math.random()*99999999);
  url=url+"?rand="+myRand+"&Fieldname="+fldname;
  
  if(fldname=='FromDST')
  	{
    //url=url+"&ExcludeDST="+document.getElementById('ToDSTid').value
    document.getElementById('ToDSTname').value='Where to';
    document.getElementById('ToDSTid').value='0'
    }  
  if(fldname=='ToDST')
  	{
    url=url+"&ExcludeDST="+document.getElementById('FromDSTid').value
    } 
  //alert (url)
  //url=url+urladditions
  //alert(url)
  xmlHttp.onreadystatechange=stateChanged ;
 	xmlHttp.open("GET",url,true);
 	xmlHttp.send(null);
 
 } 

function CallCalendar(Objid,SYear,SMonth,SDate,actiontype)
{
	objectname=Objid;
 areaToDisplay = 'Calendar';
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return;
 } 
 SelectedReturnDate=''
 SelectedDepartureDate=''
 if (document.getElementById('DepartureDate').value!='Departure date' && actiontype!='nav' && Objid=='Departure')
 	{
  SDate=document.getElementById('DepartureDateVal').value;
  var SplitDate = document.getElementById('DepartureDateVal').value.split('/');
  SMonth=SplitDate[1]
  SYear=SplitDate[0]
  SelectedReturnDate=document.getElementById('ReturnDateVal').value
  }
 if (document.getElementById('ReturnDate').value!='Departure date' && actiontype!='nav' && Objid=='Return')
 	{
  SDate=document.getElementById('ReturnDateVal').value;
  
  SelectedDepartureDate=document.getElementById('DepartureDateVal').value
  var SplitDate = document.getElementById('DepartureDateVal').value.split('/');
  SMonth=SplitDate[1]
  SYear=SplitDate[0]
  }	
 if (document.getElementById('ReturnDate').value!='Departure date' && Objid=='Return')
  {
  SelectedDepartureDate=document.getElementById('DepartureDateVal').value
  }
 if (document.getElementById('DepartureDate').value!='Departure date' && Objid=='Departure')
  {
  SelectedReturnDate=document.getElementById('ReturnDateVal').value
  }
 var url="includes/Calendar.asp?Objid="+Objid+"&SYear="+SYear+"&SMonth="+SMonth+"&SDate="+SDate+"&SelectedDepartureDate="+SelectedDepartureDate+"&SelectedReturnDate="+SelectedReturnDate
 var myRand=parseInt(Math.random()*99999999);  
 url=url+"&rand="+myRand;
 xmlHttp.onreadystatechange=stateChanged ;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}



function stateChanged() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		switch(areaToDisplay)
			{
			case "MainWindow":
				document.getElementById('MainWindow').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow',-170,20,'reka')
			break
      case "MainWindow1":
				document.getElementById('MainWindow1').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow1',-435,20,'reka')
			break
      case "Calendar":
				document.getElementById('MainWindow').innerHTML=xmlHttp.responseText;
        showdd(objectname,'MainWindow',-170,20,'reka')
			break
      case "iti":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          alert('Welcome back, Please fill in passengers details, update yours (if needed) and continue to payment');
  				document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          }
			break
      
      case "login":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          //alert('Welcome back!');
  				//document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          //document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          window.location="account.asp"
          }
       break
      
      case "agt":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          //alert('Welcome back!');
  				//document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          //document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          window.location="account.asp"
          }
       break
      
      case "login1":
      	responsefromaction = xmlHttp.responseText
 				splitValues = responsefromaction.split(";")
      	if(splitValues[0]=="001")
        	{alert(splitValues[1])}
          else
          {
          //alert('Welcome back!');
  				//document.getElementById('RT').innerHTML=Left(xmlHttp.responseText,3);
          //document.getElementById('CUST').innerHTML=xmlHttp.responseText;
          window.location="account.asp"
          }
       break
			}
		}
  }



function GetXmlHttpObject()
{ 
 var objXMLHttp=null;
 if (window.XMLHttpRequest)
 {
  objXMLHttp=new XMLHttpRequest();
 }
 else 
  if (window.ActiveXObject)
  {
   objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 return objXMLHttp;
}
