﻿// Copyright 2005 West Georgia Golf Company - All rights reserved
// File Name     : bridges_golf.js
// Notes		 : Javascript library
// Created       : 11.23.2005_rg
// Last Modified : 12.26.2005_rg, 02.26.2006_rg, 04.12.2006_rg --->

// isEmail()
// Determine if string is a valid Email address
function isEmail(sv){  // s = string value
	var emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	if(emailpat.test(sv)) // validate
		return true;
	return false;
} // isEmail()

// IsNumeric()
// Determine if string is a number
function IsNumeric(sv, jpttrn, minv, maxv, minl) // sv = string value to validate; jpttrn = pattern/characters allowed in number;
												 // minv/maxv = max. and min. values allowed; minl = min. length
{
   for (i=0; i<sv.length; i++) // Look at every character
	  if (jpttrn.indexOf(sv.charAt(i)) == -1)
		 return false;
   // Maximum/Minimum value	
   if ((minv != "" && (sv*1) < (minv*1)) || (maxv != "" && (sv*1) > (maxv*1)) || (minl != "" && sv.length < (minl*1)))
		return false;
return true;
} // IsNumeric()

// validateRequiredField()
// Validate that a field is required
function validateRequiredField(msg, frmnbr, fnm){ // msg = error message; frmnbr = form number; fnm = field name to validate
   var fMsg = msg; // error message
   var fFrmnbr = frmnbr; // form number
   var fObjNm = fnm; // field name to validate
   var fObj = document.forms[fFrmnbr][fObjNm];
   if (fObj.value != '' && fObj.value.toUpperCase() != 'N/A') // validate
		fMsg = '';
   return fMsg;	// blank for no error
} // validateRequiredField

// validateRequiredField2()
// Validate that a field is required, ALLOW 'N/A'
function validateRequiredField2(msg, frmnbr, fnm){ // msg = error message; frmnbr = form number; fnm = field name to validate
   var fMsg = msg; // error message
   var fFrmnbr = frmnbr; // form number
   var fObjNm = fnm; // field name to validate
   var fObj = document.forms[fFrmnbr][fObjNm];
   if (fObj.value != '') // validate
		fMsg = '';
   return fMsg;	// blank for no error
} // validateRequiredField2

// validateRequiredField_RADIO()
//  Validate that a radio button is required
function validateRequiredField_RADIO(msg, frmnbr, fnm){ // msg = error message; frmnbr = form number; fnm = radio button name to validate
	jCnt = 0;
	var fMsg = msg; // error message
	var fFrmnbr = frmnbr; // form number
    var fObjNm = fnm; // field name to validate
    var fObj = document.forms[fFrmnbr][fObjNm];	
	for (i=0; i<fObj.length; i++){
		if (fObj[i].checked)
		  jCnt = jCnt + 1;
    }
	if (jCnt > 0) // validate
		fMsg = '';
    return fMsg;	// blank for no error	
} // validateRequiredField_RADIO()

// validateEmailField()
// Validate email is formatted properly and is required
function validateEmailField(msg, frmnbr, fnm){ // msg = error message; frmnbr = form number; fnm = field name to validate
   var fMsg = msg; // error message
   var fFrmnbr = frmnbr; // form number
   var fObjNm = fnm; // field name to validate
   var fObj = document.forms[fFrmnbr][fObjNm];
   if(isEmail(fObj.value)) // validate
		fMsg = '';
   return fMsg;	// blank for no error
} // validateEmailField()

// validateNumericField()
// Validate number is valid
function validateNumericField(msg, frmnbr, fnm, jpttrn, minv, maxv, minl){ // msg = error message; frmnbr = form number; fnm = field name to validate
																           // jpttrn = pattern/characters allowed in number; minv/maxv = max. and min. values allowed
																		   // minl = min. length
   var fMsg = msg; // error message
   var fFrmnbr = frmnbr; // form number
   var fObjNm = fnm; // field name to validate
   var fObj = document.forms[fFrmnbr][fObjNm];
   if(fObj.value.length < 1 || IsNumeric(fObj.value, jpttrn, minv, maxv, minl)) // validate
		fMsg = ''; // blank for no error
   return fMsg;	
} // validateNumericField()

// comparePasswords()
// Compare the value of 2 password fields
function comparePasswords(msg, frmnbr, fnm, fnm2){ // msg = error message; frmnbr = form number; fnm, fnm2 = field name for passwords to compare
   var fMsg = msg; // error message
   var fFrmnbr = frmnbr; // form number
   var fObjNm = fnm; // field name to compare
   var fObjNm2 = fnm2; // field name to compare
   var fObj = document.forms[fFrmnbr][fObjNm];
   var fObj2 = document.forms[fFrmnbr][fObjNm2];   
   if(fObj.value == fObj2.value) // validate
		fMsg = ''; // blank for no error
   return fMsg;	
} // comparePasswords()

// validateSearch()
// Validate SearchForm criteria field
function validateSearch()
{
   var eMsg = '';
   var fObj = document.forms[0]['strngvr1'];
   if (fObj.value == '')
		eMsg = eMsg + '* [Enter Search Criteria]\n\n';
   // Display error message
   if (eMsg != ''){
		alert(eMsg);
		return false;
   }
   // Success
   return true;

} // validateSearch()

// validateContactUs()
// Validate ContactUsForm
function validateContactUs()
{
   var eMsg = '';
   eMsg = eMsg + validateRequiredField('* [Name] is required\n', 1, 'ContactName');
   eMsg = eMsg + validateRequiredField('* [Address1] is required\n', 1, 'ContactAddress1');   
   eMsg = eMsg + validateRequiredField('* [City] is required\n', 1, 'ContactCity');   
   eMsg = eMsg + validateRequiredField('* [State] is required\n', 1, 'ContactState');
   eMsg = eMsg + validateEmailField('* [Email Address] must be valid\n', 1, 'EmailAddress');
   
   // Display error message for * REQUIRED FIELDS * 
   if (eMsg != ''){
		alert(eMsg);
		return false;
   }
   // Success
   return true;

} // validateContactUs()

// validateGiftCardForm()
// Validate GiftCardForm
function validateGiftCardForm()
{
   var eMsg = '';
   eMsg = eMsg + validateRequiredField('* [Amount] is required\n', 1, 'Amount1');
   eMsg = eMsg + validateNumericField('* [Amount] must be a numeric value or at least $5.00\n', 1, 'Amount1',
   									  '1234567890.', '5', '', 1);
   // Display error message 
   if (eMsg != ''){
		alert(eMsg);
		return false;
   }
   // Success
   return true;

} // validateGiftCardForm()

// privacyPolicy()
// Privacy policy
function privacyPolicy()
{
	alert('Privacy Policy\n\n' +
	      'West Georgia Golf Company is committed to protecting your personal privacy.\n\n' +
		  'We will not rent, sell, or otherwise release any of the personal information to a third party.\n\n' +
		  'Information submitted to us is only available to employees managing this information for\npurposes of contacting you or sending you e-mails based on your request for information.\n\n'); 		  

} // privacyPolicy()

// validateCustomerTestimonials()
// Validate Customer Testimonials
function validateCustomerTestimonials()
{
   var eMsg = '';
   eMsg = eMsg + validateRequiredField('* [Customer Name] is required\n', 1, 'CustomerName');
   eMsg = eMsg + validateRequiredField('* [State] is required\n', 1, 'State');
   // eMsg = eMsg + validateRequiredField('* [Handicap] is required\n', 1, 'Handicap');   
   eMsg = eMsg + validateRequiredField('* [Series] is required\n', 1, 'ProductDescription');   
   eMsg = eMsg + validateRequiredField('* [Grade] is required\n', 1, 'Grade');
   if(document.forms[1]['Comments'].value.length> 100)
	   eMsg = eMsg + '* [Comments] is max. 50 characters\n';
   // Display error message for * REQUIRED FIELDS * 
   if (eMsg != ''){
		alert(eMsg);
		return false;
   }
   // Success
   return true;

} // validateCustomerTestimonials()
