
var oEmailForm = {
	/* [start] GUI variables : change the values of theses variables as you see fit */
	MSG_fillRequiredFields : "Please fill in all required fields.\n"+"Tous les champs sont requis.", 
	MSG_badEmail : "Please provide a valid email address.\n"+"Adresse de courriel invalide.", 
	STYLE_FieldFilledColor : "#ffffff",
	STYLE_FieldMissingColor : "#ff0000",
	/* [end] GUI variables*/
	
	elem : function(s){
		return document.getElementById(s);
	},
	
	checkEmail : function (email){
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email)){
			return true;
		}else{
			return false;
		}
	},
	clean : function(i){

	/// PREVENT cross-site-scripting
	var v = i.value;
			//alert(v);
			if (v!=undefined){
				v = v.replace(/javascript/gi,'');
				v = v.replace(/java/gi,'');
				v = v.replace(/script/gi,'');
				v = v.replace(/document./gi,'');
				v = v.replace(/document ./gi,'');
				v = v.replace(/js/gi,'');
				v = v.replace(/&{/gi,'');
				v = v.replace(/& {/gi,'');
				v = v.replace(/</gi,'');
				v = v.replace(/>/gi,'');
				v = v.replace(/%/gi,'');
				i.value = v;
			}

	},
	validate : function (oForm){
		/** 
		 * Check to see that all required fields arefilled
		 * required fields should have the attribute alt="*"
		 */
		isRequiredMissing = false;
		for(i=oForm.elements.length-1; i>=0 ; i--){
			var _elem = oForm.elements[i];
			
			 if(_elem.type!="hidden" && _elem.type!="submit" && _elem.type!="reset" && _elem.type!="select-one"){
				this.clean(_elem);
			 }
			
			if( typeof(_elem.alt)!="undefined"){
				if    (_elem.alt=="required"){
					if  ( (_elem.value=="")||(_elem.value==" ") ){
						//alert(_elem.name)
						_elem.style.backgroundColor = this.STYLE_FieldMissingColor;
						_elem.focus();
						isRequiredMissing = true;
					}else{
						 //alert(_elem.name + "filled")
						_elem.style.backgroundColor = this.STYLE_FieldFilledColor;
					}
				}
			}
		}
		
		/// alert errors if necessary
		if (isRequiredMissing){
			alert(this.MSG_fillRequiredFields);
		}else if( this.checkEmail(oForm.email.value) == false){
			alert(this.MSG_badEmail);
			oForm.email.style.backgroundColor = this.STYLE_FieldMissingColor;
			oForm.email.focus();
		}
		/// submit form if all is ok
		else{
			return true;
		}
		
		return false;
	}
};

function submitNewsletterForm(_form){
	/**** using a popup */
	/*
		if(oEmailForm.validate(_form)){
			var url = "test.html";
			/// NOTE: the <form> tag has the attribute target="newsletterwinpopup" and method="post" so that data is sent via post
			var newwindow = window.open(url,"newsletterwinpopup",'height=200,width=150');
			if (window.focus) {newwindow.focus()}
			return true; /// submit the form
		}
		return false;/// there is something wrong
	*/
	
	/**** using an iframe */
		if(oEmailForm.validate(_form)){
			var url = "";
			var postdata="";
			 for (i=0;i<_form.elements.length;i++){
				postdata += _form[i].name + "=" + _form[i].value;
				if (i != _form.elements.length-1)postdata += "&";
			 }
			document.getElementById("NewletterSubmitFrame").src = "/lib-custom/php/email.newslettersignup.php?"+postdata;
		}
		return false;
};