/// #################################
///    common.js
/// #################################
/// -------+----------+-----------+---------------+-----------------------------------
/// Version|Date      |Developper |Action         |Description
/// -------+----------+-----------+---------------+-----------------------------------
/// R1.0   |08.03.2001|Marc       |Creation       |
///

//if (window != top) location.replace("http://www.franceguide.com/401-1.htm");

function OpenForm(url,w,h,options) {
	w = (w) ? w : '800';
	h = (h) ? h : '600';
	
	options = (options) ? options : 'scrollbars=yes,location=no,toolbar=no,menu=no,resizable=yes,status=no';

	l = (top.screen.width-w)/2;
	t = (top.screen.height-h)/2;

//	options = '"toolbar=no,status=yes,menubar=no,fullscreen=no,height="+h+",width="+w';	
	options = 'height='+h+',width='+w+',left='+l+',top='+t+','+options;
	wnd = window.open(url,'',options);
	wnd.focus();
}


function OpenForm2(strForm) {
	
	var win = window.open(strForm,"","resizable=yes,toolbar=yes,status=yes,menubar=yes,fullscreen=no,height=600,width=800");
  	onerror = null;
 	win.focus();
}

function PopBox(strPrompt,strTitle,strIcon) {
	 var msg = "";
	 
	 strIcon = (strIcon) ? strIcon : "/common/icoinformation.gif";
	 strTitle = (strTitle) ? strTitle : "Message";

	 msg += '<HTML><TITLE>' + strTitle + '</TITLE>';
	 msg += '<BODY BGCOLOR=#BFBFBF MARGINHEIGHT=0 MARGINWIDTH=0 STYLE="font-family:Arial;font-size:8pt;margin:0pt;border:0pt solid;"><BGSOUND SRC="file:///c:/windows/media/ding.wav">';
	 msg += '<TABLE BORDER=0 SCROLL="NO" CELLPADDING=0 CELLSPACING=0 WIDTH=100% HEIGHT=95% >';
	 msg += '<TR HEIGHT=95% >';
	 msg += '<TD WIDTH=15% VALIGN=TOP ALIGN=CENTER>';
	 msg += '<IMG SRC='+strIcon+' border=0 vspace=20 hspace=3>';
	 msg += '</TD>';
	 msg += '<TD VALIGN=TOP><BR>';
	 msg += strPrompt + '<BR><BR>';
	 msg += '</TD></TR>';
	 msg += '<TR><TD ALIGN=CENTER COLSPAN=2><FORM><INPUT TYPE=BUTTON VALUE="&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;" onclick="window.close();"></FORM></TD></TR>';
	 msg += '</TABLE></BODY></HTML>';

 	var winPopup=open('','','resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no,fullscreen=no,height=200,width=450,alwaysRaised=yes');
 	winPopup.document.write(msg);
  	onerror = null;
 	winPopup.focus();
 	winPopup.moveTo((top.screen.width-450)/2,(top.screen.height-200)/2)
}

function ShowTheme(el) {
	document.styleSheets('Theme').href = "themes/"+el.id+".css";
}

function HideFolder() {
	if (parent.frames['folders'].cols == "0,*") {
		parent.frames['folders'].cols = "200,*";
	} else {
		parent.frames['folders'].cols = "0,*";
	}
}

function ShowSplashScreen(url, w, h) {
	var splashWin, autoCloseTimeoutHandle, ontopIntervalHandle;
	splashWin = window.open(url, '_splash', 'fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0' );
	splashWin.blur();	
	window.focus();
	splashWin.resizeTo(w,h);
 	splashWin.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
	splashWin.focus();
}

function openPopup(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var Win = open(url, '_pop', 'resizable=no,scrollbars='+scroll+',toolbar=no,status=no,menubar=0,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes' );
	Win.blur();
	Win.focus();
	if (!nocenter) {
		onError = null;
 		Win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
 	}
}

function openPopup2(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var Win = open(url, '_pop2', 'resizable=no,scrollbars='+scroll+',toolbar=no,status=no,menubar=0,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes' );
	Win.blur();
	Win.focus();
	if (!nocenter) {
		onError = null;
 		Win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
 	}
}

function openPopup3(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var Win = open(url, '_pop', 'resizable=no,scrollbars='+scroll+',toolbar=no,status=no,menubar=1,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes' );
	Win.blur();
	Win.focus();
	if (!nocenter) {
		onError = null;
 		Win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
 	}
}

function ShowContent(url) {
	top.frames['frmContent'].location.href = url;
}

function SearchAndReplace(Content, SearchFor, ReplaceWith) {

   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;

   if (SearchFor.length == 0)
      return;


   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
   
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;

      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;


      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);

   }

   return tmpOutput + tmpContent;

}

function confirm_delete(sUrl) {
	var bchoice = confirm('Confirmez-vous la suppression de cet enregistrement ?');
	if (!bchoice) return;
	self.location.href = sUrl;
}

function checkall(el) {
	for (var i=0;i<frmlist.elements.length;i++) {
		if (frmlist.elements[i].type == 'checkbox') {
			frmlist.elements[i].checked = el.checked;
		}
	}
}

function ModifierSelection(liste1, liste2, listeId, ChaineId, booRecords){
	
//	Tous les enregistrements	
	if (booRecords == true){
		i = 0 ;
		while (i != liste1.options.length ){
			o = new Option(liste1.options[i].text, liste1.options[i].value);
			//o = Option.create(liste1.options[i].text, liste1.options[i].value);
			liste2.options[liste2.options.length]=o;
			o = null;
			i = i + 1;
		}
		
		liste1.options.length = null;
	}
//  Un seul enregistrement	
	else {
		if (liste1.options.selectedIndex>=0) {
			//o = Option.create(liste1.options[liste1.options.selectedIndex].text,liste1.options[liste1.options.selectedIndex].value);
			o = new Option(liste1.options[liste1.options.selectedIndex].text,liste1.options[liste1.options.selectedIndex].value);
			liste2.options[liste2.options.length]=o;
			liste1.options[liste1.options.selectedIndex]=null;
			o = null;
		} 
	}
//	Mettre à jour le champ caché	
	UpdateListeId(listeId, ChaineId)

}



function UpdateListeId(listeId, ChaineId){

//	Mettre à jour le champ caché contenant les id sélectionnés

	i = listeId.options.length;
	sChaineId = "";
	if ( i > 0){
		while(i != 0){
			sChaineId = sChaineId + listeId.options[i-1].value + ', ';
			i = i - 1;	
		}
		ChaineId.value = sChaineId.substr(0, sChaineId.length-2);
	}
	else{
		ChaineId.value = "";
	}
}


function AjouterElement(liste, identifiant, libelle){
	o = new Option(libelle, identifiant);
	liste.options[liste.options.length]=o;
	o = null;
}

function checkedAll(frm) {
	for (var i=0;i<document.forms[frm].elements.length;i++)	{
		if (document.forms[frm].elements[i].type == 'checkbox') {
			document.forms[frm].elements[i].checked = true;
		}
	}
}

function uncheckedAll(frm) {
	for (var i=0;i<document.forms[frm].elements.length;i++)	{
		if (document.forms[frm].elements[i].type == 'checkbox')	{
			document.forms[frm].elements[i].checked = false;
		}
	}
}

function tcheck(elm,frm) {
	if (elm.checked)
		checkedAll(frm);
	else 
		uncheckedAll(frm);
}

function submitForm(frm,name_action,mode_action, url, target) {
	if ((url.length) > 0) {
		document.forms[frm].action = url;
	}
	if ((target.length) > 0) {
		document.forms[frm].target = target;
	}
	document.forms[frm].elements[name_action].value = mode_action;
	document.forms[frm].submit();
}

function DisplayTag(bChecked, sTag){
	if (bChecked) {
		document.all.item(sTag).innerHTML = document.all("id_" + sTag).innerHTML;
	} else {
		document.all.item(sTag).innerHTML = '';
	}
}

function DisplayListe(bValue){
	if (bValue==1) {
		document.all.item("musees").innerHTML = document.all("id_" + "musees").innerHTML;
		document.all.item("sites").innerHTML = '';
		document.all.item("centres").innerHTML = '';
		document.all.item("jardins").innerHTML = '';
	}
	
	if (bValue==2) {
		document.all.item("sites").innerHTML = document.all("id_" + "sites").innerHTML;
		document.all.item("musees").innerHTML = ''
		document.all.item("centres").innerHTML = ''
		document.all.item("jardins").innerHTML = ''
	}

	if (bValue==3) {
		document.all.item("centres").innerHTML = document.all("id_" + "centres").innerHTML;
		document.all.item("sites").innerHTML = '';
		document.all.item("musees").innerHTML = '';
		document.all.item("jardins").innerHTML = '';
	}
	if (bValue==4) {
		document.all.item("jardins").innerHTML = document.all("id_" + "jardins").innerHTML;
		document.all.item("musees").innerHTML = '';
		document.all.item("sites").innerHTML = '';
		document.all.item("centres").innerHTML = '';
	}
	if (bValue==0) {
		document.all.item("jardins").innerHTML = '';
		document.all.item("musees").innerHTML = '';
		document.all.item("sites").innerHTML = '';
		document.all.item("centres").innerHTML = '';
	}
	
	
}
function DisplayListe2(bValue){
	if (bValue==1) {
		document.all.item("musees2").innerHTML = document.all("id_" + "musees2").innerHTML;
		document.all.item("sites2").innerHTML = '';
		document.all.item("centres2").innerHTML = '';
		document.all.item("jardins2").innerHTML = '';
	}
	
	if (bValue==2) {
		document.all.item("sites2").innerHTML = document.all("id_" + "sites2").innerHTML;
		document.all.item("musees2").innerHTML = ''
		document.all.item("centres2").innerHTML = ''
		document.all.item("jardins2").innerHTML = ''
	}

	if (bValue==3) {
		document.all.item("centres2").innerHTML = document.all("id_" + "centres2").innerHTML;
		document.all.item("sites2").innerHTML = '';
		document.all.item("musees2").innerHTML = '';
		document.all.item("jardins2").innerHTML = '';
	}
	if (bValue==4) {
		document.all.item("jardins2").innerHTML = document.all("id_" + "jardins2").innerHTML;
		document.all.item("musees2").innerHTML = '';
		document.all.item("sites2").innerHTML = '';
		document.all.item("centres2").innerHTML = '';
	}
	if (bValue==0) {
		document.all.item("jardins2").innerHTML = '';
		document.all.item("musees2").innerHTML = '';
		document.all.item("sites2").innerHTML = '';
		document.all.item("centres2").innerHTML = '';
	}
	
}


function VerifChecked(element){
	if (element.checked){
		element.checked = false;
	}
}


function choixCommune(frm,fieldcom,fieldcp,cp,nom,guid)
{
	openPopup2('/adherents/recherche/commune/liste.asp?z1=' + guid + '&cp=' + cp + '&nom=' + nom + '&frm=' + frm + '&fieldcom=' + fieldcom + '&fieldcp=' + fieldcp,500,600,0,1);
		
}


function Compter(Target, max, nomchamp)
{
	StrLen = Target.value.length
	if (StrLen > max)
		{
			Target.value = Target.value.substring(0,max);
			CharsLeft = max;								
		}
	else
		{CharsLeft = StrLen;}	
	nomchamp.value = CharsLeft;
}

function PopupVisiteVirtuelle(idatf, params)
{
	params = (params) ? params : '';
	OpenForm('/adherents/visites_virtuelles/default.asp?idatf='+idatf+params, 472, 530, 'scrollbars=no,location=no,toolbar=no,menu=no,resizable=no,status=no');
}

// function act : permet d'afficher la page adhérent correspondante suite à un clique de souris
function act(idatf, idact, z1)
{
	if (z1 == null)
	{
		z1="$$Z1$$";
	}
	window.location.href = "/adherents/fiche_atf.asp?z1=" + z1 + "&idatf="+idatf+"&ida="+idact+"&m1=";
	//<%=cSession.GUID%>
}

// Ajout de nouvelle fct DH
	function RemplirChamps(Liste,Calque)
		{
		//alert(Liste.options[Liste.selectedIndex].value)
		//document.form1.ou.value=Liste.selectedIndex.value
		if(Calque=="ou")
		{
			document.form1.outxt.value=Liste.options[Liste.selectedIndex].text
			document.form1.ouval.value=Liste.options[Liste.selectedIndex].value
		}
		if(Calque=="quoi")
		{
			document.form1.quoitxt.value=Liste.options[Liste.selectedIndex].text
			document.form1.quoival.value=Liste.options[Liste.selectedIndex].value
		}
		
		OuvrFermMenu(Calque)
		}

	function ShowOu()
	{
		win_ou.setSize(200,115);
		win_ou.offsetX = -243;
		win_ou.offsetY = 21;
		win_ou.showPopup('anchor_ou');
		win_ou.autoHide();
	}
	function ShowQuoi()
	{
		win_quoi.setSize(200,105);
		win_quoi.offsetX = -243;
		win_quoi.offsetY = 21;
		win_quoi.showPopup('anchor_quoi');
		win_quoi.autoHide();
	}
//autre fonction
function launchrech(typeRech,result,reg,femsel,result1,result2)
	{
		switch (typeRech)
		{
			case 1 : 
				
				if (document.form1.ouval.value>0)
				{
					//alert(document.form1.quoival.value);
					if (document.form1.quoival.value>0)
					{
						//1 er param <%=cSession.HREF("/home/resultat2.asp","idr=' + document.form1.ouval.value + '&idact=' + document.form1.quoival.value + '")%>
						window.location = result;
					}
					else
					{ //2 eme param <%=cSession.HREF("/regions/region.asp","idr=' + document.form1.ouval.value + '")%>
						window.location = reg;
					}
					
				}
				else
				{
					
					if (document.form1.quoival.value==9) //FEM
						{ //3 ème param <%=cSession.HREF("/thematiques/fetemanifs/selection.asp","")%>
						window.location = femsel;
						}
					else
						{
							if (document.form1.quoival.value>0)
							{ //4 ème param <%=cSession.HREF("/home/resultat2.asp","idr=' + document.form1.ouval.value + '&idact=' + document.form1.quoival.value + '")%>
								window.location = result1;
							}						
						}
				}
				break;



			case 3 : 
				//if (document.form1.motcle.value <> "")
				//	{ 
				// 5 param <%=cSession.HREF("/home/resultat1.asp","")%>
						document.form1.action = result2;
						document.form1.submit();
						//window.location = '<%=cSession.HREF("/home/resultat1.asp","mc=' + document.form1.motcle.value + '")%>';
				//	}
				break;


		}
	}

//-----------
	function TestChange()
		{
			alert('le texte a change');
		}
		
//------------
function MM_jumpMenu2(targ,selObj,restore)
{
	if (selObj.options[selObj.selectedIndex].value != '')
	{
		whereclose = 'and ID_Bureau = ' + selObj.options[selObj.selectedIndex].value;
		window.form_test.requete.value = whereclose;
		window.form_test.submit();
	}
	else 
		alert('Veuillez selectionner un pays');
}		

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

