// JavaScript for opening external links in XHTML document
/*function swapGraphic()
{
	var totalImages = 8;
	var evenOut = totalImages - 1;
    if (document.getElementById("swapImage") != null)
    {
        var rnd_no = 1 + Math.round(evenOut * Math.random());
        
        if (document.getElementById("swapImage") != null)
        {
            el = document.getElementById("swapImage");
            el.style.background = "url(/ksl/images/bkg_headerImg0"+ rnd_no +".jpg) no-repeat 0 0 #000";
        }
    }
	
}*/

function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

function fontSize(x) {
	Value = x;
	document.getElementById('fontSize1').className -= " activeSize";
	document.getElementById('fontSize2').className -= " activeSize";
	document.getElementById('fontSize3').className -= " activeSize";
	if(Value == 3){
		newSize = "122%";
		document.getElementById('fontSize3').className += " activeSize";
	}
	else if(Value == 2){
		newSize = "102%";
		document.getElementById('fontSize2').className += " activeSize";
	}
	else{
		newSize = "82%";
		document.getElementById('fontSize1').className += " activeSize";
	}
	document.getElementById('pageContainer').style.fontSize = newSize;
	matchColumns();
	setCookieFontSize(Value);
}

function setCookie(name, value)
{
  document.cookie =
    name+"="+escape(value) + ";expires=Tue, 01-Jan-2099 00:00:00 GMT;path=/;";
}
function Get_Cookie( name ) {      
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookieFontSize(x) {
	setCookie("fontSize", x);
}

function selectReplacement(obj) {
  document.getElementById('howDoIULList').style.display= "none";
  var ul = document.createElement('ul');
  ul.className = 'singleList';
    
  var opts = obj.childNodes;
  
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[0].firstChild.firstChild.nodeValue);
	li.appendChild(txt);
  
  li.onclick = function() {
	  if(document.getElementById('howDoIULList').style.display=="block"){document.getElementById('howDoIULList').style.display="none";}
	  else {document.getElementById('howDoIULList').style.display="block";}
  }
  
  
  ul.appendChild(li);
  obj.parentNode.insertBefore(ul,obj);
  
  /*obj.className += ' replaced';
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
 
  
  
  alert(opts[0].firstChild.firstChild);
	  
	  
  for (var i=0; i<opts.length; i++) {
	var selectedOpt;
	if (opts[i].firstChild.firstChild) {
	  selectedOpt = i;
	  break;
	} else {
	  selectedOpt = 0;
	}
  }
  
  
  for (var i=0; i<opts.length; i++) {
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[i].text);
	li.appendChild(txt);
	li.selIndex = opts[i].index;
	li.selectID = obj.id;
	li.onclick = function() {
	  selectMe(this);
	}
	if (i == selectedOpt) {
	  li.className = 'selected';
	  li.onclick = function() {
		this.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		}
	  }
	}
	if (window.attachEvent) {
	  li.onmouseover = function() {
		this.className += ' hover';
	  }
	  li.onmouseout = function() {
		this.className = 
		  this.className.replace(new RegExp(" hover\\b"), '');
	  }
	}
	
  }
  obj.parentNode.insertBefore(ul,obj);*/
}
function selectMe(obj) {
  var lis = obj.parentNode.getElementsByTagName('li');
  for (var i=0; i<lis.length; i++) {
	if (lis[i] != obj) {
	  lis[i].className='';
	  lis[i].onclick = function() {
		selectMe(this);
	  }
	} else {
	  setVal(obj.selectID, obj.selIndex);
	  obj.className='selected';
	  obj.parentNode.className = 
		obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
	  obj.onclick = function() {
		obj.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		}
	  }
	}
  }
}
function setVal(objID, selIndex) {
  var obj = document.getElementById(objID);
  obj.selectedIndex = selIndex;
}


function setForm() {
  var s = document.getElementById('howDoIULList');
  if(s = document.getElementById('howDoIULList')){selectReplacement(s);}
}
	

function addMattesAndShadows() {

/*

1. Get all the imgs in the document.
2. Step through the imgs, identifying the shadow ones. (Hi, DOM guys?
   A getElementByCSSSelector functon would kick ass. Kay? Thanks.)
3. For each img of class shadow:
   a. Create a new div node of class shadow.
   b. Set the width of the new node to the width of the img plus a little
      extra to accommodate the matte we’re adding.
   c. Add a clone of the img to the new div as a child.
   d. Create the four corner divs and add them to the new div as children.
   e. Replace the img with the new shadow div.

I’m going to identify each step as I go, so if you see something that doesn’t
make sense, just look for the closest number.

*/

  /* 1. */
  var imgs = document.getElementsByTagName("img");

  /* 2. */
  for (var i = 0; i < imgs.length; i++) {
	  
    var thisImg = imgs[i];
    var isShadow = false;
    var extraWidth = 14;
	
	
    /* A word about extraWidth. This value represents the width of the white
       matte we’re adding around our shadowed images. I like a five-pixel
       matte, hence extraWidth equals ten.

       Yes, it’s lame to hard-code the matte into both the CSS and the
       JavaScript. We are, in fact, just asking for trouble by doing it this
       way. But after literally tens of seconds of intense thought, I failed
       to come up with a more clever solution. If you feel like tackling
       it, knock yourself out. Since I’m only applying one kind of matte
       per site-wide instance of this technique, I really don’t care. */


      /* First we’ll tokenize the className, since classes can have multiple
         space-separated values. */

      var classTokens = thisImg.className.split(' ');
      for (var j = 0; j < classTokens.length; j++) {
        var thisToken = classTokens[j];
        if (thisToken == "shadow" || thisToken == "shadow-alignCenter" || thisToken == "shadow-alignLeft" || thisToken == "shadow-alignRight") {
          isShadow = true; 
		  thisImg.className = ""; 
		  
				checkHeight = parseInt(imgs[i].height)

				if (checkHeight == 0)
				   {
				   }
				else if (checkHeight%2)
				   {
				   newHeight = imgs[i].height+1;
				   }
				else
				   {
				   newHeight = imgs[i].height
				   }
				   
				imgs[i].height = newHeight;
				
				
				
				checkWidth = parseInt(imgs[i].width)
				
				if (checkWidth == 0)
				   {
				   }
				else if (checkWidth%2)
				   {
				   newWidth = imgs[i].width
				   }
				else
				   {
				   newWidth = imgs[i].width+1;
				   }
				   
				imgs[i].width = newWidth
		  
        if (thisToken == "nomatte") {
          extraWidth = 0;
		}
		  
      }

      /* If thisImg is a shadow image … um  apply the shadow. Duh. */
      /* 3. */
      if (isShadow) {

        /* 3a. */
        var shadowDiv = document.createElement('div');
		if (thisToken == "shadow"){
        shadowDiv.className = 'shadow';		
		}
		if (thisToken == "shadow-alignCenter"){
        shadowDiv.className = 'shadow-alignCenter';		
		}
		if (thisToken == "shadow-alignLeft"){
        shadowDiv.className = 'shadow-alignLeft';		
		}
		if (thisToken == "shadow-alignRight"){
        shadowDiv.className = 'shadow-alignRight';		
		}

        /* Yes, you can use setAttribute, but this way works in IE too. */

        /* 3b. */
        shadowDiv.style.width = (thisImg.width + extraWidth) + "px";

        /* 3c. */
        if(imgs[i].parentNode.tagName=="A"){
			
			shadowDiv.appendChild(thisImg.parentNode.cloneNode(false)).appendChild(thisImg.cloneNode(false));
			//linkA.style.height=imgs[i].height;
		}
		else{
			shadowDiv.appendChild(thisImg.cloneNode(false));
		}
        /* Img elements can’t have children in HTML, so no need for a deep
           clone. That’s what the “false” argument means. Stupid C-like
           non-named-arguments having JavaScript syntax. */

        /* 3d. */
        var topLeft = document.createElement('div');
        topLeft.className = "topleft";
        shadowDiv.appendChild(topLeft);

        var topRight = document.createElement('div');
        topRight.className = "topright";
        shadowDiv.appendChild(topRight);

        var bottomLeft = document.createElement('div');
        bottomLeft.className = "bottomleft";
        shadowDiv.appendChild(bottomLeft);

        var bottomRight = document.createElement('div');
        bottomRight.className = "bottomright";
        shadowDiv.appendChild(bottomRight);


		tContent = shadowDiv.innerHTML;
		var newDivOpen = "<div class='left'>";
		var newDivClose = "</div>"
		shadowDiv.innerHTML = newDivOpen + tContent + newDivClose;

		tContent = shadowDiv.innerHTML;
		newDivOpen = "<div class='right'>";
		newDivClose = "</div>"
		shadowDiv.innerHTML = newDivOpen + tContent + newDivClose;


		/* 3e. */
        thisImg.parentNode.replaceChild(shadowDiv, thisImg);

      }

    }

  }

}
function blockQuoteStyle() {
	if (!document.getElementsByTagName("blockquote")) return;
	var blockQuotes = document.getElementsByTagName("blockquote");
	for (var i=0; i<blockQuotes.length; i++) {
	   blockQuotes[i].style.backgroundImage = "url(/ksl/images/curveBlockquote_top.gif)";
	   blockQuotes[i].style.marginBottom = 0;
	   
	   tContent = blockQuotes[i].innerHTML;
	   var newSpan02 = "<span class='BQ_bottom'></span>";
	   blockQuotes[i].innerHTML = tContent + newSpan02;
	}
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}


function homeSearchBoxStyle() {
	var hideLabels = document.getElementById("homeSearchContainer").getElementsByTagName("label");
	for (var i=0; i<hideLabels.length; i++) {
		if(hideLabels[i].className == "hideContent") {
			hideLabels[i].style.display = "none"; 
		}	
	}
	//document.getElementById("searchKSLSite").style.display = "none";
	//document.getElementById("searchCatalog").style.display = "none";
	//document.getElementById("searchOther").style.display = "none";

	/*allLinks = document.getElementById("homeSearchNav").getElementsByTagName("li");
	for (var i=0; i<allLinks.length; i++) {
		allLinks[i].onmouseover=function() {
			this.className+=" hoverSearchLink";
		}
		allLinks[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hoverSearchLink\\b"), "");
		}
	}*/
}

function changeSearchBoxes(searchID, linkChange) {
	document.getElementById("searchEverything").style.display = "none";
	document.getElementById("searchKSLSite").style.display = "none";
	document.getElementById("searchCatalog").style.display = "none";
	document.getElementById("searchOther").style.display = "none";

	document.getElementById(searchID).style.display = "block";
	
	allLinks = document.getElementById("homeSearchNav").getElementsByTagName("li");
	for (var i=0; i<allLinks.length; i++) {
			allLinks[i].className = ""; 
		}	
	linkChange.parentNode.className = "activeLink";
}

function imageListControls() {
	
	var imageListArray = new Array()
	allImages = document.getElementById("imagesListForArray").getElementsByTagName("img");
	for (var i=0; i<allImages.length; i++) {
		imageListArray[i] = allImages[i].getAttribute('src'); 
	}	
	var imageLinkArray = new Array()
	allLinks = document.getElementById("imagesListForArray").getElementsByTagName("a");
	for (var i=0; i<allLinks.length; i++) {
		imageLinkArray[i] = allLinks[i].getAttribute('href'); 
	}
	//alert(imageListArray)
	
	var currentImg = 0;
	var currentLink = 0;
	
	thisImage = document.getElementById("homeImageListContainer").getElementsByTagName("img")[0];
	thisImage.setAttribute('src',imageListArray[0]);
	thisLink = document.getElementById("homeImageListContainer").getElementsByTagName("a")[0];
	thisLink.setAttribute('href',imageLinkArray[0]);
	
	NextLink = document.getElementById("homeImageListContainer").getElementsByTagName("ul")[1].getElementsByTagName("li")[1].getElementsByTagName("a")[0];
	NextLink.onclick = function() {
		currentImg += 1;
		if(currentImg > allImages.length - 1){
			currentImg = 0;
		}
		thisImage.setAttribute('src',imageListArray[currentImg]);

		currentLink += 1;
		if(currentLink > allLinks.length - 1){
			currentLink = 0;
		}
		thisLink.setAttribute('href',imageLinkArray[currentLink]);

	}
	
	PreviousLink = document.getElementById("homeImageListContainer").getElementsByTagName("ul")[1].getElementsByTagName("li")[0].getElementsByTagName("a")[0];
	PreviousLink.onclick = function() {
		currentImg -= 1;
		if(currentImg < 0){
			currentImg = allImages.length - 1;
		}
		thisImage.setAttribute('src',imageListArray[currentImg]);
		
		currentLink -= 1;
		if(currentLink < 0){
			currentLink = allLinks.length - 1;
		}
		thisLink.setAttribute('href',imageLinkArray[currentLink]);
	}
	
	//for (var i=1; i<allImages.length; i++) {
		//allImages[i].style.display = "none"; 
	//}
}

function EmailPage()
{
    var strPath = URLencode(document.URL);
    var strTitle = URLencode(document.title);
    var strUrl = '/ksl/Email_SendLink.aspx?SendUrl=' + strPath + '&Title=' + strTitle;
    window.open(strUrl,'',
        'height=420,width=390,toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=no,directories=no,location=no');
}

/* Description: escape() encodes most of the stuff you need to encode. It misses single and double 
 * quotes, so you should replace those manually.
 * Params: sStr - The string to be encoded
 * Returns: The encoded string
 */
function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }

/* Description: This function allows us to indicate links as external using rel="external"
 * instead of the deprecated target="_blank", but achieve the same effect
 */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}


// JavaScript for suckerfish drop-downs <http://www.htmldog.com/articles/suckerfish/>
sfHover = function(menu) {
	var mnuEl = document.getElementById(menu);
	if (mnuEl != null) {
		var sfEls = mnuEl.getElementsByTagName("LI");
		for (var i = 0; i < sfEls.length; i++) {
			sfEls[i].onmouseover = function() {
				this.className += " sfhover";
			}
			sfEls[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}

		var sfEl = document.getElementById(menu).getElementsByTagName("A");
		for (var i = 0; i < sfEl.length; i++) {
			if (sfEl[i].nextSibling != null && sfEl[i].nextSibling.nodeName == "UL") {
				if (sfEl[i].nextSibling.childNodes[0] != null) {
					sfEl[i].className += " hasChild";
				}
			}
		}
	}
	/*var sfEls = document.getElementById("navQuickLinks").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {
	this.className+=" sfhover";
	}
	sfEls[i].onmouseout=function() {
	this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	}
	}*/
}

matchColumns=function(){
     var divs,contDivs,maxHeight,divHeight,d;  
     // get all <div> elements in the document
     divs=document.getElementsByTagName('div');
     contDivs=[];
     // initialize maximum height value
     maxHeight=0;
     // iterate over all <div> elements in the document
     for(var i=0;i<divs.length;i++){
          // make collection with <div> elements with class attribute 'container'
          if(/\bcolumnHome\b/.test(divs[i].className)){
                d=divs[i];
                contDivs[contDivs.length]=d;
				divs[i].style.minHeight = 0+'px';
                // determine height for <div> element
                if(d.offsetHeight){
                     divHeight=d.offsetHeight;                                 
                }
                else if(d.style.pixelHeight){
                     divHeight=d.style.pixelHeight;                                     
                }
                // calculate maximum height
                maxHeight=Math.max(maxHeight,divHeight);
          }
     }
     // assign maximum height value to all of container <div> elements
     for(var i=0;i<contDivs.length;i++){
         contDivs[i].style.minHeight=maxHeight + "px";
     }
	  if ('function' == typeof window.matchColumnsIE6) {
		   matchColumnsIE6()
		 } 
	 //if(matchColumnsIE6() == typeof window.noFunc ){ matchColumnsIE6(); }
}
//pgFAQ

function activeTabs(thisItem){
	if(document.getElementById(thisItem)!=null) {
		var links=document.getElementById(thisItem).getElementsByTagName("A");
		for(x = 0;links.length>x;x++){
			if(links[x].className=="activelink"	){
				links[x].parentNode.className = "activelink";
			}
		}
		sfHover(thisItem)
	}
}

function firstLinkFooter(){
	document.getElementById("footerNav").getElementsByTagName("LI")[0].className = "firstLink";
}


