//sets a global array that will track the clicks for each button
var clicks = new Array();
var clicks = 0;
var submitOk = false;
//calculates the button's clicks
function disableSubmit(obj, func) {
  if(clicks[obj] > 1){
   submitOk = false;
  } 
  else{          
  //obj.form.submit();
  if(!clicks[obj]){
   clicks[obj] = 1;
  }else{
   clicks = clicks[obj]+1;
   clicks[obj] = clicks; 
  }  
   submitOk =  true; 
  } 
  if(func == undefined || func){
    if(submitOk){
      obj.disabled = true;    
      //obj.value = "Processing";  	
      obj.form.submit();
      return true;
    }else{ 
      return false;
    }
  }
  return false;
}

function showTab(me, info){ // show tabs
	var tabHolder = me.parentNode.parentNode.childNodes; // Get the top UL
	var tabInfo = document.getElementById(info);
	for(i=0; i<tabHolder.length; i++){ // cycle through the li's
		if(tabHolder[i].className == "on"){ // if they li's class is "on"		
			tabHolder[i].className = "";	 // turn it off			
			me.parentNode.className = "on" // turn the selected tab on			
			return; // kill the script
		}			
	}	
}


function isEmailAddress(string) { //email checking function
	return /^[^@]+@[^.]+(\.[^.]+)+$/.test(string); // return the legit email
}

//validates the registration form
function checkMe(regForm){	
	var canSubmit = true;
	var error = ''; // errors holder
	if(!regForm.firstName.value){		
		error += "Please fill in your First Name\n";			
	}	
	if(!regForm.lastName.value){
		error += "Please fill in your Last Name\n";		
	}	
	if(!regForm.screenName.value){
		error += "Please fill in your User Name\n";		
	}
	if(!regForm.email.value){
		error += "Please fill in your Email\n";		
	}else{
		if(!isEmailAddress(regForm.email.value)){ // checking to see if the email is valid
			error +="Please enter a valid email address\n";			
		}
	}
	if(!regForm.confirmEmail.value){
		error += "Please Confirm your Email\n";		
	}else{
		if(regForm.email.value != regForm.confirmEmail.value){ // check to see if the email matches the confirmation email
			error +="Confirm Email address doesn't match your Email address\n";			
		}
	}	
	if(!regForm.countryCode.value){
		error += "Please fill in your Country\n";		
	}
	
	if(!regForm.postal.value){
		error += "Please fill in your Zip/Postal Code\n";		
	}	
	if(!regForm.birthMonth.value){
		error += "Please fill in the Month\n";		
	}
	if(!regForm.birthDate.value){
		error += "Please fill in the Day\n";		
	}
	if(!regForm.birthYear.value){
		error += "Please fill in the Year\n";		
	}
	if(regForm.accept_terms.checked == false){
		error += "Please accept the terms\n";		
	}
	
	if(error != ''){ // if there are errors
		alert(error); // alert all errors	
		canSubmit = false;
	}
	
	return canSubmit;
}


