function setClass(obj, cl){
	if (obj.className!=cl) obj.className = cl;
}

function setClassById(objid, cl){
	if (!cl) cl = '';
	document.getElementById(objid).className = cl;
}

function changeDisplayById(objId){
	for (c = 0; c < changeDisplayById.arguments.length; c++){
		obj = document.getElementById(changeDisplayById.arguments[c]);
		if (obj.style.display == 'none') obj.style.display = 'block';
		else obj.style.display = 'none';
	}
}

function gotoURL(url){
	if (!url) url = "/";
	if (window.event){
		var src = window.event.srcElement;
		if((src.tagName != 'A') && ((src.tagName != 'IMG') || (src.parentElement.tagName != 'A'))){
			if (window.event.shiftKey) window.open(url);
			else document.location = url;
		}
	} else document.location = url;
}


function getLeftPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return res;
}

function getTopPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return res;
}

function chbCheckAll(formObj, checkName, checkVal){
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]')
			if (!el[count].disabled) el[count].checked = checkVal;
}

function chbExamAll(formObj, checkName, resName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	formObj.elements[resName].checked = (checkCount == boxCount);
}

function chbIsAllEmpty(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	return(checkCount == 0);
}

function chbIsOnlyOne(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++){
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	return(checkCount == 1);
}

function disableAll(){
	for (c1 = 0; c1 < document.forms.length;  c1++){
		var formElements = document.forms[c1].elements;
		for (c2 = 0; c2 < formElements.length;  c2++) formElements[c2].disabled = true;
	}
}


function CheckAll(checkName, checkVal)
{
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName + checkCount)
		{
			if (!el[count].disabled)
			{
				el[count].checked = checkVal;
			}
			checkCount++;
		}
	}
}

function ExamAll(checkName, resName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName + boxCount)
		{
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}
	
	if (document.forms[0].elements[resName])
	{
		document.forms[0].elements[resName].checked = (checkCount == boxCount);
	}
}

function chbIsAllEmpty(checkName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName + boxCount)
		{
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	
	return (checkCount == 0)
}

var selectedSheet='';


/*
 * Sets the style sheet passed by title.
 *
 *
*/
function setActiveStyleSheet(title) 
{
	
	try
	{
		
	 /* if (selectedSheet!=''){
		var widget = document.getElementById(selectedSheet+"on");
		widget.id=selectedSheet;
	  }*/
	  var i, a, main;
	  
	  if (!title.indexOf('null') == 0)
	  {
			for (i=0; (a = document.getElementsByTagName("link")[i]); i++) 
			{
				if (a.getAttribute("rel") &&
					a.getAttribute("rel").indexOf("style") != -1 &&
					a.getAttribute("title")) 
					{
					a.disabled = true;
					
						if(a.getAttribute("title") == title) 
						{
							a.disabled = false;
						}
					}
			}
			/*var widget = document.getElementById(title);
			widget.id=title+"on";*/
			
	  }
	  else
	  {
			title='default';
			/*var widget = document.getElementById(title);
			widget.id=title+"on";*/
	  } 
	
	}
	catch(e)
	{
	}
	selectedSheet=title;
	/*createCookie("style", title, 365);
	start();*/
		
}

/*
 * Gets the current sheet
 *
 *
*/
function getActiveStyleSheet() 
{
	
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title") &&
        !a.disabled
        ) return a.getAttribute("title");
  }
  return 'default';
}

/*
 * Gets the prefered sheet 
 * stored in the cookie. 
 *
*/
function getPreferredStyleSheet() 
{
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("rel").indexOf("alt") == -1 &&
        a.getAttribute("title")
        ) return a.getAttribute("title");
  }
  return null;
}

/*
 *
 * Helper function to create a cookie. 
 *
*/
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=/";
}


/*
 * Returns the cookie value of name
 *
 *
*/
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.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

