///////////////////////
// Pop-up a new window, given its URL
function popup(url,name){
    window.open(url,name,config='height=500,width=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
}

/*
function validatePassword() {
	if (document.getElementById("password1").value == document.getElementById("password2").value) {
		return true;
	} else {
		alert("Les mots de passes ne sont pas identiques")
		return false;
	}
}*/

function readyForPassword() {
    //var addr = document.getElementById('password');
    //addr.value = '';
    if(document.all){
        document.getElementById('text_password').style.setAttribute('cssText','display:none;');
        document.getElementById('crypted_password').style.setAttribute('cssText','color:#333333;border:1px solid #d4d4d4;margin-top:5px;width:180px;');
    }
    else{
        document.getElementById('text_password').setAttribute('style','display:none;');
        document.getElementById('crypted_password').setAttribute('style','color:#333333;border:1px solid #d4d4d4;margin-top:5px;width:180px;');
    }

}

function checkEmail(id) {
    var addr = document.getElementById(id).value;

    var place = addr.indexOf("@",1);
    var point = addr.indexOf(".",place+1);
    if ((place > -1)&&(addr.length >2)&&(point > 1)) {
        return(true);
    }
    else  {
        alert('Votre adresse E-Mail est invalide !');
        return(false);
    }
    return false;
}


function reset_input(){
	document.getElementById('newmail').value='';
	document.getElementById('newmail').setAttribute('style','color:black;');
}

function cgvread(cgv){
	if (document.cgvform.cgvbox.checked == 1) {
		return true
	}
	else {
		alert('Merci de confirmez que vous avez pris connaissance des conditions générales de ventes');
		return false
	}
	
}

function checkForm(email_id) {
  if($('lastname').value == ''){
    alert('Merci de renseigner votre nom');
    return false;
  }
  if(!checkEmail(email_id)){
    return false;
  }
  if($('firstname').value == ''){
    alert('Merci de renseigner votre prénom');
    return false;
  }
}  

function checkEstimateForm(){
  if (document.getElementById('first_name').value == '') {
    highlight('first_name');
    alert("Merci de saisir votre nom");
    return false;
  }
  if (document.getElementById('last_name').value == '') {
    highlight('last_name');
    alert("Merci de saisir votre nom");
    return false;
  }  
  if (document.getElementById('address').value == '') { 
    highlight('address');
    alert("Merci de préciser votre adresse");
    return false;
  }
  if (document.getElementById('zip').value == '') { 
    highlight('zip');
    alert("Merci de préciser votre code postal");
    return false;
  }
  if (document.getElementById('phone').value == '' && document.getElementById('mobile').value == '') { 
    highlight('phone');
    alert("Merci de préciser au moins un numéro de téléphone");
    return false;
  }
  if (checkEmail('email') == false){
    highlight('email');
    return false;
  }
  if (document.getElementById('subject').value == 0) {
    highlight('subject');
    alert("Merci de choisir le sujet de votre message");
    return false;
  }
  if (document.getElementById('building').value == 0) {
    highlight('building');
    alert("Merci de préciser le type de batiment");
    return false;
  }
  if (document.getElementById('year').value == 0) {
    highlight('year');
    alert("Merci de préciser l'ancienneté du batiment");
    return false;
  }
  if (document.getElementById('actual').value == 0) { 
    highlight('actual');
    alert("Merci de préciser le type d'équipement actuel");
    return false;
  }


}

function check_logon_form(){
  //Check new customer creation form
  if (document.getElementById('firstname').value == '') {
    highlight('firstname');
    alert("Merci de saisir votre prénom");
    return false;
  }
  if (document.getElementById('name').value == '') {
    highlight('name');
    alert("Merci de saisir votre nom");
    return false;
  }
  if (document.getElementById('addr1').value == '') {
    highlight('addr1');
    alert("Merci de saisir votre adresse");
    return false;
  }
  if (document.getElementById('zip').value == '') {
    highlight('zip');
    alert("Merci de saisir votre code postal");
    return false;
  }
  if (document.getElementById('city').value == '') {
    highlight('city');
    alert("Merci de saisir votre ville");
    return false;
  }
  if (document.getElementById('phone').value == ''){
    highlight('phone');
    alert('Merci de renseigner votre numéro de téléphone');
    return false;
  }
  if (checkEmail('email') == false){
    highlight('email');
    return false;
  }
  if (document.getElementById('toship_false').value == 'false' && document.getElementById('toship_true').value == 'false'){
    alert("Préferez vous la livraison à domicile ou bien le retrait sur place ?");
    return false;
  }
  
  return false
}

function highlight(the_element) {
  //highlight selected input
  $(the_element).setStyle({border:'1px solid red'}); 
}

function downlight(the_element) {
  //highlight selected input
  if(document.all){
      document.getElementById(the_element).style.setAttribute('cssText','border:1px solid #d4d4d4');
  }
  else{
      document.getElementById(the_element).setAttribute('style','border:1px solid #d4d4d4');
  }
}

function start_slide(pics,id,site,size){
  //image 0 is already displayed by default
  var a = 1;
  new PeriodicalExecuter(function(){  
    new Effect.Fade(id, { 
      duration: 1, 
      fps: 50,
      afterFinish: function() {    
        var pic_url =  "/thumbnailer/"+pics[a]+"/"+size;
        //alert(pic_url);
        $(id).src = pic_url;
        (a < pics.length-1) ? a++ : a = 0;    
        new Effect.Appear(id, {
          duration: 1,
          fps: 50,
          queue:'end'
        })   
      }
    })       
  }, 5);
  return true
}

