// JavaScript Document
// for location change
function doPost(optional){
	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		if(optional == "location"){
			url = ajax_path + "location_changer.php";
		}
		
		
		myConn.connect( url, "POST", request, function( XML ) {
				var city;
				var location;
				var location_ID;
				var byname;
				var byprice;
				var hotel;
				if(optional == "location"){
					location = document.getElementById("location_search");
					location.innerHTML = XML.responseText;
				}
			} 
		);
	
	
}

function doPostLocation(optional){

	var ajax_path = "http://www.gotophuket.com/ajax/";
	var request = "";
	var url = "";
	var myConn = new XHConn();			
	
	if(optional == "country"){
		url = ajax_path + "load_country.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "city"){
		url = ajax_path + "load_city.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "location"){
		url = ajax_path + "load_location.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "location_search"){
		url = ajax_path + "load_location_search.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "byname"){
		url = ajax_path + "load_search_byname.php?city_ID=" + check_uri('city_ID=');
	}else if(optional == "byprice"){
		url = ajax_path + "load_search_byprice.php?city_ID=" + check_uri('city_ID=');
	}else if(optional == "hotel"){
		url = ajax_path + "load_hotel.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "review"){
		url = ajax_path + "load_review.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}else if(optional == "recommend"){
		url = ajax_path + "load_recommendation.php?country_ID=" + check_uri('country_ID=') + "&city_ID=" + check_uri('city_ID=');
	}
	
	myConn.connect( url, "POST", request, function( XML ) {
			var element;			
			if(optional == "country"){
				element = document.getElementById("country");
				element.innerHTML = XML.responseText;
				doPostLocation('city');
			}else if(optional == "city"){
				element = document.getElementById("city");
				element.innerHTML = XML.responseText;
				doPostLocation('location');
			}else if(optional == "location"){
				element = document.getElementById("location");
				element.innerHTML = XML.responseText;
				doPostLocation('byname');
				doPostLocation('byprice');
				doPostLocation('hotel');
				doPostLocation('review');
				doPostLocation('recommend');
			}else if(optional == "location_search"){
				element = document.getElementById("location_search");
				element.innerHTML = XML.responseText;
			}else if(optional == "byname"){
				element = document.getElementById("byname");
				element.innerHTML = XML.responseText;
			}else if(optional == "byprice"){
				element = document.getElementById("byprice");
				element.innerHTML = XML.responseText;
			}else if(optional == "hotel"){
				element = document.getElementById("hotel");
				element.innerHTML = XML.responseText;
			}else if(optional == "review"){
				element = document.getElementById("review");
				element.innerHTML = XML.responseText;
			}else if(optional == "recommend"){
				element = document.getElementById("recommend");
				element.innerHTML = XML.responseText;
			}
			
		} 
	);
	
}

//script for get value of uri parameter in url
function check_uri(findStr){
	var url = location.href;
	var posQuery = (url.search(/\?/));
	var posStr;
	var foundStr = "";
	var strQuery = "";
	var aryStrQuery;
	

	if(posQuery > 0){
		strQuery = url.substring((posQuery)+1, url.length);
	}
	
	aryStrQuery = strQuery.split("&");
	
	
	for(i=0; i<aryStrQuery.length; i++){
		posStr = (aryStrQuery[i].search(findStr));
		if(posStr != -1){
			foundStr = aryStrQuery[i].substring((posStr+findStr.length), aryStrQuery[i].length);			
		}
	}
	return foundStr;
}


//-----------------------------------random recommendation-------------------------------

function doPostRandomRecomend(cityId, elementId){
	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "random_recommendation.php?city_ID=" + cityId;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
	
}

//------------------------------------show hotel rate------------------------------------------
function doPostHotelRateAgent(hotelId, elementId){
	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "rate.php?hotelId=" + hotelId;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}

//------------------------------------show hotel by location------------------------------------------
function doPostHotelByLocation(locationId, elementId){
	
	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "hotelbylocation.php?location_ID=" + locationId;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}

function doPostHotelByLocationList(location, elementId){
	
	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "hotelbylocationlist.php?location=" + location;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}

////------------------------------------show random recommend hotel------------------------------------------
function doPostHotelRecommend(elementId){
	

	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "recommendation.php?city_ID=35";
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}

function doPostHotelRecommendSelection(elementId, noofhotel){
	

	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "recommendation.php?city_ID=35&noofhotel=" + noofhotel;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}

function doPostHotelByLocationSelection(elementId, location ,noofhotel){
	

	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "hotelbylocation_selection.php?city_ID=35&location=" + location  + "&noofhotel=" + noofhotel;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}



////------------------------------------show random recommend tour------------------------------------------
function doPostTourRecommendSelection(elementId, noofrandom){
	

	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "recommendtour.php?city_ID=35&noofrandom=" + noofrandom;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}


////------------------------------------show random review hotel------------------------------------------
function doPostHotelReview(elementId, noofreview){
	

	var ajax_path = "http://www.gotophuket.com/ajax/";

	var request = "";
	var url = "";
	var myConn = new XHConn();		
	
		
		url = ajax_path + "review.php?city_ID=35&noofreview=" +  noofreview;
		
		myConn.connect( url, "POST", request, function( XML ) {
				var element;
				
				element = document.getElementById(elementId);
				element.innerHTML = XML.responseText;
			} 
		);
	
}
