/**
 * @author Olivier Latignies
 */

function orena_dummy()
{
	
}

function orena_refreshallselect()
{
	var specialites = document.getElementById("orena_rubriques");
	var selectedoption = specialites.options[specialites.selectedIndex];
	// Get specialites limited by the newly selected rubriques
	var specialiteicon = document.getElementById("orena_specialites_loadingicon");
	specialiteicon.src = "images/loading.gif";
	var categoriesicon = document.getElementById("orena_categories_loadingicon");
	categoriesicon.src = "images/loading.gif";
	var classesicon = document.getElementById("orena_classes_loadingicon");
	classesicon.src = "images/loading.gif";
	
	CallServer("getspecialitesbyrubriqueanddate",new Function("orena_changeRubriquesReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=specialitesbyrubrique;" + selectedoption.value,"");
	// Get categories limited by the newly selected rubriques
	CallServer("getcategoriesbyrubriqueanddate",new Function("orena_changeCategoriesReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=categoriesbyrubrique;" + selectedoption.value,"");
	// Get classes limited by the newly selected rubriques
	CallServer("getclassesbyrubriqueanddate",new Function("orena_changeClassesReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=classesbyrubrique;" + selectedoption.value,"");
}

function orena_changeRubriques(element)
{
	orena_refreshallselect();
}

function orena_changeRubriquesReturn()
{
	var specialiteicon = document.getElementById("orena_specialites_loadingicon");
	specialiteicon.src = "images/blank14x14.png";
	var rubriques = GetServerResponce("getspecialitesbyrubriqueanddate");
	var specialitescontainer = document.getElementById("orena_specialites_container");
	specialitescontainer.innerHTML = rubriques;
}

function orena_changeCategoriesReturn()
{
	var categoriesicon = document.getElementById("orena_categories_loadingicon");
	categoriesicon.src = "images/blank14x14.png";
	var rubriques = GetServerResponce("getcategoriesbyrubriqueanddate");
	var categoriescontainer = document.getElementById("orena_categories_container");
	categoriescontainer.innerHTML = rubriques;
}

function orena_changeClassesReturn()
{
	var classesicon = document.getElementById("orena_classes_loadingicon");
	classesicon.src = "images/blank14x14.png";
	var rubriques = GetServerResponce("getclassesbyrubriqueanddate");
	var classescontainer = document.getElementById("orena_classes_container");
	classescontainer.innerHTML = rubriques;
}

function orena_changeSelectDate(selectelement)
{
	var startdateelement = document.getElementById("orena_startdate");
	var stopdateelement = document.getElementById("orena_stopdate");
	var startdate = startdateelement.options[startdateelement.selectedIndex];
	var stopdate = stopdateelement.options[stopdateelement.selectedIndex];
	var selectvalue = selectelement.value;
	if (selectvalue == "1")
	{
		// Change selected date
		CallServer("changesearchdatetolastupdate",new Function("orena_dateHasBeenChanged()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=changesearchdatetolastupdate;yes","");
	}
	if (selectvalue == "2")
	{
		// Change selected date range
		CallServer("changesearchdaterange",new Function("orena_dateHasBeenChanged()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=changesearchdaterange;yes,state=startdate;" + startdate.text + ":stopdate;" + stopdate.text,"");
	}
}

function orena_changeDate(element)
{
	var selectelement = document.getElementById("orena_selectdaterange");
	if (!selectelement.checked)
	{
		selectelement.click();
	}
	else
	{
		var startdateelement = document.getElementById("orena_startdate");
		var stopdateelement = document.getElementById("orena_stopdate");
		var startdate = startdateelement.options[startdateelement.selectedIndex];
		var stopdate = stopdateelement.options[stopdateelement.selectedIndex];
		// Select the right radio button first to sync display
		// Change selected date range
		CallServer("changesearchdaterange",new Function("orena_dateHasBeenChanged()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=changesearchdaterange;yes,state=startdate;" + startdate.text + ":stopdate;" + stopdate.text,"");
	}
}

function orena_dateHasBeenChanged()
{
	// Refresh select
	orena_refreshallselect();
}

function orena_applyprofiletosearch(element)
{
	if (element.value == "0")
	{
		CallServer("rubriqueforprofile",new Function("orena_rubriqueForProfileReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=allrubrique;yes","");
		orena_refreshallselect();
		return;
	}
	CallServer("rubriqueforprofile",new Function("orena_rubriqueForProfileReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=rubriqueforprofile;" + element.value,"");
	CallServer("specialiteforprofile",new Function("orena_specialiteForProfileReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=specialiteforprofile;" + element.value,"");
	CallServer("categorieforprofile",new Function("orena_categorieForProfileReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=categorieforprofile;" + element.value,"");
	CallServer("classeforprofile",new Function("orena_classeForProfileReturn()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=classeforprofile;" + element.value,"");
}

function orena_rubriqueForProfileReturn()
{
	// Update rubrique
	var rubriques = GetServerResponce("rubriqueforprofile");
	var rubriquescontainer = document.getElementById("orena_rubriques_container");
	rubriquescontainer.innerHTML = rubriques;
}

function orena_specialiteForProfileReturn()
{
	// Update specialite
	var specialites = GetServerResponce("specialiteforprofile");
	var specialitescontainer = document.getElementById("orena_specialites_container");
	specialitescontainer.innerHTML = specialites;	
}

function orena_categorieForProfileReturn()
{
	// Update categorie
	var categories = GetServerResponce("categorieforprofile");
	var categoriescontainer = document.getElementById("orena_categories_container");
	categoriescontainer.innerHTML = categories;
}

function orena_classeForProfileReturn()
{
	// Update rubrique
	var classes = GetServerResponce("classeforprofile");
	var classescontainer = document.getElementById("orena_classes_container");
	classescontainer.innerHTML = classes;
}

function orenaExpandAvis(avisId)
{
	var buttonswitch = document.getElementById("buttonexpandavi_" + avisId);
	var avisummary = document.getElementById("avisummary_" + avisId);
	var detaillink = document.getElementById("orena_avisdetaillink_" + avisId);
	if (buttonswitch.src.match("images/plus.gif"))
	{
		// Expand
		buttonswitch.src = "images/moins.gif";
		detaillink.style.visibility = "visible";
		detaillink.style.display = "block";
		CallServer("getavissummary",new Function("orena_getAvisSummary()"),avisId,"/orena/ABAjax.php?module=orenaAdjudication,action=getavissummary;" + avisId,"");
	}
	else
	{
		// Collapse
		buttonswitch.src = "images/plus.gif";
		avisummary.innerHTML = "";
		detaillink.style.visibility = "hidden";
		detaillink.style.display = "none";
	}
}

function orena_getAvisSummary()
{
	var newsummary = GetServerResponce("getavissummary");
	var avissummary = document.getElementById("avisummary_" + GetServerResponceExtend("getavissummary"));
	avissummary.innerHTML = newsummary;
}

function orenaExpandResultat(avisId)
{
	var buttonswitch = document.getElementById("buttonexpandresultat_" + avisId);
	var avisresultat = document.getElementById("avisresultat_" + avisId);
	if (avisresultat.innerHTML.length < 3)
	{
		// Expand
		buttonswitch.src = "images/moins.gif";
		CallServer("getavisresultat",new Function("orena_getAvisResultat()"),avisId,"/orena/ABAjax.php?module=orenaAdjudication,action=getavisresultat;" + avisId,"");
	}
	else
	{
		// Collapse
		buttonswitch.src = "images/plus.gif";
		avisresultat.innerHTML = "";
	}
}

function orena_getAvisResultat()
{
	var resultat = GetServerResponce("getavisresultat");
	var avisresultat = document.getElementById("avisresultat_" + GetServerResponceExtend("getavisresultat"));
	avisresultat.innerHTML = resultat;
}

function orena_ChangeProfileQuery(element)
{
	// get selected option
	var selected = element.value;
	CallServer("changeprofilequery",new Function("orena_ChangeProfileQueryResult()"),null,"/orena/ABAjax.php?module=orenaAdjudication,action=changeprofilequery;" + selected,"");
}

function orena_ChangeProfileQueryResult(element)
{
	// Reload page
	this.location.href = "ABWebBuilder.php?page=/lachronique/adjudication";
}

function isValidEmail(str)
{
   return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function orena_enableuserinfo(element)
{
	var username = document.getElementById("user_name");
	var userfunction = document.getElementById("user_function");
	var userfunctionother = document.getElementById("user_function_other");
	var userfunctionotherspan = document.getElementById("user_function_span");
	var userlanguage = document.getElementById("user_language");
	var useremail = document.getElementById("user_email");
	var useravisperiod = document.getElementById("user_avisperiod");
	
	var userinfobuttons = document.getElementById("orena_userinfobuttons");
	var userinfotitle = document.getElementById("orena_enableuserinfotitle");
	
	if (element.innerHTML == "Modifier")
	{
		username.disabled = false;
		userfunction.disabled = false;
		if (userfunction.value == "10")
		{
			userfunctionother.disabled = false;
			userfunctionotherspan.style.visibility = "visible";
		}
		else
		{
			userfunctionother.disabled = true;
			userfunctionotherspan.style.visibility = "hidden";
		}	
			
		userlanguage.disabled = false;
		useremail.disabled = false;
		useravisperiod.disabled = false;
		userinfotitle.innerHTML = "Enregistrer";
		userinfobuttons.innerHTML = "<img onclick=\"orena_enableuserinfo(this);\" class=\"fake_link\" border=\"0\" src=\"images/lachronique/save.png\"><a href=\"ABWebBuilder.php?page=/lachronique/user/profile\"><img border=\"0\" src=\"images/lachronique/cancel.png\"></a>";
	}
	else
	{
		if (!isValidEmail(useremail.value))
		{
			alert("Adresse e-mail non valide");	
		}
		else
		{
			// Send new information to server
			CallServer("enableuserinfo",new Function("orena_enableuserinforesult()"),null,"/orena/ABAjax.php?module=orenaProfileWeb,action=updateuserinfo;yes","username="+username.value+"&userfunction="+userfunction.value+"&userfunctionother="+userfunctionother.value+"&userlanguage="+userlanguage.value+"&useremail="+useremail.value+"&useravisperiod="+useravisperiod.value);
			userinfotitle.innerHTML = "Modifier";
			userinfobuttons.innerHTML = "";
		}			
	}
}

function orena_enableuserinfo_close(element)
{
	var userinfobuttons = document.getElementById("orena_userinfobuttons");
	var userinfotitle = document.getElementById("orena_enableuserinfotitle");
	userinfotitle.innerHTML = "Modifier";
	userinfobuttons.innerHTML = "";
	var username = document.getElementById("user_name");
	var userfunction = document.getElementById("user_function");
	var userfunctionother = document.getElementById("user_function_other");
	var userlanguage = document.getElementById("user_language");
	var useremail = document.getElementById("user_email");
	var useravisperiod = document.getElementById("user_avisperiod");
	username.disabled = true;
	userfunction.disabled = true;
	userfunctionother.disabled = true;
	userlanguage.disabled = true;
	useremail.disabled = true;
	useravisperiod.disabled = true;
}

function orena_enableuserinforesult()
{
	var username = document.getElementById("user_name");
	var userfunction = document.getElementById("user_function");
	var userfunctionother = document.getElementById("user_function_other");
	var userlanguage = document.getElementById("user_language");
	var useremail = document.getElementById("user_email");
	var useravisperiod = document.getElementById("user_avisperiod");
	
	username.disabled = true;
	userfunction.disabled = true;
	userfunctionother.disabled = true;
	userlanguage.disabled = true;
	useremail.disabled = true;
	useravisperiod.disabled = true;	
}

function orena_enablenewprofile(element)
{
	var profilediv = document.getElementById("new_profile");
	var newprofiletitle = document.getElementById("orena_newprofiletitle");
	
	if (profilediv.style.visibility == "hidden")
	{
		profilediv.style.visibility = "visible";
		profilediv.style.display = "block";
		newprofiletitle.innerHTML = "Annuler l'ajout d'un profil";
	}
	else
	{
		profilediv.style.visibility = "hidden";
		profilediv.style.display = "none";
		newprofiletitle.innerHTML = "Ajouter un profil";
	}	
}

function orena_searchcata()
{
	var societefield = document.getElementById("orenaSociete");
	var rubriquefield = document.getElementById("orenaRubrique");
	var marquefield = document.getElementById("orenaMarque");
	var loadingicon = document.getElementById("orena_catalogueloadingicon");
	loadingicon.src =  "images/loading.gif";
	CallServer("orena_searchcata",new Function("orena_searchcataresult()"),null,"/orena/ABAjax.php?module=orenaCatalogue,action=searchcata;yes","societe="+societefield.value+"&rubrique="+rubriquefield.value+"&marque="+marquefield.value);	
}

function orena_searchcataresult()
{
	var resultat = GetServerResponce("orena_searchcata");
	var resultdiv = document.getElementById("ann_adj");
	var catadetail = document.getElementById("catalogue_detail");
	if (catadetail)
	{
		catadetail.innerHTML = "";
	}
	resultdiv.innerHTML = "";
	resultdiv.innerHTML = resultat;
	var loadingicon = document.getElementById("orena_catalogueloadingicon");
	loadingicon.src =  "images/blank14x14.png";
}

var gSearchSocieteTimer = 0;
var gSearchSocieteField;
var gSearchMarqueTimer = 0;
var gSearchMarqueField;

function orena_searchcatasociete(element)
{
	var societefield = document.getElementById("orenaSociete");
	var rubriquefield = document.getElementById("orenaRubrique");
	var marquefield = document.getElementById("orenaMarque");
	
	if (element.value.length == 0)
	{
		// enable rubrique et marque
		rubriquefield.disabled = false;
		marquefield.disabled = false;
	}
	else
	{
		rubriquefield.disabled = true;
		marquefield.disabled = true;
	}
	if (element.value.length < 2)
	{
		clearTimeout(gSearchSocieteTimer);
		gSearchSocieteTimer = 0;
		return;
	}
	
	gSearchSocieteField = element;
	
	// Start timer to trigger the search
	if (gSearchSocieteTimer != 0)
	{
		clearTimeout(gSearchSocieteTimer);
	}
	gSearchSocieteTimer = setTimeout("orena_searchcatasocietestart()",400);
}

function orena_searchcatasocietestart()
{
	// Clear timer
	if (gSearchSocieteTimer != 0)
	{
		clearTimeout(gSearchSocieteTimer);
		gSearchSocieteTimer = 0;
	}
	// double check for inputfield length
	if (gSearchSocieteField.value.length < 2)
	{
		return;
	}
	orena_searchcata();	
}

function orena_searchcatamarque(element)
{
	var societefield = document.getElementById("orenaSociete");
	var rubriquefield = document.getElementById("orenaRubrique");
	var marquefield = document.getElementById("orenaMarque");
	
	if (element.value.length == 0)
	{
		// enable rubrique et societe
		rubriquefield.disabled = false;
		societefield.disabled = false;
	}
	else
	{
		rubriquefield.disabled = true;
		societefield.disabled = true;
	}
	if (element.value.length < 2)
	{
		clearTimeout(gSearchMarqueTimer);
		gSearchMarqueTimer = 0;
		return;
	}
	
	gSearchMarqueField = element;
	
	// Start timer to trigger the search
	if (gSearchMarqueTimer != 0)
	{
		clearTimeout(gSearchMarqueTimer);
	}
	gSearchMarqueTimer = setTimeout("orena_searchcatamarquestart()",400);
}

function orena_searchcatamarquestart()
{
	// Clear timer
	if (gSearchMarqueTimer != 0)
	{
		clearTimeout(gSearchMarqueTimer);
		gSearchMarqueTimer = 0;
	}
	// double check for inputfield length
	if (gSearchMarqueField.value.length < 2)
	{
		return;
	}
	orena_searchcata();	
}

function orena_searchcatarubrique(element)
{
	var societefield = document.getElementById("orenaSociete");
	var rubriquefield = document.getElementById("orenaRubrique");
	var marquefield = document.getElementById("orenaMarque");
	if (rubriquefield.value == "0")
	{
		societefield.disabled = false;
		marquefield.disabled = false;
	}
	else
	{
		societefield.disabled = true;
		marquefield.disabled = true;
	}
	orena_searchcata();
}

function orenaExpandSociete(societeid)
{
	var buttonswitch = document.getElementById("buttonexpandsociete_" + societeid);
	var societedetail = document.getElementById("societedetail_" + societeid);
	if (societedetail.innerHTML.length < 3)
	{
		// Expand
		buttonswitch.src = "images/moins.gif";
		CallServer("getsocietedetails",new Function("orena_getSocieteDetails()"),societeid,"/orena/ABAjax.php?module=orenaCatalogue,action=getsocietedetail;" + societeid,"");
	}
	else
	{
		// Collapse
		buttonswitch.src = "images/plus.gif";
		societedetail.innerHTML = "";
	}
}

function orena_getSocieteDetails()
{
	var resultat = GetServerResponce("getsocietedetails");
	var societeresultat = document.getElementById("societedetail_" + GetServerResponceExtend("getsocietedetails"));
	societeresultat.innerHTML = resultat;
}

function orena_checkuserfunction(element)
{
	var userfunctionother = document.getElementById("user_function_other");
	var userfunctionotherspan = document.getElementById("user_function_span");
	if (element.value == "10")
	{
		userfunctionother.disabled = false;
		userfunctionotherspan.style.visibility = "visible";
	}
	else
	{
		userfunctionother.disabled = true;
		userfunctionotherspan.style.visibility = "hidden";
	}	
}

function orena_printpage()
{
	window.print();
}

function orena_modifyprofile(profileid)
{
	CallServer("modifyprofile",new Function("orena_modifyprofilereturn()"),profileid,"/orena/ABAjax.php?module=orenaProfileWeb,action=displayprofile;" + profileid,"");
}

function orena_modifyprofilereturn()
{
	var modifydiv = document.getElementById("modify_profile");
	modifydiv.innerHTML = GetServerResponce("modifyprofile");
}

function orena_modifyprofileclose(element)
{
	var modifydiv = document.getElementById("modify_profile");
	modifydiv.innerHTML = "";
}

/************************************************************************************************/
/* --- CLIENT  --- */
/************************************************************************************************/
function orenaclient_selectid(clientid)
{
		CallServer("selectclientid",new Function("orenaclient_selectidReturn("+clientid+")"),null,"/orena/ABAjax.php?module=orenaClient,action=getclientinfo;" + clientid,"");
}

function orenaclient_selectidReturn(clientid)
{
	
	var clientform = document.getElementById("clientform");
	clientform.innerHTML = "";
	
	// info du client
	var clientinfo = GetServerResponce("selectclientid");
	clientform.innerHTML += clientinfo;
	// adresses du client
	clientform.innerHTML += '<div id="orena_table_address2" class="orena_table_adresse_div2"></div>';
	orenaclient_DisplayAddress(clientid);
	//abonnements du client
	clientform.innerHTML += '<div id="orena_table_abt" class="orena_table_abt_div"></div>';
	orenaclient_DisplayAbts(clientid);
	//agent du client
	clientform.innerHTML += '<div id="orena_client_agent" class="orena_client_Agent_div"></div>';
	orenaclient_DisplayAgent(clientid);
	//annonceur du client
	clientform.innerHTML += '<div id="orena_client_annonceur" class="orena_client_Annonceur_div"></div>';
	orenaclient_DisplayAnnonceur(clientid);
}

// TO CONTINUE...
function client_updateid(clientid)
{
		//var agent_name = document.getElementById("agent_name");
		//var agent_client = document.getElementById("client_id");		
		CallServer("updateclientid",new Function("client_updateidReturn("+clientid+")"),null,"/orena/ABAjax.php?module=orenaclient,action=updateclientinfo;" + clientid,"CLIENT_ID="+ agent_client.value +"&NAME="+ agent_name.value);
}

function client_updateidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAgent(clientid);
}

/************************************************************************************************/
/* --- ADRESSE  --- */
/************************************************************************************************/

function address_selectid(addressid)
{
		CallServer("selectaddressid",new Function("address_selectidReturn()"),null,"/orena/ABAjax.php?module=adresse,action=getaddressinfo;" + addressid,"");
}

function address_selectidReturn()
{	
	var addressinfo = GetServerResponce("selectaddressid");
	var addressform = document.getElementById("orena_table_address2");
	addressform.innerHTML = addressinfo;
}

function address_updateid(addressid)
{
		var address_type = document.getElementById("address_type");
		var address_address = document.getElementById("address_address");
		var address_cp = document.getElementById("address_cp");
		var address_locality = document.getElementById("address_locality");
		var address_client = document.getElementById("address_client");		
		CallServer("updateaddressid",new Function("address_updateidReturn("+address_client.value+")"),null,"/orena/ABAjax.php?module=adresse,action=updateaddressinfo;" + addressid,"CLIENT_ID="+ address_client.value +"&TYPE="+ address_type.value +"&ADRESSE=" + address_address.value + "&CP="+ address_cp.value +"&LOCALITE="+ address_locality.value);
}

function address_updateidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	
	// DEBUG...
	//var addressinfo = GetServerResponce("updateaddressid");
	//var addressform = document.getElementById("DEBUGform");
	//addressform.innerHTML = addressinfo;
	
	orenaclient_DisplayAddress(clientid);
}

function orenaclient_DisplayAddress(clientid)
{
		
		CallServer("DisplayclientAddress",new Function("orenaclient_DisplayAddressReturn()"),null,"/orena/ABAjax.php?module=orenaClient,action=getclientAddress;" + clientid,"");
}

function orenaclient_DisplayAddressReturn()
{
	var clientinfo = GetServerResponce("DisplayclientAddress");
	var clientform = document.getElementById("orena_table_address2");
	clientform.innerHTML = clientinfo;
}

function address_newid()
{
		var address_type = document.getElementById("address_type");
		var address_address = document.getElementById("address_address");
		var address_cp = document.getElementById("address_cp");
		var address_locality = document.getElementById("address_locality");
		var address_client = document.getElementById("client_id");		
		CallServer("newaddressid",new Function("address_newidReturn("+address_client.value+")"),null,"/orena/ABAjax.php?module=adresse,action=newaddressinfo;","CLIENT_ID="+ address_client.value +"&TYPE="+ address_type.value +"&ADRESSE=" + address_address.value + "&CP="+ address_cp.value +"&LOCALITE="+ address_locality.value);
}
function address_newidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAddress(clientid);
}

/************************************************************************************************/
/* --- ABONNEMENT  --- */
/************************************************************************************************/
function abt_selectid(abtid)
{
		CallServer("selectabtid",new Function("abt_selectidReturn("+abtid+")"),null,"/orena/ABAjax.php?module=orenaAbts,action=getabtinfo;" + abtid,"");
}

function abt_selectidReturn(abtid)
{	
	var abtinfo = GetServerResponce("selectabtid");
	var abtform = document.getElementById("orena_table_abt");
	abtform.innerHTML = abtinfo;
	
	//abt_DisplayRoutage(abtid);
}

function abt_DisplayRoutage(abtid)
{
		CallServer("DisplayAbtRoutage",new Function("abt_DisplayRoutageReturn()"),null,"/orena/ABAjax.php?module=orenaAbts,action=DisplayAbtRoutage;" + abtid,"");
}

function abt_DisplayRoutageReturn()
{
	var abtinfo = GetServerResponce("DisplayAbtRoutage");
	var abtform = document.getElementById("orena_abt_routage");
	abtform.innerHTML = abtinfo;
}

function abt_updateid(abtid)
{
		var abt_status = document.getElementById("abt_status");
		var abt_exchange = document.getElementById("abt_exchange");
		var abt_language = document.getElementById("abt_language");
		var abt_datenew = document.getElementById("abt_datenew");
		var abt_daterenew = document.getElementById("abt_daterenew");
		var abt_email = document.getElementById("abt_email");
		var abt_client = document.getElementById("client_id");
		var abt_memo = document.getElementById("abt_memo");
		CallServer("updateabtid",new Function("abt_updateidReturn("+abt_client.value+")"),null,"/orena/ABAjax.php?module=orenaAbts,action=updateabtinfo;" + abtid,"CLIENT_ID="+ abt_client.value +"&STATUS="+ abt_status.value +"&EXCHANGE=" + abt_exchange.value + "&LANGUAGE="+ abt_language.value +"&DATE_NEW="+ abt_datenew.value+"&DATE_RENEW="+ abt_daterenew.value+"&EMAIL="+abt_email.value+"&MEMO="+ abt_memo.value);
}

function abt_updateidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAbts(clientid);
}
function orenaclient_DisplayAbts(clientid)
{
		CallServer("DisplayclientAbts",new Function("orenaclient_DisplayAbtsReturn()"),null,"/orena/ABAjax.php?module=orenaClient,action=getclientAbts;" + clientid,"");
}

function orenaclient_DisplayAbtsReturn()
{
	var clientinfo = GetServerResponce("DisplayclientAbts");
	var clientform = document.getElementById("orena_table_abt");
	clientform.innerHTML = clientinfo;
}
function abt_newid()
{
		var abt_status = document.getElementById("abt_status");
		var abt_exchange = document.getElementById("abt_exchange");
		var abt_language = document.getElementById("abt_language");
		var abt_datenew = document.getElementById("abt_datenew");
		var abt_daterenew = document.getElementById("abt_daterenew");
		var abt_client = document.getElementById("client_id");
		var abt_memo = document.getElementById("abt_memo");
		CallServer("newabtid",new Function("abt_newidReturn("+abt_client.value+")"),null,"/orena/ABAjax.php?module=orenaAbts,action=newabtinfo;","CLIENT_ID="+ abt_client.value +"&STATUS="+ abt_status.value +"&EXCHANGE=" + abt_exchange.value + "&LANGUAGE="+ abt_language.value +"&DATE_NEW="+ abt_datenew.value+"&DATE_RENEW="+ abt_daterenew.value+"&MEMO="+ abt_memo.value);
}
function abt_newidReturn(clientid)
{	
	orenaclient_selectid(clientid);
}
/************************************************************************************************/
/* --- AGENT  --- */
/************************************************************************************************/
function agent_newid()
{
		var agent_name = document.getElementById("agent_name");
		var agent_client = document.getElementById("client_id");
		CallServer("newagentid",new Function("agent_newidReturn("+agent_client.value+")"),null,"/orena/ABAjax.php?module=orenaAgent,action=newagentinfo;","CLIENT_ID="+ agent_client.value +"&NAME="+ agent_name.value);
}
function agent_newidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAgent(clientid);
}
function agent_updateid(agentid)
{
		var agent_name = document.getElementById("agent_name");
		var agent_client = document.getElementById("client_id");		
		CallServer("updateagentid",new Function("agent_updateidReturn("+agent_client.value+")"),null,"/orena/ABAjax.php?module=orenaAgent,action=updateagentinfo;" + agentid,"CLIENT_ID="+ agent_client.value +"&NAME="+ agent_name.value);
}

function agent_updateidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAgent(clientid);
}
function orenaclient_DisplayAgent(clientid)
{
		CallServer("DisplayclientAgent",new Function("orenaclient_DisplayAgentReturn()"),null,"/orena/ABAjax.php?module=orenaClient,action=getclientAgents;" + clientid,"");
}

function orenaclient_DisplayAgentReturn()
{
	var clientinfo = GetServerResponce("DisplayclientAgent");
	var clientform = document.getElementById("orena_client_agent");
	clientform.innerHTML = clientinfo;
}

/************************************************************************************************/
/* --- ANNONCEUR  --- */
/************************************************************************************************/
function annonceur_newid()
{
		var annonceur_name = document.getElementById("annonceur_name");
		var annonceur_client = document.getElementById("client_id");
		CallServer("newannonceurid",new Function("annonceur_newidReturn("+annonceur_client.value+")"),null,"/orena/ABAjax.php?module=orenaAnnonceur,action=newannonceurinfo;","CLIENT_ID="+ annonceur_client.value +"&NAME="+ annonceur_name.value);
}
function annonceur_newidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAnnonceur(clientid);
}


function annonceur_updateid(annonceurid)
{
		var annonceur_name = document.getElementById("annonceur_name");
		var annonceur_client = document.getElementById("client_id");		
		CallServer("updateannonceurid",new Function("annonceur_updateidReturn("+annonceur_client.value+")"),null,"/orena/ABAjax.php?module=orenaAnnonceur,action=updateannonceurinfo;" + annonceurid,"CLIENT_ID="+ annonceur_client.value +"&NAME="+ annonceur_name.value);
}

function annonceur_updateidReturn(clientid)
{	
	//orenaclient_selectid(clientid);
	orenaclient_DisplayAnnonceur(clientid);
}

function orenaclient_DisplayAnnonceur(clientid)
{
		CallServer("DisplayclientAnnonceur",new Function("orenaclient_DisplayAnnonceurReturn()"),null,"/orena/ABAjax.php?module=orenaClient,action=getclientAnnonceur;" + clientid,"");
}

function orenaclient_DisplayAnnonceurReturn()
{
	var clientinfo = GetServerResponce("DisplayclientAnnonceur");
	var clientform = document.getElementById("orena_client_annonceur");
	clientform.innerHTML = clientinfo;
}

/************************************************************************************************/
/* --- ROUTAGE  --- */
/************************************************************************************************/
function routage_newid()
{
		var routage_type = document.getElementById("routage_type");
		var routage_abt = document.getElementById("abt_id");
		var routage_client = document.getElementById("client_id");
		//CallServer("newroutageid",new Function("routage_newidReturn("+routage_client.value+")"),null,"/orena/ABAjax.php?module=orenaRoutage,action=newroutageinfo;","ABT_ID="+ routage_abt.value +"&TYPE="+ routage_type.value);
		CallServer("newroutageid",new Function("routage_newidReturn("+routage_abt.value+")"),null,"/orena/ABAjax.php?module=orenaRoutage,action=newroutageinfo;","ABT_ID="+ routage_abt.value +"&TYPE="+ routage_type.value);
}
function routage_newidReturn(abtid)
{	
	//orenaclient_selectid(clientid);
	abt_selectid(abtid);
}
function routage_updateid(routageid)
{
		var routage_type = document.getElementById("routage_type");
		var routage_abt = document.getElementById("abt_id");
		var routage_client = document.getElementById("client_id");		
		//CallServer("updateroutageid",new Function("routage_updateidReturn("+routage_client.value+")"),null,"/orena/ABAjax.php?module=orenaRoutage,action=updateroutageinfo;" + routageid,"ABT_ID="+ routage_abt.value +"&TYPE="+ routage_type.value);
		CallServer("updateroutageid",new Function("routage_updateidReturn("+routage_abt.value+")"),null,"/orena/ABAjax.php?module=orenaRoutage,action=updateroutageinfo;" + routageid,"ABT_ID="+ routage_abt.value +"&TYPE="+ routage_type.value);
}
/*
function annonceur_updateidReturn(abtid)
{	
	//orenaclient_selectid(clientid);
	abt_selectid(abtid);
}
*/

/************************************************************************************************/
/* --- FACTURATION  --- */
/************************************************************************************************/
function facturation_newid()
{
		var facturation_paying = document.getElementById("facturation_paying");
		var facturation_payment_mode = document.getElementById("facturation_payment_mode");
		var facturation_amount = document.getElementById("facturation_amount");
		var facturation_abt = document.getElementById("abt_id");
		var facturation_client = document.getElementById("client_id");
		//CallServer("newfacturationid",new Function("facturation_newidReturn("+facturation_client.value+")"),null,"/orena/ABAjax.php?module=orenaFacturation,action=newfacturationinfo;","ABT_ID="+ facturation_abt.value +"&AMOUNT="+ facturation_amount.value+"&PAYING="+ facturation_paying.value+"&PAYMENT_MODE="+ facturation_payment_mode.value);
		CallServer("newfacturationid",new Function("facturation_newidReturn("+facturation_abt.value+")"),null,"/orena/ABAjax.php?module=orenaFacturation,action=newfacturationinfo;","ABT_ID="+ facturation_abt.value +"&AMOUNT="+ facturation_amount.value+"&PAYING="+ facturation_paying.value+"&PAYMENT_MODE="+ facturation_payment_mode.value);
}
function facturation_newidReturn(abtid)
{	
	//orenaclient_selectid(clientid);
	abt_selectid(abtid);
}
function facturation_updateid(facturationid)
{
		var facturation_paying = document.getElementById("facturation_paying");
		var facturation_payment_mode = document.getElementById("facturation_payment_mode");
		var facturation_amount = document.getElementById("facturation_amount");
		var facturation_abt = document.getElementById("abt_id");
		var facturation_client = document.getElementById("client_id");		
		//CallServer("updatefacturationid",new Function("facturation_updateidReturn("+facturation_client.value+")"),null,"/orena/ABAjax.php?module=orenaFacturation,action=updatefacturationinfo;" + facturationid,"ABT_ID="+ facturation_abt.value +"&AMOUNT="+ facturation_amount.value+"&PAYING="+ facturation_paying.value+"&PAYMENT_MODE="+ facturation_payment_mode.value);
		CallServer("updatefacturationid",new Function("facturation_updateidReturn("+facturation_abt.value+")"),null,"/orena/ABAjax.php?module=orenaFacturation,action=updatefacturationinfo;" + facturationid,"ABT_ID="+ facturation_abt.value +"&AMOUNT="+ facturation_amount.value+"&PAYING="+ facturation_paying.value+"&PAYMENT_MODE="+ facturation_payment_mode.value);
}

function facturation_updateidReturn(abtid)
{	
	//orenaclient_selectid(clientid);
	abt_selectid(abtid);
}

/************************************************************************************************/
/* --- OCCURENCE  --- */
/************************************************************************************************/
function orenaclient_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform");
		paramform.innerHTML = paraminfo;
	}
	if (selectvalue == "1")
	{
		CallServer("orenaclient_displayoccurence",new Function("orenaclient_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaclient_displayoccurence;yes","");
	}
	
}
function orenaclient_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaclient_displayoccurence");
	var paramform = document.getElementById("paramform");
	paramform.innerHTML = paraminfo;
}

function orenaclientStatus_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform2");
		paramform.innerHTML = paraminfo;
	}
	
	if ((selectvalue == "1") | (selectvalue == "2") |(selectvalue == "3")  | (selectvalue == "4"))
	{
		CallServer("orenaclientstatus_displayoccurence",new Function("orenaclientstatus_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaclientstatus_displayoccurence;yes","");
	}
	if ((selectvalue == "6") | (selectvalue == "7") )
	{
		CallServer("orenaclientstatus_displayoccurence",new Function("orenaclientstatus_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaclientstatus_display2occurence;yes","");
	}
	
}
function orenaclientstatus_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaclientstatus_displayoccurence");
	var paramform = document.getElementById("paramform2");
	paramform.innerHTML = paraminfo;
}
function orenaAdresseType_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform3");
		paramform.innerHTML = paraminfo;
	}
	if (selectvalue == "1")
	{
		CallServer("orenaAdresseType_displayoccurence",new Function("orenaAdresseType_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAdresseType_displayoccurence;yes","");
	}
	
}
function orenaAdresseType_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAdresseType_displayoccurence");
	var paramform = document.getElementById("paramform3");
	paramform.innerHTML = paraminfo;
}
function orenaAdresse_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform4");
		paramform.innerHTML = paraminfo;
	}
	if (selectvalue == "1")
	{
		CallServer("orenaAdresse_displayoccurence",new Function("orenaAdresse_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAdresse_displayoccurence;yes","");
	}
	
}
function orenaAdresse_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAdresse_displayoccurence");
	var paramform = document.getElementById("paramform4");
	paramform.innerHTML = paraminfo;
}
function orenaAdresseCP_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform5");
		paramform.innerHTML = paraminfo;
	}
	if (selectvalue == "1")
	{
		CallServer("orenaAdresseCP_displayoccurence",new Function("orenaAdresseCP_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAdresseCP_displayoccurence;yes","");
	}
	
}
function orenaAdresseCP_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAdresseCP_displayoccurence");
	var paramform = document.getElementById("paramform5");
	paramform.innerHTML = paraminfo;
}
function orenaAdresseLocality_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform6");
		paramform.innerHTML = paraminfo;
	}
	if (selectvalue == "1")
	{
		CallServer("orenaAdresseLocality_displayoccurence",new Function("orenaAdresseLocality_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAdresseLocality_displayoccurence;yes","");
	}
	
}
function orenaAdresseLocality_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAdresseLocality_displayoccurence");
	var paramform = document.getElementById("paramform6");
	paramform.innerHTML = paraminfo;
}

function orenaAbtDateNew_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform7");
		paramform.innerHTML = paraminfo;
	}
	
	if ((selectvalue == "1") | (selectvalue == "2") |(selectvalue == "3")  | (selectvalue == "4"))
	{
		CallServer("orenaAbtDateNew_displayoccurence",new Function("orenaAbtDateNew_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAbtDateNew_displayoccurence;yes","");
	}
	if ((selectvalue == "6") | (selectvalue == "7") )
	{
		CallServer("orenaAbtDateNew_displayoccurence",new Function("orenaAbtDateNew_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAbtDateNew_display2occurence;yes","");
	}
	
}
function orenaAbtDateNew_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAbtDateNew_displayoccurence");
	var paramform = document.getElementById("paramform7");
	paramform.innerHTML = paraminfo;
}
function orenaAbtAmount_displayoccurence(selectelement)
{
	var selectvalue = selectelement.value;
	if (selectvalue == "0")
	{
		var paraminfo = "";
		var paramform = document.getElementById("paramform8");
		paramform.innerHTML = paraminfo;
	}
	
	if ((selectvalue == "1") | (selectvalue == "2") |(selectvalue == "3")  | (selectvalue == "4"))
	{
		CallServer("orenaAbtAmount_displayoccurence",new Function("orenaAbtAmount_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAbtAmount_displayoccurence;yes","");
	}
	if ((selectvalue == "6") | (selectvalue == "7") )
	{
		CallServer("orenaAbtAmount_displayoccurence",new Function("orenaAbtAmount_displayoccurenceReturn()"),null,"/orena/ABAjax.php?module=orenaTableau,action=orenaAbtAmount_display2occurence;yes","");
	}
	
}
function orenaAbtAmount_displayoccurenceReturn()
{
	var paraminfo = GetServerResponce("orenaAbtAmount_displayoccurence");
	var paramform = document.getElementById("paramform8");
	paramform.innerHTML = paraminfo;
}

/************************************************************************************************/
/* --- ACCESS  --- */
/************************************************************************************************/
function orenaaccess_newid()
{
		var access_type = document.getElementById("access_type");
		var access_login = document.getElementById("access_login");
		var access_password = document.getElementById("access_password");
		var access_right = document.getElementById("access_right");
		var access_zipcode = document.getElementById("access_zipcode");
		var access_validity = document.getElementById("access_validity");
		
		var access_abt = document.getElementById("abt_id");
	
		CallServer("newaccessid",new Function("orenaaccess_newidReturn("+access_abt.value+")"),null,"/orena/ABAjax.php?module=orenaAccess,action=newaccessinfo;","ABT_ID="+ access_abt.value +"&TYPE="+ access_type.value+"&LOGIN="+ access_login.value+"&PASSWORD="+ access_password.value+"&RIGHT="+ access_right.value+"&ZIPCODE="+ access_zipcode.value+"&VALIDITY="+ access_validity.value);
}
function orenaaccess_newidReturn(abtid)
{	
	abt_selectid(abtid);
}

function orenaaccess_updateid(accessid)
{
		var access_type = document.getElementById("access_type");
		var access_login = document.getElementById("access_login");
		var access_password = document.getElementById("access_password");
		var access_right = document.getElementById("access_right");
		var access_zipcode = document.getElementById("access_zipcode");
		var access_validity = document.getElementById("access_validity");
		var access_abt = document.getElementById("abt_id");
		CallServer("updateaccessid",new Function("orenaaccess_updateidReturn("+access_abt.value+")"),null,"/orena/ABAjax.php?module=orenaAccess,action=updateaccessinfo;" + accessid,"ABT_ID="+ access_abt.value +"&TYPE="+ access_type.value+"&LOGIN="+ access_login.value+"&PASSWORD="+ access_password.value+"&RIGHT="+ access_right.value+"&ZIPCODE="+ access_zipcode.value+"&VALIDITY="+ access_validity.value);																		
}

function orenaaccess_updateidReturn(abtid)
{	
	abt_selectid(abtid);
	// DEBUG...
	//var addressinfo = GetServerResponce("updateaccessid");
	//var addressform = document.getElementById("DEBUGform");
	//addressform.innerHTML = addressinfo;
}

