
function ValidateFuelCard() {
	document.getElementById("ValidationErrors").innerHTML = 0;
	document.getElementById("FormIsValid").value = "False";
	var ValidationErrors = 0;
	
	var tCheck = document.getElementById("tcheck");
	var comData = document.getElementById("comdata");
	var tch = document.getElementById("tch");
	var efs = document.getElementById("efs");
	var other = document.getElementById("other");
	
	var txtTcheck = document.getElementById("txtTcheck");
	var txtComData = document.getElementById("txtComData");
	var txtTch = document.getElementById("txtTch");
	var txtEfs = document.getElementById("txtEfs");
	var txtOther = document.getElementById("txtOther");
	
	var name = document.getElementById("name").value;
	var aba = document.getElementById("aba");
	var account = document.getElementById("account");
	var terms = document.getElementById("terms");
	
	if (tCheck.checked) {
	//alert("Validating TCHECK");
		ValidateInput(txtTcheck.id, "acctNumber", txtTcheck.value);
		
	}
	if (comData.checked) {
		ValidateInput(txtComData.id, "acctNumber", txtComData.value);
	}
	if (tch.checked) {
		ValidateInput(txtTch.id, "acctNumber", txtTch.value);
	}
	if (efs.checked) {
		ValidateInput(txtEfs.id, "acctNumber", txtEfs.value);
	}
	if (other.checked) {
		ValidateInput(txtOther.id, "acctNumber", txtOther.value);
		ValidateInput(aba.id, "acctNumber", aba.value);
		ValidateInput(account.id, "acctNumber", account.value);
	}
	if (terms.checked != true) {
		alert("You must agree to the term of service.");
		ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
		ValidationErrors += 1;
		
	}
	ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
	if (ValidationErrors == 0) {
		document.getElementById("FormIsValid").value = "True";
		document.getElementById("button").style.display = "inline";
	}
	if (ValidationErrors != 0) {
		ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
		document.getElementById("FormIsValid").value = "False";
	}
	
}
function ValidateBankAccount() {
	document.getElementById("ValidationErrors").innerHTML = 0;
	document.getElementById("FormIsValid").value = "False";
	var ValidationErrors = 0;
	
	var terms = document.getElementById("terms");
	
	var wirerouting = document.getElementById("wirerouting");
	var achrouting = document.getElementById("achrouting");
	var accountnumber = document.getElementById("accountnumber");
	
	var bankname = document.getElementById("bankname");
	var bankphone= document.getElementById("bankphone");
	var bankaddress= document.getElementById("bankaddress");
	var bankcity= document.getElementById("bankcity");
	var bankstate= document.getElementById("bankstate");
	var bankzip= document.getElementById("bankzip");
	
	ValidateInput(wirerouting.id, "acctNumber", wirerouting.value);
	ValidateInput(achrouting.id, "acctNumber", achrouting.value);
	ValidateInput(accountnumber.id, "acctNumber", accountnumber.value);
	ValidateInput(bankname.id, "blank", bankname.value)
	ValidateInput(bankphone.id, "blank", bankphone.value)
	ValidateInput(bankaddress.id, "blank", bankaddress.value)
	ValidateInput(bankcity.id, "blank", bankcity.value)
	ValidateInput(bankstate.id, "blank", bankstate.value)
	ValidateInput(bankzip.id, "blank", bankzip.value)
	ValidateInput(bankzip.id, "blank", bankzip.value)
	if (terms.checked != true) {
		alert("You must agree to the term of service.");
		ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
		ValidationErrors += 1;
		document.getElementById("ValidationErrors").innerHTML = ValidationErrors;
		document.getElementById(elementID).bgColor = "yellow";
	}
	ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
	if (ValidationErrors == 0) {
		document.getElementById("FormIsValid").value = "True";
		document.getElementById("button").style.display = "inline";
	}
	if (ValidationErrors != 0) {
		ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
		document.getElementById("FormIsValid").value = "False";
	}
	
}

function ValidateInput(elementID, strType, strInput) {
		var ValidationErrors = parseInt(document.getElementById("ValidationErrors").innerHTML);
		oElement = document.getElementById(elementID);
		addElement(elementID + "Validation", oElement);
		if (strType == "acctNumber") {
			validationOutPut = ValidateAccount(strInput);
		}
		if (strType == "blank") {
			validationOutPut = ValidateBlank(strInput);
		}
		
		oElement = document.getElementById(elementID + "Validation");
		oElement.innerHTML = validationOutPut;
		 if (validationOutPut == "Valid.") {
			oElement.style.borderColor= "green";
			
		} else {
			oElement.style.borderColor= "red";
			ValidationErrors += 1;
			document.getElementById("ValidationErrors").innerHTML = ValidationErrors;
			document.getElementById(elementID).bgColor = "yellow";
		}
}
function ValidateBlank(strToCheck){
	var iLen = strToCheck.length;
	if (iLen != 0) {
		return "Valid.";
	} else {
		return "Field cannot be blank."
	}
}
function ValidateAccount(strToCheck) {
	var iLen = strToCheck.length;
	var boolcheck = IsNumeric(strToCheck);
	if (boolcheck == true && iLen > 8) {
		return "Valid.";
	} else {
			return "Not enough digits or invalid characters.";
	}
}

function ValidateEmail(strToCheck)
{
  apos=strToCheck.indexOf("@");
  dotpos=strToCheck.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return "This is not a valid email address";}
  else {return "Valid.";}
 
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }






function addElement(validationResults, oChildOFElement) {
  var divIdName = validationResults;
	
	document.getElementById("mydiv").innerHTML += '<div id="'+validationResults+'" style="background-color:white; font-family:verdana; font-size:10pt; border:2px solid red; position:absolute; left:'+getX(oChildOFElement)+'px; top:'+getY(oChildOFElement)+'px;"></div>';
    newdiv = document.getElementById(validationResults);
	newdiv.style.height = '20px';
	newdiv.style.position = "absolute";
	newdiv.style.left = (getX(oChildOFElement)+150).toString(10) + 'px';
    newdiv.style.top  = (getY(oChildOFElement)).toString(10) + 'px';
}
function addtext(what){
if (document.createTextNode){
var mytext=document.createTextNode(what)
document.getElementById("mydiv").appendChild(mytext)
}
}
function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

// open hidden layer
function mopen(id, ele)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.display = 'none';
	ddmenuitem = document.getElementById(id);

	//CreateWindow at mouse coords
	 CreateWindow(id, ele);
}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.display = 'none';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
function getY( oElement )
	{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function getX( oElement )
	{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

