function write_menu(v_selected_index, flag_first_load) {
	
	var so_menu = new SWFObject("./_flash/banner_adl.swf", "banner_adl", "1000", "150", "8");
	//so_menu.addVariable("selected_index", v_selected_index);
	so_menu.addVariable("selected_index", "3");
	//so_menu.addVariable("first_load", flag_first_load);
	so_menu.addParam("wmode", "transparent");	
	so_menu.write("menu_flash");	
}

function doc_id(v_element) {
	return document.getElementById(v_element);
}

function print_debug(v_message) {
		
	if (!doc_id("desktop_debug")) {
		
		var div_debug = document.createElement("div");
		div_debug.setAttribute("id","desktop_debug");
		div_debug.style.position = "fixed";
		div_debug.style.width = "200px";
		div_debug.style.height = "200px";
		div_debug.style.right = "0";
		div_debug.style.top = "0";
		div_debug.style.backgroundColor = "#ffffff";
		div_debug.style.border = "solid 1px #000000";
		div_debug.style.zIndex = 1000;
		document.body.appendChild(div_debug);
	}
	
	doc_id("desktop_debug").innerHTML = v_message;			
}			


function search_button_click(v_uid) {
	
	if (document.getElementById("div_search")) {
		
		if (parseInt(document.getElementById("div_search").style.height.replace("px",""))<=50) {
			
			open_search_div();
			
		}else {
			switch(v_uid.toUpperCase()) {
				case "ACHETER": 	document.location.href='achats.html'; 		break;
				case "VENDRE":		document.location.href='ventes.html';		break;
				case "LOUER": 		document.location.href='locations.html';	break;
			}
		}
	}
}

function open_search_div() {
	
	if (document.getElementById("div_search")) {
		v_height = parseInt(document.getElementById("div_search").style.height.replace("px",""));
		
		if ( parseInt(v_height) < 320) {
			v_height += 20;
			document.getElementById("div_search").style.height = v_height +"px";
			
			setTimeout("open_search_div()" , 25);		
		} else {
			document.getElementById("div_search").style.height = "320px";
		}
	}
}

/* Add an event listener to the specified object, and map it with the specified function */
function addEventListener2(obj,event,fct){
	
     if(obj.attachEvent)
        obj.attachEvent('on' + event,fct);
     else
        obj.addEventListener(event,fct,true);
}

function set_body(v_select) {
	v_body_picture = v_select.value;
	if (v_body_picture.length<=0) return false;
	
	document.body.style.backgroundImage = "url('" +v_body_picture +"')";
	
}
function set_sort_mode() {
	
	var v_sort_mode = "1";
	if (document.getElementById("s_sort_mode")) v_sort_mode = document.getElementById("s_sort_mode").value;
	
	fill_div("div_results_detail","./results.php?sort=" +v_sort_mode);
}

function page_next() {
	
	var v_page = 0;
	if (document.getElementById("t_page")) {
		v_page = document.getElementById("t_page").value;
		set_page(parseInt(v_page)+1);
	}
}

function page_previous() {
	
	var v_page = 0;
	if (document.getElementById("t_page")) {
		v_page = document.getElementById("t_page").value;
		set_page(parseInt(v_page)-1);
	}	
}
function set_page(v_page) {
	
	fill_div("div_results_detail","./results.php?page=" +v_page);
}

function show_bien(v_idbien, v_idsource, v_url_name) {
	
	document.location.href= "./bien-" +v_idbien +"-" +v_idsource +"-" +v_url_name +".html";
}

function check_search() {
	
	
	return true;
}

function search_biens() {
	
	if (!check_search()) return false;	

	if (document.getElementById("flag_send")) document.getElementById("flag_send").value = "1";
	if (document.getElementById("form_search")) document.getElementById("form_search").submit();	
	
}

function set_type_offre(v_type_offre) {
		
	switch(v_type_offre.toUpperCase()) {		
		
		case "ACHETER":
			if (document.getElementById("type_offre")) document.getElementById("type_offre").value ="1";
			if (document.getElementById("span_offre_acheter")) document.getElementById("span_offre_acheter").style.color = "#e4b759";
			if (document.getElementById("span_offre_vendre")) document.getElementById("span_offre_vendre").style.color = "#ffffff";
			if (document.getElementById("span_offre_louer")) document.getElementById("span_offre_louer").style.color = "#ffffff";
			set_search_mode();
		break;
		
		case "LOUER":
			if (document.getElementById("type_offre")) document.getElementById("type_offre").value ="2";
			if (document.getElementById("span_offre_acheter")) document.getElementById("span_offre_acheter").style.color = "#ffffff";
			if (document.getElementById("span_offre_vendre")) document.getElementById("span_offre_vendre").style.color = "#ffffff";
			if (document.getElementById("span_offre_louer")) document.getElementById("span_offre_louer").style.color = "#e4b759";
			set_search_mode();
		break;
	}
}

function set_result_mode() {
	
	if (document.getElementById("div_search")) document.getElementById("div_search").style.height = "50px";
	if (document.getElementById("div_loves")) document.getElementById("div_loves").style.display = "none"
	if (document.getElementById("div_results")) document.getElementById("div_results").style.display = ""	
}

function set_search_mode() {
	
	if (document.getElementById("div_search")) document.getElementById("div_search").style.height = "320px";
	if (document.getElementById("div_loves")) document.getElementById("div_loves").style.display = ""
	if (document.getElementById("div_results")) document.getElementById("div_results").style.display = "none"
	if (document.getElementById("div_results_loading")) document.getElementById("div_results_loading").style.display = "none"
	if (document.getElementById("div_results_detail")) document.getElementById("div_results_detail").style.display = "none"
	
}

function focus_control(v_control,v_text) {
		
	try {
		
		/*v_value = v_control.value.replace(/é/g,"e");
		v_value = v_control.value.replace(/\351/g,"e");
		v_value = trim(v_value.toUpperCase());*/
		
		//v_text  = v_text.replace(/é/g,"e");
		//v_text = v_text.replace(/\351/g,"e");
		//v_text = trim(v_text.toUpperCase());		

		v_value = v_control.value;
		//v_value = v_control.value.replace(é/g,"e");
		//v_value = v_control.value.replace(/\351/g,"e");
		v_value = trim(v_value.toUpperCase());
		
		/*v_text  = v_text.replace(é/g,"e");
		v_text = v_text.replace(/\351/g,"e");
		*/
		v_text = trim(v_text.toUpperCase());		

		if (v_value == v_text) {
			v_control.style.color = "#000000";
			v_control.value = "";
			//v_control.focus();
		}
		
	}catch(evt) { } 	
}

function blur_control(v_control,v_text) {
	
	
	try {

		//v_text = v_text.replace(/é/g,"\351");
		//v_text = v_text.replace(é/g,"\351");
		
		if (v_control.value.length<=0) {
			
			v_control.style.color = "#000000";
			v_control.value = v_text;
			//v_control.focus();
		}
		
	}catch(evt) { } 	
}

function check_div(v_div_string, v_hidden_string) {

	try {
		
		if (!document.getElementById(v_hidden_string)) return false;
		if (!document.getElementById(v_div_string)) return false;
		
		v_class_Name = "class";
		if (navigatori_is_IE()) v_class_Name = "className";		
		
		var v_hidden = document.getElementById(v_hidden_string);
		var v_div = document.getElementById(v_div_string);
	
		if (v_hidden.value == "0") {
			v_div.setAttribute(v_class_Name, "div_checkbox_selected");		
			v_hidden.value = "1";
		} else {
			v_div.setAttribute(v_class_Name, "div_checkbox");		
			v_hidden.value = "0";
		}
		
	}catch(evt) { }
}

function trim(myString){
	
	try {
		
		return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
		
	}catch(evt) { }
} 

function jstring(v_string) {
	
	try {
		
		v_string_out = v_string;
		
		return v_string_out;
		
	}catch(evt) { } 
}


function isEmail(String){
	
	try {
		
		emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/
		return emailRegExp.test(String);
		
	}catch(err) {
		
		catch_error("isEmail",err);
	}
}



function ajax(v_httpFile) { 	
		
	try {
		
		if(window.XMLHttpRequest) // FIREFOX
		  	xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // IE
		  	xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return(false);
						
		xhr_object.open("GET", v_httpFile, false);
		xhr_object.send(null);
		if(xhr_object.readyState == 4) {
				return xhr_object.responseText;								
		}			
		
	}catch(err) {
		
		catch_error("ajax",err);
	}		
}

function fill_div(div_id, v_httpFile) { 	
		
	try {
		
		if(window.XMLHttpRequest) // FIREFOX
		  	xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // IE
		  	xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else
			return(false);
						
		xhr_object.open("GET", v_httpFile, false);
		xhr_object.send(null);
		if(xhr_object.readyState == 4) {
			if (document.getElementById(div_id))
				document.getElementById(div_id).innerHTML = xhr_object.responseText;				
				
				try {
					
					var AllScripts=xhr_object.responseText.extractTags("script");
					AllScripts.forEach(function (v) {						
					eval(v);
					})
					
				} catch (ex) {}
					
								
		}
		else 
			return(false);
			
	}catch(err) {
		
		catch_error("fill_div",err);
	}		
}

String.prototype.extractTags=function(tag) {
	
    var matchAll = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'img');
    var matchOne = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'im');
    return (this.match(matchAll) || []).map(function(scriptTag) {
      return (scriptTag.match(matchOne) || ['', ''])[1];
    });
  }
 
Object.prototype.forEach=function(delegate, ownpropertiesonly) {
	
        if (typeof(delegate)=="function") {
            if (this instanceof Array && typeof(ownpropertiesonly)=="undefined") {
                ownpropertiesonly=true;
            }
            for (key in this) {
                var ok = (!ownpropertiesonly);
                if (!ok) {
                    try {
                        ok=this.hasOwnProperty(key)
                    } catch (ex) {}
                }
                if (ok) {
                    try { delegate(this[key], key, this) } catch(e) {
                        // ...
                    }
                }
            }
        }
        return false;
    }
 
Object.prototype.map=function(iterator) {
	
    var results = [];
    this.forEach(function(value, index) {
      results.push(iterator(value, index));
    });
    return results;
  }



function get_ie_version(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}
function write_flash(v_id, v_flash_file, v_animation_width, v_animation_height, v_width, v_height, v_style, v_bgcolor, v_flashvars) {
			
	var v_string = "";
	
	var v_screen_width = document.body.parentNode.scrollWidth;
	var v_screen_height = document.body.parentNode.scrollHeight;	

	//var v_screen_width =   document.body.clientWidth;
	//var v_screen_height = document.body.scrolltHeight;	
	
	//alert(v_screen_width);
	
	if (v_style == undefined) v_style = "";
	if (v_bgcolor == undefined) v_bgcolor = "";
	if (v_flashvars == undefined) v_flashvars = "";
	if (v_width == undefined) v_width = "";
	if (v_height == undefined) v_height = "";
	
	if (v_width.length<=0) v_width = v_screen_width;
	if (v_height.length<=0) v_height = v_screen_height;
	
	if (navigator.appName.toUpperCase() == "NETSCAPE") v_width = v_width - 16;
	if (get_ie_version() == 6) v_width = v_width - 16;			
	
	v_string = "";	
	v_string += "<div style='" +v_style +"'>";
		
	v_string += "<object style='position:relative; margin:0; padding:0;' id='" +v_id +"' type='application/x-shockwave-flash' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' data='" +v_flash_file +"' width='" +v_animation_width +"px' height='" +v_animation_height +"'>";

	v_string += "	<param name='movie' value='" +v_flash_file +"' />";
	v_string += "	<param name='quality' value='high' />";
	v_string += "	<param name='AllowScriptAccess' value='always' />";

	
	if (v_bgcolor.length<=0)
		v_string += "	<param name='wmode' value='transparent' />";
	else
		v_string += "	<param name='bgcolor' value='" +v_bgcolor +"' />";
		
	if (v_flashvars.length<=0) {
		v_flashvars = "my_width=" +v_width +"&amp;my_height=" +v_height;
	} else {
		v_flashvars += "&amp;my_width=" +v_width +"&amp;my_height=" +v_height;
	}
	
	v_string += "	<param name='flashvars' value='" +v_flashvars +"' />";	
	
	v_string += "<embed style='margin:0; padding:0;' AllowScriptAccess='always' flashvars='" +v_flashvars +"' src='" +v_flash_file +"' quality='autohigh' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" +v_animation_width +"' height='" +v_animation_height +"'";
	
	if (v_bgcolor.length<=0)
		v_string += "wmode='transparent'>";
	else
		v_string += "bgcolor='" +v_bgcolor +"'>";
		
	v_string += "</embed>";
	
	v_string += "</object>";
	
	v_string += "</div>";

	document.write(v_string);
}
