///////////////////////
// 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');
}

//////////////////////////////////////////////////////////////
// correctly handle PNG transparency in Win IE 5.5/6

function correctPNG() {
    for(var i=0; i<document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
        }
    }
}
if (document.all){
    window.attachEvent("onload", correctPNG);
}

function raiseSubMenu(id){
    if(document.all){
        document.getElementById('submenu_'+id).style.setAttribute('cssText','display:block;list-style-type:none;padding-bottom:10px;');
        var links = document.getElementById('submenu_'+id).childNodes;
        /*for(var i=0;i<links.length;i++) {
            links[i].firstChild.style.setAttribute('cssText','color:#4d4d4d;font-size:15px;margin:0;padding-right:20px;height:100%;display:block;text-align:right;');
            links[i].style.setAttribute('cssText','color:#fff;border:0;margin:0;');
        }*/
    }
    else{
        document.getElementById('submenu_'+id).setAttribute('style','display:block;list-style-type:none;padding-bottom:10px;');
        var links = document.getElementById('submenu_'+id).childNodes;
        /*for(var i=0;i<links.length;i++) {
            links[i].firstChild.setAttribute('style','color:#4d4d4d;font-size:15px;margin:0;padding-right:10px;display:block;height:100%;');
            links[i].setAttribute('style','color:#4d4d4d;border:0;margin:0;');
        }*/
    }
}

function hideSubMenu(id){
    if(document.all){
        document.getElementById('submenu_'+id).style.setAttribute('cssText','display:none;');
    }
    else{
        document.getElementById('submenu_'+id).setAttribute('style','display:none;');
    }
}

function hideSubMenuIE(id){
    if(document.all){
        document.getElementById('submenu_'+id).style.setAttribute('cssText','display:none;');
    }
}

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 readyForSearch() {
    var pattern = document.getElementById('searchInput');
    if(pattern.value == 'Rechercher...'){
        pattern.value='';
        if(document.all){
            document.getElementById('searchInput').style.setAttribute('cssText','height:20px;color:#4d4d4d;font-size:14px;position:absolute;margin:10px auto auto 15px;width:180px;');
        }
        else{
            document.getElementById('searchInput').setAttribute('style','height:15px;color:#4d4d4d;font-size:12px;position:absolute;margin:7px auto auto 15px;width:180px;');
        }
    }
}

function readyForLogin() {
    var addr = document.getElementById('login');
    if(addr.value == 'Votre adresse E-Mail'){
        addr.value = '';
        if(document.all){
            document.getElementById('login').style.setAttribute('cssText','color:#333333 !important;font-size:12px;');
        }
        else{
            document.getElementById('login').setAttribute('style','color:#333333 !important;font-size:12px;');
        }
    }
}

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 countCartContent(){  
  //alert('hu');
  new Ajax.Updater('cart_content','/cart/count',{method:'get',parameters:{authenticity_token: window._token}});
}

function check_comment_form(){

  if (checkEmail('email_addr') == false){
    return false;
  }  
  if (document.getElementById('name').value == '') {
    alert("Merci de saisir votre nom");
    return false;
  }
  if (document.getElementById('title').value == '') {
    alert("Merci de saisir un titre pour votre commentaire");
    return false;
  }
  if (document.getElementById('speech').value == '') {
    alert("Merci de saisir un commentaire");
    return false;
  }
  return false;
}

function check_change_password_form(){
  
  if (document.getElementById('password1').value == '') {
    alert("Vous n'avez pas saisi de mot de passe !");
    return false;
  }
  
  if (document.getElementById('password1').value != document.getElementById('password2').value) {
    alert("Vos mots de passe ne correspondent pas, merci de vérifier");
    return false;
  }

}

function reHeight() {
  //Reposition 100% wide footer absolute positionned
  var divTop;
  var obj = document.getElementById('footer');

  if(obj.offsetTop) {divTopt=obj.offsetTop;}
  else if(obj.style.pixelTop){divTop=obj.style.pixelTop;} 
  
  if(document.all){
    document.getElementById('grass_bg').style.setAttribute('cssText','height:218px;top:'+divTopt+'px;');
  }
  else {
    document.getElementById('grass_bg').setAttribute('style','height:218px;top:'+divTopt+'px;');
  }
  return false;

}
