var docI= document.getElementById;
var docL= document.layers;
var docA= document.all;
var currentObj;var settime;var mainObj = new Object; var swapped = new Array();

function clearText(ref) {
  if(ref.value == ref.defaultValue) {
    ref.value = '';
  }
}

function getObj(ref){
  return ( (docI && document.getElementById(ref)) ? document.getElementById(ref) :
	   (docA && document.all[ref])            ? document.all[ref]            :
	   (docL && document.layers[ref])         ? document.layers[ref]         : null);
}

function swapImage(ref,sc) {
	swapped.push(ref);
	var obj = getObj(ref);
	if(!obj.oSrc) obj.oSrc = obj.src;
	obj.src = sc;
}

function resetImage(ref) {
	var obj = getObj(ref);
	if(!obj.oSrc) return;
	obj.src = obj.oSrc;
}

function ReDirect(ref) {
	var obj = getObj(ref);
	obj.autofilled.submit();
}

function makeVis(i,viz) {
	var obj = getObj(i);
	if (viz) {
		obj.style.display="block";
	} else {
		obj.style.display="none";
	}
}

function Switch(i) {
	var obj = getObj(i);
	visible=(obj.style.display!="none" && obj.style.display!='');
	if (visible) {
		obj.style.display="none";
	} else {
		obj.style.display="block";
	}
}

function openpopup(url,wid,hei) {
	if (typeof(popupWin)!="object") popupWin=window.open(url,"PU","status=1,scrollbars=1,width="+wid+",height="+hei);
	else
	{
		if (!popupWin.closed) popupWin.location.href=url;
		else popupWin=window.open(url,"PU","status=1,scrollbars=1,width="+wid+",height="+hei);
	}
	popupWin.focus();
}


function CheckConfirmation() {
	if(CheckMark(document.confirmation_form.agree)) {
		alert('You must Agree to the Terms and Conditions');
		return false;
	}
}

function CheckReg() {
	var errormessage = new String();
	if(document.regform.newusername.value.length < 5) { errormessage += "\n\nUsername must be atleast 5 characters long"; }
	if(document.regform.newpassword.value.length < 6) { errormessage += "\n\nPasswords must be atleast 6 characters long"; }
	if(document.regform.newpassword.value != document.regform.retypepassword.value) { errormessage += "\n\nPasswords do not match"; }
	if(document.regform.newemail.value != document.regform.retypeemail.value) { errormessage += "\n\nEmail addresses do not match"; }
	if(!CheckEmails(document.regform.newemail.value)) { errormessage += "\n\nEmail is not valid"; }
	if(errormessage.length > 2) {
		alert('Error(s):' + errormessage);
		return false;
	}
	return true;
}

function CheckUpdateReg() {
	var errormessage = new String();
	if(document.regform.newpassword.value.length < 6 && document.regform.newpassword.value.length != 0) { errormessage += "\n\nPasswords must be atleast 6 characters long"; }
	if(document.regform.newpassword.value != document.regform.retypepassword.value) { errormessage += "\n\nPasswords do not match"; }
	if(document.regform.newemail.value != document.regform.retypeemail.value) { errormessage += "\n\nEmail addresses do not match"; }
	if(!CheckEmails(document.regform.newemail.value)) { errormessage += "\n\nEmail is not valid"; }
	if(errormessage.length > 2) {
		alert('Error(s):' + errormessage);
		return false;
	}
	return true;
}

// Check Functions
function CheckContent(p) {
	if(p.length > 0) { return false; }
	return true;
}

function CheckMark(p) {
	if(p.checked) { return false; }
	return true;
}

function CheckAllMarks(p) {
	for(var i = 0; i < p.length; i++) {
		if(p[i].checked) { return false; }
	}
	return true;
}

function CheckSelection(p) {
	if(p.value != 0) { return false; }
	return true;
}

function CheckEmails(p) {
	var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(var i=0; i < p.length ;i++){
		if(ok.indexOf(p.charAt(i))<0){
			return false;
		}
	}

	if(p.indexOf("@")<0) {
		return false;
	}

	if(p.indexOf(".")<0) {
		return false;
	}

	return true;
}

function SingleSelection(p,t,n) {
  var sel = p.selectedIndex;
  var ops = p.options.length;
  var matched = new Array();
  var chosen = new Array();
  var unselected = new Array();
  
  var cnt = parseInt(document.getElementById('count').value,10) || 0;
  
  for(var i=1;i<=cnt;i++) {
    var ti = t+i;
    var e = document.getElementById(ti);
    if(e) {
      if((i != n) && (sel == e.selectedIndex)) matched.push(ti);
      chosen.push(e.selectedIndex);
    }
  }
  
  for(var i=0; i < ops; i++) {      // go through all options
    if(CheckUnique(chosen,i)) unselected.push(i);      // add to unselected
  }

  for(var i=0; i < matched.length; i++) {        // go through all the matched
    // change it to an unselected value
    document.getElementById(matched[i]).selectedIndex = unselected[i];
  }
}


function CheckUnique(ar,p) {      // match against any array
  for (i=0; i < ar.length; i++) {
    if (ar[i] == p) return false;
  }
  return true;
}

// versions of IE before 5.5 don't support Array.push() natively.
// You might want this for versions of IE before 5.5.
if(![].push){ // for old browsers that don't natively support Array.push()
  Array.prototype.push=function(){
    for(var i=0;i<arguments.length;i++) this[this.length]=arguments[i];
    return this.length;
  }
}

function swapImg(e,p) {
document.getElementById('mainImg').src = p;
}

var userAgent = window.navigator.userAgent;
var isIE6 = (parseFloat(userAgent.substring(userAgent.indexOf("MSIE ") + 5)) <= 6);

function writePngImage(url, width, height, alt) {
	if (!isIE6)
		document.write("<img src=\"" + url + "\" style=\"WIDTH: " + width + "px; HEIGHT: " + height + "px;\" alt=\"" + atl + "\">");
	else
		document.write("<img src=\"spacer.png\" style=\"WIDTH: " + width + "px; HEIGHT: " + height + 
			"px; FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\" alt=\"" + alt + "\">");
}

