// from Mike Industries
// http://www.mikeindustries.com/blog/scripts/common-20060417.js


var HOST = 'hds.com';
//var HOST = '202.164.52.201';



function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;

}


function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
	var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
	
    if (cookieStartIndex == -1)
	        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        {
		cookieEndIndex = c.length;
		return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
		}
}
//Function to set cookies enabled from 30July2007
function getCookie(name){ 
var re=new RegExp(name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
	{
	return document.cookie.match(re)[0].split("=")[1] //return its value
	}
return ""
}
//cookies functin ends 
function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

// BEGIN STYLESWITCHER SCRIPTS

  var now = new Date();
  fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

function setActiveStyleSheet(title) {
  setCookie('style', title, now, '/', HOST, '');
  var selfhref = self.location.href;
  if (selfhref.indexOf('#') > -1) {
     var selfhref_array = selfhref.split('#');
     self.location.replace(selfhref_array[0]+'?styleswitch');
  } else {
     self.location.replace(selfhref);
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) {
		
		return a.getAttribute("title");
	}
  }
  return null;
}


var cookie = getCookie("style");

var currentstyle = cookie;

var title = cookie ? cookie : getPreferredStyleSheet();

  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
	       if(a.getAttribute("title") == title) 
		   {
			   a.disabled = false;}

    }
  }

// END STYLE SWITCHER SCRIPTS