function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
	func();
	}
	}
  }
  	/* EXAMPLES */
//  	addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
//  	addLoadEvent(function() {
	/* more code to run on page load */
//});


function CheckLength(sid, Maxlen, allowNull, Minlen){
	if (document.getElementById(sid).value.length > Maxlen)
		{
			missinginfo = missinginfo + sid + ' is too long please keep it ' + Maxlen + " or under\n"
			document.getElementById(sid).setAttribute("class", "badfield");
			document.getElementById(sid + "Msg").innerHTML = ' <span class="badtxtfield">is too long</span>'
			return
		}
		else
		{
			document.getElementById(sid).setAttribute("class", "");
			document.getElementById(sid + "Msg").innerHTML = '&nbsp;'
		}
	if (allowNull == false)
		{
			if (document.getElementById(sid).value.length == 0)
				{
					missinginfo = missinginfo + sid + ' must be filled in \n'
					document.getElementById(sid).setAttribute("class", "badfield");
					document.getElementById(sid + "Msg").innerHTML = ' <span class="badtxtfield">Must Be Entered</span>'
					return
				}
				else
				{
					document.getElementById(sid).setAttribute("class", "");
					document.getElementById(sid + "Msg").innerHTML = '&nbsp;'
				}
		}
	if (document.getElementById(sid).value.length < Minlen)
		{
			missinginfo = missinginfo + sid + ' must be at least ' + Minlen + ' \n'
			document.getElementById(sid).setAttribute("class", "badfield");
			document.getElementById(sid + "Msg").innerHTML = ' <span class="badtxtfield">Must Be at least ' + Minlen + ' Characters</span>'
			return
		}
		else
		{
			document.getElementById(sid).setAttribute("class", "");
			document.getElementById(sid + "Msg").innerHTML = '&nbsp;'
		}
}

// Use the below code to use tooltip.
//  onmouseover="tooltip.show('the tooltip text.', 200);" onmouseout="tooltip.hide();"
var tooltip=function(){
 var id = 'tt';
 var top = 3;
 var left = 3;
 var maxw = 300;
 var speed = 10;
 var timer = 20;
 var endalpha = 95;
 var alpha = 0;
 var tt,t,c,b,h;
 var ie = document.all ? true : false;
 return{
  show:function(v,w){
   if(tt == null){
    tt = document.createElement('div');
    tt.setAttribute('id',id);
    t = document.createElement('div');
    t.setAttribute('id',id + 'top');
    c = document.createElement('div');
    c.setAttribute('id',id + 'cont');
    b = document.createElement('div');
    b.setAttribute('id',id + 'bot');
    tt.appendChild(t);
    tt.appendChild(c);
    tt.appendChild(b);
    document.body.appendChild(tt);
    tt.style.opacity = 0;
    tt.style.filter = 'alpha(opacity=0)';
    document.onmousemove = this.pos;
   }
   tt.style.display = 'block';
   c.innerHTML = v;
   tt.style.width = w ? w + 'px' : 'auto';
   if(!w && ie){
    t.style.display = 'none';
    b.style.display = 'none';
    tt.style.width = tt.offsetWidth;
    t.style.display = 'block';
    b.style.display = 'block';
   }
  if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  h = parseInt(tt.offsetHeight) + top;
  clearInterval(tt.timer);
  tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  },
  pos:function(e){
   var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
   var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
   tt.style.top = (u - h) + 'px';
   tt.style.left = (l + left) + 'px';
  },
  fade:function(d){
   var a = alpha;
   if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    var i = speed;
   if(endalpha - a < speed && d == 1){
    i = endalpha - a;
   }else if(alpha < speed && d == -1){
     i = a;
   }
   alpha = a + (i * d);
   tt.style.opacity = alpha * .01;
   tt.style.filter = 'alpha(opacity=' + alpha + ')';
  }else{
    clearInterval(tt.timer);
     if(d == -1){tt.style.display = 'none'}
  }
 },
 hide:function(){
  clearInterval(tt.timer);
   tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  }
 };
}();

function CheckUserForm(){
	var msg = ""
		if (document.getElementById('email').value == ""){msg += "Email Must be Filled In<br>"}
		if (document.getElementById('password').value == ""){msg += "Password Must be Filled In<br>"}
		if (document.getElementById('fname').value == ""){msg += "First Name Must be Filled In<br>"}
		if (!VSCheckEmailFormat(document.getElementById('email').value)){msg +="Email Address appears to be invalid"}
		
		if (msg != ""){document.getElementById('status').innerHTML = msg;	return}
	document.getElementById('status').innerHTML = '<h3>Checking User Information<br>Please Wait...</h3>'
	var oXMLHttp = zXmlHttp.createRequest();
	var url = "/XML/XmlQuoteUser.asp?email=" + document.getElementById('email').value + '&password=' + document.getElementById('password').value + '&fName=' +document.getElementById('fname').value
	oXMLHttp.open("GET", url + '&rnd=' + Math.random(), true);
	oXMLHttp.onreadystatechange = function() {
		if(oXMLHttp.readyState == 4) {
			if(oXMLHttp.status == 200){
				var Response = oXMLHttp.responseText;
					if (Left(Response, 1) == 1)
						{
							document.getElementById('VisitorUserAccountId').value = Response.replace('1-', '')
							document.getElementById('login').innerHTML = "New Account Created!<br><strong>Account Logged In!</strong><!--" + Response.replace('1-', '') + "-->"
							document.getElementById('submitbutton').value = 'Request Rates'
							document.getElementById('submitbutton').disabled = false
							document.getElementById('VisitorUserAccountId').value = Response.replace('1-', '')
						}
					if (Left(Response, 1) == 0)
						{
							document.getElementById('VisitorUserAccountId').value = Response.replace('0-', '')
							document.getElementById('login').innerHTML = "Current Email Has an Account!<br><strong>Account Logged In! </strong><!--" + Response.replace('0-', '') + "-->"
							document.getElementById('submitbutton').value = 'Request Rates'
							document.getElementById('submitbutton').disabled = false
							document.getElementById('VisitorUserAccountId').value = Response.replace('0-', '')
						}
					if (Left(Response, 1) == 2)
						{
							document.getElementById('status').innerHTML = "Current Email has an Account!<br><strong>Wrong Password!</strong>"
						}
					if (Left(Response, 1) == 3)
						{
							document.getElementById('login').innerHTML = "Current Email has an Account!<br><strong>Your Account has been Lockedout until " + Response.replace('3-', '') + "</strong><br><a href='/UnlockAccount.asp'>Click Here</a> to unlock your account faster."
						}		
			} else alert("There was an error while processing this screen.  The document was not ready to process. (Code: " + oXMLHttp.status + ")  Please try again.");
		}
	};
	oXMLHttp.send(null);

}
