var IsTypeDefined=false; 
/** 
 * Determines if TYPE is defined and if so, it set a global variable to true
 */
function SetTypeState() {
       if (typeof(Type)!='undefined') {
               IsTypeDefined=true
       }
       else {
            IsTypeDefined=false;
            eval("Kerastase=function() {  }");
       
       }
}
/** 
 * calls SetTypeState and sets it to true if TYPE is defined
 */
SetTypeState();
/*
 * It Creates a namespace "making javascript easier" if TYPE is defined
 */
if (IsTypeDefined){ Type.registerNamespace("Kerastase");  }
 
Kerastase.LeftNav_Class=function() {
    this.disappeardelay= 500; //set delay in miliseconds before menu disappears onmouseout
    this.disablemenuclick= false; //when user clicks on a menu item with a drop down menu, disable menu item's link?
    this.enableswipe= 1; //enable swipe effect? 1 for yes, 0 for no
	this.swipeDirection= "right";
    this.dropmenuobj= null;
    this.ie= document.all;
    this.firefox= document.getElementById&&!document.all;
    this.swipetimer= undefined;
    this.bottomclip=0;
    this.DoMouseOver=false;
    
    this.getposOffset=function(what, offsettype){
        var totaloffset=0;
        var parentEl=what.offsetParent;
        if (parentEl!=null){
            totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
            //parentEl=parentEl.offsetParent;
        }
        else
        {
            totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        }
        if (offsettype!="left" && this.ie)
        {
            totaloffset = totaloffset - 1;
        }
        return totaloffset;
    }

    this.swipeeffect=function(){
		if (this.swipeDirection == "down"){
			if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
				this.bottomclip+=10+(this.bottomclip/10); //unclip drop down menu visibility gradually
				this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)";
			}
			else
				return;
			this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10);
		}
		if (this.swipeDirection == "right"){
			if (this.bottomclip<parseInt(this.dropmenuobj.offsetWidth)){
				this.bottomclip+=2+(this.bottomclip/10); //unclip drop down menu visibility gradually
				this.dropmenuobj.style.clip="rect(0 "+this.bottomclip+"px auto 0)";
			}
			else
				return;
			this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10);
		}   
		if (this.swipeDirection == "left"){
			if (this.bottomclip>0){
				this.bottomclip = this.bottomclip - 10; //unclip drop down menu visibility gradually
				//alert("rect(" + this.dropmenuobj.offsetWidth + "px " + this.dropmenuobj.offsetHeight + "px 0 " + this.bottomclip + "px)");
				this.dropmenuobj.style.clip="rect(" + this.dropmenuobj.offsetWidth + "px " + this.dropmenuobj.offsetHeight + "px 0 " + this.bottomclip + "px)";
			}
			else
				return;
			this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10);
		}    
    }

    this.showhide=function(obj){
        if (this.ie || this.firefox)
            this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px";
			
          if (obj.zIndex==1){
            if (this.enableswipe==1){

                if (this.swipeDirection == "left"){
					this.bottomclip = this.dropmenuobj.offsetWidth;
				}else{
					this.bottomclip=0;
				}
                this.swipeeffect();
                obj.zIndex=100;
            }
            
        }
    }

    this.iecompattest=function(){
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }

    this.dropit=function(obj, dropmenuID, parentContainerID){	       
        if (this.dropmenuobj!=null) //hide previous menu
	        this.dropmenuobj.style.zIndex=1;
       
        if (this.ie||this.firefox){       
			// set the objects
			this.parentObj=document.getElementById(parentContainerID);
			this.dropmenuobj=document.getElementById(dropmenuID);
			//debugger;
			this.dropmenuobj.style.visibility="Visible";
        
			// if mouse over is wanted
            if(this.DoMouseOver){
				this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu();}
				this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e);}
				
			}
            this.showhide(this.dropmenuobj.style);
            // get the position of the parent div
            this.dropmenuobj.x=this.getposOffset(this.parentObj, "left");
            this.dropmenuobj.y=this.getposOffset(this.parentObj, "top");
            
            // set the new div to cover the parent div
	        this.dropmenuobj.style.left = "0px";
		    this.dropmenuobj.style.top = "0px";
        }
    }

    this.contains_firefox=function(a, b) {
        while (b.parentNode)
            if ((b = b.parentNode) == a)
                return true;
        return false;
    }

    this.dynamichide=function(e){
		var evtobj=window.event? window.event : e
        if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
			this.dropmenuobj.style.clip="rect(0 auto 0 0)";
		else if (this.firefox&&evtobj.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
            this.dropmenuobj.style.clip="rect(0 auto 0 0)";
			
    }
    
    this.clearhidemenu=function(){
        if (this.delayhide!="undefined")
            clearTimeout(this.delayhide)
    }
    
    this.delayhidemenu=function(){
        var imgOFF = this.getswapimagesrc(this.dropmenuimg, "off");
        var cmd = "cssdropdown.dropmenuimg.src='" + imgOFF + "';cssdropdown.dropmenuobj.style.visibility='hidden'";
        this.delayhide=setTimeout(cmd,this.disappeardelay); //hide menu
    }
}

//if (IsTypeDefined) { Kerastase.LeftNav_Class.registerClass('Kerastase.LeftNav_Class'); }
if (IsTypeDefined) { Kerastase.LeftNav_Class.registerClass('Kerastase.LeftNav_Class'); }

var mouseOut = 1;
var ie = false; 
var firefox = false;
debTab = '<table border=0 cellpadding=0 cellspacing=0 width="100" bgcolor="#FFFFFF"><tr><td align="center">';
finTab = '</td></tr></table>';
/*function rollOn(x){
	GetEnvironment();
	var prodObj = document.getElementById("container_"+x);
	var prodContainer = document.getElementById("rollProd");

	showHide("rollProd", "hidden");
	setToAnchor("prod"+x, "rollProd");
	
	if(ie){
		prodContainer.style.left = prodObj.offsetLeft + 250 + "px";
		prodContainer.style.top = prodObj.offsetTop + 65 + "px";
	}else{
		prodContainer.style.left = prodObj.offsetLeft + 275 + "px";
		prodContainer.style.top = prodObj.offsetTop + 65 + "px";
	}
	document.getElementById("rollProd").innerHTML = debTab + document.getElementById("roll"+x).innerHTML + finTab;
	showHide("rollProd", "visible");
	
}*/
/*function rollOff(x, evt){
		GetEnvironment();
		
		var obj = document.getElementById(x);
				
        if ((ie)&&!obj.contains(evt.toElement)){
			showHide("rollProd", "hidden");
			document.getElementById("rollProd").innerHTML = "";
		}else if ((firefox)&&evt.currentTarget!= evt.relatedTarget&& !contains_firefox(evt.currentTarget, evt.relatedTarget)){
		
			showHide("rollProd", "hidden");
			document.getElementById("rollProd").innerHTML = "";
		}
}*/

function getOffset(obj, offsettype){
	    var totaloffset=0;
        var parentEl=obj.offsetParent;
        if (parentEl!=null){
            totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;;
        }else{
           totaloffset=(offsettype=="left")? obj.offsetLeft : obj.offsetTop;
        }
        if (offsettype!="left" && this.ie)
        {
            totaloffset = totaloffset - 1;
        }
        return totaloffset;

}
function contains_firefox(a,b){
        while (b.parentNode)
            if ((b = b.parentNode) == a)
                return true;
        return false;
}
function GetEnvironment(){
		if(document.all)
			ie = true;
			
		
		if(document.getElementById&&!document.all)	
			firefox = true;  
}

function rollOn(x){	
	showHide("rollProd", "hidden");	
	setToAnchor("prod"+x, "rollProd");
	posLeft("rollProd", left("rollProd")-20);
	version= navigator.appVersion;
	whole_version = version.substring(version.lastIndexOf("S")+7, version.length);
	browser = version.substring(version.lastIndexOf("n")+14, version.length-9);

	if(navigator.userAgent.indexOf("Firefox") >= 0){
		posTop("rollProd", pot("rollProd")-100-(document.getElementById("content").scrollTop));
	}
	else if((browser = "Safari")&& (whole_version <= 419.3)){
		//posTop("rollProd", pot("rollProd")+ this);
		//posLeft("rollProd", )- this + 300);
	posLeft("rollProd", left("rollProd")+ 300);
		posTop("rollProd", pot("rollProd")+(document.getElementById("content").scrollTop));


	}	
	else{	
	posLeft("rollProd", left("rollProd")-10);
	posTop("rollProd", pot("rollProd")-50-(document.getElementById("content").scrollTop));
	}
		document.getElementById("rollProd").innerHTML = debTab + document.getElementById("roll"+x).innerHTML + finTab;
		showHide("rollProd", "visible");
	}
/*function rollOn(obj,lyr)
{
	showHide("rollProd", "hidden");
	var coors = findPos(obj);
	if (lyr == 'rollProd') coors[1] -= 50;
	var x = document.getElementById(lyr);
	x.style.top = coors[1] + 'px';
	x.style.left = coors[0] + 'px';
}
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
*/
function rollOff(){
	/*if (window.event.toElement)
		alert("to");
	if (window.event.fromElement)
		alert("from");*/
		
	//if (!x.contains(window.event.toElement)) {
	//showHide("rollProd", "hidden");
showHide("rollProd", "hidden");
			document.getElementById("rollProd").innerHTML = "";
		//document.getElementById("rollProd").innerHTML = "";
	//}
}
// FLASH ACTIVATION
function CreateControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id="' + ObjectID + '" width=' + WIDTH + ' height=' + HEIGHT +' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value="' + URL + '">'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '/>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  objectTag = objectTag + '<param name="bgcolor" value="#ffffff">'  
  objectTag = objectTag + '<param name="wmode" value="transparent">'
  //objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
 objectTag = objectTag + '<embed src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">';
// objectTag = objectTag + '<embed src="' + URL + '" quality="high" bgcolor="#ffffff" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>';
 
 objectTag = objectTag + "</object>";
// alert(objectTag);
  d.innerHTML = objectTag;
 // alert (d.innerHTML);
}

/* Sets the Hidden_Login value on Registration Page */		
function Sethiddenloginvalue(val)
{
	var _f = document.forms[0];
	for (i=0;i<_f.elements.length;i++)
	{
		if (_f.elements[i].id.indexOf('hidden_login') != -1)
			_f.elements[i].value=val;

	}
}

/* Sudeshna - Below functions are commented out because these are available in refSite.js */
/* Gets the Main Form Name on page */
/*function GetMainFormName(){
	var i;
	for (i=0;i<document.forms.length;i++){
		if (document.forms[i].name.indexOf("__aspnetForm") != -1)
		return document.forms[i].name;
	}
	return null;
}*/

/* Gets the Element from form */
/*function GetElementName(name,mf)
{	
	var n = name.toLowerCase()
	if (n==null || n=="") return null;
	var i, s, j;
	
	for (i=0;i<document.forms[mf].elements.length;i++){
		if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n) != -1){
			var strform = document.forms[mf].elements[i].name.toLowerCase();
			var strformname = strform.substr(strform.indexOf(n),n.length);
			if (strformname == n)
				return document.forms[mf].elements[i].name;
		}	
	}
	return null;
}

function GetElement(ElementName, formName)
{	
	return document.forms[formName].elements[GetElementName(ElementName,formName)];
}*/

/* Sets the URL for GO button on "Search By Category" pages based on the Sub-Category selected in dropdown */
function goUrlNav(nameDropdown)
{	
	var mf = GetMainFormName();					
	if (mf==null) return;
	
	var elementDropdown  = GetElement(nameDropdown, mf);	
	togo = elementDropdown.options[elementDropdown.selectedIndex].value;		
	
	if (togo!="") document.location.href= togo;
}

/* Sets the URL for GO button on "Search By Category" pages based on the Sub-Category selected in dropdown */
function goUrlNav2(nameDropdown)
{	
	var elementDropdown  = document.getElementById(nameDropdown);	
	togo = elementDropdown.options[elementDropdown.selectedIndex].value;		
	
	if (togo!="") document.location.href= togo;
}

//Function to validate zipcode: Zip should have 5 numeric characters
function CheckZipCode(zipCtrl, errorMsgCtrl, tblCell)
{	
	var mf = GetMainFormName();
	
	var zipname = zipCtrl + "$" + "address_zip" ;	
	
	var zipCode = GetElement(zipname, mf);	
	
	var divZipError = document.getElementById(errorMsgCtrl);
		
	var tblcellZip = document.getElementById(tblCell);
	
	var allValid = true;
		
	/*Check if the object exists before manipulating the values */
	if(divZipError!= null)
	{
		divZipError.style.display = "none";
		if(tblcellZip != null) tblcellZip.style.color = "#51555C";
				
		//If zip code is not entered, then let the webbox validation methods capture that error. 
		//This will enable the validation to work when "ship to billing" address checkbox is checked.
		if(zipCode != null && zipCode.value.length == 0)
		{
			allValid = false;
		}
		else
		{	
			var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/

			if (objRegExp.exec(zipCode.value) == null) allValid = false;	
							
		}
	}
	else
	{
		allValid = false;
	}
	
	if (!allValid) 
	{
		if(tblcellZip != null) tblcellZip.style.color = "#FF0000";
		divZipError.style.display = "block";
		return false;
	}	
	else
	{
		return true;
	}		
}

//Function to validate State: The first option "-Select-" should not be selected.
function CheckState(stateCtrl, errorMsgCtrl, tblCell)
{	
	var mf = GetMainFormName();
	
	var stateDropName = stateCtrl + "$" + "address_state_choice";	
	
	var stateDrop = GetElement(stateDropName, mf);	
	
	var divStateError = document.getElementById(errorMsgCtrl);
		
	var tblcellState = document.getElementById(tblCell);
		
	/*Check if the object exists before manipulating the values */
	if(divStateError!= null)
	{
		divStateError.style.display = "none";
		if(tblcellState != null) tblcellState.style.color = "#51555C";
			
	    //Check if the first option is selected in the dropdown
	    if(stateDrop.selectedIndex == 0)
	    {
	        if(tblcellState != null) tblcellState.style.color = "#FF0000";
			divStateError.style.display = "block";
			return false;
	    }
	    else
		{
			return true;
		}
	 }
}

/* New Left Nav Menu */
 
//Variables to be defined by user. Pee=-200 is the ending position of the menu upon closing
//It must match the left position of the menuBar layer as defined in the Style Sheet
//drec and speed can be experimented with to adjust smoothness and speed of animation

var pee = -200
var drec = 40;
var speed = 20;
var menuWidth = 223;

//Don't touch!
var l = pee;
var holderWidth = menuWidth;

//Don't touch. This is the function that closes the menu
function Proj7GlideBack () {
  l += drec;
  if (l>0) l = 0;
  holderWidth = l + menuWidth;
  if (document.getElementById) {
	document.getElementById('LN_HOLDER').style.width = holderWidth + 'px';
	document.getElementById('menuBar').style.left = l + 'px';
  }
  else if (document.all) {
	document.all.LN_HOLDER.style.pixelWidth = holderWidth;
	document.all.menuBar.style.pixelLeft = l;
  }
  else if (document.layers) {
	document.LN_HOLDER.width = holderWidth;
    document.menuBar.left = l;
  }
  if (l < 0)
    setTimeout('Proj7GlideBack()', speed);
  
else {
	  if (document.layers) {
      var html = '';
      html += '<A HREF="javascript:;"';
      html += 'onmouseover="Proj7GlideOut(); return false;"'
      html += '<\/A>';
      var a = window.document.menuBar.document.glider;
      a.document.open();
      a.document.write(html);
      a.document.close();
    }
    else if (document.all) {document.all.glidetextLink.innerHTML = '<img src="/img/LN_menu.gif" width="13" height="400" border="0">';
      document.all.glidetextLink.onmouseover = moveIn;
    }
    else if (document.getElementById) {
      document.getElementById('glidetextLink').firstChild.nodeValue ='<img src="/img/LN_menu.gif" width="13" height="400" border="0">';
      document.getElementById('glidetextLink').onmouseover = moveIn;
    }
  }
}
//Don't touch. This is the function that opens the menu
function Proj7GlideOut () {
  l -= drec;
  if (l<pee) l = pee;
  holderWidth = l + menuWidth;
  if (document.getElementById) {
	document.getElementById('LN_HOLDER').style.width = holderWidth + 'px';
	document.getElementById('menuBar').style.left = l + 'px';
  }
  else if (document.all) {
	document.all.LN_HOLDER.style.pixelWidth = holderWidth;
	document.all.menuBar.style.pixelLeft = l;
  }
  else if (document.layers) {
	document.LN_HOLDER.width = holderWidth;
	document.menuBar.left = l;
  }
  if (l > pee)
    setTimeout('Proj7GlideOut()', speed);
  else {
    if (document.layers) {
      var html = '';
      html += '<A HREF="javascript:;"';
      html += 'onmouseover="Proj7GlideBack(); return false;"';
      html += 'Class="glideText"';
      html += 'menu'+ '<br>';
      html += 'menu'+ '<br>';
      html += '<\/A>';
      var a = window.document.menuBar.document.glider;
      a.document.open();
      a.document.write(html);
      a.document.close();
    }
    else if (document.all) {document.all.glidetextLink.innerHTML = '<img src="/img/LN_menu.gif" width="13" height="400" border="0">';
      document.all.glidetextLink.onmouseover = moveOut;
    }
    else if (document.getElementById) {
      document.getElementById('glidetextLink').firstChild.nodeValue ='<img src="/img/LN_menu.gif" width="13" height="400" border="0">';
      document.getElementById('glidetextLink').onmouseover = moveOut;
    }
  }
}
function moveIn () {Proj7GlideOut();return false;
}
function moveOut() {Proj7GlideBack();return false;
}

<!--NNresizeFix Reloads the page to workaround a Netscape Bug-->
if (document.layers) {
origWidth = innerWidth;
origHeight = innerHeight;}
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();}
if (document.layers) onresize = reDo;

/* New Left Nav Menu */

 /* Toggles for the leftNavmenu */ 
    
    
    function toggle(id,state,id2) { 
        
         var obj=document.getElementById(id); 
         var obj2=document.getElementById(id2); 
        if (obj != null){ 
             if(state=="on") { 
                  obj.style.display="block"; 
                  obj2.style.display="none"; 
             } else { 
                  obj.style.display="none"; 
                  obj2.style.display="block"; 
             } 
         }
         
    }
    
    
/* Opacity*/
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
} 
function GetSeal()
{
 document.write("<script src=https://seal.verisign.com/getseal?host_name=www.kerastase-usa.com&size=S&use_flash=YES&use_transparent=YES&lang=en></script>") ;	
}

/* 
 * Prevents user from entering more than specific number of characters in a textbox/textarea
 */
function LimitTextLength(textArea, maxLength)
{		
	if (maxLength == 0)
		maxLength = 150;

	/*if(textArea.value.length == maxLength)
		textArea.style.color = "Red";
	else
	if(textArea.value.length < maxLength)
		textArea.style.color = "#484848";
	*/
		
	if(textArea.value.length > maxLength )
	{		
		alert('Gift card message has reached the 100 character limit.\nPlease review and revise your message, if needed.');
		textArea.value = textArea.value.substring(0, maxLength);
		textArea.focus();
	}			
}	