//XMLhttp variable will hold the XMLHttpRequest object
var xmlhttp = false;
        
// If the user is using Mozilla/Firefox/Safari/etc
if (window.XMLHttpRequest) {
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type
        //xmlhttp.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function GetRadioButtonValue(id) {
	var radio = document.getElementsByName(id);
	for (var j = 0; j < radio.length; j++) {
		if (radio[j].checked)	
		return (radio[j].value);
	}
}


function preSearch(language,accommodation) {
	
    //Put the form data into a variable
	var theQuery = document.getElementById('tourism').value;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		//document.getElementById('town_table').innerHTML = "Търся ...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
		if (language == "bg") {
			var url = '/ajax/ajax_towns_by_tourism.php?language=' + language + '&accommodation=' + accommodation + '&q=' + theQuery;
		} else {
			var url = '/pochivka/ajax/ajax_towns_by_tourism.php?language=' + language + '&accommodation=' + accommodation + '&q=' + theQuery;
		}
//document.write(url);
	
//return;

		
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('town_table').innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null);  
	}
}

//NOVA SA NOVIA SAIT
function preSearchNew(language,accommodation) {
	
    //Put the form data into a variable
	var theQuery = document.getElementById('tourism').value;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		//document.getElementById('town_table').innerHTML = "Търся ...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
		if (language == "bg") {
			var url = '/ajax/ajax_towns_by_tourism_new.php?language=' + language + '&accommodation=' + accommodation + '&q=' + theQuery;
		} else {
			var url = '/pochivka/ajax/ajax_towns_by_tourism_new.php?language=' + language + '&accommodation=' + accommodation + '&q=' + theQuery;
		}
//document.write(url);
	
//return;

		
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('town_table').innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null);  
	}
}



function updatePositionFromPrice(id) {
	
	
	
    //Put the form data into a variable
	//var theQuery = document.getElementById('price_of_vip').value;
	var theQuery = GetRadioButtonValue('radio_vip');
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById('positions_by_prices_div').innerHTML = "Моля изчакайте ...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
			var url = '/ajax/ajax_positions_by_price.php?pay=' + theQuery + '&id=' + id;
//document.write(url);
	
//return;

		
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById('positions_by_prices_div').innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null);  
	}
}

function readFileOnServer(url_to_file) {
	
	var myResponse = "";
	
    //Put the form data into a variable
	//var theQuery = document.getElementById('price_of_vip').value;
	var theQuery = url_to_file;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		//document.getElementById('positions_by_prices_div').innerHTML = "Моля изчакайте ...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
			var url = url_to_file;
//document.write(url);
	
//return;
		
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				//alert(xmlhttp.responseText + ' ');
				document.getElementById('hidden_div').innerHTML = xmlhttp.responseText;
				
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null); 
	}
	
}

function getTownInfo1(id_of_page_element,id_of_town,language) {
	
    //Put the form data into a variable
	//var theQuery = document.getElementById('price_of_vip').value;
	var theQuery = id_of_town;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById(id_of_page_element).innerHTML = "...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
			

        //This sets a variable with the URL (and query strings) to our PHP script
		if (language == "bg") {
			var url = '/ajax/town_info_for_map.php?id=' + theQuery + '&language=' + language;
		} else {
			var url = '/pochivka/ajax/town_info_for_map.php?id=' + theQuery + '&language=' + language;
		}
			
			
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById(id_of_page_element).innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null);  
	}
	
}



function getOfferInfo1(id_of_page_element,id_of_offer,language) {
	
    //Put the form data into a variable
	//var theQuery = document.getElementById('price_of_vip').value;
	var theQuery = id_of_offer;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById(id_of_page_element).innerHTML = "...";
		
        //This sets a variable with the URL (and query strings) to our PHP script
			

        //This sets a variable with the URL (and query strings) to our PHP script
		if (language == "bg") {
			var url = '/ajax/offer_info_for_map.php?id=' + theQuery + '&language=' + language;
		} else {
			var url = '/pochivka/ajax/offer_info_for_map.php?id=' + theQuery + '&language=' + language;
		}
			
			
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
				document.getElementById(id_of_page_element).innerHTML = xmlhttp.responseText + ' ';
			} else {
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		xmlhttp.send(null);  
	}
	
}










function MapLinkToTownPage(id_of_page_element,id_of_town,language) {
	
    //Put the form data into a variable
	//var theQuery = document.getElementById('price_of_vip').value;
	var theQuery = id_of_town;
	
    //If the form data is *not* blank, query the DB and return the results
	if(theQuery !== "") {
        //Change the content of the "result" DIV to "Searching..."
        //This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
		document.getElementById(id_of_page_element).innerHTML = "...do tuk dobre";
        //This sets a variable with the URL (and query strings) to our PHP script
			

        //This sets a variable with the URL (and query strings) to our PHP script
		if (language == "bg") {
			var url = '/ajax/town_link_for_map.php?id=' + theQuery + '&language=' + language;
		} else {
			var url = '/pochivka/ajax/town_link_for_map.php?id=' + theQuery + '&language=' + language;
		}
		
		//document.getElementById(id_of_page_element).innerHTML = url;
		
        //Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
		xmlhttp.open('GET', url, true);
        //Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //Replace the content of the "result" DIV with the result returned by the PHP script
                
				document.getElementById(id_of_page_element).innerHTML = xmlhttp.responseText + ' ';
			} else {
				//document.getElementById(id_of_page_element).innerHTML = xmlhttp.responseText + ' ';
				//document.getElementById(id_of_page_element).innerHTML = url;
				
                //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
				//document.getElementById('town_table').innerHTML = 'Error: preSearch Failed!';
			}
		};
		
		xmlhttp.send(null);  
	}
	
}