addEvent(window, "load", setStyleSheet);
addEvent(window, "unload", setStyleCookie);

function setStyleSheet() {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

function setStyleCookie() {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}


/* addEvent & remove Event from Scott Andres */
function addEvent(obj,evType,fn,useC){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,useC);
		return true;
	}
	else if(obj.attachEvent)
	{
		var r=obj.attachEvent("on"+evType,fn);
		return r;
	}
	else
		return false;
}

function removeEvent(obj,evType,fn,useC) {
  if(obj.removeEventListener){
    obj.removeEventListener(evType,fn,useC);
	return true;
  }
  else if(obj.detachEvent) {
    var r=obj.detachEvent("on"+evType,fn);
	return r;
  }
  else
    return false;
}


/*  opens a new window with parameters */
var objWin = null;
function NewWindow(thepageurl,thename,w,h,l,t,toolbar,location,directories,statusbar,resize,menubar,scroll,copyhistory) {
	LeftPosition = l;
	TopPosition = t;
	if (l == 'center')
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;

	if (t == 'center')
		TopPosition = (screen.height) ? (screen.height-h)/4 : 0;

	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',status='+statusbar+',toolbar='+toolbar+',location='+location+',directories='+directories+',menubar='+menubar+',copyhistory='+copyhistory;
	objWin = window.open(thepageurl,thename,settings);
	if(objWin.focus){objWin.focus();}
}

function accessibleFormField(id){
	var obj0 = document.getElementById(id);
	if(obj0) {

		obj0.onfocus= function() {this.className+=' inwork'; this.select();}
		obj0.onblur = function() {
			  this.className = this.className.replace(/\sinwork/, '');
			  if (this.value=="") {this.value=this.defaultValue;}
			  this.value=this.value;
		}
	}
}

