var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE6 = (navigator.userAgent.indexOf('MSIE 6') != -1)? true : false ;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;

function init(){
//	if($("navLeft")){
//		var myNavLeft = new NavLeft();
//	}
	
//	loadInputFocus();
}

Event.observe(window, 'load',init);



function loadInputFocus(){
	
	$$("#header input.inp").each( function(e) { addEventInputFocus(e); });
}
function addEventInputFocus(e){
	Event.observe(e, 'focus',focusInput.bindAsEventListener(this));
	Event.observe(e, 'blur',blurInput.bindAsEventListener(this));
}
function focusInput(e){
	if(e.currentTarget.value == e.currentTarget.alt) e.currentTarget.value = "";
	else if(e.currentTarget.value == e.currentTarget.title) e.currentTarget.value = "";
}
function blurInput(e){
	if(e.currentTarget.value == ""){
		if(e.currentTarget.alt) e.currentTarget.value = e.currentTarget.alt;
		else if(e.currentTarget.title) e.currentTarget.value = e.currentTarget.title;
	}
}


function loadLayer(obj){
	
	if(!$('maskLay')){
		var divmask = document.createElement("div");
		divmask.id="maskLay";
		divmask.style.visibility = "visible";
		divmask.style.height = $("container").getHeight();
		$("container").appendChild(divmask);
		rescueFrame($('maskLay'));
	}
	
	Event.observe($("maskLay"), 'click',function(){});
	
	obj.style.top = ($("container").getHeight()/2)-(obj.offsetHeight/2)+"px";
	obj.style.left = ($("container").getWidth()/2)-(obj.offsetWidth/2)+"px";
	obj.style.visibility = "visible";
	obj.style.zIndex = 20;
}

function closeLayer(obj){
	if($('maskLay')){
		removeRescueFrame($('maskLay'));
		$("container").removeChild($('maskLay'));
	}
	
	obj.style.visibility = "hidden";
}

function setBudget(valueMin,valueMax){
	//alert(valueMin+" - "+valueMax)
	$("priceMin").value = valueMin;
	$("priceMax").value = valueMax;
}

/***** rescueFrame *****/
function rescueFrame(obj){
	if(isIE && !isIE7){		
		if(!$('rescueFrame'+obj.id)){
			var rescueObj = document.createElement('iframe');
			var rescueElement = Element.up(obj).appendChild(rescueObj);
			rescueElement.id = 'rescueFrame'+obj.id;
			rescueElement.style.position = 'absolute';
			
			rescueElement.style.top = obj.offsetTop+'px'; 
			rescueElement.style.left = obj.offsetLeft+'px';
			
			rescueElement.style.width = obj.offsetWidth+'px'; 
			rescueElement.style.height = obj.offsetHeight+'px'; 
			//rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '0';
			rescueElement.style.filter = 'alpha(opacity=0);';
			rescueElement.style.zIndex = 0;
		}
	}
}
function removeRescueFrame(obj){
	if(isIE && !isIE7){
		if($('rescueFrame'+obj.id)){
			Element.up(obj).removeChild($('rescueFrame'+obj.id));
		}
	}
}
/*****************************/


function openBox(param){
	if (param == "oui"){
		GB_showCenter('title','/search_cicerone_pneu.aspx?id_secteur=6&id_famille=31&code_famille=10&code_sous_famille=1&connaissance_taille=1', 990, 990)
	}
	else if(param == "non"){
		//GB_showCenter('title','/search_cicerone_pneu.aspx?id_secteur=15&id_famille=112&code_famille=10&code_sous_famille=1&connaissance_taille=0', 990, 990)
		GB_showCenter('title','/search_cicerone.aspx?id_secteur=6&id_famille=31&code_famille=1&code_sous_famille=1', 420, 400)
	}
}

function openBoxAdvanced(id_secteur, id_famille, code_famille, code_sous_famille){
            //alert("id_secteur"+ id_secteur +"id_famille"+ id_famille +"code_famille"+  code_famille +"code_sous_famille"+ code_sous_famille);
            //GB_showCenter('title','', 550, 550)
	    GB_showCenter('title','/search_cicerone.aspx?id_secteur='+ id_secteur +'&id_famille='+ id_famille +'&code_famille='+  code_famille +'&code_sous_famille='+ code_sous_famille, 420, 380)
}



function validImmat(txt) {
    var valide = "";
    var alphanum = new RegExp("[A-Z0-9]");
    
    txt = txt.toUpperCase();
    
    for(var ii = 0; ii < txt.length;ii++) {
        if(alphanum.test(txt.substr(ii,1)))
            valide += txt.substr(ii,1);
    }
    
    return valide;
}