// Switch Stylesheets
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;
    }
  }
}

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("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

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

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


// Switch Between 2 Stylesheets with Flip Flop Style based switch
function Smodeswap( type, myID, myClass, friendID, friendClass ){
	setActiveStyleSheet(type);
	document.getElementById(myID).className=myClass;
	document.getElementById(friendID).className=friendClass;
	}

// Switch Between 2 Stylesheets with Flip Flop image based switch
function Imodeswap( type, thisID, thisImg, thatID, thatImg ){
	setActiveStyleSheet(type);
	document.getElementById(thisID).src=thisImg;
	document.getElementById(thatID).src=thatImg;
	}

// Advanced Search Div Animation Functions
   //Mask the DOM
   if(document.layers) {
      pre = 'document.';
      post = '';
   }
   if(document.getElementById) {
      pre = 'document.getElementById("';
      post = '").style';
   }
   if(document.all) {
      pre = 'document.all.';
      post = '.style';
   }
   //Arrays
	var xPos = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0);
	var yPos = new Array(-350,-220,-160,-120,-80,-50,-30,-20,-15,-10,-6,-2,0);
	var yPosR = new Array(0,-50,-150,-250,-350,-350,-350,-350,-350,-350,-350,-350,-350);
      
   //Counters
   var currentX = 0;
   var currentY = 0;

   function animateDN() {
      //Return at end of arrays
      if(currentX > xPos.length - 1) {
         currentX = 0;
         currentY = 0;
         return;
      }
      //Move the DIV
      eval(pre + 'advsearch' + post).left = 
         parseInt(xPos[currentX]);
      eval(pre + 'advsearch' + post).top = 
         parseInt(yPos[currentY]);
      currentX++;
      currentY++;
      setTimeout('animateDN()',10);
   }
   
      function animateUP() {
      //Return at end of arrays
      if(currentX > xPos.length - 1) {
         currentX = 0;
         currentY = 0;
         return;
      }
      //Move the DIV
      eval(pre + 'advsearch' + post).left = 
         parseInt(xPos[currentX]);
      eval(pre + 'advsearch' + post).top = 
         parseInt(yPosR[currentY]);
      currentX++;
      currentY++;
      setTimeout('animateUP()',10);
   }

//Clear default Value onFocus
function clearDefault(el,clss) {
  if (el.defaultValue==el.value) el.value = ""
  // If CSS supported, clear the style
	if (el.style) el.className = clss
}


//Check content of txtKeywords on submit of search
function checktxtKeywords(fn,val){
if (document.forms[fn].txtKeywords.value == val){
	document.forms[fn].txtKeywords.value='';
	} else {
	}
}
