function change_photo(increment) {

	photo = photo + increment;

	if(photo > nb_photos)
		photo = 1;

	if(photo <= 0)
		photo = nb_photos;

	if(nb_photos > 0)
		document.getElementById("img").src = tab_photos[photo];
	else
		document.getElementById("img").src = "/static/photos/detail/default.jpg";
}

function zoom(options) {
	var largeur = 820;
	var hauteur = 670;
		
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;
	window.open("/mandats/"+id_annonce+"/zoom/"+photo,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


function valide_suppr(type) {

		if (type == "visite")
			var intitule = "cette visite";
		else if (type == "tour")
			var intitule = "ce tour";
		else if (type == "compte")
			var intitule = "ce compte";
		else if (type == "message")
			var intitule = "ce message";
		else if (type == "document")
			var intitule = "ce document";
		else if (type == "actualite")
			var intitule = "cette actualité";
		
		if (confirm("Etes-vous sûr de vouloir supprimer "+intitule+" ?"))
			return true;
		else
			return false;
}

function valide_desactive() {

	if (confirm("Etes-vous sûr de vouloir désactiver ce compte ?"))
		return true;
	else
		return false;
}

function valide_active() {

	if (confirm("Etes-vous sûr de vouloir activer ce compte ?"))
		return true;
	else
		return false;
}

function verif_saisie(type) {
	
	var valide = 0;
	
	if(type == "visites" || type == "tours"){
		//test sur la date
		if (document.getElementById('id_date_visite').value.search(/[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}/) != -1){
			document.getElementById('id_date_visite').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_date_visite').style.backgroundColor="#ffdfdf";
			
		//test sur l'heure
		if (document.getElementById('id_heure_visite').value.search(/[0-9]{1,2}:[0-9]{2}/) != -1){
			document.getElementById('id_heure_visite').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_heure_visite').style.backgroundColor="#ffdfdf";
		
		if (valide == 2)
			return true;
		else
			alert("Veuillez saisir correctement la totalité des champs colorés en rose.");
			return false;
	}
	else if(type == "infos_sia"){

		//Rue du bien
		if(document.getElementById('rue').value.length > 0){
			document.getElementById('rue').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('rue').style.backgroundColor="#ffdfdf";

		//Honoraires
		var honoraires=document.getElementById('honoraires').value;
		honoraires=honoraires.replace(" ","");
		if((honoraires.length>=2)&(honoraires>0)){
			document.getElementById('honoraires').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('honoraires').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('jour_deb').options[document.getElementById('jour_deb').selectedIndex].value != "--"){
			document.getElementById('jour_deb').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('jour_deb').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('mois_deb').options[document.getElementById('mois_deb').selectedIndex].value != "--"){
			document.getElementById('mois_deb').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('mois_deb').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('annee_deb').options[document.getElementById('annee_deb').selectedIndex].value != "--"){
			document.getElementById('annee_deb').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('annee_deb').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('jour_fin').options[document.getElementById('jour_fin').selectedIndex].value != "--"){
			document.getElementById('jour_fin').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('jour_fin').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('mois_fin').options[document.getElementById('mois_fin').selectedIndex].value != "--"){
			document.getElementById('mois_fin').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('mois_fin').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('annee_fin').options[document.getElementById('annee_fin').selectedIndex].value != "--"){
			document.getElementById('annee_fin').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('annee_fin').style.backgroundColor="#ffdfdf";
		

		if(valide<8){
			alert("Veuillez saisir correctement la totalite des champs colores en rose.");
				return false;
		}
		else{
			return true;
		}
	}
	else if(type == "mailing"){
		
		if(document.getElementById('id_sujet').value.length >= 3){
			document.getElementById('id_sujet').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_sujet').style.backgroundColor="#ffdfdf";

		if(document.getElementById('id_texte').value.length >= 20){
			document.getElementById('id_texte').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_texte').style.backgroundColor="#ffdfdf";
		
		if (valide == 2)
			return true;
		else{
			alert("Veuillez saisir correctement la totalité des champs colorés en rose.");
			return false;
		}
	}
}


function verif_compte() {
	
	var valide = 0;

		//Nom
		if(document.getElementById('id_nom').value.length > 1){
			document.getElementById('id_nom').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_nom').style.backgroundColor="#ffdfdf";

		//Prenom
		if(document.getElementById('id_prenom').value.length > 1){
			document.getElementById('id_prenom').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_prenom').style.backgroundColor="#ffdfdf";
		
		//Email
		ok = false ;
		var adr=document.getElementById('id_email').value;

		for (var j=1 ; j<(adr.length) ; j++) {
			if (adr.charAt(j)=='@') {
				if (j<(adr.length-4)){
					for (var k=j ; k<(adr.length-2) ; k++) {
						if (adr.charAt(k)=='.') 
							ok = true;
					}
				}
			}
		}
		if (ok==true){
			document.getElementById('id_email').style.backgroundColor="#ffffff";
			valide++;
		}
		else
			document.getElementById('id_email').style.backgroundColor="#ffdfdf";
		
		//Agence
		if(document.getElementById('id_site').options[document.getElementById('id_site').selectedIndex].value != "0"){
			document.getElementById('id_site').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_site').style.backgroundColor="#ffdfdf";

		
		//Login
		if(document.getElementById('id_login').value.length > 0){
			document.getElementById('id_login').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_login').style.backgroundColor="#ffdfdf";
			
			
		//Mots de passe
		if(document.getElementById('id_password').value.length == 6){
			document.getElementById('id_password').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_password').style.backgroundColor="#ffdfdf";
		
		if(document.getElementById('id_password_c').value.length == 6){
			document.getElementById('id_password_c').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else
			document.getElementById('id_password_c').style.backgroundColor="#ffdfdf";
		

		if (document.getElementById('id_password').value == document.getElementById('id_password_c').value && document.getElementById('id_password').value.length == 6){
			document.getElementById('id_password').style.backgroundColor="#f5f9fd";
			document.getElementById('id_password_c').style.backgroundColor="#f5f9fd";
			valide++;
		}
		else{
			document.getElementById('id_password').style.backgroundColor="#ffdfdf";
			document.getElementById('id_password_c').style.backgroundColor="#ffdfdf";
		}

		if(valide<8){
			alert("Veuillez saisir correctement la totalite des champs colores en rose.");
				return false;
		}
		else
			return true;
		
	}


function verif_archivage() {
	
	finalite = document.getElementById('id_finalite').options[document.getElementById('id_finalite').selectedIndex].value
	
	if(finalite == ''){
		alert("Veuillez cocher l'une des 2 propositions s'il vous plait");
		return false;
	}
	else if(finalite == 'V'){
	
			var finalite=document.getElementById('id_prix').value;
			
			var valide=0;
			
			var prix=document.getElementById('id_prix').value;
			prix=prix.replace(" ","");

			if(document.getElementById('id_date_operation').value.length==10){
				document.getElementById('id_date_operation').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_date_operation').style.backgroundColor="#ffdfdf";
			
			if((prix.length>=2)&(prix>0)){
				document.getElementById('id_prix').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_prix').style.backgroundColor="#ffdfdf";

			if(document.getElementById('id_site_vente').options[document.getElementById('id_site_vente').selectedIndex].value != "--"){
				document.getElementById('id_site_vente').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_site_vente').style.backgroundColor="#ffdfdf";

			if(document.getElementById('id_numero').value.length>0){
				document.getElementById('id_numero').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_numero').style.backgroundColor="#ffdfdf";

			if(document.getElementById('id_rue').value.length>2){
				document.getElementById('id_rue').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_rue').style.backgroundColor="#ffdfdf";

			if(document.getElementById('id_code_postal').value.length == 5){
				document.getElementById('id_code_postal').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_code_postal').style.backgroundColor="#ffdfdf";
			
			if(document.getElementById('id_commune').value.length > 1){
				document.getElementById('id_commune').style.backgroundColor="#f5f9fd";
				valide++;
			}
			else
				document.getElementById('id_commune').style.backgroundColor="#ffdfdf";

			if(valide < 7){
				alert("Veuillez saisir correctement la totalite des champs colorés en rose.");
					return false;
			}
			else
				return true;
	}
	else if(finalite == 'R'){
		if(document.getElementById('id_explications').value.length > 1){
				document.getElementById('id_explications').style.backgroundColor="#f5f9fd";
				return true;
		}
		else
			document.getElementById('id_explications').style.backgroundColor="#ffdfdf";
			alert("Veuillez saisir le motif de retrait s'il vous plait.");
			return false;

	}
}

function vers_detail(largeur,hauteur,id_annonce, type, options) {
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;

		window.open("/mandats/"+id_annonce+"/impressions/"+type,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function vers_pdf(id_mandat, type, options) {
	
	var largeur = 600;
	var hauteur = 540;
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;
	
	var types = "";
	
	if (document.getElementById('dea').checked)
		types += 'dea-';
	if (document.getElementById('dec').checked)
		types += 'dec-';
	if (document.getElementById('vpa').checked)
		types += 'vpa-';
	if (document.getElementById('vpo').checked)
		types += 'vpo-';

	types = types.substr(0, (types.length-1))

	window.open("/mandats/"+id_mandat+"/impressions/"+types+"/","","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function change_finalite(){
	finalite = document.getElementById('id_finalite').options[document.getElementById('id_finalite').selectedIndex].value
	if (finalite == "V"){
		//document.getElementById('infos_bien').style.display = 'block';
		document.getElementById('infos_vente').style.display = 'block';
		document.getElementById('explications').style.display = 'none';
	}
	else if (finalite == "R" | finalite == ""){
		//document.getElementById('infos_bien').style.display = 'none';
		document.getElementById('infos_vente').style.display = 'none';
		document.getElementById('explications').style.display = 'block';
	}
}

function verif_email() {
	
	var valide = 0;

	//Destinataire

	if(document.getElementById('destinataire').value != ""){
		document.getElementById('destinataire').style.backgroundColor="#f5f9fd";
		valide++;
	}
	else
		document.getElementById('destinataire').style.backgroundColor="#ffdfdf";

	//Sujet
	if(document.getElementById('sujet').value != ""){
		document.getElementById('sujet').style.backgroundColor="#f5f9fd";
		valide++;
	}
	else
		document.getElementById('sujet').style.backgroundColor="#ffdfdf";
		
	//Message
	if(document.getElementById('message').value != ""){
		document.getElementById('message').style.backgroundColor="#f5f9fd";
		valide++;
	}
	else
		document.getElementById('message').style.backgroundColor="#ffdfdf";
	
	if(valide < 3){
		alert("Veuillez saisir correctement la totalite des champs colorés en rose.");
		return false;
	}
	else
		return true;
}

