

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}




function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
      var i,p,v,obj,args=MM_showHideLayers.arguments;
      for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
        obj.visibility=v; 
}
}

  function toggleToolTip(objName) {
        var obj = document.getElementById(objName); //$get(objName); 
        obj.style.display = "";
    }
    
    function clearToolTip(objName) {
        var obj = document.getElementById(objName); //$get(objName); 
        obj.style.display = "none";
    }
    
function SetExtendedProp(id)
{
    var querystr = document.location.search;
    var _f = document.forms[0];
    if (querystr!=''){
		querystr=querystr.substring(1,querystr.length);
    }
    if (querystr!=''){
        var prop_array = querystr.split('&');
        for (var i=0;i<prop_array.length;i++){
            var prop=prop_array[i].split('=');
            //check if page has field to update requested extended property 
            for (var j = 0; j < _f.elements.length; j++)
            {
                if (_f.elements[j].id.indexOf(id)>-1){ 
                            _f.elements[j].value=prop[1];
                }
            }           
        }
    }
 
}

function SetLogin(loginname)
{
    var mf = GetMainFormName();
    if (mf==null) return;
    var login = GetElementName("hidden_login",mf)
    if (login!= null)
        document.forms[mf].elements[login].value = loginname;
}
							
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;
	}
 }
 									
function GetElementName(n, mf)
{
	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.toLowerCase()) != -1)
	return document.forms[mf].elements[i].name;

	}
	return null;
}

// CSS Drop Down
var cssdropdown={
    disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
    disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
    enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no

    //No need to edit beyond here////////////////////////
    dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,
    dropmenuimg: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,
    
    getposOffset:function(what, offsettype){
//        var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        var totaloffset=12;
        var parentEl=what.offsetParent;
        if (parentEl!=null){
          
           if (offsettype=="left"){
          totaloffset=  totaloffset+parentEl.offsetLeft-39;
           }else{
           totaloffset= totaloffset+parentEl.offsetTop;
           }
          
        }
        else
        {
            var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
           
        }
        if (offsettype!="left" && this.ie)
        {
            totaloffset = totaloffset-13;
        }
        return totaloffset;
    },

    swipeeffect:function(){
        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)
    },

    showhide:function(obj, e){
        try {
             _QuickShop_Class.Hide();
             }
        catch (err) {
        
        }     
        if (this.ie || this.firefox)
            this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
        if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
            this.swapimage(this.dropmenuimg, "on");
            if (this.enableswipe==1){
                if (typeof this.swipetimer!="undefined")
                    clearTimeout(this.swipetimer)
                obj.clip="rect(0 auto 0 0)" //hide menu via clipping
                this.bottomclip=0
                this.swipeeffect()
            }
            obj.visibility="visible"
            
        }
        else if (e.type=="click")
        {
            this.swapimage(this.dropmenuimg, "off");
            obj.visibility="hidden";
             
        }
    },

    iecompattest:function(){
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    },

    clearbrowseredge:function(obj, whichedge){
        var edgeoffset=0
        if (whichedge=="rightedge"){
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
            this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
            if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
                edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
        }
        else{
            var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
            var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
            this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
            if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
                edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
                if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
                    edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
            }
        }
        return edgeoffset
    },

    dropit:function(obj, e, dropmenuID, imageID){
        if (this.dropmenuobj!=null) //hide previous menu
        {
            this.dropmenuobj.style.visibility="hidden" //hide menu
            var keepOn = this.dropmenuimg.getAttribute("keepOn");
            if (keepOn == null)
            {
                this.swapimage(this.dropmenuimg, "off"); // turn off image
            }
        }

        /* <Begin> */
        /* F.N This code hides the drop downs if ie 6.0 only */
        try 
        {
            ToggleDropDowns('hidden');
        }
        catch (err) { }
        /*<end> */

        this.clearhidemenu()
        if (this.ie||this.firefox){
            obj.onmouseout=function(){cssdropdown.delayhidemenu()}
            obj.onclick=function(){return !cssdropdown.disablemenuclick} //disable main menu item link onclick?
            this.dropmenuobj=document.getElementById(dropmenuID)
            this.dropmenuimg=document.getElementById(imageID)
            this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
            this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e)}
            this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
            this.showhide(this.dropmenuobj.style, e)
            this.dropmenuobj.x=this.getposOffset(this.dropmenuimg, "left")
            this.dropmenuobj.y=this.getposOffset(this.dropmenuimg, "top")
            this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
            this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
        }
    },

    contains_firefox:function(a, b) {
        while (b.parentNode)
            if ((b = b.parentNode) == a)
                return true;
        return false;
    },

    dynamichide:function(e){
        var evtobj=window.event? window.event : e
        if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
            this.delayhidemenu()
        else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
            this.delayhidemenu()
    },
    
    delayhidemenu:function(){
        var keepOn = this.dropmenuimg.getAttribute("keepOn");
        var imgSrc = ""; 
        if (keepOn == null)
        {
            imgSrc = this.getswapimagesrc(this.dropmenuimg, "off");
        }
        else
        {
            imgSrc = this.getswapimagesrc(this.dropmenuimg, "on");
        }
        var cmd = "cssdropdown.dropmenuimg.src='" + imgSrc + "';cssdropdown.dropmenuobj.style.visibility='hidden'";
        this.delayhide=setTimeout(cmd,this.disappeardelay); //hide menu

        /* F.N This code below will show the drop downs if IE 6.0 only */
        try {
            ToggleDropDowns('visible');
        }
        catch (err) {
            //do nothing
        }
    },
    
    swapimage:function(img, imgState)
    {
        img.src=this.getswapimagesrc(img, imgState);
    },

    // Given an image string, return the off/on state src.
    // ASSUME: the image name will be for the form *_[off | on].*
    getswapimagesrc:function(img, imgState)
    {
        var imgSrc = '';
        if (img != null)
        {
	        var imgStateOn = "_on.";
	        var imgStateOff = "_off.";
	        imgSrc = img.src;
	        var imgPathAndFileName = imgSrc.slice(0, imgSrc.lastIndexOf(".") + 1)
	        var imgFileExtension = imgSrc.slice(imgSrc.lastIndexOf(".") + 1, imgSrc.length);

	        if (imgPathAndFileName.indexOf(imgStateOn) > 0 && imgState == 'off')
	        {
		        imgSrc = imgPathAndFileName.slice(0, imgPathAndFileName.indexOf(imgStateOn)) + imgStateOff + imgFileExtension;
	        }
	        if (imgPathAndFileName.indexOf(imgStateOff) > 0 && imgState == 'on')
	        {
		        imgSrc = imgPathAndFileName.slice(0, imgPathAndFileName.indexOf(imgStateOff)) + imgStateOn + imgFileExtension;
	        }
        }
    	
	    return imgSrc;
    },

    clearhidemenu:function(){
        if (this.delayhide!="undefined")
            clearTimeout(this.delayhide)
    },

    startchrome:function(){
        for (var ids=0; ids<arguments.length; ids++){
        var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
        for (var i=0; i<menuitems.length; i++){
            if (menuitems[i].getAttribute("rel")){
                var relvalue=menuitems[i].getAttribute("rel");
                var imageID=menuitems[i].getAttribute("imgID");
                menuitems[i].onmouseover=function(e){
                    var event=typeof e!="undefined"? e : window.event
                    cssdropdown.dropit(this,event,this.getAttribute("rel"),this.getAttribute("imgID"))
                }
            }
        }
    }
    }
}


function gosearch(absoluteURL)
{	
	var mf = GetMainFormName();		
	if (mf==null) return;
	var searchVal = document.forms[mf].elements["SearchKeywords"].value;
	searchVal = searchVal.toLowerCase();
	if (typeof(absoluteURL)!='undefined') {
	document.forms[mf].action=absoluteURL + "/search/index.aspx?SearchKeywords=" + searchVal;
	}
	else {
	document.forms[mf].action="/search/index.aspx?SearchKeywords=" + searchVal;
	}
	document.forms[mf].submit();
}	

function search_onfocus(el)
{
	var mf = GetMainFormName();
	if (mf==null) return;
	//el.value = '';
	document.forms[mf].target = "_top";
	document.forms[mf].action="/search/index.aspx?SearchKeywords=" + document.forms[mf].elements["SearchKeywords"].value;
}
function isEnter(e,absoluteURL)
{
	if (e.keyCode == 13)
	{		if (typeof(absoluteURL)!='undefined') {
		    gosearch(absoluteURL);
		   }
		   else {
		       gosearch();
		  }
	}	
	return true;
}

var SUBMIT_ID='ctl00$ctl00$brandlayout0$ctl00$mainbody0$ctl00$ctl03$ctl00$ctl00$submit';
var SUBMIT_ID_STEP1_CHECKOUT="ctl00$ctl00$brandlayout0$ctl00$mainbody0$ctl00$ctl04$ctl00$ctl00$submit";
                              
function SubmitForm_OnEnterPressed(e,buttonID) {
   if (e.keyCode == 13) {
          // var mf = GetMainFormName();
          //if (mf==null) return;
          //var _submitid=GetElementName(buttonID,mf);
          //__doPostBack(_submitid, '') ;
            __doPostBack(buttonID, '') ;
    }

}
function search_GoToURL(url)
{
	if (url!="") document.location.href= url;
}



function getswapimagesrc(img, imgState)
{
    var imgSrc = '';
    if (img != null)
    {
        var imgStateOn = "_on.";
        var imgStateOff = "_off.";
        imgSrc = img.src;
        var imgPathAndFileName = imgSrc.slice(0, imgSrc.lastIndexOf(".") + 1).toLowerCase();
        var imgFileExtension = imgSrc.slice(imgSrc.lastIndexOf(".") + 1, imgSrc.length);

        if (imgPathAndFileName.indexOf(imgStateOn) > 0 && imgState == 'off')
        {
	        imgSrc = imgPathAndFileName.slice(0, imgPathAndFileName.indexOf(imgStateOn)) + imgStateOff + imgFileExtension;
        }
        if (imgPathAndFileName.indexOf(imgStateOff) > 0 && imgState == 'on')
        {
	        imgSrc = imgPathAndFileName.slice(0, imgPathAndFileName.indexOf(imgStateOff)) + imgStateOn + imgFileExtension;
        }
    }
	
    img.src = imgSrc;
}


function HideQuickShopiIcon() {

   try {
             _QuickShop_Class.Hide();
             }
        catch (err) {
        
        }   

}

/* 
 * 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.value = textArea.value.substring(0, maxLength);
		textArea.focus();
	}			
}	

// turns on/off the MyDermablend DropDown Menu in the top nav.
   function  ToggleMyDermablendDropDown(display)
   {
   var dropDownMenu=document.getElementById('dropmenu1');  //$get('dropmenu1');
   if(display==true){   dropDownMenu.style.display='';}
   else{dropDownMenu.style.display='none';}
  } 
   
    // correctly handle PNG transparency in Win IE 5.5 & 6.
 //**Please note the size of the image is defined in the code
 function correctSinglePNG(thePNG) 
    {
       var arVersion = navigator.appVersion.split("MSIE")
       var version = parseFloat(arVersion[1])
        if ((version >= 5.5)&& (version < 7.0) && (document.body.filters))  {
      
             var img = thePNG;
             
             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
                //+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + " style=\"" + "width:100px;height:100px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='crop');\"></span>"; 
                img.outerHTML = strNewHTML;                 
             
             }
         
      }    
}

 // correctly handle PNG transparency in Win IE 5.5 & 6.
 function correctPNG() 
    {
       var arVersion = navigator.appVersion.split("MSIE")
       var version = parseFloat(arVersion[1])
         if ((version >= 5.5)&& (version < 7.0) && (document.body.filters)) 
       {
          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='crop');\"></span>"; 
                img.outerHTML = strNewHTML;
                i = i-1
             }
          }
       }    
    }
    
    
    function ToggleDropDowns(_visibility) {
      // to make a drop down to hide automatically, please ad the style.visibility
      // please DO NOT DO it for bubbles, only for defaulted drop down on a particula page.
       if (AJAX_IsIE6()) {
             //Drpw downs with style visibility
               GetAllSelects();
               for (var i=0; i < allVisibleSelects.length; i++) {
                 allVisibleSelects[i].style.visibility=_visibility;
              }
              //SHOPPING CART SUMMARY PAGE
               try {
             // var obj2=$get('SHOPPINGCART_LAYER_CONTAINER');
             var obj2 = document.getElementById('SHOPPINGCART_LAYER_CONTAINER');
             if (obj2!=null) {
                   var  allSelects = obj2.getElementsByTagName("select");
                    for (var i=0; i < allSelects.length; i++) {
                        allSelects[i].style.visibility=_visibility; 
                    }
             }
           }   
           catch(err) {}
       
             
       }
} 
function AJAX_IsIE6() {
  if (navigator.appName=='Microsoft Internet Explorer') {
      if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
         return true;
      }
  }
  return false;

}






