/*
	byO.es // 2006-10
	ajax v0.1
*/
var ajax = new GLM.AJAX();
var container;

function js_array_to_php_array (a) {
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
}

function ajaxCallback(content) {

//	alert(content);
	document.getElementById(container).innerHTML= content;
	
	//alert(content);

}
function logoutCallback(content){
	document.getElementById(container).innerHTML= content;
}

function getCity(province, active, urlvar) {

	container= 'contCity';

	tmp= '';
	if (active==true) tmp= 'Active';

	ajax.callPage(urlvar+"ajax.php?function=get"+tmp+"City&province="+province, ajaxCallback);

}

function getPrice(type, urlvar) {
	var _urltype = '';
	switch(type)
	{
		case 'sell':
			_urltype = 'property-for-sale/';
			break;
		case 'rent':
			_urltype = 'property-to-let/';
			break;
		default:
		case '':
			_urltype = 'property-for-sale/';
			break;
	}
	document.getElementById("search").action= urlvar+_urltype;
	
	container= 'contPrices';
	//ajax.callPage(urlvar+"ajax.php?function=getPrice&type="+type, ajaxCallback);
	

}

function getPriceComm(type, urlvar) {
	document.getElementById("search").action= urlvar+'commercial-property/';	
	container= 'contPrices';
	//ajax.callPage(urlvar+"ajax.php?function=getPriceComm&type="+type, ajaxCallback);
}

function logout(urlvar){	
	container='content';
	ajax.callPage(urlvar+"ajax.php?function=logout", logoutCallback);
}

function getOptions(type) {	
	container= 'contOptions';
	// patch for the form
	crurrentType= type;
	//dynForm();
	// /patch for the form	
	ajax.callPage("ajax.php?function=getOptions&type="+type, ajaxCallback);		
}

