// JScript File

//the AjaxPage variable
var AjaxPage = "ActivateAjax.aspx";
//the global XMLHTTP Request variable
var XMLHTTP;
var XMLHTTP2;
//the Hotel ID variable for the btnFindHotel_OnClick() function
var hotelID;
var reservationID;
//hotel county variable
//that is used to get this value when hotel combo box is clicked
var hotelCounty;
var thecounty;
var roomchosen;
var roomid;

// hotel to reserve id that is used by the
// btnFindHotelToReserve_OnClick function
var hoteltoreserveID;


//validation variables
var validated2=0;
var validated=0;
var fullyvalidated = false;
//variable that validates that all the data fro the hotel search has been entered
var searchvalidated;

//start date and end date variables
var startdate;
var enddate;

var startd;
var endd;

var rate;
var county;

//single, double and total rooms variables
var sRooms =null;
var dRooms =null;
var totRooms =null;

//various strings to be displayed in event of errors
var blanktexterrorstring="=All fields must be completed";
var nonnumericerrorstring="=This field must be numeric";
var singleroomserrorstring = "=Single rooms cannot be greater than total rooms";
var doubleroomserrorstring="=Double rooms cannot be greater than total rooms";
var totalroomserrorstring="=Single and double rooms combined is not equal to total rooms";
var checkindateerrorstring="No check in date chosen";
var checkoutdateerrorstring="No check out date chosen";
var countyspellingerrorstring="=This is not a valid county";

var buttonid=null;

var num;

var page;

var option;

var Date1;

var Date2;

var changediv;

var changediv2=false;

var pageselected;

var pageis;







function SendEmail_OnClick()
{
var requestUrl ="Ajax2.aspx?Action=SendMail";
	CreateXMLHTTP();

	// If browser supports XMLHTTPRequest object
	if(XMLHTTP)
	{
		//Setting the event handler for the response
		XMLHTTP.onreadystatechange = ShowEmailSuccessMsg;
		
		//Initializes the request object with the "POST" method of posting), 
		//the request URL and sets the request as asynchronous="true".
		XMLHTTP.open(param, requestUrl, true);
	
		//Sends the request to server
		XMLHTTP.send(null);	

	}



}



function ShowEmailSuccessMsg()
{

	//receiving response from server	
	
	if(XMLHTTP.readyState == 4)
	{
	

		//Valid Response is received
		if(XMLHTTP.status == 200)
		{	
				
			
		}
		else //something is wrong 
		{
			alert("Could not retrieve the data" );
        
                }
		
	}
	else
	{
		 //Waiting for response for server 
	}
}








function btnSetSingleRoom_OnClick()

{
roomchosen="single";
}



function btnSetDoubleRoom_OnClick()

{
roomchosen="double";
}




function hideCells()


{
document.getElementById("date1").className = "hideMe"; 
document.getElementById("date2").className = "hideMe"; 

document.getElementById("sdate").className = "hideMe"; 
document.getElementById("edate").className = "hideMe"; 

document.getElementById("hotelID").className = "hideMe";
document.getElementById("hotelcombox").className = "hideMe";

}



function btnGethotelCounty_OnClick()
    {
    hotelCountyx=document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value;

    }

function btnCompareDates_OnClick(startdate,enddate)

	{
var hotelCounty2=document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value;
	
	//set validation variable to zero
	searchvalidated=0;
	//setting the cells in the first row of the table at the bottom
	//to be empty
	var tbl  = document.getElementById('Table2');
    //gets the first row
    var rows = tbl.getElementsByTagName('tr');
	var cels2 = rows[0].getElementsByTagName('td')
    //text in first cell of first row is set to be empty
    cels2[0].innerHTML="";
    //text in second cell of first row is set to be empty
    cels2[1].innerHTML="";
  
     
     
    //setting the cells of the second row of the table at the bottom
	//to be empty 
    var tbl  = document.getElementById('Table2');
    //gets the second row
    var rows = tbl.getElementsByTagName('tr'); 
    var cels2 = rows[1].getElementsByTagName('td')
    //text in first cell of second row is set to be empty
    cels2[0].innerHTML="";
    //text in second cell of that row is set to be empty
    cels2[1].innerHTML="";
    
    
    
     var tbl  = document.getElementById('Table2');
    //gets the second row
    var rows = tbl.getElementsByTagName('tr'); 
    var cels2 = rows[2].getElementsByTagName('td')
    //text in first cell of second row is set to be empty
    cels2[0].innerHTML="";
    //text in second cell of that row is set to be empty
    cels2[1].innerHTML="";
    
          
          
    //sets the asterixes in the cells beside the 
    //price to be invisible
    var tbl  = document.getElementById('calendartable');
    //gets the row
    var rows = tbl.getElementsByTagName('tr'); 
    //second row of that table
    var cels3 = rows[1].getElementsByTagName('td')
    //background color of third cell of that row is set to be white

    cels3[2].style.color='#ece9d8';	
        
		    
	//sets the asterixes in the cells beside the 
	//room type to be invisible 
    var tbl  = document.getElementById('calendartable');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');   
	//third row of that table	    
    var cels3 = rows[2].getElementsByTagName('td')
    //background color of third cell of that row is set to be white
    cels3[2].style.color='#ece9d8';

	    
	//sets the asterixes in the cells beside the 
	//room type to be invisible 
    var tbl  = document.getElementById('calendartable');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');   
	//third row of that table	    
    var cels3 = rows[0].getElementsByTagName('td')
    //background color of third cell of that row is set to be white
    cels3[2].style.color='#ece9d8';


    //sets the text in the cells
    //that shows the checkindateerrorstring and
    //checkoutdateerrorstring to be empty
    var tbl  = document.getElementById('tblcalbottomdiv');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr')		    
    //gets the first row
    var cels2 = rows[0].getElementsByTagName('td')
    //text in first cell of that row is set to be empty
    cels2[0].innerHTML="";
    //text in the second cell of that row is set to be empty
    cels2[1].innerHTML="";
    
    
    //sets the Check In Date and Check Out Date to null
    document.getElementById("ctl00_mainContentPlaceHolder_txtCheckInDate").value=="";
    document.getElementById("ctl00_mainContentPlaceHolder_txtCheckOutDate").value=="";
    document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value=="";        
	//checks to see if there has been a price entered
	if((document.getElementById("ctl00_mainContentPlaceHolder_txtEuros").value==""))
			
	{
	
	//sets the error string to appear in the table at the bottom		
    var tbl  = document.getElementById('Table2');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');
    //gets the first row
    var cels2 = rows[0].getElementsByTagName('td')
    //colour in first cell of that row is set to be red
    cels2[0].style.color='red';
    //text in first cell of that row is set to be '*'
    cels2[0].innerHTML="*";
    var cels3 = rows[0].getElementsByTagName('td')
    //text in second cell of that row is set to '*'
    cels2[1].innerHTML="= No price entered";
            
            
    //makes the asterix appear in the cell beside the
    //price text box
    var tbl  = document.getElementById('calendartable');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr'); 
    //gets the second  row
    var cels3 = rows[1].getElementsByTagName('td')
    //sets the text of the third cell of that row to be red
    //so asterix will appear
    cels3[2].style.color='red';
    //sets the searchvalidated variable to be not zero
    searchvalidated=1;
             
	}
else{	

if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtEuros").value))


{



}		
	
else
{
	
	//sets the error string to appear in the table at the bottom		
    var tbl  = document.getElementById('Table2');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');
    //gets the first row
    var cels2 = rows[0].getElementsByTagName('td')
    //colour in first cell of that row is set to be red
    cels2[0].style.color='blue';
    //text in first cell of that row is set to be '*'
    cels2[0].innerHTML="*";
    var cels3 = rows[0].getElementsByTagName('td')
    //text in second cell of that row is set to '*'
    cels2[1].innerHTML="=This field must be numeric";
            
            
    //makes the asterix appear in the cell beside the
    //price text box
    var tbl  = document.getElementById('calendartable');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr'); 
    //gets the second  row
    var cels3 = rows[1].getElementsByTagName('td')
    //sets the text of the third cell of that row to be red
    //so asterix will appear
    cels3[2].style.color='blue';
    //sets the searchvalidated variable to be not zero
    searchvalidated=1;
             
	}
	
}




	//if there is no room type chosen
	if (hotelCounty2.trim()=="")
		    
		    {
		    
    //sets the asterix
    //to appear in the table at the bottom		
    var tbl  = document.getElementById('Table2');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');   
	//gets the second row of that table    
    var cels2 = rows[2].getElementsByTagName('td')
    //text in first cell of that row is set to '*'
    cels2[0].style.color='red';
    cels2[0].innerHTML="*";
    var cels3 = rows[0].getElementsByTagName('td')
    //text in second cell of that row is set to show error
    cels2[1].innerHTML="= No county chosen";
          
    
    //sets the asterix
    //to appear in the cell beside the
    //euros text box	
    var tbl  = document.getElementById('calendartable');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');   
	//gets the third row	    
    var cels3 = rows[0].getElementsByTagName('td')
    //gets the third cell of that row
    //and sets the text to be red
    //so asterix will appear
    cels3[2].style.color='red';
    //sets the searchvalidated variable to be not zero
    searchvalidated=2;
            
		    }
		    
	
		    
	//if there is no check in date chosen
    if((document.getElementById("ctl00_mainContentPlaceHolder_txtCheckInDate").value==""))
		    
    {
    //sets the cell in the bottom 
    //table to show the checkindateerrorstring
    var tbl  = document.getElementById('tblcalbottomdiv');
    //gets the first row
    var rows = tbl.getElementsByTagName('tr')
    var cels2 = rows[0].getElementsByTagName('td')
    //text in first cell of that row is set to show the
    //checkindateerrorstring
    cels2[0].innerHTML=checkindateerrorstring;
    //sets the searchvalidated variable to be not zero
    searchvalidated=3;  
    }
			
	//if there is no check out date chosen		
    if((document.getElementById("ctl00_mainContentPlaceHolder_txtCheckOutDate").value==""))
		    
    {
	//sets the cell in the bottom 
    //table to show the checkoutdateerrorstring	    
    var tbl  = document.getElementById('tblcalbottomdiv');
    //gets the first row
    var rows = tbl.getElementsByTagName('tr')
    var cels2 = rows[0].getElementsByTagName('td')
    //text in second cell of that row is set to show the
    //checkoutdateerrorstring
    cels2[1].innerHTML=checkoutdateerrorstring;
    //first row of the table
    //sets the searchvalidated variable to be not zero
    searchvalidated=4;
    }
	


	//if all the validation is completed successfully
	if(searchvalidated==0)
	
	{



    //assigning values to start date and end date
    startdate=document.getElementById("ctl00_mainContentPlaceHolder_txtCheckInDate").value;
    enddate=document.getElementById("ctl00_mainContentPlaceHolder_txtCheckOutDate").value;
    rate=document.getElementById("ctl00_mainContentPlaceHolder_txtEuros").value;

    requestUrl="";
    //re-assigning AjaxPage variable to "Ajax3.aspx"
    AjaxPage = "Ajax3.aspx";
    //creating the URL to be sent by the XMLHTTP Request object 
    var requestUrl =AjaxPage  += "?Action=testDates&hotelstartdate="+startdate+"&hotelenddate="+enddate+"&county="+encodeURIComponent(hotelCounty2)+"&price="+encodeURIComponent(rate);
  
   
    //calling the function that creates the XMLHTTPRequest object
    CreateXMLHTTP();
    if(XMLHTTP)
        {

            //calls Comparedates function
            XMLHTTP.onreadystatechange = CompareDates;
            XMLHTTP.open(param, requestUrl,true);
            XMLHTTP.send(null);	

           		
        }
	  
	  }
	  
	  
	  
}



//function that compares dates
function CompareDates()
{

 var tbl  = document.getElementById('tblcalbottomdiv');
   //gets the rows
   var rows = tbl.getElementsByTagName('tr');
   
    //code to show asterix and error string in bottom table for this error
	var cels2 = rows[0].getElementsByTagName('td')
   //text in first cell of that row is set to be empty
   cels2[0].innerHTML="";
   //first row of the table  
   
   
   
    var cels2 = rows[0].getElementsByTagName('td')
    //text in first cell of that row is set to be empty
    cels2[1].innerHTML="";
  
 document.getElementById("showloader").innerHTML="<font color='red'>Please Wait</font>&nbsp;&nbsp;<img src='ajax-loader.gif' />";
  


if(XMLHTTP.readyState == 4)
	{
  



		//If a valid Response is received
		if(XMLHTTP.status == 200)
		{	
			
		   var str2=XMLHTTP.responseText;
                   //var firstoccur=str.indexOf("<");
                   //var str2=str.substring(0,firstoccur);


		    if(str2.substring(0,16)=="currentdateerror")
		    {
                    alert("Please choose a check in date in the future");
		    }
		    
		    else if(str2.substring(0,9)=="dateerror")
		    {
		        alert("Please choose a check out date in the future");
		    }
		     else if(str2.substring(0,14)=="startdateerror")
		    {
		         alert("Please choose a check out date in the future");
		    }
		    
		    //or else the end date is after the start date
		    else if(str2.substring(0,5)=="False")
		         {
		    
		       alert("Sorry, no hotels match your search");
		    
                    }
            
           else if(str2=="notdate")
           {
            alert("These date(s) are not valid");
           } 
           
		   	else 
		    {
		    

		        alert("Hotels match your search");
window.location.href="http://www.centralreservations.ie/ReserveRoom.aspx";
		    }
		}
		else 
		{
		//if a valid response could not be retrieved from server
		alert("Could not retrieve data from server");
		}
		
	   
	}
	else
	{
	//Waiting for response for server 
	}
}



 String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

//function that is called when ID of hotel is clicked in the grid


function btnFindHotel_OnClick(hotelID) 
{

 


//clearCells();

    //set request url to empty string
    requestUrl="";
    //re-assigning AjaxPage variable to "ActivateAjax.aspx"
	AjaxPage = "ActivateAjax.aspx";
	//creating the URL to be sent by the XMLHTTP Request object 
	var requestUrl =AjaxPage  += "?Action=FindHotel&hotelID=" + encodeURIComponent(hotelID);
	//calling the function that creates the XMLHTTPRequest object
	CreateXMLHTTP();
	
	// If browser supports XMLHTTPRequest object
	if(XMLHTTP)
	{
		//The state of the XMLHTTPRequest 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" 
		XMLHTTP.onreadystatechange = FindHotel;
		//Passing 3 values to the "open" method of the XMLHTTP 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".
		XMLHTTP.open(param, requestUrl,  true);
		
		//Sends the request to server
		XMLHTTP.send(null);	
	}


      document.getElementById("divDisplayHotel").className = "divdisplay";

   
   

}



function ReturnTable(){


if(XMLHTTP2.readyState == 4)
	{
  


		//If a valid Response is received
		if(XMLHTTP2.status == 200)
		{	
		 	
            		
        var editstr=null;
        editstr=XMLHTTP2.responseText;	
        
               if (editstr=="false")
                
               {	

          
               }
               else
            
               {
          
                             

             
                    
                    document.getElementById("hoteldiv").innerHTML=editstr;
                   
           
           
               }
            
      			


		}
		else 
		{
		//if a valid response could not be retrieved from server
		alert("Could not retrieve data from server");
		}
		
	   
	}
	else
	{
	//Waiting for response for server 
	}



}








function refreshGrid(){

 
    var requestUrl="";
    //re-assigning AjaxPage variable to "Ajax4.aspx"
    AjaxPage = "Ajax4.aspx";
    //creating the URL to be sent by the XMLHTTP Request object 
    requestUrl =AjaxPage  += "?Action=UpdateGrid&rowNum=" + encodeURIComponent(num);
  


 CreateXMLHTTP2();
    if(XMLHTTP2)
        {

            //calls Comparedates function
            XMLHTTP2.onreadystatechange = ReturnTable;
            XMLHTTP2.open(param, requestUrl,true);
            XMLHTTP2.send(null);	

           		
        }


        
    
}



function changecells(pageselected)
                    {

var tbl;
var div = document.getElementsByTagName('div');

for(var i=0; i<div.length; i++)
{
if (div[i].className == 'hideMe')
        {
  
  div[i].className = 'showMe';
        }
        
    


 }

 if(pageselected==1)
 {    
 pageis=1;     
 tbl = document.getElementById("ctl00_mainContentPlaceHolder_dgHotels");
 }
 else if(pageselected==2)
 {
 pageis=2;
 tbl  = document.getElementById("ctl00_mainContentPlaceHolder_ReservationsDataGrid");

 }
 else if(pageselected==3)
 {
 pageis=3;
tbl  = document.getElementById("ctl00_mainContentPlaceHolder_HotelDataGrid2");

 }


var oRow;
var curr_row;
var curr_cell;
num=-1;

    for (curr_row = 0; curr_row < tbl.rows.length; curr_row++)
    {
  
    num=num+1;
    }

tbl.deleteRow(num);
                       
                                      
                       }


function clearCells(){

       
        //text of first cell of first row is set to be empty
        document.getElementById("row1cell1").innerHTML="";
    
        //second cell of first row
         document.getElementById("row1cell2").innerHTML="";
 
        //first cell of second row
        document.getElementById("row2cell1").innerHTML="";
    
        //second cell of second row
        document.getElementById("row2cell2").innerHTML="";   
    
        //first cell of third row
        document.getElementById("row3cell1").innerHTML="";
       
    
        //second cell of third row
       document.getElementById("row3cell2").innerHTML="";
        
    
        //first cell of fourth row
        document.getElementById("row4cell1").innerHTML="";
    
        //second cell of fourth row
        document.getElementById("row4cell2").innerHTML="";
    
        //first cell of fourth row
        document.getElementById("row5cell1").innerHTML="";
    
        //second cell of fourth row
        document.getElementById("row5cell2").innerHTML="";
        
       

        //makes sure 'validated' variable is set to 'false'
        validated=0;
        //start of code that validates the hotel details
        //by displaying asterix's for each invalid entry




 //text of first cell of first row is set to be empty
        document.getElementById("hotelnamecell").style.color="#ece9d8";
    
        //second cell of first row
         document.getElementById("hoteladdress1cell").style.color="#ece9d8";
 
        //first cell of second row
        document.getElementById("hoteladdress2cell").style.color="#ece9d8";
    
        //second cell of second row
        document.getElementById("hotelcountycell").style.color="#ece9d8";
    
        //first cell of third row
        document.getElementById("hotelemailcell").style.color="#ece9d8";
       
    
        //second cell of third row
       document.getElementById("hoteltotcaproomscell").style.color="#ece9d8";
        
    
        //first cell of fourth row
        document.getElementById("hotelsinroomscell").style.color="#ece9d8";
    

        //first cell of fourth row
        document.getElementById("hotelsinroomsratecell").style.color="#ece9d8";

          //first cell of fourth row
        document.getElementById("hoteldoubroomscell").style.color="#ece9d8";

        
          //first cell of fourth row
        document.getElementById("hoteldoubroomsratecell").style.color="#ece9d8";

}

function btnFindReservation_OnClick(reservationID) {
 //display Reservation Details
 
 
//clearCells();

    //set request url to empty string
    requestUrl="";
    //re-assigning AjaxPage variable to "ActivateAjax.aspx"
	AjaxPage = "ActivateAjax.aspx";
	//creating the URL to be sent by the XMLHTTP Request object 
	var requestUrl =AjaxPage  += "?Action=FindReservation&reservationID=" + encodeURIComponent(reservationID);
	//calling the function that creates the XMLHTTPRequest object
	CreateXMLHTTP();
	
	// If browser supports XMLHTTPRequest object
	if(XMLHTTP)
	{
		//The state of the XMLHTTPRequest 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" 
		XMLHTTP.onreadystatechange = FindReservation;
		//Passing 3 values to the "open" method of the XMLHTTP 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".
		XMLHTTP.open(param, requestUrl,  true);
		
		//Sends the request to server
		XMLHTTP.send(null);	
	}
	
       
        document.getElementById("divDisplayReservation").className = "divdisplay2";


        
        
    
    
    

}


//function that creates the XMLHTTP Request object
function CreateXMLHTTP()
{	  
	
	try
	{   //Creating XMLHTTP Request object for Internet Explorer browser
		XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");

param="POST";
	}
	catch(e)
	{
		try
		{
            //Creating XMLHTTP Request object for browsers other than Internet Explorer or 

			XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			//if the XMLHTTP Request object cannot be created
              
                 XMLHTTP = null;
			
		}
	}

	 //Creating XMLHTTP Request object for Mozilla and Safari browser
	 //(i.e. it has been created but the type is undefined)
	if(!XMLHTTP && typeof XMLHttpRequest != "undefined") 
	{
	
XMLHTTP = new XMLHttpRequest();
param="GET";
	}
}


//function that creates the XMLHTTP Request object
function CreateXMLHTTP2()
{	  
	
	try
	{   //Creating XMLHTTP Request object for Internet Explorer browser
		XMLHTTP2 = new ActiveXObject("Msxml2.XMLHTTP");

param="POST";
	}
	catch(e)
	{
		try
		{
            //Creating XMLHTTP Request object for browsers other than Internet Explorer or 

			XMLHTTP2 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			//if the XMLHTTP Request object cannot be created
              
                 XMLHTTP2 = null;
			
		}
	}

	 //Creating XMLHTTP Request object for Mozilla and Safari browser
	 //(i.e. it has been created but the type is undefined)
	if(!XMLHTTP2 && typeof XMLHttpRequest != "undefined") 
	{
	
XMLHTTP2 = new XMLHttpRequest();
param="GET";
	}
}






//function called from btnFindHotel_OnClick function
function FindHotel()
{


    //receiving response from server	
	if(XMLHTTP.readyState == 4)
	{
		//If a valid Response is received
		if(XMLHTTP.status == 200)
		{		
	
			//calls "SetHotelFields" function
			//and passes in as a parameter the response received from
			//the call to the XMLHTTP Request Object
			//this response has been returned as an XML document object. 
			//"responseXML.documentElement" returns all the elements of this document
			SetHotelFields(XMLHTTP.responseXML.documentElement);
		}
		else  
		{
			//if a valid response could not be retrieved from server
			alert("Could not retrieve data from server");
			
		}
		
	}
	
	else
	{
	   //Waiting for response for server 
	}
}


//function called from btnFindHotel_OnClick function
function FindReservation()
{

    //receiving response from server	
	if(XMLHTTP.readyState == 4)
	{
		//If a valid Response is received
		if(XMLHTTP.status == 200)
		{			
			//calls "SetHotelFields" function
			//and passes in as a parameter the response received from
			//the call to the XMLHTTP Request Object
			//this response has been returned as an XML document object. 
			//"responseXML.documentElement" returns all the elements of this document
			SetReservationFields(XMLHTTP.responseXML.documentElement);
		}
		else  
		{
			//if a valid response could not be retrieved from server
			alert("Could not retrieve data from server");
			
		}
		
	}
	
	else
	{
	   //Waiting for response for server 
	}
}



function SetHotelFields(ClientNode)
{

	//clearing the fields on the text boxes where the hotel details are to be displayed
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelID").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelName").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress1").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress2").value="";
	//document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelEmail").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value="";
    document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value="";
    document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value="";
    document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value=""; 
	
	if(ClientNode!=null)
	{ 
           
		//getting the values back from the ClientNode
		var ID = ClientNode.getElementsByTagName('HotelID');
		var HName = ClientNode.getElementsByTagName('HotelName');
		var Add1 = ClientNode.getElementsByTagName('Address1');
		var Add2 = ClientNode.getElementsByTagName('Address2');
		var County = ClientNode.getElementsByTagName('County');
		var Email = ClientNode.getElementsByTagName('Email');
		var TotalRooms = ClientNode.getElementsByTagName('Rooms');
		var SingleRooms = ClientNode.getElementsByTagName('SRooms');
		var SRoomsRate = ClientNode.getElementsByTagName('SRoomsRate');
		var DoubleRooms= ClientNode.getElementsByTagName('DRooms');	
		var DRoomsRate = ClientNode.getElementsByTagName('DRoomsRate');
	
	
		
		
		//Sets the values returned from ClientNode in the text boxes
		document.getElementById("ctl00_mainContentPlaceHolder_txtHotelID").value=GetInnerText(ID[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtHotelName").value=GetInnerText(HName[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress1").value=GetInnerText(Add1[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress2").value=GetInnerText(Add2[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value=GetInnerText(County[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtHotelEmail").value=GetInnerText(Email[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value=GetInnerText(TotalRooms[0]);
        document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value=GetInnerText(SingleRooms[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value=GetInnerText(SRoomsRate[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value=GetInnerText(DoubleRooms[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value=GetInnerText(DRoomsRate[0]);
	  
	}
	else
	{
            //ClientNode is null
	}
	
}

function SetReservationFields(ClientNode)
{

	//clearing the fields on the text boxes where the hotel details are to be displayed
	document.getElementById("ctl00_mainContentPlaceHolder_txtReservationIDReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtCustomerIDReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtHotelIDReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtRoomTypeReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtRoomNumberReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtDateFromReservationDetailsdiv").value="";
	document.getElementById("ctl00_mainContentPlaceHolder_txtDateToReservationDetailsdiv").value="";
    
	
	if(ClientNode!=null)
	{ 
              
		//getting the values back from the ClientNode
		var resID = ClientNode.getElementsByTagName('ReservationID');
		var custID = ClientNode.getElementsByTagName('CustomerID');
		var hotID = ClientNode.getElementsByTagName('HotelID');
		var rType = ClientNode.getElementsByTagName('RoomType');
		var rNumber = ClientNode.getElementsByTagName('RoomNumber');
		var dFrom = ClientNode.getElementsByTagName('DateFrom');
		var dTo = ClientNode.getElementsByTagName('DateTo');
		
	
	
		
		
		//Sets the values returned from ClientNode in the text boxes
		document.getElementById("ctl00_mainContentPlaceHolder_txtReservationIDReservationDetailsdiv").value=GetInnerText(resID[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtCustomerIDReservationDetailsdiv").value=GetInnerText(custID[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtHotelIDReservationDetailsdiv").value=GetInnerText(hotID[0]);
		document.getElementById("ctl00_mainContentPlaceHolder_txtRoomTypeReservationDetailsdiv").value=GetInnerText(rType[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtRoomNumberReservationDetailsdiv").value=GetInnerText(rNumber[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtDateFromReservationDetailsdiv").value=GetInnerText(dFrom[0]);
	    document.getElementById("ctl00_mainContentPlaceHolder_txtDateToReservationDetailsdiv").value=GetInnerText(dTo[0]);

	  
	}
	else
	{
            //ClientNode is null
	}
	
}





function btnInsertHotel_OnClick()
{

 
  
       
clearCells();

           
   
                //setting requestUrl to null
	                requestUrl="";
	                //re-assigning AjaxPage to "ActivateAjax.aspx"
	                AjaxPage = "ActivateAjax.aspx";

                		
                var hotelName = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelName").value);

                var hotelAddress1 = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress1").value);

                var hotelAddress2 = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress2").value);

                var hotelCounty = thecounty;

                var hotelEmail = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelEmail").value);

                var totCapRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value);

                var sinRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value);

                var sinRoomsRate = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value);

                var doubRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value);

                var doubRoomsRate = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value);
                 
	                // constructing the URL 
                	
	                var requestUrl =AjaxPage  + "?Action=InsertHotel&HotelName="+ hotelName	
	                +"&HotelAddress1="+ hotelAddress1
	                +"&HotelAddress2="+ hotelAddress2
	                +"&HotelCounty="+ hotelCounty
	                +"&HotelEmail="+ hotelEmail
	                +"&TotCapRooms="+ totCapRooms
	                +"&SinRooms="+ sinRooms
	                +"&SinRoomsRate="+ sinRoomsRate
	                +"&DoubRooms="+ doubRooms
	                +"&DoubRoomsRate=" + doubRoomsRate;



	                //calling the function that creates the XMLHTTPRequest object
	                CreateXMLHTTP();

	                // If browser supports XMLHTTPRequest object
	                if(XMLHTTP)
	                {
		                //Setting the event handler for the response
		                XMLHTTP.onreadystatechange = ShowInsertSuccessMsg;
                		
		                //Initializes the request object with the "GET" method of posting), 
		                //Request URL and sets the request as asynchronous="true".
		                XMLHTTP.open("GET", requestUrl, true);
                		
		                //Sends the request to server
		                XMLHTTP.send(null);		
	                }


                         
           
                        //goes to the bottom table and sets the text
                        //to indiacte the hotel has been added successfully
                        var tbl  = document.getElementById('tblbottomdiv');
                        //gets the first row
                        var rows = tbl.getElementsByTagName('tr');

                        //gets first cell of first row and sets it's text to be null
                        var cels2 = rows[0].getElementsByTagName('td')
                        cels2[0].innerHTML="";
                        
                        //gets second cell of first row and sets it's text to be 
                        //'Thank you for adding your hotel'
                        
                       clearFields(1);

                        var cels3 = rows[0].getElementsByTagName('td')
                        cels3[1].innerHTML="Thank you for adding your hotel";
                       
                      
                        //gets first cell of second row and sets it's text to be 
                        //null
                        var cels4 = rows[1].getElementsByTagName('td')
                        cels4[0].innerHTML="";
                        
                        //gets second cell of second row and sets it's text to be 
                        //null
                        var cels3 = rows[1].getElementsByTagName('td')    
                        cels3[1].innerHTML="";
                        
                        //gets first cell of third row and sets it's text to be 
                        //null       
                        var cels5 = rows[2].getElementsByTagName('td')
                        cels5[0].innerHTML="";
                    
                        //gets second cell of third row and sets it's text to be 
                        //null 
                        var cels5 = rows[2].getElementsByTagName('td')    
                        cels5[1].innerHTML=""; 
                            
                        //gets first cell of fourth row and sets it's text to be 
                        //null 
                        var cels6 = rows[3].getElementsByTagName('td')
                        cels6[0].innerHTML="";
                        
                        //gets second cell of fourth row and sets it's text to be 
                        //null 
                        var cels7 = rows[3].getElementsByTagName('td') 
                        cels7[1].innerHTML="";
                      
                      
                    

    }
   




                    

   
    
function validateHotels(buttonid){

if(buttonid==2)

{

           if(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelID").value=="")
           { 
           
           alert("Please choose a hotel to update");
           clearCells();
           validated=20;
           return;
           }
           

}


thecounty=null;

clearCells();




//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelName").value=="")
{
    
//fourth row of the table


document.getElementById("hotelnamecell").style.color='red';


    //validated is not zero
    validated = 1;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();
   
} 

else
{
   
document.getElementById("hotelnamecell").style.color="#ece9d8";

}
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress1").value=="")
{
 
 document.getElementById("hoteladdress1cell").style.color="red";

  
    //validated is not zero
    validated = 2;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();

}
else

{

    //else gets the same cell and sets it's text color to be white 

    //so the asterix wil not be seen
  

    
    document.getElementById("hoteladdress1cell").style.color="#ece9d8";
   
}
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress2").value=="")
{
   
    //fifth row of the table
   document.getElementById("hoteladdress2cell").style.color="red";

    //validated is not zero
    validated = 3;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();

}

else
{
    //else gets the same cell and sets it's text color to be white 
    //so the asterix wil not be seen
  
  
 document.getElementById("hoteladdress2cell").style.color="#ece9d8";
    
}

if(buttonid==2)

{

thecounty=document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value;

}
else
{
thecounty=document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value
}


//if the value in this cell is empty
if (thecounty.trim()=="")
{  

    //color of third cell of that row is set to 'red'
    document.getElementById("hotelcountycell").style.color='red';

    //validated is not zero

    validated = 4; 
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();

}

else
{
   if(buttonid==2)

    {
       validateCounties();
    }

    else
      {
        document.getElementById("hotelcountycell").style.color="#ece9d8";
       }
} 



  

   
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelEmail").value=="")
{ 
    //seventh row of the table
      
    

    //color of third cell of that row is set to 'red'
    document.getElementById("hotelemailcell").style.color='red'; 

    //validated is not zero
    validated = 5;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring(); 
}    
else
{
    //else gets the same cell and sets it's text color to be white 
    //so the asterix wil not be seen
    
    document.getElementById("hotelemailcell").style.color="#ece9d8";
 
}  




//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value=="")
{  

   
 
    //color of sixth cell gf that row is set to 'red'

    document.getElementById("hoteltotcaproomscell").style.color='red';

    //validated is not zero
    validated = 6;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();
}
else
{
   
   //calls the isNumeric function so that it can be validated
   if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value))
    {
    //if it returns 'true' then the cells text color is set to be white 
    //so the asterix wil not be seen
    document.getElementById("hoteltotcaproomscell").style.color="#ece9d8";
    }
    else
    {
    //else it sets the color of that cell to 'blue'  
     document.getElementById("hoteltotcaproomscell").style.color='blue'; 

    //validated is not zero  
    validated = 7; 
    //shows the appropriate error string in bottom table cell
    shownonumericerrorstring();    
    }
}
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value=="")
{
    //fourth row of the table
   document.getElementById("hotelsinroomscell").style.color='red';

    //validated s not zero
    validated = 8;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();
}  
else
{
    //calls the isNumeric function so that it can be validated
   if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value))
    {
    //if it returns 'true' then the cell's text color is set to be white 
    //so the asterix wil not be seen
   document.getElementById("hotelsinroomscell").style.color="#ece9d8";
    }
    else
    {
    //else it sets the color of that cell to 'blue'



   document.getElementById("hotelsinroomscell").style.color='blue';

    //shows the appropriate error string in bottom table cell 


    shownonumericerrorstring();
    //validated is not zero  
    validated = 9; 
    }  
}  
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value=="")
{
    
    //fifth row of the table
   document.getElementById("hotelsinroomsratecell").style.color='red';

    //validated is not zero
    validated =10;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();
}

else
{
   //calls the isNumeric function so that it can be validated
   if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value))
    {
    //if it returns 'true' then the cell's text color is set to be white 
    //so the asterix wil not be seen
   document.getElementById("hotelsinroomsratecell").style.color="#ece9d8";
   
    }
    else
    {
    //else it sets the color of that cell to 'blue'
    document.getElementById("hotelsinroomsratecell").style.color='blue'; 

    //shows the appropriate error string in bottom table cell 
    shownonumericerrorstring();
    //validated is not zero
    validated = 11; 
    }  
}
//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value=="")
{
    
    //sixth row of the table
    document.getElementById("hoteldoubroomscell").style.color='red';

    //validated is not zero
    validated = 12;
    //shows the appropriate error string in bottom table cell 
    showtexterrorstring();
}
else
{
    //calls the isNumeric function so that it can be validated
    if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value))
    {
    //if it returns 'true' then the cell's text color is set to be white 
    //so the asterix wil not be seen
     document.getElementById("hoteldoubroomscell").style.color='#ece9d8';

    }
    else
    {
    //else it sets the color of that cell to 'blue'
   document.getElementById("hoteldoubroomscell").style.color='blue';

    //shows the appropriate error string in bottom table cell
    shownonumericerrorstring();
    //validated is not zero
    validated = 13;
    }  
}

//if the value in this cell is empty
if(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value=="")
{   
    //seventh row of the table
  document.getElementById("hoteldoubroomsratecell").style.color='red';

    //validated is not zero
    validated = 14;
    //shows the appropriate error string in bottom table cell
    showtexterrorstring();
}                                   
else
{
   //calls the isNumeric function so that it can be validated
   if(IsNumeric(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value))
    {
     //if it returns 'true' then the cell's text color is set to be white 
    //so the asterix wil not be seen
    document.getElementById("hoteldoubroomsratecell").style.color='#ece9d8';

    }
    else
    {
    //else it sets the color of that cell to 'blue'
   document.getElementById("hoteldoubroomsratecell").style.color='blue'; 

    //shows the appropriate error string in bottom table cell
    shownonumericerrorstring();
    //validated is not zero
    validated = 15;
    }   
}



if(validated==0)

{

validateNos(buttonid);


}
else

{

}


                       }
 
    
function validateCounties()

{
  
        var CountyValid = false;

var myCounties=new Array();

myCounties[0]="Armagh";
myCounties[1]="Antrim";
myCounties[2]="Carlow";
myCounties[3]="Cork";
myCounties[4]="Clare";
myCounties[5]="Cavan";
myCounties[6]="Dublin";
myCounties[7]="Donegal";
myCounties[8]="Down";
myCounties[9]="Derry";
myCounties[10]="Fermanagh";
myCounties[11]="Galway";
myCounties[12]="Kildare";
myCounties[13]="Kilkenny";
myCounties[14]="Kerry";
myCounties[15]="Laois";
myCounties[16]="Leitrim";
myCounties[17]="Longford";
myCounties[18]="Limerick";
myCounties[19]="Louth";
myCounties[20]="Monaghan";
myCounties[21]="Meath";
myCounties[22]="Mayo";
myCounties[23]="Offaly";
myCounties[24]="Roscommon";
myCounties[25]="Sligo";
myCounties[26]="Tipperary";
myCounties[27]="Tyrone";
myCounties[28]="Waterford";
myCounties[29]="Westmeath";
myCounties[30]="Wicklow";
myCounties[31]="Wexford";

var countyentered=document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value;


var newcountyentered=countyentered.toLowerCase();

for (var i=0; i<=31;i++)

{

thecounty=myCounties[i];



var thecountynew=thecounty.toLowerCase();






       if (thecountynew==newcountyentered.trim())
       
       {

           CountyValid = true;
           break;
       }

       
       if ((i == 31)&&(CountyValid==false))
       {
           document.getElementById("hotelcountycell").style.color='green';
                //validated is not zero

                validated = 16; 
                //shows the appropriate error string in bottom table cell 
                showcountyspellingerror();
       }

      else
      {
  document.getElementById("hotelcountycell").style.color='#ece9d8';	

// bottom table
 var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
    var rows = tbl.getElementsByTagName('tr');
    
    //second row of the table
   
    
    //color of text in first cell of that row is set to 'blue'
    var cels2 = rows[5].getElementsByTagName('td')
    
    cels2[0].innerHTML="";

   
    //text in second cell of that row is set to the appropropriate error string
    var cels2 = rows[5].getElementsByTagName('td')
    cels2[1].innerHTML= "";
    
    //fullyvalidated variable is set to false
    fullyvalidated=false;






      }

}






}

 


String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};





//ajax function that validates hotel room numbers
function validateNos(buttonid)
{

                        //to indiacte the hotel has been added successfully
                        var tbl  = document.getElementById('tblbottomdiv');
                        //gets the first row
                        var rows = tbl.getElementsByTagName('tr');


                        //gets first cell of second row and sets it's text to be 
                        //null
                        var cels4 = rows[1].getElementsByTagName('td')
                        cels4[0].innerHTML="";
                        
                        //gets second cell of second row and sets it's text to be 
                        //null
                        var cels3 = rows[1].getElementsByTagName('td')    
                        cels3[1].innerHTML="";
                        
                        //gets first cell of third row and sets it's text to be 
                        //null       
                        var cels5 = rows[2].getElementsByTagName('td')
                        cels5[0].innerHTML="";
                    
                        //gets second cell of third row and sets it's text to be 
                        //null 
                        var cels5 = rows[2].getElementsByTagName('td')    
                        cels5[1].innerHTML=""; 
                            
                        //gets first cell of fourth row and sets it's text to be 
                        //null 
                        var cels6 = rows[3].getElementsByTagName('td')
                        cels6[0].innerHTML="";
                        
                        //gets second cell of fourth row and sets it's text to be 
                        //null 
                        var cels7 = rows[3].getElementsByTagName('td') 
                        cels7[1].innerHTML=""; 

                    


var sin=parseInt(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value,10);

var doub=parseInt(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value,10);

var tot=parseInt(document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value,10);

var doubsin =doub + sin;

validated2=null;



 if((doub+sin)!=tot)
{

showtotalroomserrorstring();


}
else
{
 

          if(buttonid==1)
           {
         
         btnInsertHotel_OnClick();
           }

             if(buttonid==2)

            {
           btnUpdateHotel_OnClick();
           }
}

}








                       
 function showtexterrorstring (){
 
    // bottom table
    var tbl  = document.getElementById('tblbottomdiv');
    //gets the rows
    var rows = tbl.getElementsByTagName('tr');

    //first row of the table
    var cels2 = rows[0].getElementsByTagName('td')
    //color of text in first cell of that row is set to 'red'
    cels2[0].style.color='red';
     //text in first cell of that row is set to '*'
    cels2[0].innerHTML="*";
    
    //first row of the table
    var cels2 = rows[0].getElementsByTagName('td')
    //text in second cell of that row is set to the appropropriate error string
    cels2[1].innerHTML=blanktexterrorstring;
    
    //fullyvalidated variable is set to false
    fullyvalidated=false;
 }
  
 function shownonumericerrorstring (){
 // bottom table
 var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
    var rows = tbl.getElementsByTagName('tr');
    
    //second row of the table
    var cels = rows[1].getElementsByTagName('td')
    
    //color of text in first cell of that row is set to 'blue'
    var cels2 = rows[1].getElementsByTagName('td')
    cels2[0].style.color='blue';
    //text in first cell of that row is set to '*'
    cels2[0].innerHTML="*";

   
    //text in second cell of that row is set to the appropropriate error string
    var cels2 = rows[1].getElementsByTagName('td')
    cels2[1].innerHTML=nonnumericerrorstring;
    
    //fullyvalidated variable is set to false
    fullyvalidated=false;
 }
 
 
  function showsingleroomserrorstring (){
  
   document.getElementById("hotelsinroomscell").style.color='green';

 
    
    
   //bottom table
   var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
   var rows = tbl.getElementsByTagName('tr');

   //third row of the table
   var cels2 = rows[2].getElementsByTagName('td')
   //color of text in first cell of that row is set to 'green'
   cels2[0].style.color='green';
   //text in first cell of that row is set to '*'

   cels2[0].innerHTML="*";

   //third row of the table
   var cels2 = rows[2].getElementsByTagName('td')
   
   //text in second cell of that row is set to the appropropriate error string
   cels2[1].innerHTML=singleroomserrorstring;
   
   //fullyvalidated variable is set to false
   fullyvalidated=false;
 }
  
  
  function showdoubleroomserrorstring (){
  
    
   document.getElementById("hoteldoubroomscell").style.color='green';

 
    
    
   //bottom table 
   var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
   var rows = tbl.getElementsByTagName('tr');
   
   //fourth row of the table     

   var cels2 = rows[3].getElementsByTagName('td')
   //color of text in first cell of that row is set to 'green' 
   cels2[0].style.color='green';
   //text in first cell of that row is set to '*'
   cels2[0].innerHTML="*";

   //fourth row of the table    
   var cels2 = rows[3].getElementsByTagName('td')
   //text in second cell of that row is set to the appropropriate error string
   cels2[1].innerHTML=doubleroomserrorstring;
   
   //fullyvalidated variable is set to false
   fullyvalidated=false;
 }
  
  function showtotalroomserrorstring (){
 
   document.getElementById("hotelsinroomscell").style.color='green';

   document.getElementById("hoteldoubroomscell").style.color='green';

   document.getElementById("hoteltotcaproomscell").style.color='green';


       
   //bottom table 
   var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
   var rows = tbl.getElementsByTagName('tr');
       
   //fourth row of the table  
   var cels2 = rows[3].getElementsByTagName('td')
   //color of text in first cell of that row is set to 'green'
   cels2[0].style.color='green';
   //text in first cell of that row is set to '*'
   cels2[0].innerHTML="*";

   //fourth row of the table  
   var cels2 = rows[3].getElementsByTagName('td')
   //text in second cell of that row is set to the appropropriate error string
   cels2[1].innerHTML=totalroomserrorstring;
   
   //fullyvalidated variable is set to false
   fullyvalidated=false;  
    
 }
  
 
 function showcountyspellingerror (){
 // bottom table
 var tbl  = document.getElementById('tblbottomdiv');
   //gets the rows
    var rows = tbl.getElementsByTagName('tr');
    
    //second row of the table
   
    
    //color of text in first cell of that row is set to 'blue'
    var cels2 = rows[5].getElementsByTagName('td')
    cels2[0].style.color='green';
    //text in first cell of that row is set to '*'
    cels2[0].innerHTML="*";

   
    //text in second cell of that row is set to the appropropriate error string
    var cels2 = rows[5].getElementsByTagName('td')
    cels2[1].innerHTML= countyspellingerrorstring;
    
    //fullyvalidated variable is set to false
    fullyvalidated=false;
 
 
 
 }



  
  function isNull(val)
{
return(val==null);

}

  
                       
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
  //declare valid strings
   var strValidChars = "0123456789.";
   //declare variable that is the each character to be checked
   var strChar;
   //declare boolean result
   var blnResult = true;

   //if there is no string
   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   
   }




function btnDeleteHotel_OnClick() 
{



 

var ans = window.confirm ("Are you sure you want to delete this record?")

if (ans)
{

	    //setting requestUrl to null
	    requestUrl="";
	    //re-assigning AjaxPage to "ActivateAjax.aspx";
	    AjaxPage = "ActivateAjax.aspx";

	    //getting the values entered into the text boxes and assigning them to variables
	    var hotelID = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelID").value);
    	
	    // constructing the URL 
	    var requestUrl =AjaxPage  + "?Action=RemoveHotel&hotelID="+ hotelID;
    	
	    //calling the function that creates the XMLHTTPRequest object
	    CreateXMLHTTP();

	    // If browser supports XMLHTTPRequest object
	    if(XMLHTTP)
	    {
		    //Setting the event handler for the response
		    XMLHTTP.onreadystatechange = ShowSuccessMsg2;
    		
		    //Initializes the request object with the "GET" method of posting), 
		    //Request URL and sets the request as asynchronous="true".
		    XMLHTTP.open("GET", requestUrl, true);
    		
		    //Sends the request to server
		    XMLHTTP.send(null);		
	    }
clearHotelFields(3);
	   
}
else
{


}
   


   
}




function ShowSuccessMsg()
{

	//receiving response from server	
	
	if(XMLHTTP.readyState == 4)
	{
		//Valid Response is received
		if(XMLHTTP.status == 200)
		{			
			alert("Record successfully updated");
		}
		else //something is wrong 
		{
			alert("Could not retrieve data from the server" );
		}
		
	}
	else
	{
		 //Waiting for response for server 
	}
}


function ShowSuccessMsg2()
{

	//receiving response from server	
	
	if(XMLHTTP.readyState == 4)
	{
		//Valid Response is received
		if(XMLHTTP.status == 200)
		{			
			alert("Record successfully deleted");
		}
		else //something is wrong 
		{
			alert("Could not retrieve data from the server" );
		}
		
	}
	else
	{
		 //Waiting for response for server 
	}
}




function btnUpdateHotel_OnClick() 
{


	//setting requestUrl to null
	requestUrl="";
	//re-assigning AjaxPage to "ActivateAjax.aspx";
	AjaxPage = "ActivateAjax.aspx";

	//getting the values entered into the text boxes and assigning them to variables
	var hotelID = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelID").value);
	var hotelName = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelName").value);
    var hotelAddress1 = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress1").value);
    var hotelAddress2 = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelAddress2").value);
    var hotelCounty = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelCounty").value);
    var hotelEmail = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtHotelEmail").value);
    var totCapRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtTotCapRooms").value);
    var sinRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRooms").value);
	var sinRoomsRate = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtSinRoomsRate").value);
	var doubRooms = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRooms").value);
	var doubRoomsRate = encodeURIComponent(document.getElementById("ctl00_mainContentPlaceHolder_txtDoubRoomsRate").value);
	// constructing the URL 
	var requestUrl =AjaxPage  + "?Action=UpdateHotel&hotelID="+ hotelID
	+"&HotelName="+ hotelName
	+"&HotelAddress1="+ hotelAddress1
	+"&HotelAddress2="+ hotelAddress2
	+"&HotelCounty="+ hotelCounty
	+"&HotelEmail="+ hotelEmail
	+"&TotCapRooms="+ totCapRooms
	+"&SinRooms="+ sinRooms
	+"&SinRoomsRate="+ sinRoomsRate
	+"&DoubRooms="+ doubRooms
	+"&DoubRoomsRate=" + doubRoomsRate;
	
	//calling the function that creates the XMLHTTPRequest object
	CreateXMLHTTP();

	// If browser supports XMLHTTPRequest object
	if(XMLHTTP)
	                 {
		//Setting the event handler for the response
		XMLHTTP.onreadystatechange = ShowSuccessMsg;
		
		//Initializes the request object with the "GET" method of posting), 
		//Request URL and sets the request as asynchronous="true".
		XMLHTTP.open("GET", requestUrl, true);
		
		//Sends the request to server
		XMLHTTP.send(null);		
	
	
                //goes to the bottom table and sets the text
                        //to indiacte the hotel has been added successfully
                        var tbl  = document.getElementById('tblbottomdiv');
                        //gets the first row
                        var rows = tbl.getElementsByTagName('tr');

                        //gets first cell of first row and sets it's text to be null
                        var cels2 = rows[0].getElementsByTagName('td')
                        cels2[0].innerHTML="";
                        
                        //gets second cell of first row and sets it's text to be 
                        //'Thank you for updating your hotel'
                        
                         var cels3 = rows[0].getElementsByTagName('td')
                         cels3[1].innerHTML="Thank you for updating your hotel";
                       
                        
                        //gets first cell of second row and sets it's text to be 
                        //null
                        var cels4 = rows[1].getElementsByTagName('td')
                        cels4[0].innerHTML="";
                        
                        //gets second cell of second row and sets it's text to be 
                        //null
                        var cels3 = rows[1].getElementsByTagName('td')    
                        cels3[1].innerHTML="";
                        
                        //gets first cell of third row and sets it's text to be 
                        //null       
                        var cels5 = rows[2].getElementsByTagName('td')
                        cels5[0].innerHTML="";
                    
                        //gets second cell of third row and sets it's text to be 
                        //null 
                        var cels5 = rows[2].getElementsByTagName('td')    
                        cels5[1].innerHTML=""; 
                            
                        //gets first cell of fourth row and sets it's text to be 
                        //null 
                        var cels6 = rows[3].getElementsByTagName('td')
                        cels6[0].innerHTML="";
                        
                        //gets second cell of fourth row and sets it's text to be 
                        //null 
                        var cels7 = rows[3].getElementsByTagName('td') 
                        cels7[1].innerHTML=""; 
	                     }  

                

    }






function ShowSuccessMsg()
{

	//receiving response from server	
	
	if(XMLHTTP.readyState == 4)
	{
		//Valid Response is received
		if(XMLHTTP.status == 200)
		{			
			alert("Record successfully updated");
		}
		else //something is wrong 
		{
			alert("Could not retrieve data from the server" );
		}
		
	}
	else
	{
		 //Waiting for response for server 
	}
}


function ShowInsertSuccessMsg()
{

	//receiving response from server	
	
	if(XMLHTTP.readyState == 4)
	{
		//Valid Response is received
		if(XMLHTTP.status == 200)
		{			
			alert("Record successfully created");
		}
		else //something is wrong 
		{
			alert("Could not retrieve data from the server for insert" );
        
         }
		
	}
	else
	{
		 //Waiting for response for server 
	}
}






//function to get the inner text of variables
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}




