/// #################################
///    common.js
/// #################################
/// -------+----------+-----------+---------------+-----------------------------------
/// Version|Date      |Developper |Action         |Description
/// -------+----------+-----------+---------------+-----------------------------------
/// R1.0   |08.03.2001|Marc       |Creation       |
///

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);
	if(wnd) 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%>
}

function CheckAllCheckBoxes(ctl, key) {
	for (var i=0;i<ctl.form.elements.length;i++)	{
		var c = ctl.form.elements[i];
		var id = c.id;
		if (c.type == 'checkbox' && id.substr(id.length-key.length) == key) {
			c.checked = ctl.checked;
		}
	}
}

function HideForCoolMenu()
{
	if (document.all)
	{
        if (document.all.CoolmenuHide)
			document.all.CoolmenuHide.style.visibility='hidden';
        if (document.all.CoolmenuHide2)
			document.all.CoolmenuHide2.style.visibility='hidden';

     } 
     else
     {
		if (document.layers['CoolmenuHide'])			
			document.layers['CoolmenuHide'].visibility='hide';
		if (document.layers['CoolmenuHide2'])			
			document.layers['CoolmenuHide2'].visibility='hide';
	}
}

function ShowForCoolMenu()
{
	if (document.all)
	{
        if (document.all.CoolmenuHide)
			document.all.CoolmenuHide.style.visibility='visible';
        if (document.all.CoolmenuHide2)
			document.all.CoolmenuHide2.style.visibility='visible';

     } 
     else
     {
		if (document.layers['CoolmenuHide'])			
			document.layers['CoolmenuHide'].visibility='show';
		if (document.layers['CoolmenuHide2'])			
			document.layers['CoolmenuHide2'].visibility='show';
	}
}

function st(txt) {	window.status=txt?txt:' ';	return true;}

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)
}

var win_ou = new PopupWindow('clqou');
var win_quoi = new PopupWindow('clqquoi');

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();
}

function stripFormatedHTML(strHTML, sTags){
	var j;
	
	if(strHTML && strHTML!="&nbsp;"){
//		var sTags = ['BR', 'STRONG', 'EM', 'U', 'I', 'B'];
		
		strHTML = strHTML.replace(eval('/<p>/ig'), '<BR>');

		for(j=0; j<sTags.length; j++){
			strHTML = strHTML.replace(eval('/<'+sTags[j]+'>/ig'), 'µµ'+sTags[j]);
			strHTML = strHTML.replace(eval('/<\\/'+sTags[j]+'>/ig'), '££'+sTags[j]);
		}
				
		strHTML = strHTML.replace(/<[^>]*>/g, "");
		 
		for(j=0; j<sTags.length; j++){
			strHTML = strHTML.replace(eval('/µµ'+sTags[j]+'/g'), '<'+sTags[j]+'>');
			strHTML = strHTML.replace(eval('/££'+sTags[j]+'/g'), '</'+sTags[j]+'>');
		}
		
		if(strHTML.indexOf('<BR>') == 0){
			strHTML = strHTML.substr(4);
		}
	}
	return strHTML;
}

