/// #################################
///    common.js
/// #################################
/// -------+----------+-----------+---------------+-----------------------------------
/// Version|Date      |Developper |Action         |Description
/// -------+----------+-----------+---------------+-----------------------------------
/// R1.0   |08.03.2001|Marc       |Creation       |
/// R1.1   |21.12.2003|DH	  |Ajout fct OpenWIn

function openPopupMenu(url, w, h, nocenter, withscroll) {
	var scroll = (withscroll==1)?'yes':'no';
 	w = (w) ? w : '800';
	h = (h) ? h : '600';

	var win = window.open(url,"_print","toolbar=no,scrollbars="+scroll+",status=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	if (!nocenter) {
 		win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
 	}
}

function OpenWin(strForm) {
//var win = window.open(strForm,"page externe","toolbar=yes,status=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
var win = window.open(strForm);
}

function OpenWin(strForm) {
//var win = window.open(strForm,"page externe","toolbar=yes,status=yes,menubar=yes,fullscreen=no,height="+h+",width="+w);
var win = window.open(strForm);
}

//Ouvertutre d'une fenêtre en popup

function openPopupCenter(url, w, h,nom,pos) {

            var Win;

            Win = window.open(url, nom, 'resizable=yes,scrollbars=yes,toolbar=no,status=yes,menubar=no,fullscreen=no,height=' + h + ',width=' + w + ',alwaysRaised=yes' );
            if (pos=="center") {
                        Win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2);
            } else if (pos=="topleft") {
                        Win.moveTo(0,0);
            } else if (pos=="topright") {
                        Win.moveTo((top.screen.width-w),0);
            } else if (pos=="bottomleft") {
                        Win.moveTo((top.screen.height-h),0);
            } else if (pos=="bottomright") {
                        Win.moveTo((top.screen.width-w),(top.screen.height-h));
            }
            Win.focus();

}


function OpenForm(strForm,width,height) {
	w = (width) ? width : '800';
	h = (height) ? height : '600';

	var win = window.open(strForm,"","toolbar=no,status=yes,menubar=no,fullscreen=no,height="+h+",width="+w);
  	onerror = null;
 	win.focus();
 	win.moveTo((top.screen.width-w)/2,(top.screen.height-h)/2)
}

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 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;
		} /*else {
				alert("Aucune sélection");
		}*/
	}
//	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 = sChaineId.substr(0, sChaineId.length-2);
	}
}


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) {
	document.forms[frm].elements[name_action].value = mode_action;
	document.forms[frm].submit();
}
*/
function IsChecked(frmName){
	i = 0;
	bChecked = false;	
	while (i != document.forms[frmName].length ){	
		if (document.forms[frmName].elements[i].checked){
			bChecked = true;
			break
		}
		i++;
	}
	return bChecked;
}

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 submitForDel(frm,name_action,mode_action, url, target, hidden_field, hidden_value) {
	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].elements['RecordToDel'].value = hidden_value;
	document.forms[frm].submit();
}


function submitForAdd(frm,name_action,mode_action, url, target, hidden_field, hidden_value) {
	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].elements['RecordToAdd'].value = hidden_value;
	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).children[0].outerHTML = '';
	}
}

function DisplayTag2(bChecked, sTag1,sTag2){
	if (bChecked) {
		document.all.item(sTag1).all.item(sTag2).innerHTML = document.all("id_" + sTag2).innerHTML;
	} else {
		document.all.item(sTag1).all.item(sTag2).children[0].outerHTML = '';
	}
}


function Recherche(sLettre){
	document.forms['frmRecherche'].elements['LETTRE'].value = sLettre;
	document.forms['frmRecherche'].submit();
}


function AjoutFavo() {
	if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite("http://www.citoyens-justice.fr/adherents/default.asp","Citoyens et Justice - espace adhérents" );
	} else {
		alert("Cette fonction n'est proposée que par Internet Explorer 4+")
	}
}

function expandIt(whichEl){
    whichEl.style.display = (whichEl.style.display == "none" ) ? "block" : "none";
}

