NS4 = (document.layers)
IE4 = (document.all)
ver4 = (NS4 || IE4)
IE5 = (IE4 && navigator.appVersion.indexOf("5.")!=-1)
isMac = (navigator.appVersion.indexOf("Mac") != -1)
isMenu = (NS4 || (IE4 && !isMac) || (IE5 && isMac))
function popUp(){return}
function popDown(){return}
if (!ver4) event=null

formArr = new Array()
formArr[0] = "####"
formArr[1] = "Name on Credit card"
formArr[2] = "Your street address or P O Box"
formArr[3] = "Your town and post code"
formArr[4] = "Your e-mail address (for us to confirm dispatch)"
formArr[5] = "Any personal message to Focal Point Publications?"
errorMsg = new Array()
errorMsg[1] = "Please select credit card type"
errorMsg[2] = "Please check card number"
errorMsg[3] = "Please select credit card expiration month"
errorMsg[4] = "Please select credit card expiration year"
errorMsg[5] = "Please input name on card"
errorMsg[6] = "Please input street address"
errorMsg[7] = "Please input city address"
errorMsg[8] = "Please check book desired"
monthflag = false
yearflag = false
country = 'GBP'
for(i = 0; i < exchRateArray.length; i++)
{
	tmp = exchRateArray[i]
	if(tmp.substring(0,3) == country) break
}
tmp = tmp.split('=')
exchrate = tmp[1]
  submitFlag = false
  function checkInput(form) {
	if(submitFlag == true)
	{
		alert('You have submitted form!')
		return false
	}
	ptr = false
	if(/Name on Credit card/.exec(form.NAME.value) || form.NAME.value == "") ptr = 5 
	else if(/Your street address or P O Box/.exec(form.STREET.value) || form.STREET.value.length == 0) ptr = 6
	else if(/Your town and post code/.exec(form.TOWN.value) || form.TOWN.value.length == 0) ptr = 7
	else if(!emailCheck(form.confirm_to.value)) return false
	else if(!/\£/g.exec(form.total.value)) ptr = 8
	if(ptr>0)
	{
		alert(errorMsg[ptr])
		return false
	}
	form.x_last_name.value = form.NAME.value
	form.x_address.value = form.STREET.value
	form.x_city.value = form.TOWN.value
	form.x_email.value = form.confirm_to.value
	document.authorize.submit()
	submitFlag = true
  }
  function emailCheck (emailStr)
  {
	emailPat=/^(.+)@(.+)$/
	specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	validChars="\[^\\s" + specialChars + "\]"
	quotedUser="(\"[^\"]*\")"
	ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	atom=validChars + '+'
	word="(" + atom + "|" + quotedUser + ")"
	userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	matchArray=emailStr.match(emailPat)
	if(matchArray==null)
	{
		alert("Invalid e-mail address!")
		return false
	}
	user=matchArray[1]
	domain=matchArray[2]
	if(user.match(userPat)==null)
	{
		alert("Invalid username!")
		return false
	}
	IPArray=domain.match(ipDomainPat)
	if(IPArray!=null) {
		for (var i=1;i<=4;i++) {
        		if (IPArray[i]>255) {
				alert("Invalid IP address!")
				return false
			}
		}
		return true
	}
	domainArray=domain.match(domainPat)
	if(domainArray==null)
	{
		alert("Invalid domain name!")
		return false
	}
	atomPat=new RegExp(atom,"g")
	domArr=domain.match(atomPat)
	len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		alert("The address must end in a three-letter domain, or two letter country.")
		return false
	}
	if(len<2)
	{
		var errStr="This address is missing a hostname!"
		alert(errStr)
		return false
	}
	return true;
  }

  function selectChoice(form)
  {
	form.hiddentotal.value = 0
	tot = 0 ; num = 0
	for( i = 0; i < document.forms[0].elements.length; i++)
	{
		if(form.elements[i].type == 'select-one')
		{
			obj = form.elements[i]
			str = obj.name
			tmpArr = str.split('-')
			tot += tmpArr[1] * obj[obj.selectedIndex].text
		}
	}
	form.total.value = formatCurrency(tot)
	form.hiddentotal.value = tot	
	// compute exchange
	num = tot * exchrate
	cents=Math.floor((num*100+0.5)%100)
	num=Math.floor((num*100+0.5)/100).toString()
	if(cents<10) cents="0"+cents
	for(var i=0;i<Math.floor((num.length-(1+i))/3);i++)
		num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3))
	document.authorize.x_amount.value = num+"."+cents
  }

  function formatCurrency(num)
  {
	num=num.toString().replace(/\£|\,/g,'')
	if(isNaN(num)) num="0"
	cents=Math.floor((num*100+0.5)%100)
	num=Math.floor((num*100+0.5)/100).toString()
	if(cents<10) cents="0"+cents
	for(var i=0;i<Math.floor((num.length-(1+i))/3);i++)
	{
		num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3))
	}
	return("£"+num+"."+cents)
  }
//  window.onload = init
  function init()
  {
	document.authorize.reset()
  }
