﻿// JScript File


var loaded=false;
var XMLHTTP5;
var str3=null;
var username;
var password;
var usern;

var userlocked=false;

function loadwaitLoader()
{
            document.getElementById("waitloader2").innerHTML="<font color='black'>&nbsp;&nbsp;Please Wait</font>&nbsp;&nbsp;<img src='ajax-loader.gif' />";
}
  


function window_load()
{

loaded=true;
}

  function CreateXMLHTTP5()
{	  
	
	try
	{   //Creating XMLHTTP5 Request object for Internet Explorer browser
		XMLHTTP5 = new ActiveXObject("Msxml2.XMLHTTP5");

param="POST";
	}
	catch(e)
	{
		try
		{
            //Creating XMLHTTP5 Request object for browsers other than Internet Explorer or 

			XMLHTTP5 = new ActiveXObject("Microsoft.XMLHTTP5");
		} 
		catch(oc)
		{
			//if the XMLHTTP5 Request object cannot be created
              
                 XMLHTTP5 = null;
			
		}
	}

	 //Creating XMLHTTP5 Request object for Mozilla and Safari browser
	 //(i.e. it has been created but the type is undefined)
	if(!XMLHTTP5 && typeof XMLHTTP5Request != "undefined") 
	{
	
XMLHTTP5 = new XMLHTTP5Request();
param="GET";
	}
}
          
            //if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
               // $get('LoggedInView').style.display = '';
           // } else {
               // $get('AnonymousView').style.display = '';
           // }
           
           
          
           
            function onLoginComplete(result, context, methodName) {

 
                      
                       if(result==true)
                       {
                       changelog=false;              
                       document.getElementById("userastcell").className = "donotshowcell"; 
                       document.getElementById("passastcell").className = "donotshowcell"; 
                       document.getElementById("usernamecell").className = "donotshowcell"; 
                       document.getElementById("usercell").className = "donotshowcell";
                       document.getElementById("passwordcell").className = "donotshowcell";
                       document.getElementById("pwordcell").className = "donotshowcell";
                       document.getElementById("remembermecell").className = "donotshowcell";
                       document.getElementById("btnlogoutcell").className = "showcell";
                       document.getElementById("btnlogincell").className = "donotshowcell";
                       document.getElementById("ctl00_Label1").innerHTML = " Logged in as <B>"+ loggedinuser+"</B>";
                       var str=window.location.href;
                       
                       
                       document.getElementById("waitloader2").innerHTML="";
                                if(str.substring(0,71)=="http://www.centralreservations.ie/AccessDenied.aspx")
                                {
                               document.getElementById("ctl00_mainContentPlaceHolder_privelegesLabel").innerHTML="You cannot view this page as you have insufficient priveleges. Try refreshing the page or else use the Contact Form on the left to contact the Website Administrator.";
                                
                                }
                             isReserving(); 
                            
                         } 
                         else
                         {
                                      
                         document.getElementById("waitloader2").innerHTML="";
                         alert("Incorrect login");
                         
                         }
                       
                      
            
           
            }
           
            function onLogoutComplete(result, context, methodName) {
           
                // Logged out.  Hide the logged in view.
                //$get('LoggedInView').style.display = 'none';
                //$get('AnonymousView').style.display = '';
            }
           
            function onError(error, context, methodName) {
            
            
                alert("Error logging on");
                document.getElementById("waitloader2").innerHTML="";
           }
          
         
       



function isReserving()

{

    //set request url to empty string
    requestUrl="";
    //re-assigning AjaxPage variable to "ActivateAjax.aspx"
	AjaxPage = "Ajax6.aspx";
	//creating the URL to be sent by the XMLHTTP5 Request object 
	var requestUrl =AjaxPage  += "?Action=CheckReserving";
	//calling the function that creates the XMLHTTP5Request object
	CreateXMLHTTP5();
 
	// If browser supports XMLHTTP5Request object
	if(XMLHTTP5)
	{
		//The state of the XMLHTTP5Request object has changed.
		//Specifying a reference to an event handler ("FindHotel" function) as the event that fires at every state change.
		//calling jscript function "FindHotel" 
		XMLHTTP5.onreadystatechange = CallCheckReserve;
		//Passing 3 values to the "open" method of the XMLHTTP5 object we have just created
		//1.The first parameter is "POST" (method parameter)
		//2.The second parameter is the URL (as set above)
		//3.The third parameter (async) is set to "true".
		XMLHTTP5.open(param, requestUrl,  true);
		
		//Sends the request to server
		XMLHTTP5.send(null);
	}	
}

function CallCheckReserve()

{
  var str=window.location.href;
//receiving response from server	
	
	if(XMLHTTP5.readyState == 4)
	{
	

		//Valid Response is received
		if(XMLHTTP5.status == 200)
		{	             
            editstr=XMLHTTP5.responseText;
           	
                        

           if((editstr=="isreserving")&&(str.substring(0,74)=="http://www.centralreservations.ie/PersonalDetails.aspx"))
           {
           window.location.href="http://www.centralreservations.ie/BookingDetails.aspx";
           }
           else
           {
           
           }
		}
		else //something is wrong 
		{
			alert("Could not retrieve the data" );
        
                }
		
	}
	else
	{
		 //Waiting for response for server 
	}
}


function checkforLock(usern)

{

    //set request url to empty string
    requestUrl="";
    //re-assigning AjaxPage variable to "ActivateAjax.aspx"
	AjaxPage = "Ajax6.aspx";
	//creating the URL to be sent by the XMLHTTP5 Request object 
	var requestUrl =AjaxPage  += "?Action=CheckForLock&usern="+ usern;	
	//calling the function that creates the XMLHTTP5Request object
	CreateXMLHTTP5();

	// If browser supports XMLHTTP5Request object
	if(XMLHTTP5)
	{
		//The state of the XMLHTTP5Request object has changed.
		//Specifying a reference to an event handler ("FindHotel" function) as the event that fires at every state change.
		//calling jscript function "FindHotel" 
		XMLHTTP5.onreadystatechange = CallCheckForLock;
		//Passing 3 values to the "open" method of the XMLHTTP5 object we have just created
		//1.The first parameter is "POST" (method parameter)
		//2.The second parameter is the URL (as set above)
		//3.The third parameter (async) is set to "true".
		XMLHTTP5.open(param, requestUrl,  true);
		
		//Sends the request to server
		XMLHTTP5.send(null);
	}	


}



function CallCheckForLock()

{

 var editstr;
//receiving response from server	
	
	if(XMLHTTP5.readyState == 4)
	{
	

		//Valid Response is received
		if(XMLHTTP5.status == 200)
		{	             
          editstr=XMLHTTP5.responseText;
           	
                  
          
           if(editstr.substring(0,8)=="islocked")
           {
           userlocked=true;
        
           }
           else
           {
           
           }
		}
		else //something is wrong 
		{
			alert("Could not retrieve the data" );
        
                }
		
	}
	else
	{
		 //Waiting for response for server 
	}

}
