// preload
img_floor_off = new Image ();
img_floor_off.src = "../_gfx/bt_floor.gif";
img_floor_on = new Image ();
img_floor_on.src = "../_gfx/bt_floor_close.gif";
img_map_off = new Image ();
img_map_off.src = "../_gfx/bt_map.gif";
img_map_on = new Image ();
img_map_on.src = "../_gfx/bt_map_close.gif";
img_local_off = new Image ();
img_local_off.src = "../_gfx/bt_local.gif";
img_local_on = new Image ();
img_local_on.src = "../_gfx/bt_local_close.gif";
//////////////////////////////////////////////////////////
// function to show all the criteria in the search page //
//////////////////////////////////////////////////////////
function showall() {
	if (document.property_search.show_all.checked) {
		document.property_search.show_garage.checked = true;
		document.property_search.show_garden.checked = true;
	}
	if (!document.property_search.show_all.checked) {
		document.property_search.show_garage.checked = false;
		document.property_search.show_garden.checked = false;
	}
}
////////////////////////////////////////////////////////////////
// function to show the big property image in the detail page //
////////////////////////////////////////////////////////////////
// id = id of the div you want to show in the html page
// nbr_image = images/div maximum in the html to hide before showing
// ref = manage the link border of the referer (div)
var img_ref;
function show_image(id, nbr_image, ref) {
	img_ref = ref;
	var d = document.getElementById(id);
	var d_ref = document.getElementById(ref);
	for (var i = 1; i<=nbr_image; i++) {
		if (document.getElementById('property_img'+i)) {document.getElementById('property_img'+i).style.display='none';}
		if (document.getElementById('property_small'+i)) {document.getElementById('property_small'+i).style.border='1px solid #EDEBDE';}
	}
	if (d) {d.style.display='block';}
	if (d_ref) {d_ref.style.border='1px solid #4769AD';}
}
//////////////////////////////////////////////////////////////////
// function to show and hide the border of the picture, a:hover //
//////////////////////////////////////////////////////////////////
function check_border(when, who) {
	if (when=="over") who.style.border='1px solid #4769AD';
	if (when=="out") who.style.border='1px solid #EDEBDE';
	document.getElementById(img_ref).style.border='1px solid #4769AD';
}
////////////////////////////////////
// function to show the alert box //
////////////////////////////////////
function show_alertbox(val) {
	// start hide other
	if (document.getElementById('mapbox')) document.getElementById('mapbox').style.display='';
	if (document.getElementById('aerialbox')) document.getElementById('aerialbox').style.display='';
	if (document.getElementById('floorplanbox')) document.getElementById('floorplanbox').style.display='';
	if (document.getElementById('contactbox')) document.getElementById('contactbox').style.display='';
	if (document.getElementById('sendfriendbox')) document.getElementById('contactbox').style.display='';
	// end hide other
	if (val) document.getElementById('alertbox').style.display='block';
	else document.getElementById('alertbox').style.display='none';
}
//////////////////////////
// function to show div //
//////////////////////////
function show_div(who) {
	// start hide other
	if (who!='contactbox') document.getElementById('contactbox').style.display='';
	if (who!='sendfriendbox') document.getElementById('sendfriendbox').style.display='';
	if (who!='floorplanbox') document.getElementById('floorplanbox').style.display='';
	if (who!='mapbox') document.getElementById('mapbox').style.display='';
	if (who!='aerialbox') document.getElementById('aerialbox').style.display='';
	// end hide other
	if (document.getElementById('alertbox')) document.getElementById('alertbox').style.display='none';
	el = document.getElementById(who);
	var display = el.style.display ? '' : 'block';
	el.style.display = display;
	//document.getElementById(who).style.display=val;
}
//////////////////////////////
// function to roll imgages //
//////////////////////////////
function roll_img(who) {
	var display = el.style.display ? '_on.src' : '_off.src';
	eval("document." + who + ".src = " + who + display);
}
/////////////////////////////////
// function to show/hide areas //
/////////////////////////////////
function toggle_area() {
	el = document.getElementById("ct_areas");
	var display = el.style.display ? '' : 'block';
	el.style.display = display;
}
/*
function toggle_office(officeId) {
	var divId = document.getElementById('officediv'+officeId);
	var officeBoxId = document.getElementById('officebox'+officeId);

	ele1 = document.getElementById('officebox1').checked;
	ele2 = document.getElementById('officebox2').checked;
	if (officeBoxId.checked) {
		divId.style.display='block';
		var i = 1;
		while (eval(document.getElementById('areabox_'+officeId+'_'+i))) {
			document.getElementById('areabox_'+officeId+'_'+i).checked = true;
			i = i + 1;
		} 		
	} else {
		divId.style.display='none';
		var i = 1;
		while (eval(document.getElementById('areabox_'+officeId+'_'+i))) {
			document.getElementById('areabox_'+officeId+'_'+i).checked = false;
			i = i + 1;
		} 		
	}
}
*/
///////////////////////////////
// AJAX FUNCTION TO CALL MAP //
///////////////////////////////
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();
function sndReq() {
	group = "test";
    http.open('get', 'scripts/callmap.php?group=' + group, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function handleResponse() {
    if(http.readyState == 4){
    	if (http.status == 200) {
        	var response = http.responseText;
       		document.getElementById('map_pic').innerHTML = response;
        } else {
        	alert("There was a problem retrieving the data.");
        }
    }
}


// Show office areas without altering their states if any areas within them are selected
function open_offices(officeIDs) {

	// Create array with office IDs
	offices = officeIDs.split(",");

	// Cycle through offices
	for (o=0; o<offices.length; o++) {
		officeID = offices[o];
		divId = document.getElementById('officediv'+officeID);
		officeBoxId = document.getElementById('officebox'+officeID);

		// Cycle through areas
		var i = 1;
		while (eval(document.getElementById('areabox_'+officeID+'_'+i))) {
			if (document.getElementById('areabox_'+officeID+'_'+i).checked) {
				divId.style.display='block';
				officeBoxId.checked = true;
				break;
			}
			i = i + 1;
		}
	}

	// Hack to set styles correctly
	ele1 = document.getElementById('officebox1').checked;
	ele2 = document.getElementById('officebox2').checked;
	if (ele1) {
		document.getElementById("content_center").style.height = "520px";
		document.getElementById("content_right").style.height = "530px";
	}
	if (ele1&&ele2) {
		document.getElementById("content_center").style.height = "650px";
		document.getElementById("content_right").style.height = "660px";
	}
	if (!ele1&&!ele2) {
		document.getElementById("content_center").style.height = "410px";
		document.getElementById("content_right").style.height = "420px";
	}

}

//////////////////////////
// function to show div //
//////////////////////////
function show_div_flash(who, val) {
	// hide others
	if (document.getElementById("infobox")) document.getElementById("infobox").style.display='none';
	if (document.getElementById("sendfriendbox")) document.getElementById("sendfriendbox").style.display='none';
	// show the div
	if (val) document.getElementById(who).style.display='block';
	else document.getElementById(who).style.display='none';
	// run the slide show
	if (who=="slideshowbox") {
		if (val&&flash_val=="off") getNumberImgAndPlay();
		else clearInterval(int_slide);
	}
}


///////////////////////////////////////
// function to manage the slide show //
///////////////////////////////////////
var count_slide_img = 0;
var int_slide;
var number_img = 4;
function getNumberImgAndPlay() {
	count_slide_img = 0;
	number_img = 0;
	document.getElementById('slide_player').style.display = 'block';
	for (b=1; b<=6; b++) {
		if (document.getElementById('slide_img'+b)) number_img++;
	}
	returnToPlay();
}
function returnToPlay() {
	clearInterval(int_slide);
	count_slide_img++;
	slide_show_play();
}
function slide_show_play() {
	if (count_slide_img>number_img) count_slide_img = 1;
	for (b=1; b<=number_img; b++) {
		if (count_slide_img!=b) document.getElementById('slide_img'+b).style.display='none';
		else document.getElementById('slide_img'+b).style.display='block';
	}
	color_link("play");
	int_slide = setInterval(returnToPlay, 3000);
}
function slide_show_stop() {
	clearInterval(int_slide);
	color_link("stop");
}
function slide_show_prev() {
	clearInterval(int_slide);
	count_slide_img--;
	if (count_slide_img<1) count_slide_img = number_img;
	for (b=1; b<=number_img; b++) {
		if (document.getElementById('slide_img'+b)) document.getElementById('slide_img'+b).style.display='none';
	}
	document.getElementById('slide_img'+count_slide_img).style.display='block';
	color_link("prev");
}
function slide_show_next() {
	clearInterval(int_slide);
	count_slide_img++;
	if (count_slide_img>number_img) count_slide_img = 1;
	for (b=1; b<=number_img; b++) {
		if (document.getElementById('slide_img'+b)) document.getElementById('slide_img'+b).style.display='none';
	}
	document.getElementById('slide_img'+count_slide_img).style.display='block';
	color_link("next");
}
function color_link(status_player) {
	document.getElementById("sl_play").style.color = "#BA1F23";
	document.getElementById("sl_stop").style.color = "#BA1F23";
	if (status_player!="prev" && status_player!="next") document.getElementById("sl_"+status_player).style.color = "#575757";
	else document.getElementById("sl_stop").style.color = "#575757";
}

////////////////////////////////////////////////////////////////////////////////////////
// function to correct the clear style if the window is too small (internet explorer) //
////////////////////////////////////////////////////////////////////////////////////////
function correct() {
	var browser=navigator.appName;
	if (browser=="Microsoft Internet Explorer") window.resizeBy(0,-1);
}

////////////////////////////////////////////////////////////////////////////////////////
// function to correct the clear style if the window is too small (internet explorer) //
////////////////////////////////////////////////////////////////////////////////////////
function open_link(where) {
	location.href = where;
}



