
var selectedTabName = "";
/*yes*/
// -- Simplified Image Swap
function swap(imgName, imgSrc){
	if (selectedTabName!=imgName){
		document[imgName].src = imgSrc;
	}
}
/*yes*/
function RefreshAllFrames(SessionID, urlsidebar, urlmainpage){
//	parent.frames["Main_" + SessionID].location.href = urlmain;
	if (urlmainpage.length ==0){
		parent.frames["Main_" + SessionID].location.reload();
	}else{
		parent.frames["Main_" + SessionID].location.href = urlmainpage;
	}
	if (urlsidebar.length==0){
		parent.frames["AdminNav_" + SessionID].location.reload();
	}else{
		parent.frames["AdminNav_" + SessionID].location.href = urlsidebar;
	}
}
/*yes*/
function RefreshRightFrame(SessionID, urlmainpage){
//	parent.frames["Main_" + SessionID].location.href = urlmain;
	if (urlmainpage==0){
		parent.frames["Main_" + SessionID].location.reload();
	}else{
		parent.frames["Main_" + SessionID].location.href = urlmainpage;
	}
}
/*no*/
// window popup
function popWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
/*no*/
// simple window popup
function simplePopup(theURL) {
  window.open(theURL,'window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=760,height=450,left=10,top=10');
}
/*no*/
function imagePopup(theURL) {
  window.open(theURL,'window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=400,left=10,top=10');
}
/*Show go into Toyota racing js*/
// homepage tab DOM compliant switcher
function showItem(selectedItem){
	for (i=0; i < tabbedresultsitem.length; i++){
		if(document.all) {
			document.all(tabbedresultsitem[i]).style.display = 'none';
			document.all("tabbedresultsimage_" + i).src = "images/" + tabbedresultsimage[i] + "Out.gif";
		}else {
			document.getElementById(tabbedresultsitem[i]).style.display = 'none';
			document.getElementById("tabbedresultsimage_" + i).src = "images/" + tabbedresultsimage[i] + "Out.gif";
		}
	}
	
	selectedTabName = "tabbedresultsimage_" + selectedItem;
	if(document.all) {
		document.all(tabbedresultsitem[selectedItem]).style.display = '';
		document.all(selectedTabName).src = "images/" + tabbedresultsimage[selectedItem] + "Over.gif";
	}else if(document.getElementById(tabbedresultsitem[selectedItem])) {
		document.getElementById(tabbedresultsitem[selectedItem]).style.display = '';
		document.getElementById(selectedTabName).src = "images/" + tabbedresultsimage[selectedItem] + "Over.gif";
	}
}

/*Show go into Toyota racing js*/			
function hideItem(){
	for (i=0; i < item.length; i++){
		if(document.all) {
			document.all(item[i]).style.display = 'none';
		}
		else {
			document.getElementById(item[i]).style.display = 'none';
		}
	}
}

/*Show go into Toyota racing js*/
// prevent right clicking
function noRightClick() {
	var message=" All images and copy on this site are property of Toyota New Zealand Limited.\n To request permission to use any of this site's content please contact:\n webmaster@toyotaracing.co.nz ";

	function click(e) {
	if (document.all) {
	   if (event.button == 2) {
		  alert(message);
	      return false;
	    }
	}

	if (document.layers) {
	   if (e.which == 3) {
		alert(message);
		return false;
	   }
    }
	}

    if (document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
	}

    document.onmousedown=click;
}
/*Show go into Toyota racing js*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*Show go into Toyota racing js*/
var item = new Array();
item[0] = 'tabMenuSchedule';
item[1] = 'tabMenuResults';
item[2] = 'tabMenuDriverPts';


//==============================================================================
//*FILENAME	-: crushernet.js
//*VERSION	-: 1.00.001
//*DESCRIPTION	-: Crusher.net Javascript funcitons
//==============================================================================

isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
/*yes admin.js?*/
/* Toggles the Highlight on the Button rollovers */
function toggleHighlight(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        var elem
        if (evt.target) {
            if (evt.target && (evt.currentTarget != evt.target)) {
                elem = evt.target
            } else {
                elem = evt.currentTarget
            } 
        } else {
            elem = evt.srcElement
        }
        if(elem != null){
            if (elem.className == 'bton' || elem.className == 'btoff' ) {
              elem.className = (evt.type == 'mouseover') ? 'bton' : 'btoff'
            }
		    if (elem.className == 'btwhiteon' || elem.className == 'btwhiteoff' ) {
              elem.className = (evt.type == 'mouseover') ? 'btwhiteon' : 'btwhiteoff'
            }
        }
    }
}
document.onmouseout = toggleHighlight;
document.onmouseover = toggleHighlight;

/*yes*/
function toggleDisplay(tagID)  {
	if (document.getElementById(tagID).style.display == 'none') 
	{
		document.getElementById(tagID).style.display = '';
	}
	else
	{
		document.getElementById(tagID).style.display = 'none';
	}
}
/*yes*/
function toggleOption(object)  {
	if (object.checked!='undefined'){
		object.checked==!object.checked;
	}
}
/*yes*/
function check_toggle(frm_object,value){
	for(i=0;i< frm_object.length;i++){
		e=frm_object.elements[i];
		if (e.type=='checkbox' ) e.checked=value;
	}
}
/*yes*/
function TreeToggle(node){
	//'==============================================================================
	//'*FUNCTION NAME	-: TreeToggle
	//'*DESCRIPTION		-: Toggles a tree element open or closed
	//'==============================================================================
	var oNode=node;
	do{
		oNode = oNode.nextSibling;
	}while (oNode.nodeName != 'DIV' )

	var str = node.firstChild.src;

	if (oNode.style.display == 'none'){
		if (node.childNodes.length > 0){
			str = str.substring(0,str.indexOf('plus.gif')) + 'minus.gif';
			if (node.firstChild.tagName == 'IMG') node.firstChild.src = str;
		}
		oNode.style.display = '';
	}else{
		if (node.childNodes.length > 0){
			str = str.substring(0,str.indexOf('minus.gif')) + 'plus.gif';
			if (node.firstChild.tagName == 'IMG') node.firstChild.src = str;
		}
		oNode.style.display = 'none';
	}
}
/*yes admin?*/
function Validator(frmname){
  this.formobj=document.forms[frmname];
	if(!this.formobj)	{
	  alert("BUG: could not get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}else{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}

function set_addnl_vfunction(functionname){
  this.formobj.addnlvalidation = functionname;
}

function clear_all_validations(){
	for(var itr=0;itr < this.formobj.elements.length;itr++)	{
		this.formobj.elements[itr].validationset = null;
	}
}

function form_submit_handler(){
	for(var itr=0;itr < this.elements.length;itr++)	{
		if(this.elements[itr].validationset && !this.elements[itr].validationset.validate()){
		  return false;
		}
	}
	if(this.addnlvalidation){
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
	  if(!ret) return ret;
	}
	return true;
}

function add_validation(itemname,descriptor,errstr){
	if(!this.formobj){
	  alert("BUG: the form object is not set properly");
	  return;
	}
	var itemobj = this.formobj[itemname];
	if(!itemobj){
	  alert("BUG: Could not get the input object named: " + itemname);
	  return;
	}
	if(!itemobj.validationset){
	  itemobj.validationset = new ValidationSet(itemobj);
	}
	itemobj.validationset.add(descriptor,errstr);
}

function ValidationDesc(inputitem,desc,error){
	this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}

function vdesc_validate(){
 if(!V2validateData(this.desc,this.itemobj,this.error)) {
	if (this.itemobj.visible){
		this.itemobj.focus();
	}
	return false;
 }
 return true;
}

function ValidationSet(inputitem){
	this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}

function add_validationdesc(desc,error){
	this.vSet[this.vSet.length] = new ValidationDesc(this.itemobj,desc,error);
}

function vset_validate(){
	for(var itr=0;itr<this.vSet.length;itr++){
	   if(!this.vSet[itr].validate()){
	      return false;
	   }
	}
	return true;
}

function validateEmailv2(email){
	if(email.length <= 0){
	   return true;
	}
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null ){
	   var regexp_user=/^\"?[\w-_\.]*\"?$/;
	   if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null){
	   var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
	   if(splitted[2].match(regexp_domain) == null) {
	      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	      if(splitted[2].match(regexp_ip) == null) return false;
	   }
	   return true;
	}
	return false;
}

function V2validateData(strValidateStr,objValue,strError){ 
	var epos = strValidateStr.search("="); 
	var  command  = ""; 
	var  cmdvalue = ""; 
	if(epos >= 0){ 
	   command  = strValidateStr.substring(0,epos); 
	   cmdvalue = strValidateStr.substr(epos+1); 
	} else { 
	   command = strValidateStr; 
	} 
	switch(command){ 
	   case "chk":{
	      if(eval(objValue.checked) == 0){ 
	         if(!strError || strError.length ==0){ 
	            strError = objValue.name + " : Please tick to submit."; 
                 }
                 alert(strError); 
                 return false; 
	      }
          break;             
       }
       case "req": 
       case "required": { 
		  if(eval(objValue.value.length) == 0){ 
             if(!strError || strError.length ==0){ 
                strError = objValue.name + " : Please complete this information"; 
             }
             alert(strError); 
             return false; 
          }
          break;             
        }
        case "maxlength": 
        case "maxlen":{ 
           if(eval(objValue.value.length) >  eval(cmdvalue)){ 
              if(!strError || strError.length ==0){ 
                  strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
              } 
              alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
              return false; 
           } 
           break; 
        }
        case "minlength": 
        case "minlen":{ 
            if(eval(objValue.value.length) <  eval(cmdvalue)){ 
               if(!strError || strError.length ==0){ 
                   strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
            }
            break; 
        }
        case "alnum": 
        case "alphanumeric":{ 
            var charpos = objValue.value.search("[^A-Za-z0-9]"); 
            if(objValue.value.length > 0 &&  charpos >= 0){ 
                if(!strError || strError.length ==0){ 
                    strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
            }
            break; 
        }
        case "num": 
        case "numeric":{ 
            var charpos = objValue.value.search("[^0-9]"); 
            if(objValue.value.length > 0 &&  charpos >= 0){ 
                if(!strError || strError.length ==0){ 
                  strError = objValue.name+": Only digits allowed "; 
                }
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
            }
            break;               
        }//numeric 
        case "alphabetic": 
        case "alpha":{ 
            var charpos = objValue.value.search("[^A-Za-z]"); 
            if(objValue.value.length > 0 &&  charpos >= 0){ 
                if(!strError || strError.length ==0){ 
                    strError = objValue.name+": Only alphabetic characters allowed "; 
                }
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
            }
            break; 
        }
		case "alnumhyphen":{
            var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
            if(objValue.value.length > 0 &&  charpos >= 0){ 
                if(!strError || strError.length ==0){ 
                    strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
            }
			break;
		}
        case "email":{ 
            if(!validateEmailv2(objValue.value)){ 
               if(!strError || strError.length ==0){ 
                    strError = objValue.name+": Enter a valid Email address "; 
               }
               alert(strError); 
               return false; 
            }
            break; 
        }
        case "lt": 
        case "lessthan":{ 
            if(isNaN(objValue.value)){ 
                alert(objValue.name+": Should be a number "); 
            return false; 
            }
            if(eval(objValue.value) >=  eval(cmdvalue)) { 
              if(!strError || strError.length ==0){ 
                 strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }
              alert(strError); 
              return false;                 
            }
            break; 
        }
        case "gt": 
        case "greaterthan":{ 
            if(isNaN(objValue.value)){ 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }
            if(eval(objValue.value) <=  eval(cmdvalue)){ 
               if(!strError || strError.length ==0){ 
                   strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }
               alert(strError); 
               return false;                 
            }
            break; 
        }
        case "regexp":{ 
		 	if(objValue.value.length > 0){
	            if(!objValue.value.match(cmdvalue)){ 
	              if(!strError || strError.length ==0){ 
	                strError = objValue.name+": Invalid characters found "; 
	              }
	              alert(strError); 
	              return false;                   
	            }
			}
            break; 
        }
        case "dontselect":{ 
            if(objValue.selectedIndex == null){ 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)){ 
				if(!strError || strError.length ==0){ 
				strError = objValue.name+": Please Select one option "; 
				}
				alert(strError); 
				return false;                                   
            } 
            break; 
        }
    }
    return true; 
}

function ValidateDate_InputOnFocus() {
    var ele = this;
    if(!ele) return;
    
    ele.value = "";
    ele.style.color = ele.originalTextColor;
    ele.onfocus = null;
}

function ValidateDate(csIds) {
    if(!typeof csIds === 'string') return false;
    if(csIds.length == 0) return true;
    
    var isSuccess = true;

    var ids = csIds.split(",");
    for(var i = 0, ci = ids.length; i < ci; i++) {
        var ele = document.getElementById(ids[i]);
        if(!ele || !ele.value) continue; //element not found - assume developer error and ignore
        
        var value = ele.value;
        if(value.length == 0) continue; //empty is ok.

        var parsedDate = Date.parse(value);
        
        if(parsedDate != null) {
            ele.value = parsedDate.toString("dd/MM/yyyy");
            continue; //date is okay so look at the next one
        }
        
        ele.originalTextColor = ele.style.color;
        ele.style.color = "red";
        ele.value = "Invalid Date";
        ele.onfocus = ValidateDate_InputOnFocus;
        
        isSuccess = false;
    }

    return isSuccess;
}
function deleteconfirm() {
	return confirm('Are you sure you want to Delete this?\n\r\n\rBEWARE: You cannot undo this operation!');
}

function approveconfirm() {
	return confirm('Are you sure you want to Approve this article?\n\r\n\rBEWARE: This operation will overwrite the current \'Live\' information!');
}

/*
	Image swap for Bliss-Stick product pages:
*/
function MM_findObj(n, d) 
{ //v4.01
  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 && d.getElementById) 
  		x=d.getElementById(n);
  return x;
}

function MM_swapImage()
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
   	document.MM_sr[j++]=x; 
   	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
   }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a && i<a.length && (x=a[i]) && x.oSrc; i++)
  	x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//used by feedback form
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    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+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

//Fix for IE 6 and below. Divs appear behind SELECT form elements...
//These were used in Horizons
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ShowIFrameShim(div)
{
	if (needsIEFix()) 
	{
	    var local_div = div;
	    var tt = function()
	    {
	        ShowIFrameShim2(local_div);
	    }
	    setTimeout(tt, 1);
	}
}

function ShowIFrameShim2(div)
{	    
	var iframe = document.createElement('iframe');
	iframe.setAttribute( 'src', 'javascript:false;document.write("");' );
	iframe.setAttribute( 'frameBorder', '0' );
	iframe.className = "ie_overlay_iframe";

	if (div.parentNode) 
		div.parentNode.appendChild(iframe);
	else
		document.body.appendChild(iframe);

	iframe.style.top = div.offsetTop;
	iframe.style.left = div.offsetLeft;
	iframe.style.width = (div.clientWidth) + "px";
	iframe.style.height = (div.clientHeight) + "px";
	iframe.style.zIndex = div.style.zIndex - 1;
	iframe.style.display = "block";
	
	div.iframeShim = iframe;
}

function HideIFrameShim(div)
{
	if (needsIEFix()) 
	{
	    var local_div = div;
	    var tt = function()
	    {
	        if(local_div.iframeShim)
	            HideIFrameShim2(local_div.iframeShim);
	    }
	    setTimeout(tt, 1);
	}
}

function HideIFrameShim2(iframe)
{
    iframe.parentNode.removeChild(iframe);
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function needsIEFix()
{
  var msg = false;
  var ver = getInternetExplorerVersion();

  if (( ver > -1 ) && ( ver <= 6.0 ))
  {
      msg = true;
  }
  return msg;
}

function showHideDiv(thisID) {
	if (document.getElementById){
		obj = document.getElementById(thisID);
		if (obj.style.display == "none"){
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	} 
	
}
function updateEmailFields(thisValue,input1,input2) {

    //split the value on ":"
    var valueArr = new Array();
    valueArr = thisValue.split(":");
    
    //Add values to the hidden fields (by default, "Subject" and "toAdd"
    document.getElementById(input1).value = valueArr[0];
    document.getElementById(input2).value = valueArr[1];
    
}
function checkAllFormFields(formFieldList,elementId) {

    //formFieldList is a comma separated list of compulsory form fields
    //each entry contains the field name and instruction to display
    //checkAllFormFields('form field 1:message 1,form field 2:message 2')e.g:
    //onclick="javascript:return checkAllFormFields('fromAdd:Please enter your Email Address,subject:Please enter a Subject');"
    
    //extra checks are available as an OPTIONAL extra, for example:
    //checkAllFormFields('form field 1:message 1:string/number to check:string/number:string/number should be there flag','returnArea')e.g:
    //onclick="javascript:return checkAllFormFields('fromAdd:Please enter a valid Email Address:@:string:true','errorMessageDiv');"
    //errorMessageDiv is the id of the element to return the error message to. If no id is given, an alert box will be shown
    //onclick="javascript:return checkAllFormFields('subject:Please select a Subject:-1:number:false');"
    //onclick="javascript:return checkAllFormFields('ipaddress:Please enter a valid ip address::ip:false');"
    
    //onclick="javascript:return checkAllFormFields('fromAdd:Please enter a valid email address::email:true');"
    
    var fieldArr = new Array();
    var partArr = new Array();
    var error = "";

    fieldArr = formFieldList.split(",");
    
    //Loop through all form fields:
    for(idx=0;idx< fieldArr.length;idx++){
        //Split on ":" to get the field name and the display name
        partArr = fieldArr[idx].split(":");
        //Check the length of the partArr, if it's greater than 2, then 
        //there are different checks to do (for example, checking for an "@" symbol
        if (partArr.length == 2) {
            if (document.getElementById(partArr[0]).value == "") {
                error += partArr[1] + "\r\n";
            }
        }else if (partArr.length > 2) {
            //Are we looking for a string or a number?
            if (partArr[3] == 'string') {
                if (partArr[4] == 'true') {
                    //The character should be in the field value
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue.indexOf(partArr[2]) == -1) {
                        error += partArr[1] + "\r\n";
                    }
                }else if (partArr[4] == 'false') {
                    //The character should NOT be in the field value
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue.indexOf(partArr[2]) != -1) {
                        error += partArr[1] + "\r\n";
                    }
                }
            
            }else if (partArr[3] == 'number') {
                if (partArr[4] == 'true') {
                    //The field value should be equal to the number
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue != partArr[2]) {
                        error += partArr[1] + "\r\n";
                    }
                }else if (partArr[4] == 'false') {
                    //The field value should NOT be equal to the number
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue == partArr[2]) {
                        error += partArr[1] + "\r\n";
                    }
                }
                
            }else if (partArr[3] == 'length') {
                if (partArr[4] == 'equal') {
                    //The field value should be equal to the number
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue.length != partArr[2]) {
                        error += partArr[1] + "\r\n";
                    }
                }else if (partArr[4] == 'greater') {
                    //The field value should NOT be equal to the number
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue.length <= partArr[2]) {
                        error += partArr[1] + "\r\n";
                    }
                }else if (partArr[4] == 'less') {
                    //The field value should NOT be equal to the number
                    var fieldValue = document.getElementById(partArr[0]).value
                    if (fieldValue.length >= partArr[2]) {
                        error += partArr[1] + "\r\n";
                    }
                }
                
            }else if (partArr[3] == 'match') {
                //compares two fields to ensure that they match, used for confirmation fields
                var field1Value = document.getElementById(partArr[0]).value
                var field2Value = document.getElementById(partArr[2]).value
                if (field1Value != field2Value) {
                    error += partArr[1] + "\r\n";
                }
                
            }else if (partArr[3] == 'checkbox') {
                if (partArr[4] == 'true') {
                    //The field should be checked
                    var fieldValue = document.getElementById(partArr[0]).checked
                    if (fieldValue != true) {
                        error += partArr[1] + "\r\n";
                    }
                }else if (partArr[4] == 'false') {
                    //The field should not be checked
                    var fieldValue = document.getElementById(partArr[0]).checked
                    if (fieldValue != false) {
                        error += partArr[1] + "\r\n";
                    }
                }
            }else if (partArr[3]== 'ip') {
                var regexIP = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
                var fieldValue = document.getElementById(partArr[0]).value;
                
                if ((partArr[4] == 'false') && (fieldValue=="")){
                    //if the ip address is not required and is empty
                    
                }else {
                    if (fieldValue.match(regexIP)) {
                    } else {
                      error += partArr[1] + "\r\n";
                    }
                }
            }else if (partArr[3]== 'email') {
                if ((partArr[4] == 'true') && (!validateEmail(partArr[0]))){
                    //email is not valid
                    error += partArr[1] + "\r\n";
                }
            }
            else if (partArr[3]== 'regex') {
            	var fieldValue = document.getElementById(partArr[0]).value;
            	var expression = new RegExp(partArr[2]);
                if (!fieldValue.match(expression)){
                    //value does not match the regular expression
                    error += partArr[1] + "\r\n";
                }
            }
        }
    }
	if (error != "") {
	    if (elementId != null) {
	        //Add to the innerHTML
	        var ele = document.getElementById(elementId)
	        ele.innerHTML = error.replace(/\r\n/gi,"<br />");
	    }else{
	        //Create an alert
		    alert(error);
		}
		return false;
	}

	return true;
}

//http://javascript.internet.com/forms/email-address-validation.html
validateEmail = function(emailFormField){
    var emailStr = document.getElementById(emailFormField).value;

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */
    var checkTLD=1;
    /* The following is the list of known TLDs that an e-mail address must end with. */
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain <b style="color:black;background-color:#99ff99">format</b>.  It also is used to separate the username
    from the domain. */
    var emailPat=/^(.+)@(.+)$/;
    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/
    var validChars="\[^\\s" + specialChars + "\]";
    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */
    var quotedUser="(\"[^\"]*\")";
    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    /* The following string represents an atom (basically a series of non-special characters.) */
    var atom=validChars + '+';
    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */
    var word="(" + atom + "|" + quotedUser + ")";
    // The following pattern describes the structure of the user
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null || matchArray.length > 3) {
        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */

        //alert("<b style="color:black;background-color:#a0ffff">Email</b> address seems incorrect (check @ and .'s)");
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
            //alert("Ths username contains invalid characters.");
            return false;
        }
    }
   
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
            //alert("Ths domain name contains invalid characters.");
            return false;
       }
    }
    
    // See if "user" is valid 
    if (user.match(userPat)==null) {
        // user is not valid
        return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
        // this is an IP address
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                //alert("Destination IP address is invalid!");
                return false;
            }
        }
        return true;
    }

    // Domain is symbolic name.  Check if it's valid.
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
            //alert("The domain name does not seem to be valid.");
            return false;
       }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 && 
        domArr[domArr.length-1].search(knownDomsPat)==-1) {
        //alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }

    // Make sure there's a host name preceding the domain.
    if (len<2) {
        //alert("This address is missing a hostname!");
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}


// IP Picker JS functions
function ippicker_fill(sender, base){
	
	//	alert('sender' + sender.value);
	
	var value = Number(sender.value);
	
	if (isNaN(value) || value=='undefined')
		value = 0;
	
	if (sender.value>255) 
		value = 255;
	
	sender.value = PadLeft(value.toString(),3,"0");
		
	var name = sender.name;
	var value1 = Number(document.getElementById(base + "_1").value);
	var value2 = Number(document.getElementById(base + "_2").value);
	var value3 = Number(document.getElementById(base + "_3").value);
	var value4 = Number(document.getElementById(base + "_4").value); 
	  
	var ipaddress = Number(document.getElementById(base).value);
	
	ipaddress = (value1 * 1000000000) + (value2 * 1000000) + (value3 * 1000) + (value4);
	
	document.getElementById(base).value = ipaddress;
}

function ippicker_jump(sender, nextnumber, base){
	if (sender.value.length==3 && nextnumber>0){
		// now go to next field in list
		//alert("jump to " +base + "_" + nextnumber);
		document.getElementById(base + "_" + nextnumber).focus();
	}
}

function ippicker_load(base){
	// Here we will initially fill the parts of the ippicker
	var sender = document.getElementById(base);
	
	//alert('here -> ' + sender.name + '=' + sender.value);
	
	var IPNumber = Number(sender.value);
	
	if (!isNaN(IPNumber) && IPNumber!='undefined'){
		// ok, we have a number we can split up
		var IPPart1 = parseInt(IPNumber / 1000000000);
		document.getElementById(base + "_1").value = PadLeft(IPPart1.toString(), 3, "0");
		
		var IPPart2 = parseInt((IPNumber - (IPPart1 * 1000000000)) / 1000000);
		document.getElementById(base + "_2").value = PadLeft(IPPart2.toString(), 3, "0");
		
		var IPPart3 = parseInt((IPNumber - (IPPart1 * 1000000000) - (IPPart2 * 1000000)) / 1000);
		document.getElementById(base + "_3").value = PadLeft(IPPart3.toString(), 3, "0");
		
		var IPPart4 = parseInt((IPNumber - (IPPart1 * 1000000000) - (IPPart2 * 1000000) - (IPPart3 * 1000)));
		document.getElementById(base + "_4").value = PadLeft(IPPart4.toString(), 3, "0");
	}
}

function PadLeft(valuestring, total, padchar){
	if (valuestring.length < total){
		for(var i=0; i=(total-valuestring.length); i++){
			valuestring = padchar + valuestring;
		}
	}
	//alert("value=" + valuestring);
	return valuestring;
}


/*
   ***************************************************************************
   Function: ListBoxFromTo(FromListBox, ToListBox)
   ***************************************************************************
   This function moves selected items from one list box to another list box
   
   Parameters:
      FromListBox - a reference to a listbox (Drop-Down Box control) from which selected items are to be moved from
      ToListBox - a reference to a listbox (Drop-Down Box control) to which items selected in FromListBox are to be moved to
      
   Returns:
      nothing returned update ListBox
*/
ListBoxFromTo = function(FromListBox, ToListBox){
    var arrFrom = new Array();     
    var arrTo = new Array();     
    var arrValues= new Array();     
    var i;     
    
    //copy items in the ToListBox into the To array
    
    for (i = 0; i < ToListBox.options.length; i++) {
        arrValues[ToListBox.options[i].text] = ToListBox.options[i].value;
        arrTo[i] = ToListBox.options[i].text;
    }     
  
    var fromCount = 0;     
    var toCount = arrTo.length;     
    //iterate through items in FromListBox, if item is selected copy into To array else into From array
    for(i = 0; i < FromListBox.options.length; i++) {
	    arrValues[FromListBox.options[i].text] = FromListBox.options[i].value;
	    if (FromListBox.options[i].selected && FromListBox.options[i].value != "") {
			arrTo[toCount] = FromListBox.options[i].text;     
			toCount++;     
	    }else {     
	        arrFrom[fromCount] = FromListBox.options[i].text;
	        fromCount++;     
	    }     
    }
         
    arrFrom.sort();     
    arrTo.sort();     

    //re-build the FromListBox from the From array   
    FromListBox.length = 0;  
    for(i = 0; i < arrFrom.length; i++) {
        var optionItem = new Option();     
        optionItem.value = arrValues[arrFrom[i]];     
        optionItem.text = arrFrom[i];     
        FromListBox[i] = optionItem;     
    }  

    //re-build the ToListBox from the To array 
    ToListBox.length = 0;     
    for(i = 0; i < arrTo.length; i++) {     
        var optionItem = new Option();     
        optionItem.value = arrValues[arrTo[i]];     
        optionItem.text = arrTo[i];     
        ToListBox[i] = optionItem;     
    }     

}

/*
   ***************************************************************************
   Function: ListBoxRemoveItem(CurrentListBox, FromListBox)
   ***************************************************************************
   This function removes an item from from one list box from another listbox (Drop-Down Box control)
   
   Parameters:
      CurrentListBox - a reference to a listbox (Drop-Down Box control) from which item has been selected
      FromListBox - a reference to a listbox (Drop-Down Box control) from which item is to be removed
      
   Returns:
      nothing returned update ListBox
*/
ListBoxRemoveItem = function(CurrentListBox, FromListBox){
    var arrFrom = new Array();     
    var arrTo = new Array();     
    var arrValues= new Array();     
    var i;     
    var itemKey;
    var itemValue
    //iterate through items in CurrentListBox to determine, the selected item
    for(i = 0; i < CurrentListBox.options.length; i++) {
	   
	    if (CurrentListBox.options[i].selected && CurrentListBox.options[i].value != "") {
            itemKey = CurrentListBox.options[i].text;
            itemValue = CurrentListBox.options[i].value;
	    }else {     
	           
	    }     
    }
    
    
    //copy items in the ToListBox into the To array
    var j=0;
    for (i = 0; i < FromListBox.options.length; i++) {
        if ((FromListBox.options[i].text==itemKey) && (FromListBox.options[i].value=itemValue)) {
           //match found (item to remove)
        }else{
      
        arrValues[FromListBox.options[j].text] = FromListBox.options[i].value;
        arrTo[j] = FromListBox.options[i].text;
        j++;
        }
    }     

    //re-build the FromListBox from the To array   
    FromListBox.length = 0;     
    for(i = 0; i < arrTo.length; i++) {     
        var optionItem = new Option();     
        optionItem.value = arrValues[arrTo[i]];     
        optionItem.text = arrTo[i];     
        FromListBox[i] = optionItem;     
    }     

}



/*
   ***************************************************************************
   Function: ListBoxSelectAll(ListBox)
   ***************************************************************************
   This function selects all items in a listbox
   
   Parameters:
      ListBox - a reference to a listbox (Drop-Down Box control)
      
   Returns:
      nothing returned update ListBox
*/
ListBoxSelectAll = function(ListBox){
    for(var i=0; i<ListBox.length; i++) {
        ListBox[i].selected = true;     
    }
}

function checkPassword(username, password, confirmPassword, passLength, messageArea, allowDisable, submitId) {
	
	//Example use: onkeyup="checkPassword('registerpanel_email', 'registerpanel_password', 'registerpanel_confirmpassword','userloginerror', true, 'registerSubmit')"
	//INPUTS:
	//username - id of form field for the username
	//password - id of form field for the password
	//confirmPassword - id of form field for the confirmed password
	//passLength - minimum length of the password
	//messageArea - id of form field to return error messages to
	//allowDisable - allow the submit button to be disabled if conditions aren't met
	//submitId - id of the submit button in the form
	
	//OUTPUT:
	//Error message as innerHTML of messageArea
	
	//TODO:
	//Perhaps would be nice to have option of not including username
	
    //Checks length of password and whether password and confirm password match
    //Outputs message to let user know if length or confirmed password are not correct
	var errormessage = "";
	var input_username = document.getElementById(username).value;
	var input_pass = document.getElementById(password).value;
	var input_confirm = document.getElementById(confirmPassword).value;
	
	//Check that the password contains alphanumeric input
	// \W is a shortcut for [^a-zA-Z0-9_], \w (short for [a-zA-Z0-9_])

	if (/\W/.test(input_pass)) {
	    if (allowDisable) document.getElementById(submitId).disabled = true;
	    errormessage = "Your password should contain only letters and/or numbers.";
	    document.getElementById(messageArea).innerHTML = errormessage;
		
		return false;
	}else{
	    if (input_pass != "" && input_confirm != "" && input_username != "" && input_confirm == input_pass && input_pass.length >= passLength && input_username!=input_pass) {
		    if (allowDisable) document.getElementById(submitId).disabled = false;
		    document.getElementById(messageArea).innerHTML = "";
		    return true;
	    }else{
		    if (allowDisable) document.getElementById(submitId).disabled = true;
		    if (input_pass != "" && input_confirm != "" && input_confirm != input_pass){
			    errormessage = "The confirmation password does not match the password entry.";
		    }
		    if (input_pass != "" && input_pass.length < passLength){
			    errormessage = "The password must be more than " + passLength + " characters long.";
		    }
		    if (input_pass != "" && input_username != "" && input_username==input_pass){
			    errormessage = "The password and email can not be the same.";
		    }
		    document.getElementById(messageArea).innerHTML = errormessage;
    		
		    return false;
	    }
    }
}

if( crusherNet == null ) var crusherNet = new Object();
/*
// To use, simple do: crusherNet.Get_Cookie('cookie_name')
// replace cookie_name with the real cookie name, '' are required
*/
crusherNet.Get_Cookie = function( check_name ) {
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )	{
	    // now we'll split apart each name=value pair
	    a_temp_cookie = a_all_cookies[i].split( '=' );
	    // and trim left/right whitespace while we're at it
	    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
    	
	    // if the extracted name matches passed check_name
	    if ( cookie_name == check_name && a_temp_cookie.length>1){
		    b_cookie_found = true;
		    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '')) ;
		    //cookie_value = a_temp_cookie[1];
		    return cookie_value;
		    break;
	    }
	    //a_temp_cookie = null;
	    a_temp_cookie = '';
	    cookie_name = '';
    }
    if ( !b_cookie_found )	{
	    //return null;
	    return '';
    }
}



/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
crusherNet.Set_Cookie = function( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() ); // this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString()); // this is for testing purposes only
    
    sCookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	//alert(sCookie.length); // this is for testing purposes only
	document.cookie = sCookie;
}

// this deletes the cookie when called
crusherNet.Delete_Cookie = function( name, path, domain ) {
	if ( crusherNet.Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
crusherNet.getQueryString = [];
crusherNet.processQueryString = function() {
	var queryString = window.location.search.substring(1);
	var nvpList = queryString.split('&');
	for (var i=0; i<nvpList.length; i++) {
		var x = nvpList[i].indexOf('=');
		if (x > 0) {
			var qsKey = nvpList[i].substring(0,x);
			var qsValue = nvpList[i].substring(x+1);
			crusherNet.getQueryString[qsKey] = qsValue;
		}
	}
}

//HtmlEncode: takes in a string and returns encoded version for html display
crusherNet.HTMLEncode = function( text )
{
    if ( text.length == 0 ){
        return '' ;
    }

    text = text.replace( "&", "&amp;" ) ;
    text = text.replace( "\"", "&quot;" ) ;
    text = text.replace( "<", "&lt;" ) ;
    text = text.replace( ">", "&gt;" ) ;
    text = text.replace( "'", "&#39;" ) ;

    return text ;
}

/*
this is used for a key press event to catch a particular keypress and force it do something other than the default
this takes in parameters: 
e (the keypress event)
objectId (a string which is the ID for the html object to trigger)
type (an enumerated type to describe what sort of object is to be triggered which will effect how it gets triggered)
key (the ascii key to check for. If the event key matches this it will trigger the object otherwise it continues)
stop(boolean to determine if the default action of the keypress should continue. true to consume keypress, false to continue)
this function needs to be added to in order for it to handle extra object types
*/
keyHandler = function(e,objectId,type,key,stop) {
    var pK;
    if(window.event)
          pK = window.event.keyCode; //IE
     else
          pK = e.which; //firefox   
    if(pK == key){
        if(type == 1){//button
            var button = document.getElementById(objectId);
            button.click();
        }
        return !stop;
    }else{
        return true;
    }
}

//Disable the enter key
function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
     return (key != 13);
}

/***********************************
    function enterKeyHandler(e, functionToRun, ...)
        consumes the enter key, and run a function if the enter key is pressed
        usage:
            onkeypress="return enterKeyHandler(event, 'RunThisFunction();');">
            onkeypress="return enterKeyHandler(event);">
        @param: functionToRun - either a string to eval or a function to call
        @param: ... - any number of arguments to pass to functionToRun if it is a function (not a string)
*/
function enterKeyHandler(e, functionToRun){
    if (e.keyCode != 13) return true;
  
    //stop the event (platform independent)
    e.cancelBubble = true;
    if (e.returnValue)
       e.returnValue = false;
    
    if (e.stopPropagation)
      e.stopPropagation();
    
    if(functionToRun && typeof functionToRun === 'string')    
        eval(functionToRun);
    else {
        var args = [];
        for(var i = 2; i < arguments.length; i++)
            args.push(arguments[i]);
            
        functionToRun.apply(this,args); //'this' has no real meaning here since we're not in a object :)
    }
    
    return false;
}

function setFocusTo(fieldname){//set the focus to the supplied element.
        var formElement = null;
        if (formElement==null){
            formElement=document.getElementById(fieldname);
        }
        if (formElement==null){
            var formElements=document.getElementsByName(fieldname);
            if (formElements.length>0){
                formElement=formElements[0];
            }
        }
        if (formElement!=null){
            try{
                formElement.focus();
            }catch(err){
            }
        }    
}

// usage e.g. showEmail ('test','ourdomain','co.nz', 'support test')
function showEmail(user, domain, suffix, displayName){
  document.write('<a href="' + 'mai' + 'lto:' + user + '@' + domain + '.' + suffix + '">' + displayName + '</a>');
}
// usage e.g. showEmailOnly ('test','ourdomain','co.nz')
function showEmailOnly(user, domain, suffix){
  document.write('<a href="' + 'mai' + 'lto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix + '</a>');
}
function showEmailAndSubject(user, domain, suffix, displayName, subject){
  document.write('<a href="' + 'mai' + 'lto:' + user + '@' + domain + '.' + suffix + '?subject=' + subject + '">' + displayName + '</a>');
}

// Server File Picker modification for FCK Editor - www.fckeditor.net
// Opens a Server Browser window, and allows you to upload / pick files from the server.
//'obj' is the id of the element to pass the reference back to of the file you pick.
//'fckEditorVersion' is the version of FCK editor that we are using. Currently is '2.6.3'
var urlobj;
function BrowseServer(obj,type) {
    if(!type) type = '';
    urlobj = obj;
    OpenServerBrowser('FCKeditor/editor/filemanager/browser/default/browser.html?Type=' + type + '&Connector=connectors/aspx/connector.aspx', screen.width * 0.7, screen.height * 0.7);
}
function OpenServerBrowser(url, width, height) {
    var iLeft = (screen.width - width) / 2; 
    var iTop = (screen.height - height) / 2;
    var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes";
    sOptions += ",width=" + width;
    sOptions += ",height=" + height;
    sOptions += ",left=" + iLeft;
    sOptions += ",top=" + iTop;
    var oWindow = window.open(url, "BrowseWindow", sOptions);
}
function SetUrl(url, width, height, alt) {
    document.getElementById(urlobj).value = url;
    oWindow = null;
}