function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);title = args[i+1];
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+title+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+title+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+title+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+title+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.returnValue = (errors == '');
}
function readCookie() {
	//set null reference so we always have something to return
	var cookie = null;
	
	//if a cookie exists
	if(document.cookie)
	{
		//if it's our cookie
		if(document.cookie.indexOf('bodyColor')!=-1)
		{
			//extract and store relevant information (turning '#' back into spaces)
			cookie = document.cookie.split('bodyColor=');
			cookie = cookie[1].split(';');
			cookie = cookie[0];
		}
	}
	
	return cookie;
}
function writeCookie(value) {
	//format expiry date
	var date = new Date();
	date.setTime(date.getTime() + ( 30 *24*60*60*1000));
	
	//if the value is empty, set its expiry in the past to delete the cookie
	if(value == '') { date.setTime(0); }
	
	//create the cookie
	document.cookie = 'bodyColor=' + value
		+ '; expires=' + date.toGMTString() 
		+ '; path=/';
		
}

function getBody(nnm) {
	iframe = MM_findObj(nnm);
	if(iframe) {
		if(iframe.contentDocument)
	        doc = iframe.contentDocument; // For NS6
	    else if(iframe.contentWindow)
	        doc = iframe.contentWindow.document;
		return doc.getElementsByTagName('body').item(0);
	}
	return null;
}

var trans = '';
function changeColor(cl) {
	var b = MM_findObj('body');
	b.className = cl+' '+trans;
	writeCookie(cl);

	b = getBody('istatus');
	if(b != null) {
		b.className = cl+' trans';
		b = getBody('iplaylist');
		if(b != null) b.className = cl+' trans';
	}
	return false;
}
function doLoad(tr) {
	trans = tr||'';
	var color = readCookie();
	if(color == null) {
		// selecting random color
		var i = Math.ceil(Math.random()*3);
		if(i == 1)
			color = 'blue';
		else if(i == 2)
			color = 'orange';
		else
			color = 'green';
			
	}
	//changeColor(color);
}
