function check(mod,url){
	var i = mod.search.value;
	if (i == null || i == ""){
		mod.search.focus();
		mod.search.style.backgroundColor= "#FFFF91";
		alert("Inserer le texte pour la recherche.");
		return false;
	}
	else{
		mod.method = "post";
		document.mdsearch.action = ( url ? url : "/Search" );
		return true;
	}
}
function checkdate(input){
	if (input.value==""){
		return true;
	}
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/; 
	var returnval=false;
	
	if (!validformat.test(input.value)){
		alert("Invalid Date Format. Please correct and submit again.");
	}
		else{
		returnval=true;
	}
	if (returnval==false){
		input.select();
		return returnval;
	}
	
	else{
		//alert(input.value);
		//Detailed check for valid date ranges
		var dayfield=input.value.split("/")[0];
		var monthfield=input.value.split("/")[1];
		var yearfield=input.value.split("/")[2];
		var dayobj = new Date(yearfield, monthfield-1, dayfield);
	}
	returnval=false;
	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)){
		alert("Invalid Day, Month, or Year range detected. Please correct and submit again.");
	}	
	else{
		returnval=true;
	}
	if (returnval==false){
		input.select();
		return returnval;
	}
}

function checkadvancedFinance(mod,checkNum,url){
	var textestring = mod.texte.value;
	var dateStart = mod.dateStart.value;
	var dateEnd = mod.dateEnd.value;
	
	while (textestring.substring(textestring.length-1, textestring.length) == ' '){
		textestring = textestring.substring(0,textestring.length-1);
	}
	
	if (textestring==null || textestring==""){
		mod.texte.focus();
		mod.texte.style.backgroundColor= "#FFFF91";
		alert("Inserer un critere de recherche!!!!");
		return false;
	}
	else{
	if (checkdate(mod.dateStart)==false || checkdate(mod.dateEnd)==false){
		return false;
	}
		var countchk=0;
		for (i=1; i < checkNum; i++){
			var tmpid='chk'+i;
			if(document.getElementById(tmpid).checked == true){
				countchk++;
			}
		}
		//alert(countchk);
		document.formAdv.countChk.value=countchk;
	mod.method = "post";
	document.formAdv.action = ( url ? url : "/Search" );
	return true;
	}
}


function checkadvanced(mod,checkNum,url){
	var textestring = mod.texte.value;
	var auteurstring = mod.auteur.value;
	var dateStart = mod.dateStart.value;
	var dateEnd = mod.dateEnd.value;

	while (textestring.substring(textestring.length-1, textestring.length) == ' '){
		textestring = textestring.substring(0,textestring.length-1);
	}
	
	while (auteurstring.substring(auteurstring.length-1, auteurstring.length) == ' '){
		auteurstring = auteurstring.substring(0,auteurstring.length-1);
	}
	
	if ((textestring==null || textestring=="") && (auteurstring==null || auteurstring=="")){
			mod.texte.focus();
			mod.texte.style.backgroundColor= "#FFFF91";
			alert("Inserer un critere de recherche!!!!");
			return false;
	}
	
	else{
	if (checkdate(mod.dateStart)==false || checkdate(mod.dateEnd)==false){
		return false;
	}
		var countchk=0;
		for (i=1; i < checkNum; i++){
			var tmpid='chk'+i;
			if(document.getElementById(tmpid).checked == true){
				countchk++;
			}
		}
		//alert(countchk);
		document.formAdv.countChk.value=countchk;
	mod.method = "post";
	document.formAdv.action = ( url ? url : "/Search" );
	return true;
	}
}


/* Write Comment in Opinions */
function checkArea(mod,url){
	var msg = mod.content.value;
	if (msg == null || msg == ""){
		mod.content.focus();
		mod.content.style.backgroundColor= "#FFFF91";
		alert("Inserer le texte du Message!!!!");
		return false;
	}
	else{
		mod.method = "post";
		document.form.action = ( url ? url : "/Comments" );
		alert("Merci, votre commentaire a \u00E9t\u00E9 envoy\u00E9 \u00E0 la R\u00E9daction du Temps.");
		return true;
	}
}

/* Send EMail Friends */
function validate_form(mod,url){
	var sa = mod.sourceAddress.value;
	var da = mod.destAddress.value;
	var expres = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	
	if (!expres.test(sa) || !expres.test(da)){
		alert("Vous avez indiqu\u00E9 une adresse e-mail invalide.");
		if (!expres.test(sa)){
			mod.sourceAddress.focus();
			mod.sourceAddress.style.backgroundColor= "#FFFF91";
			
		}else{
			mod.destAddress.focus();
			mod.destAddress.style.backgroundColor= "#FFFF91";
		}
		return false;
	}else{
		mod.method = "post";
		document.sendEmail.action = ( url ? url : "/SendStory" );
		window.close();
		return true;
	}
}
/* Signup */
function checkSignup(mod,url){
	var nom = mod.firstname.value;
	var prenom = mod.lastname.value;
	var ville = mod.city.value;
	var email = mod.email.value;
	var login = mod.username.value;
	var password = mod.password.value;
	var password2 = mod.password2.value;

	if (nom == null || nom == ""){
		mod.firstname.focus();
		mod.firstname.style.backgroundColor= "#FFFF91";
		alert("Inserer votre Nom.");
		return false;
	}
	else if (prenom == null || prenom == ""){
		mod.lastname.focus();
		mod.lastname.style.backgroundColor= "#FFFF91";
		alert("Inserer votre Pr\u00E9Nom.");
		return false;
	}
	else if (ville == null || ville == ""){
		mod.city.focus();
		mod.city.style.backgroundColor= "#FFFF91";
		alert("Inserer votre Ville.");
		return false;
	}
	else if (password != password2){
		mod.password.focus();
		mod.password.style.backgroundColor= "#FFFF91";
		mod.password2.style.backgroundColor= "#FFFF91";
		alert("Les deux mots de passe doivent être identiques.");
		return false;
	}
	else if (checkEmail(email) == null){
		mod.email.focus();
		mod.email.style.backgroundColor= "#FFFF91";
		alert("Vous avez indiqu\u00E9 une adresse e-mail invalide");
		return false;
	}
	else if (login == null || login == ""){
		mod.username.focus();
		mod.username.style.backgroundColor= "#FFFF91";
		alert("Inserer votre Nom utilisateur.");
		return false;
	}
	else{
		mod.method = "post";
		document.mdsignup.action = ( url ? url : "/Signup" );
		return true;
	}
}
/* Contact */
function checkContact(mod,url){
	var contact = mod.contact.value;
	var nom = mod.lastname.value;
	var prenom = mod.firstname.value;
	var email = mod.email.value;
	var message = mod.message.value;
	
	if (contact == null || contact == ""){
		mod.contact.focus();
		mod.contact.style.backgroundColor= "#FFFF91";
		alert("Merci de choisir une rubrique.");
		return false;
	}
	else if (nom == null || nom == ""){
		mod.firstname.focus();
		mod.firstname.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir votre nom.");
		return false;
	}
	else if (prenom == null || prenom == ""){
		mod.lastname.focus();
		mod.lastname.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir votre prénom.");
		return false;
	}
	else if (checkEmail(email) == null){
		mod.email.focus();
		mod.email.style.backgroundColor= "#FFFF91";
		alert("Vous avez indiqu\u00E9 une adresse e-mail invalide");
		return false;
	}
	else if (message == null || message == ""){
		mod.city.focus();
		mod.city.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir un message.");
		return false;
	}
	else{
		mod.method = "post";
		document.mdcontact.action = ( url ? url : "/contact" );
		return true;
	}
}
/* UserDataCollection */
function checkUserDataCollection(mod,url){
	var nom = mod.lastname.value;
	var prenom = mod.firstname.value;
	var email = mod.email.value;
	var npa = mod.npa.value;
	var birthdate = mod.birthdate.value;
	var telephone = mod.telephone.value;	

	if (nom == null || nom == ""){
		mod.firstname.focus();
		mod.firstname.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir votre nom.");
		return false;
	}
	else if (prenom == null || prenom == ""){
		mod.lastname.focus();
		mod.lastname.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir votre prénom.");
		return false;
	}
	else if (checkEmail(email) == null){
		mod.email.focus();
		mod.email.style.backgroundColor= "#FFFF91";
		alert("Vous avez indiqu\u00E9 une adresse e-mail invalide");
		return false;
	}
	else if (npa == null || npa == ""){
		mod.npa.focus();
		mod.npa.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir un npa.");
		return false;
	}
	else if (birthdate == null || birthdate == ""){
		mod.birthdate.focus();
		mod.birthdate.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir une date de naissance.");
		return false;
	}
	else if (telephone == null || telephone == ""){
		mod.telephone.focus();
		mod.telephone.style.backgroundColor= "#FFFF91";
		alert("Merci de saisir un numéro de téléphone.");
		return false;
	}
	else{
		mod.method = "post";
		document.mdcontact.action = ( url ? url : "/formulaire" );
		return true;
	}
}
/* Check email */
function checkEmail(email) {
  var re = new RegExp('^\\S+@\\S+\\.[a-zA-Z_0-9]+$');
  return email.match(re);
}
/* Epaper Function */
function openObjEpaper (path){
	document.getElementById('textZone').src=path;
}
function Hiddiv(){
	document.getElementById('EP_hid').style.display = 'none';
}

var min=6;
var max=50;

function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}