﻿/*
    External Javascript File
*/

    var invoiceTotal = 25.00;
    function CalculateTotal(txt, lbl1, lbl2)
    {
        var quantity;
        if (txt.value == "" || txt.value == "0")
        {
            quantity = 1;
        } 
        {       
            quantity = txt.value;
        }
        var formattedSubtotal = "$" + (Math.round((quantity * 25.00) * 100)/100).toFixed(2);
        document.getElementById(lbl1).innerText = formattedSubtotal;
        document.getElementById(lbl2).value = formattedSubtotal;
        invoiceTotal  =  (Math.round((quantity * 25.00) * 100)/100).toFixed(2);
    }
    
    function SubmitPayment()
    {
        PayByCC();
        return false;
    }
    
    function PayByCC()
    {
        if (invoiceTotal == 0)
            return;
            
       // set paypal variable names 
        amount.name = "amount";  
        amount.value = invoiceTotal
        item_name.name = "item_name";
        first_name.name = "first_name";
        last_name.name = "last_name";
        address1.name = "address1";
        address2.name = "address2";
        city.name = "city";
        state.name = "state";
        zip.name = "zip";
        invoice.name = "invoice";
        custom.name = "custom";
        option_name_1.name = "option_name_1";
        option_name_2.name = "option_name_2";
        option_selection1.name = "option_selection1";   
             
        //prepare to submit
         document.aspnetForm.action="https://www.paypal.com/cgi-bin/webscr";
        document.aspnetForm.target="_blank";
        document.aspnetForm.submit();
    }
    
/* ********************************************************************************************************
// HTML Text Validators
 *********************************************************************************************************/
	function isNothing(oVar){
	//oVar== ""  ||
 		return (oVar == undefined || oVar == null ||  (typeof(oVar) == "undefined")) ? true: false;
	}

	function numbersonly(myfield, e, dec)
	{
		var key;
		var keychar;

		if (window.event){
			key = window.event.keyCode;
		}else if (e){
					key = e.which;
		}
		else{
			return true;
		}
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			return true;

		// numbers
		else if ((("0123456789.\-").indexOf(keychar) > -1))
			return true;

		// decimal point jump
		else if (dec && (keychar == "."))
			{
			myfield.form.elements[dec].focus();
			return false;
			}
		else
			return false;
	}
	
	function datesOnly(oEvent){
		return baseMatchOnly(oEvent,"[0-9\:\/\ ]");
	}
	
	function noSpecialCharacters( oEvent){
		return baseMatchOnly(oEvent,"[A-Z0-9\-\_\.\\/ \:\!\@\#\$\%\&\*\(\)]");
	}
	function phoneNumberOnly( oEvent ){
		return baseMatchOnly(oEvent,"[0-9\-\(\)\ ]");
	}
	function emailCharactersOnly( oEvent ){
		return baseMatchOnly(oEvent,"[A-Z0-9\-\_\@\.]");			
			
	}
	function alphaNumericOnly( oEvent){
		return baseMatchOnly(oEvent,"[A-Z0-9]");			
	}
	function integersOnly( oEvent){
		return baseMatchOnly(oEvent,"[\-\+0-9]");			
	}
	function numbersOnly( oEvent){
		return baseMatchOnly(oEvent,"[<#48><#48><#49><#50><#51><#52><#53><#54><#55><#56><#57>]");			
	}

	function currencyOnly( oEvent){
		return baseMatchOnly(oEvent,"[\$0-9]");			
	}

	function isMatch( strToMatch, RegExpression ) {
   			var regExp = new RegExp(RegExpression,"i");
			return regExp.test( strToMatch );
		}
	function baseMatchOnly( oEvent, sRegEx ){
		var key;
		var keychar;

		if (window.event){
			key = window.event.keyCode;
		}else if (oEvent){
			key = oEvent.which;
		}
		else{
			return true;
		}
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			return true;

		// numbers
		else if (isMatch(keychar,sRegEx))
			return true;
		else
			return false;
	}
function makeTextUpperCase(oControl){
	oControl.value = oControl.value.toUpperCase();
}
function EnterToTab()
{
	var key = window.event.keyCode;
			
	if (!((key == 9) || (key == 13)))
		return;
		
	if (key == 13)
		window.event.keyCode = 9;	
}
