// JavaScript Document
function favoris() { 
if ( navigator.appName != 'Microsoft Internet Explorer' ) 
{ window.sidebar.addPanel("BOURSEA : la bourse aux devis","http://www.boursea.com",""); } 
else { window.external.AddFavorite("http://www.boursea.com","BOURSEA : la bourse aux devis"); } } 

function inputMask(champs){
	var longueur = champs.value;
	longueur.toString();

  	if(longueur.length==1){
      if(champs.value>2){
         champs.value = "0"+longueur;
         champs.value = champs.value + ":";
      }
   }
   if(longueur.length==2){
      if(champs.value<=23){
      champs.value = longueur + ":";
      }else{
      alert("Veuillez entrer une heure valide");
      champs.value ="";
      }
      }
   if(longueur.length==5){
         long2 = longueur.slice(3,5);        

         if(long2 > 60){
         alert("Le nombre de minute n'est pas valide");
         champs.value = longueur.slice(0,3);
         }
   }

}

function hidElement(objId) {
	if(document.getElementById(objId) != null) {
		document.getElementById(objId).style.visibility = 'hidden';
		document.getElementById(objId).style.display = 'none';
	}
}
function showElement(objId) {
	if(document.getElementById(objId) != null) {
		document.getElementById(objId).style.visibility = 'visible';
		document.getElementById(objId).style.display = 'block';
	}
}
function switchVisibility(objId) {
	if(document.getElementById(objId) != null) {
		if(document.getElementById(objId).style.visibility == "visible") {
			hidElement(objId);
		} else {
			showElement(objId);
		}							
	}
	return true;
}

var activMenu = "sidebar2_met1";

function hidPanels() {
	hidElement('sidebar2_met1');
	hidElement('sidebar2_met2');
	hidElement('sidebar2_met3');
	hidElement('sidebar2_met4');
	
	document.getElementById("sidebar2_img1").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.habitat.gif";
	document.getElementById("sidebar2_img2").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.service.gif";
	document.getElementById("sidebar2_img3").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.finance.gif";
	document.getElementById("sidebar2_img4").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.entreprise.gif";
}

function switchPanel(name) {
	hidPanels(); 
	showElement(name);
	activMenu = name;
	
	if(name == "sidebar2_met1") {
		document.getElementById("sidebar2_img1").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.habitat_f2.gif";
	}
	if(name == "sidebar2_met2") {
		document.getElementById("sidebar2_img2").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.service_f2.gif";
	}
	if(name == "sidebar2_met3") {
		document.getElementById("sidebar2_img3").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.finance_f2.gif";
	}
	if(name == "sidebar2_met4") {
		document.getElementById("sidebar2_img4").src = "http://"+window.location.host+"/themes/boursea/website/pictures/home.website.entreprise_f2.gif";
	}
}

function reloadField(fieldId, nameOfTable, idParent) {
	var callback = {
		success : function(o) {
			document.getElementById('fld_'+fieldId).innerHTML = o.responseText;       
        },
        failure : function(o) { alert('PB');  }
	}
    var conn = YAHOO.util.Connect.asyncRequest("POST", 'http://'+window.location.host+'/boursea/manager/?action=field_reload&fdt_id='+fieldId+'&fpt_code='+nameOfTable+'&fpa_idparent='+idParent, callback);    
}


// Ouverture Ajax des Metier
function reloadSelect(fieldId, paramName, value) {
	if(value == "") value = "-1";
	
	var callback = {
		success : function(o) {
			document.getElementById(fieldId).innerHTML = o.responseText;       
        },
        failure : function(o) { alert('PB');  }
	}
	if(value != -1) {
    	var conn = YAHOO.util.Connect.asyncRequest("POST", '/boursea/website/?action=reloadSelect&'+paramName+'='+value, callback);
    } 
}

// Appel du formaulaire
function loadFormulaire(fieldId, value) {
	
	var Pwait = new YAHOO.widget.Panel("wait", { width: "240px", 
                                                     fixedcenter: true, 
                                                     close: false, 
                                                     draggable: true, 
                                                     zindex:90,
                                                     modal: false,
                                                     visible: false
                                                   } 
                                               );
    Pwait.setHeader("Chargement, veuillez patienter ...");
    Pwait.setBody("<img src=\"http://"+window.location.host+"/themes/boursea/website/pictures/rel_interstitial_loading.gif\"/>");
    Pwait.render(document.getElementById('sidebar4'));
    Pwait.show();
	
	setTimeout('loadFormulaireLoad("'+ fieldId +'",'+ value +')', 500);
	
	return;
}

function loadFormulaireLoad(fieldId, value) {
	var callback = {
		success : function(o) {
			document.getElementById(fieldId).innerHTML = o.responseText;
        },
        failure : function(o) { alert('PB'); }
	}
	
	if(value != -1) {             
    	var conn = YAHOO.util.Connect.asyncRequest("POST", '/boursea/website/?action=formulaire_edit&for_id='+value, callback);
    }
}
// Chargement des Tooltip sur formulaire
function loadTT() {
	if(document.getElementById('ttJavascript') != null) {
		eval(document.getElementById('ttJavascript').innerHTML);
	}
	return;
}


//Google maps
var map = null;
var geocoder = null;

function load() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GScaleControl());
	map.addControl(new GOverviewMapControl());
	map.addControl(new GMapTypeControl());
	geocoder = new GClientGeocoder();
  }
}
	
function showAddress(address,infobulle) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  alert(address + " not found");
		} else {
		  map.setCenter(point, 13);
		  var marker = new GMarker(point);
		  map.addOverlay(marker);
		  GEvent.addListener(marker, "click", function() {
        		  	marker.openInfoWindowHtml(infobulle);
      		  });
		  marker.openInfoWindowHtml(infobulle);
		}
	  }
	);
  }
}

function init() {
	YAHOO.overlay1 = new YAHOO.widget.Overlay("hdespace", { y:65, visible:false,
																width:"220px",
																zIndex:1000,
																effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}} );
	YAHOO.overlay1.render("body");
	YAHOO.util.Event.addListener("sinscrire", "mouseover", YAHOO.overlay1.show, YAHOO.overlay1, true);
	YAHOO.util.Event.addListener("mainContent", "mouseover", YAHOO.overlay1.hide, YAHOO.overlay1, true);
}

YAHOO.util.Event.onDOMReady(init);
