function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/**
 * Automated footer height script
 * @version 1.0
 * @autor ***
 */
function autoHeight() {

    try {

        var wrap_footer_height = document.getElementById('wrap-footer').offsetHeight;
        var container_height = document.getElementById('container').offsetHeight;
        var window_height = getWindowHeight();

        if ((window_height - container_height - wrap_footer_height) > 0){
            document.getElementById('push').style.height   = (window_height - container_height - wrap_footer_height) + "px";
        } else {
            document.getElementById('push').style.height   = (wrap_footer_height) + "px";
        }

        document.getElementById('fwrap1').style.height = wrap_footer_height + "px";
        document.getElementById('fwrap2').style.height = wrap_footer_height + "px";
        document.getElementById('fwrap3').style.height = wrap_footer_height + "px";
        document.getElementById('container').style.marginBottom = (0 - wrap_footer_height) + "px";

  
        container_height = document.getElementById('container').offsetHeight;
        document.getElementById('bg1').style.height = container_height + "px";
        document.getElementById('bg2').style.height = container_height + "px";
        document.getElementById('bg3').style.height = container_height + "px";


    }
    catch (e) {
    }
    finally {
    }
};

/**
 * Anti-spam function
 * @version 1.0
 */

var mails = new Array();
mails[0] = "con"+"tac"+"t@"+"lep"+"ailleenq"+"ueu"+"e-fl"+"euri"+"ste"+"."+"com";
mails[1] = "";

function changeToMail(id,i,title){
    if (!title) title = "Envoyez-nous un e-mail";
    if (document.getElementById(id)) {
        document.getElementById(id).innerHTML = "<a href='" + "mai" + "lto:" + mails[i] + "' title='" + title + "'>" + mails[i] + "</a>";
    }
}
                   
function changeToMail1(id,i,title){
    if (!title) title = "Envoyez-nous un e-mail";
    if (document.getElementById(id)) {
        document.getElementById(id).setAttribute("href", "mailto:" + mails[i]);
    }
}

var xmlHttp;
var WindowPopUp;

function refreshCaptcha(id){
    if ( jQuery("#"+id) )
        jQuery("#"+id).attr( "src", jQuery("#"+id).attr( "src" )+"?x=" + Math.random() );
}


function initAjax() {
try
		{
		xmlHttp=new XMLHttpRequest();
		}
catch (e)
	{
	try
	{
		xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
		{
			try
				{
					xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
				}
			catch (e)
				{
					return false;
				}
		}
	}
return true;
}



function checkEmail(txtEmail)
{
	strMail = txtEmail.replace(/ /g,"");
		regex = 
/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (regex.test(strMail)) {
			return true;
	}	else {
			return false;
	}
}

function isFloat(objText) {
	var floatPoint = false;
		if (objText.charAt(0) == "." || objText.charAt(0) == ",")
		return false;
		for (i=0; i < objText.length; i++) {
			if (!isDigit(objText.charAt(i))) {
			if (!floatPoint && (objText.charAt(i) == "." || objText.charAt(i) == ","))
			floatPoint = true;
			else
			return false;
			}
		}
		return true;
}

function checkFirstLetter(strString) {
		letter = strString.charAt(0);
		switch (letter) {
				case "e":
				case "a":
				case "i":
				case "o":
				case "u":
				case "é":
					return true;
				break;
				default:
					return false;
				break;
		}
}


function isDigit (c) {
	return ((c >= "0") && (c <= "9"));
}

function doResetById(formId) {
	form = document.getElementById(formId);
	form.reset();
}


function isNumber(param) {
	strLocalString = param.replace(/ /g, "");
	for (t = 0; t < strLocalString.length; t++) {
		if (!isDigit(strLocalString.charAt(t))) {
			return false;
		}
	}
	return true;
}



function doFormSubmit(objForm, strFormTarget, strFormAction) {
/*
attributes will be read fron id value
your id should be of the form id="x/y/z", if not then the corresponding element won't be checked

where:
  x = "mandatory"(if the lement is mandatory ) or any other string if you do not want that element to be mandatory(try to use "notmandatory"..estetics)
  y = the element type  = email, checkbox, text, number, select, password
  z = an error message to be displayed if the validation process for that field has failed

copy/paste this code into a "button" tag to use for submitting a form:
 -=  onClick="doFormSubmit(this.form)"  =-
*/

	arrValidation = Array();
  	arrRejected = Array();
    var arrVisited = new Array();
	txtErr = "";
	strTmp = "";
	arrElements = objForm.elements;
	for(i=0;i<arrElements.length;i++) {
	  obj = arrElements[i];
	  if(jQuery.inArray(obj.name, arrVisited) != -1) continue;

	  arrVisited.push(obj.name);

      arrObjOptions = obj.id.split("---");
      if ((arrObjOptions.length == 3)) {

        if (arrObjOptions[0] == "mandatory")
          strTmp = validateObjectByType(obj, arrObjOptions[1], arrObjOptions[2].replace(/_/g," "), false);
        else
          strTmp = validateObjectByType(obj, arrObjOptions[1], arrObjOptions[2].replace(/_/g," "), true);

    	if(strTmp != "") {
    	    txtErr += strTmp;
    	    arrRejected[arrRejected.length] = obj;
        }
      }
  }

   if((objForm.elements["capa"] != null && (document.getElementById("capa").value.replace(/ /g,"") == ""))){
				txtErr += "Vous devez remplir le code de sécurité !\r\n";

             arrRejected[arrRejected.length] = objForm.elements["capa"];
	}
	if(txtErr != "") {

		jAlert(txtErr, "Erreurs");
	 	//arrRejected[0].focus();
	} else {
        if(strFormTarget.replace(/ /g,"") != "")
				objForm.setAttribute("target",strFormTarget.replace(/ /g,""));
		if(strFormAction.replace(/ /g,"") != "")
				objForm.setAttribute("action",strFormAction.replace(/ /g,""));
		objForm.submit();
	}


}


function validateObjectByType(obj, strType, strIdent, bTypeOnly) {
		bErr = false;
		errType = -1;
		strErrorMsg = "";

    		if(!bTypeOnly) {
    			objVal = obj.value;
    			if(objVal.replace(/ /g,"") == "") {
    					bErr = true;
    					errType = 0;
    			}
		    }

			if(strType == "email") {
					objVal = obj.value.replace(/ /g,"");
					if( !bTypeOnly || objVal != "") {
             if(objVal == "") {
              errType = 0;
             } else if(!checkEmail(objVal)) {
									errType = 1;
							}
					}
			} else if(strType == "text")  {
					objVal = obj.value;

					if(objVal.replace(/ /g,"") == "") {
					  if (!bTypeOnly)
							errType = 0;
					}
			} else if(strType == "checkbox" || strType == "radio") {
				   //	if(!obj.checked) {

                   if(!bTypeOnly) {
				   	if(typeof(jQuery("input[name='"+obj.name+"']:"+strType+":checked").val()) == 'undefined') {
							errType = 0;
					}
                   }
			} else if(strType == "select")  {
					objVal = obj.value;
					if(objVal.replace(/ /g,"") == "" || parseInt(objVal.replace(/ /g,"")) == 0) {
							errType = 1;
					}
			} else if(strType == "number") {
					objVal = obj.value;
          if(!bTypeOnly) {
             if(objVal == "") {
              errType = 0;
             } else 	if(!isNumber(objVal)) {
   						errType = 1;
   					}
					}

          if(bTypeOnly) {
   					if(!isNumber(objVal)) {
   						errType = 1;
   					}
          }
			} else if(strType == "password")  {
					objVal = obj.value;
					objID = obj.getAttribute("id") + "2";
					if(!document.getElementById(objID)) {
							errType = 3;
					} else if((objVal.replace(/ /g,"") == "") || (document.getElementById(objID).value.replace(/ /g,"") == "") ){
							errType = 0;
					} else if (document.getElementById(objID).value.replace(/ /g,"") != objVal.replace(/ /g,"")) {
							errType = 2;
					}
			}



		if(errType != -1) {
			switch(errType) {
					case 0:
							strErrorMsg = "Vous devez saisir votre " + strIdent + " dans le formulaire !\r\n";

					break;
					case 1:
							if(checkFirstLetter(strIdent)) {
								strErrorMsg = "L'"+strIdent;
							} else {
								strErrorMsg = "Le " + strIdent;
							}
								strErrorMsg += " que vous avez introduit n'est pas valide !\r\n";
					break;
					case 2:
								strErrorMsg = "Les mots de passe introduits ne correspondent pas\r\n";
					break;
					case 3:
								strErrorMsg = "Le formulaire est invalide\r\n";
					break;

			}
			return strErrorMsg;
		}  else {
			return "";
		}
}



function makeHttpRequest(scriptpath,urlmethod) {
		if(!initAjax()) {
				alert('Votre navigateur ne supporte pas AJAX!');
				return false;
		}
		strString = "";
		xmlHttp.open(urlmethod,scriptpath,true);
		xmlHttp.onreadystatechange = function() {
				if(xmlHttp.readyState == 4) {
						if(xmlHttp.status == 200) {
							strString = xmlHttp.responseText.toString();
						} else {
							strString = "Page: " + scriptpath + " - " + xmlHttp.status + ": " + xmlHttp.statusText.toString();
						}
							
				} else {
							//parent.document.getElementById("divContact").innerHTML = "<strong>Envoi du message</strong>";
				}
				processResult(strString, xmlHttp.readyState);
		}
    xmlHttp.send(null);
}
function parseFloatCustom(strVal,nDecimals) {
    divider = Math.pow(10,nDecimals);
    subject = parseFloat(strVal.replace(/,/g,"."));
    if (!isNaN(subject)) {
        result = Math.round(subject * divider)/divider;
        return result;
    } else {
        return subject;
    }
}

function AjaxExecutePost(strFunction, strArgs, strReturnFunction){	
    jQuery.post("request.php", {strFunction: strFunction, strArgs: unescape(strArgs)}, function(data){
        data = jQuery.trim(data);
	    eval(strReturnFunction + "(data);");
	});
}
function ControlExists(strObject){
	return ((document.getElementById(strObject) != null) && (document.getElementById(strObject) != "undefined"));
}
/*
function doLoginMonCompte(){
	var strParm = "'"+escape(jQuery("#m_loginEmail").val())+"'";
    strParm += ",'"+escape(jQuery("#m_loginPwd").val())+"'";
    AjaxExecutePost("loginUser", escape(strParm), "afterLogin");
}
function afterLogin(strRes){
	if (strRes == 'ERROR')
		alert('Utilisateur ou mot de passe invalide.');
	else{
		eval ("objRES="+strRes+";");
		jQuery("#p_logedInName").html(objRES.client_firstname+" "+objRES.client_lastname);
		jQuery("#bottom-header").fadeOut("100", function() {
		    jQuery("#bottom-header1").fadeIn();
	    });
	}
}
*/
function unsetCart(){
	AjaxExecutePost("unsetCart", "", "afterUnsetCart");
}
function afterUnsetCart(r){
    document.location = document.location;
}

function createCookie(name,value,days) {
  if (days) {
  	var date = new Date();
  	date.setTime(date.getTime()+(days*24*60*60*1000));
  	var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
String.prototype.tcreplace = stringReplace;

function stringReplace(findText, replaceText) {   
  var originalString = new String(this);

  var pos = 0;
  var len = findText.length;
  pos = originalString.indexOf(findText);
  while (pos != -1) {
    preString = originalString.substring(0, pos);
    postString = originalString.substring(pos + len,originalString.length);
    originalString = preString + replaceText + postString;
    pos = originalString.indexOf(findText);
  }
  return originalString;
}


function rewriteUrl(url){
	url = url.tcreplace("/","");		
	url = url.tcreplace("-", "+");
	url = url.tcreplace(" ", "+");
	url = url.tcreplace("&#039","");
	url = url.tcreplace("\"", "");
	url = url.tcreplace("@", "");
	url = url.tcreplace("]", "");
	url = url.tcreplace("[", "");
	url = url.tcreplace("?", "");
	url = url.tcreplace("&", "");
	url = url.tcreplace("!", "");
	url = url.tcreplace("#", "");
	url = url.tcreplace("&amp;", "et");
	url = url.tcreplace("&", "et");
	url = url.tcreplace(".", "");	
	url = url.tcreplace(",", "");
	url = url.tcreplace("(", "");
	url = url.tcreplace(")", "");
	url = url.tcreplace("{", "");
	url = url.tcreplace("}", "");
	url = url.tcreplace("é","e");
	url = url.tcreplace("è","e");
	url = url.tcreplace("ê","e");
	url = url.tcreplace("ë","e");
	url = url.tcreplace("É","E");
	url = url.tcreplace("È","E");
	url = url.tcreplace("Ê","E");
	url = url.tcreplace("Ë","E");
	url = url.tcreplace("à","a");
	url = url.tcreplace("â","a");
	url = url.tcreplace("ä","a");
	url = url.tcreplace("À","A");
	url = url.tcreplace("Â","A");
	url = url.tcreplace("Ä","A");
	url = url.tcreplace("î","i");
	url = url.tcreplace("ï","i");
	url = url.tcreplace("Î","I");
	url = url.tcreplace("Ï","I");
	url = url.tcreplace("ô","o");
	url = url.tcreplace("ö","o");
	url = url.tcreplace("Ô","O");
	url = url.tcreplace("Ö","O");
	url = url.tcreplace("ç","c");
	url = url.tcreplace("Ç","C");
	url = url.tcreplace("û","u");
	url = url.tcreplace("ü","u");
	url = url.tcreplace("Û","U");
	url = url.tcreplace("Ü","U");
	url = url.tcreplace("~","+");
	url = url.tcreplace(";","+");
	url = url.tcreplace("\/","+");
	url = url.tcreplace("'","+");
	url = url.tcreplace(":","+");
	url = url.tcreplace("%","+");
	url = url.tcreplace("^","+");
	url = url.tcreplace("€","+");
	url = url.tcreplace("$","+");
	url = url.tcreplace("*","+");
	url = url.tcreplace("’","+");	
	return url;
}
