function openRemote(url) {
	rmtWin=window.open(url, window.name + 'rmt', 'status=yes,menubar=yes,width=600,height=500,scrollbars=yes,resizable=yes');
	window.setTimeout("if (rmtWin) rmtWin.focus();", 200);
}

function checkEmpty(fieldObj) {
	fieldObj.siblings(".fieldInfos").remove();
	fieldObj.parent().removeClass('format');
	if ( fieldObj.val() == '' ) 
		fieldObj.parent().addClass('errored').end()
			.after("<span class='fieldInfos'>* Information obligatoire</span>");
	else fieldObj.parent().removeClass("errored");
	return (fieldObj.val() != '');
}

function checkEmail(fieldObj) {
	var t;
	if (t=checkEmpty(fieldObj)) {
		fieldObj.siblings(".fieldInfos").remove();
		if (!isEmail(fieldObj.val())) {
			fieldObj.parent().addClass('errored').addClass('format').end()
				.after("<span class='fieldInfos'>* L'adresse e-mail que vous avez renseignée ne semble pas avoir un format valide.</span>");
		}
		else fieldObj.parent().removeClass('errored').removeClass('format');
	}
	return (t && isEmail(fieldObj.val()));
}
function isEmail(val) {
	var re = new RegExp("^\\w+((-\\w+)|(\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", "gi");
	return (re.test(val) || (val==""));
}			

			
function init_createForm() {
	$("form#pDemoCreate").submit(function() {
		var alright = true;
		$(this).find("p.required input").each(function() {
			if ($(this).attr("id").toLowerCase().indexOf("email")!=-1)
				alright = alright &  checkEmail($(this));
			else 
				alright = alright &  checkEmpty($(this));
		});
		
		if ( alright ) { this.submit(); }
		else {
			$(this)
				.find(".msg").remove().end()
				.find("h2").after("<p class='msg err'>Vous n'avez pas rempli tous les champs obligatoires</p>").end()
				.find(".msg").hide().fadeIn("slow").end()
				.find(".errored:first input")[0].focus();
				
		}
		return false;
	});
}

function init_loginForm() {
	$("form#elquickLogonX").submit(function() {
		var alright = true;
		$(this).find("p.required input").each(function() {
			alright = alright &  checkEmpty($(this));
		});
		
		if ( alright ) { this.submit(); }
		else {
			$(this)
				.find(".msg").remove().end()
				.find("h2").after("<p class='msg err'>Vous n'avez pas rempli tous les champs obligatoires</p>").end()
				.find(".msg").hide().fadeIn("slow").end()
				.find(".errored:first input")[0].focus();
				
		}
		return false;
	});
}

function init_contactForm() {
	$("form#contactFormX").submit(function() {
		var alright = true;
		$(this).find("p.required input, p.required textarea").each(function() {
			if ($(this).attr("id").toLowerCase().indexOf("email")!=-1)
				alright = alright &  checkEmail($(this));
			else 
				alright = alright &  checkEmpty($(this));
		});
		
		if ( alright ) { this.submit(); }
		else {
			$(this)
				.find(".msg").remove().end()
				.find("h2").after("<p class='msg err'>Vous n'avez pas rempli tous les champs obligatoires</p>").end()
				.find(".msg").hide().fadeIn("slow").end()
				.find(".errored:first input")[0].focus();
				
		}
		return false;
	});
}


			$(document).ready(function() {
				$("body").addClass("jse");
				$("a[@rel='launchContenu']").bind("click", function() {
					openRemote(this.href); return false;
				});
				$("a[@rel='popup']").bind("click", function() {
					openRemote(this.href); return false;
				});
				
				$("form .userinput").focus(function() { $(this).addClass("focus"); });
				$("form .userinput").blur(function() { $(this).removeClass("focus"); });
				
				// apple search box
				if(!$.browser.safari) {
					// add style if not safari
					$("form.qsearch").find("input[@type='submit']").hide();
					$("form.qsearch").addClass("applesearch")
					.find("input[@type='text']")
					.before("<span class='sbox_l'></span>")
					.after("<span class='sbox_r'></span>")
					.wrap("<span class='sbox'></span>")
					;
				}
				var qsKeyWords_init = "Rechercher";
				$("form.qsearch").find("input[@type='text']").val(qsKeyWords_init);
				$("form.qsearch").find("input[@type='text']").focus(function () {
					if ($(this).val() == qsKeyWords_init) $(this).val("");
					$(this).addClass("focused");
				});
				$("form.qsearch").find("input[@type='text']").blur(function () {
					if ($(this).val() == "") $(this).val(qsKeyWords_init);
					$(this).removeClass("focused");
				});
				
				$("form.qsearch").find("input[@type='text']").focus(function () { 
					$(this).parent().parent().find(".sbox_r")
						.addClass("reset").click(function() { $(this).parent().find("input[@type='text']").val("").get(0).focus(); });
				});
				$("form.qsearch").find("input[@type='text']").blur(function () { 
					$(this).parent().parent().find(".sbox_r")
						.removeClass("reset").click(function() {  }); 
				});
			});