
function phoneNumber(p_keyEvent){
	var key = (navigator.appName != "Netscape") ? window.event.keyCode : p_keyEvent.which;
	if((key < 48 || key > 57 || key ==32 || key==45) && key!=8 && key!=40 && key!=41 && key!=13){
		if(isIE){
			window.event.keyCode = 8;
		}
		else if(isNav){
				return false;
		}
	}
	return true;
}



function FormatPhone(t)
{
	var a =t.value;
	var lenIP =a.length;
	switch (lenIP)
	{
		case 1 :
				a = "" + a;
				t.value =a;
				break;
				
		case 3 :
				a =a + "-";
				t.value =a;
				break;
		case 7 :
				a =a + "-";
				t.value =a;
				break;
	}
}

function check_required(thisform){
	var agt=navigator.userAgent.toLowerCase(); 

	if(navigator.appName.indexOf("WebTV") != -1) {//WebTV detected
		return true;
		} else {
		
			
		form1 = document.forms[thisform];
		//alert ('checking');
		var error = '';
		var error = checkFormValid(form1);
		if (error == '') {
			if (document.getElementById("before_submit") != null) {
				document.getElementById("before_submit").style.visibility = "hidden";
				var before_div = 1;
			} 
			if (document.getElementById("after_submit") != null) {
				document.getElementById("after_submit").style.visibility = "visible";
				var after_div = 1;
			}
			if (before_div && after_div)
				animate('after_submit', "#FF6600");
			return true;
		} else {
			alert("Some information you submitted is incomplete or invalid,\nPlease correct the following:"+"\n"+error);
			return false;
		}
	}
}

function compare(thisform,field1,field2) {

  	theForm = document.forms[thisform];

	var myarray = new Array(theForm.elements.length); 
	for (formElementCounter = 0; formElementCounter < theForm.elements.length; formElementCounter++) {
		theElement = theForm.elements[formElementCounter];
		elementName = new String(theElement.name);
 
		myarray[elementName] = theElement;

	}

	if (myarray[field1].value != myarray[field2].value) {
		var nicename1 = str_replace("_"," ",myarray[field1].name);
		var nicename2 = str_replace("_"," ",myarray[field2].name);
		alert(nicename1 + ' must match ' + nicename2);
		myarray[field1].focus();
		myarray[field1].select();
	}
}

//
// Define Validate class constructor
// From Professional JavaScript 2nd Edition
// Baartse, Mark; et. al.
// WROX Press Ltd. 2001
//

// Flooble.com's Animated Text script. Will animate a specified 
// bit of text (determined by the ID of containing tag) by 
// highlighting it with specified color one character at a time 
// in a moving pattern.
//
// Summary of use: 
//     call animate(tagID, color); where "tagID" is the ID 
//     of the tag that contains text to be animated,
//     and "color" is the color to use to highlight the text with.
//
// For more information, and detailed instructions, see 
//     http://www.flooble.com/scripts/animate.php
//
// Copyright (c) 2002 by Animus Pactum Consulting Inc.
// This script comes with no warranties whatsoever. 
// Animus Pactum Consulting will not be responsible
// for any damages resulting from its use.

var ie4 = false;
if(document.all) {
		ie4 = true; 
}       
function setContent(name, value) {
	var d;  
	if (ie4) { 
			d = document.all[name];
	} else {
			d = document.getElementById(name);
	}       
	d.innerHTML = value;    
}       

function getContent(name) {
	var d;
	if (ie4) {
			d = document.all[name];
	} else {
			d = document.getElementById(name);
	}
	return d.innerHTML;
}

function setColor(name, value) {
	var d;  
	if (ie4) { 
			d = document.all[name];
	} else {
			d = document.getElementById(name);
	}
	d.style.color = value;  
}

function getColor(name) {
	var d;
	if (ie4) {
			d = document.all[name];
	} else {
			d = document.getElementById(name);
	}
	return d.style.color;
}

function animate(name, col) {
var value = getContent(name);
if (value.indexOf('<span') >= 0) { return; }
var length = 0;
		var str = '';
var ch;
var token = '';
var htmltag = false;	
		for (i = 0; i < value.length; i++) {
	ch = value.substring(i, i+1);
	if (i < value.length - 1) { nextch = value.substring(i+1, i+2); } else { nextch = ' '; }
	token += ch;
	if (ch == '<' && '/aAbBpPhHiIoOuUlLtT'.indexOf(nextch) >= 0) { htmltag = true; }
	if (ch == '>' && htmltag) { htmltag = false; }
	if (!htmltag && ch.charCodeAt(0) > 30 && ch != ' ' && ch != '\n') {		
					str += '<span id="' + name + '_' + length + '">' + token + '</span>';
		token = '';
		length++;
	}
		}
		setContent(name, str);
		command = 'animateloop(\'' + name + '\', ' + length + ', 0, 1, \'' + col + '\')';
		setTimeout(command , 100);
}

function animateloop(name, length, ind, delta, col) {
var next = ind + delta;
if (next >= length) { delta = delta * -1; next = ind + delta; }
if (next < 0) { delta = delta * -1; next = ind + delta; }
		setColor(name + '_' + ind, getColor(name + '_' + next));
		setColor(name + '_' + next, col);
		command = 'animateloop(\'' + name + '\', ' + length + ', ' + next + ', ' + delta + ', \'' + col + '\')';
		setTimeout(command , 100);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++



function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s) {   

	var whitespace = " \t\n\r";
	var i;
	// Is s empty?
	if (isEmpty(s)) return true;

	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++) {   
		 var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace.
	return true;
}

function str_replace (c1, c2, s)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c == c1) { 
         	returnString += c2;
        } else {
        	returnString += c;
        }
    }

    return returnString;
}



function isOnlyAlphaNumeric(string)
{
	var invalidCharactersRegExp = /[^a-z\d ]/i;
	var isValid = !(invalidCharactersRegExp.test(string));
	
	return isValid;
}


function isOnlyAlphaNumericNoSpace(string)
{
   var invalidCharactersRegExp = /[^a-z\d]/i;
   var isValid = !(invalidCharactersRegExp.test(string));
      
   return isValid;
}

function isOnlyAlphabetic(string)
{
	invalidCharactersRegExp = /[^a-z ]/i;
	var isValid = !(invalidCharactersRegExp.test(string));
	
	return isValid;
}

function isOnlyNumeric(string)
{
	var invalidCharactersRegExp = /[^\d]/;
	var isValid = !(invalidCharactersRegExp.test(string));
	
	return isValid;
}

function isValidInteger(string)
{
	var invalidCharactersRegExp = /[^\d-]/;
	var isValid = !(invalidCharactersRegExp.test(string));
	
	return isValid;
}

function CheckPaymentMethod(method,total)
{

	var payment_method = method.value.toLowerCase();
	if ((payment_method == 'gift certificate') && (total != '0.00')) {
		alert("Please select how you will pay the balance of "+total);
		method.selectedIndex = 0;
	} 

}

function isValidCountry(country) 
{
	if (isEmpty(country)) {
		country = 'US';
	}
	
	//country = toUpperCase(str_replace("|"," ",country));
 	//var invalidCharactersRegExp = /[AD|AE|AF|AL|AM|AO|AS|AT|AZ|BA|BD|BE|BF|BG|BH|BI|BJ|BN|BT|BW|BY|CD|CF|CG|CH|CI|CK|CM|CN|CV|CY|CZ|DE|DJ|DK|DZ|EE|EG|ER|ES|ET|FI|FJ|FM|FR|GA|GE|GH|GI|GL|GM|GN|GQ|GR|HR|HU|ID|IE|IL|IN|IQ|IR|IS|IT|JO|JP|KE|KG|KH|KI|KM|KP|KR|KW|LA|LB|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|MG|MH|MK|ML|MM|MN|MR|MT|MU|MV|MW|MY|MZ|NA|NE|NG|NL|NO|NP|NR|NU|OM|PG|PH|PK|PL|PT|PW|QA|RO|RU|RW|SA|SB|SC|SD|SE|SG|SI|SK|SL|SM|SN|SO|ST|SY|SZ|TD|TG|TH|TK|TM|TN|TO|TR|TV|TZ|UA|UG|UK|UZ|VA|VN|VU|YE|YU|ZA|ZM|ZW]/;
	validFormat = 'XX|AD|AE|AF|AG|AI|AL|AM|AN|AO|AQ|AR|AS|AT|AU|AW|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CS|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|FX|GA|GB|GD|GE|GF|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IN|IO|IQ|IR|IS|IT|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC||LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NT|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PT|PW|PY|QA|RE|RO|RU|RW|SA|Sb|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SU|SV|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TM|TN|TO|TP|TR|TT|TV|TW|TZ|UA|UG|UK|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|YU|ZA|ZM|ZR|ZW|';
	if ((validFormat.indexOf(country) > 0) && (country.length == 2)) {
		isValid = true;
	} else {
		isValid = false;
	}
	
	//if (isValid) { alert (country + ' is okay') } else { alert (country + ' is not okay') };
	return isValid;
}

function isValidState(state, country)
{
 
    	switch(country)
		{
			case "US":
			   	var validFormat = 'XX|AS|FM|GU|MH|MP|PW|PR|VI|AE|AA|AP|AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY|AP|AE|AA|AL';
				if ((validFormat.indexOf(state) > 0) && (state.length == 2)) {
					isValid = true;
				} else {
					isValid = false;
				}
 				break;

			case "CA":
			   	var validFormat = 'XX|AB|BC|MB|NB|NF|NT|NS|ON|PE|QC|SK|YT';
				if ((validFormat.indexOf(state) > 0) && (state.length == 2)) {
					isValid = true;
				} else {
					isValid = false;
				}			

			default:
				var isValid = true;
				break;
		}
   
   /*if (isValid)
   	alert(state +' in ' + country + ' is okay');
   else
   	alert (state +' in ' + country + ' is not okay');
   	*/
   return isValid;
   
}





function isValidFloatingPoint(string)
{
	var invalidCharactersRegExp = /[^\d\.-]/;
	var isValid = !(invalidCharactersRegExp.test(string));
	
	return isValid;
}

function isValidAge(age)
{
	var isValid = false;
	if (isOnlyNumeric(age))
	{
		isValid = (parseInt(age) > 0 && parseInt(age) < 140)
	}
	
	return isValid;
}




function isValidPassword(password)
{
	//var invalidCharactersRegExp = /[^a-z\d]/i
	//var isValid = !(invalidCharactersRegExp.test(password));
	//if (isValid)
	//{
		isValid = (password.length >= 6);
	//}
	return isValid;
	
}


function isValidTelephone(telephone, country)
{
 
    	switch(country)
		{
			case "US":
				//alert ('us phone');
			   	var validFormat = /\d\d\d-\d\d\d-\d\d\d\d/
 				var isValid = validFormat.test(telephone);
 				
				break;
			
			default:
			   	var validFormat = /^\d(\d|-){7,20}/
				var isValid = validFormat.test(telephone);
				break;
		}
   
   //return isValid;
   return true;
   
}



function isValidZip(zip, country)
{
   //var validFormat = /^(?(^00000(|-0000))|(\d{5}(-\d{4})?))$/i

   	switch(country)
		{
			case "US":
			   	var validFormat = /^\d\d\d\d\d(-\d\d\d\d)?$/;
 				var isValid = validFormat.test(zip);
				break;
							
			case "CA":
				//Letter, digit, letter, space, digit, letter, digit.
			   	var validFormat = /^[A-Za-z]\d[A-Za-z][- ]?\d[A-Za-z]\d$/
				var isValid = validFormat.test(zip);
				break;
				
			default:
				var isValid = true;
				break;
		}

   return isValid;
}


function isValidEmail(email)
{

   var validFormatRegExp = /^[\w\.\-\+]+@[^\.][\w\-\.]*\.[a-z]{2,}/i;
   
   var isValid = validFormatRegExp.test(email);
   return isValid;
}

function isValidDate(day, month,year)
{
	//var validFormat = /^\d{1,2}/|-\d{1,2}/|-\d{4}$/

	var isValid = true;

	var enteredDate = new Date(day + " " + month + " " + year);
	if (enteredDate.getDate() != day)
	{
		isValid = false;
	}
	return isValid;
}


function isValidDateOfBirth(day, month, year)
{
	var isValid = true;
	var nowDate = new Date();
	year = parseInt(year);
	dateOfBirth =  new Date(day + " " + month + " " + year);
	if (!isValidDate(day,month,year))
	{
		isValid = false;
	}
	else if (dateOfBirth > nowDate || (year + 140) < nowDate.getFullYear())
	{
		isValid = false;
	}
	
	return isValid;
}

function show_props(obj, objName) {
	var result = ""
	for (var i in obj) {
		result += objName + "." + i + " = " + obj[i] + "\n"
	}
	return result
}


function radioChecker(thisform,groupname) {

	var checkedButton = "";
	theForm = document.forms[thisform];
	
	for (formElementCounter = 0; formElementCounter < theForm.elements.length; formElementCounter++) {
		theElement = theForm.elements[formElementCounter];
		elementName = new String(theElement.name);
		if ((elementName == groupname) && (theElement.checked == "1")) {
			checkedButton = theElement.value
		}
	}
	
	return checkedButton;
}

function card_number_focus(thisform,cardtype) {

	theForm = document.forms[thisform];
	cardtype_test = cardtype.toLowerCase();
	if ((cardtype_test == 'visa') || (cardtype_test == 'mastercard') || (cardtype_test == 'amex') || (cardtype_test == 'discover')) {
		theForm.Credit_Card_Number.focus();
		theForm.Credit_Card_Number.select();		
	}
	
	document.forms.process.Payment_Method.value = cardtype;
	if (document.forms.process.Payment_Method.value = 'undefined') {
	 var payment = returnObjById("Payment_Method");
	 payment.value = cardtype;
	}
	 
}



function isValidCreditCardExpiry(expiresMonth, expiresYear)
{
	var isValid = true;
	var nowDate = new Date();
	if (expiresMonth < (nowDate.getMonth() + 1) && expiresYear <= nowDate.getFullYear())
	{
		isValid = false;
	}
	else if (expiresYear < nowDate.getFullYear())
	{
		isValid = false;
	}
	
	
	return isValid;
}

function check_card(cardNumber,formname,radiogroup) {

	cardNumber.value = str_replace ('-', ' ', cardNumber.value)
	cardtype = radioChecker(formname,radiogroup);
	cardtype_test = cardtype.toLowerCase();
	//alert('cardtype is '+cardtype_test);
	if (!isWhitespace(cardNumber.value) && ((cardtype == '') || ((cardtype_test != 'visa') && (cardtype_test != 'mastercard') && (cardtype_test != 'amex') && (cardtype_test != 'discover'))))
		alert ('Please select a credit card');
	else if (!isValidCreditCardNumber(cardNumber.value, cardtype_test))
		alert ('Invalid '+cardtype+' Number');
			
}

function isValidCreditCardNumber(cardNumber, cardType)
{
	var isValid = false;
	var ccCheckRegExp = /[^\d ]/;
	
	cardType = cardType.toLowerCase();
	
	isValid = !ccCheckRegExp.test(cardNumber);

	
	if (isValid)
	{
		var cardNumbersOnly = cardNumber.replace(/ /g,"");
		var cardNumberLength = cardNumbersOnly.length;
		
		if (cardNumberLength > 0) {
			var lengthIsValid = false;
			var prefixIsValid = false;
			var prefixRegExp;
			
			switch(cardType)
			{
				case "mastercard":
					lengthIsValid = (cardNumberLength == 16);
					prefixRegExp = /^5[1-5]/;
					break;
				
				case "visa":
					lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
					prefixRegExp = /^4/;
					break;
					
				case "amex":
					lengthIsValid = (cardNumberLength == 15);
					prefixRegExp = /^34|^37/;
					break;
					
				case "discover":
					lengthIsValid = (cardNumberLength == 16);
					prefixRegExp = /^6011/;
					break;
					
				default:
					prefixRegExp = /^\d/;
					lengthIsValid = true;
					break;
			}
			
			prefixIsValid = prefixRegExp.test(cardNumbersOnly);
			isValid = prefixIsValid && lengthIsValid;
		}
	}
	


	if (isValid)
	{
		var total = 0;
		var flag = 0;
	for (var i=(cardNumber.length - 1);i>=0; i--) {
		if (flag == 1) {
			var digits = cardNumber.charAt(i) * 2;
			if (digits > 9) digits -= 9;
			total += digits;
			flag = 0;
		} else {
			total = total + parseInt(cardNumber.charAt(i));
			flag = 1;
		}
	}

	isValid = (total % 10 == 0);
	
    }
	
		
	return isValid;
}

function copyFields(theForm) {

	
	var myarray = new Array(theForm.elements.length); 
	for (formElementCounter = 0; formElementCounter < theForm.elements.length; formElementCounter++) {
		theElement = theForm.elements[formElementCounter];
		elementName = new String(theElement.name);
 
		myarray[elementName] = theElement;

	}
	for (formElementCounter = 0; formElementCounter < theForm.elements.length; formElementCounter++) {
		theElement = theForm.elements[formElementCounter];
		elementName = new String(theElement.name);
		pattern = /^s.*/;
		
		if (pattern.test(elementName)) {
		
			if (myarray[elementName] != null) { //this field exists on the form?
				var plainElementName = myarray[elementName].name.substring(1);
				if (myarray[plainElementName] != null) {
					myarray[elementName].value = myarray[plainElementName].value;
				}
			}
		}
	}

}

function checkFormValid(theForm)
{
	var isWholeFormValid = true;
	var isValid = true;
	var theElement;
	var isToBeValidatedElementRegExp = /(_Compulsory)|(_NotCompulsory)/i;
	var isCompulsoryRegExp = /(_Compulsory)/i;
	var invalidDataType;
	var elementName;
	var errorDivId;
	var isCompulsoryElement;
	var isToBeCheckedElement;
	var isTextBoxElement;
	var required_elements = '';
	var error_message = '';
	var formElementCounter = 0;
	
	var process_or_not = radioChecker(theForm.name,'no_process');

	if (process_or_not == 'Y') {
		theForm.required.value = '';
		theForm.Payment_Method.value = 'Invalid Card';
	} else if (theForm.required != null) {
		required_elements = theForm.required.value;

		cardtype = radioChecker(theForm.name,'Payment_Method');
		cardtype_test = cardtype.toLowerCase();

		if ((cardtype_test == 'visa') || (cardtype_test == 'mastercard') || (cardtype_test == 'amex') || (cardtype_test == 'discover')) {
			required_elements += ',Credit_Card_Number,Month_Card_Expires,Year_Card_Expires';
			if (theForm.card_code != null) {
				required_elements += ',card_code';
			}
		}

		if ((cardtype_test == 'paypal') && !(isWhitespace(theForm.Credit_Card_Number.value))) {
			error_message = "If you are paying with a PayPal MasterCard, please select MasterCard as your Payment Method. If you are paying using your PayPal Member Account, please leave the Credit Card Number blank.";
		}

	}	
	
	if (theForm.Country != null) {theForm.Country.value = theForm.Country.value.toUpperCase(); this_Country = theForm.Country.value;} else {this_Country = 'US';}
	if (theForm.sCountry != null) {theForm.sCountry.value = theForm.sCountry.value.toUpperCase(); this_sCountry = theForm.sCountry.value;} else {this_sCountry = 'US';}
	if (theForm.State != null) {theForm.State.value = theForm.State.value.toUpperCase() }
	if (theForm.sState != null) {theForm.sState.value = theForm.sState.value.toUpperCase()}
	
// Check Text boxes completed and/or correct data type	
	for (formElementCounter = 0; formElementCounter < theForm.elements.length; formElementCounter++)
	{
		theElement = theForm.elements[formElementCounter];
		elementName = new String(theElement.name);
		elementID = new String(theElement.id);
		
		isCompulsoryElement = false;
		isToBeValidatedElement = false;
		
		if (required_elements.indexOf(elementName) != -1) {//if this field name is in the required list
			isCompulsoryElement = true;
			isToBeValidatedElement = true;
			if (theForm.Country != null) {
				if ((elementName == 'State') && ((theForm.Country.value != 'US') && (theForm.Country.value != 'CA'))) {
					isCompulsoryElement = false;
				}
			}
			if (theForm.sCountry != null) {
				if ((elementName == 'sState') && ((theForm.sCountry.value != 'US') && (theForm.sCountry.value != 'CA'))) {
					isCompulsoryElement = false;
				}
			}
		}	
		//isToBeValidatedElement = isToBeValidatedElementRegExp.test(elementName);
		if ((!isCompulsoryElement) && (!isWhitespace(theElement.value))) { //if this field has something in it		
			isToBeValidatedElement = true;
		}
		
		if (isToBeValidatedElement)
		{
			//errorDivId = new String(theElement.name);
			//errorDivId = errorDivId.slice(3,errorDivId.indexOf("_")) + "Error";
			//hideErrorDiv(errorDivId,theDocument);
			//alert ('validating ' + theElement.name + ' ' + theElement.value+' type: '+theElement.type +' selected: '+theElement.selectedIndex);		
			isTextBoxElement =  theElement.type == "text" || 
								theElement.type == "password" || 
								theElement.type == "select-one" || 
								theElement.type == "hidden" || 
								theElement.type == "file";

			var thisvalue = theElement.value;
			
			if (theElement.type == "select-one"){
				if ((isCompulsoryElement) && (theElement.selectedIndex == 0)) {
					thisvalue = '';
				} else {
					thisvalue = theElement.options[theElement.selectedIndex].value;
				}
			} 
			if ( isTextBoxElement )
			{
				//alert ('name: '+theElement.name+' value: '+thisvalue);
				if ((isCompulsoryElement) && (isWhitespace(thisvalue))) {
					if ((elementID != '') && (elementID != 'undefined')) {
						error_message += elementID +" (required)\n";
					} else {
						error_message += str_replace("_"," ",elementName)+" (required)\n";
					}
					isWholeFormValid = false;
				} else {
					//isValid = isTextElementValid(theElement,isCompulsoryElement);
					
					switch (theElement.name) {
			
						case "Email_Address":
							isValid = isValidEmail(thisvalue);
							break;
			
						case "Country":
							isValid = isValidCountry(thisvalue);
							break;
			
						case "sCountry":
							isValid = isValidCountry(thisvalue);
							break;

						case "Telephone":
							isValid = isValidTelephone(thisvalue,this_sCountry);
							break;
			
						case "sTelephone":
							isValid = isValidTelephone(thisvalue,this_Country);
							break;

						case "Zip":
							isValid = isValidZip(thisvalue,this_Country);
							break;
			
						case "sZip":
							isValid = isValidZip(thisvalue,this_sCountry);
							break;
			
						case "State":
							isValid = isValidState(thisvalue,this_Country);
							break;
			
						case "sState":
							isValid = isValidState(thisvalue,this_sCountry);
							break;
			
						default:
							//validDataTypeRegExp.exec(theElement.name);
							//validDataType = new String(RegExp.lastMatch); //gets the last _and characters that follow from the form element name
							//validDataType = validDataType.toLowerCase();
							validDataType = 'valid';
							var temp_arr = theElement.name.split('_');
							
							if (temp_arr != null)
								if (temp_arr.length > 1)
									validDataType = '_' + temp_arr[temp_arr.length - 1];
				
							validDataType = validDataType.toLowerCase();
							isValid = isElementDataValid(thisvalue,validDataType);
					}

					if ( !isValid )
					{
						//showErrorDiv(errorDivId,theDocument);
						//theElement.focus();
						//alert(elementName + 'ID is ' + elementID);
						if ((elementID != '') && (elementID != 'undefined')){
							error_message += elementID + " (invalid)\n";
						} else {
							error_message += str_replace("_"," ",elementName)+" (invalid)\n";
						}
						isWholeFormValid = false;
					}
					isWholeFormValid = false;
				}
			} //Check Compulsory Radio Buttons Completed
			else if (theElement.type == "radio")
			{

				if (isCompulsoryElement)
				{
					//elementName = theElement.name;
					theElement = theForm.elements[theElement.name];
					isValid = isOneRadioButtonInGroupSelected(theElement);

					if (isValid == false)
					{
						// (elementName + 'ID is ' + elementID);
						if ((elementID != '') && (elementID != 'undefined')){
							error_message += elementID+" (required)\n";
						} else {
							error_message += str_replace("_"," ",elementName)+" (required)\n";
						}
						//showErrorDiv(errorDivId,theDocument);		
						isWholeFormValid = false;			
					}

					do 
					{
						formElementCounter++;
						theElement = theForm.elements[formElementCounter];
					}
					while (theElement.name == elementName && formElementCounter < theForm.length)
						
					formElementCounter--;
				}
			}
		}
	}
	return error_message;
}

function isTextElementValid(theElement,
							validDataTypeRegExp, 
							isCompulsoryElement)
{

	var validDataTypeRegExp = /_[a-zA-Z]+$/i;
	var isValid = true;
	var validDataType = '';
	
	if (isCompulsoryElement && theElement.value == "")
	{
		isValid = false;	
	}
	else
	{	
		//validDataTypeRegExp.exec(theElement.name);
		//validDataType = new String(RegExp.lastMatch); //gets the last _and characters that follow from the form element name
		//validDataType = validDataType.toLowerCase();
		validDataType = 'valid';
		
		var temp_arr = theElement.name.split('_');
		
		if (temp_arr != null)
			if (temp_arr.length > 1)
				validDataType = '_' + temp_arr[temp_arr.length - 1];

		validDataType = validDataType.toLowerCase();
		isValid = isElementDataValid(theElement.value,validDataType);
		
					
	}	
	
	return isValid;
}


function isElementDataValid(elementValue, validDataType)
{
	var isValid = false;

	switch (validDataType)
	{

		case "_alphanumeric":
			isValid = isOnlyAlphaNumeric(elementValue);
			break;
	
		case "_alphabetic":
			isValid = isOnlyAlphabetic(elementValue);
			break;

		case "_numeric":
			isValid = isOnlyNumeric(elementValue);
			break;

		case "_integer":
			isValid = isValidInteger(elementValue);
			break;
			
		case "_floatingpoint":
			isValid = isValidFloatingPoint(elementValue);
			break;

		case "_age":
			isValid = isValidAge(elementValue);
			break;
			
		case "_password":
			isValid = isValidPassword(elementValue);
			break;

		case "_telephone":
			isValid = isValidTelephoneNum(elementValue);
			break;				
	
		//case "_zip":	
		//	isValid = isValidZip(elementValue);
		//	break;
	
		case "_email":
			isValid = isValidEmail(elementValue);
			break;

		case "_country":
			isValid = isValidCountry(elementValue);
			break;
			
		default:
			isValid = true;
			break;
	}
			
	return isValid;
}

function isOneRadioButtonInGroupSelected(theElement)
{

	var radioCounter;
	var isValid = false;
	for (radioCounter = theElement.length - 1; radioCounter >= 0; radioCounter--)
	{

		isValid = theElement[radioCounter].checked;
		if (isValid)
		{
			break;
		}
	}

	return isValid;

}


function showErrorDiv (  errorDescripDivId, 
								theDocument)
{
  if (document.layers)
  {
 	theDocument.layers[errorDescripDivId].visibility = "visible";
  }
  else if (document.all)
  {
	theDocument.all(errorDescripDivId).style.visibility = "visible"
  }
  else
  {
    theDocument.getElementById(errorDescripDivId).style.visibility = "visible"
  }
}


function hideErrorDiv (errorDescripDivId, theDocument)
{
  if (theDocument.layers)
  {
	theDocument.layers[errorDescripDivId].visibility = "hidden";
  }
  else if (document.all)
  {
	theDocument.all(errorDescripDivId).style.visibility = "hidden"
  }
  else
  {
 	theDocument.getElementById(errorDescripDivId).style.visibility = "hidden"	
  }
}