var closewindow = true;
var openwindow = '';

function get (el) {
	return document.getElementById(el);
}

function ins_city(town_id,town_name){
	townBox = get("town");
	townBox.options[townBox.options.length] = new Option(town_name, town_id, false, true);
}
////////////////////////////////////////////////// rule pop up windows in user navigation
function show_bar(name, id, type, path) {

	if (type == 1)
		var max = '3';
	else
		var max = '5';

	var show_path = '';	
	if (path == '1')
		show_path = '../';
	if ((closewindow == true) && (openwindow != '')) {
		get(openwindow).style.visibility="hidden";		
	}
	openwindow = name + "[" + id + "]";
	obj = get(openwindow);
	obj.style.visibility = "visible";
	if (name == 'win') {
		get("nav_icon").innerHTML = '<img src="' + show_path + 'img/icon/close.gif" alt="close" class="pop_close" onclick="hide_bars(&quot;' + name + '&quot;, &quot;' + type + '&quot;, &quot;' + max + '&quot;, &quot;' + path + '&quot;)" />';
		
		get("tab" + id).src = show_path + 'img/navigation/' + type + '/top' + id +'_1.gif';
		for (var i = 1; i <=max; i++) {
			if (i != id) {
				get(name +"[" + i + "]").style.visibility="hidden";
				get('tab' + i).src = show_path + 'img/navigation/' + type + '/top' + i +'.gif';
			}		
		}
	}
}
function close_bar() {
	if ((closewindow == true) && (openwindow != '')) {
		get(openwindow).style.visibility="hidden";
	}
}
function hide_bars(name, type, max, path) {
	var show_path = '';	
	if (path == '1')
		show_path = '../';
	get("nav_icon").innerHTML = '<img src="' + show_path + 'img/icon/help.gif" alt="help" />';
	
	for (var i = 1; i <=max; i++) {
		get(name + "[" + i + "]").style.visibility="hidden";
		get('tab' + i).src = show_path + 'img/navigation/' + type + '/top' + i +'.gif';
	}
}
function close_window(id) {
	get(id).style.visibility="hidden";
}

function hide_bar(id) {

	get("win[" + id + "]").style.visibility="hidden";
	get("nav_icon").innerHTML = '<img src="img/icon/help.gif" alt="help" />';
	
	get("tab" + id).src = 'img/tab/top' + id + '.gif';	
}

//////////////////////////////////////////////////
function get_properties_results(){
	if(window.location.search.get('gmap')){
		GUnload();
		load();
	}else{
		
		var bottomPrice = get("hidBottomPrice");
		var topPrice = get("hidTopPrice");
		var pageno = get("pageno").value;
		var bed = get("hidBeds").value
		var url = get("url").value;
		var pageno2="";
		pageno2 = '&pageno='+pageno;
		//alert(get_window_location_search());
		//alert(getURLVar('s_p_from', url));
		bed1="";
		pricemin1="";
		pricemax1="";
		if(bed > 0){
			bed1 = '&beds='+bed;
		}
		if(bottomPrice.value > 0){
			pricemin1 = '&pricemin='+bottomPrice.value;
		}
		if(topPrice.value > 0){
			pricemax1 = '&pricemax='+topPrice.value;
		}
		link = bed1+pricemin1+pricemax1+pageno2;
		get("url2").value = link;
		new Ajax.Updater('ajaxseach', 'getProperties.php'+window.location.search+link, { method: 'get' , 
   		onCreate: function(){
			get("loadsearch").style.display="block";
			},
   		onSuccess: function(){
			get("loadsearch").style.display="none";
			}
		});
		
		//ajaxdisplay('getProperties.php'+window.location.search+'&beds='+bed+'&pricemin='+bottomPrice.value+'&pricemax='+topPrice.value+pageno2, 'loadsearch', 'ajaxseach')
	}
}
//////////////////////////////////////////////////
function changePrice(price){
	var n = 16;
	
}
////////////////////////////////////////////////// rules for nonstandard checkboxes
function checked (divs, box) {
	var obj = get(box); 
	if (obj.value == 1)
		ground = "url(/img/icon/ch0.gif) no-repeat";
	else
		ground = "url(/img/icon/ch1.gif) no-repeat";
	get(divs).style.background = ground;
	obj.value = Math.abs(obj.value - 1);
}
////////////////////////////////////////////////// rules for nonstandard checkboxes: edit property info
function checked_edit (divs, box) {
	var obj = get(box); 
	if (obj.value == 1) {
		ground = "url(/img/icon/ch0.gif) no-repeat";
		get("status_text").innerHTML = "Hidden on the site";
	}
	else {
		ground = "url(/img/icon/ch1.gif) no-repeat";
		get("status_text").innerHTML = "Shown on the site";
	}
	get(divs).style.background = ground;
	obj.value = Math.abs(obj.value - 1);
}
////////////////////////////////////////////////// rules for nonstandard radiobuttons
function radio (num) {
	var ch0 = new Image;
	var ch1 = new Image;
	ch0.src = "/img/icon/ch0.gif";
	ch1.src = "/img/icon/ch1.gif";
	sel = get("groupbox").value;
	get("div1").style.background = "url(" + ch0.src + ") no-repeat";
	if (num != sel) {
		if (sel != 0) {
			get("div"+sel).style.background = "url(" + ch0.src + ") no-repeat";
		}
		get("div"+num).style.background = "url(" + ch1.src + ") no-repeat";
		get("groupbox").value = num;

	}
} 
////////////////////////////////////////////////// show or hide some block by click on link
function showHide (id) {
	var myDiv = get(id);	
	if (myDiv.style.display == 'none') {
		myDiv.style.display = 'block';
	}
	else {
		myDiv.style.display = 'none';
	}
	return false;
}

////////////////////////////////////////////////// add input field in form
function AddParam (form, tool, property) {
	var params = document.forms[form].num_names.value;
	div = get("tool_names_"+property);
	button = get("new_add_"+property);
	params++;
	qnt = params;
	var ID = Math.floor(Math.random() * (9999 - 10 + 1)) + 10;
	newparam = "<input type=\"text\" name=\"" + tool + "_tool" + tool + "_address_" + params + "\" maxlength=\"255\"> <br>";  
	newnode = document.createElement("span");
	newnode.setAttribute('id',ID);
	newnode.innerHTML = newparam;
	div.insertBefore (newnode, button);
	document.forms[form].num_names.value = qnt;
}
////////////////////////////////////////////////// delete input field in form
function DelParam(ID, pdiv){
 	var olddiv = get(pdiv);
    olddiv.removeChild(ID);
}
////////////////////////////////////////////////// functions for check registration form
function checkForm(type) {	
	var err = true;
	var error_class = 'form_error';
	if (drop_spaces(trim(get("r_f_name").value)) == '' || get("r_f_name").value == 'First name') {
		get("r_f_name").className = error_class;
		get("r_f_name_err").innerHTML = "Please fill your first name";
		err = false;
	}
	if (drop_spaces(trim(get("r_s_name").value)) == '' || get("r_s_name").value == 'Surname') {
		get("r_s_name").className = error_class;
		get("r_s_name_err").innerHTML = "Please fill your last name";
		err = false;
	}
	if (type == 1) {
	
		var mandatory_text = ' Please enter all fields. ';
		/*
		if (drop_spaces(trim(get("r_address").value)) == '') {
			get("r_address").className = error_class;
			get("r_address").value = '';
			get("r_address_err").innerHTML = "Please fill your address";
			err = false;
		}
		if (drop_spaces(trim(get("r_postcode").value)) == '') {
			get("r_postcode").className = error_class;
			get("r_postcode").value = '';
			get("r_postcode_err").innerHTML = "Please fill your postcode";
			err = false;
		}
		*/
		if (get('email_dop')) {
			if (drop_spaces(trim(get("email_dop").value)) != '') {
				var email_dop = get("email_dop").value; 
				email_dop = trim(email_dop);
				if (!check_email(email_dop)) {
					get("email_dop").className = error_class;
					err = false;
					if (drop_spaces(trim(get("email_dop").value)) == '') {
						get("email_dop").value = '';
					}
				}
			}
		}
		if (get('email1')) {
			if (drop_spaces(trim(get("email1").value)) != '') {
				var email1 = get("email1").value; 
				email1 = trim(email1);
				if (!check_email(email1)) {
					get("email1").className = error_class;
					err = false;
				}
			}
		}
		if (get('email2')) {
			if (drop_spaces(trim(get("email2").value)) != '') {
				var email2 = get("email2").value; 
				email2 = trim(email2);
				if (!check_email(email2)) {
					get("email2").className = error_class;
					err = false;
				}
			}
		}
		if (drop_spaces(trim(get("r_landline").value)) == '' && drop_spaces(trim(get("r_mobile").value)) == '') {
			get("r_landline").className = error_class;
			get("r_landline").value = '';
			get("r_mobile").className = error_class;
			get("r_mobile").value = '';
			err = false;
			get('r_landline_err').innerHTML = 'Please enter landline phone or mobile phone';
		} else {
			if (drop_spaces(trim(get("r_mobile").value)) != '') {
				if (drop_spaces(trim(get("r_mobile").value)) != '') {
					var r_mobile = drop_spaces(trim(get("r_mobile").value));
					if (!check_digits (r_mobile, '11')) {
						get("r_mobile").className = error_class;
						get("r_mobile_err").innerHTML = "Please check your mobile phone";
						err = false;
					}
				}
			}
		}

	}
	if (!get("update_details")) {	
		if (drop_spaces(trim(get("r_pass").value)) == '') {
			get("r_pass").className = error_class;
			get("r_pass").value = '';
			get("r_pass_err").innerHTML = "Please create password";
			err = false;
		}
		if (drop_spaces(trim(get("r_cpass").value)) == '') {
			get("r_cpass").className = error_class;
			get("r_cpass").value = '';
			get("r_cpass_err").innerHTML = "Please confirm password";
			err = false;
		}
		if (get("r_pass").value > 0 && get("r_cpass").value > '') {	
			if (get("r_pass").value != get("r_cpass").value) {
				
				get("r_cpass").className = error_class;
				get("r_cpass_err").innerHTML = "Wrong password confirm";
				err = false;
			}
		}
		
		var email = get("r_email").value; 
		email = trim(email);
		if (!check_email(email)) {
			get("r_email").className = error_class;
			get("r_email_err").innerHTML = "Wrong email address";
			err = false;
			if (drop_spaces(trim(get("r_email").value)) == '') {
				get("r_email").value = '';
			}
		}
		if (get("r_terms").value == 0) {
			get("r_terms").className = error_class;
			get("r_terms_err").innerHTML = "Please read Terms of Use";
			err = false;
		}
		
		if (get('ex_email')) {
			if (get('ex_email').value == '1') {
				get("r_email").className = error_class;
				err = false;
			}
		}
		
	} else {
		get('up_result').innerHTML = '<br />';
	}
	return err;
}
////////////////////////////////////////////////// functions for check form with add and edit property
function checkPropertyForm() {
	var err = true;
	var error_class = 'form_error';
	var error_text = 'form_error_text';
	
	if (!get('active')) {
		if (get("select_type").value == '0') {
			get("select_type").className = error_class;
			get("p_select_type_err").innerHTML = "Please select Type of property";
			get("p_select_type_err").className = error_text;
			err = false;
		}
		
		if (drop_spaces(trim(get("p_house").value)) == '') {
			get("p_house").className = error_class;
			get("p_house").value = '';
			get("p_house_err").innerHTML = "Please fill House Number";
			get("p_house_err").className = error_text;
			err = false;
		}
		if (drop_spaces(trim(get("p_road").value)) == '') {
			get("p_road").className = error_class;
			get("p_road").value = '';
			get("p_road_err").innerHTML = "Please fill Road Name ";
			get("p_road_err").className = error_text;
			err = false;
		}
		if (drop_spaces(trim(get("p_postcode").value)) == '') {
			get("p_postcode").className = error_class;
			get("p_postcode").value = '';
			get("p_postcode_err").innerHTML = "Please fill Postcode";
			get("p_postcode_err").className = error_text;
			err = false;
		}
		if (drop_spaces(trim(get("town").value)) == 0) {
			get("town").className = error_class;
			get("area").className = error_class;
			get("town_err").innerHTML = "Please select borough";
			get("town_err").className = error_text;
			err = false;
		}
	}
	
	var rent = get("p_rent").value;
	if (!isFloat(rent)) {
		get("p_rent").className = error_class;
		get("p_rent_err").innerHTML = "Wrong sum, example: 350.50 or 150";
		get("p_rent_err").className = error_text;
		get("rent_example").innerHTML = "";
		if (drop_spaces(trim(get("p_rent").value)) == '') {
			get("p_rent").value = '';
		}
		err = false;
	}
	
	var deposit = get("p_deposit").value;
	if (deposit != '') {
		if (deposit != '0') {
			if (!isFloat(deposit)) {
				get("p_deposit").className = error_class;
				get("p_deposit_err").innerHTML = "Wrong Deposit rent, example: 350.50 or 150";
				get("p_deposit_err").className = error_text;
				get("deposit_example").innerHTML = "";
				if (drop_spaces(trim(get("p_deposit").value)) == '') {
					get("p_deposit").value = '';
				}
				err = false;
			}
				}
	}
	
	if (get("ft_option")) {
		if (get("ft1").checked == false && get("ft2").checked == false) {
			get("ft_err").innerHTML = "Please select<br />";
			get("ft_err").className = error_text;
			err = false;
		}
	}
	return err;
}
////////////////////////////////////////////////// check agree checkbox
function checkRequestForm() {
	var err = true;
	if (get("r_agree").value == 0) {
		get("r_agree_err").innerHTML = "Please read Terms of Use";
  		err = false;
  	}  	
	return err;
}
////////////////////////////////////////////////// functions for check send message to friend form
function checkEmailFriendForm() {
	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	var u_email = get("u_email").value; 
	if (!check_email(u_email)) {
		get("u_email").className = error_class;
		get("u_email_err").innerHTML = "Wrong email address";
		get("u_email_err").className = error_text;
		err = false;
		if (drop_spaces(trim(get("u_email").value)) == '') {
			get("u_email").value = '';
		}
  	}
	var r_email = get("r_email").value; 
	if (!check_email(r_email)) {
		get("r_email").className = error_class;
		get("r_email_err").innerHTML = "Wrong email address";
		get("r_email_err").className = error_text;
		err = false;
		if (drop_spaces(trim(get("r_email").value)) == '') {
			get("r_email").value = '';
		}
  	}
	if (drop_spaces(trim(get("u_name").value)) == '') {
		get("u_name").className = error_class;
		get("u_name").value = '';
		get("u_name_err").innerHTML = "Please fill your name";
		get("u_name_err").className = error_text;
		err = false;
	}
	if (drop_spaces(trim(get("r_name").value)) == '') {
		get("r_name").className = error_class;
		get("r_name").value = '';
		get("r_name_err").innerHTML = "Please fill recipient name";
		get("r_name_err").className = error_text;
		err = false;
	}
	if (drop_spaces(trim(get("mess").value)) == '') {
		get("mess").className = error_class;
		get("mess").value = '';
		get("mess_err").innerHTML = "Please fill message";
		get("mess_err").className = error_text;
		err = false;
	}
	return err;
}
function drop_spaces(str) {
    var newstr = trim(str);
    return newstr.replace(/(\s)+/g, ""); 
}
function trim(str) {
    var newstr = str.replace(/^\s*(.+?)\s*$/, "$1");
    if (newstr == " ") {
        return "";
    }
    return newstr;
}
/*
function check_email(email) {
    var template = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
    email = drop_spaces(email);
    if (template.test(email)) {
        return true;
    }
    return false; 
}
*/
function check_email (email) {
    //var template = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
    var template =  /^[A-Za-z0-9](([\.\-]?[a-zA-Z0-9_]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
    if (template.test(email)) {
        return true;
    }
    return false; 
}
function isFloat (summ) {
	if (summ.length > 0) {
		var template = /^-?\d+[\.|\,]?\d*$/;
		summ = drop_spaces(summ);
		if (template.test(summ)) 
			return true;
		else 
			return false;
	}
	else
		return false;
}
function setBorder(id) {
	if (get(id))
		get(id).className = 'form_field';
	if (get(id+"_err"))
		get(id+"_err").innerHTML = "";
}
function setRegBorder(id) {
	if (get(id))
		get(id).className = 'form_field';
}
function setBorderForm(id) {
	if (get(id)) {
		get(id).className = 'form_field';
	}
	if (get(id+"_err"))
		get(id+"_err").className = '';
}
function setMessBorderForm(id, message) {
	if (get(id)) {
		get(id).className = 'form_field';
	}
	if (get(id+"_err")) {
		get(id+"_err").className = '';
		get(id+"_err").innerHTML = message;
	}
}
function setBorderName(id) {
	get(id).className = 'form_field_name';
	get(id+"_err").innerHTML = "";
}
function clearBorder(id, cname) {
	if (get(id))
		get(id).className = cname;
	if (get(id+"_err"))
		get(id+"_err").innerHTML = "";
}
function backBorder(id) {
	if (get(id))
		get(id).className = '';
}
////////////////////////////////////////////////// clear set payment form
function clearError(id) {
	get(id).innerHTML = "";
}
var window_close = function () {
	window.location.reload(false);		
}

////////////////////////////////////////////////// delete cookie
function logout () {
	var expireDate = new Date();
	date.setTime(date.getTime()-1);
	var expires = "; expires="+expireDate.toGMTString();
	document.cookie = "user_id="+"'.$user_info['user_id'].'"+expires+"; path=/";
	document.cookie = "user_key="+"'.$secret_key.'"+expires+"; path=/";
}
////////////////////////////////////////////////////
function checkScheme (id) {
	var current_value = get(id).value;
	var other_value =  get(id + '_other').value;
	if (current_value == other_value) {
		get('other_' + id).style.display="block";
	}
	else {
		get('other_' + id).style.display="none";
	}
	
} 
//////////////////////////////////////////////////// functions for create lists with areas and towns
function dynamicSelect (id1, id2) {
	if (get && document.getElementsByTagName) {
		var sel1 = get(id1);
		var sel2 = get(id2);
		var clone = sel2.cloneNode(true);
		var clonedOptions = clone.getElementsByTagName("option");
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		}
	}
}

function refreshDynamicSelectOptions (sel1, sel2, clonedOptions) {
	while (sel2.options.length) {
		sel2.remove(0);
	}
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	for (var i = 0; i < clonedOptions.length; i++) {
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}
String.prototype.get = function(p){
    return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
}

function count_chars (textField, countField, maxlen, show_alert) {
    if(textField != null && textField.value != null) {
	    if (textField.value.length > maxlen) {
            if (show_alert)
               alert('This field should not be more than ' +  maxlen + ' chars!');
            textField.value = textField.value.substring(0, maxlen);
	    } else {
            countField.value = maxlen - textField.value.length;
	    }
    }
}
function init2(vr, path){
	if(vr){
		init(path);
	}
}
function nextpage(type){
	var bottomPrice = get("hidBottomPrice");
    var topPrice = get("hidTopPrice");
	var beds = get("hidBeds").value;
   	var pageno = get("pageno");
   	pageno.value = parseInt(pageno.value) + 1;
   	if(pageno.value == false || pageno.value == "NaN"){
   		pageno.value = 1;
   	}
   	var topPrice1 = "";
	topPrice1 = '&pricemax='+topPrice.value;
   	if(type == "gmap"){
   		load();
   	}else{
   		new Ajax.Updater('ajaxseach', 'getProperties.php'+window.location.search+'&beds='+beds+'&pricemin='+bottomPrice.value+topPrice1+'&pageno='+pageno.value, { method: 'get' , 
   		onCreate: function(){
			get("loadsearch").style.display="block";
			},
   		onSuccess: function(){
			get("loadsearch").style.display="none";
			scroll(0,0);
			} 
		});
   	}
   	
   	if(pageno.value > 0){
   		get("prev").innerHTML = "<a href=javascript:prevpage('gmap');><img id=prev src=img/button/prev50.gif alt= /></a>";
   	}
   	openwindow = '';
   	
}
function prevpage(type){
	var bottomPrice = get("hidBottomPrice");
    var topPrice = get("hidTopPrice");
	var beds = get("hidBeds").value;
   	var pageno = get("pageno");
   	pageno.value = parseInt(get("pageno").value) -1;
   	var topPrice1 = "";
	topPrice1 = '&pricemax='+topPrice.value;
   	if(type == "gmap"){
   		load();
   	}else{
   		//ajaxdisplay('getProperties.php'+window.location.search+'&beds='+beds+'&pricemin='+bottomPrice.value+'&pricemax='+topPrice.value+'&pageno='+pageno.value, 'loadsearch', 'ajaxseach');
   		new Ajax.Updater('ajaxseach', 'getProperties.php'+window.location.search+'&beds='+beds+'&pricemin='+bottomPrice.value+topPrice1+'&pageno='+pageno.value, { method: 'get' , 
   		onCreate: function(){
			get("loadsearch").style.display="block";
			},
   		onSuccess: function(){
			get("loadsearch").style.display="none";
			scroll(0,0);
			} 
		});
   	}
   	if(pageno.value == 0){
   		//alert(pageno.value);
   		get("prev").innerHTML = '<img id="prev" src="img/button/prev_empty50.gif" alt="" />';
   	}
   	openwindow = '';
}
function getPageUrl(split){
	var url = get("url").value;
	if(url != ""){
		var link = url;
	}else{
		var link = window.location.search;
	}
	if (link == '') {
		if (get('tag')) {
			link = '?' + get('tag').value;
		}
	}
	if(split){
		var link = link.split("&"+split);
		link = link[0];
	}
	return link;
}
function ViewMap(){
	if (get('tag'))
		var link = 'search.php' + getPageUrl("gmap")+"&gmap=1";	
	else
		var link = getPageUrl("gmap")+"&gmap=1";
//alert(link);
	window.location = link;
}
function ViewResults(){
	if (get('tag'))
		var link = 'search.php' + getPageUrl("gmap");
	else
		var link = getPageUrl("gmap");
//alert(link);
	window.location = link;
}
function getPageNum(type, start, page){
	//var bottomPrice = get("hidBottomPrice");
   // var topPrice = get("hidTopPrice");
	//var beds = get("hidBeds").value;
    var page1 = get("page");
   	var start1 = get("start");
    page1.value = page;
    start1.value = start;
   	var topPrice1 = "";
   	if(type == "gmap"){
   		load();
   	}else{
   		new Ajax.Updater('ajaxseach', 'getProperties.php'+getPageUrl()+'&start='+start+'&page='+page, { method: 'get' , 
   		onCreate: function(){
			get("loadsearch").style.display="block";
			},
   		onSuccess: function(){
			get("loadsearch").style.display="none";
			scroll(0,0);
			},
		onFailure: function(transport){
			alert(transport.status);
			}
		});
   	}
   	openwindow = '';
}
function sorting(type, sortby){
	var sort = "";
	var by = ""
	if(sortby == 1){
		var sort = "desc";
		var by = "property_rent"
	}else if(sortby == 2){
		var sort = "asc";
		var by = "property_rent"
	}else if(sortby == 3){
		var sort = "desc";
		var by = "property_bedrooms"
	}else if(sortby == 4){
		var sort = "asc";
		var by = "property_bedrooms"
	}
	var link = getPageUrl()+'&sort='+sort+'&by='+by+'&val='+sortby;
	get("url").value = link;
	if(type == "gmap"){
   		load();
   	}else{
		
   		new Ajax.Updater('ajaxseach', 'getProperties.php'+link, { method: 'get' , 
   		onCreate: function(){
			get("loadsearch").style.display="block";
			},
   		onSuccess: function(){
			get("loadsearch").style.display="none";
			scroll(0,0);
			},
		onFailure: function(transport){
			alert(transport.status);
			}
		});
   	}
}
function get_map(id, latitude, longitude){
	window.open("map_property.php?id="+id+"&latitude="+latitude+"&longitude="+longitude,"gmap", "menubar=no,width=776,height=500,toolbar=no");
} 
//////////////////////////////////////////////////// functions for change images in photogallery for description of property
function changePhoto (path, size, text) {
	get("main_photo").src = 'getthumb.php?path=' + path + '&size=' + size;
	get("photo_text").innerHTML = text;
}
//////////////////////////////////////////////////// functions for moving block
function ge() {
  var ea;
  for( var i = 0; i < arguments.length; i++ ) {
    var e = arguments[i];
    if (typeof e == 'string')
      e = get(e);
    if (arguments.length == 1)
      return e;
    if (!ea)
      ea = new Array();
    ea[ea.length] = e;
  }
  return ea;
}

function show () {
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style)
    	element.style.display = 'block';
  }
}
function collapseBox(id, container, dopen, dclose) {
  var box = $(id);
  if (!box){
    return;
  }
  var c = document.getElementsByClassName("c", box);
  if (c.length > 0 && !c[0].blinding) {
    c[0].blinding = true;
    if (c[0].style.display == "none") {
      Effect.BlindDown(c[0], {
        afterFinish: function() {
          c[0].blinding = false;
        },
        duration: dopen
      });
      container.parentNode.className = "bOpen";
      
    } else {
      Effect.BlindUp(c[0], {
        afterFinish: function(){
          c[0].blinding = false; 
        },
        duration: dclose
      });
      container.parentNode.className = "bShut";
    }
  }
  return false;

}
function del_selected(link) {
	var chk = document.forms['msgs'].elements['msgchk[]'];
    var chk_count  = (typeof(chk.length) != 'undefined') ? chk.length : 0;
    var checkbox_choices = 0;
    var str="";
    for (counter = 0; counter < chk_count ; counter++) {
            if (chk[counter].checked) {
                checkbox_choices ++;
                str = str + chk[counter].value +",";
            }
        }
        if(checkbox_choices == 0) {
            if(chk.checked) {
                str = str + chk.value + ",";
                checkbox_choices ++ ;
            }
        }

        if(checkbox_choices == 0) {
            alert("There is no record has selected, please select one record at least");
        }else{
            if(confirm("Are you sure you want delete the selected records?")) {
            //alert("<?=$php_self?>");
                window.location.href = link+str;
            }
        }
 }
function del(str, hash, link, type, load, display) {
           if(confirm('Are you sure you want delete this record?')) {
           		//ajaxdisplay('request.php?action=delete_msgs&ids='+str+'&hash='+hash, '', 'msgs');
               //window.location.href = link+str;
               if(type && display){
            	   new Ajax.Updater(display, 'request.php?action='+link+'&id='+str+'&tenant_id='+0+'&hash='+hash, { method: 'get' , 
                 		onCreate: function(){
	            		   	if(load){
	            		   		get(load).style.display="block";
	            		   	}
              			},
                 		onSuccess: function(){
              				if(load){
	            		   		get(load).style.display="none";
	            		   	}
							if(link == "delete_searches2"){
							//alert(1);
								window.location.reload();
									//alert(2);
							}
              			}
              		});
               }else{
            	   window.location = link+str;
               }
               
           }
       
	}
function select_all() {
      var chk = document.forms['msgs'].elements['msgchk[]'];
      var chk_count  = (typeof(chk.length) != 'undefined') ? chk.length : 0;
      var flags = document.forms['msgs'].elements['check'].checked;
      var checkbox_choices = 0;
      var str="";


      for (counter = 0; counter < chk_count ; counter++) {
          chk[counter].checked = flags
      }
      if(checkbox_choices == 0) {
       chk.checked = flags
      }

}
function report(do1,str,hash) {
	var div = 'tr_'+str;
	
	if(do1 == 1){
		var confirm1 = 'Are you sure you want confirm report this property?';
		get(div).className = "row0";
	}else{
		var confirm1 = 'Are you sure you want delete confirmation report this property?';
		get(div).className = "row1";
	}
	
     if(confirm(confirm1)) {
     	 //ajaxdisplay('request.php?action=delete_msgs&ids='+str+'&hash='+hash, '', 'msgs');
     	 ajaxdisplay('../request.php?action=report_ad&do='+do1+'&report_id='+str+'&tenant_id='+str+'&hash='+hash, '', 'check_'+str);
     }
       
}
function save_property(property, tenant, hash, div){
	if(property){
		if(!div){
			div = 'saved_pads_s_'+property;
			div2 = 'saved_pads_2_s_'+property;
		}
		new Ajax.Updater('', 'request.php?action=save_property&property_id='+property+'&tenant_id='+tenant+'&hash='+hash, { method: 'get' , 
   		onCreate: function(){
	   		try{
	   			get("loadsearch").style.display="block";
	   		}catch(e){
	   		}
			},
   		onSuccess: function(){
			try{
	   			get("loadsearch").style.display="none";
	   		}catch(e){
	   		}
			get(div).innerHTML="Property Saved";
			try{
				get(div2).innerHTML="Property Saved";
			}catch(e){
			}
			
				new Ajax.Updater('matched_properties_1', 'request.php?action=get_saved_property&property_id='+property+'&tenant_id='+tenant+'&hash='+hash, { method: 'get'}); 
			}
		});
		//ajaxdisplay('request.php?action=save_property&property_id='+property+'&tenant_id='+tenant+'&hash='+hash, 'loadsearch', '');
		//ajaxdisplay('request.php?action=get_saved_property&property_id='+property+'&tenant_id='+tenant+'&hash='+hash, '', 'matched_properties_1');
	}
	
}
function main_search(){
	var s_p_from = document.forms["frm"].elements['s_p_from'].value;
    var s_p_to = document.forms["frm"].elements['s_p_to'].value;
	if(s_p_from > 0 && s_p_to > 0){
		//alert(s_p_from+' - '+s_p_to);
		if(parseInt(s_p_from) > parseInt(s_p_to)){
			alert('Please insert a valid number in Price to field bigger then the number in Price from field');
			document.forms["frm"].elements['s_p_to'].focus();
			return false;
		}
	}
}
function left_search(hash, type){
	if(document.forms["frm"].elements['searchr'].value == "Search"){
		alert('Please insert a search word');
		document.forms["frm"].elements['searchr'].focus();
		return false;
	}
    if(document.forms["frm"].elements['searchr'].value == ""){
		alert('Please insert a search word');
		document.forms["frm"].elements['searchr'].focus();
		return false;
	}
	var str = document.forms["frm"].elements['s_p_from'].value;
    str = str.toString();
    var str2 = document.forms["frm"].elements['s_p_to'].value;
	str2 = str2.toString();
    var re = /^[-]?\d*\.?\d*$/;
    if (!str.match(re)) {
		alert('Please insert a valid number in Price from field');
		document.forms["frm"].elements['s_p_from'].focus();
		return false;
	}
    if (!str2.match(re)) {
		alert('Please insert a valid number in Price to field');
		document.forms["frm"].elements['s_p_to'].focus();
		return false;
	}
	
	//alert(parseInt(str.match(re)) +' - '+ str2.match(re));
	if(parseInt(str.match(re)) > parseInt(str2.match(re))){
		alert('Please insert a valid number in Price to field bigger then the number in Price from field');
		document.forms["frm"].elements['s_p_to'].focus();
		return false;
	}
	if(parseInt(str2.match(re)) == 0){
		alert('Please insert a valid number in Price to field bigger then 0 or leave the field blank');
		document.forms["frm"].elements['s_p_to'].focus();
		return false;
	}
	
	var s_d_from3 = document.forms["frm2"].elements['s_d_from'].value;
	var s_d_to3 = document.forms["frm2"].elements['s_d_to'].value;

	s_d_from2 = s_d_from3.split("/");
	s_d_to2 = s_d_to3.split("/");
	s_d_from2.sort();
	s_d_to2.sort();
	if(s_d_from2[2].length == 2){
		var s_d_from1 = parseInt(s_d_from2[1])+parseInt(s_d_from2[0])+parseInt(s_d_from2[2]);
	}else{
		var s_d_from1 = parseInt(s_d_from2[2])+parseInt(s_d_from2[0])+parseInt(s_d_from2[1]);
	}
	
	if(s_d_to2[2].length == 2){
		var s_d_to1 = parseInt(s_d_to2[1])+parseInt(s_d_to2[0])+parseInt(s_d_to2[2]);
	}else{
		var s_d_to1 = parseInt(s_d_to2[2])+parseInt(s_d_to2[0])+parseInt(s_d_to2[1]);
	}
	//alert(s_d_from1+' - '+s_d_to1);
	if(parseInt(s_d_from1) > parseInt(s_d_to1)){
		alert('The Available to date should be after then the Available from date');
		document.forms["frm"].elements['s_p_to'].focus();
		return false;
	}
	
	//alert(s_d_to1+ ' - ' + s_d_from1);
	var searchr = get("searchr").value;
	var search_id = get("search_id").value;
	var search_type = get("search_type").value;
	var searchr2 = get("searchr2").value;
	var s_d_from = get("s_d_from").value;
	var s_d_to = get("s_d_to").value;
	var beds = get("beds").value;
	var pricep = get("pricep").value;
	var m1="";
	var m1 = document.forms["frm2"].elements['pads'];
	m1len = m1.length ;
	var pads="";
    for ( i=0; i<m1len ; i++){
        if (m1.options[i].selected == true ) {
			pads += m1.options[i].value+',';
        }
    }
	//alert(pads);
	pads2="";
	if(pads){
		pads2 = "&pads="+pads;
	}
	var Psearch = "";
	if(searchr == searchr2){
		Psearch = '&search_id='+search_id+'&search_type='+search_type+'&searchr2='+searchr2;
	}
	var link = "";
	if(type == 1){
		var link = 'searchr='+searchr+Psearch+'&s_p_from='+str+'&s_p_to='+str2+'&beds='+beds+'&pricep='+pricep;
	}else if(type == 2){
		var link = 'searchr='+searchr+Psearch+'&s_p_from='+str+'&s_p_to='+str2+'&beds='+beds+'&pricep='+pricep+pads2+'&s_d_from='+s_d_from+'&s_d_to='+s_d_to;
	
	}
	get("url").value = '?'+link;
	window.location.href="search.php"+get("url").value;
	return false;
}
function getPageName(){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}
function centerDiv(){
	var theBody = document.getElementsByTagName("BODY")[0];
	//theBody.style.overflow = "hidden";
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(theBody.scrollLeft,10);
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	//alert((scTop + ((fullHeight - (60)) / 2)) + "px");
	get(div).style.top = (scTop + ((fullHeight - (60)) / 2)) + "px";
	get(div).style.left =  (scLeft + ((fullWidth - 80) / 2)) + "px";
}
function suggest_Input(){
	if(document.readyState){
		if (document.readyState=="complete")
		   {
		     suggestInput_init();
		     clearTimeout(timeout);
		   }
	}else{
	try
	  {
	  	if (window.captureEvents) {
		    window.captureEvents(Event.LOAD)
		    window.onload=suggestInput_init();
		    //alert(444432432);
		    clearTimeout(timeout);
		}
	  }
	  catch (e)
	  {
	  	suggestInput_init();
	  	clearTimeout(timeout);
	  }
	}
}
function checktime(day, month, year, id){
	var currentTime = new Date()
	var m = currentTime.getMonth() + 1
	var d = currentTime.getDate()
	var y = currentTime.getFullYear()
	var h = currentTime.getHours()
	var am = "am_"+id;
	var pm = "pm_"+id;
	var evening = "evening_"+id;
	//alert(am);
	if(day == d && month == m && year == y){
		if(h > 11){
			get(am).disabled=true;
			get(pm).checked=true;
		}
		if(h > 18){
			get(pm).disabled=true;
			get(evening).checked=true;
		}
		if(h > 22){
			get(am).checked=true;
			get(am).disabled=false;
			get(pm).disabled=false;
		}
	}else{
		get(am).checked=true;
		get(am).disabled=false;
		get(pm).disabled=false;
	}
	//alert(hour+' - '+day+' - '+month+' - '+year);
	
}

//////////////////////////////////////////////////// index page: clear example text in search form
function clearSearchExample (value) {
	if (value == '1') {
		if (get('search').value == '') {
			get('search_example_text').innerHTML="Enter area, town or postcode <span>e.g. Camden</span>";
		}
	} else if (value == '0') {
		if (get('search').value == '')
			get('search_example_text').innerHTML="";
			get('search').focus();
	}	
}

////////////////////////////////////////////////////  index page: scrolling blocks
function marginMove(order, id, move_height) {
	var step = 20;
	var movedDiv;
	if (!(movedDiv = get(id))) return;
	var top = movedDiv.style.marginTop ? parseInt(movedDiv.style.marginTop) : 0;
	var height = get(id).offsetHeight;
	if (get(id + '_height').value == '') {
		get(id + '_height').value = height - move_height;
	}
	switch (order) {
		case "up" :			
			if (get(id + '_height').value > 0) {
				movedDiv.style.marginTop = (top - step) + "px";
				get(id + '_height').value = get(id + '_height').value - step;
			}
		break;
		case "down" :	
			if (top != 0) {
				movedDiv.style.marginTop = (top + step) + "px";
				height = height - step;
			} else {
				get(id + '_height').value = height - move_height;
			}
		break;
		default :
			// Nothing
		break;
	}
	return false;
}
function suggetSearch(s, t, hash){
	var search = get(s);
	if(t == 1){
		clearSearchExample(0);
	}else if(t == 2){
		if (search.value=="Search"){
			search.value="";
		} 
	}
	$(s).observe('blur', function(){
		if(t == 1){
			clearSearchExample(1);
		}else if(t == 2){
			if (search.value==""){
				search.value="Search";
			} 
		}
	});
	//new Ajax.Request('request.php?action=get_suggestions&hash='+hash,
	//{
	//    method:'get',
	//    onSuccess: function(obj){
		   var options = {
			script:'request.php?action=get_suggestions&hash='+hash+'&',
			varname:'input',
			json:true,
			shownoresults:false,
			maxresults:5,
			ajax: false,
			//objv: obj,
			callback: function (obj) {
				get('search_id').value= obj.area_id; 
				get('search_type').value=obj.type;
				get(s+'2').value=obj.value;
				if(t == 1){
					suggestTube('tube', hash);
				}
				}
			};
			var json=new AutoComplete(s,options);return true;
	    //}
	//});
	
}
function suggestTube(s, hash){
	var search = get(s);
	var q=""
	if(checkSuggestId("search", "search2")){
		q = get('search_id').value;
	}
	new Ajax.Request('request.php?action=get_tube_suggestions&q='+q+'&hash='+hash,
	{
	    method:'get',
	    onSuccess: function(obj2){
			

			
			var jsondata = eval('(' + obj2.responseText + ')');
      		var aSug = jsondata.results;
			var tube_span = get("tube_span");
			var tube = document.createElement('select');
			tube.id='tube';
			tube.name='tube';
			//tube.setAttribute("onchange", "changeTube(this.options[this.selectedIndex].value)");
			var id="";
			tube.options.add(new Option("None", "0"));
			for (var i=0;i<aSug.length;i++) {
			 	//id = aSug[i].id+','+aSug[i].lat+','+aSug[i].lng;
				tube.options.add(new Option(aSug[i].value, aSug[i].id));
	  		}
			tube_span.innerHTML="";
			tube_span.appendChild(tube);
			
     		$('tube').observe('change', function(){
				var tube = $('tube').options[$('tube').selectedIndex].value;
				//alert(tube)
				changeTube(tube);
			});
		   /*
 			var options = {
			script:'test.php?json=true&limit=6&',
			varname:'input',
			json:true,
			shownoresults:false,
			maxresults:5,
			ajax: false,
			objv: obj2,
			callback: function (obj2) {
				get('tube_id').value= obj2.id; 
				get('tube2').value=obj2.value;
				get('lat').value=obj2.lat;
				get('lng').value=obj2.lng;
			}
			
			};
			var json=new AutoComplete(s,options);return true;
			*/
	    }
	});

}
function checkSuggestId(s1, s2){
	var search1 = get(s1).value;
	var search2 = get(s2).value;
	if (search1 == search2) {
		return true;
	}else {
		return false;
	}
}
////////////////////////////////////////////////////  set temporary ID for not logged user
function setTempId (id) {
	var date = new Date();
	var new_date = date.toGMTString(date.setDate(date.getDate()+1));
	var my_time = /([0-9]){2}:([0-9]){2}:([0-9]){2}/;
	new_date = new_date.replace (my_time, '00:00:00');
	document.cookie = "temp_user_id=" + id + "; expires=" + new_date + "; path=/";
}
function get_saved_property(tenant, hash){
	new Ajax.Updater('matched_properties_1', 'request.php?action=get_saved_property&tenant_id='+tenant+'&hash='+hash, { method: 'get'}); 
}
////////////////////////////////////////////////////  show or hide additional links in properties list
function addLinks (id) {
	if (get('more_links_' + id)) {
		if (get('more_links_' + id).style.display == "block") {
			get('more_links_' + id).style.display = "none";
			get('more_' + id).innerHTML = 'More';
		} else if (get('more_links_' + id).style.display == "none") {
			get('more_links_' + id).style.display = "block";
			get('more_' + id).innerHTML = 'Hide';
		}
	}

} 
////////////////////////////////////////////////////  show/hide press text
function viewDesc(id) {
	get('descmore'+id).style.display = 'none';
	get('second_text'+id).style.display = 'inline';
	get('descfull'+id).style.display = 'inline';
}

function hideDesc(id) {
	get('descfull'+id).style.display = 'none';
	get('second_text'+id).style.display = 'none';
	get('descmore'+id).style.display = 'inline';
}

function changePriceRange(price, id, hash){
	if(price == 1){
		var pricep = "monthly";
	}else{
		var pricep = "weekly";
	}
	new Ajax.Updater(id, 'request.php?action=price_range&pricep='+pricep+'&hash='+hash, { method: 'get'}); 
}
function changeTube(tube){
	//alert(tube);
	if(tube > 0){
		$('radius').disabled = false;
	}else{
		$('radius').disabled = true;
	}
}
function property_alert(s){
	if(s){
		save_search_links();
	}else{
		var property_alerts = getElementsByClass('property_alert',null,'span');
		get('Email_property_alert').innerHTML='<a>Email property alert</a>';
		get('Email_property_alert2').innerHTML='<a>Email property alert</a>';
		for (i = 0; i < property_alerts.length; i++) {
			get(property_alerts[i].id).innerHTML='<span>Property Alert</span>';
		}
	}
	
}
function save_search_links(){
	get('save_search_link').innerHTML='<a>Search saved</a>';
	get('save_search_link2').innerHTML='<a>Search saved</a>';
}
function getElementsByClass(searchClass,node,tag) {

        var classElements = new Array();
        if (node == null)
                node = document;
        if (tag == null)
                tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        var j = 0;
        for (i = 0; i < elsLen; i++) {
                if (pattern.test(els[i].className) ) {
                        classElements[j] = els[i];
                        j++;
                }
        }
        return classElements;
}
function hideTerms() {
	if (get('terms_title'))
		get('terms_title').innerHTML = '';
	if (get('popupTitleBar'))
		get('popupTitleBar').style.Height = '10px';
}
function showTerms() {
	get('terms_title').innerHTML = 'Terms & Conditions';
	get('popupTitleBar').style.height = '45px';
}
function showPolicy() {
	get('terms_title').innerHTML = 'Privacy Policy';
	get('popupTitleBar').style.height = '45px';
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
///////////////////////////// check phone number //////////////
function check_phone(phone) {
	var stripped_phone = phone.replace(/[\(\)\.\-\ ]/g, '');

	if (isNaN(parseInt(stripped_phone)) || stripped_phone.length<6) {
   		return false;
 	} else {
 		return true;
 	}
} 
//////////////////////////// change class at run time /////
function change_class (elementID, newClass) {
	if (get(elementID)) {
		var element = get(elementID);	
		
		if(navigator.appName == "Microsoft Internet Explorer")
			element.setAttribute("className", newClass); //For IE; harmless to other browsers.
		else
			element.setAttribute("class", newClass); //For Most Browsers
	}
}
/////////////////////////////// validate form controls ///////
function check_empty(control_id, error_message ) {
	var return_val = true;
	var css_class = "form_error";
	if(get(control_id).value=="") 	{
 		set_error_message(control_id, error_message, css_class); 		
 		return_val = false;
	}
	else {
		set_error_message(control_id, "", "");
	}
	return return_val;
}
/////////////////////////////////// set error message //////////////
function set_error_message(id,msg,cls) {
	if (get(id+"_err"))
		get(id+"_err").innerHTML=msg;
	if (get(id))
		change_class(id,cls);
}
////////////////////////////////////////////////// function check rent form ///
 function check_rent_form() {
 	var return_flag = true;
 	var err1 = true;
	var err2 = true;
	var err3 = true;
	var err4 = true;
	
 	if(!check_empty("landlordAndPropertyDetails111","Please fill Landlords agreement name 1")) {
 		return_flag = false;
		err1 = false;
	}
 	if(!check_empty("landlordAndPropertyDetails112","Please fill Landlords agreement name 2")) {
 		return_flag = false;
		err2 = false;
	}
 	if(!check_empty("tenantDetails01","Please fill tenant agreement name 1")) {
 		return_flag = false;
		err3 = false;
	}
 	if(!check_empty("tenantDetails02","Please fill tenant agreement name 2")) {
 		return_flag = false;
		err4 = false;
	}
 	 	
	if (!return_flag) {
		if (err1 == false) {
			get('landlordAndPropertyDetails111').focus();		
		} else if (err2 == false) {
			get('landlordAndPropertyDetails112').focus();		
		} else if (err3 == false) {
			get('tenantDetails01').focus();			
		} else if (err4 == false) {
			get('tenantDetails02').focus();				
		}
	}
	return return_flag;	
}
////////////////////////////////////////////////// function for check management form ///
function check_property_management_form() {
	var return_flag = true;
	var css_class = "form_error";
	var err1 = true;
	var err3 = true;
	var err4 = true;
	var err5 = true;
	var err6 = true;
	var err7 = true;
	var err8 = true;
	var err10 = true;
	var err11 = true;
	var err12 = true;
	//Property
	if(!check_empty("contactDetails2","Please fill property home phone no")) {
		return_flag = false;
		err1 = false;
	}
	if(!check_phone(get("contactDetails2").value)) {
		set_error_message("contactDetails2", "Please fill a valid phone no",css_class);		
		err1 = false;
		return_flag = false;
	} else {
		set_error_message("contactDetails2", "", "");	
	}

	//Landlord Correspondence
	var element = document.getElementsByName("contactDetails3").item(0);
	if(element.value=="") {
		get("contactDetails3_err").innerHTML="Please fill landlord name";
		if(navigator.appName == "Microsoft Internet Explorer")
			element.setAttribute("className", css_class); //For IE; harmless to other browsers.
		else
			element.setAttribute("class", css_class);
		err3 = false;	
		return_flag = false;
	} else {
		get("contactDetails3_err").innerHTML="";
		if(navigator.appName == "Microsoft Internet Explorer")
			element.setAttribute("className", ""); //For IE; harmless to other browsers.
		else
			element.setAttribute("class", "");		
	}
		 	
	if(!check_empty("contactDetails5","Please fill landlord phone or mobile no"))	{
		 if(!check_empty("contactDetails6","")) {
			err4 = false; 	
		  	return_flag = false;
		}
		if(!check_phone(get("contactDetails6").value)) {
			set_error_message("contactDetails6", "Please fill a valid mobile no",css_class);	
			err5 = false;
			return_flag = false;
		}
		else set_error_message("contactDetails6", "", "");
	}

	if(get("contactDetails5").value!="" && !check_phone(get("contactDetails5").value)) {
		set_error_message("contactDetails5", "Please fill a valid phone no",css_class);	
		err6 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails5", "", "");

	if(!check_empty("contactDetails7","Please fill a valid email")) {
		err7 = false;
		return_flag = false;
	}

	if(!check_email(get("contactDetails7").value)) {
		set_error_message("contactDetails7", "Please fill a valid email",css_class);	
		err7 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails7", "", "");

	if(get("contactDetails8").value!="" && !check_phone(get("contactDetails8").value)) {
		set_error_message("contactDetails8", "Please fill a valid fax no",css_class);	
		err8 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails8", "", "");

	//Business
	if(get("contactDetails10").value!="" && !check_phone(get("contactDetails10").value)) {
		set_error_message("contactDetails10", "Please fill a valid phone no",css_class);		
		err10 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails10", "", "");	
	

	if(get("contactDetails11").value!="" && !check_phone(get("contactDetails11").value)) {
		set_error_message("contactDetails11", "Please fill a valid fax no",css_class);	
		err11 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails11", "", "");

	if(get("contactDetails12").value!="" && !check_email(get("contactDetails12").value)) {
		set_error_message("contactDetails12", "Please fill a valid email",css_class);		
		err12 = false;
		return_flag = false;
	}
	else set_error_message("contactDetails12", "", "");


	if (!return_flag) {
		if (err1 == false) {
			get('contactDetails2').focus();		
		} else if (err3 == false) {
			get('contactDetails3').focus();		
		} else if (err4 == false) {
			get('contactDetails6').focus();			
		} else if (err6 == false) {
			get('contactDetails5').focus();				
		} else if (err7 == false) {
			get('contactDetails7').focus();				
		} else if (err8 == false) {
			get('contactDetails8').focus();				
		}  else if (err10 == false) {
			get('contactDetails10').focus();				
		} else if (err11 == false) {
			get('contactDetails11').focus();				
		} else if (err12 == false) {
			get('contactDetails12').focus();				
		} 
	}
	return return_flag;	
}
////////////////////////////////////////////////// function for check tenancy form ///
function check_tenancy_form () {
	var return_flag = true;
	var css_class = "form_error";
	var err1 = true;
	var err2 = true;
	var err3 = true;
	var err4 = true;
	var err5 = true;
	var err6 = true;
	var err7 = true;
	var err8 = true;
	var err9 = true;
	var err10 = true;
	var err11 = true;
	var err12 = true;
	var err13 = true;
	var err14 = true;
	var err15 = true;
	
	//Property
	if(!check_empty("landlordAndPropertyDetails01","Please fill property address1")) {
		return_flag = false;
		err1 = false;
	}
	if(!check_empty("landlordAndPropertyDetails1","Please fill property town")) {
		return_flag = false;
		err2 = false;
	}
	if(!check_empty("landlordAndPropertyDetails3","Please fill property post code")) {
		return_flag = false;
		err3 = false;
	}

	//Landlords names
	if(!check_empty("landlordAndPropertyDetails111","Please fill Landlords Agreement Name 1")) {
		return_flag = false;
		err4 = false;
	}
	if(!check_empty("landlordAndPropertyDetails121","Please fill Landlord Address 1")) {
		return_flag = false;
		err5 = false;
	}
	if(!check_empty("landlordAndPropertyDetails13","Please fill Landlord Town")) {
		return_flag = false;
		err6 = false;
	}
	if(!check_empty("landlordAndPropertyDetails15","Please fill Landlord Post Code")) {
		return_flag = false;
		err7 = false;
	}
	
	//Tenant details
	if(!check_empty("tenantDetails01","Please fill Tenant Agreement Name 1")) {
		return_flag = false;
		err8 = false;
	}
	if(!check_empty("tenantDetails11","Please fill Tenant Address 1")) {
		return_flag = false;
		err9 = false;
	}
	if(!check_empty("tenantDetails2","Please fill Tenant Town")) {
		return_flag = false;
		err10 = false;
	}
	if(!check_empty("tenantDetails4","Please fill Tenant Postcode")) {
		return_flag = false;
		err11 = false;
	}
	
	//Tenancy Agreement Details
	if(!check_empty("tenancyAgreementDetails0","Please fill Type of Tenancy")) {
		return_flag = false;
		err12 = false;
	}
	if(get("tenancyAgreementDetails1").value == '0') {
		set_error_message("tenancyAgreementDetails1", "Please fill Length of Tenancy",css_class);	
		return_flag = false;
		err13 = false;
	}
	if(!check_empty("newDealDetails0","Please fill Rent Agreed")) {
		return_flag = false;
		err14 = false;
	}
	if (get('landlordAndPropertyDetails16_1').checked == false && get('landlordAndPropertyDetails16_2').checked == false && get('landlordAndPropertyDetails17').value == '') {
		set_error_message("landlordAndPropertyDetails16", "Please fill Landlord Home Abode",css_class);	
		return_flag = false;
		err15 = false;
		
		if (get('landlordAndPropertyDetails17').value == '') {
			change_class('landlordAndPropertyDetails17',css_class);
		}
	}
	
	if (!return_flag) {

		if (err1 == false) {
			get('landlordAndPropertyDetails01').focus();	
		} else if (err2 == false) {
			get('landlordAndPropertyDetails1').focus();			
		} else if (err3 == false) {
			get('landlordAndPropertyDetails3').focus();		
		} else if (err4 == false) {
			get('landlordAndPropertyDetails111').focus();			
		} else if (err5 == false) {
			get('landlordAndPropertyDetails121').focus();	
		} else if (err6 == false) {
			get('landlordAndPropertyDetails13').focus();				
		} else if (err7 == false) {
			get('landlordAndPropertyDetails15').focus();				
		} else if (err8 == false) {
			get('tenantDetails01').focus();				
		} else if (err9 == false) {
			get('tenantDetails11').focus();				
		}  else if (err10 == false) {
			get('tenantDetails2').focus();				
		} else if (err11 == false) {
			get('tenantDetails4').focus();				
		} else if (err12 == false) {
			get('tenancyAgreementDetails0').focus();				
		} else if (err13 == false) {
			get('tenancyAgreementDetails1').focus();				
		} else if (err14 == false) {
			get('newDealDetails0').focus();				
		} else if (err15 == false) {
			get('landlordAndPropertyDetails17').focus();				
		}
	}
	return return_flag;	
}

////////////////////////////////////////////////// function check services form ///
 function check_services_form() {
 	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	
	var email = get("email").value; 
	if (!check_email(email)) {
		get("email").className = error_class;
		get("email_err").innerHTML = "Wrong email address";
		get("email_err").className = error_text;
		err = false;
		
		if (drop_spaces(trim(get("email").value)) == '') {
			get("email").value = '';
		}
  	}
	if (drop_spaces(trim(get("name").value)) == '') {
		get("name").className = error_class;
		get("name").value = '';
		get("name_err").className = error_text;
		err = false;
	}
	if (get('view').checked == true || get('photo').checked == true || get('plan').checked == true  || get('ref').checked == true || get('ast').checked == true || get('manage').checked == true || get('collection').checked == true) {
	} else {
		get("services_err").className = error_text;
		err = false;
	}
	return err;
}

function checkNewsLetterForm() {	
	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	
	var u_email = get("u_email").value; 
	if (!check_email(u_email)) {
		get("u_email").className = error_class;
		get("u_email_err").innerHTML = "Wrong email address";
		get("u_email_err").className = error_text;
		err = false;
		
		if (drop_spaces(trim(get("u_email").value)) == '') {
			get("u_email").value = '';
		}
  	}
	if (drop_spaces(trim(get("u_name").value)) == '') {
		get("u_name").className = error_class;
		get("u_name").value = '';
		get("u_name_err").innerHTML = "Please fill your name";
		get("u_name_err").className = error_text;
		err = false;
	}
	if(get("u_type").selectedIndex == "0")
	{
		get("u_type").className = error_class;
		get("u_type").value = '';
		get("u_type_err").innerHTML = "Are you a Tenant/Landlord?";
		get("u_type_err").className = error_text;
		err = false;
	}
	return err;
}

//-----------------------------------------------------------------------------rerender

function rerender (x) {
w = 100 - 0.0001* (x);
//get ('header').style.width = w + '%';
}

//-----------------------------------------------------------------------------cookie functions

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//-----------------------------------------------------------------------------include css styles only for Opera
function includeOperaStyles () {
	UserAgent = navigator.userAgent
	AgentName = UserAgent.substring(0,5)
	if (AgentName == "Opera") {
		document.write('<link rel="stylesheet" type="text/css" media="screen" href="css/opera9.css">');
	}
}

//----------------------------------------------------------------------------- open subwindow
function openWindow (type, hash) {
	if (type == 'fr_form') {
		ft_window=dhtmlmodal.open('ftbox', 'div', 'ft_window', '', 'width=650px,height=150px,center=1,resize=0,scrolling=0');
	} else if (type == 'fm_window') {
		fm_window=dhtmlmodal.open('fmbox', 'div', 'fm_window', '', 'width=650px,height=330px,center=1,resize=0,scrolling=0');
	}
}

//----------------------------------------------------------------------------- open subwindow
function openWindow (type, hash) {
	if (type == 'fr_form') {
		ft_window=dhtmlmodal.open('ftbox', 'div', 'ft_window', '', 'width=650px,height=150px,center=1,resize=0,scrolling=0');
	} else if (type == 'fm_window') {
		fm_window=dhtmlmodal.open('fmbox', 'div', 'fm_window', '', 'width=650px,height=330px,center=1,resize=0,scrolling=0');
	}
}

//----------------------------------------------------------------------------- open subwindow
function openWindowDynamic (type,size,title) {
        dynamic_window=dhtmlmodal.open(type, 'div', 'contentbox', title, size);
}

//----------------------------------------------------------------------------- close fasttrack subwindow
function close_news_form () {
	news_window.hide();
}

//----------------------------------------------------------------------------- open subwindow with login, registration and upload property
function openLoginWindow (step, additional) {
	if (step >=1 && step <=4)
		step = '?action=step'+step;
	else
		step = '?action='+step;
	step += additional;	

	main_window=dhtmlmodal.open('mainbox', 'iframe', '/new/subwindow.php'+step, '', 'width=480px,height=500px,center=1,resize=0,scrolling=0');

	main_window.onclose=function(){
		window.location.reload();
		return true;
	}	
	main_window.payment=function(){
		location.href = "/landlord.php?property&payment";
		return true;
	}
	main_window.paymentItem=function(itemId){
		location.href = "/landlord.php?property&payment&item_id="+itemId;
		return true;
	}
	main_window.dashboard=function(){
		location.href = "/landlord.php?properties";
		return true;
	}	
	main_window.my_details=function(){
		location.href = "/landlord.php?my_details";
		return true;
	}
        main_window.more=function(){
		location.href = "/learn_more";
		return true;
	}	
	main_window.free=function(){
		location.href = "/landlord.php?properties&make_free";
		return true;
	}	
}
//----------------------------------------------------------------------------- open subwindow with property info preview for tenant enquiry page
function openEnquiryWindow (enquiry_id, message_id, property_id, hash) {
	main_window=dhtmlmodal.open('mainbox', 'iframe', '/inc/enquiry_preview.php?property_id='+property_id+'&enquiry_id='+enquiry_id+'&message_id='+message_id+'&hash='+hash, '', 'width=490px,height=488px,center=1,resize=0,scrolling=0');
}

//----------------------------------------------------------------------------- close subwindow with property info preview for tenant enquiry page
function closeEnquiryWindow () {
	main_window.hide();
}

//----------------------------------------------------------------------------- close fasttrack subwindow
function close_news_form () {
	news_window.hide();
}

function openLoginLlmWindow(userId, affiliateName) {
    main_window=dhtmlmodal.open('mainbox', 'iframe', '/new/subwindow.php?action=login_llm&affiliate_name='+affiliateName+'&user_id='+userId, '', 'width=480px,height=500px,center=1,resize=0,scrolling=0');

    main_window.onclose=function(){
		window.location.reload();
		return true;
	}
    
    main_window.llmClient=function(logged, userId){
		location.href = "/inc/services/llm_client.php?logged="+logged+"&user_id="+userId;
		return true;
	}
    main_window.rentbuddyClient=function(logged, userId){
		location.href = "/inc/services/rentbuddy.php?logged="+logged+"&user_id="+userId;
		return true;
	}
    main_window.dashboard=function(){
		location.href = "/landlord.php?properties";
		return true;
	}
    main_window.payment=function(){
		location.href = "/landlord.php?property&payment";
		return true;
	}
	main_window.more=function(){
		location.href = "/learn_more";
		return true;
	}
    main_window.free=function(){
		location.href = "/landlord.php?properties&make_free";
		return true;
	}

//    main_window.llmClient=function(){
//        alert("11111");
//        return true;
//		location.href = "/inc/services/llm_client.php?logged="+logged+"&user_id="+userId;
//		return true;
//	}

}
function openRegisterLlmWindow(email, fn, ln, affiliateName, phone) {
    main_window=dhtmlmodal.open('mainbox', 'iframe', '/new/subwindow.php?action=register_llm&email='+email+'&fn='+fn+'&ln='+ln+'&affiliate_name='+affiliateName+'&phone='+phone, '', 'width=480px,height=500px,center=1,resize=0,scrolling=0');

    main_window.onclose=function(){
		window.location.reload();
		return true;
	}
    main_window.llmClient=function(logged, userId){
		location.href = "/inc/services/llm_client.php?logged="+logged+"&user_id="+userId;
		return true;
	}
    main_window.rentbuddyClient=function(logged, userId){
		location.href = "/inc/services/rentbuddy.php?logged="+logged+"&user_id="+userId;
		return true;
	}
    main_window.dashboard=function(){
		location.href = "/landlord.php?properties";
		return true;
	}
    main_window.payment=function(){
		location.href = "/landlord.php?property&payment";
		return true;
	}
	main_window.more=function(){
		location.href = "/learn_more";
		return true;
	}
    main_window.free=function(){
		location.href = "/landlord.php?properties&make_free";
		return true;
	}

}

function openRegisterAffiliateWindow(email) {
    main_window=dhtmlmodal.open('mainbox', 'iframe', '/new/subwindow.php?action=register_affiliate&email='+email, '', 'width=480px,height=500px,center=1,resize=0,scrolling=0');

    main_window.onclose=function(){
		window.location.reload();
		return true;
	}
    main_window.advertiseNow=function(){
		location.href = "/landlord.php?properties&property_id=0";
		return true;
	}
    main_window.dashboard=function(){
		location.href = "/landlord.php?properties";
		return true;
	}
    main_window.payment=function(){
		location.href = "/landlord.php?property&payment";
		return true;
	}
	main_window.more=function(){
		location.href = "/learn_more";
		return true;
	}
    main_window.free=function(){
		location.href = "/landlord.php?properties&make_free";
		return true;
	}

}


function openCampaignWindow(href, name){
    if (false && window.showModalDialog) {
        var retValue = window.showModalDialog(href, name,"dialogWidth:900px;dialogHeight:820px");
        if (retValue)
        window.location.reload(true);
    } else {
        window.open(href, name, 'menubar=no,width=900,height=820,toolbar=no,scrollbars=yes, modal=yes');
    }
    return false;
}
//----------------------------------------------------------------------------- RSS function on index page - start
var xmlhttp;

function showRSS(){
	xmlhttp=GetRSSXmlHttpObject();
    if (xmlhttp==null){
	alert ("Your browser does not support XML HTTP Request");
	return;
    }
    var url="/rss/getrss.php?sid="+Math.random();
    xmlhttp.onreadystatechange=RSSstateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function RSSstateChanged(){
    if (xmlhttp.readyState==4){
	document.getElementById("rssOutput").innerHTML=xmlhttp.responseText;
    }
}

function GetRSSXmlHttpObject(){
    if (window.XMLHttpRequest){
	// code for IE7+, Firefox, Chrome, Opera, Safari
	return new XMLHttpRequest();
    }
    if (window.ActiveXObject){
	// code for IE6, IE5
	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}
//----------------------------------------------------------------------------- RSS function on index page - end


function checkPasswordForm () {

	var err = true;
	var error_class = 'form_error';

	if (drop_spaces(trim(get("current_pass").value)) == '') {
		get("current_pass").value = '';
		get("current_pass").className = error_class;
		get("current_pass_err").innerHTML = 'Please enter all the required information. ';
		err = false;
	}
	var new_pass = drop_spaces(trim(get("new_pass").value));
	if (new_pass == '') {
		get("new_pass").value = '';
		get("new_pass").className = error_class;
		get("new_pass_err").innerHTML = 'Please enter all the required information. ';
		err = false;
	} else {
		if (new_pass.length < 6 || new_pass.length > 12) {
			get("new_pass").className = error_class;
			get("new_pass_err").innerHTML = 'Passwords must be between 6 and 12 characters long. ';
		}
	}
	var pass_confirm = drop_spaces(trim(get("pass_confirm").value));
	if (pass_confirm == '') {
		get("pass_confirm").value = '';
		get("pass_confirm").className = error_class;
		get("pass_confirm_err").innerHTML = 'Please enter all the required information. ';
		err = false;
	} else {
		if (pass_confirm.length < 6 || pass_confirm.length > 12) {
			get("pass_confirm").className = error_class;
			get("pass_confirm_err").innerHTML = 'Passwords must be between 6 and 12 characters long. ';
			err = false;
		}
	}
	if (new_pass != '' && pass_confirm != '') {
		if (new_pass != pass_confirm) {
			get("pass_confirm").className = error_class;
			get("pass_confirm_err").innerHTML = 'You have entered an incorrect password confirm. ';
			err = false;
		}
	}
	return err;	
}

//*****************  scroll page content on top
function scrollit () {
	for (i=25; i>=1; i--) {
		self.scroll(1,i)
	}
}
//***************** allow only float numbers to be entered in a input
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    	return false;
	return true;
}
//***************** check is email exist in registration form
function checkEmail (ft) {
	var email = get('r_email').value;
	var hash = get('hash').value;
	var error_class = 'form_error';
	var add = '';
	if (drop_spaces(trim(get("r_email").value)) != '') {
		//get('email_result').innerHTML = '<span class="checking">Checking...</span>';
		if (!check_email(email)) {
			get("r_email").className = error_class;
			get("r_email_err").innerHTML = "Wrong email address";
		} else {
			if (ft != '')
				var add = '&ft=' + ft;
			ajaxdisplay('../request.php?action=check_email&email='+email+'&hash='+hash+add, '', 'email_result');
		}
	}
}

//***************** check form in automation tool for sending sms or email
function checkMailForm () {
	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	
	var u_email = get("u_email").value; 
	if (!check_email(u_email)) {
		get("u_email").className = error_class;
		get("u_email_err").innerHTML = "Wrong email address";
		get("u_email_err").className = error_text;
		err = false;
		
		if (drop_spaces(trim(get("u_email").value)) == '') {
			get("u_email").value = '';
		}
  	}
	if (drop_spaces(trim(get("u_name").value)) == '') {
		get("u_name").className = error_class;
		get("u_name").value = '';
		get("u_name_err").innerHTML = "Please fill your name";
		get("u_name_err").className = error_text;
		err = false;
	}
	if (drop_spaces(trim(get("m_text").value)) == '') {
		get("m_text").className = error_class;
		get("m_text").value = '';
		get("m_text_err").innerHTML = "Please enter message";
		get("m_text_err").className = error_text;
		err = false;
	}
	return err;
}

//***************** check form for saving contact data for property (step: Check Contact Details)
function checkContactDetailsForm () {
	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	
	if (drop_spaces(trim(get("email1").value)) != '') {
		var email1 = get("email1").value; 
		if (!check_email(email1)) {
			get("email1").className = error_class;
			get("e_email1").className = error_text;
			err = false;
			if (drop_spaces(trim(get("email1").value)) == '') {
				get("e_email1").value = '';
			}
	  	}
	}
	if (drop_spaces(trim(get("email2").value)) != '') {
		var email2 = get("email2").value; 
		if (!check_email(email2)) {
			get("email2").className = error_class;
			get("e_email2").className = error_text;
			err = false;
			if (drop_spaces(trim(get("email2").value)) == '') {
				get("e_email2").value = '';
			}
	  	}
	}
	if (!err) {
		get("result").innerHTML = '<span >Please check email</span>';
	}
	return err;
}

//***************** check form for saving contact data for property (step: Check Contact Details)
function checkEnquiryForm (type) {

	var err = true;
	var error_class = 'form_error';
	var error_text = 'label_wrong';
	var error_text = '';

	if (get('second')) {
		var benefit = drop_spaces(trim(get("benefit").value));
	} else {
		var benefit = getRadioValue ('benefit');
		if (benefit == false) {
			error_text = 'Please enter all nessesary fields. ';
			get("e_benefit").className = error_text;
			err = false;
		}
	}
	var name = get("name").value;
	if (drop_spaces(trim(get("name").value)) == '') {
		get("name").className = error_class;
		get("e_name").className = error_text;
		error_text = 'Please enter all nessesary fields. ';
		err = false;
	}
	var phone = get("phone").value;
	/*
	if (drop_spaces(trim(get("phone").value)) == '') {
		get("phone").className = error_class;
		get("e_phone").className = error_text;
		error_text = 'Please enter all nessesary fields. ';
		err = false;
	}
	*/
	var email = get("email").value; 
	if (drop_spaces(trim(get("email").value)) != '') {
		if (!check_email(email)) {
			get("email").className = error_class;
			err = false;
			error_text += ' Wrong email address. ';
			get("e_email").className = error_text;
		}
	}
	if (drop_spaces(trim(get("email").value)) == '' && drop_spaces(trim(get("phone").value)) == '') {
		err = false;
		error_text += ' Please enter email or phone. ';
	}
	
	if (!err) {
		if (get("result")) {
			get("result").innerHTML = error_text;
		}
	}
	
	if (type == 'second' || type == 'third') {
		if (err) {
			var hash = get("hash").value; 
			var people = drop_spaces(trim(get("people").value));
			var message = get("message").value; 
			var property_id = get("property_id").value;
			ajaxdisplay('../request.php?action=send_enquire&property_id='+property_id+'&message='+message+'&name='+name+'&email='+email+'&phone='+phone+'&benefit='+benefit+'&people='+people+'&hash='+hash, '', 'form');
			return false;	
		} else {
			return err;
		}
	} else {
		return err;
	}
}

//*****************  get radio input value
function getRadioValue (radio_name) {
	var inputs = document.getElementsByName(radio_name);
	var selectedValue = -1;
	var input_len = inputs.length;
	for (var i = 0; i < input_len; i++) {
	    if (inputs[i].checked) {
	        selectedValue = inputs[i].value;
	        break;
	    }
	}
	if (selectedValue == -1)
		return false;
	else
		return selectedValue;
}

//********************************* only *** digits are allowed
function check_digits (text, len) {
	if (text.length != len) {
		return false;
	} else {
		 var template = /^[0-9]+$/;
		if (template.test(text)) {
			return true;
		}
		return false; 
	}
}

/**
 * United Kingdom Telephon validator
 * http://www.braemoor.co.uk/software/telnumbers.shtml
 * http://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom
 * 
 * @param telephoneNumber
 */
function checkUKTelephone (telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var telnum = telephoneNumber + " ";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telnum.length = telnum.length - 1;

  // Don't allow country codes to be included (assumes a leading "+")
  var exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telnum) == true) {
     telNumberErrorNo = 2;
     return false;
  }

  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }

  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }

  // Now check that all the characters are digits
  exp = /^[0-9]{10,11}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 3;
     return false;
  }

  // @Artem changes
  // Now check that the first digit is 00 - international
  exp = /^00[0-9]{9}$/;
  if (exp.test(telnum) == true) {
     return telnum;
  }
    
  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 4;
     return false;
  }

    // Disallow numbers allocated for dramas.

  // Array holds the regular expressions for the drama telephone numbers
  var tnexp = new Array ();
    tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
    tnexp.push (/^02079460[0-9]{3}$/);
    tnexp.push (/^01914980[0-9]{3}$/);
    tnexp.push (/^02890180[0-9]{3}$/);
    tnexp.push (/^02920180[0-9]{3}$/);
    tnexp.push (/^01632960[0-9]{3}$/);
    tnexp.push (/^07700900[0-9]{3}$/);
    tnexp.push (/^08081570[0-9]{3}$/);
    tnexp.push (/^09098790[0-9]{3}$/);
    tnexp.push (/^03069990[0-9]{3}$/);

    for (var i=0; i<tnexp.length; i++) {
        if ( tnexp[i].test(telnum) ) {
          telNumberErrorNo = 5;
          return false;
        }
    }

  // Finally check that the telephone number is appropriate.
  exp = (/^(01|02|03|05|070|071|072|073|074|075|07624|077|078|08|079)[0-9]+$/);
    if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }

  // Telephone number seems to be valid - return the stripped telehone number
  return telnum;
}

//*********************************  show big image preview for property on enquiry window
function bigImg (id) {
	ajaxdisplay('../request.php?action=resize_img&id=' + id + '&type=3', '', 'big_photo');
}

//*********************************  send ome more enquire to landlord
function sendMoreEnquire (property_id, message_id) {
	ajaxdisplay('../request.php?action=send_enquire&property_id=' + property_id + '&message' + message_id, '', 'big_photo');
}

//*********************************  change dimension of affiliate banner
function changeBannerDimension (group, dimension_id) {
	var count = group.length;
	for (var i = 0; i < count; i++) {
		var div_name = group[i];
		if (get(div_name)) {
		
			get(div_name).style.display = 'none';
			get('link_'+div_name).className = '';
		}
	}
	get(dimension_id).style.display = 'block';
	get('link_'+dimension_id).className = 'current';
}

//***************** functions for check tabs images
function changeDetailPageTab (imgIndex, tabCount, type) {
	var tabFlag = 0;
	var imageArray = new Array();
	if (type == 'dashboard') {
		imageArray[0] = "../img/tab/d_publish.gif"+","+"../img/tab/d_publish1.gif";
		imageArray[1] = "../img/tab/d_pause.gif"+","+"../img/tab/d_pause1.gif";
		imageArray[2] = "../img/tab/d_not_publish.gif"+","+"../img/tab/d_not_publish1.gif";
	}
	
	for (var i=0; i<tabCount; i++) {
    	get('tab'+i).src = (imageArray[i].split(','))[0];
    	get('div'+i).style.display = "none";
	}
	get('tab'+imgIndex).src = (imageArray[imgIndex].split(','))[1];
	get('div'+imgIndex).style.display = "block";
	tabFlag = imgIndex;
}

//***************** functions for remove white spaces in the end and begin of string
function trim(s) {
  return rtrim(ltrim(s));
}

function ltrim(s) {
  return s.replace(/^\s+/, ''); 
}

function rtrim(s) {
  return s.replace(/\s+$/, ''); 
}

