var VNH = {};

/* gestion images png avec ie 6 */

VNH.display = {
  "alphaBackgrounds" : function (e) {
    var bg = e.currentStyle.backgroundImage;
    if (bg.match(/\.png/i) != null && e.hasClassName("trans")) { 
      var mypng = bg.substring(5,bg.length-2);
      e.setStyle({  
        filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mypng + "', sizingMethod='" + (e.currentStyle.backgroundRepeat == "no-repeat" ? "crop" : "scale") + "')",
        backgroundImage : "none"}); 
    }
  },

  "fnLoadPngs" : function (img){
    if (img.src.match(/\.png$/i) != null) {
      var src = img.src;
      var div = document.createElement("DIV");    
      div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
      div.style.width = img.width + "px";
      div.style.height = img.height + "px";
      img.replaceNode(div); 
    }
  },

  "swapBg" : function (el) {
    var position = "top";
    if (!el.style.backgroundPosition.match(/bottom/gi)) position = "bottom";
    el.setStyle({ backgroundPosition: "left " + position });
  }

};

document.observe("dom:loaded", function() {
  if (Prototype.Browser.IE) {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, "");
    if (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7) {
      $$("*").each(VNH.display.alphaBackgrounds);
      $$("img.trans").each(VNH.display.fnLoadPngs);
    }
  }
});

/*******/


VNH.menu = {
  'over' : function(args){
	  $(args).setStyle({backgroundColor : "#FFFFFF"});
	},
	 'out' : function(argsb){
	  $(argsb).setStyle({backgroundColor : "#eff7f6"});
	}
}

VNH.contact = {
  'button' : null,
  'onSubmit' : function(args){
    if(VNH.contact.verifform())
      Kwo.exec('/contact.mail',args,{"callback":VNH.contact.onCallBack});
  },
  'onCallBack' : function(h) {
     //VNH.contact.button.enable();
      if(h["error"]>0){
        Kwo.error(h["result"]["msg"]);
      }else{
        //Kwo.warn(h["result"]["alert"]);
       $('kwo-vnh-boxcontact').update(h["result"]["alert"]);
      }
  },
  'verifform' : function(){
    var msg="";
    if($F("fieldsemail").empty()){
      msg+="Champ Requis : Email \n";
    }
    if($F("fieldssubject").empty()){
      msg+="Champ Requis : Sujet \n";
    }
    if($F("fieldsmessage").empty()){
      msg+="Champ Requis : Message \n";
    }
    if(msg!=""){
      alert(msg);
      return false;
    }
    return true;
  }
}

VNH.agences = {
  'list' : function(id) {
   // Kwo.exec('/agences.list',{'id':id},{"container":"agences_renseignements"});
   Kwo.exec('/agences.list',{'id':id},{"container":"kwo-vnh-boxgauchegroupe"});
  }
}

VNH.answer = {
  'onSubmit' : function(args) {
     var msg ="";
    if($F('fieldsnom').empty()){
     msg+="Champ Requis : Nom \n"; 
    }  
    if($F('fieldsprenom').empty()){
      msg+="Champ Requis : Prenom \n";
    }
    if($F('fieldsville').empty()){
      msg+="Champ Requis : Ville \n";
    }
    if($F('fieldsemail').empty()){
      msg+="Champ Requis : Email \n";
    }
    if($F('fieldsphone').empty()){
      msg+="Champ Requis : Telephone \n";
    }
    if($F('fieldsdispo').empty()){
      msg+="Champ Requis : Disponibilite \n";
    }
    if($F('fieldsrenum').empty()){
      msg+="Champ Requis : Derniere renumeration \n";
    }
    if($F('fieldscv').empty()){
      msg+="Champ Requis : CV \n";
    }


    if(msg!=""){
      alert(msg);   
    return false;
    }
    return true;
  }
}

VNH.map = {
  'click' : function(type){
    $('kwo-box-paris').setStyle('display:none');
    $('kwo-box-californie').setStyle('display:none');  
    $(type).setStyle('display:block');
  },
  'clean' : function() {
    $('kwo-box-paris').setStyle('display:none');
    $('kwo-box-californie').setStyle('display:none');   
  }
  
}

VNH.display = {
  "alphaBackgrounds" : function (e) {
    var bg = e.currentStyle.backgroundImage;
    if (bg.match(/\.png/i) != null && e.hasClassName('trans')) { 
      var mypng = bg.substring(5,bg.length-2);
      e.setStyle({ 
        filter : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mypng + "', sizingMethod='" + (e.currentStyle.backgroundRepeat == "no-repeat" ? "crop" : "scale") + "')",
        backgroundImage : "none"}); 
    }
  },

  "fnLoadPngs" : function (img){
    if (img.src.match(/\.png$/i) != null) {
      var src = img.src;
      var div = document.createElement("DIV");    
      div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
      div.style.width = img.width + "px";
      div.style.height = img.height + "px";
      img.replaceNode(div); 
    }
  },

  "swapBg" : function (el) {
    var position = "top";
    if (!el.style.backgroundPosition.match(/bottom/gi)) position = "bottom";
    el.setStyle({ backgroundPosition: "left " + position });
  }

};

document.observe("dom:loaded", function() {
  if (Prototype.Browser.IE) {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, "");
    if (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7) {
      $$("*").each(VNH.display.alphaBackgrounds);
      //$$(".trans").each(VNH.display.alphaBackgrounds);
      $$("img.trans").each(VNH.display.fnLoadPngs);
    }
  }
});

VNH.offre = {
  "hover" : function(id) {
     var y = -30;
     $('left_'+id).setStyle({backgroundPosition : "0px "+y+"px"});
     $('right_'+id).setStyle({backgroundPosition : "0px "+y+"px"});
  },
  "out" : function(id) {
     var y = 0;
     $('left_'+id).setStyle({backgroundPosition : "0px "+y+"px"});
     $('right_'+id).setStyle({backgroundPosition : "0px "+y+"px"});
  }
};
