/* 	Javascript functions which validate form fields before submission.
 	Results open in a layer called validation_layer, created in the main template, which is hidden by default.
 */

function errorString_display ()  /*This function shows the validation layer and writes to it */
{  
	validation_layer.style.display = 'block';											
	valText = '';
	valText = valText + "<span class='header1'>Some of the information is incomplete...</span>";
	valText = valText + "<span style='text-align: left; ' class='apptext' >";
	valText = valText + error_string;
	valText = valText + "</span>";
	validation_layer.innerHTML = valText;
	return (false) ; 
	/*This returns FALSE to the validate function, which in turn passes FALSE back to root and cancels the submit.*/
}  	



function customer_validate(myForm)
{	
	/*Can be used for both customer_add and customer_update */
	error_string = ""
	

			if (eval(myForm + ".firstname.value" ) == "")
			{
				error_string = "<BR><BR>Enter a first name."
			}
	
		if (eval(myForm + ".lastname.value" ) == "")
			{
				error_string =  error_string + "<BR><BR>Enter a last name."
			}
		
		

/////////////////This validation is turned off for now, on request of Michael 10 March 2005		
//		if (eval(myForm + ".address1.value" ) == "")
//			{
//				error_string = error_string + "<BR><BR>Enter the first line of an address." 
//			}
		
//		if ( eval(myForm + ".postcode.value" ) == "")
//			{
//				error_string = error_string + "<BR><BR>Enter a postcode." 
//			}

//		myDate = eval(myForm + ".date_of_birth.value" )
//		if ( checkDate(myDate) == false )
//			{
//			error_string = error_string + "<BR><BR>Select a valid date of birth." 
//			}		
			
			
			
			
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
}




function passport_validate(myForm)
{	
	error_string = ""
	

			if (eval(myForm + ".passport_num.value" ) == "")
			{
				error_string = "<BR><BR>Enter a passport number."
			}
			
			
		myDate = eval(myForm + ".issue_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid issue date." 
			}
		
		myDate = eval(myForm + ".expiry_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid expiry date." 
			}
			
		firstDate = eval(myForm + ".issue_date.value" );
		lastDate  = eval(myForm + ".expiry_date.value" )
		if (  UKDateToUTC(firstDate) > UKDateToUTC(lastDate)  ) /* Are 2 dates valid relative to each other?*/
			{
			error_string = error_string + "<BR><BR>The issue date is later than the expiry date." 
			}	
			
			
		
		if (eval(myForm + ".issue_place.value" ) == "")
			{
				error_string = error_string + "<BR><BR>Enter the issue place." 
			}
		

		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
}























function SO_validate(myForm)
{	
	error_string = ""
	

		myDate = eval(myForm + ".order_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string =  "<BR><BR>Select a valid order date." 
			}
					
					
if (eval(myForm + ".category.value" ) != 'Other' 
&&  eval(myForm + ".category.value" ) != 'Voucher'
&&  eval(myForm + ".category.value" ) != 'Overhead'
&&  eval(myForm + ".category.value" ) != 'Discount'
&&  eval(myForm + ".category.value" ) != 'Theatre') 
{					
		myDate = eval(myForm + ".travel_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid travel date." 
			}
		
		myDate = eval(myForm + ".return_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid return date." 
			}
			
		firstDate = eval(myForm + ".travel_date.value" );
		lastDate  = eval(myForm + ".return_date.value" )
		if (  UKDateToUTC(firstDate) > UKDateToUTC(lastDate)  ) /* Are 2 dates valid relative to each other?*/
			{
			error_string = error_string + "<BR><BR>The travel date is later than the return date." 
			}		
					
		
		if (   eval(myForm + ".depart_from.value" ) == 'Not set' 
		||  eval(myForm + ".depart_from.value" ) == '' )  
			{
				error_string = error_string + "<BR><BR>Enter the place of departure." 
			}

		
		if (   eval(myForm + ".destination.value" ) == 'Not set' 
		||  eval(myForm + ".depart_from.value" ) == '' )  		
			{
				error_string = error_string + "<BR><BR>Enter the final destination."
			}
}
	
		if (   eval(myForm + ".category.value" ) == 'None') 		
			{
				error_string = error_string + "<BR><BR>Select a category."
			}	
	
		if (   eval(myForm + ".payment_method.value" ) == 'None') 		
			{
				error_string = error_string + "<BR><BR>Select an intended payment method."
			}		
		
					
		myDate = eval(myForm + ".status_timeout.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid status timeout." 
			}
		
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
}






function SO_line_validate(myForm)
{	
	error_string = ""
			
		
		if (   eval(myForm + ".vendorID.value" ) == '0' 
		||  eval(myForm + ".vendorID.value" ) == '' )  
			{
				error_string = error_string + "<BR><BR>Choose a vendor." 
			}
		
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
}














function SO_line_entry_validate(myForm)
{	
	error_string = ""
	
		if ( (eval(myForm + ".booking_ref.value") =='') && (eval(myForm + ".category.value") =='Voucher') )
		{
			error_string = '<BR><BR>Enter a booking reference for this voucher.';
		}


if ( eval(myForm + ".quantity.value") == '' )
		{
			error_string = error_string +'<BR><BR>Enter a quantity.'
		}

		
if ( isNaN(eval(myForm + ".quantity.value")) )
			{
				error_string = error_string +'<BR><BR>Quantity must be a number.' ;
			}


if ( eval(myForm + ".unit_price.value") == '' )
		{
			error_string = error_string + '<BR><BR>Choose a unit price.'
		}		
					
		
if ( isNaN(eval(myForm + ".unit_price.value")) )
			{
				error_string = error_string + '<BR><BR>Unit price must be a number.'
			}
						
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }	
}	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
function SO_search_validate(myForm)
{	
	error_string = ""			
		
		if ( isNaN(eval(myForm + ".orderParam.value")) )  /* If not a number.... (NaN). */
			{
				error_string = "<BR><BR>The sales order reference must be a number." 
			}
	
	
	
		if ( eval(myForm + ".orderParam.value") =='' )
			{
				error_string = "<BR><BR>You must enter a sales order reference." 
			}			
		
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }	
}	
	


function PO_search_validate(myForm)
{	
	error_string = ""			
		
		if ( isNaN(eval(myForm + ".orderParam.value")) )  /* If not a number.... (NaN). */
			{
				error_string = "<BR><BR>The purchase order reference must be a number." 
			}
	
	
	
		if ( eval(myForm + ".orderParam.value") =='' )
			{
				error_string = "<BR><BR>You must enter a purchase order reference." 
			}			
		
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }	
}	





	
	
function SO_deposit_validate(myForm)
{	
	error_string = ""			
		
		if ( isNaN(eval(myForm + ".amount.value")) )  /* If not a number.... (NaN). */
			{
				error_string = "<BR><BR>The payment amount must be a number." 
			}
	
	
	
		if ( eval(myForm + ".amount.value") =='' && eval(myForm + ".voucher_amount.value") ==0 )
			{
				error_string = error_string + "<BR><BR>You must enter a cash payment amount or a voucher." 
			}
		
	
			
			
		if ( eval(myForm + ".payment_method.value") =='' )
			{
				error_string = error_string + "<BR><BR>You must enter a payment method." 
			}	


		if ( eval(myForm + ".payment_method.value") =='None' )
			{
				error_string = error_string + "<BR><BR>You must enter a payment method." 
			}


		if ( eval(myForm + ".payment_method.value") =='cheque'  && eval(myForm + ".cheque_number.value") =='')
			{
				error_string = error_string + "<BR><BR>You must enter a cheque number." 
			}




			
		if ( isNaN(eval(myForm + ".voucher_amount.value")) )  /* If not a number.... (NaN). */
			{
				error_string = "<BR><BR>The voucher amount must be a number." 
			}
			


		if ( eval(myForm + ".voucher_amount.value") <0 )
			{
				error_string = error_string + "<BR><BR>The voucher amount must be a positive number" 
			}


		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
	
}	
	
	
	
	
	
function PO_line_deposit_validate(myForm)
{	
window.status = ":"+eval(myForm + ".SO_invoiceID.value" );
	error_string = ""			
		
		if ( eval(myForm + ".amount.value") =='' )
			{
				error_string =  "<BR><BR>You must enter a payment amount." 
			}
		
			
				if ( isNaN(eval(myForm + ".amount.value")) )  /* If not a number.... (NaN). */
			{
				error_string = error_string + "<BR><BR>The payment amount must be a number." 
			}	
		
		
		
		if ( eval(myForm + ".payment_method.value") =='' || eval(myForm + ".payment_method.value") =='None')
			{
				error_string = error_string + "<BR><BR>You must enter a payment method." 
			}	

		/*if (   eval(myForm + ".SO_invoiceID.value" ) == ''  )  
			{
				error_string = error_string + "<BR><BR>Select a sales invoice." 
			}*/

		if ( eval(myForm + ".payment_method.value") =='cheque'  && eval(myForm + ".cheque_number.value") =='')
			{
				error_string = error_string + "<BR><BR>You must enter a cheque number." 
			}
		
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
	
}	
	
	
	


	function ins_agent_validate(myForm)
{	
	error_string = ""
	

			if (eval(myForm + ".agent_name.value" ) == "")
			{
				error_string = "<BR><BR>Enter a company name."
			}
			
				
			//if (eval(myForm + ".address1.value" ) == "")
			//{
				//error_string = error_string + "<BR><BR>Enter at least the first line of an address."
			//}
			
			
			//if (eval(myForm + ".phone_work.value" ) == "")
			//{
				//error_string =  error_string + "<BR><BR>Enter a main phone number."
			//}
				

		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }

}










	function vendor_validate(myForm)
{	
	error_string = ""
	

			if (eval(myForm + ".vendor_name.value" ) == "")
			{ 
				error_string = "<BR><BR>Enter a company name."
			}
	
	
			if (eval(myForm + ".address1.value" ) == "")
			{
				error_string = error_string + "<BR><BR>Enter at least the first line of an address."
			}
			
			
			if (eval(myForm + ".phone_work.value" ) == "")
			{
				error_string =  error_string + "<BR><BR>Enter a main phone number."
			}
			
			if (eval(myForm + ".category.value" ) == "None")
			{
				error_string =  error_string + "<BR><BR>Select a category."
			}			
			
			
			
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }

}






function PO_validate(myForm)
{	
	error_string = ""

		
		if ( eval(myForm + ".vendorID.value" ) == '' ) 
			{
			error_string = error_string + "<BR><BR>Select a vendor." 
			}	
			
		myDate = eval(myForm + ".order_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid order date." 
			}


if (eval(myForm + ".category.value" ) != 'Other' 
&&  eval(myForm + ".category.value" ) != 'Voucher'
&&  eval(myForm + ".category.value" ) != 'Overhead'
&&  eval(myForm + ".category.value" ) != 'Overhead'
&&  eval(myForm + ".category.value" ) != 'Theatre') 
{		
		myDate = eval(myForm + ".travel_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid travel date." 
			}
		
		myDate = eval(myForm + ".return_date.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid return date." 
			}
			
		firstDate = eval(myForm + ".travel_date.value" );
		lastDate  = eval(myForm + ".return_date.value" )
		if (  UKDateToUTC(firstDate) > UKDateToUTC(lastDate)  ) 
			{
			error_string = error_string + "<BR><BR>The travel date is later than the return date." 
			}		
							
		if (   eval(myForm + ".depart_from.value" ) == 'Not set' 
		||  eval(myForm + ".depart_from.value" ) == '' )  
			{
				error_string = error_string + "<BR><BR>Enter the place of departure." 
			}

		
		if (   eval(myForm + ".destination.value" ) == 'Not set' 
		||  eval(myForm + ".depart_from.value" ) == '' )  		
			{
				error_string = error_string + "<BR><BR>Enter the final destination."
			}
}	


	
		if (   eval(myForm + ".category.value" ) == 'None') 		
			{
				error_string = error_string + "<BR><BR>Select a category."
			}	
		
		if (   eval(myForm + ".payment_method.value" ) == 'None') 		
			{
				error_string = error_string + "<BR><BR>Select an intended payment method."
			}		
			
			myDate = eval(myForm + ".status_timeout.value" )
		if ( checkDate(myDate) == false )
			{
			error_string = error_string + "<BR><BR>Select a valid status timeout." 
			}
		
			if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }

}




function PO_line_validate(myForm)
	{	
	error_string = ""
			
		
		if (   eval(myForm + ".line_cost_net.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a net line cost for this line." 
			}
	
		if ( isNaN(eval(myForm + ".line_cost_net.value")) )
			{
				error_string = error_string +'<BR><BR>The net line cost must be a number.' ;
			}
			
	
			if (   eval(myForm + ".line_cost_gross.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a gross line cost for this line." 
			}
	
		if ( isNaN(eval(myForm + ".line_cost_gross.value")) )
			{
				error_string = error_string +'<BR><BR>The gross line cost must be a number.' ;
			}
			
			
			if (   eval(myForm + ".commission_gross.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a gross commission for this line." 
			}
	
		if ( isNaN(eval(myForm + ".commission_gross.value")) )
			{
				error_string = error_string +'<BR><BR>The gross commission must be a number.' ;
			}

			if (   eval(myForm + ".commission_VAT.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a Commission VAT value for this line." 
			}
	
		if ( isNaN(eval(myForm + ".commission_VAT.value")) )
			{
				error_string = error_string +'<BR><BR>The Commission VAT value must be a number.' ;
			}
			
			
	
			if (   eval(myForm + ".commission_net.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a Net Commission for this line." 
			}
	
		if ( isNaN(eval(myForm + ".commission_net.value")) )
			{
				error_string = error_string +'<BR><BR>The Net Commission  must be a number.' ;
			}			
			
			
			
	
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
	
	
} /* End of function */





function report_generator_validate(myForm)
	{	
	error_string = ""
			

		if (   eval(myForm + ".report_select.value" ) == '' )
			{
				error_string = error_string + "<BR><BR>Choose a report title." 
			}
			
					
		if (   eval(myForm + ".start_date.value" ) == ''  || eval(myForm + ".end_date.value" ) == ''   )
			{
				error_string = error_string + "<BR><BR>Choose a valid date range." 
			}
	
			
	
		if (error_string != "")	 { if (errorString_display() == false )  {return (false);}	 }
	
	
} /* End of function */