// ############################################################
// <SCRIPT>
// Javascript Library for FlexWeb 2
// ID-3 Technologies inc. 2003
// ############################################################

// ============================================================
// PopupWindow
// ============================================================
function gf_PopUpWindow(URL, WindowName, WindowWidth, WindowHeight) {
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open(URL,WindowName,"scrollbars=no,resizable=yes,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
    //return(popupwin);
}
function gf_PopUpWindowScroll(URL, WindowName, WindowWidth, WindowHeight) {
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open(URL,WindowName,"scrollbars=yes,resizable=yes,directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth )
    popupwin.focus();
    //return(popupwin);
}

function gf_PopUpModalWindow(URL,WindowWidth, WindowHeight) {	
	sReturnValue = window.showModalDialog(URL,'',"help:no;scroll:no;resizable:yes;center:yes;status:no;dialogHeight:" + WindowHeight + "px;dialogWidth:" + WindowWidth + "px")
    return(sReturnValue);
}

function gf_PopUpWindowExtra(URL, WindowName, WindowWidth, WindowHeight,sExtraAttributes) {
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	
	popupwin = window.open(URL,WindowName,"directories=no,menubar=no,screenx=" + PosX + ",screeny=" + PosY + ",left=" + PosX + ",top=" + PosY + ",status=no,titlebar=yes,toolbar=no,height=" + WindowHeight + ",width=" + WindowWidth + "," + sExtraAttributes)
    popupwin.focus();
    return(popupwin);
}



// ############################################################
// Edition Forms
// ############################################################
function gf_OpenUsersForm(sID){
	gf_PopUpWindow("Users_e.asp?PK=" + sID,"UsersForm",400,220);
}
function gf_OpenMagasinsForm(sID){
	gf_PopUpWindow("Magasins_e.asp?PK=" + sID,"MagasinsForm",500,320);
}
function gf_ShowComment(sID){
	gf_PopUpWindowScroll("commentaire.asp?PK=" + sID,"CommentForm",500,320);
}

// ############################################################
// Autre fonctions
// ############################################################
function ID3_FormatAsURL(oField) {
	var sString;

	sString = oField.value;
	sString = sString.replace(/ /gi,'');
	if (sString.length > 0) {
		if (sString.length > 5 && sString.indexOf('.') > 0) {
			if (sString.substr(0,7) != 'http://' && sString.substr(0,8) != 'https://') {
				sString = 'http://' + sString
				}
			}
		else {
			sString = '';
			alert("Ce champ doit contenir une adresse URL valide");
			}
		}
	oField.value = sString;
	}
	
// ##############################################################
// ############COCHER ET DECOCHER ELS CASES A COCHER ############
// ##############################################################


  function checkAll(pForm) {
 for (i=0, n=pForm.elements.length; i<n; i++){
   var objName = pForm.elements[i].name;
   var objType = pForm.elements[i].type;
   if (objType = "checkbox"){
     box = eval(pForm.elements[i]);
     if (box.checked == false) box.checked = true;
   }
 }
}

function unCheckAll(pForm) {
 for (i=0, n=pForm.elements.length; i<n; i++){
   var objName = pForm.elements[i].name;
   var objType = pForm.elements[i].type;
   if (objType = "checkbox"){
     box = eval(pForm.elements[i]);
     if (box.checked == true) box.checked = false;
   }
 }
}
