/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
/* Function called to get the city list */
function chk_email(email_id){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'intermediate.php?mode=chk_email&email_id='+email_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleEmail; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleEmail(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
			var response='';
		var response = http.responseText;
			//alert(response);
		resp_ary=response.split('@@');
		//alert(resp_ary[1]);
		if(resp_ary[0]==1)
		{
			document.getElementById('signup_email').value = '';
			document.getElementById('tag_Email').className='red';

		}
		document.getElementById('tag_Email').innerHTML ='<font class\"red\">'+resp_ary[1]+'</font>';
				
	}
}


function chk_subscriber(email_id){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'intermediate.php?mode=chk_scriber&email_id='+email_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleSubscriber; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function  handleSubscriber(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		//alert(response);
		resp_ary=response.split('@@');
		
		if(resp_ary[0]==1)
		{
			document.getElementById('email').value = '';
			
			document.getElementById('sub_news_error').innerHTML = '<font class\"error\">'+resp_ary[1]+'</font>';
			
		}
		
	}
}


function calculate_milage(from,to){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'getmilage.php?from='+from+'&to='+to);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = function (){
		if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
			var response='';
		var response = http.responseText;
	//alert('Please enter valid postcode');
	alert(response);
	return response;
		
	}
	}
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function check_coupan_code(coupan_code,book_price)
{
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'intermediate.php?mode=chk_coupan_code&coupan_code='+coupan_code+'&book_price='+book_price);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handlecoupan; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
function handlecoupan(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		
		resp_ary=response.split('@@');
		
		if(resp_ary[0]==1)
		{
			document.getElementById('coupan_code').value = '';
			document.getElementById('tag_coupan_id').innerHTML = resp_ary[1];
			document.getElementById('cp_flag').value=1;
		}
		else 
		{
		
		document.getElementById('tag_coupan_id').innerHTML = resp_ary[1];
		//price = number_format(resp_ary[2],2);
		document.getElementById('tag_book_price').innerHTML = 'Your final booking amount is: £'+resp_ary[2];
		document.getElementById('dis_book_price').value= resp_ary[2];
		document.getElementById('cp_id').value= resp_ary[3];
				
		document.getElementById('cp_flag').value=1;
		}
	}
}


function backend_subscriber(email_id){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
//	alert("dsaf");
	http.open('get', 'intermediate.php?mode=bk_email&email_id='+email_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handle_subscriber; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function  handle_subscriber(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		//alert(response);
		resp_ary=response.split('@@');
		
		if(resp_ary[0]==1)
		{
			document.getElementById('x_email').value = '';
			
			document.getElementById('sub_news_error').innerHTML = '<font class\"error\">'+resp_ary[1]+'</font>';
			
		}
		
	}
}
function session_out(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
//	alert("dsaf");
	http.open('get', 'intermediate.php?mode=session_out');
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handle_session_out; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
/* Function called to handle the list that was returned from the internal_request.php file.. */
function  handle_session_out(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		
		
	}
}
function get_fill_dest(pickup_airport)
{
	
	http.open('get', 'intermediate.php?mode=fill_dest&pickup_airport='+pickup_airport);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handle_fill_dest; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
function  handle_fill_dest(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		document.getElementById('des_airport_html').innerHTML = response;
		
	}
}

function reFresh() {
  location.reload(true)
}
