function setActiveStyleSheet(title){
var tags = document.getElementsByTagName("link");
var type, i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(title){
if(title.indexOf("fontSize") != -1){
type = "font";
}
if(title.indexOf("toggle") != -1){
type = "toggle";
}
if(type == "toggle"){
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("toggle") != -1){
a.disabled = true;
if(a.getAttribute("title") == title){
a.disabled = false;
}
}
}

if(type == "font"){
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("fontSize") != -1){
a.disabled = true;
if(a.getAttribute("title") == title){
a.disabled = false;
}
}
}

}
}

}

function getActiveToggle(){
var tags = document.getElementsByTagName("link");
var i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("toggle") != -1 && !a.disabled){
return a.getAttribute("title");
}
}
}

function getActiveFont(){
var tags = document.getElementsByTagName("link");
var i, a, title;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("fontSize") != -1 && !a.disabled){
return a.getAttribute("title");
}
}
}

function changeFontSize(arg){
var title, y;
var title = getActiveFont();
var x = title.split("fontSize")[1];
var direction = arg.split("fontSize")[1];
if(direction == "Up"){
if(x >= 3){
x = 2;
}
y = "fontSize" + (parseInt(x) + 1);
}

if(direction == "Down"){
if(x < 1){
x = 1;
}
else{
y = "fontSize" + (parseInt(x) - 1);
}
}
setActiveStyleSheet(y);
}

function getPreferredStyleSheet(){
var tags = document.getElementsByTagName("link");
var type, i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")){
return a.getAttribute("title");
}

}
}

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");
if(cookie){
var cookiesp = cookie.split('|');
var toggle = cookiesp[0];
var font = cookiesp[1];
setActiveStyleSheet(toggle);
setActiveStyleSheet(font);
}
else{
setActiveStyleSheet(getPreferredStyleSheet());
}
}

window.onunload = function(e){
var toggle = getActiveToggle();
var font = getActiveFont();
if(font == undefined){
font = null;
}
else{
font = font;
}
var titles = toggle+"|"+font;
createCookie("style", titles, 365);
}

var cookie = readCookie("style");
if(cookie){
var cookiesp = cookie.split('|');
var toggle = cookiesp[0];
var font = cookiesp[1];
setActiveStyleSheet(toggle);
setActiveStyleSheet(font);
}
else{
setActiveStyleSheet(getPreferredStyleSheet());
}

/*---------- Pop-up Message ----------*/
function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}
var popUpId = "popUp";
function showPopUp(whoClicked) {
    if (arguments.length == 2)
        popUpId = arguments[1];
    else
        popUpId = "popUp";
	var yPos =  findPosY(document.getElementById(whoClicked));
	var top = yPos - 50;
	var xPos = findPosX(document.getElementById(whoClicked));
	var left = xPos - 225;
	if (left < 30)
	    left = 30;
	    
	document.getElementById(whoClicked).onmouseout  = hidePopUp;
	document.getElementById(popUpId).className = "show";
	if(document.getElementById) {
		// for firefox
		document.getElementById(popUpId).setAttribute("style", "top:" + top + "px; left:" + left + "px;");
		// for IE
		document.getElementById(popUpId).style.top = top;
		document.getElementById(popUpId).style.left = left;
	}
	else {
		alert('no');
	}
}

function changeColor(newColor)
{
 elem = document.getElementById("para1");
 elem.style.color = newColor;
 elem.style.fontWeight = 'bold';

}

function hidePopUp(e) {
	document.getElementById(popUpId).className = "hide";
}

