
function MM_openBrWindow(theURL,winName,features)
	{ //v2.0
		window.open(theURL,winName,features);
	}



function ietruebody()
	{
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}



function ddrivetip(thetext, thecolor, thewidth)
	{
		if (ns6||ie)
		{
			if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
			if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
			tipobj.innerHTML=thetext;
			enabletip=true;
			return false;
		}
	}



function positiontip(e)
	{
		if (enabletip)
			{
				var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
				var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
				//Find out how close the mouse is to the corner of the window
				var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
				var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
				var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
				//if the horizontal distance isn't enough to accomodate the width of the context menu
				if (rightedge<tipobj.offsetWidth)
					//move the horizontal position of the menu to the left by it's width;
					tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
				else if (curX<leftedge)
					tipobj.style.left="5px";
				else
					//position the horizontal position of the menu where the mouse is positioned
					tipobj.style.left=curX+offsetxpoint+"px";
					//same concept with the vertical position
					if (bottomedge<tipobj.offsetHeight)
						tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
					else
						tipobj.style.top=curY+offsetypoint+"px";
						tipobj.style.visibility="visible";
			}
	}



function hideddrivetip()
	{
		if (ns6||ie)
		{
			enabletip=false;
			tipobj.style.visibility="hidden";
			tipobj.style.left="-1000px";
			tipobj.style.backgroundColor='';
			tipobj.style.width='';
		}
	}



function autoTab(input,len, e) 
	{
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter, keyCode))
		{
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
		}

		function containsElement(arr, ele)
		{
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			found = true;
			else
			index++;
			return found;
		}

		function getIndex(input)
		{
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input) { index = i; }
			else i++;
			return index;
		}

		return true;
	}



function validate_form(thisform)
	{
	with (thisform)
		{
		if (validate_required(loan_type,"Please fill out Loan Type") == false)
			{ loan_type.focus(); return false; }
		if (validate_required(loan_amount,"Please fill Desired Loan Amount") == false)
			{ loan_amount.focus(); return false; }
		if (validate_required(estimated_value,"Please fill out Estimated Home Value") == false)
			{ estimated_value.focus(); return false; }
		if (validate_required(property_state,"Please fill out Property State") == false)
			{ property_state.focus(); return false; }
		if (validate_required(email_address,"Please fill out Email Address") == false)
			{ email_address.focus(); return false; }
		if (validate_required(home_phone,"Please fill out Best Contact Number") == false)
			{ home_phone.focus(); return false; }
		if (validate_required(first_name,"Please fill out First Name") == false)
			{ first_name.focus(); return false; }
		if (validate_required(last_name,"Please fill out Last Name") == false)
			{ last_name.focus(); return false; }
		if (validate_email(email_address,"Not a valid e-mail address") == false)
			{ email_address.focus(); return false; }
		}
	}



function validate_email(field, alerttxt)
	{
	with (field)
		{
			apos = value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if (apos<1 || dotpos-apos<2) 
  			{
				alert(alerttxt); return false;
			} else {
				return true;
			}
		}
	}



function validate_required(field, alerttxt)
	{
	with (field)
		{
			if (value==null || value=="")
			{
				alert(alerttxt); return false;
			} else {
				return true;
			}
		}
	}



function showDiv()
	{
		if (document.getElementById)
		{
			// DOM3 = IE5, NS6
			document.getElementById('HideMe1').style.display = 'block';
		} else {
			if (document.layers)
			{
				// Netscape 4
				document.HideMe1.display = 'block';
			} else { 
				// IE 4
				document.all.HideMe1.style.display = 'block';
			}
		}
	}



function showDiv2(controls)
	{
		if (document.getElementById) 
		{
			// DOM3 = IE5, NS6
			document.getElementById(controls).style.display = 'block';
		} else {
			if (document.layers) 
			{ 
				// Netscape 4
				document.controls.display = 'block';
			} else {
				// IE 4
				document.all.controls.style.display = 'block';
			}
		}
	}



