

/*
 * method = POST / GET
 * file = fichier php
 * callback = fonction de retour sans ()
 * data = variable envoyée a file formatée ex : "id="+id+"&id_ref="+id_ref;
 * div = id de div de retour
 * 
 * EXEMPLE :
 * 
=> function setDefaultPict(id, id_ref){
	data = "id="+id+"&id_ref="+id_ref;
	ajax('POST' , 'test.php' , callBackDefaultPict , data , 'nb_photos');
}

=> function callBackDefaultPict(div,response){
	alert('b');
	document.getElementById(div).innerHTML = response;
}
 **/	
function DOAJAX(method , file , callback , data , div){
	
	var xhr_object = null; 
	 
	if(window.XMLHttpRequest) // Firefox 
	  xhr_object = new XMLHttpRequest(); 
	  if (xhr_object.overrideMimeType) {
			xhr_object.overrideMimeType('text/xml; charset=ISO-8859-15');
	  }
	else if(window.ActiveXObject) // Internet Explorer 
	  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { // XMLHttpRequest non supporté par le navigateur 
	  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	  return; 
	} 
	
	xhr_object.open(method, file, true); 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 

	var data = data;
	xhr_object.send(data);

	xhr_object.onreadystatechange = function() { 
		if(xhr_object.readyState == 4) 
			{
				callback(div,xhr_object.responseText);			
			}
	} 
}
function resetText(div_id){
	document.getElementById(div_id).innerHTML = "";
}

function resetForm(inputName,formName,initValue){
	t = document.forms[formName].elements[inputName].value
	if ( t == initValue)
	document.forms[formName].elements[inputName].value = "";
}
function displayDiv(id){
	div = document.getElementById(id); 					
	state = div.style.display;
	switch (state) {
	case 'none':
		div.style.display = 'block';
		break;
	case 'block':
		div.style.display = 'none';
		break;
	default:
		div.style.display = 'block';
		break;
	}
}
function showDiv(id){
	document.getElementById(id).style.display= 'block';
}
function hideDiv(id){			
	document.getElementById(id).style.display='none';
}
function ConfirmToSubmit (text,form) {
	if (confirm(text)){
		document.form.submit();
	}	
}
function ConfirmToUrl (text,url) {
	if (confirm(text)){
		window.location = url;
	}	
}
function stripslashes(string){
	string = string.replace(/\\\'/g,"'");
	return string.replace(/\\\"/g,"\"");
}

function getSelectValue(select,form){
	return form.elements[select].options[form.elements[select].selectedIndex].value;
}
function getSelectText(select,form){
	return form.elements[select].options[form.elements[select].selectedIndex].text;
}
function getValueRadio(radio) {
	for (var i=0; i<radio.length;i++) {
		if (radio[i].checked) {
			return radio[i].value;
		}
	}
}

/*tags admin*/
function displayTags(div_id,select,form,id_comp){
	id_ref = getSelectValue(select,form);
	getTags_link(id_ref,id_comp);
}
function displayRefs(div_id,select,form){
	resetText("getTags");
	id_comp = getSelectValue(select,form);
	getRefs(id_comp);
}
function displayTagsToPond(div_id,select,form,type_section){
	id_section = getSelectValue(select,form);
	getTags(id_section,type_section);
}
function displayPondTag(div_id,select,form,type_section){
	id_tag = getSelectValue(select,form);
	getPondTag(id_tag,type_section);
}


function displaySection(radio,div1,div2){
	section = getValueRadio(radio);
	switch (section) {
		case 'ref':
			showDiv(div1);	
			hideDiv(div2);
			break;
		case 'comp':
			showDiv(div2);	
			hideDiv(div1);			
			break;
		default:
			break;
	}
}
function displaySEO(div_id,select,form){
	val = getSelectValue(select,form);
	str = val.split("_");
	type = str[0];
	id_type = str[1];
	getSEO(id_type,type,div_id);
}