/* Javascript for Ramprasad's Webpages */
/* Functions defined for a Style Switcher*/
/* Implements a pulldown menu for listing the styles*/
/* Reloads the page with the new style */
/* Sets a cookie with the preferred style to make it persist across all RamPages

/* Author: RamV (bitsnpixels@gmail.com)
/* Created: 28 Mar 2005 */

/*
This page design file is shared under a 
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 license. 
http://creativecommons.org/licenses/by-nc-sa/2.5/
If you use this in your work, please let me know by e-mail. 
*/

/*
Function List
	function pulldown(id,flag)
	function switchImages(title)
	function setActiveStyleSheet(title)
	function getActiveStyleSheet()
	function getPreferredStyleSheet()
	function createCookie(name,value,days)
	function readCookie(name)

Event Listeners
	window.onload
	window.onunload
*/


function pulldown(id,flag) {
var d = document.getElementById(id);
if (d){
	if (flag==0) {d.style.display='none';}
	if (flag==1) {d.style.display='block';}
	}
}

function switchImages(title) 
{
  imgName = "imgPgTitle";
  imgWidth = new Array("404","404","404","233","404");
  imgHeight = new Array("52","52","52","30","52");
  
  imgSrc = loc+Pg+"Logo"+title+".png";
  var d = document.getElementById(imgName);
  if (d) { d.src = imgSrc; d.width = imgWidth[title-11]; d.height = imgHeight[title-11]; }
}

function setActiveStyleSheet(title) 
{
  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;
		  switchImages(title);
	  }
  }
}}

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;
}

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(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("rampage");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  pulldown('smenu',0);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("rampage", title, 30);
}

var cookie = readCookie("rampage");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);