// JavaScript Document
var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
var consult = new Array('myname','address','phone','email');
var globalSmartKey = true;
var fields = ['Gender','DOB','Height','Weight'];
function validateForm(Obj){
				
				var error1 = true, errorS='';
					
					if (Obj.email.value=='') {
						errorS+='-E-mail address required.<br>';
						error1 = false;
					} else if (emailRegxp.test(Obj.email.value) != true ) {
						errorS+='-Invalid e-mail address.<br>';
						error1 = false;
					} else if (Obj.email.value != Obj.emailconfirm.value ) {
						errorS+='-E-mail address not matched.<br>';
						error1 = false;
					}
					
					// first name
					if (Obj.fname.value=='') {
						errorS+='-First Name required.<br>';
						error1 = false;
					}
					
					// last name
					if (Obj.lname.value=='') {
						errorS+='-Last Name required.<br>';
						error1 = false;
					}
                    
                    if (Obj.zipcode.value=='') {
						errorS+='-Zip Code required.<br>';
						error1 = false;
					} else if ( !/[0-9]{5}/.test( Obj.zipcode.value ) ) {
                        errorS+='-Invalid Zip Code.<br>';
						error1 = false;
                    }
                    
                    if (Obj.phone.value=='') {
						errorS+='-Phone required.<br>';
						error1 = false;
					}
					
                    /*
					if (globalSmartKey)
					{
						for(var t=0; t<fields.length; t++)
						{
							if (Obj[fields[t]].value == '') 
							{
								errorS+= '-' + fields[t] + ' required.<br>'
								error1 = false;
							}
						}
					} */
                        
					if (Obj.vcode.value=='') {
						errorS+='-Verification Code required.<br>';
						error1 = false;
					}
					
				
				if (error1) {
                    return true;
					
				} else {
					document.getElementById("error").innerHTML= '<strong>Please check your form to correct the following error(s):</strong><br>' + errorS + '<br>';
					var uri = '' + window.location;
		  			window.location.href =  (uri.indexOf('#error')== -1) ? window.location.href + '#error' : window.location.href;
				}
				
				return false;
}


function addSmartKey()
{
	globalSmartKey = true;
	
	addS2 = document.getElementById("addS");
	removeS2 = document.getElementById("removeS");
	
	addS2.style.display = "none";
	removeS2.style.display = "block";
	
	var smartkeyId = document.getElementById("smartkey");
	
	smartkeyId.style.display = "block";
	/*
	addS.style.display = "none";
	removeS.style.display = "block";
	

	var pNew = document.createElement("p");
	
	//pNew.setAttribute("id","pSmart");
	pNew.id="pSmart"; 
	pNew.innerHTML = '<br /><strong>Please fill in the information below to set up your SmartKey. It will be pre-programmed and waiting for you when you arrive at the club.</strong><br />';
	pNew.innerHTML +='<br /><small>This information is private.  It\'s used to pre-load your SmartKey so that it may provide you with accurate fitness information during and after your workout.</small><br />';

	for(var t=0; t<fields.length; t++)
	{
		pNew.innerHTML += '<label for="'+fields[t]+'">' +
			'<span id="err' + fields[t] +'" class="error"></span>' +
			'<span class="error">*</span>' + fields[t] +':' +
						'</label>' +
		'<input class="medium" id="' + fields[t] +'" name="' + fields[t] +'" type="text" value="" />';
	}
	
	pNew.innerHTML += '<br /><br />';
	smartkeyId.appendChild(pNew); */

}

function subSmartKey()
{
		globalSmartKey = false;
		
		addS2 = document.getElementById("addS");
	removeS2 = document.getElementById("removeS");
		
		addS2.style.display = "block";
		removeS2.style.display = "none";
	
		var smartkeyId = document.getElementById("smartkey");
		
		smartkeyId.style.display = "none";

}

function validateForm2(Obj){
var error = false, errorMsg='';
					
					if (Obj.CUemail.value=='') {
						errorMsg += 'E-mail is a required field.<br>';
						error = true;
						//Obj.email.focus();
					} else if (emailRegxp.test(Obj.CUemail.value) != true ) {
						errorMsg += 'Invalid e-mail address.<br>';
						error = true;
						//Obj.email.focus();
					}
					
					if (Obj.CUname.value=='') {
						errorMsg += 'Name is a required field.<br>';
						error = true;
						//Obj.fullname.focus();
					}
					
					if (Obj.CUmsg.value=='') {
						errorMsg += 'Message is a required field.<br>';
						error = true;
						//Obj.fullname.focus();
					}
                    
                    if (Obj.vcode.value=='') {
						errorMsg += 'Verification Code is a required field.<br>';
						error = true;
						//Obj.fullname.focus();
					}
					
					
					
				if (error == false) {
					return true;
				} else {
					document.getElementById("error").innerHTML= '<strong>Please check your form to correct the following error(s):</strong><br>' + errorMsg + '<br>';
					var uri = '' + window.location;
		  			window.location.href =  (uri.indexOf('#error')== -1) ? window.location.href + '#error' : window.location.href;
				}
                return false;
}
