/*
 *** This javascript library contains the methods for dealing with
 *** the display on the product lister page; list or grid
 *
 *  author: Mark B
*/


function setActiveStyleSheet(title) { 
  var i, link, links; 
  links = document.getElementsByTagName("link"); 
  for(i=0; i<links.length; i++) { 
    link = links[i]; 
    if(link.getAttribute("title") && link.getAttribute("rel").indexOf("style") != -1) { 
	  link.disabled = true; 
	  if(link.getAttribute("title") == title) link.disabled = false; 
    } 
  } 
} 


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(pCookieName) {
  var returnValue = "";
  var cookies = document.cookie.split(";");
  for (var i=0; i<cookies.length; i++) {
    var cookieCrumbs = cookies[i].split("=");
    var cookieName = cookieCrumbs[0];
    var cookieValue = cookieCrumbs[1];
    // if the first character of the cookie name is a space, strip it
    if (cookieName.indexOf(" ") == 0) {
	  cookieName = cookieName.substring(1, cookieName.length);
	}
    if (cookieName.toUpperCase() == pCookieName.toUpperCase()) {
      returnValue = cookieValue;		
    }
  }  
  return returnValue;
}


function switchActiveStyleSheet(name) {
	setActiveStyleSheet(name);
  	createCookie("PLPVIEWCOOKIE", name, 7);
}


var cookie = readCookie("PLPVIEWCOOKIE");
if (cookie != null && cookie == 'grid') {
	setActiveStyleSheet(cookie);
}


