function submittest(a_value)
{
	 document.myform.action.value = a_value; 
     document.myform.submit();
}	

function submitreport(action,id,field_list)
{
	 document.myform.action.value     = action;
	 document.myform.id.value         = id; 
	 document.myform.field_list.value = field_list;
	 document.myform.submit(); 
}


function submitenter(myfield,e,a_value)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.myform.action.value = a_value; 	   
   myfield.form.submit();
   return false;
   }
else
   return true;
}

	
function move_window(a,b)
{
   window.scrollTo(a, b );
}


function lockCol(tblID) {

	var table = document.getElementById(tblID);
	var button = document.getElementById('toggle');
	var cTR = table.getElementsByTagName('TR');  //collection of rows

	if (table.rows[0].cells[0].className == '') {
		for (i = 0; i < cTR.length; i++)
			{
			var tr = cTR.item(i);
			tr.cells[0].className = 'locked'
			tr.cells[1].className = 'locked'
			tr.cells[2].className = 'locked'
			tr.cells[3].className = 'locked'
			
			}
		button.innerText = "Unlock First Column";
		}
		else {
		for (i = 0; i < cTR.length; i++)
			{
			var tr = cTR.item(i);
			tr.cells[0].className = ''
			}
		button.innerText = "Lock First Column";
		}
}

function lockCol5(tblID) {

	var table = document.getElementById(tblID);
	var button = document.getElementById('toggle');
	var cTR = table.getElementsByTagName('TR');  //collection of rows

	if (table.rows[0].cells[0].className == '') {
		for (i = 0; i < cTR.length; i++)
			{
			var tr = cTR.item(i);
			tr.cells[0].className = 'locked'
			tr.cells[1].className = 'locked'
			tr.cells[2].className = 'locked'
			tr.cells[3].className = 'locked'
			tr.cells[4].className = 'locked'
			tr.cells[5].className = 'locked'
			}
		button.innerText = "Unlock First Column";
		}
		else {
		for (i = 0; i < cTR.length; i++)
			{
			var tr = cTR.item(i);
			tr.cells[0].className = ''
			}
		button.innerText = "Lock First Column";
		}
}

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}


function removeElement(id) {
  var element = document.getElementById(id);
  element.parentNode.removeChild(element);
}



function validate_form ( )
{
	valid = true

	var n_tickets      =  +document.input_form.n_tickets.value
	var n_tables       =  +document.input_form.n_tables.value
	var tbls_available =  +document.input_form.tbls_available.value
	var tks_available  =  +document.input_form.tks_available.value
	var seats_per_table  =  document.input_form.seats_per_table.value
			
	if (n_tickets == "")
	   {  n_tickets = 0 }
	     
	if (n_tables == "")
	   {  n_tables = 0 }    
	   			     
    if ( isInteger(n_tickets) == false || isInteger(n_tables) == false || n_tables < 0 || n_tickets < 0 || (n_tables == 0 && n_tickets == 0) )
       {
	     alert("The number of tickets or tables looks to be invalid.")
	     valid = false
	     return valid	   
	   }   
	   
	if (n_tables > tbls_available)
	   {
		 alert( "Sorry there are only " + tbls_available + " tables available, please chose a smaller number.")
	     valid = false
	     return valid  
       }	      
	   
 	if (n_tickets > tks_available)
	   {
		 alert( "Sorry there are only " + tks_available + " tickets available, please chose a smaller number.")
	     valid = false
	     return valid  
       }   
	   
	if (n_tickets == 0 || n_tables == 0)  // only tickets or tables sold   
	{   
	     removeElement("qty2")  // remove second item if only one used... 
	     removeElement("amt2")
	     removeElement("item2")   
    
	     if (n_tickets > 0) // tickets sold 
	     {
	          document.paypal_form.amount_1.value =  document.input_form.current_price.value  // ticket price	     
	          document.paypal_form.quantity_1.value =  n_tickets
	          document.paypal_form.item_name_1.value = "Individual Tickets North Trail Dinner"
	     }
	     else
	     {    document.paypal_form.amount_1.value =  document.input_form.current_table_price.value  // ticket price	     
	          document.paypal_form.quantity_1.value =  n_tables
	          document.paypal_form.item_name_1.value = "Table for " + seats_per_table + " North Trail Dinner"
	     }
	     
	} 
	else // both tickets and tables sold 
	{      
	    document.paypal_form.amount_1.value =  document.input_form.current_price.value  // ticket price	     
	    document.paypal_form.quantity_1.value =  n_tickets
	    document.paypal_form.item_name_1.value = "Individual Tickets North Trail Dinner"
	    document.paypal_form.amount_2.value =  document.input_form.current_table_price.value  // ticket price	     
	    document.paypal_form.quantity_2.value =  n_tables
	    document.paypal_form.item_name_2.value = "Table for " + seats_per_table + " North Trail Dinner"    
    } 
    return valid
 }
 
 function paypal()
 {
    if (validate_form ( ))
    {   
       document.paypal_form.submit()
    }
 }   