//------------------------------------------------------------------------------------------------//
// MAIN FUNCTIONS SECTION                                                                         //
//------------------------------------------------------------------------------------------------//
function GetMainFormName()
{
	var i;
	for (i=0;i<document.forms.length;i++)
	{
		// Framework v1.0.3705
		if (document.forms[i].name.indexOf("_ServerForm") != -1)
			return document.forms[i].name;
		// Framework v1.1.4322
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
			return document.forms[i].name;
	}
	return null;
}

function SaveElement(ElementObject,ElementValue)
{
	var mf = GetMainFormName();					
	if (mf==null) return;
	var element  = GetElement(ElementObject,mf);
	if (element!=null) 
		element.value = ElementValue;
}

function GetElementName(n,mf)
{
	if (n==null || n=="") return null;
	n = n.toLowerCase();
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
		if (document.forms[mf].elements[i].name.toLowerCase().lastIndexOf(n) != -1)
		{
			var strform = document.forms[mf].elements[i].name.toLowerCase();
			var strformname = strform.substr(strform.lastIndexOf(n));
			if (strformname == n)
				return document.forms[mf].elements[i].name;
		}	
	}
	return null;
}

function GetElement(ElementName, formName)
{
	return document.forms[formName].elements[GetElementName(ElementName,formName)];
}

//------------------------------------------------------------------------------------------------//
// CONTACT US FUNCTIONS SECTION                                                                   //
//------------------------------------------------------------------------------------------------//
var subjectlist;

//-----------------------------------------------//
// This function add a subject to subjects list. //
//-----------------------------------------------//
function AddSubject(subject, subsubject)
{
	var index;
	var subjectfound = false;
	var currentsubject;
	
	if (!subjectlist)
	{
		// Initialize subject Array;
		 subjectlist = new Array();
	}

	// Search the subject in subjects Array
	for (index = 0; (index < subjectlist.length) && !subjectfound; index++)
	{
		currentsubject = subjectlist[index];
		
		// Test if subject and current subject are defined
		if (subject && currentsubject)
		{
			if (subject.code == currentsubject.code)
			{
				subjectfound = true;
			}
		}
	}

	if (!subjectfound)
	{
		// Add the subject to subjects Array
		subjectlist.push(subject);
		currentsubject = subject;
	}

	// Add the subsubject to the subject
	AddSubSubject(currentsubject, subsubject);
}

//---------------------------------------------//
// This function add a subsubject to a subject //
//---------------------------------------------//
function AddSubSubject(subject, subsubject)
{
	// Test if subject and subsubject are defined
	if (subject && subsubject)
	{
		if (!subject.subsubjects)
		{
			subject.subsubjects = new Array();
		}
		
		// Add subsubject
		subject.subsubjects.push(subsubject);
	}
}

//---------------------------------------------//
// This function fills a select with subjects. //
//---------------------------------------------//
function FillSubject()
{
	var index;
	var optionitem;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subjecthidden = GetElement("mail_subject", 0);
	
	if (subjectselect && subjectlist)
	{
		// Reset subjects
		ResetSelect(subjectselect);
		
		for (index = 0; index < subjectlist.length; index++)
		{
			// Add option item
			optionitem = document.createElement("OPTION");
			optionitem.text = subjectlist[index].text;
			optionitem.value = subjectlist[index].code;
			subjectselect.options[subjectselect.options.length] = optionitem;
			
			if (subjecthidden)
			{
				// Select the current value
				optionitem.selected = (optionitem.value == subjecthidden.value);
			}
		}
	}
}

//------------------------------------------------//
// This function fills a select with subsubjects. //
//------------------------------------------------//
function FillSubSubject()
{
	var optionitem;
	var index;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subsubjectselect = GetElement("mail_subsubject_list", 0);
	var subsubjecthidden = GetElement("mail_subsubject", 0);

	if (subjectselect && subsubjectselect)
	{
		// Reset subsubjects					
		ResetSelect(subsubjectselect);
		
		currentsubject = subjectlist[subjectselect.options.selectedIndex - 1];
		
		if (currentsubject && currentsubject.subsubjects)
		{		
			for (index = 0; index < currentsubject.subsubjects.length; index++)
			{
				// Add option item
				optionitem = document.createElement("OPTION");
				optionitem.text = currentsubject.subsubjects[index].text;
				optionitem.value = currentsubject.subsubjects[index].code;
				subsubjectselect.options[subsubjectselect.options.length] = optionitem;
				
				if (subsubjecthidden)
				{
					// Select the current value
					optionitem.selected = (optionitem.value == subsubjecthidden.value);
				}
			}
		}
	}
}

//------------------------------------------------//
// This function resets a select.                 //
//------------------------------------------------//
function ResetSelect(selectlist)
{
	// Remove options
	while (selectlist.options.length != 1)
	{
		selectlist.options[1] = null;
	}
}

//------------------------------------------------//
// This function gets a value from a list using   //
// its index and return the default value if      //
// index is out of range or list is null.         //
//------------------------------------------------//
function GetListValue(list, index, defaultvalue)
{
	if (list && list[index])
	{
		return list[index];
	}
	else
	{
		return defaultvalue;
	}
}	

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubjectListChange()
{
	var subsubject;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		// Get the first subsubject for current subject
		subsubject = subject.subsubjects[0];
		SaveElement('mail_subject', subject.text);
		SaveElement('mail_subject_code', subject.code);
		
		if (subsubject)
			SaveElement('mail_to', subsubject.emailto);
	}
	else
	{
		SaveElement('mail_subject', '');
		SaveElement('mail_subject_code', '');
		SaveElement('mail_to', '');
	}
	
	if(GetElement("mail_subsubject_list", 0))
	{
		FillSubSubject();
	}
}

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubSubjectListChange()
{
	var subjectselect;
	var subsubjectselect;
	var subject;
	var subsubject;
	
	subjectselect = GetElement("mail_subject_list", 0);
	subsubjectselect = GetElement("mail_subsubject_list", 0);
	subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		subsubject = GetListValue(subject.subsubjects, subsubjectselect.selectedIndex - 1, null);
		
		if (subsubject)
		{
			SaveElement('mail_subsubject', subsubject.text);
			SaveElement('mail_subsubject_code', subsubject.code);
			SaveElement('mail_to', subsubject.emailto);
		}
		else
		{
			SaveElement('mail_subsubject', '');
			SaveElement('mail_subsubject_code', '');
			SaveElement('mail_to', '');
		}
	}
}

// ==========================================================
// OPEN WINDOW
// ==========================================================

function openw(url,name,w,h,resize,scroll)
	{
	winopen = window.open(url,name,"width="+w+",height="+h+",resizable="+resize+",scrollbars="+scroll+",menubar=no,toolbar=no,directories=no,location=no,status=no,left=100,top=100");
	winopen.focus();
	}
	


// ==========================================================
// INITIALISATION DE l'AXE PRINCIPALE
// ==========================================================

var AXE = 0;

var NumAXE = new Array();
NumAXE[0]='spacer';
NumAXE[1]='dermato';
NumAXE[2]='ico';
NumAXE[3]='expert';
NumAXE[4]='actu';
NumAXE[5]='inscrits';

function RollAxe(AXE){
	eval("document.maintitle.src='/img/_int/_fr/navtop/t_"+NumAXE[AXE]+".gif'");
	eval("document.pict_"+NumAXE[AXE]+".src='/img/_common/pict_nav_"+NumAXE[AXE]+".jpg'");
}

function hideAxe(){
	for(i=1;i<5;i++){
	eval("document.pict_"+NumAXE[i]+".src='/img/_common/pict_nav_"+NumAXE[i]+"_off.jpg'");
	}
}

function INITAxe(){
	hideAxe();
	RollAxe(AXE);
	}



// ==========================================================
// SOUS NAVIGATION PAR ONGLET 
// ==========================================================

var numCourant = 0;

function showdetail(num){
	hidedetail();
	layerdetail(num);
}

function hidedetail(){
	for (i=0; i<3; i++)
	{
	eval("document.getElementById('layerdetail"+i+"').style.display = 'none'");
	}
}

function layerdetail(num){
	eval("document.getElementById('layerdetail"+num+"').style.display = 'block'");
	numCourant = num;
}




// ==========================================================
// AFFICHAGE DYNAMIQUE
// ==========================================================

function ConditionalDisplay(url,value, descrition, parametre, type)
{


	if (value != null && value != "")
	{
		switch (type)
		{
			case "img" :	TextToDisplay = '<img src="'+ url + value +'" alt="'+descrition;
							if (parametre != null  && parametre != "")
									TextToDisplay = TextToDisplay + '" ' + parametre +' />';
							else
									TextToDisplay = TextToDisplay +'" />';
							break;
			case "href" :	TextToDisplay = '<a href="'+ url + value +'">'+descrition+'</a>';
							break;
			default :
							break;

		}
		//alert(TextToDisplay)
		document.write(TextToDisplay);
	}
}

var countryList;
var listSchool;

//-----------------------------------------------//
// This function add a a list of countries.		 //
//-----------------------------------------------//
function AddCountry(country)
{
	var index;
	var countryFound = false;
	var currentCountry;

    //alert ("addcountry");

	if (!countryList)
	{
		// Initialize theme Array;
		countryList = new Array();
	}

	// Search the theme in themes Array
	for (index = 0; (index < countryList.length) && !countryFound; index++)
	{
		currentCountry = countryList[index];
		// Test if country is already defined
		if (countryList && currentCountry)
		{
			if (country.Code == currentCountry.code)
			{
				countryFound = true;
			}
		}
	}

	if (!countryFound)
	{
		// Add the theme to themes Array
		countryList.push(country);
	}
}

//-----------------------------------------------//
// This function get a country using its name.	 //
//-----------------------------------------------//
function GetCountry(countryName)
{
	var index;
	var currentCountry;

	if (countryList)
	{
		// Search the theme in themes Array
		for (index = 0; (index < countryList.length); index++)
		{
			currentCountry = countryList[index];
			if (currentCountry.name == countryName)
			{
				return currentCountry;
			}
		}
	}	
	return null;
}

//-----------------------------------------------//
// This function add a localisation theme to lacalisation list. //
//-----------------------------------------------//
function AddSchool(school)
{
	if (!listSchool)
	{
	    //alert ("initialyse shoollist");
		// Initialize theme Array;
		listSchool = new Array();
	}
    listSchool.push(school);
}



//---------------------------------------------//
// This function fills a select with themes. //
//---------------------------------------------//
function FillCountry()
{
    //alert("fillcountry");
    //alert ("countryList.length : " + countryList.length);
	var index;
	var optionItem;
	var countrySelect = GetElement("countryList", 0);
	var countryHidden = GetElement("f1Country_Code", 0);
	if (countrySelect && countryHidden)
	{
		// Reset theme
		ResetSelect(countrySelect);

		for (index = 0; index < countryList.length; index++)
		{
			// Add option item
			optionItem = document.createElement("OPTION");
			optionItem.text = countryList[index].CountryName;
			optionItem.value = countryList[index].CountryCode;
			countrySelect.options[countrySelect.options.length] = optionItem;

			if (countryHidden)
			{
				// Select the current value
				optionItem.selected = (optionItem.value == countryHidden.value);
			}
		}
	}
}

//---------------------------------------------//
// This function fills a select with localisation. //
//---------------------------------------------//
function FillSchool()
{
    var index;
	var optionItem;
	var otherSchoolCode;
	var otherSchoolName;
	var flagOther = 0;
	var schoolSelect = GetElement("schoolList", 0);
	var HiddenSchoolName = GetElement("ep1ihSchoolName", 0);
	var HiddenSchoolId = GetElement("ep1ihSchoolId", 0);

	var countrySelect = GetElement("address_country_choice", 0);

	var currentCountry = countrySelect[countrySelect.options.selectedIndex].text;
	//alert ("currentCountry : " + currentCountry);
	//alert ("listSchool.length : " +listSchool.length);
	if (schoolSelect && HiddenSchoolId)
	{
		// Reset theme
		ResetSelect(schoolSelect);

		if (currentCountry)
		{
			for (index = 0; index < listSchool.length; index++)
			{
                /*if (index < 10)
                    alert(listSchool[index].CountryName);*/
                    
				if (currentCountry == listSchool[index].CountryName)
				{
				    if (listSchool[index].SchoolName == "Other, not specified") 
				    {
				        otherSchoolName = listSchool[index].SchoolName;
					    otherSchoolCode = listSchool[index].SchoolOrder;
					    flagOther = 1;
				    }
				    else
				    {
					    // Add option item
					    optionItem = document.createElement("OPTION");
					    optionItem.text = listSchool[index].SchoolName;
					    optionItem.value = listSchool[index].SchoolOrder;


					    schoolSelect.options[schoolSelect.options.length] = optionItem;
					    
					    if (HiddenSchoolName)
					    {
						    // Select the current value
						    optionItem.selected = (optionItem.value == HiddenSchoolName.value);
					    }
					}

					
				}
			}
			
			if (flagOther == 1)
			{
			    optionItem = document.createElement("OPTION");
		        optionItem.text = otherSchoolName;
		        optionItem.value = otherSchoolCode;

		        schoolSelect.options[schoolSelect.options.length] = optionItem;
		    }
		    
		    if (HiddenSchoolName)
		    {
			    // Select the current value
			    optionItem.selected = (optionItem.value == HiddenSchoolName.value);
		    }
		}
	}
}

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnCountryListChange()
{
	var country;
	var countryControl;
	var countryCodeControl;
	var countryCode;
	// Get the current country code
	countryControl = GetElement('group_address_country_choice', 0);
	//alert(countryControl)
	if (countryControl)
	{
		country = GetCountry(countryControl.value);
		
		if (country != null)
		    countryCode = country.code;
		
		if (countryCode)
		{
			SaveElement('hidden_country_code', countryCode);
			Refresh();
		}
		else
		{
			SaveElement('ep1ihGroupSchoolName', '');
			SaveElement('ep1ihGroupSchoolName', '');
			
			Refresh();
		}
	}
}

    function ReloadDegree()
    {
        var degreeSelect = GetElement("degree", 0);
        var mf = GetMainFormName();
	    if (mf==null) return;
	    var ep1ihUserDegreeId = GetElementName("ep0ihUserDegreeId",mf)
	    //alert ("document.forms[mf].elements[ep1ihUserDegreeId].value : " + document.forms[mf].elements[ep1ihUserDegreeId].value);
        if (document.forms[mf].elements[ep1ihUserDegreeId].value != null && document.forms[mf].elements[ep1ihUserDegreeId].value!= "" && document.forms[mf].elements[ep1ihUserDegreeId].value != "undefined")
        {
            /*alert ("mise à jour");
	        degreeSelect[document.forms[mf].elements[ep1ihUserDegreeId].value].selected = true;*/
	        
	        for (var i = 0; i != degreeSelect.options.length; i ++)
	        {
	            optionItem = degreeSelect.options[i];
	            //alert (optionItem.text + "-" + optionItem.value);
	            if (optionItem.value == document.forms[mf].elements[ep1ihUserDegreeId].value)
	            {
	                optionItem.selected = true;
	            }
	        }
	        
	        /*for (var i in degreeSelect)
	        {
	            alert(degreeSelect[i]);
	        }*/
	    }
    
    }

    function OnDegreeListChange()
    {
        var degreeSelect = GetElement("degree", 0);
        
        var mf = GetMainFormName();
	    if (mf==null) return;
	    var ep1ihUserDegreeId = GetElementName("ep0ihUserDegreeId",mf)

	    if (ep1ihUserDegreeId != null)
	        document.forms[mf].elements[ep1ihUserDegreeId].value = degreeSelect[degreeSelect.options.selectedIndex].value;
    	
	    var ep1ihUserDegreeName = GetElementName("ep0ihUserDegreeName",mf)
        if (ep1ihUserDegreeName != null)
	        document.forms[mf].elements[ep1ihUserDegreeName].value = degreeSelect[degreeSelect.options.selectedIndex].text;
    }

    function ReloadField()
    {
        var fieldSelect = GetElement("field", 0);
        
        var mf = GetMainFormName();
	    if (mf==null) return;
    	
	    var ep1ihFieldId = GetElementName("ep0ihFieldId",mf)
        if (document.forms[mf].elements[ep1ihFieldId].value != null && document.forms[mf].elements[ep1ihFieldId].value != "")
        {
	        fieldSelect[document.forms[mf].elements[ep1ihFieldId].value].selected = true;
	    }
    }

    function OnFieldListChange()
    {
        var fieldSelect = GetElement("field", 0);
        
        var mf = GetMainFormName();
	    if (mf==null) return;
    	
	    var ep1ihFieldId = GetElementName("ep0ihFieldId",mf)
	    if (ep1ihFieldId != null)
	        document.forms[mf].elements[ep1ihFieldId].value = fieldSelect[fieldSelect.options.selectedIndex].value;
    	
	    var ep1ihFieldName = GetElementName("ep0ihFieldName",mf)
        if (ep1ihFieldName != null)
	        document.forms[mf].elements[ep1ihFieldName].value = fieldSelect[fieldSelect.options.selectedIndex].text;
    }

    function ReloadSchoolId()
    {
        var fieldSelect = GetElement("schoolList", 0);
        
        var mf = GetMainFormName();
	    if (mf==null) return;
    	
	    var ep1ihSchoolId = GetElementName("ep1ihSchoolId",mf)
        if (document.forms[mf].elements[ep1ihSchoolId].value != null && document.forms[mf].elements[ep1ihSchoolId].value != "")
        {
	        fieldSelect[document.forms[mf].elements[ep1ihSchoolId].value].selected = true;
	    }
    }


    function OnSchoolListChange()
    {
        //alert("OnSchoolListChange");
        var schoolSelect = GetElement("schoolList", 0);
        
        var mf = GetMainFormName();
	    if (mf==null) return;
    	
	    var ep1ihSchoolId = GetElementName("ep1ihSchoolId",mf)
	    if (ep1ihSchoolId != null)
	        document.forms[mf].elements[ep1ihSchoolId].value = schoolSelect[schoolSelect.options.selectedIndex].value;
    	
	    var ep1ihSchoolName = GetElementName("ep1ihSchoolName",mf)
        if (ep1ihSchoolName != null)
	        document.forms[mf].elements[ep1ihSchoolName].value = schoolSelect[schoolSelect.options.selectedIndex].text;
        
        //alert (schoolSelect[schoolSelect.options.selectedIndex].value);
    }



function SetPage(page)
{
	var mf = GetMainFormName();
	if (mf==null) return;
	var p = GetElement('p',mf);
	p.value=page;
	//alert(p.value);
	//Refresh();


	document.forms[mf].submit();
}

function Write(num)
{
	document.write('<a href="#" onclick="SetPage('+num+');">'+num+'</a>');
}

/************************************/
/*	Used to selected the Status		*/
/************************************/
function GetStatus()
{
	var mf = GetMainFormName();
	if (mf==null) return;
	var f1Status	= GetElementName('f',mf);
	var StatusSelect = GetElementName('StatusSelect',mf);
	var df = document.forms[mf];
	var len = df.elements[StatusSelect].length;

	if (df.elements[f1Status].value != null)
	{
		if(df.elements[f1Status].value != "")
		{
			for(var i=0; i<len; i++)
			{
				if(df.elements[f1Status].value == df.elements[StatusSelect][i].value)
				{
					df.elements[StatusSelect][i].selected = true;
					break;
				}
			}
		}
	}
}

/************************************/
/*	Used to set the status selected */
/************************************/
function SetStatus()
{
	var mf = GetMainFormName();
	if (mf==null) 
		return;
	var df = document.forms[mf];
	var StatusSelect = GetElementName('StatusSelect',mf);
	var f1Status = GetElementName('f',mf);
	if(df.elements[StatusSelect].options[df.elements[StatusSelect].selectedIndex].value != "##")
	{
			df.elements[f1Status].value = df.elements[StatusSelect].options[df.elements[StatusSelect].selectedIndex].value;
	}
	else
		df.elements[f1Status].value = "0";
}

/************************************/
/*	Used to Refrech the page		*/
/************************************/
function Refresh()
{
	var mf = GetMainFormName();
	if (mf==null) return;
	document.forms[mf].submit();
}

function GetStatusName(StatusValue)
{
	var StatusName = "";
	if (StatusValue != null && StatusValue != "")
	{
		switch (StatusValue)
		{
			case "0" :	StatusName = "EC Com.Technique";
							break;
			case "1" :	StatusName = "EC Com.Scientifique";
							break;
			case "2" :	StatusName = "EC Com.Anapath";
							break;
			case "3" :	StatusName = "EC publication. Dermatologue";
							break;
			case "4" :	StatusName = "Valid&eacutee publiable";
							break;
			case "5" :	StatusName = "Valid&eacutee publication refus&eacutee";
							break;
			case "8" :	StatusName = "Arret publication";
							break;
			case "9" :	StatusName = "Refus&eacutee";
							break;
		}
	}
	document.write(StatusName);
}

function Sesame(page,larg,haut,scraul)
{
	//alert("function sesame");
	var posXpop = (screen.availWidth-larg)/2
	var posYpop = (screen.availHeight-haut)/2
	param = "width="+larg+",height="+haut+",left="+posXpop+",top="+posYpop+",status=1,scrollbars="+scraul
	popup = window.open(page,"pop",param)
}
