/// #################################
///    common.js
/// #################################
/// -------+----------+-----------+---------------+-----------------------------------
/// Version|Date      |Developper |Action         |Description
/// -------+----------+-----------+---------------+-----------------------------------
/// R1.0   |08.03.2001|Marc       |Creation       |
/// R1.1   |18.02.2004|Daniel     |Ajout	      |Ajout de la fonction MM_openBrWindow

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,'',features);
}



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 left = 0;
	var top = 0;
	if (!nocenter) {
		left = (screen.width-w)/2;
		top = (screen.height-h)/2;
 	}
	var Win = open(url, '_pop', 'resizable=no,scrollbars='+scroll+',toolbar=no,status=no,menubar=0,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes,left='+left+',top='+top );
	Win.blur();
	Win.focus();
/*	if (!nocenter) {
		onError = null;
 		Win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
 	}*/
}

function openPopupName(url, name, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var left = 0;
	var top = 0;
	if (!nocenter) {
		left = (screen.width-w)/2;
		top = (screen.height-h)/2;
 	}
	var Win = open(url, '', 'resizable=no,scrollbars='+scroll+',toolbar=no,status=no,menubar=0,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes,left='+left+',top='+top );
	Win.blur();
	Win.focus();

}

function openPopup5(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var Win = open(url, '5', '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 openPopup1(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
	var Win = open(url, '_pop', 'resizable=yes,scrollbars='+scroll+',toolbar=no,status=no,menubar=yes,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 OpenResizablePopup(url,name, width,height) {
	w = (width) ? width : '800';
	h = (height) ? height : '600';

	var win = window.open(url, name,"toolbar=no,scrollbars=yes,status=yes,menubar=no,resizable =yes,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	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 ShowContent(url) {
	if(top.frames['frmContent'])
		top.frames['frmContent'].location.href = url;
	else
		parent.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) {
	old_url = document.forms[frm].action;
	old_target = document.forms[frm].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();
	document.forms[frm].action = old_url;
	document.forms[frm].target = old_target;
}

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 AddToBasket(){
	document.forms['frmObjectToPanier'].submit();
}

function stripFormatedHTML(strHTML){
	return strHTML.replace(/<\S[^><]*>/g, "")
}


	function ExportCmdBroch(date_debut, date_fin, export_type, id_marche, zz1) {
	
			//alert(zz1);
			openPopup1('./export.asp?export=' + export_type + '&ID_MARCHE=' + id_marche + '&datedebut=' + date_debut +'&datefin=' + date_fin + '&z1='+zz1, 800, 600, true, 1);
	}


  function showHideLink(){
  
   var permaText = getObject("PermaLinkText");
  
    var permaDiv = getObject("PermalinkDiv");
      if(permaDiv.style.display == "none"){
        permaDiv.style.display = "block";                       
      }
      else{
        permaDiv.style.display = "none";
      }
  }
  
     
  
  	function getObject(objectId) {
		if (document.getElementById) return document.getElementById(objectId);
		else {
			if (document.layers) return document.layers[objectId];
			else{if (document.all) return document.all(objectId);}}}