// Protection de la page
function droit(e) {
 if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
return false;
 else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
  alert('Powered by Open Media!')
  return false;
 }
 return true;
}
document.onmousedown=droit;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=droit;

sas_tmstp=Math.round(Math.random()*10000000000);sas_masterflag=1;
function SmartAdServer(sas_pageid,sas_formatid,sas_target) {
 if (sas_masterflag==1) {sas_masterflag=0;sas_master='M';} else {sas_master='S';};
 document.write('<SCR'+'IPT SRC="http://www.smartadserver.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></SCR'+'IPT>');
}

function shadeTable(name, bgcolor_odd, bgcolor_even)
{
    var table = document.getElementById(name);
    if (!table) { alert("Could not find id "+name); return; }
    var allTRs = table.getElementsByTagName("tr");
    if (!allTRs) { alert("Missing TR elements in table id "+name); return; }
//    var bgcolor_odd = document.getElementById('shade_odd').style.backgroundColor;
    if (!bgcolor_odd) { alert("Missing stylesheet attribute shade_odd"); return; }
//    var bgcolor_even = document.getElementById('shade_even').style.backgroundColor;
    if (!bgcolor_even) { alert("Missing stylesheet attribute shade_even"); return; }
    for (i=0; i < allTRs.length ; i++)
    {
        if (i % 2 == 1)
            allTRs[i].style.backgroundColor = bgcolor_odd;
        else
            allTRs[i].style.backgroundColor = bgcolor_even;
    }
}

//Highlight image script- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

function makevisible(cur,which){
strength=(which==0)? 1 : 0.8

if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

// End of Dynamic Drive section

// pour empecher le clique droit sur les liens de la page:
for (var i=0; i<document.links.length; i++)
document.links[i].onmousedown=droit;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

var NullString  = "";
var AucunTxt	= new Array ("Tous","",NullString,"");

function FillListWithArray (objet, my_array)
{
	var i = 0;
	CleanUpList(objet);
	while(my_array[i])
	{
		AddOptionList(objet, my_array[i+1], my_array[i]);
		i+=2;
	}
}

// Genere le tableau d'arrondissement
function GenerateArrondissementArray (ville, max)
{
	var myArray = new Array();
	var i,c;
	
	myArray[0]   = "Tous";
	myArray[1] = "";
	for(c=2,i=1;i<=max;i++,c+=2)	
	{
		myArray[c]   = ville + " " + i;
		myArray[c+1] = i;
	}
	myArray[c]  = NullString;
	myArray[c+1]= "";

	return myArray;
}

function OnArronClick()
{
	var Ville = document.multi.ville.value; 
	Ville = Ville.toUpperCase();

	if (Ville.indexOf(" ",0) > 0)	Ville=Ville.substring(0,Ville.indexOf(" ",0));
	
	switch(Ville)
	{
		case "MARSEILLE": FillListWithArray(document.multi.arrondisiment, GenerateArrondissementArray("Marseille", 16)); if (document.multi.departement) document.multi.departement.value='13'; break;
		case "PARIS"	: FillListWithArray(document.multi.arrondisiment, GenerateArrondissementArray("Paris", 20)); if (document.multi.departement) document.multi.departement.value='75'; break;
		case "LYON"	 	: FillListWithArray(document.multi.arrondisiment, GenerateArrondissementArray("Lyon", 9)); if (document.multi.departement) document.multi.departement.value='69'; break;
		default		 	: FillListWithArray(document.multi.arrondisiment, AucunTxt); if (document.multi.departement) document.multi.departement.value=''; break;
	}
}
function CleanUpList (objet)
{	
		
		if (objet) while (objet.length) objet.remove(0);

}
// Permet d'ajouter un element dans une liste
function AddOptionList (objet, href, texte)
{
	if (!objet) return;
	var optionName = new Option (texte, href, false, false);
    var length 	   = objet.length;

    objet.options[length] = optionName;
}

function open_window(url, popup_width, popup_height)
{
	window.open(url,'OpenMedia','width='+popup_width+',height='+popup_height+',menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,top=80,left=140'); 
}

function vVirtuelle(url)
{
	open_window(url, 760, 515);
}

function submit_popup(form)
{
	form.submit();
	window.close();
}

function GoContact(url)
{
	open_window(url, 800,480);
}

function GoImpri()
{
	window.print();
}

function validateForm(object)
{
	if (object.postcode.value.length > 2)
		object.departement.value = object.postcode.value.substr(0,2);
	if (object.departement.value == "" && object.pays.value == "FRANCE")
		alert(word_departement+"?");
	else if (object.type.value == "")
		alert(word_subtype+"?");
	else
	{
		if (object.rooms.value == 8)
		{
			object.rooms.value = '';
			object.rooms8plus.value = 'true';
		}
		object.submit();
	}
}

function clearRooms()
{
//	int i;
	if (document.multi['rooms[0]'].checked == true)
	{
		for (i = 1; i < 8; i++)
			document.multi['rooms['+i+']'].checked = false;
		document.multi.rooms8plus.value = "true";
		document.multi.tmp_rooms8plus.checked = "";
	}
	else
	{
		document.multi.rooms8plus.value = "";
	}
}

function roomChecked()
{
	document.multi['rooms[0]'].checked=false;
}

/* OLD FUNCTION - DO NOT USE */
function countRooms()
{
	document.multi['rooms[0]'].checked=false;
	document.multi.rooms8plus.value = (document.multi.tmp_rooms8plus.checked?"true":"");
}

function roomsUncheck(num)
{
	var i;
	for (i = 1; i <= num; i++)
		document.multi['rooms['+i+']'].checked=false;
}

function GetCookie (name)
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen)
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function DeleteCookie (name)
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function amt()
{
	var count = GetCookie('count')
	if(count == null)
	{
		SetCookie('count','1')
		return 1
	}
	else
	{
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
   }
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function showPopup(url, width, height)
{
	var exp = 7;
	var count = GetCookie('count');
	if (count == null)
	{
		count=1;
		SetCookie('count', count, exp);
		open_window(url, width, height);
	}
	else
	{
		count++;
		SetCookie('count', count, exp);
	}
}

function getQueryVariable(variable)
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++)
  {
    var pair = vars[i].split("=");
    if (pair[0] == variable)
	{
      return pair[1];
    }
  } 
//  alert('Query Variable ' + variable + ' not found');
 return '';
}

/* Used in search forms to set whether sector or arrond. depending on dept */
function setSectorText(departement,text1,text2)
{
	if (departement==75 || departement==69 || departement==13)
		document.getElementById('sectorText').innerHTML=text2;
	else
		document.getElementById('sectorText').innerHTML=text1;
}

/* Dummy comment at end */

