function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function helpToggle(el){
	Effect.toggle(el,'blind',{duration:.7});
}

// Builds rollovers for any image with class "imgover"
/*function initRollovers() {
	if (!document.getElementById) return
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}*/

function navHover(index, img)
{
	if (img) {
		if (img.src){
				var hovURL = img.src;
				img.src = imgArray[index].src; 
				imgArray[index].src = hovURL;
		}
	}
}

function limitText(limitField, limitCount, limitNum) {
    limitCount.innerHTML = limitNum - limitField.value.length;
}

function testLink(inputUrl, testUrl){
	var testUrl = $(testUrl);
	var inputUrl = $(inputUrl);
	testUrl.setAttribute('href',inputUrl.value)
}

function paintRows(rowClass){
	var clients = document.getElementsByClassName(rowClass);
	for (var i=0;i < clients.length;i++){
		if(i%2!=0){
		clients[i].className="even";
		}	
	}
}

function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    var allfields = document.getElementsByTagName("input");

    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i];
        if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
            field.onfocus = function () {this.className = 'highlightActiveField';}
            field.onblur = function () {this.className = 'highlightInactiveField';}
        }
    }
}

//Preloads the rollover images in the header.
var imgArray=new Array(8);

function imgPreload(contextPath){
	var images = new Array(8)
		images[0] = contextPath + '/images/nav/nav-home_o.gif';
		images[1] = contextPath + '/images/nav/nav-dashboard_o.gif';
		images[2] = contextPath + '/images/nav/nav-trust_o.gif';
		images[3] = contextPath + '/images/nav/nav-clients_o.gif';
		images[4] = contextPath + '/images/nav/nav-docs_o.gif';
		images[5] = contextPath + '/images/nav/nav-settings_o.gif';
		images[6] = contextPath + '/images/nav/nav-login_o.gif';
		images[7] = contextPath + '/images/nav/nav-logout.gif';
		
	for (var i = 0;i < images.length;i++){
		var imageObj = new Image();
		imageObj.src=images[i];
		imgArray[i]=imageObj;
	}
}

function checkit() {
     var theurl=$('website').value;
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
        $('website').value = theurl;
				return true;
     }
     else
     {
         $('website').value = "http://" + theurl;
					return false;
     }
}