var url = '../../../../../ajax/';


var QuickSearchFormRCCP = url+'ajax_rccp_quicksearch_form.php';
var PropertyFormRCCP = url+'ajax_rccp_property_form.php';
var PropertyFormTotalPrice = url+'ajax_property_form_totalprice.php';
var PropertyFormGoogleMap = url+'ajax_property_form_google.php';
var AutomaticSearchFormRCCP = url+'ajax_rccp_automaticsearch_form.php';
var PropertyShowPrice = url+'ajax_property_show_price.php';

var xmlRequest_QuickSearchForm = createRequestObject();
var xmlRequest_PropertyFormRCCP = createRequestObject();
var xmlRequest_PropertyFormTotalPrice = createRequestObject();
var xmlRequest_PropertyFormGoogleMap = createRequestObject();
var xmlRequest_AutomaticSearchForm = createRequestObject();
var xmlRequest_PropertyShowPrice = createRequestObject();


function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        //ro = new ActiveXObject("Microsoft.XMLHTTP");
        try {
       		ro = new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e) {
       		ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
        //alert('Internet Explorer ');
    }else{
        ro = new XMLHttpRequest();
        //alert('Firefox, Safari...');
    }
    return ro;
}

/*******/

function getQSearchRCCP(countryID, regionID, cityID, citypartID, retID) {
	var args = QuickSearchFormRCCP+'?countryID='+countryID+'&regionID='+regionID+'&cityID='+cityID+'&citypartID='+citypartID;
		
	xmlRequest_QuickSearchForm.open('GET', args, true);
	xmlRequest_QuickSearchForm.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_QuickSearchForm.onreadystatechange = function() { AjaxQuickSearchRCCP(retID); };
    xmlRequest_QuickSearchForm.send(null);
}

function AjaxQuickSearchRCCP(retID) {
	var ret = document.getElementById(retID);
 	if(xmlRequest_QuickSearchForm.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_QuickSearchForm.readyState == 4) ret.innerHTML = xmlRequest_QuickSearchForm.responseText;   
}

/********************/

function getPropertyRCCP(countryID, regionID, cityID, citypartID, retID) {
	var args = PropertyFormRCCP+'?countryID='+countryID+'&regionID='+regionID+'&cityID='+cityID+'&citypartID='+citypartID;
		
	xmlRequest_PropertyFormRCCP.open('GET', args, true);
	xmlRequest_PropertyFormRCCP.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_PropertyFormRCCP.onreadystatechange = function() { AjaxPropertyRCCP(retID); };
    xmlRequest_PropertyFormRCCP.send(null);
}

function AjaxPropertyRCCP(retID) {
	var ret = document.getElementById(retID);
 	if(xmlRequest_PropertyFormRCCP.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_PropertyFormRCCP.readyState == 4) ret.innerHTML = xmlRequest_PropertyFormRCCP.responseText;   
}

/********************/

function getPropertyTotalPrice(retID){
	var client_price = document.getElementById('client_price').value;
	var client_price_vat = document.getElementById('client_price_vat').value;
	var extra_charge_price = document.getElementById('extra_charge_price').value;
	var extra_charge_percent = document.getElementById('extra_charge_percent').value;
	var extra_charge_vat = document.getElementById('extra_charge_vat').value;
	var countryID = document.getElementById('countryID').value;
	var args = PropertyFormTotalPrice+'?client_price='+client_price+'&client_price_vat='+client_price_vat+'&extra_charge_price='+extra_charge_price+'&extra_charge_percent='+extra_charge_percent+'&extra_charge_vat='+extra_charge_vat+'&countryID='+countryID;
	
	xmlRequest_PropertyFormTotalPrice.open('GET', args, true);
	xmlRequest_PropertyFormTotalPrice.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_PropertyFormTotalPrice.onreadystatechange = function() { AjaxTotalPrice(retID); };
    xmlRequest_PropertyFormTotalPrice.send(null);
}

function AjaxTotalPrice(retID) {
	var ret = document.getElementById(retID);
 	//if(xmlRequest_PropertyFormTotalPrice.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_PropertyFormTotalPrice.readyState == 4) ret.value = xmlRequest_PropertyFormTotalPrice.responseText;
}

/********************/

function getPropertyGoogleMap(retID){
	var country = document.getElementById('countryID');
	var city = document.getElementById('cityID');
	var address = document.getElementById('ofaddress').value;
	var args;
	if(!city || city.value=="0") 
		args = PropertyFormGoogleMap+'?country='+country.options[country.selectedIndex].text+'&address='+address;
	else 
		args = PropertyFormGoogleMap+'?country='+country.options[country.selectedIndex].text+'&city='+city.options[city.selectedIndex].text+'&address='+address;
	
	xmlRequest_PropertyFormGoogleMap.open('GET', args, true);
	xmlRequest_PropertyFormGoogleMap.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_PropertyFormGoogleMap.onreadystatechange = function() { AjaxGoogleMap(retID); };
    xmlRequest_PropertyFormGoogleMap.send(null);
}

function AjaxGoogleMap(retID) {
	var ret = document.getElementById(retID);
 	if(xmlRequest_PropertyFormGoogleMap.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_PropertyFormGoogleMap.readyState == 4) ret.innerHTML = xmlRequest_PropertyFormGoogleMap.responseText;   
}


/********************/

function getAutomaticSearchRCCP(countryID, regionID, cityID, citypartID, retID) {
	var args = AutomaticSearchFormRCCP+'?countryID='+countryID+'&regionID='+regionID+'&cityID='+cityID+'&citypartID='+citypartID;
		
	xmlRequest_AutomaticSearchForm.open('GET', args, true);
	xmlRequest_AutomaticSearchForm.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_AutomaticSearchForm.onreadystatechange = function() { AjaxAutomaticSearchRCCP(retID); };
    xmlRequest_AutomaticSearchForm.send(null);
}

function AjaxAutomaticSearchRCCP(retID) {
	var ret = document.getElementById(retID);
 	if(xmlRequest_AutomaticSearchForm.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_AutomaticSearchForm.readyState == 4) ret.innerHTML = xmlRequest_AutomaticSearchForm.responseText;   
}

/********************/

function getPropertyPrice(price, currencyIN, currencyOUT, retID) {
	var args = PropertyShowPrice+'?price='+price+'&currencyIN='+currencyIN+'&currencyOUT='+currencyOUT;
		
	xmlRequest_PropertyShowPrice.open('GET', args, true);
	xmlRequest_PropertyShowPrice.setRequestHeader("Content-Type", "application/x-www-formurlencoded");
	xmlRequest_PropertyShowPrice.onreadystatechange = function() { AjaxPropertyShowPrice(retID); };
    xmlRequest_PropertyShowPrice.send(null);
}

function AjaxPropertyShowPrice(retID) {
	var ret = document.getElementById(retID);
 	if(xmlRequest_PropertyShowPrice.readyState == 1) ret.innerHTML = "<center>LOADING...</center>";
    if(xmlRequest_PropertyShowPrice.readyState == 4) ret.innerHTML = xmlRequest_PropertyShowPrice.responseText;   
}

/********************/
