// Fonction spécifiques à la section immobilier
var resultData = new Object;
function coche_1()
{
document.getElementsByName("mode")[0].checked = 1;
document.getElementsByName("ville")[0].checked = 1;
}
function ins_chx(p)
{
var i = document.forms["immobilier"].elements["type"].selectedIndex;
if (i==0){ins_pieces(0);}
if (i==1){ins_pieces(1);}
if (i==2){ins_surfaces();}
if ((i==3)&&(p==0)){ins_vide();}
if ((i==3)&&(p==1)){ins_vide();avertir('immobilier','type');}
}
function ins_communes()
{
so_clearInnerHTML(document.getElementById("precision"));
so_clearInnerHTML(document.getElementById("precision_choix"));
document.getElementById("precision").appendChild(document.createTextNode("Pr\351cisez la commune :"));
var myData = new Array("---- Toutes communes -----","Abobo","Adjam\351","Angr\351","Att\351coub\351","Cocody","Koumassi","Marcory","Port-Bouet","Plateau","Rivi\351ra","Treichville","Yopougon","II Plateau","Autres");
var myShortData = new Array("all","abo","adj","ang","att","coc","kou","mar","por","pla","riv","tre","yop","2pl","autres");	//Attribut value des balises option créées
var list = so_createSelect(myData,myShortData,0);
list.setAttribute("name","commune");	//Attribut name de la balise select créée
document.getElementById("precision_choix").appendChild(list);
}
function ins_villes()
{
so_clearInnerHTML(document.getElementById("precision"));
so_clearInnerHTML(document.getElementById("precision_choix"));
document.getElementById("precision").appendChild(document.createTextNode("Pr\351cisez la ville :"));
var myData = new Array("-------- Toutes villes ---------","Abengourou","Aboisso","Bondoukou","Bouak\351","Bouna","B\351oumi","Dabou","Daloa","Danan\351","Daoukro","Dimbokro","Divo","Du\351kou\351","Ferkess\351dougou","Gagnoa","Grand-Bassam","Guiglo","Katiola","Korogho","Lakota","Odi\351n\351","Man","Mbahiakro","San-P\351dro","Sassandra","S\351gu\351la","Sinfra","Tiassal\351","Toumodi","Yamoussoukro", "Autres");
var myShortData = new Array("all","aben","aboi","bond","boua","boun","beou","dabo","dalo","dana","daou","dimb","divo","duek","ferk","gagn","bass","guig","kati","koro","lako","odie","man","mbah","pedr","sass","segu","sinf","tias","toum","yakro","autres");
var list = so_createSelect(myData,myShortData,0);
list.setAttribute("name","ville");
document.getElementById("precision_choix").appendChild(list);
}
function ins_pieces(p)
{
so_clearInnerHTML(document.getElementById("attrib"));
so_clearInnerHTML(document.getElementById("attrib_choix"));
document.getElementById("attrib").appendChild(document.createTextNode("Nombre de pi\350ces :"));
	if(p==0)
	{
	var myData = new Array("-------- Peu importe ----------","Studio","2 pi\350ces","3 pi\350ces","4 pi\350ces","5 pi\350ces","6 pi\350ces","7 pi\350ces","8 pi\350ces","9 pi\350ces","10 pi\350ces et plus");
	var myShortData = new Array("nochoice","1","2","3","4","5","6","7","8","9","10+");
	var list = so_createSelect(myData,myShortData,0);
	}
	if(p==1)
	{
	var myData = new Array("-------- Peu importe ----------","2 pi\350ces","3 pi\350ces","4 pi\350ces","5 pi\350ces","6 pi\350ces","7 pi\350ces","8 pi\350ces","9 pi\350ces","10 pi\350ces et plus");
	var myShortData = new Array("nochoice","2","3","4","5","6","7","8","9","10+");
	var list = so_createSelect(myData,myShortData,0);
	}
list.setAttribute("name","nbrpieces");
document.getElementById("attrib_choix").appendChild(list);
}
function ins_surfaces()
{
so_clearInnerHTML(document.getElementById("attrib"));
so_clearInnerHTML(document.getElementById("attrib_choix"));
document.getElementById("attrib").appendChild(document.createTextNode("Surface en m\350tre carr\351 :"));
var myData = new Array("-------- Peu importe ----------","Moins de 600","600 \340 1 200","1 200 \340 1 800","1 800 \340 2 400","2 400 \340 3 000","3 000 \340 3 600","3 600 \340 4 200","4 200 \340 4 800","4 800 \340 5 400","5 400 \340 6 000","6 000 \340 6 600","6 600 \340 7 200","7 200 \340 7 800","8 400 \340 9 000", "9 000 \340 9 600","Un hectare et plus");
var myShortData = new Array("nochoice","0-6","6-12","12-18","18-24","24-30","30-36","36-42","42-48","48-54","54-60","60-66","66-72","72-78","78-84", "84-90","90-96","h+");
var list = so_createSelect(myData,myShortData,0);
list.setAttribute("name","surface");
document.getElementById("attrib_choix").appendChild(list);
}
function ins_prix(p)
{
	so_clearInnerHTML(document.getElementById("prix"));
	/*so_clearInnerHTML(document.getElementById("prix_low"));
	so_clearInnerHTML(document.getElementById("prix_high"));*/
	if(p==0)
	{
		document.getElementById("prix").appendChild(document.createTextNode("Loyer mensuel :"));
		var myData = new Array(50000,100000,150000,200000,250000,300000,350000,400000,450000,500000,1000000);
	}
	if(p==1)
	{
		document.getElementById("prix").appendChild(document.createTextNode("Prix :"));
		var myData = new Array(2000000,10000000,20000000,30000000,40000000,50000000,1000000000);
	}
	/*var list = so_createSelect(myData,myData,0);
	var list1 = so_createSelect(myData,myData,0);
	list1.setAttribute("name","highp");
	document.getElementById("prix_low").appendChild(list);
	document.getElementById("prix_high").appendChild(list1);*/
	fillSelect('highp', myData);
	$('highp').options[2].selected="1"; //selectionne un montant par defaut
}
function switchPrice(id) {
	var disp, nondisp;
	if (id == 0) {
		disp = 'plocation';
		nondisp = 'pachat';
	}
	if (id == 1) {
		disp = 'pachat';
		nondisp = 'plocation';
	}
	document.getElementById(disp).style.display = 'block';
	document.getElementById(nondisp).style.display = 'none';
}
function ins_vide()
{
	so_clearInnerHTML(document.getElementById("attrib"));
	so_clearInnerHTML(document.getElementById("attrib_choix"));
}

function allAbidjan() { //check et uncheck les cases des communves d'abidjan
	var form1 = document.immobilier;
	var obj1 = form1.elements['city_0'];
	var status = (obj1.checked == true ? false: true);
	for (var i=0; i<10; i++) {
		var obj = form1.elements['city_' + i];
		obj.checked = status;
	}
}

function chkForm() {
	document.immobilier.submit();	
	return true;
}

function sendMsg () {
	//alert($('contUser').serialize(true)); return false;
	new Ajax.Request('../msg.php',
	{
		method:'post',
		parameters: $('contUser').serialize(true),
		onSuccess: function(response){
			var resultData = response.responseText;
			//alert(resultData); return false;
			var jsonData = Ext.util.JSON.decode(resultData);
			if (jsonData['error']) {
				Ext.MessageBox.show({
					title: 'Erreur',
					msg: jsonData['error'],
					buttons: Ext.MessageBox.OK,
					icon: Ext.MessageBox.WARNING
				});
				return false;
			}
			else {
				Ext.MessageBox.show({
					title: 'Confirmation',
					msg: 'Votre message a bien &eacute;t&eacute; envoy&eacute;',
					buttons: Ext.MessageBox.OK,
					fn: function () {
						eToggle('contFrame');
					}
				});

			}
		},
		onFailure: function(){
			alert('Something went wrong...');
			return false;
		}
	});
}

function switchOrder (n) {
	var form1 = document.fclone;
	form1.order.value = n;
	form1.submit();
}

function switchLimit (n) {
	var form1 = document.fclone;
	form1.num.value = n;
	form1.submit();
}

function switchPage (n) {
	var form1 = document.fclone;
	form1.page.value = n;
	form1.submit();
}

function switchName () {
	$('typeLibelle').innerHTML = ($('mode').value == '1' ? 'Prix de vente :': 'Loyer :');
	$('otherprice').style.display = ($('mode').value == '1' ? 'none': 'block');
}

function switchType() {
	if ($('htype').value == '0') {
		$('cfloor').style.display = 'inline';
	}
	else {
		$('cfloor').value = '';
		$('cfloor').style.display = 'none';
	}
	if ($('htype').value == '0' || $('htype').value == '1') {
		$('cdescription').style.display = 'block';
	}
	else {
		$('description').value = '';
		$('cdescription').style.display = 'none';
	}
}

function addFiles() {
	var no = 0;
	while ($('picture_'+ no)) {
		no++;
	}
	if (no < 4) $('addFile').innerHTML += '<input type="file" name="picture_'+no+'" id="picture_'+no+'" size="30" style="height:20px;"><br>';
	if (no == 3) $('addLink').style.display = 'none';
}

var maxWidth=100;
var maxHeight=100;
var fileTypes=["bmp","gif","png","jpg","jpeg"];
var outImage="previewField";
var defaultPic="spacer.gif";
var globalPic;

function preview(what){
	var field=document.getElementById(outImage);
	var source=what.value;
	var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
	for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
	globalPic=new Image();
	if (i<fileTypes.length) {
		field.src=source;
	}
	else {
		globalPic.src=defaultPic;
		alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
	}
	//field.src = globalPic.src;
}
