// JavaScript Document
/************************************
Validation de formulaire
************************************/
function gId(i,p){return(p||document).getElementById(i)}

function checkForm(form,inputT)
{    
    var ret = true;
    for ( var x = 0 ; x < inputT.length ; x++ ) {
      if(form.elements[inputT[x]].value == "" ){
          alert("All text noted by the (*) must be completed, please : "+inputT[x]);
          ret = false;
      }
    }
    return ret;
}

/******************************************
Affiche le div d de divT et cache les autres
******************************************/
function swapDivT( d , divT )
{
	for ( var x = 0 ; x < divT.length ; x++ ) 
	{
		var div = gId(divT[x]);	
		if ( divT[x] == d )
		    div.style.display = "block";
		else div.style.display = "none";
	}
}

/******************************************
Affiche / Cache le div d 
******************************************/
function showHide( d )
{
	var div = gId(d);	
	//alert('in showHide '+div.style.display);
	if ( div.style.display == "none" )
	 div.style.display = "block";
	else
     div.style.display = "none";
}
//Td is an array build of [div,"",div1,"inline"...]
function showDiv(Td)
{
	for(var ct=0 ; ct < Td.length ; ct ++)
	{
		var div = gId(Td[ct]);	
	 	if(Td[ct+1]=="inline")
		 	div.style.display = "inline";
		else
			div.style.display = "block";
		ct++;
	}
}
function hideDiv( Td )
{
	for(var ct=0 ; ct < Td.length ; ct ++)
	{
		div=gId(Td[ct]);
		if(div)div.style.display="none";
    }
}

function showHideInfo( iddiv , idhtml , type , id, user, file)
{
	//parametre pour ajouter photo/comment xtra sur cette entr?
	if(document.xtraForm){
		document.xtraForm.id.value = id;
		document.xtraForm.type.value = type;
	}
	//rempli le tableau d'image de l'album photo xtraT
	ajaxGetXtras(type , id , 'photo' , cpath+'users/'+user+'/gfx/'+type+'/'+file);
	
	var html = ajaxGetHtml(type , id, user, file);
	//swap the active html section
	gId(idhtml).innerHTML = html;	
	//show the whole containing div
	var div = gId(iddiv);
	if ( div.style.display == "none" )
	 div.style.display = "block";
}
/*******************************************
*Generates a random Hexa color
*******************************************/
function genHex()
{
    colors = new Array(14);
    colors[0]="0";
    colors[1]="1";
    colors[2]="2";
    colors[3]="3";
    colors[4]="4";
    colors[5]="5";
    colors[5]="6";
    colors[6]="7";
    colors[7]="8";
    colors[8]="9";;
    colors[9]="a";
    colors[10]="b";
    colors[11]="c";
    colors[12]="d";
    colors[13]="e";
    colors[14]="f";
    
    digit = new Array(6);
    color="";
    for (i=0;i<7;i++)
    {
        digit[i] = colors[Math.round(Math.random()*14)];
        color = color+digit[i];
    }
    return "#"+color;
}

/*******************************************
*Cleans a string of its white spaces replacing them with underscores
*******************************************/
function CleanFileName(name,lower){
	name = name.replace(/ /g, "_");
	name = name.replace(/'/g, "");
	name = name.replace(/"/g, "");
	if(lower)
		return name.toLowerCase();
	else 
		return name;
}

/*******************************************
* Some input value mustn't be shown according to the chosen lodging 
*******************************************/
function showHideLodging(type)
{
	if(type == "myhouse")
	{
		gId("price").style.display = "none";
		gId("minstay").style.display = "none";
		gId("adv").style.display = "none";
	} else if(type == "house4sale")
	{
	    gId("price").style.display = "block";
		gId("payperiod").style.display = "none";
		gId("minstay").style.display = "none";
		gId("adv").style.display = "none";
	} else 
	{
		gId("price").style.display = "block";
		gId("payperiod").style.display = "inline";
		gId("minstay").style.display = "block";
		gId("adv").style.display = "block";
	}	
}
/*******************************************
//xtraT et xtraTindex sont des variable globale de la page
******************************************/
function manuelDiapo(sens)
{ 
	if(sens == "next")
	{
		if(xtraTindex < xtraT.length-1)
		 xtraTindex++;
		else 
		  xtraTindex = 0;
	 }
	else 
	{
		if(xtraTindex > 0)
			xtraTindex--;
		else
			xtraTindex = xtraT.length-1; 
	}
	document.images.SlideShow.src = xtraT[xtraTindex];
	//for SlideSHow Diaporama weird bug 
	if(rundiap)
		setTimeout("manuelDiapo('"+sens+"')",1000);
}
function setCoord(city,lat,lon)
{
	rCl(gId('suggest'),'show');
	gId('city').value = city;
	gId('formlat').value = lat;
	gId('formlong').value = lon;
	tmp = typeof mapform;
	if(tmp != undefined && tmp != null)
		mapform.setCenter(new GLatLng(lat,lon),3);
}
