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 = 'ZAR'
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.x_last_name.value) || form.x_last_name.value == "") ptr = 5 
	else if(/Your street address or P O Box/.exec(form.x_address.value) || form.x_address.value.length == 0) ptr = 6
	else if(/Your town and post code/.exec(form.x_state.value) || form.x_state.value.length == 0) ptr = 7
	else if(!emailCheck(form.x_email.value)) return false
	else if(form.total.value == 0) ptr = 8
	if(ptr>0)
	{
		alert(errorMsg[ptr])
		return false
	}

	tot = document.authorize.total.value
	if(tot < 100) tot = tot * 1.06
	// compute exchange rate
	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
	document.authorize.submit()
	submitFlag = true
  }
  function calcAmount(form)
  {
	tot = 0
	qty = form.Quantity_1[form.Quantity_1.selectedIndex].value
	tmpArr = form.FIRST_BOOK[form.FIRST_BOOK.selectedIndex].text.split('R.')
	tot = qty * tmpArr[1]
	form.EXTENSION1.value = tot
	qty = form.Quantity_2[form.Quantity_2.selectedIndex].value
	tmpArr = form.SECOND_BOOK[form.SECOND_BOOK.selectedIndex].text.split('R.')
	tot1 = qty * tmpArr[1]
	form.EXTENSION2.value = tot1
	tot = tot + tot1
	form.total.value = tot+'.00'
  }
  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 checkChoice(whichbox)
  {
	with(whichbox.form)
	{
		if(whichbox.checked==false)
		{
			hiddentotal.value=eval(hiddentotal.value)-eval(whichbox.value)
		}
		else
		{
			hiddentotal.value=eval(hiddentotal.value)+eval(whichbox.value)
		}
		// compute exchange
		num = hiddentotal.value * 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
		return(formatCurrency(hiddentotal.value))
	}
  }
  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()
  {
	// get exchange rate
	for(i = 0; i < exchRateArray.length; i++)
	{
		tmp = exchRateArray[i]
		if(tmp.substring(0,3) == country) break
	}
	tmp = tmp.split('=')
	exchrate = tmp[1]
  }
