// ----------------------------------------------------------------------------------
// Only digits in field!
// ----------------------------------------------------------------------------------
function checkKey(field, evt) {
  var keyCode = 
    document.layers ? evt.which :
    document.all ? event.keyCode :
    document.getElementById ? evt.keyCode : 0;
  //alert(keyCode);
  if ((document.all || document.getElementById) && evt.shiftKey) {
    if (keyCode == 9) return true;
	return false;
  }
  if (document.layers && evt.modifiers & event.SHIFT_MASK) {
    if (keyCode == 9) return true;
	return false;
  }
  // 0 .. 9, 0 .. 9 on right keyboard, Backspace, Tab, End, Home, Left Arrow, Right Arrow, Del button
  if ((keyCode > 47 && keyCode < 58) || (keyCode > 95 && keyCode < 106) || keyCode == 8 || keyCode == 9 || keyCode == 35 || keyCode == 36 || keyCode == 37 || keyCode == 39  || keyCode == 46) return true;
  return false;
}
//-----------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Script Anti-flash
//------------------------------------------------------------------------------------
function fixFlash(s) { document.write(s); }

//------------------------------------------------------------------------------------
// Script Notice légale
//------------------------------------------------------------------------------------
function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}

//------------------------------------------------------------------------------------
// Fonction CacheMail
//------------------------------------------------------------------------------------

function CacheMail(mail,domain) {
	this.location = 'mailto:' + mail + '@'+ domain;
	}

// a rajouter au niveau des liens mailto ---> <a href="#" onclick="CacheMail('jerome','actisens.com')">test</a>

//------------------------------------------------------------------------------------
// Fonction TestParam()
//------------------------------------------------------------------------------------

function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}

function isTel(obj) {
	if (isNaN(obj.value)==false && obj.value.length==10)  return true;
	else return false;
}

function isEmail(obj) 
{
       if (obj.value.indexOf(" ") + "" == "-1"
       && obj.value.indexOf("@") + "" != "-1"
       && (obj.value.lastIndexOf(".") > obj.value.indexOf("@"))
       && obj.value != "") return true;
       else return false;
}

function TestParam() 
{
	var Form = document.forms["FormContact"]; //forms = tous les formulaires du document
	if (Form.eNom.value == "")
		{ alert("Attention, le champ 'Nom' doit être renseigné."); Form.eNom.focus(); return false; }
	if (Form.ePrenom.value == "")
		{ alert("Attention, le champ 'Prénom' doit être renseigné."); Form.ePrenom.focus(); return false; }
	if (Form.eCodePostal.value != "" && !isCP(Form.eCodePostal))
		{ alert("Merci de renseigner correctement le champ 'Code postal'."); Form.eCodePostal.focus(); return false; }
	if (Form.eEmail.value == "" || !isEmail(Form.eEmail))
		{ alert("Merci de renseigner le champ 'Email' correctement."); Form.eEmail.focus(); return false; }
	if (Form.eTel.value == "" || (Form.eTel.value).length!=10)
		{ alert("Attention, le téléphone est nécessaire"); Form.eTel.focus(); return false; }
	/*if (Form.eDestinataire.value == "")// Optionnel
		{ alert("Merci de sélectionner un destinataire pour votre message."); Form.eDestinataire.focus(); return false; }*/
	if (Form.eMessage.value == "")
		{ alert("Attention, le champ 'Message' doit être renseigné."); Form.eMessage.focus(); return false; }
	if (Form.eCaptcha.value == "")
		{ alert("Merci de saisir les caractères indiqués par l'image"); Form.eMessage.focus(); return false; }
	
	Form.action = "Procs/psContact.asp";
	Form.submit();
}

function RefreshCaptcha() {
	var i = new Image();
	var d = new Date();
	i.src = 'Includes/modCaptcha.asp?Type=4&Dt=' + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() ;
	document.getElementById("Captcha").src =  i.src;
}


//------------------------------------------------------------------------------------
// Script Notice légale
//------------------------------------------------------------------------------------
// s est l'année de création du site.
function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}

function testEtudeChiffree() 
{
	var Form = document.forms["mail_form"]; //forms = tous les formulaires du document
		
	if (Form.champ1.value == "")
		{ alert("Attention, le champ 'Nom' doit être renseigné"); Form.champ1.focus(); return; }
	
	if (Form.champ3.value == "")
		{ alert("Attention, le champ 'Tél.' doit être renseigné"); Form.champ3.focus(); return; }
	if (Form.champ3.value != "" && !isTel(Form.champ3))
		{ alert("Merci de renseigner le champ 'Tél.' correctement"); Form.champ3.focus(); return; }
	
	if (Form.zone_email.value == "")
		{ alert("Attention, le champ 'Courriel' doit être renseigné"); Form.zone_email.focus(); return; }
	if (Form.zone_email.value != "" && !isEmail(Form.zone_email))
		{ alert("Merci de renseigner le champ 'Email' correctement"); Form.zone_email.focus(); return; }
	
	if(Form.champ7)
	{
	  if (Form.champ7.value == "0")
		  { alert("Attention, le champ 'Département de construction' doit être renseigné"); Form.champ7.focus(); return; }
	}
	
	/*if(Form.champ5)
	{
	  if (Form.champ5.value != "" && !isCP(Form.champ5))
		{ alert("Merci de renseigner le champ 'Code Postal' correctement"); Form.champ5.focus(); return; }
	}*/
		
	Form.action = "/Procs/psEtudeChiffree.asp";
	Form.submit();	
}
function verifCode(obj) {
       return (obj.value == "") || (obj.value.length == 5 && !isNaN(obj.value));
	   //si le champ est vide, je retourne vrai (parce que ca n est pas un champ obligatoire)
	   // ou si le champ a une longueur de 5 caractères et que c'est un nombre, je returne vrai
}

function TestParam(Form) 
{
	if (Form.eNom.value == "") 
		{ alert("Attention, le nom est nécessaire"); Form.eNom.focus(); return }
	if (Form.ePrenom.value == "") 
		{ alert("Attention, le prénom est nécessaire"); Form.ePrenom.focus(); return }
	if (Form.eTel.value != "" && (Form.eTel.value).length!=10)
		{ alert("Merci d'indiquer un téléphone correct"); Form.eTel.focus(); return }
	if (!isEmail(Form.eEmail))
		{ alert("Merci d'indiquer un E-mail correct"); Form.eEmail.focus(); return }
	if (Form.eCodePostal.value != "" && !verifCode(Form.eCodePostal))
		{ alert("Merci d'indiquer un code postal correct"); Form.eCodePostal.focus(); return }
	if (Form.eComment.value=="")
		{ alert("Attention, le Message est nécessaire"); Form.eComment.focus(); return }	
	Form.action = "/Procs/psContact.asp";
	Form.submit();															
}


$(function()
	{
		$(".iframe").colorbox({
			width:"370px",
			height:"190px",
			iframe:true,
			close: "Fermer la fenêtre"
			});
		$(".iframe2").colorbox({
			width:"370px",
			height:"290px",
			iframe:true,
			close: "Fermer la fenêtre"
			});
		
		if($(".zoom_promo").size() > 0)
		{
		  $(".zoom_promo").colorbox();
		}
		
		if($('#coin-slider').size() > 0)
		{
		  $('#coin-slider').coinslider({width: 300, height:100, navigation: false, delay: 5000});
		}
		
		if($('#slidervideo').size() > 0)
		{
		  $('#slidervideo').coinslider({width: 200, height:220, navigation: false, delay: 5000, effect: 'rain', transitionSpeed: 800});
		}
	}
);

function TestEnvoiReponses() 
{
	var Form = document.forms["formReponsesQuizz"];
	
	if (Form.eEmail.value == "") 
		{ alert("Merci d'indiquer votre adresse e-mail pour recevoir l'ensemble des réponses"); Form.eEmail.focus(); return }
	
	if (!isEmail(Form.eEmail))
		{ alert("Merci d'indiquer une adresse e-mail correcte"); Form.eEmail.focus(); return }
	
	Form.action = "/Procs/psEnvoiReponses.asp";
	Form.submit();															
}

function TestEnvoiAmi() 
{
	var Form = document.forms["formEnvoiAmi"];
	
	if (Form.eNom.value == "") 
		{ alert("Merci d'indiquer votre nom"); Form.eNom.focus(); return }
	
	if (Form.eNomAmi.value == "") 
		{ alert("Merci d'indiquer le nom de votre ami"); Form.eNomAmi.focus(); return }
	
	if (Form.eEmailAmi.value == "") 
		{ alert("Merci d'indiquer votre adresse e-mail pour recevoir l'ensemble des réponses"); Form.eEmailAmi.focus(); return }
	
	if (!isEmail(Form.eEmailAmi))
		{ alert("Merci d'indiquer une adresse e-mail correcte"); Form.eEmailAmi.focus(); return }
	
	Form.action = "/Procs/psEnvoiAmi.asp";
	Form.submit();															
}

function TestEnvoiVideoAmi() 
{
	var Form = document.forms["formVideoAmi"];
	
	if (Form.eNom.value == "") 
		{ alert("Merci d'indiquer votre nom"); Form.eNom.focus(); return }
	
	if (Form.eNomAmi.value == "") 
		{ alert("Merci d'indiquer le nom de votre ami"); Form.eNomAmi.focus(); return }
	
	if (Form.eEmailAmi.value == "") 
		{ alert("Merci d'indiquer votre adresse e-mail pour recevoir l'ensemble des réponses"); Form.eEmailAmi.focus(); return }
	
	if (!isEmail(Form.eEmailAmi))
		{ alert("Merci d'indiquer une adresse e-mail correcte"); Form.eEmailAmi.focus(); return }
	
	Form.action = "/Procs/psEnvoiAmi.asp";
	Form.submit();															
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

jQuery(document).ready(function(){
		// --------------------------------------------------------------------------		 
		// Parrainage	
		// --------------------------------------------------------------------------		 
				 
		// Si aucun cookie
		if ($.cookie('parrainage')==null) {

			var _bg = document.createElement('div');
				_bg.style.backgroundColor = '#000000';
				_bg.style.display = 'block';
				_bg.style.position = 'absolute';
				_bg.style.zIndex = '1000';
				_bg.style.top = 0;
				_bg.style.left = 0;
				_bg.style.opacity = '0.8';
				_bg.style.filter = 'alpha(opacity=80)';
				_bg.id = 'parrainageBg';
			
			document.body.appendChild(_bg);
			
			var _img = document.createElement('img');
				_img.src = '../Images/overlay/offres_emplois.png';
				_img.style.display = 'block';
				_img.style.position = 'absolute';
				_img.style.zIndex = '1001';
				_img.style.top = 0;
				_img.style.left = 0;
				_img.style.cursor = 'pointer';
				_img.id = 'parrainageImg';
				
			document.body.appendChild(_img);		

			resize();
			
			// On enregistre le cookie			
			$.cookie('parrainage', 'true');
	}
			
	$(window).resize(function() {
		if ($('#parrainageBg').css('display') == 'block') resize();
	});	
		
	$('#parrainageBg').click(function() {
		$(this).hide();
		$('#parrainageImg').hide();
	});
	
	$('#parrainageImg').click(function() {
		document.location = 'http://www.demeures-et-maisons-bois.com/';
	});
});

function resize() {
	var _h = $(document).height();
	var _w = $(document).width();
	
	var _bg = $('#parrainageBg');
		_bg.css('height', _h + 'px');
		_bg.css('top', 0);
		_bg.css('left', 0);
		_bg.css('width', '100%');
			
	var _h = $(window).height();
	var _w = $(window).width();
	var _l = (_w - 621) /2;
	var _t = (_h - 621) /2;
	
	var _img = $('#parrainageImg');
		_img.css('width', '621px');
		_img.css('height', '621px');
		_img.css('top', _t + 'px');
		_img.css('left', _l + 'px');
}
