
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}





function verifyFormSupport(){


	if (document.form1.email.value.length == 0)
	{
		alert("Please enter your email address");
		return false;
	}

}


function verifyFormProduct(){


	if (document.form1.fName.value.length == 0)
	{
		alert("Please enter your First Name");
		return false;
	}

	if (document.form1.lName.value.length == 0)
	{
		alert("Please enter your Last Name");
		return false;
	}

	if (document.form1.email.value.length == 0)
	{
		alert("Please enter your email address");
		return false;
	}

	if (document.form1.phone.value.length == 0)
	{
		alert("Please enter your Telephone Number");
		return false;
	}

}

function verifyForm()
{
	if (document.form1.company.value.length == 0)
	{
		alert("Please enter your company name");
		return false;
	}
	if (document.form1.address.value.length == 0)
	{
		alert("Please enter your company address (not PO Box)");
		return false;
	}
	if (document.form1.state.value.length == 0)
	{
		alert("Please enter your state");
		return false;
	}
	if (document.form1.suburb.value.length == 0)
	{
		alert("Please enter your suburb");
		return false;
	}
	if (document.form1.postcode.value.length == 0)
	{
		alert("Please enter your Post Code");
		return false;
	}
	if (document.form1.attn.value.length == 0)
	{
		alert("Please specify who it will be addressed to");
		return false;
	}
	if (document.form1.email.value.length == 0)
	{
		alert("Please enter your email address");
		return false;
	}
	if (document.form1.phone.value.length == 0)
	{
		alert("Please enter your phone number");
		return false;
	}
	if (document.form1.authName.value.length == 0)
	{
		alert("Please enter the Authorisation Name");
		return false;
	}
	if (document.form1.authDate.value.length == 0)
	{
		alert("Please enter the Authorisation Date");
		return false;
	}
	if ((document.form1.payment_opt[0].checked == false) && (document.form1.payment_opt[1].checked == false) && (document.form1.payment_opt[2].checked == false) && (document.form1.payment_opt[3].checked == false))
	{
		alert("Please select a payment option");
		return false;
	}
	
	if (document.form1.payment_opt[3].checked)
	{
		if ((document.form1.ccType[0].checked == false) && (document.form1.ccType[1].checked == false) && (document.form1.ccType[2].checked == false) && (document.form1.ccType[3].checked == false))
		{
			alert("Please enter the card type");
			return false;
		}
		if (document.form1.ccNum.value.length == 0)
		{
			alert("Please enter the credit card number (without spaces)");
			return false;
		}
		
		if (document.form1.ccType[0].checked == true || document.form1.ccType[1].checked == true)
		{
			if (document.form1.ccNum.value.length != 16)
			{
				alert("Please enter the number of digits of your credit card number");
				return false;
			}
		}
		
		if (document.form1.ccType[2].checked == true)
		{
			if (document.form1.ccNum.value.length != 15)
			{
				alert("Please enter the number of digits of your credit card number");
				return false;
			}
		}
		
		if (document.form1.ccType[3].checked == true)
		{
			if (document.form1.ccNum.value.length != 14)
			{
				alert("Please enter the number of digits of your credit card number");
				return false;
			}
		}
		if (document.form1.ccName.value.length == 0)
		{
			alert("Please enter the name on the credit card");
			return false;
		}
		if (document.form1.ccExpDate.value.length == 0)
		{
			alert("Please enter the expiry date");
			return false;
		}
	}
	if (document.form1.authTotal.value.length == 0)
	{
		alert("Please enter the payment Total");
		return false;
	}
	return true;
}

function roundcurrency(number)
{
  if (number == 0)
  { return 0 ;}
  else 
  {
    var dol=number*100;
    dol=Math.round(dol);
    var dolstring=dol+"";
    var len=dolstring.length;
	
	if (dol < 10) {
		var endFig = "0.0"+dol;
	}
	else {
		var endFig = dolstring.substring(0,len-2)+"."+dolstring.substring(len-2,len);
	}

    return endFig;
  }
} 

function isNum(field_value)
{
  if (field_value.value.length > 0)
  {
    if (isNaN(field_value.value))
    {
      field_value.value = "";
      alert("Please enter a valid numerical value.");
      field_value.focus();
      return false;
    }
  }
}

function calProdTotal(field_value)
{
	if (field_value != null)
	{
	    isNum(field_value);
    	if ( field_value.name.indexOf("price") >= 0 && field_value.value.length != 0 )
	    {
    	  field_value.value = roundcurrency( parseFloat(field_value.value) );
	    }
	}
	
	var form_name = 'form1';
	var s_total_tally = 0;
	var s_rows_to_total = 20;
	var freightTotal = 0;
	
	for ( k = 1; k <= s_rows_to_total + 1; k++ )
	{
    	if ( eval('document.' +form_name+ '.s' +k+ '_qty.value.length') != 0 )
	    {
    		var s_current_total = 0;
		    s_current_total = parseFloat( eval('document.' +form_name+ '.s' +k+ '_unit_price.value') ) * parseFloat( eval('document.' +form_name+ '.s' +k+ '_qty.value') );
		    s_current_total = roundcurrency(s_current_total);
		    eval('document.' +form_name+ '.s' +k+ '_total.value = s_current_total');
		    s_total_tally = parseFloat(s_total_tally) + parseFloat( eval('document.' +form_name+ '.s' +k+ '_total.value') );
			
			fTotal = parseInt( eval('document.'+form_name+'.s'+k+'_size.value') ) * parseFloat(eval('document.'+form_name+'.s'+k+'_qty.value') );

			freightTotal = parseInt(freightTotal+fTotal);
	    }
	    else if ( eval('document.' +form_name+ '.s' +k+ '_qty.value.length') == 0 && eval('document.' +form_name+ '.s' +k+ '_total.value.length') != 0 )
    	{
	      eval('document.' +form_name+ '.s' +k+ '_total.value = ""');
		  eval('document.'+form_name+'.s22_total.value = ""');
    	}
	}
	
	if (freightTotal < 2000)
	{
		freightTotalCharge = parseFloat(eval('document.'+form_name+'.s22_total.value = "11.00"'));
	}
	else
	{
		freightTotalCharge = parseFloat(eval('document.'+form_name+'.s22_total.value = "0.00"'));
	}
	
	s_total_tally = roundcurrency(s_total_tally + freightTotalCharge);
	
	eval('document.' +form_name+ '.s_total.value = s_total_tally');
	eval('document.' +form_name+ '.authTotal.value = s_total_tally');
}

function checkQty(sValue, sQty) {
	var form_name = 'form1';
	if ( eval('document.'+form_name+'.'+sQty+'_qty.value') > 1) {
		eval('document.'+form_name+'.'+sQty+'_qty.value = ""');
		eval('document.'+form_name+'.'+sQty+'_qty.focus()');
		alert("For order quantities of 2000 payslips or more please use this product's 'Per 1000's' Pack Size.");
	}
}

function checkQty2(sValue, sQty) {
	var form_name = 'form1';
	if ( eval('document.'+form_name+'.'+sQty+'_qty.value') == 1) {
		eval('document.'+form_name+'.'+sQty+'_qty.value = ""');
		eval('document.'+form_name+'.'+sQty+'_qty.focus()');
		alert("For order quantities of less than 2000 payslips please use this product's 'Box of 500' or 'Box of 1000' Pack Size");
	}
}