

	function isWhite(value){
		if(value == ""){
			return true
		}
		for(i=0; i<value.length; i++){
			if(value.charAt(i) != ' '){
				return false
			}
		}
		return true
	}

	function trimHead(value){
		if(value == ""){
			return ""
		}
		for(i=0; i<value.length; i++){
			if(value.charAt(i) != ' '){
				return value.substring(i);
			}
		}
		return ""
	}

	function trimTail(value){
		if(value == ""){
			return ""
		}
		for(i=value.length-1; i>=0; i--){
			if(value.charAt(i) != ' '){
				return value.substring(0,i+1);
			}
		}
		return ""
	}

	function trim(value){
		var s1 = trimHead(value)
		return trimTail(s1)
	}

	function submitIt(tranForm){
		if(tranForm.TYPE.value == null || tranForm.TYPE.value == ""){
			alert("Transaction Type required")
				return false;
			}

		if(tranForm.TYPE.value == "C"){
			if(isWhite(tranForm.REFSEQNUM.value)){
				alert("Pre-Authorisition Sequence Number required")
				tranForm.REFSEQNUM.focus()
				tranForm.REFSEQNUM.select()
				return false
			}
		}else if(tranForm.TYPE.value == "V"){
			if(isWhite(tranForm.REFSEQNUM.value)){
				alert("Sequence Number required")
				tranForm.REFSEQNUM.focus()
				tranForm.REFSEQNUM.select()
				return false
			}
		}
		
		if(isWhite(tranForm.CARDNUM.value) || trim(tranForm.CARDNUM.value).length < 16 ){
			alert("Valid Card Number required")
			tranForm.CARDNUM.focus()
			tranForm.CARDNUM.select()
			return false
		}
		if(!isAmount(tranForm.AMOUNT.value)){
			alert("Valid Amount required")
			tranForm.AMOUNT.focus()
			tranForm.AMOUNT.select()
			return false
		}
		if(!isWhite(tranForm.EMAIL.value) && !isEmail(trim(tranForm.EMAIL.value))){
			alert("Valid Purchasers email Address required")
			tranForm.EMAIL.focus()
			tranForm.EMAIL.select()
			return false
		}
		if(isWhite(tranForm.EMAIL.value)){
			alert("Valid Purchasers email Address required")
			tranForm.EMAIL.focus()
			tranForm.EMAIL.select()
			return false
		}
		return true
	}

	function isEmail(email){
		invalidChars = " /:,;"
		for(i=0; i<invalidChars.length; i++){
			badChar = invalidChars.charAt(i)
			if(email.indexOf(badChar,0) > -1){
				return false
			}
		}
		atPos = email.indexOf('@')

		if(atPos == -1){
			return false
		}

		if(email.indexOf("@",atPos+1) > -1){
			return false
		}

		periodPos = email.indexOf(".",atPos)
		if(periodPos == -1){
			return false
		}

		if(periodPos+3 > email.length){
			return false
		}

		return true
	}

	function isAmount(amount){
		if(amount == "" || isWhite(amount)){
			return flase
		}
		periodPos = amount.indexOf(".",0)
		trimed = trim(amount)
		if(periodPos == -1){
			for(i=0; i<trimed.length; i++){
				if(trimed.charAt(i) < "0"){
					return false
				}
				if(trimed.charAt(i) > "9"){
					return false
				}
			}
			return true
		}
		secPeriodPos = amount.indexOf(".",periodPos+1)
		if(secPeriodPos > -1){
			return false
		}
		for(i=0; i<trimed.length; i++){
			if(trimed.charAt(i) < "0" && trimed.charAt(i) != "."){
				return false
			}
			if(trimed.charAt(i) > "9" && trimed.charAt(i) != "."){
				return false
			}
		}
		return true
	}