// JavaScript Document

/* navigator dectection */
if((navigator.appName).indexOf("Microsoft")!=-1){
	document.cookie ='browser=IE;'					
}else if((navigator.appName).indexOf("Mozilla")!=-1 || (navigator.appName).indexOf("Netscape")!=-1){
	document.cookie ='browser=NS;'
}

/* and finally the functions */
function init() { 
	setTimeout("re()",900000);
}
function re() {
	window.location.reload();
}
function show(obj){
	document.getElementById(obj).style.display = '';
}
function hide(obj){
	document.getElementById(obj).style.display = 'none';
}
function rollover(imgRef,imgNew){
	document.getElementById(imgRef).src = imgNew;
}
function showHideRow(obj){
	//alert(obj);
	if (document.getElementById(obj).style.display == 'none'){
		document.getElementById(obj).style.display = '';
	}else{
		document.getElementById(obj).style.display = 'none';
	}
}
function hideAll(list){
	for(i=0; i < list.length; i++){
		document.getElementById(list[i]).style.display = 'none';
	}
}
function popUpWindow(url,wname,w,h){
	window.open(url,wname,"status=1,menubar=0,resizable=1,height="+h+",width="+w);
}
function changeType(obj){
	window.location = window.location + "&ctype=" + obj.value;
}
function showImg(obj,path){
	if(path != ""){
	document.getElementById(obj).style.display = 'list-item';
	document.getElementById(obj).style.listStyle = 'none';
	document.getElementById(obj).innerHTML = '<img src="'+path+'"" hspace="5" vspace="5" />';
	}
}
function warn(obj, active){
	if (active){
		document.getElementById(obj).style.border = '1px solid #849d5c';
	}else{
		document.getElementById(obj).style.border = '1px solid red';
	}
}
function getLocation(loc){
	document.location = loc;	
}

/* SPECIAL : validations */
/* exemple : 
	validate(this.form, ['title_1','title_2','title_3','title_4','active'], [regString,regString,regString,regString,regBool]);
*/

/* regExp variables */
var regNum = new RegExp(/(^\d+$)/i);
var regBool = new RegExp(/(^[01]$)/i);
var regString = new RegExp(/(^[^<>]{1,255}$)/i);
var regText = new RegExp(/(^[^<>]+$)/i);
var regMail = new RegExp(/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/i);
						
function validate(formobj, requiredfields, requiredvalues){
	for(i in requiredfields){
		reg = requiredvalues[i];
		if(formobj[requiredfields[i]].value != "" && formobj[requiredfields[i]].value.match(reg)){
			continue;
		}else{
			return errMsg(formobj[requiredfields[i]].name);
		}
	}
	formobj.submit();
}
function errMsg(field){
	switch(field){
		case "active":
			msg = 'Veuillez indiquez si le contenu doit être affiché ou non.';
			break;
		case "title_1":
		case "title_2":
		case "title_3":
		case "title_4":
			msg = 'Veuillez entrer un titre valide pour chaque langue.\n\n  Note : les caractères < et > ne sont pas permis. Utilisez plutôt des guillemets anglais (").';
			break;
		case "content_1":
		case "content_2":
		case "content_3":
		case "content_4":
			msg = 'Veuillez entrer un contenu valide pour chaque langue.\n\n Note : les caractères < et > ne sont pas permis. Utilisez plutôt des guillemets anglais (").';
			break;
		case "name":
			msg = 'Veuillez entrer un nom pour ce contenu.';
			break;
		case "nom":
			msg = 'Veuillez entrer votre nom.';
			break;
		case "email":
			msg = 'Veuillez entrer une adresse de courriel valide.';
			break;
		case "msg":
			msg = 'Veuillez entrer votre message.';
			break;
		default:
			msg = 'Veuillez remplir le formulaire correctement.';
	}
	alert(msg);
	//alert(field);
	return false;
}