function disableSubmit () {
	document.forms[0].submitBtn.disabled=true
	document.forms[0].submitBtn.value='Processing'
}	


//Monitor function used to prevent duplicate form submission
counter = 0;
function monitor() {
	counter++;
	if(counter > 1) { 
		return false;
	}
	return true;
}


function box (boxname, menustate){

if (document.getElementById)
{document.getElementById(boxname).style.visibility = menustate;}

else {document[boxname].visibility = menustate} }

function openWindow(url, height, width)
	{
		var win;
		win=window.open (url,"newwin","height=" + height +",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=20,left=20");

	}

function checkFormNew () {
	var form = document.pricePlan;
	var strSIC = form.SIC.value
	var plan = form.planSelected.value
	
	if (plan=="") {
		alert ('Please select a price plan.')
		return false;
	}
	if (strSIC=="") {
		alert ('Please select an industry/business type from the list below.')
		return false;
	}
}

function checkForm () { //Validation for PricePlan.asp
		
		var form = document.pricePlan;
		var strSIC = form.SIC.value
		
		var RiskLevel = strSIC.substr(0, 1)
		//alert (RiskLevel)
		//alert (form.planSelected.value)
		//return false;
	
	/*	for (var i=0;i<document.pricePlan.radio_plan.length;i++){
		    if (document.pricePlan.radio_plan[i].checked){
				planSelected = 1
		    }
		}
		 
	*/
		if (form.planSelected.value=='') {
			alert ('Please select a price plan.')
			return false;
		}
			
	   if (form.SIC.value=="") {
			alert ('Please select an industry from the list below.');
			return false;
		}
		if (RiskLevel=="3") {
			alert ('First ACH does not process for the selected industry.');
			return false;
		}
		
		if (RiskLevel=="2") {
			if (!confirm ('The industry you selected is deemed high risk and will therefore incur a 1.5% discount rate. \n                            By clicking OK, you agree to these terms.')) {
				return false;			
			}
			else {
				return true;
			}
		}
		
	}

function select_plan (plan_ID, setupFee, monthlyFee) {
	document.forms[0].planSelected.value=plan_ID
		
	document.forms[0].setupFee.value=setupFee
	//alert (document.forms[0].planSelected.value)
	//get days in current month:
	var now = new Date();
	//get today's day of the month
	var day_today = now.getDate ();
	var month = now.getMonth () //zero based
	var year = now.getYear ()
	proratedMonthly (month, year, day_today, monthlyFee)
	//document.forms[0].monthlyFee.value=monthlyFee/31
	imgClick ('select' + plan_ID)
}

function proratedMonthly(month,year,day_today,monthlyFee) {
	month = month + 1
	//get number of days for current month
	var dd = new Date(year, month, 0);
	var daysMonth = dd.getDate()
	
	//remaing days of month
	var daysRemain =  daysMonth - day_today
	//alert (daysRemain)
	//alert (dd.getDate())
	
	var proRatedFee = monthlyFee/daysMonth * daysRemain
	proRatedFee = proRatedFee.toFixed(2)
	document.forms[0].proratedMonthlyFee.value = proRatedFee
	//Math.round(proRatedFee*100) / 100
	//alert (document.forms[0].proratedMonthlyFee.value)
	costTotal ()
} 

function calSelected(){
	var cal = document.forms[0].cal.selectedIndex
	if (cal==0) {
		var calPrice = 0
	}
	if (cal==1) {
		var calPrice = 25.00
	}
	if (cal==2) {
		var calPrice = 112.50
	}
	if (cal==3) {
		var calPrice = 212.50
	}
	if (cal==4) {
		var calPrice = 468.75
	}
	//document.forms[0].addlCAL.value = calPrice
	document.forms[0].purchasedCAL.value = calPrice.toFixed(2)
}

function costTotal () {
	//alert (document.forms[0].purchasedCAL.value)
	var cal = document.forms[0].purchasedCAL.value * 1
	var setup = document.forms[0].setupFee.value * 1
	var proratedMonthly = document.forms[0].proratedMonthlyFee.value * 1
	
	var total = cal + setup + proratedMonthly
	document.forms[0].total.value = total.toFixed(2)
}

var on =""
function imgClick(imgName) {
	document.forms[0].cal.focus ()
	document[imgName].src = "/images/selectInvert.gif"
	on = imgName;
	imgOff (on)
}

function imgOff(imgName) {
	var minPlanID = (document.forms[0].minPlanID.value) * 1
	var maxPlanID = (document.forms[0].maxPlanID.value) * 1
	var imgOn = imgName
	//alert ('imgOn=' + imgOn)
	var baseImgName = "select"
	//NOTE:  i<=maxPlanID was i<maxPlanID: changed 5/20/2007
	for (var i=minPlanID; i<=maxPlanID; i++){
	//alert (baseImgName + i)
		if (baseImgName + i != imgOn) {
			document[baseImgName + i].src = "/images/select.gif"
		}
	}
	
}
function imgOn(imgName) {
		//alert (imgName)
		//alert (on)
		if (imgName!=on)
		{document[imgName].src = eval(imgName + "on.src");}
}
function setFocus (field) {
	 field.focus ();
	return false;
}

function routing_check (field) {
	bankID = field.value
	if (bankID == null || bankID == "") {
		alert ("Please enter a value for the routing number.")
		setFocus(field)
		return false
	}
	
	for (x = 0; x < bankID.length; x++) {

	   oneChar = bankID.charAt(x) 

		if (oneChar < "0" || oneChar > "9") {
			alert ("Please enter numbers only for the routing number.")
			setFocus(field)
			return false
		}
	}

	if (bankID.length < 9 || bankID.length > 9) {
		alert ("Please enter a valid 9 digit routing number.")
		setFocus(field)
		return false
	}
	
	rtg = bankID
	rtg0 = (rtg.charAt(0) * 3)
	rtg1 = (rtg.charAt(1) * 7)
	rtg2 = (rtg.charAt(2) * 1)
	rtg3 = (rtg.charAt(3) * 3)
	rtg4 = (rtg.charAt(4) * 7)
	rtg5 = (rtg.charAt(5) * 1)
	rtg6 = (rtg.charAt(6) * 3)
	rtg7 = (rtg.charAt(7) * 7)
	rtg8 = rtg.charAt(8) 

	rtgCalc = (rtg0 + rtg1 + rtg2 + rtg3 + rtg4 + rtg5 + rtg6 + rtg7)
	rtgCalc = rtgCalc.toString()
	rtgCalcSwitch = rtgCalc.charAt(rtgCalc.length - 1)

	addTo = new Array(0,9,8,7,6,5,4,3,2,1)

	for (x = 0; x < 10; x++) {
		if (x == rtgCalcSwitch) {
		minFrom = (parseInt(rtgCalc) + parseInt(addTo[x]))
		}
	}

	checkDig = (minFrom - rtgCalc)
	if (checkDig != rtg8) {
		alert ("The routing number you entered is invalid. Please enter a valid 9 digit bank routing number")
		setFocus(field)
		return false
	}
}



function isValidDate(fieldName) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
	alert("Date is not in a valid format.")
	return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31.");
	return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn't have 31 days!")
	return false
	}
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
	   }
	}
	return true;  // date is valid
}


function email_check (field) {
	if ((field.value.indexOf('@') == -1) || (field.value.indexOf('.') == -1)) {
			alert ('The email address entered is incorrectly formated.')
			setFocus (field)
			return false;
		}
}

function zip_check (field) {
	//alert ('zip')
	if ((field.value.length < 5) || (field.value.length > 5)){
			alert ('Please enter a valid 5 digit zip code.')
			setFocus (field)
			return false;
	}
	if (field.value != "" && field.value != null) {
		for (x = 0; x < field.value.length; x++) {
			oneChar = field.value.charAt(x)
			if (oneChar < "0" || oneChar > "9") {
				alert ("Please enter numbers only for the zip code.")
				setFocus (field)
				return false
			}
		}
	}	
}	

function ss_check (field) {
	if (field.value.length < 9) {
		alert ('Please enter a valid 9 digit social security number.')
		setFocus (field)
		return false;
	}
	//alert (field.value)
	if (field.value=="") {
			alert ('Please enter the social security number.')
			setFocus (field)
			return false
		}

	if ((field.value=="000000000") || (field.value=="999999999")){
		alert ('Please enter a valid social security number.')
		setFocus (field)
		return false
	}
/*	
	for (x = 0; x < field.value.length; x++) { 
		var oneChar = field.value.charAt(x)
		if (field.value.charAt(3) != "-" || field.value.charAt(6) != "-") {
			alert ("Please enter the social security number in the proper format(xxx-xx-xxxx).")
			setFocus (field)
			return false
		}
	}
*/
	for (x = 0; x < 9; x++) {
		var oneChar = field.value.charAt(x)
		if (oneChar < "0" || oneChar > "9") {
			//alert (oneChar)
			alert ("Please enter numbers only for the social security number.")
			setFocus (field)
			return false
		}
	}
	
/*	
	for (x = 4; x < 6; x++) {
		var oneChar = field.value.charAt(x)
		if (oneChar < "0" || oneChar > "9") {
			alert ("Please enter numbers only for the social security number.")
			setFocus (field)
			return false
		}
	}
	for (x = 7; x < 11; x++) {
		var oneChar = field.value.charAt(x)
		if (oneChar < "0" || oneChar > "9") {
			alert ("Please enter numbers only for the social security number.")
			setFocus (field)
			return false
		}
	}
*/
}

function dob_check (field) {
		if (field.value=="") {
			alert ('Please enter the DOB.')
			setFocus (field)
			return false
		}
		for (x = 0; x < field.value.length; x++) { 
				var oneChar = field.value.charAt(x)
				if (field.value.charAt(2) != "/" || field.value.charAt(5) != "/") {
					alert ("Please enter the DOB in the proper format (MM/DD/YYYY).")
					setFocus (field)
					return false
				}
		}
		for (x = 0; x < 2; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the DOB.")
					setFocus (field)
					return false
				}
		}
		for (x = 3; x < 5; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the DOB.")
					setFocus (field)	
					return false
				}
		}
		for (x = 6; x < 10; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the DOB.")
					setFocus (field)	
					return false
				}
		}
}

function phone_check (field, name) {
	
	if (field.value != "" && field.value != null && field.value.length==12) {
		for (x = 0; x < field.value.length; x++) { 
				var oneChar = field.value.charAt(x)
				if (field.value.charAt(3) != "-" || field.value.charAt(7) != "-") {
					alert ("Please enter the " + name + " # in the proper format(xxx-xxx-xxxx).")
					setFocus (field)
					return false
				}
			}
		
			for (x = 0; x < 3; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the " + name + "  #.")
					setFocus (field)
					return false
				}
			}
	
			for (x = 4; x < 7; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the " + name + "  #.")
					setFocus (field)	
					return false
				}
			}
	
			for (x = 8; x < 12; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the " + name + "  #.")
					setFocus (field)	
					return false
				}
			}
		}
		else {
			if (field.value.length != 10) {
				alert ("Please enter a valid 10 digit " + name + " number.")
				setFocus (field)
				return false
			}
			
			for (x = 0; x < 10; x++) {
				var oneChar = field.value.charAt(x)
				if (oneChar < "0" || oneChar > "9") {
					alert ("Please enter numbers only for the " + name + "  #.")
					setFocus (field)
					return false
				}
			}
		}
		
}

function check_numbers (field, name) {
	var strlen = field.value.length 
	//alert (field.value)
	for (x = 0; x < strlen; x++) {
		var oneChar = field.value.charAt(x)
		if (oneChar < "0" || oneChar > "9") {
			alert ("Please enter numbers only for the " + name + ".")
			setFocus (field)	
			return false
		}
	}
}

function zeroCheck (field, name) {
	if (field.value == '0.00') {
		alert ("Please enter a number greater than zero for the " + name + ".")
		setFocus (field)	
		return false
	}	
}

function isURL(url){
  alert (url)
  if (/^w+([.-]?w+)*.w+([.-]?w+)*(.w{2,3})+$/.test(url)){
	
   return (true)
  } else {
    return (false);
  }
}


function set_zero (field) {
	var str='document.merchantApp.' + field + '.value'
	var str1 = 'document.merchantApp.' + field + '.value=0'
	
	if (eval(str)=="") {
		eval(str1)
	}

}
function popfields () {
	var f = document.forms[0];
//	alert (document.forms[0].fieldpop.checked)
	if (f.fieldpop.checked==true) {
		f.legalName.value = f.dbaName.value
		f.legalAddress.value = f.locationAddress.value 
		f.legalCity.value = f.locationCity.value 
		f.legalState.value = f.locationState.value
		f.legalZip.value = f.locationZip.value 
		f.corpPhone.value = f.dbaPhone.value 
		f.corpFax.value = f.fax.value 
		f.legalContactName.value = f.contactName.value
		f.corpEmail.value = f.email.value 
	}
}

function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0
	var key = ''
	var i = j = 0
	var len = len2 = 0
	var strCheck = '0123456789'
	var aux = aux2 = ''
	var whichCode = (window.Event) ? e.which : e.keyCode
	if (whichCode == 13) {
	return true  // Enter
	}
	key = String.fromCharCode(whichCode)  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
	return false  // Not a valid key
	}
	len = fld.value.length
	while (len < 11) {
		for(i = 0; i < len; i++) {
			if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) {
				break
			}
		}
		aux = ''
		for(; i < len; i++) {
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
				aux += fld.value.charAt(i)
			}
		}
		aux += key
		len = aux.length
		if (len == 0) {
			fld.value = ''
		}
		if (len == 1) {
			fld.value = '0'+ decSep + '0' + aux
		}
		if (len == 2) {
			fld.value = '0'+ decSep + aux
		}
		if (len > 2) {
			aux2 = ''
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) {
					aux2 += milSep
					j = 0
				}
			aux2 += aux.charAt(i)
			j++
			}
			fld.value = ''
			len2 = aux2.length
			for (i = len2 - 1; i >= 0; i--) {
				fld.value += aux2.charAt(i)
			}
			fld.value += decSep + aux.substr(len - 2, len)
		
		}
		return false
	}
	return false
}
	