// ====================================================
// (c) 2000 Concepto enr.
// 
// Déclaration des fonctions JavaScript globales à 
// l'application
//====================================================

// -------------------------------------------------
// Ouvre une fenêtre
// -------------------------------------------------

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=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);
	}
	

// -------------------------------------------------
// S'assure qu'un champ n'est pas vide
// -------------------------------------------------

function gf_CheckIfEmpty( sData, sDescription ) {
	if (sData.length < 1) {
		alert("Le champ «" + sDescription + "» est obligatoire.")
		return(false)
		}
	return(true)
	}

// -------------------------------------------------
//	14-fev-2002
//	BenoitAlary
//  S'assure qu'un champ est de type numérique
// -------------------------------------------------
function gf_CheckIfNumeric( sDataATester, sDescription ) {
	var sData = sDataATester
	
	 sData = sData.replace(",", "." )

	if((String(parseFloat(sData)).length != sData.length) && sData.length != 0 )
	{
		alert( "Le champ «" + sDescription + "» doit être numérique." )//+ "\n" + String(parseFloat(sData)) + " = " + String(parseFloat(sData)).length + "|\n" + sData + " = " + sData.length)
		return(false)
	}

	return(true)
	}

// -------------------------------------------------
//	22-fev-2002
//	BenoitAlary
//  Fonction "cut-and-pasté" ( et modifier ) du site :
//	http://javascript.internet.com/forms/currency-format.html
//
//	qui sert à générer l'affichage d'un chiffre en format "money"
//
// -------------------------------------------------
function gf_FormatCurrency(num) {
	
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	return (((sign)?'':'-') + num + '.' + cents + " $");
}


// -------------------------------------------------
// Formate un champ contenant un numéro de téléphone
// -------------------------------------------------

function gf_FormatAsPhoneNumber(oField) {
	var sString;

	sString = oField.value;
	sString = sString.replace(/\D/gi,'');
	sString = sString.replace(/ /gi,'');
	if (sString.length > 0) {
		switch (sString.length) {
			case 7 :
				sString = (sString.substr(0,3) + '-' + sString.substr(3,4));
				break;
			case 10 :
				sString = ('(' + sString.substr(0,3) + ') ' + sString.substr(3,3) + '-' + sString.substr(6,4));
				break;
			case 11 : case 12 : case 13	: case 14 : case 15 :
				sString = ('(' + sString.substr(0,3) + ') ' + sString.substr(3,3) + '-' + sString.substr(6,4) + ' ext.' + sString.substr(10,4));
				break;
			default :
				sString = '';
				alert("Ce champ doit contenir un numéro de téléphone valide");
			}
		}
	oField.value = sString;
	}


// -------------------------------------------------
// Formate un champ contenant une adresse web
// -------------------------------------------------

function gf_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;
	}




// -------------------------------------------------
// Formate un champ contenant une adresse email
// -------------------------------------------------

function gf_FormatAsEmail(oField) {
	var sString;

	sString = oField.value;
	sString = sString.replace(/ /gi,'');
	if (sString.length > 0) {
		if (!(sString.length > 5 && sString.indexOf('@') > 0 && sString.lastIndexOf('.') > 0 && (sString.indexOf('@') < sString.lastIndexOf('.')))) {
			sString = '';
			alert("Ce champ doit contenir une adresse de courriel valide");
			}
		}
	oField.value = sString;
	}


// -------------------------------------------------
// Ouvre les differentes popups d'edition
// -------------------------------------------------

function gf_UserForm( ID ) {
	gf_PopUpWindow( "users_e.asp?PK=" + ID, "UserForm", 600, 280 );
	}
	


	
function gf_faqForm( ID ) {
	gf_PopUpWindow( "faq_e.asp?PK=" + ID, "FAQForm", 600, 300 );
	}

function gf_fournisseurForm( ID ) {
	gf_PopUpWindow( "fournisseur_e.asp?PK=" + ID, "FournisseurForm", 600, 350 );
	}

function gf_lienForm( ID ) {
	gf_PopUpWindow( "lien_e.asp?PK=" + ID, "LienForm", 600, 280 );
	}
	
function gf_clientForm( ID ) {
	gf_PopUpWindow( "client_e.asp?PK=" + ID, "ClientForm", 440, 440 );
	}
	
function gf_liste_prixForm( ID ) {
	gf_PopUpWindow( "liste_prix_e.asp?PK=" + ID, "Liste_PrixForm", 600, 280 );
	}
	
function gf_manufacturierForm( ID ) {
	gf_PopUpWindow( "manufacturier_e.asp?PK=" + ID, "ManufacturierForm", 600, 280 );
	}
	
function gf_pieceForm( ID ) {
	gf_PopUpWindow( "piece_e.asp?PK=" + ID, "PieceForm", 600, 525 );
	}
	
function gf_soumissionForm( ID ) {
	gf_PopUpWindow( "soumission_e.asp?PK=" + ID, "SoumissionForm", 760, 500 );
	}
	
function gf_soumissionDeleteForm( ID ) {
	gf_PopUpWindow( "soumission_del.asp?PK=" + ID, "SoumissionDeleteForm", 450, 250 );
	}
	
function gf_sous_typeForm( ID ) {
	gf_PopUpWindow( "sous_type_e.asp?PK=" + ID, "Sous_TypeForm", 600, 280 );
	}
	
function gf_systemeForm( ID ) {
	gf_PopUpWindow( "systeme_e.asp?PK=" + ID, "SystemeForm", 760, 550 );
	}
	
function gf_typeForm( ID ) {
	gf_PopUpWindow( "type_e.asp?PK=" + ID, "TypeForm", 600, 280 );
	}
	
function gf_h_ouvertureForm( ID ) {
	gf_PopUpWindow( "H_Ouverture_e.asp?PK=" + ID, "TypeForm", 600, 420 );
	}
	
	
//------------------------------------------------------------------
	
// -------------------------------------------------
// Ouvre une boite d'assitant de création de code HTML
// -------------------------------------------------
function gf_Id3HtmlEdit(FieldName) {

	var popupwin
	var PosX
	var PosY
	var Texte
	var WindowWidth
	var WindowHeight

	WindowWidth = 485
	WindowHeight = 315
	
	PosX = Math.round(screen.availWidth / 2) - (WindowWidth / 2) 
	PosY = Math.round(screen.availHeight / 2) - (WindowHeight / 2) - 20
	Texte = eval("document." + FieldName + ".value")
	Texte = escape(Texte)
	
	popupwin = window.open("inc/id3htmledit/HtmlEditor.asp?FieldName="+FieldName+"&CreationHTML="+Texte,"ID3HtmlEdit","scrollbars=no,resizable=no,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);
	}
	
	
// --------------------------------------------------------
// Gère les images

function gf_PictureAdd(NomImage){
	
	if (lf_Valide()){
		gf_PopUpWindow("Picture_add.asp?ImageNom=" + NomImage,"PictureAdd",400, 138 );
	}
}

function gf_PictureDelete(NomImage,sPK){
	gf_PopUpWindow("Picture_del.asp?ImageNom=" + NomImage + "&sPK=" + sPK,"PictureDel",400, 85 );
}

function gf_PictureReplace(NomImage,sPK){
	gf_PopUpWindow("Picture_replace.asp?ImageNom=" + NomImage + "&sPK=" + sPK,"PictureRep",400, 138 );
}

