
function ChangeImage(diaporamaImage, annonce_id, num) {
	var nb_image = diaporamaImage.length;
	if (num.value == -1) {
		num.value = (nb_image-1);
	}
	if(document.getElementById) {
		if (!num.mini) {
		
			if (num.value_zoom == num.value) {
				num.value = (num.value-1+nb_image)%nb_image ;
			} 
			
			for (i = 1; i < nb_image; i++) {
				document.getElementById('div_diaporama_' + annonce_id + '_mini_' + i).innerHTML ='<img src="'+ rep_mini + diaporamaImage[(num.value + i)%nb_image] + '" onclick="changeAndStopDiaporama(num_'+annonce_id+', \''+annonce_id+'\', '+(num.value + i)%nb_image+');return false;"/> ';
			}
			rep_main = rep;
		}
		else {
			rep_main = rep_mini;
		}
		img = new Image();
		img.src = rep_main + diaporamaImage[num.value];
		document.getElementById('div_diaporama_' + annonce_id).getElementsByTagName('img')[0].src = img.src;
		num.value = num.value-1 ;
	}
	if (num.play == true) {
		img.onLoad = activerTimer (num, annonce_id);
	}
}	

function activerTimer (num, annonce_id) {
	num.timer = setTimeout("ChangeImage(diaporamaImage_"+annonce_id+", '"+annonce_id+"', num_"+annonce_id+")", 2000);
}

function changeAndStopDiaporama(num, annonce_id, image_num) {
	num.value = image_num;
	num.play = false;
	clearTimeout(num.timer);
	num.timer = setTimeout("ChangeImage(diaporamaImage_"+annonce_id+", '"+annonce_id+"', num_"+annonce_id+")", 0);
	
}	


function zoom_changeImage(diaporamaImage, annonce_id, num, direction) {
	var image_num;
	var nb_image = diaporamaImage.length;
	if (direction == 'next') {
		image_num = (num.value_zoom-1+nb_image)%nb_image;
	}
	else {
		image_num = (num.value_zoom+1)%nb_image;
	}
	zoomInImage(diaporamaImage, annonce_id, num, image_num);
}

function zoomOutImage(diaporamaImage, annonce_id, num, image_num) {
	var par = window.document;
	var div_img = par.getElementById('annonce_box_zoom');
	var img = par.getElementById('annonce_image_zoom');
	if (img != null) {
		div_img.removeChild(img);
	}
	par.getElementById('annonce_image_zoom_navigation').style.display = 'none';

	num.value_zoom = -1;
	window.location.href='#global';
}

function zoomInImage(diaporamaImage, annonce_id, num, image_num) {
	if (image_num==-1) {
		var nb_image = diaporamaImage.length;
		image_num = (num.value + 1)%nb_image;
	}
	num.value_zoom = image_num;
	var par = window.document;
	img_zoom = new Image();
	//img_zoom.onError = zoomInUnavailable(diaporamaImage, annonce_id, num, image_num);
	img_zoom.src = rep_grand + diaporamaImage[image_num];
	//alert (img_zoom.src + " " + image_num)
	//if (img_zoom.complete) {
	
	var div_img = par.getElementById('annonce_box_zoom');
	var img = par.getElementById('annonce_image_zoom');
	if (img != null) {
		div_img.removeChild(img);
	}
	par.getElementById('annonce_image_zoom_navigation').style.display = 'block';
		/**
    var new_img = par.createElement('img');
    new_img.src = 'img/indicator.gif';
    new_img.className = 'load';
    div_img.appendChild(new_img);
	//while (!img_zoom.complete) {};
    div_img.removeChild(new_img);
    **/
		img = par.createElement('img');
		img.src = img_zoom.src;
		img.className = 'annonce_image_zoom';
		img.id = 'annonce_image_zoom';
		div_img.appendChild(img);
		//div_img.insertBefore(img, par.getElementById('annonce_image_zoom_navigation'));
		window.location.href='#annonce_box_zoom';
	//}
}

/**
function zoomInUnavailable(diaporamaImage, annonce_id, num, image_num) {
	var div_img = par.getElementById('annonce_box_zoom');
}
**/

function stopOrPlayDiaporama(num, annonce_id) {
	if (num.play == true) {
		num.play = false;
		clearTimeout(num.timer);
	}
	else {
		num.play = true;
		num.timer = setTimeout("ChangeImage(diaporamaImage_"+annonce_id+", \""+annonce_id+"\", num_"+annonce_id+")", 0);
	}
}	



function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}


function CheckUncheckRadio(el) {
	var par = window.document;
	//var listRa = par.getElementsByClassName('Valider');
	//alert (listRa.length);
	var radio = par.getElementById(el.id);
	if(radio.className == 'radio ' + radio.value + '_checked') {
		radio.checked=false;
		radio.className = 'radio ' + radio.value;
		radio.parentNode.className = 'label_radio ' + radio.value;
	}
	else {
		var listRadio = par.getElementsByName(radio.name);
		for (i = 0; i < listRadio.length; i++) {
			var reg = new RegExp('_checked');
			listRadio[i].className = listRadio[i].className.replace(reg,' ');
			listRadio[i].parentNode.className = listRadio[i].parentNode.className.replace(reg,' ');
		}
		radio.className = 'radio ' + radio.value + '_checked';
		radio.parentNode.className = 'label_radio ' + radio.value + ' _checked';
		
	}
}


function CheckUncheckCheckBox(checkBox) {
	var par = window.document;
	if(checkBox.checked) {
		checkBox.parentNode.className = 'label_checkbox ' + '_checked';
	}
	else {
		var reg = new RegExp('_checked');
		checkBox.parentNode.className = checkBox.parentNode.className.replace(reg,' ');
	}
}

function CheckUncheckRadio2(el) {
	var par = window.document;
	var listForm = par.getElementsByClassName('form_Annonce_gestion_multiple');
	var form = listForm[0];
	//alert(par.getElementsByClassName('form_Annonce_gestion_multiple').length);
	var radio = par.getElementById(el.id);
	var inpid = par.getElementById('AnnonceControlAction' + radio.value + '_' + radio.id);
	if (inpid) {
		form.removeChild(inpid);
		radio.checked=false;
	}
	else {
		var inpid;
		inpid = par.createElement('input');
		inpid.type = 'hidden';
		inpid.name = 'AnnonceControlAction' + radio.value + radio.name;
		inpid.id = 'AnnonceControlAction' + radio.value + '_' + radio.id;
		inpid.value = 1;
		//alert(inpid.name + '=' + inpid.value);
		form.appendChild(inpid);
	}
}
/**
	if (document.getElementById) {
		var radio = document.getElementById(el.id);
		var temp = document.getElementById(el.name+'_temp');
	}
	else if (document.all) {
		var radio = document.all[el.id];
		var temp = document.all[el.name+'_temp'];
	}
	else {
		if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
			var radio = document.layers[el.id];
			var temp = document.layers[el.name+'_temp'];
		}
	}
	if(radio.value == temp.value) {
		radio.checked = false;
		temp.value = '';
	}
	else {
		temp.value = radio.value;
	}
}
**/

function submitAllControlAction() {
	var par = window.document;
	var listForm = par.getElementsByClassName('form_Annonce_gestion_multiple');
	
	var divRadio = par.createElement('div');
	var radio;
	var checkBox;
	var hidden;
	var inpid;
	var cmp = 0;
	//alert("kkkj");
	for (i = 0; i < listForm.length; i++) {
		radio = listForm[i].getElementsByClassName('radio');
		checkBox = listForm[i].getElementsByClassName('checkbox');
		hidden = (listForm[i].getElementsByClassName('input_hidden_Annonce_Affichage_First_Page_current')[0].value==1);
		
		for (j = 0; j < checkBox.length; j++) {
			if (checkBox[j].checked != hidden) {
				inpid = par.createElement('input');
				inpid.type = 'hidden';
				inpid.name = 'hiddenAnnonce_Affichage_First_Page' + '[' + checkBox[j].value + ']';
				//inpid.id = 'AnnonceControlAction' + radio[j].value + '_' + radio[j].id;
				inpid.value = (checkBox[j].checked?1:0);
				//alert(inpid.name + '=' + inpid.value);
				divRadio.appendChild(inpid);
				cmp++;
			}
		}
		
		for (j = 0; j < radio.length; j++) {
			if (radio[j].checked) {
				inpid = par.createElement('input');
				inpid.type = 'hidden';
				inpid.name = 'hidden' + radio[j].value + radio[j].name;
				//inpid.id = 'AnnonceControlAction' + radio[j].value + '_' + radio[j].id;
				inpid.value = 1;
				//alert(inpid.name + '=' + inpid.value);
				divRadio.appendChild(inpid);
				cmp++;
			}
		}
	}
	if (cmp==0)return false;
	var submit = par.createElement('input');
	submit.type = 'hidden';
	submit.name = 'Annonce_submit_form_gestion_multiple';
	var form = listForm[0];
	divRadio.style.display='none';
	submit.style.display='none';
	form.appendChild(divRadio);
	form.appendChild(submit);
	form.submit();
	return false;
}


function aff_form_contact(id) {
	var par = window.document;
	if (par.getElementById('iframe_form_contact_annonce_' + id)) {
		return false;
	}
	var div_iframe = par.getElementById('div_form_contact_annonce_' + id);
	// create new iframe
	var new_iframe = par.createElement('iframe');
	new_iframe.className = 'iframe_form_contact_annonce';
	new_iframe.setAttribute('id', 'iframe_form_contact_annonce_'+id);
	new_iframe.src = 'contact_annonce.php?Annonce_Id='+id;
	new_iframe.frameBorder = '0';
	div_iframe.appendChild(new_iframe);
	return false;
}