if (document.images) {
    img1 = new Image();
    img1.src = "images/home/submit-down.jpg";
}

function checkEnter(e)
{
	var e=window.event || e	
	
	if (e.keyCode==13)
	{
		doSubmit();	
	}
}

function toggleImage(which)
{
	document.myform.login.src = which;
}

function setFocus()
{
	document.myform.LastName.focus();
}


function stripCharsInBag(s,bag)
{
	 var i;
     var returnString = "";
     for (i = 0; i < s.length; i++)
     {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
     }
    return returnString;
}

function checkFields()
{
	var ln = document.myform.LastName.value;
	var un = document.myform.UniqueNumber.value;
	var sn = document.myform.SchoolName.value;
	var ey = document.myform.EventYear.value;

	if (ln == "")
	{
		alert("Please enter the graduate's last name before continuing.");
		document.myform.LastName.focus();
		return false;
	}
	else if(ln.length<2)
	{
		alert("Please enter the graduate's last name before continuing.");
		document.myform.LastName.focus();
		return false;
	}
	if (un != "")
	{
		return true;	
	}
	else if (sn != "" && ey != "")
	{
		return true;
	}
	else
	{
		alert("Please enter the graduate's last name and customer number or last name, school name, and year before continuing.");
		document.myform.UniqueNumber.focus();
		return false;
	}
}

function doSubmit()
{
	var checkIt = checkFields();

	var ln = document.myform.LastName.value;
	var un = document.myform.UniqueNumber.value;
	var sn = document.myform.SchoolName.value;
	var ey = document.myform.EventYear.value;
	
	
	
	if (checkIt==true)
	{
		toRemove = ",.";
		ln = stripCharsInBag(ln,toRemove);
		document.myform.LastName.value = ln;

		if (un != "")
		{
			var toRemove = ",-.";
			un = stripCharsInBag(un,toRemove);
			un = trim(un);
			document.myform.UniqueNumber.value = un;
			document.myform.submit();
			document.myform.action = "http://www.gradimages.com/index.cfm?action=site.login";
			document.myform.submit();
		}
		else if (sn!="" && ey != "")
		{
			document.myform.action = "http://www.gradimages.com/index.cfm?action=main.search";
			document.myform.submit();
		}
		else { return;}
	}
	else { return;}
}

function trim(strText) 
{ 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

