﻿// JScript File

//Check the form is filled in correctly
function CheckForm (uid, pid) {     
    var txtUserName = document.getElementById(uid);
    var txtPassword = document.getElementById(pid);
	//Initialise variables
	var errorMsg = "";
	
	if (isEmpty(txtUserName.value)) { 
		errorMsg += "\n\tEmail Address \t- Please enter a valid user name";
	}
			
	//Check for a password
	if (isEmpty(txtPassword.value)) { 
 		errorMsg += "\n\tPassword \t- Please enter a password";
	}
		
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your inquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}

function isEmpty(string)
{
    if(trimAll(string) == "" )
        return true;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while(sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
// -->



