

function help(num)
{
    var message = new Array();
    // General
    message[0]  = "Help goes here.";
    if(num != null && message[num] != null)
        alert(message[num]);
    else
        alert("[" + num + "] " + message[0]);
    return false;
}
function setFocusForm(formname)
{
	if(formname != null)
	{
		for(var x=0;x<formname.length;x++)
		{
			if(formname.elements[x].type != 'hidden' && formname.elements[x].disabled == false)
			{
				formname.elements[x].focus();
				return;
			}
		}
	}
}
function toggleHTML(section, hide, show)
{
	var area = document.getElementById(section);
	if(area.style.display == "none")
	{
		area.style.display = "";
		if(hide != null)
		{
			area = document.getElementById(hide);
			area.style.display = "";
		}
		if(show != null)
		{
			area = document.getElementById(show);
			area.style.display = "none";
		}
	} else
	{
		area.style.display = "none";
		if(show != null)
		{
			area = document.getElementById(show);
			area.style.display = "";
		}
		if(hide != null)
		{
			area = document.getElementById(hide);
			area.style.display = "none";
		}
	}
}
function makeAllGo(formname, valuefind)
{
	if(formname != null)
	{
		for(var x=0;x<formname.length;x++)
		{
			if(formname.elements[x].type == 'radio' && 
				formname.elements[x].value == valuefind)
			{
				formname.elements[x].checked = true;
				continue;
			}
			if(formname.elements[x].type == 'select-one')
			{
				var ss = new String(formname.elements[x].name);
				var ss1 = ss.substring(0, 1);
				if(ss1 == "R")
				{
					changeReason(formname.elements[x], OKList);
				} else if(ss1 == "N")
				{
					formname.elements[x].selectedIndex = 0;
				}
			}
		}
	}
	formname.submit();
	return true;
}
function addPad(instr,finallength)
{
	var newstr = "";
	if(instr == null) return true;
	if(finallength < instr.length)
	{
		for(x=0;x<finallength;x++)
		{
			newstr = newstr + instr.charAt(x);
		}
		return newstr;
	}
	for(x=instr.length;x < finallength; x++)
	{
		instr = instr + " ";
	}
	return instr;
}
function isANumber(instr)
{
	if(instr == null) return true;
	if(instr.length < 1) return true;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			return false;
		}
	}
	return true;
}
function isAFloat(instr)
{
	if(instr == null) return true;
	if(instr.length < 1) return true;
    var foundone = false;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(!(instr.charAt(x) == '.' && foundone))
			    return false;
		}
		foundone = true;
	}
	return true;
}
function getPaymentType(formname)
{
	if(formname.PAYTYPE.selectedIndex == 0)
	{
		return -1;
	}
	var payinfo = formname.PAYTYPE[formname.PAYTYPE.selectedIndex].value.split("*");
	var paytype = parseInt(payinfo[1]);
	return paytype;
}
function checkEmailAddress(formfield)
{
	var inputStr = new String(formfield.value);
	var at = inputStr.indexOf("@");
	var name = inputStr.substring(0, at);
	var isp = inputStr.substring(at + 1, inputStr.length);
	var dot = inputStr.lastIndexOf(".");
	if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (inputStr.length - 1) || (RegExpEmailCheck(inputStr) == false)) 
	{
		return false;
	} 
	if (inputStr.indexOf(" ") > -1)
	{
		return false;
	}
	return true;
}
// Use regular expressions to check email string for RFC 822 conformance
//
// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com/forms/check-email.html
function RegExpEmailCheck (emailStr) 
{
	
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
//				alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
//			    alert("The username doesn't seem to be valid.")
		return false
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
//				        alert("Destination IP address is invalid!")
			return false
			}
		}
		return true
	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
//				alert("The domain name doesn't seem to be valid.")
		return false
	}
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
//			   alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
//			   alert(errStr)
	   return false
	}
	// If we've gotten this far, everything's valid!
	return true;
}
function addFees(currenttotal, formfield, additionalamt)
{
	if(additionalamt == null)
	{
		additionalamt = 0.0;
	}
	currenttotal = currenttotal + additionalamt; 
	if(formfield != null)
	{
		var bothvalues = formfield[formfield.selectedIndex].value.split("*");
		var citem = parseFloat(bothvalues[1]);
		if(citem > 0)
		{
			currenttotal = currenttotal + citem;
		}
	}
	return currenttotal;
}
function roundToPenny(currenttotal)
{
	var newtotalcost = currenttotal;
	newtotalcost = ((Math.round((newtotalcost) * 100)) / 100);
	var totalcoststring = checkCost(newtotalcost);
	return totalcoststring;	
}
function checkCost(ttlin, leadingspace)
{
	var ttl = "" + ttlin;
	var dec1 = ttl.substring(ttl.length-3, ttl.length-2);
	var dec2 = ttl.substring(ttl.length-2, ttl.length-1);
	var newttl = null;
	if(leadingspace == null)
	{
		leadingspace = false;
	}
	if (dec1 != '.') 
	{
		if (dec2 == '.') ttl += "0";
		else ttl += ".00";
	}
	if(newttl != null) 
	{
		ttl = newttl;
	}
	if(leadingspace == true)
	{
		while(ttl.length < 5)
		{
			ttl = " " + ttl;
		}
	}
	return ttl;
}
function addFeesMultiple(currenttotal, formfield, additionalamt)
{
	if(additionalamt == null)
	{
		additionalamt = 0.0;
	}
	currenttotal = currenttotal + additionalamt; 
	if(formfield != null)
	{
		for(var x=0;x<formfield.length;x++)
		{
			var currentvalue = null;
			if(formfield[x].selected)
			{
				var bothvalues = formfield[x].value.split("*");
				var citem = parseFloat(bothvalues[1]);
				if(citem > 0)
				{
					currenttotal = currenttotal + citem;
				}
			}
		}
	}
	return currenttotal;
}
function isAURL(instr)
{
	if(instr == null) return true;
	if(instr.length == 0) return true;
	var fhttp = instr.indexOf("http://", 0);
	if(fhttp != 0)
	{
		return false;
	}
	return true;
}
function openNewWindow(winName, inUrl, size)
{
	if(winName == null)
	{
		winName = "RRPOPUPWINDOW_" + size;
	} else
	{
		winName = "RRPOPUPWINDOW_" + winName;
	}
	var win_chk = null;
	if(size == "1")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=300,height=200',false);
	}
	if(size == "2")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=500,height=400',false);
	}
	if(size == "3")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=600,height=400',false);
	}
	if(size == "4")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=600,height=600',false);
	}
	if(size == "5")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=yes,resizable=yes,width=650,height=800',false);
	}
	if(size == "full")
	{
		win_chk = window.open( inUrl, winName,'menubar=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes,resizable=yes',false);
	}
	win_chk.focus();
}
function checkWhiteSpace(formfield, fieldname, fieldtype)
{
	if(fieldtype == null)
	{
		fieldtype = 1;
	}
	if(fieldtype == 1)
	{
		// text boxes
		if(formfield.value.length == 0)
		{
			alert(fieldname + " cannot be blank.");
			formfield.focus();
			return false;
		}
		for(i=0;i<formfield.value.length;i++)
		{
			if(formfield.value.charAt(i) != ' ')
			{
				return true;
			}
		}
		if(i == formfield.value.length)
		{
			alert(fieldname + " cannot be blank.");
			formfield.focus();
			return false;
		}
	} else if(fieldtype == 2)
	{
		// pull-downs - must be set to something other than 0
		if(formfield.selectedIndex == 0)
		{
			alert("You must select " + fieldname + ".");
			formfield.focus();
			return false;
		} else
		{
			return true;
		}
	}
	return false;
}
function validateCreditCardNumber(formfield)
{
	var field = new String(formfield);
	if ( (field.length < 13) || (field.length > 19) )
	{
		return false;
	}
	
	if (!verifyMod10(field))
	{
		return false;
	}
	return true;
}
function verifyMod10(field)
{
	var PAN = field
	PAN= removeSpaces(PAN);
	var st = PAN;
	if (st.length > 19)
		return false;
	var sum = 0;
	var mul = 1;
	var st_len = st.length;
	var tproduct;
	
	for (i = 0; i < st_len; i++) 
	{
		digit = st.substring(st_len-i-1, st_len-i);
		
		if (digit == " " || digit == "-")
			continue;
			
		tproduct = parseInt(digit ,10) * mul;
	    
	    if (tproduct >= 10)
	      sum += (tproduct % 10) + 1;
	    else
	      sum += tproduct;
	    
	    if (mul == 1)
	      mul++;
	    else
	      mul--;
	}
	if ((sum % 10) != 0)
		return false;
	return true;
}
function charsAndNumbersOnly(instr)
{
	var st_len = instr.length;
	for(var x=0;x<st_len;x++)
	{
		var newC = instr.charAt(x);
		newC = newC.toUpperCase();
		if ((newC >= 'A' && newC <= 'Z') || (newC >= '0' && newC <= '9'))
		{
			// CHAR IS GOOD
		} else
		{
			return false;
		}
	}
	return true;
}
function hasBadChars(instr)
{
	for(var x=0;x<instr.length;x++)
	{
		var newC = instr.charAt(x);
		if((newC == "*") || (newC == ";") || (newC == ":") || (newC == "^"))
		{
			return true;
		}
	}
	return false;
}
function hasChars(instr)
{
	for(var x=0;x<instr.length;x++)
	{
		var newC = instr.charAt(x);
		if((newC != " ") && (newC != "\n") && (newC != "\r") && (newC != "\t"))
		{
			return true;
		}
	}
	return false;
}
function removeSpaces(fieldName)
{
	var startIndex, lastIndex;
	var newFieldName, newC;
	lastIndex = fieldName.length-1;
	startIndex = 0;
	
	newC = fieldName.charAt(startIndex);
	while ((startIndex<lastIndex) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		startIndex++;
		newC = fieldName.charAt(startIndex);
	}
	newC = fieldName.charAt(lastIndex);
	while ((lastIndex>=0) && ((newC == " ") || (newC == "\n") || (newC == "\r") || (newC == "\t"))) {
		lastIndex--;
		newC = fieldName.charAt(lastIndex);
	}
	if (startIndex<=lastIndex) {
		newFieldName = fieldName.substring(startIndex, lastIndex+1);
		return newFieldName;
	} else {
		return fieldName;
	}
}
function removeAllSpaces(fieldName)
{
	var startIndex, lastIndex;
	var newFieldName = "";
	var newC;
	lastIndex = fieldName.length-1;
	startIndex = 0;
	
	while(startIndex <= lastIndex)
	{
		newC = fieldName.charAt(startIndex);
		if((newC != " ") && (newC != "\n") && (newC != "\r") && (newC != "\t"))
		{
			newFieldName = newFieldName + newC;
		}
		startIndex++;
	}
	return newFieldName;
}
function checkForBlanks()
{
	for (var i = 1; i < arguments.length; i += 2)
	{
		if (!arguments[i])
		{
			alert(arguments[0] + arguments[i+1] + ".");
			return false;
		}
	}
	return true;
}


