// breaks out of out frame set
//if(top.location != self.location)top.location = self.location;

// Opens window to specific size
//window.moveTo(20,20);
//window.resizeTo(screen.width - 30,screen.height - 30);

// Belongs to the showCount function
//var fieldMaxSize = 500;

function linkTxt(theText)
{
	window.status = theText;
	window.defaultstatus = theText;
}

function showCount(theObj,countObj,fieldMaxSize)
{
	if(countObj.value <= 50)
	{
		countObj.style.backgroundColor = "#FFCCCC";
	}
	else
	{
		countObj.style.backgroundColor = "#CCFFCC";
	}

	if(theObj.value.length > fieldMaxSize )
	{
		theObj.value = theObj.value.substring(0,fieldMaxSize );
	}
	else
	{
		countObj.value = fieldMaxSize - theObj.value.length;
	}
}

function checkForm()
{
	var MAXFIELDLEN = 20;
	var myObj3 = document.MKUSA.NAME;
	var myObj1 = document.MKUSA.EMAIL;
	var myObj4 = document.MKUSA.PASSWORD;
	var myObj2 = document.MKUSA.TAC;
	
	if(myObj3.value == "")
	{
		alert("Please enter your first name.");
		myObj3.style.backgroundColor = "#FFBBBB";
		selFld(myObj3);
		return false;
	}
	else
	{
		if((myObj1.value == "") || (!validEmail(myObj1.value)))
		{
			alert("Please enter a valid email address.");
			myObj1.style.backgroundColor = "#FFBBBB";
			selFld(myObj1);
			return false;
		}
		else
		{
			if(myObj4.value == "")
			{
				alert("Please enter a password between 3 and 20 chars.");
				myObj4.style.backgroundColor = "#FFBBBB";
				selFld(myObj4);
				return false;
			}
			else
			{
				if(myObj2.checked != true)
				{
					alert("Please review our Terms and Conditions. Then select the Terms and Conditions checkbox above to continue.");
					myObj2.focus();
					myObj2.select();
					myObj2.style.backgroundColor = "#FFBBBB";
					return false;
				}
				else
				{
					return true;
				}
			}
		}
	}
}

function clearDefault(myObj)
{
  if(myObj.defaultValue==myObj.value)
  {
  	myObj.value = "";
  }
}

function clearBkgnd(myObj)
{
	myObj.style.backgroundColor = "#FFFFFF";
}

function countChars(myObj)
{
	return myObj.value.length;
}

function noBlanks()
{
	// This routine serves refer.php AND process.php
	var myEMObj1 = document.REFER.FRIENDEMAIL1;
	var myEMObj2 = document.REFER.FRIENDEMAIL2;
	var myEMObj3 = document.REFER.FRIENDEMAIL3;
	var myNMObj1 = document.REFER.FRIENDNAME1;
	var myNMObj2 = document.REFER.FRIENDNAME2;
	var myNMObj3 = document.REFER.FRIENDNAME3;
	var nyMSobj1 = document.REFER.FRIENDMSG1;
	var nyMSobj2 = document.REFER.FRIENDMSG2;
	var nyMSobj3 = document.REFER.FRIENDMSG3;
	var subObj = document.REFER.SUBJECT;
	
	var gotSubj = typeof(subObj) != "undefined";
	var gotOne = myEMObj1.value != "";

	if(!gotOne)
	{
		alert("Please enter an email address.");
		myEMObj1.style.backgroundColor = "#FFBBBB";
		selFld(myEMObj1);
		return false;
	}
	
	if(gotOne && (myNMObj1.value == ""))
	{
		alert("Please enter a FIRST name.");
		myNMObj1.style.backgroundColor = "#FFBBBB";
		selFld(myNMObj1);
		return false;
	}
	
	if(gotSubj)
	{
		if(gotOne && (subObj.value == ""))
		{
			alert("Please enter a SUBJECT.");
			subObj.style.backgroundColor = "#FFBBBB";
			selFld(subObj);
			return false;
		}
	}
	
	if(nyMSobj1 != null)
	{
		clearDefault(nyMSobj1);
		if(gotOne && (nyMSobj1.value == ""))
		{
			alert("Um...you really should enter a MESSAGE...");
			nyMSobj1.style.backgroundColor = "#FFBBBB";
			selFld(nyMSobj1);
			return false;
		}
	}
	
	if(nyMSobj2 != null)
	{
		clearDefault(nyMSobj2);
	}
	
	if(nyMSobj3 != null)
	{
		clearDefault(nyMSobj3);
	}
	return true;
}

function tween(val,l,h)
{
	if((val >= l) && (val <= h))
	{
		return false;
	}
	return true;
}

function selFld(x)
{
	x.focus();
	x.select();
}



function sizer()
{
	window.moveTo(10,10);
	window.resizeTo(window.screen.width-50,window.screen.height-50);

}

function validEmail(str) {
  var supported = 0;
  if (window.RegExp)
  {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}