/*------------------------------------------------------------------*\

 Projet OSGOR immobilier

 Sous-systeme : Fonctions javascript en pagaille


 (C) Copyright Osgor 2005. 2006.

 Utilisation, reproduction et divulgation interdites
 sans autorisation ecrite de Osgor.

\*------------------------------------------------------------------*/



function file_ajax(fichier)
{
	
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", fichier, false);
xhr_object.send(null);
if(xhr_object.readyState == 4) return(xhr_object.responseText);
else return(false);
}

function afficheDiv(divname)
{
	if ( document.getElementById(divname) != null ) 
   	{
		document.getElementById(divname).style.visibility='visible';
    		document.getElementById(divname).style.display='block';
    	}
    	else
    	{
    		alert(" Erreur 001 : Le div " + divname + " n'existe pas " + chr(10) + " Contactez info@osgor.com")
    	}
}

function cacheDiv(divname)
{

	if ( document.getElementById(divname) != null ) 
   	{
   		
		document.getElementById(divname).style.visibility='hidden';
	    	document.getElementById(divname).style.display='none';
	}
	
}

function action_bien(valeur,id,type_de_personne,redirect)
{
	
	if ( valeur == "restaurer" ) 
	{
		if ( confirm('Etes vous sur de vouloir restaurer ce bien ?') ) 
		{
			window.location="admin.php?action=gestion_affaires&action2=restaurer&id_bien=" + id;
		}
		
	}
	
	if ( valeur == "archiver" ) 
	{
		if ( confirm('Etes vous sur de vouloir archiver ce bien ?') ) 
		{
			window.location="admin.php?action=gestion_affaires&action2=archiver&id_bien=" + id;
		}
		
	}
	
	if ( valeur == "delete" ) 
	{
		if ( confirm('Etes vous sur de vouloir effacer ce bien ?\n\nCette suppression est définitive et iréversible.') )
		{
			window.location="admin.php?action=gestion_affaires&action2=delete&id_bien=" + id;
		}
		
	}
	
	if ( valeur == "vendu_agence" ) 
	{
		if ( confirm('Etes vous sur de vouloir archiver ce bien ?\n\nCe bien sera considéré comme vendu par l\'agence.') )
		{
			window.location="admin.php?action=gestion_affaires&action2=vendu_par_agence&id_bien=" + id;
		}
		
	}
	if ( valeur == "vendu_concurence" ) 
	{
		if ( confirm('Etes vous sur de vouloir archiver ce bien ?\n\nCe bien sera considéré comme vendu par un concurent.') )
		{
			window.location="admin.php?action=gestion_affaires&action2=vendu_par_concurence&id_bien=" + id;
		}
		
	}
	
	
	

}


function action_acq(valeur,id,ref,nom)
{
	
	if ( valeur == 'delete' ) {
		if ( confirm('Etes vous sur de vouloir supprimer défitivement l\'acquereur :\n\n' + nom + ' ( ' + ref + ')\n\nCette suppression est définitive et iréversible.') ) 
		{
			window.location="admin.php?action=nouveau_acquereur&id_acq=" + id + "&action2=delete";
		}
	}
}

function modifier_droit(droit,ref,id)
{


	if ( droit == '0' ) {
		if ( confirm('Etes vous sur de vouloir de rendre le bien ' + ref + ' privé ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_bien=" + id + "&action2=prive";
		}
	}
	if ( droit == '1' ) {
		if ( confirm('Etes vous sur de vouloir de rendre le bien ' + ref + ' public ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_bien=" + id + "&action2=public";
		}
	}
	if ( droit == '2' ) {
		if ( confirm('Etes vous sur de vouloir de diffuser ce bien vers okcommerces.com ? (' + ref + ') ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_bien=" + id + "&action2=diffuser_okcommerces";
		}
	}
	if ( droit == '3' ) {
		if ( confirm('Etes vous sur de vouloir de supprimer ce bien du site okcommerces.com ? (' + ref + ') ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_bien=" + id + "&action2=desactiver_okcommerces";
		}
	}
}

function modifier_droit_acq(droit,ref,id)
{
	if ( droit == '0' ) {
		if ( confirm('Etes vous sur de vouloir de rendre l\'acquereur ' + ref + ' privé ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_acquereur=" + id + "&action2=prive_acq";
		}
	}
	if ( droit == '1' ) {
		if ( confirm('Etes vous sur de vouloir de rendre l\'acquereur ' + ref + ' public ? ') ) 
		{
			window.location="admin.php?action=gestion_affaires&id_acquereur=" + id + "&action2=public_acq";
		}
	}
}			


function copier_valeur(from,to)
{
	if ( document.getElementById(from).value != "" ) {
		document.getElementById(to).value=document.getElementById(from).value;
	}
}
	
	
	
function setAllDep(the_form, do_check)
{ 
    var elts      = (typeof(document.forms[the_form].elements['local_liste_arrondissement[]']) != 'undefined')
                  ? document.forms[the_form].elements['local_liste_arrondissement[]']
                  : (typeof(document.forms[the_form].elements['local_liste_arrondissement[]']) != 'undefined')
          ? document.forms[the_form].elements['local_liste_arrondissement[]']
          : document.forms[the_form].elements['local_liste_arrondissement[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function


function calcul_fr(champ_euro,champ_fr)
{	
	if (document.getElementById && document.getElementById(champ_euro) != null && document.getElementById(champ_euro).value != "" ) 
    	{
			document.getElementById(champ_fr).value=convF(document.getElementById(champ_euro).value);
			if (document.getElementById && document.getElementById("tva_annuelle") != null  ) 
    			{
				update_tva();
			}
	}
}
			
			
function ejs_img_fx(img){ 
if(img && img.filters && img.filters[0]){
img.filters[0].apply();
img.filters[0].play();
}
}

function slowhigh(which2,baseopacity){
imgobj=which2
browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2,baseopacity){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
imgobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}
	
var horizontal_offset="9px"

var vertical_offset="0" 
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+(obj.offsetWidth-(obj.offsetWidth/2))+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox

function zoom(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480,left = 192,top = 144');");
}



function selectChange() {
  var myEle ;
  var x ;
  for (var q=recherche.secteur.options.length;q>=0;q--) recherche.secteur.options[q]=null;

  myEle = document.createElement("option") ;
  myEle.value = 0 ;
  myEle.text = "[SELECT]" ;
  recherche.secteur.appendChild(myEle)
 
 if ( recherche.zone.value == "") {
 	 for ( x = 1; x <= arrSecteur.length  ; x++ ) {
 	 	myEle = document.createElement("option") ;
      		myEle.setAttribute('value',arrCp[x]);
      		var txt = document.createTextNode(arrSecteur[x]);
      		myEle.appendChild(txt)
      		recherche.secteur.appendChild(myEle)
    }
 }else{
  for ( x = 1 ; x <= arrSecteur.length  ; x++ ) {
    if ( arrZone[x] == recherche.zone.value ) {
    	
      myEle = document.createElement("option") ;
      myEle.setAttribute('value',arrCp[x]);
      var txt = document.createTextNode(arrSecteur[x]);
      myEle.appendChild(txt)
      recherche.secteur.appendChild(myEle)
    }
  }
  }
}

var please_wait = null;

function open_url(url, target) {

	if ( ! document.getElementById) {
		var chaine="";
		document.location.href=chaine.replace("ajax=1",url);
	}
	 	
	if ( document.getElementById(target)  != null) 
	{
 		if ( ! document.getElementById) {
	  		return false;
	 	}

	 	if (please_wait != null) {
  			document.getElementById(target).innerHTML = please_wait;
 		}

 		if (window.ActiveXObject) {
	  		link = new ActiveXObject("Microsoft.XMLHTTP");
	 	} else if (window.XMLHttpRequest) {
  			link = new XMLHttpRequest();
 		}

 		if (link == undefined) {
	  		return false;
	 	}
	 	link.onreadystatechange = function() { response(url, target); }
	 	link.open("GET", url, true);
	 	link.send(null);
	}
	else
	{
		
		var chaine="";
		document.location.href=chaine.replace("ajax=1",url);
		
	}
	return true;
}

function response(url, target) {
 	if (link.readyState == 4) {
	 	document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the fallowing errorcode: " + link.status;
	}
}

function set_loading_message(msg) {
 	please_wait = msg;
}

set_loading_message("<br><br><br><br><center><font size=4>PAGE EN CHARGEMENT<br><br><img src='communs/images/loading_maps.gif'></center>");
