NextItem = 1;

function ToDollars(getVal) {
	tempVal = ""+getVal
return	"$"+(tempVal.substring(0,tempVal.length-2))+"."+(tempVal.substring(tempVal.length-2,tempVal.length))
}


function totalForm() {
  with(document.TixForm) {
	line_total_1.value=ToDollars(Signed_Book.selectedIndex*1595)
	line_total_2.value=ToDollars(PDF_Book.selectedIndex*795)
	line_total.value = ToDollars((Signed_Book.selectedIndex*1595)+(PDF_Book.selectedIndex*795))

	document.PayPalForm.line_total.value = line_total.value;
  }
}
function setPP(iname,amt,qty,num,on0,os0,on1,os1) {
  with(document.PayPalForm) {
         if (NextItem==1) { item_name_1.value=iname; amount_1.value=amt; quantity_1.value=qty; item_number_1.value=num; on0_1.value=on0; os0_1.value=os0; on1_1.value=on1; os1_1.value=os1; }
    else if (NextItem==2) { item_name_2.value=iname; amount_2.value=amt; quantity_2.value=qty; item_number_2.value=num; on0_2.value=on0; os0_2.value=os0; on1_2.value=on1; os1_2.value=os1; }
    NextItem++;
  } //END WITH
}
function setValues() {

    //// DATA VALIDATION ////
    var pattern = /\s*\w+@[^\.]+\.[^\.]+(\.[^\.])*\s*/;
    legalChars = "~0123456789.-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@+";
    errorMsg = "";

    with (document.PayPalForm) {
	if (RegName.value.length < 2)	errorMsg += "\nPlease provide your Name";
	if (Phone.value.length < 10)	errorMsg += "\nPhone Number must be at least 10 numbers";
	if (Address1.value.length < 1)	errorMsg += "\nPlease provide your Address";
	if (Address2.value.length < 1)	errorMsg += "\nPlease provide your City, State, and Zip Code";
	if (Email.value.length < 7)
		errorMsg += "\nE-Mail address must be at least 7 characters";
	//Validate Email against pattern match
	if (Email.value != "")
	    if(!pattern.test(Email.value))
			errorMsg += "\nInvalid E-Mail Address."
	//This enhances the previous EMail check. This checks for legal values and returns illegal values
	if (Email.value != "" && Email.value.length > 1) {
	    for(x=0; x < Email.value.length; x++) {
		if (legalChars.indexOf(Email.value.substring(x,x+1)) < 0)
		    errorMsg += "\n" + "Illegal character '"+Email.value.substring(x,x+1)+"' at position " +(x+1)+ " in E-Mail Address.";
	    }
	}
	//FINAL CHECK FOR ERROR MESSAGES
	if (errorMsg.length > 0) {
		errorMsg = "The following errors must be corrected before submitting this form: \n" + errorMsg
		alert (errorMsg);
		return false;
	}

   }	//end WITH

/************************/

  NextItem = 1;
  with(document.TixForm) {
    if (Signed_Book.selectedIndex > 0)	setPP("That Was Zen, This is Wow.","15.95",Signed_Book.selectedIndex,"Signed_Book","xxx","yyy","Price","$15.95 each");
    if (PDF_Book.selectedIndex > 0)	setPP("That Was Zen, This is Wow.","7.95",PDF_Book.selectedIndex,"PDF_Book","xxx","yyy","Price","$7.95 each");
  } //END WITH
         if (NextItem==1) { document.PayPalForm.item_name_1.value = "noitem"; document.PayPalForm.item_name_1.name = "noitem"; }
    else if (NextItem==2) { document.PayPalForm.item_name_2.value = "noitem"; document.PayPalForm.item_name_2.name = "noitem"; }

    //if (document.TixForm.shipit[0].checked)	//    document.PayPalForm.custom.value = "Shipping Requested"
    //else	//	document.PayPalForm.custom.value = "Will Call"

return true;
//return false;
}
