﻿//UTILITY FUNCTIONS

function ValidateState(source, args)
{
  if((theForm.ddlCountry.value == "UNITED STATES" || theForm.ddlCountry.value == "CANADA") && isEmpty(theForm.ddlState.value))
    args.IsValid = false;
  else
    args.IsValid = true;
}

function CheckStateRequired()
{
    if(theForm.ddlCountry.value == "UNITED STATES" || theForm.ddlCountry.value == "CANADA")
    {
        var ele = document.getElementById("spStateRequired");
        ele.style.display = "inline";
    }
    else
    {
        var ele = document.getElementById("spStateRequired");
        ele.style.display = "none";
    }
}

//UTILITY FUNCTIONS

function rTrim(asValue) 
{
	for(iCount = asValue.length ; iCount > 0  ; iCount--) {
		if(asValue.substr(iCount - 1, 1) == " ") {
			asValue = asValue.substr(0, iCount - 1)
		}
		else
			break
	}
		
	return asValue
}

function Trim(asValue) 
{
	var bFound

	asValue = rTrim(asValue)
	do {
		bFound = false
		if(asValue.substr(0, 1) == " ") {
			bFound = true
			asValue = asValue.substr(1)
		}
	}
	while(bFound)
		
	return asValue
}

function isEmpty(sString)
{
  return (sString == null || Trim(sString) == "") ? true : false
}