﻿function isDate(dateStr,formatDateStr) {
	if (formatDateStr=='FR') {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	} else {
		var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
	}
	
    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        //alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
	    return false;
	}
	if (formatDateStr=='EN') {
		var month = matchArray[3];
		var day = matchArray[5];
		var year = matchArray[1];
	} else {
		var month = matchArray[3];
		var day = matchArray[1];
		var year = matchArray[5];
	}
	
    if (month < 1 || month > 12) { 
		// check month range
        //alert("Month must be between 1 and 12.");
        return false;
    }
    if (day < 1 || day > 31) {
        //alert("Day must be between 1 and 31.");
        return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        //alert("Month "+month+" doesn't have 31 days!")
        return false;
    }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
		    //alert("February " + year + " doesn't have " + day + " days!");
		    return false;
		}
	}
    return true; // date is valid
}

function isEntier(entierStr) {
	var valeur=entierStr;
	if (!isNaN(valeur)) {
		if (parseInt(valeur) + ''==valeur + '') {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function isNumerique(numeriqueStr) {
	var valeur=numeriqueStr;
	var re=/,/gi;
	valeur=valeur.replace(re,'.');
	for(var i=1;i<valeur.length;i++)
	{valeur=valeur.replace(String.fromCharCode(160),'');}
	if(isNaN(valeur))
	{return false;}
	else
	{return true;}
}



//Popup-Fausse popup
var win;
function affichePopup(url,titre,largeur,hauteur) {
	if (document.getElementById("headerMenu")) {
		document.getElementById("headerMenu").style.display = "none";
	}
	win = new Window({className: "alert", title: titre, width:largeur, height:hauteur, recenterAuto:false, destroyOnClose: true});
	$("overlay_modal")?$("overlay_modal").toggle():"";
	win.setAjaxContent(url, {}, true, false);
	win.show(true);
}
function fermePopup() {
	$("overlay_modal")?$("overlay_modal").hide():"";
	Dialog.closeInfo();
	win.destroy();
}

/*/
//Popup-Fausse popup
var win;
function affichePopup(url,titre,largeur,hauteur) {
	if (document.getElementById("headerMenu")) {
		document.getElementById("headerMenu").style.display = "none";
	}
	if(document.getElementById("flash_a_cacher")){
		document.getElementById("flash_a_cacher").style.display="none";
	}
	win = new Window({className: "alert", title: titre, width:largeur, height:hauteur, recenterAuto:true, destroyOnClose: true});
	$("overlay_modal")?$("overlay_modal").toggle():"";
	win.setAjaxContent(url, {}, true, false);
	win.show(true);

}
function fermePopup() {
	$("overlay_modal")?$("overlay_modal").hide():"";
	Dialog.closeInfo();
	win.destroy();
	
	if(document.getElementById("flash_a_cacher")){
		document.getElementById("flash_a_cacher").style.display="";
	}
	
	// Patch Castelis : on fait un showSelect sur tous les selects de la page
    if (Prototype.Browser.IE) {
      $$('select').each(function(element) {
        if (WindowUtilities.isDefined(element.oldVisibility)) {
          // Why?? Ask IE
          try {
            element.style.visibility = element.oldVisibility;
          } catch(e) {
            element.style.visibility = "visible";
          }
          element.oldVisibility = null;
        }
        else {
          if (element.style.visibility)
            element.style.visibility = "visible";
        }
      });
    }
}
*/

function checkEmail(mail) {
	var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	return re.test(mail);
}

function setLang(id_lang) {
	window.location.href="?page=accueil&id_lang=" + id_lang;
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function lancerSisleyColor(){		
	affichePopup('?page=contenant&url='+escape('?page=sisley_color'),"",635,455);		
}