// Form Field Validation

function RequireNotZero(thefield, thename)
{
	if(thefield.value <= 0)
	{
		alert('Please enter a value in the \''+thename+'\' field');
		thefield.focus();
	} else {
		return true;
	}
		
}

function NotZeroNoFocus(thefield, thename)
{
	if(thefield.value <= 0)
	{
		alert('Please enter a value in the \''+thename+'\' field');
	} else {
		return true;
	}
		
}

function RequireNotEmpty(thefield, thename)
{
	if(thefield.value == "")
	{
		alert('The '+thename+' field is a required field. \nPlease enter some information in the \''+thename+'\' field');
		thefield.focus();
	} else {
		return true;
	}
}

function RequireEmail(thefield, thename)
{
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
  	if (!re_mail.test(thefield.value))
  	{
    	alert("Please enter your email address in the \"Email\" field.");
    	thefield.focus();
  	} else {
		return true;
	}
}

function RequireCANPostal(thefield, thename) {
	var re_postal  = /^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)?\d[a-z]\d\s*$/i;
  	//check for valid US Zipcode
	if(!re_postal.test(thefield.value))
	{
		alert('Please enter your '+thename+' in the \''+thename+'\' field');
		thefield.focus();
 	} else {
	  	return true;
	}
}

function RequireUSZip(thefield, thename) {
	var re_zip  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
  	//check for valid US Zipcode
	if(!re_zip.test(thefield.value))
	{
		alert('Please enter your '+thename+' in the \''+thename+'\' field');
		thefield.focus();
 	} else {
	  	return true;
	}
}

function ValidateCard(thefield, theCard) {
	if(theCard == 'VISA') {
		var re_cc  = /^4[0-9]{15}$/;
	}
	if(theCard == 'Mastercard') {
		var re_cc  = /^5[1-5]{1}[0-9]{14}$/;
	}
	if(!re_cc.test(thefield.value))
	{
		alert('Your credit card number does not seem to match the card type you selected');
		thefield.focus();
	} else {
		return true;
	}
	
}

//PRE SET
function preSet()
{
	if(document.admin.adminnumber.value == '')
	{
		alert('Please enter your admin number in the \'Admin Number field\' field');
		document.admin.adminnumber.focus();
	} else {
		var agree = confirm("Closing a record is a permanent action and will clear the credit card information from the database!\nPlease make sure that you have printed a copy of this record for processing.\n\nAre you certain you want to close this record?");
		if (agree)
		document.admin.submit();
	}
}

//PRE DELETE
function preDelete(thePage)
{
	var agree = confirm("Removing an entry is a permanent action!\nAre you certain you want to remove this entry?");
	if (agree)
		window.location=thePage;
}

//CLEAR DATE - USED IN ADMIN
function clearDate(theElement)
{
var textfield = theElement+'date';
	if(theElement=="start")
	{
		document.productform.startday.value = '';
		document.productform.startmonth.value = '';
		document.productform.startyear.value = '';
	} 
	else if (theElement=="end")
	{
		document.productform.endday.value = '';
		document.productform.endmonth.value = '';
		document.productform.endyear.value = '';
	} 

cleartext(textfield, theElement);
}
	
function cleartext(thisItem, thisElement)
{
	var newtext = '<a href="javascript:openWin(\'minical.php?name='+thisElement+'\',300,165,\'center\',25)">Click to select date</a>';
	var thisItem = document.getElementById(thisItem);
	thisItem.innerHTML = newtext;
}	


function show(element) 
{
	var myelement = document.getElementById(element);
	myelement.style.display = "block"; 
}

function hide(element) 
{
	var myelement = document.getElementById(element);
	myelement.style.display = "none"; 
}

