// --------------------------------------------------------------------------------------------------------
// FieldValidation.js
//
// Field Validation Utilities
//
// Author        : Thomas E. George
// Creation Date : January 26, 2009
//
// Notes         : assumes inclusion of FieldValidationIncl.js prior to this file
//
// History       : 01/26/2009 - TEG - Initial Implementation
//               : 12/09/2011 - TEG - Added isevalidccnumber_cs() for cust_serv cs_ccard.asp CC validation
// --------------------------------------------------------------------------------------------------------

var g_eMailAddress = null;
var g_docImages    = null;

var g_ccElem         = null;
var g_bInCCHandler   = false;
var g_bInRevHandler  = false;
var g_eaElem	     = null;
var g_stElem	     = null;
var g_bInEAHandler   = false;
var g_bInCSHandler   = false;
var g_efElem         = null
var g_bInFPHandler   = false;
var g_bInFP14Handler = false;
var g_ccvElemCECC    = null;

var g_ratingElem    = null;
var g_headElem      = null;
var g_reviewElem    = null;
var g_nameElem      = null;
var g_locElem       = null;

var emfmsg       = "subscribe"; //"enter your e-mail here for offers and photos";
var eMADefColor  = "gray";
var eMAColor     = "cyan";
var emfblurred   = true;

var _popupwin    = null;

function supress_errors()
{
	return true;
}

function process_error(msg)
{
	if((msg != null) && (msg.length > 0))
	{
	    if(debugModeFlag)
		{
			alert(msg);
		}
	}
}

function ltrim(str)
{
	var strOut = null;
	
	if(str == null)
	{
		strOut = '';
	}
	else
	{
		strOut = str;
	}
	
	return strOut.replace(/^\s+/, '');
}

function rtrim(str)
{
	var strOut = null;
	
	if(str == null)
	{
		strOut = '';
	}
	else
	{
		strOut = str;
	}
	
	return strOut.replace(/\s+$/, '');
}

function trim(str)
{
	var strOut = null;
	
	if(str == null)
	{
		strOut = '';
	}
	else
	{
		strOut = str;
	}
	
	return strOut.replace(/^\s+|\s+$/g, '');
}

// clean Credit Card number string
function cleanCC(str)
{
	//var strOut = trim(str);
	var strOut = null;
	
	if(str == null)
	{
		strOut = '';
	}
	else
	{
		strOut = str;
	}
	
	// strip out all dashes and spaces (outer and inner)
	return strOut.replace(/\s|\-/g, '');
}

function onClicked()
{
	emailfieldclicked();
	emailfieldfocused();
	showsubscribe();
	emailfieldcursorchange('black');
}

function onSelected()
{
	emailfieldselected();
	emailfieldfocused();
	showsubscribe();
	emailfieldcursorchange('black');
	focusControl(g_eMailAddress);
}

function onBlurred()
{
	emailfieldblurred();
	emailfieldcursorchange('transparent');
}

function showsubscribe()
{
	try
	{
		if(document.getElementById)
		{
			oRow  = document.getElementById('submitrow');
			oCell = document.getElementById('submittd');
			
			backBtn = document.getElementById('goBackBtn');
		}
		else if(document.all)
		{
			oRow  = document.all.submitrow;
			oCell = document.all.submittd;
			
			backBtn = document.all.goBackBtn;
		}
		
		var btnInnerHTML = "<input name=\"emailsub\" type=\"submit\" value=\"click here to SUBSCRIBE\" style=\"FONT-FAMILY: Century Gothic; FONT-SIZE: 12; FONT-WEIGHT: regular\" size=\"30\" class=\"thinput\" />";
		
		if(oCell.innerHTML.length == 0)
		{
			if(backBtn != null)
			{
				//backBtn.setAttribute("visible", "false");
				//backBtn.style.visiblity = "false";
				backBtn.disabled = true;
			}
			
			var newCell = document.createElement("TD");
			newCell.setAttribute("id", "submittd");
			newCell.setAttribute("align", "center");
			//newCell.setAttribute("style", "VISIBILITY: visible"); // hidden
			newCell.innerHTML = btnInnerHTML;
			oRow.replaceChild(newCell, oCell);
		}
		
		//oCell.getElementByTagName("EMailRegistryReg").Visible = true;
		//oCell.visible = true;
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:showsubscribe() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function setemailfieldvalue(color, msg)
{
	try
	{
		g_eMailAddress.style.color = color;
		g_eMailAddress.value       = msg;
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:setmailfieldvalue() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldvalue()
{
	try
	{
		if(emfblurred)
		{
			setemailfieldvalue(eMADefColor, emfmsg);
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldvalue() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailsubscribebtn()
{
	try
	{
		if(!emfblurred)
		{
			if(isvalidemailaddr(g_eMailAddress.value))
			{
				showsubscribe();
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailsubscribebtn() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldfocused()
{
	try
	{
		emfblurred = false;
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldfocused() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldblurred()
{
	try
	{
		emfblurred = true;
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldblurred() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function focusControl(control)
{
	try
	{
		if(control != null)
		{
			control.focus();
		}
	}
	catch(e)
	{
		if(e.description.length != 0) { process_error("FieldValidation.js:focusControl(" + control + ") : '" + e.name + "' Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldclicked()
{
	try
	{
	    if(g_eMailAddress.value.length == 0)
	    {
			setemailfieldvalue(eMAColor, ""); //(eMADefColor, emfmsg);
		}
		else
		{
			if(!isvalidemailaddr(g_eMailAddress.value))
			{
				setemailfieldvalue(eMAColor, "");
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldclicked() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldselected()
{
	try
	{
		g_eMailAddress.style.color = eMAColor;
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldselected() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function isevalidemailaddr(elemNameEA, bRequired)
{
    var rc = true;
    
	try
	{
		if(eaValidate)
		{
			rc = false;
			
			if(!g_bInEAHandler) //prevent recursive entry
			{
				g_bInEAHandler = true;
		
				g_eaElem = document.getElementsByName(elemNameEA)[0];
				if(g_eaElem != null)
				{
					rc = isvalidemailaddr(g_eaElem.value);
		
					if(!rc && ((g_eaElem.value.length > 0) || bRequired))
					{
						if(bRequired)
						{
							alert("Invalid E-Mail Address - Please re-enter.");
						}
						else
						{
							alert("Invalid E-Mail Address - Please clear or re-enter.");
						}
							
						//g_eaElem.focus();
						//g_eaElem.select();
						setTimeout('g_eaElem.focus()', 5);  // delay it for the likes of Firefox
						setTimeout('g_eaElem.select()', 5); // delay it for the likes of Firefox
					}
					else if((g_eaElem.value.length == 0) && !bRequired)
					{
						rc = true;
					}
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isevalidemailaddr() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInEAHandler = false;
	}
	
	return(rc);
}

function isvalidemailaddr(emailaddr)
{
    var rc = false;
    
	try
	{
		var strim = trim(emailaddr);
		
	    if((strim != null) && (strim.length > 0))
	    {
			//var RE = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
			var RE = "^[\\w\\.-]+@[\\w-]+\\.[\\w\\.-]+$";
			
			var result = strim.match(RE);
			
			if(result != null)
			{
				rc = true;
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isvalidemailaddr() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function isnumeric(val, addlChars)
{
    var rc = false;
    
	try
	{
	    if(val != null && val.length > 0)
	    {
			//var RE = "/^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/";
			//
			//var result = val.match(RE);
			//
			//if(result != null)
			//{
			//	rc = true;
			//}
			
			if(addlChars == null)
			{
			    addlChars = "";
			}
			
			var bRes          = true;
            var strValidChars = "0123456789" + addlChars; //.-";

            for(var i = 0; i < val.length; i++)
            {
                if(strValidChars.indexOf(val.charAt(i)) == -1)
                {
                    bRes = false;
                    break;
                }
            }
            
            rc = bRes;
        }
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isnumeric() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
    
    return(rc); 
}

function isevalidccnumber(elemNameCC, elemNamePT, strPT, elemPromoCode, bSubmit)
{
    var rc = true;
    
	try
	{
		if(ccValidate)
		{
			rc = false;
			
			if(!g_bInCCHandler) //prevent recursive entry
			{
				g_bInCCHandler = true;
		
				var ptPromoCode = document.getElementsByName(elemPromoCode)[0];
				var strimpc = "";
				if(ptPromoCode != null)
				{
					strimpc = trim(ptPromoCode.value);
				}
				
				if(strimpc.length == 0)
				{
					var bValidate = true;
		
					var ptElem = document.getElementsByName(elemNamePT);
		
					if((ptElem != null) && (ptElem.length > 0))
					{
						var bFoundChecked = false;
						
						for(var i = 0; i < ptElem.length; i++)
						{
						    if(ptElem[i].checked)
						    {
								ptElem = ptElem[i];
								bFoundChecked = true;
						        break;
						    }
						}
							
						if(!bFoundChecked)
						{
							ptElem = ptElem[0]
						}
						
						bValidate = false;
						
						if(ptElem.value == strPT)
						{
							bValidate = true;
						}
					}
		
					if(bValidate)
					{
						g_ccElem = document.getElementsByName(elemNameCC)[0];
						if(g_ccElem != null)
						{
							if(g_ccElem.value.toUpperCase() != ccValidateExclusion)
							{
								rc = isvalidccnumber(g_ccElem.value);
		
								if(!rc && ((g_ccElem.value.length > 0) || bSubmit))
								{
									alert("Invalid Credit Card Number - Please clear or re-enter.");
									
									//g_ccElem.focus();
									//g_ccElem.select();
									setTimeout('g_ccElem.focus()', 5);  // delay it for the likes of Firefox
									setTimeout('g_ccElem.select()', 5); // delay it for the likes of Firefox
								}
							}
							else
							{
								rc = true;
							}
						}
					}
					else if(bSubmit)
					{
						rc = true;
					}
				}
				else
				{
					rc = true;
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isevalidccnumber() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInCCHandler = false;
	}
	
	return(rc);
}

// customer service cs_ccard.asp version
function isevalidccnumber_cs(elemNameCC, sElemECC, sElemCCC, bSubmit, bSilent, bAllowMasked)
{
    var rc = true;
					
	try
	{
		if(ccValidate)
		{
			rc = false;
			
			if(!g_bInCCHandler) //prevent recursive entry
			{
				g_bInCCHandler = true;
		
				g_ccElem = document.getElementsByName(elemNameCC)[0];
				if(g_ccElem != null)
				{
					var bDoCheck = false;
							
					var bElemCECCChecked = false;
								
					if((sElemCCC != null) && (sElemCCC.length > 0))
					{
						g_ccvElemCECC = document.getElementsByName(sElemCCC)[0];
									
						if(g_ccvElemCECC != null)
						{
							bElemCECCChecked = g_ccvElemCECC.checked;
						}
					}
					if(!bElemCECCChecked)
					{
						if((sElemECC != null) && (sElemECC.length > 0))
						{
							g_ccvElemCECC = document.getElementsByName(sElemECC)[0];
									
							if(g_ccvElemCECC != null)
							{
								bElemCECCChecked = g_ccvElemCECC.checked;
							}
						}
					}
								
					if(!bElemCECCChecked)
					{
						bDoCheck = (ccValidateExclusionCS.toUpperCase().indexOf(g_ccElem.value.toUpperCase()) < 0);
					}
					
					if(bDoCheck && bAllowMasked)
					{
						if(g_ccElem.value.length > 0)
						{
							//alert(g_ccElem.value.substr(6, 1));
							
							if(g_ccElem.value.substr(6, 1) == "X")
							{
								// masked (+++see cust_serv/cs_ccard.asp update_card())
								bDoCheck = false;
							}
						}
					}
							
					if(bDoCheck)
					{
						rc = isvalidccnumber(g_ccElem.value);

						if(!rc && ((g_ccElem.value.length > 0) || bSubmit))
						{
							alert("Invalid Credit Card Number.");
									
							//g_ccElem.focus();
							//g_ccElem.select();
							setTimeout('g_ccElem.focus()', 5);  // delay it for the likes of Firefox
							setTimeout('g_ccElem.select()', 5); // delay it for the likes of Firefox
						}
						else if(rc)
						{
							if(!bSilent)
							{
								alert("Credit Card Number Is Valid.");
							}
										
							if(!bSubmit)
							{
								rc = false; // don't submit
							}
						}
					}
					else
					{
						rc = true;
					}
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isevalidccnumber_cs() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInCCHandler = false;
	}
	
	return(rc);
}

function isvalidccnumber(val)
{
    var rc = false;
    
	try
	{
		var strim = cleanCC(val);
		
	    // AMEX has 15 digits, the rest have 16
	    if((strim != null) && ((strim.length >= 15) && (strim.length <= 16)) && isnumeric(strim, null))
	    {
			if(luhn_check(strim))
			{
				rc = true;
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isvalidccnumber() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function isvalidcvv2number(val)
{
    var rc = false;
    
	try
	{
	    if((val != null) && ((val.length >= 3) && (val.length <= 4)) && isnumeric(val, null))
	    {
			rc = true;
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isvalidcvv2number() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function isvalidzipcode(val)
{
    var rc = false;
    
	try
	{
	    if((val != null) && ((val.length == 5) || (val.length == 10)) && isnumeric(val, "-"))
	    {
			rc = true;
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:isvalidzipcode() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function timedadvance(runImmediate)
{
	try
	{
		if(runImmediate)
		{
			emailfieldvalue();
		}
		
		setTimeout('emailfieldvalue()', 6000);
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:timedadvance() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function emailfieldcursorchange(color)
{
	try
	{
		//alert("emailfieldcursorchange() called");
		//g_eMailAddress.style.cursor="text";
		if(emfblurred)
		{
			g_eMailAddress.style.backgroundColor = color;
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:emailfieldcursorchange(" + color + ") : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

function goBack()
{
	try
	{
	    var url = document.referrer;
	    
	    if(url.length > 0)
	    {
			window.location = url;
	    }
	}
	catch(e)
	{
		process_error("FieldValidation.js:goBack() : '" + e.name + "' Exception caught [" + e.description + "]");
	}
	finally
	{
	}
}

function bodyOnLoad()
{
	try
	{
		// Before the error event handler can take effect, we have to register it for this window.
		//self.onerror = report_error;
		self.onerror = supress_errors;

		g_eMailAddress = document.getElementsByName("eMailAddress")[0];
		
		if(navigator.appName.indexOf("Netscape") != -1)
		{
			// Netscape navigator in use
			//+++ fix anomalous behavior with text field properties +++
			try
			{
				g_eMailAddress.style.width           = "286px"; //g_eMailAddress.style.width * 2;
				g_eMailAddress.style.height          = "23px";
				g_eMailAddress.style.fontFamily      = "Century Gothic";
				g_eMailAddress.style.color           = "Cyan";
				g_eMailAddress.style.backgroundColor = "Transparent";
				g_eMailAddress.style.borderColor     = "White";
				g_eMailAddress.style.borderStyle     = "Solid";
				g_eMailAddress.style.borderWidth     = "1px";
				g_eMailAddress.style.fontSize        = "10pt";
				//g_eMailAddress.style.filter          = "revealTrans(duration=2,transition=3)";
				
				//+++TEST CODE+++
				//process_error("Why are you using Netscape Navigator?");
				// The following line of code purposely causes an error as a test.
				//alert(no_such_variable);
			}
			catch(e)
			{
				if(e.description.length != 0) { process_error("FieldValidation.js:bodyOnLoad() : Netscape block : Exception caught [" + e.description + "]"); }
			}
			finally
			{
			}
		}
		else
		{
			//+++TEST CODE+++
			//process_error("Ahhhhhh... Internet Explorer!");
			// The following line of code purposely causes an error as a test.
			//alert(no_such_variable);
		}
		
		//EMailRegistryReg = document.getElementsByTagName("EMailRegistryReg")[0];
		
		timedadvance(false);
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:bodyOnLoad() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Payment Form validation
function onPayButtonHit()
{
    var rc = false;
    
    alert("onPayButtonHit()");
    //process_error(msg);
    
	var ZipCode = document.getElementsByName("BuyerZipCodeTextBox")[0];

    if(ZipCode.value.length > 0)
    {
        alert("Zip code good.");
        
	    //var PayButton = document.getElementsByName("PayButton")[0];
	    
	    rc = true;
    }
    
    return rc;
}

//<a href="popupcontent.html" onclick="return jsPopup(this, 'whatsthis')">what's this?</a>
function jsPopup(link, windowname, iTop, iLeft, iWidth, iHeight)
{
    var rc = true;
    
    try
    {
        if(window.focus)
        {
            var href = null;
            
            if(typeof(link) == 'string')
            {
                href = link;
            }
            else
            {
                href = link.href;
            }
            
            var wstyle = 'top=' + iTop + ',left=' + iLeft + ',width=' + iWidth + ',height=' + iHeight + ',location=no,scrollbars=no,menubar=no,resizable=no,status=no,toolbar=no';
            
            _popupwin = window.open(href, windowname, wstyle);
            
            _popupwin.focus();
            
            rc = false
        }
	}
	catch(e)
	{
	    if(e.description.length != 0)
	    {
	        process_error("FieldValidation.js:jsPopup() : Exception caught [" + e.description + "]");
	    }
	    else
	    {
	        process_error("FieldValidation.js:jsPopup() : ERROR - Exception occurred --- Cannot process.");
	    }
	}
	finally
	{
	}
    
    return rc;
}

function jsPopupClose()
{
    try
    {
        if(_popupwin && (_popupwin != null) && !_popupwin.closed) 
        {
            _popupwin.close();
        }
	}
	catch(e)
	{
	    if(e.description.length != 0)
	    {
	        process_error("FieldValidation.js:jsPopupClose() : Exception caught [" + e.description + "]");
	    }
	    else
	    {
	        process_error("FieldValidation.js:jsPopupClose() : ERROR - Exception occurred --- Cannot process.");
	    }
	}
	finally
	{
	}
}

// use when there's a lone text field in a form to prevent pre-emptive submit on Enter key
// (i.e., when there's only 1 text field in form)
function noSubmitEnter(e, elemSubmitName)
{
	var rc = true;
	
    try
    {
		var keynum;
		var keychar;
		var numcheck;
		
		if(window.event) // IE
		{
			keynum = e.keyCode;
		}
		else if(e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which;
		}
		
		if(keynum && (keynum == 13))
		{
			var submitElem = document.getElementsByName(elemSubmitName)[0];
		
			if(submitElem != null)
			{
				//alert(navigator.appName);
				
				if(navigator.appName.indexOf("Opera") == -1)
				{
					submitElem.click();
					
					rc = false;
				}
			}
		}
		
		//keychar = String.fromCharCode(keynum);
		//
		//numcheck = /\d/;
		//
		//rc = !numcheck.test(keychar);
	}
	catch(e)
	{
	    if(e.description.length != 0)
	    {
	        process_error("FieldValidation.js:noSubmitEnter() : Exception caught [" + e.description + "]");
	    }
	    else
	    {
	        process_error("FieldValidation.js:noSubmitEnter() : ERROR - Exception occurred --- Cannot process.");
	    }
	}
	finally
	{
	}
	
	return rc;
}

/*
 * luhn_check() - Checks whether a Credit Card or Debit Card number is valid based on the Luhn algoritm.
 *                This function may be used to check for valid credit card numbers, however, additional
 *                checks may be desired, such as card prefix and length checks.
 */
function luhn_check(number)
{
	var rc = false;
	
    try
    {
		// Strip any non-digits (useful for credit card numbers with spaces and hyphens)
		number = number.replace(/\D/g, '');

		// Set the string length and parity
		var number_length = number.length;
		var parity        = number_length % 2;

		// Loop through each digit and do the math
		var total = 0;
	
		for(var i = 0; i < number_length; i++)
		{
			var digit = number.charAt(i);
			
			// Multiply alternate digits by 2
			if(i % 2 == parity)
			{
				digit = digit * 2;
				
				// If the sum is two digits, add them together (in effect)
				if(digit > 9)
				{
					digit = digit - 9;
				}
			}
			
			// Total up the digits
			total = total + parseInt(digit);
		}

		// If the total mod 10 equals 0, the number is valid
		if((total > 0) && ((total % 10) == 0))
		{
			rc = true;
		}
	}
	catch(e)
	{
	    if(e.description.length != 0)
	    {
	        process_error("FieldValidation.js:luhn_check() : Exception caught [" + e.description + "]");
	    }
	    else
	    {
	        process_error("FieldValidation.js:luhn_check() : ERROR - Exception occurred --- Cannot process.");
	    }
	}
	finally
	{
	}
	
	return(rc);
}

function efieldspop14(elemName1, dispName1, elemName2, dispName2, elemName3, dispName3, elemName4, dispName4, elemName5, dispName5, elemName6, dispName6, elemName7, dispName7, elemName8, dispName8, elemName9, dispName9, elemName10, dispName10, elemName11, dispName11, elemName12, dispName12, elemName13, dispName13, elemName14, dispName14, bRequired)
{
    var rc = true;
    
	try
	{
		if(rc)
		{
			rc = efieldpop14(elemName1, dispName1, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName2, dispName2, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName3, dispName3, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName4, dispName4, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName5, dispName5, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName6, dispName6, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName7, dispName7, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName8, dispName8, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName9, dispName9, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName10, dispName10, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName11, dispName11, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName12, dispName12, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName13, dispName13, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpop14(elemName14, dispName14, bRequired);
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:efieldspop14() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function efieldspopulated(elemName1, elemName2, elemName3, elemName4, elemName5, elemName6, elemName7, bRequired)
{
    var rc = true;
    
	try
	{
		if(rc)
		{
			rc = efieldpopulated(elemName1, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName2, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName3, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName4, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName5, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName6, bRequired);
		}
								
		if(rc)
		{
			rc = efieldpopulated(elemName7, bRequired);
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:efieldspopulated() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

function efieldpopulated(elemName, bRequired)
{
    var rc = true;
    
	try
	{
		if(fpValidate && elemName && (elemName != null) && (elemName.length > 0))
		{
			rc = false;
			
			if(!g_bInFPHandler) //prevent recursive entry
			{
				g_bInFPHandler = true;
		
				g_efElem = document.getElementsByName(elemName)[0];
				if(g_efElem != null)
				{
					rc = fieldpopulated(g_efElem.value);
		
					if(!rc && ((g_efElem.value.length > 0) || bRequired))
					{
						if(bRequired)
						{
							alert("Invalid " + elemName + " - Please re-enter.");
						}
						else
						{
							alert("Invalid " + elemName + " - Please clear or re-enter.");
						}
							
						//g_efElem.focus();
						//g_efElem.select();
						setTimeout('g_efElem.focus()', 5);  // delay it for the likes of Firefox
						setTimeout('g_efElem.select()', 5); // delay it for the likes of Firefox
					}
					else if((g_efElem.value.length == 0) && !bRequired)
					{
						rc = true;
					}
				}
								
				if(rc)
				{
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:efieldpopulated() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInFPHandler = false;
	}
	
	return(rc);
}

function efieldpop14(elemName, dispName, bRequired)
{
    var rc = true;
    
	try
	{
		if(fpValidate && elemName && (elemName != null) && (elemName.length > 0))
		{
			rc = false;
			
			if(!g_bInFP14Handler) //prevent recursive entry
			{
				g_bInFP14Handler = true;
		
				g_efElem = document.getElementsByName(elemName)[0];
				if(g_efElem != null)
				{
					rc = fieldpopulated(g_efElem.value);
		
					if(!rc && ((g_efElem.value.length > 0) || bRequired))
					{
						var elemDisp = elemName;
						if(dispName && (dispName != null) && (dispName.length > 0))
						{
							//var efElem = document.getElementsByName(dispName)[0];
							//if(efElem != null)
							//{
							//	elemDisp = efElem.value;
							//}
							//else
							//{
								elemDisp = dispName;
							//}
						}
						
						if(bRequired)
						{
							alert("Invalid " + elemDisp + " - Please re-enter.");
						}
						else
						{
							alert("Invalid " + elemDisp + " - Please clear or re-enter.");
						}
							
						//g_efElem.focus();
						//g_efElem.select();
						setTimeout('g_efElem.focus()', 5);  // delay it for the likes of Firefox
						setTimeout('g_efElem.select()', 5); // delay it for the likes of Firefox
					}
					else if((g_efElem.value.length == 0) && !bRequired)
					{
						rc = true;
					}
				}
								
				if(rc)
				{
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:efieldpop14() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInFP14Handler = false;
	}
	
	return(rc);
}

function fieldpopulated(fieldElem)
{
    var rc = false;
    
	try
	{
	    if((fieldElem != null) && (fieldElem.length > 0))
	    {
			rc = true;
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:fieldpopulated() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
	}
	
	return(rc);
}

//also see website incReview.asp:SaveForm()
function validatereviewfields(ratingElemName, headElemName, reviewElemName, nameElemName, locElemName)
{
    var rc = false;
    
	try
	{
		if(
			(ratingElemName != null && ratingElemName.length > 0) &&
			(headElemName   != null && headElemName.length   > 0) &&
			(reviewElemName != null && reviewElemName.length > 0) &&
			(nameElemName   != null && nameElemName.length   > 0) &&
			(locElemName    != null && locElemName.length    > 0)
		  )
		{
			if(!g_bInRevHandler) //prevent recursive entry
			{
				g_bInRevHandler = true;
				
				g_ratingElem = null;
				
				var iNumStars = 0;
				
				// RATING
				if(ratingElemName == "rating")
				{
					g_ratingElem = document.getElementsByName(ratingElemName); //[0];
					if(g_ratingElem != null)
					{
						var rStarRadio = null;
						for(var i = (g_ratingElem.length-1); i >= 0; i--)
						{
							rStarRadio = g_ratingElem[i];
							if(rStarRadio != null)
							{
								if(rStarRadio.checked)
								{
									iNumStars = i + 1;
									break;
								}
							}
							else
							{
								break;
							}
						}
						
						g_ratingElem = g_ratingElem[0];
					}
				}
				else if(ratingElemName == "rstar")
				{
					var rStar = null;
					var srcText = "";
						
					for(var i = 4; i >= 0; i--)
					{
						rStar = document.getElementById("rstar" + (i+1));
						if(rStar != null)
						{
							srcText = rStar.src; //unescape()
							if(srcText.indexOf("full") >= 0)
							{
								iNumStars = i + 1;
								break;
							}
						}
						else
						{
							break;
						}
					}
					
					g_ratingElem = rStar;
				}
				
				if((iNumStars > 0) && (iNumStars < 6))
				{
					var NrStars = document.getElementById("nrstars");
					if(NrStars != null)
					{
						NrStars.value = iNumStars;
					}
					
					rc = true;
				}
				else
				{
					alert("You must choose a rating between 1 and 5 stars.");
					
					if(g_ratingElem != null)
					{
						setTimeout('g_ratingElem.focus()', 5);  // delay it for the likes of Firefox
						if(ratingElemName == "rating")
						{
							setTimeout('g_ratingElem.select()', 5); // delay it for the likes of Firefox
						}
					}
				}
		
				// HEADLINE
				if(rc)
				{
					rc = false;
					
					g_headElem = document.getElementsByName(headElemName)[0];
					
					var strimpc = "";
					if(g_headElem != null)
					{
						strimpc = trim(g_headElem.value);
					}
				
					if(strimpc.length < 3)
					{
						alert("You must enter a headline for your review. (Minimum 3 characters)");
							
						if(g_headElem != null)
						{			
							//g_headElem.focus();
							//g_headElem.select();
							setTimeout('g_headElem.focus()', 5);  // delay it for the likes of Firefox
							setTimeout('g_headElem.select()', 5); // delay it for the likes of Firefox
						}
					}
					else
					{
						rc = true;
					}
				}
				
				// REVIEW
				if(rc)
				{
					rc = false;
					
					g_reviewElem = document.getElementsByName(reviewElemName)[0];
					
					var strimpc = "";
					if(g_reviewElem != null)
					{
						strimpc = trim(g_reviewElem.value);
					}
				
					if(strimpc.length < 5)
					{
						alert("You must enter your review. (Minimum 5 characters)");
							
						if(g_reviewElem != null)
						{			
							//g_reviewElem.focus();
							//g_reviewElem.select();
							setTimeout('g_reviewElem.focus()', 5);  // delay it for the likes of Firefox
							setTimeout('g_reviewElem.select()', 5); // delay it for the likes of Firefox
						}
					}
					else
					{
						rc = true;
					}
				}
				
				// NAME
				if(rc)
				{
					rc = false;
					
					g_nameElem = document.getElementsByName(nameElemName)[0];
					
					var strimpc = "";
					if(g_nameElem != null)
					{
						strimpc = trim(g_nameElem.value);
					}
				
					if(strimpc.length < 3)
					{
						alert("You must enter your e-mail address or first name. (Minimum 3 characters)");
							
						if(g_nameElem != null)
						{			
							//g_nameElem.focus();
							//g_nameElem.select();
							setTimeout('g_nameElem.focus()', 5);  // delay it for the likes of Firefox
							setTimeout('g_nameElem.select()', 5); // delay it for the likes of Firefox
						}
					}
					else
					{
						rc = true;
					}
				}
				
				// LOCATION
				if(rc)
				{
					rc = false;
					
					g_locElem = document.getElementsByName(locElemName)[0];
					
					var strimpc = "";
					if(g_locElem != null)
					{
						strimpc = trim(g_locElem.value);
					}
				
					if(strimpc.length < 4)
					{
						alert("You must enter your location. (Minimum 4 characters)");
							
						if(g_locElem != null)
						{			
							//g_locElem.focus();
							//g_locElem.select();
							setTimeout('g_locElem.focus()', 5);  // delay it for the likes of Firefox
							setTimeout('g_locElem.select()', 5); // delay it for the likes of Firefox
						}
					}
					else
					{
						rc = true;
					}
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:validatereviewfields() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInRevHandler = false;
	}
	
	return(rc);
}

function iscountrystatevalid(elemCountry, elemState)
{
    var rc = true;
    
	try
	{
		if(csValidate && (elemState != null) && (elemCountry != null))
		{
			if(!g_bInCSHandler) //prevent recursive entry
			{
				g_bInCSHandler = true;
		
				var coElem = document.getElementsByName(elemCountry)[0];
				if(coElem != null)
				{
					g_stElem = document.getElementsByName(elemState)[0];
					if(g_stElem != null)
					{
						if(coElem.value.length > 0)
						{
							if((coElem.value.toLowerCase() == "usa") || (coElem.value.toLowerCase() == "canada"))
							{
								if(g_stElem.value.length == 0)
								{
									rc = false;
							
									alert("Invalid State - Please re-enter.");
										
									setTimeout('g_stElem.focus()', 5);  // delay it for the likes of Firefox
									setTimeout('g_stElem.select()', 5); // delay it for the likes of Firefox
								}
							}
						}
					}
				}
			}
		}
	}
	catch(e)
	{
	    if(e.description.length != 0) { process_error("FieldValidation.js:iscountrystatevalid() : Exception caught [" + e.description + "]"); }
	}
	finally
	{
		g_bInCSHandler = false;
	}
	
	return(rc);
}

