//holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject(){
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP",
		"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp){
	alert("Error creating the XMLHttpRequest object.");
	}
	return xmlHttp;
}
function delete_temp_add_vila_picture(id){
	var answer = confirm("האם אתה בטוח שברצונך למחוק את התמונה?")
	if (answer){
		var url = "delete_add_vila_picture.php";
		var params = "vila_id="+id;
		xmlHttp.open("POST", url, true);
		xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
				alert('התמונה נמחקה בהצלחה');
				var temp = xmlHttp.responseText;
				var f = parent.document.getElementById('view_vila_pictures_upload');
				f.contentWindow.location.reload(true);
			}
		}
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.send(params);
		return true;
	}
}

function advance_search_area_2(value){
	if(value!=''){
		var theSel = document.getElementById('third_area_select');
		
		for(i=theSel.options.length-1;i>=0;i--){
			theSel.remove(i);
		}
		
		var url = "functions/area_2_adv_search.php";
		var params = "id="+value;
		xmlHttp.open("POST", url, true);
		xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){						 
				var temp = xmlHttp.responseText;
				var spl = temp.split('#')
				
				theSel.options[theSel.length] = new Option('כל הישובים', '');
				for(var i=1; i<spl.length; i++){
					var spl2 = spl[i].split('%')
					theSel.options[theSel.length] = new Option(spl2[1], spl2[0]);
				}
			}
		}
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.send(params);
		return true;
	}
}
function advance_search_area_1(value){
	if(value!=''){
		var theSel = document.getElementById('second_area_select');
		
		for(i=theSel.options.length-1;i>=0;i--){
			theSel.remove(i);
		}
		
		var url = "functions/area_1_adv_search.php";
		var params = "id="+value;
		xmlHttp.open("POST", url, true);
		xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){						 
				var temp = xmlHttp.responseText;
				var spl = temp.split('#')
				
				theSel.options[theSel.length] = new Option('כל אזורי המשנה', '');
				for(var i=1; i<spl.length; i++){
					var spl2 = spl[i].split('%')
					theSel.options[theSel.length] = new Option(spl2[1], spl2[0]);
				}
			}
		}
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		xmlHttp.send(params);
		return true;
	}
}
function move_to_area_1(){
	var w = document.getElementById('area_1').selectedIndex;
	var selected_text = document.getElementById('area_1').options[w].text;
	
	var temp = selected_text = selected_text.replace(' ','-');
	
	window.location = 'http://www.goholiday.co.il/וילות-ב'+temp+'.html';
}
function move_to_area_2(){
	var w = document.getElementById('second_area_select').selectedIndex;
	var selected_text = document.getElementById('second_area_select').options[w].text;
	
	var temp = selected_text.replace(' ','-');
	window.location = 'http://www.goholiday.co.il/וילות-ב'+temp+'.html';
}
function move_to_area_3(){
	var w = document.getElementById('third_area_select').selectedIndex;
	var selected_text = document.getElementById('third_area_select').options[w].text;
	
	var temp = selected_text.replace(' ','-');
	window.location = 'http://www.goholiday.co.il/וילות-ב'+temp+'.html';
}
