// JavaScript Document
function checkForm(formname) {

	var form_obj = document.forms[formname];

	switch (formname) {
	
		case 'contact':
			
			email = checkString(form_obj.email.value,1);
			subject = checkString(form_obj.subject.value,0);
			message = checkString(form_obj.message.value,0);
			name = checkString(form_obj.name.value,0);
			
			if(name == '') {
				alert('Please fill out your name!'); 
				form_obj.name.focus();
				return false;
			}  else if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			} else if(subject == '') {
				alert('Please fill out a subject!'); 
				form_obj.subject.focus();
				return false;
			} else if(message == '') {
				alert('Please fill out your a message!'); 
				form_obj.message.focus();
				return false;
			}
			break;
	
		case 'event_form':
			
			email = checkString(form_obj.email.value,1);
			first_name = checkString(form_obj.first_name.value,0);
			event_date = checkString(form_obj.event_date.value,0);
			event_name = checkString(form_obj.event_name.value,0);
			last_name = checkString(form_obj.last_name.value,0);
			agent_code = checkString(form_obj.agent_code.value,0);
			attendees = checkString(form_obj.attendees.value,0);
			
			if(event_name == '') {
				alert('Please fill out the event name!'); 
				form_obj.event_name.focus();
				return false;
			} else if(event_date == '') {
				alert('Please fill out the event date!'); 
				form_obj.event_date.focus();
				return false;
			} else if(first_name == '') {
				alert('Please fill out your first name!'); 
				form_obj.first_name.focus();
				return false;
			} else if(last_name == '') {
				alert('Please fill out your last name!'); 
				form_obj.last_name.focus();
				return false;
			} else if(agent_code == '') {
				alert('Please fill out your agent code!'); 
				form_obj.agent_code.focus();
				return false;
			} else if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			} else if(attendees == '') {
				alert('Please fill out the number of attendees!'); 
				form_obj.attendees.focus();
				return false;
			}
			break;
	
		case 'claim':
			
			name = checkString(form_obj.name.value,0);
			email = checkString(form_obj.email.value,1);
			today_date = checkString(form_obj.today_date.value,0);
			agent_code = checkString(form_obj.agent_code.value,0);
			
			if(name == '') {
				alert('Please fill out your name!'); 
				form_obj.name.focus();
				return false;
			} else if(agent_code == '') {
				alert('Please fill out your agent code!'); 
				form_obj.agent_code.focus();
				return false;
			} else if(today_date == '') {
				alert('Please fill out todays date!'); 
				form_obj.today_date.focus();
				return false;
			} else if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			}
			break;
	
		case 'email_friend':
			
			yourName = checkString(form_obj.yourName.value,0);
			yourEmail = checkString(form_obj.yourEmail.value,1);
			friendsName = checkString(form_obj.friendsName.value,0);
			friendsEmail = checkString(form_obj.friendsEmail.value,1);
			
			if(yourName == '') {
				alert('Please fill out your name!'); 
				form_obj.yourName.focus();
				return false;
			} else if(yourEmail == '') {
				alert('Please fill out your email!'); 
				form_obj.yourEmail.focus();
				return false;
			} else if(friendsName == '') {
				alert('Please fill out your friends name!'); 
				form_obj.friendsName.focus();
				return false;
			} else if(!friendsEmail)  {
				alert('Please fill out your friends email!'); 
				form_obj.friendsEmail.focus();
				return false;
			}
			break;
	
		case 'registration_form':
			
			first_name = checkString(form_obj.first_name.value,0);
			last_name = checkString(form_obj.last_name.value,0);
			address1 = checkString(form_obj.address1.value,0);
			city = checkString(form_obj.city.value,0);
			state = checkString(form_obj.state.value,0);
			zip = checkString(form_obj.zip.value,0);
			phone = checkString(form_obj.phone.value,0);
			email = checkString(form_obj.email.value,1);
			agent_code = checkString(form_obj.agent_code.value,0);
			username = checkString(form_obj.username.value,0);
			password = checkString(form_obj.password.value,0);
			password2 = checkString(form_obj.password2.value,0);
			
			if(first_name == '') {
				alert('Please fill out your first name!'); 
				form_obj.first_name.focus();
				return false;
			} else if(last_name == '') {
				alert('Please fill out your last name!'); 
				form_obj.last_name.focus();
				return false;
			} else if(address1 == '') {
				alert('Please fill out your address!'); 
				form_obj.address1.focus();
				return false;
			} else if(city == '') {
				alert('Please fill out your city!'); 
				form_obj.city.focus();
				return false;
			} else if(state == '') {
				alert('Please fill out your state!'); 
				form_obj.state.focus();
				return false;
			} else if(zip == '') {
				alert('Please fill out your zip code!'); 
				form_obj.zip.focus();
				return false;
			} else if(phone == '') {
				alert('Please fill out your phone number!'); 
				form_obj.phone.focus();
				return false;
			} else if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			} else if(agent_code == '') {
				alert('Please fill out your agent code!'); 
				form_obj.agent_code.focus();
				return false;
			} else if(username == '') {
				alert('Please fill out a username!'); 
				form_obj.username.focus();
				return false;
			} else if(password == '') {
				alert('Please fill out a password!'); 
				form_obj.password.focus();
				return false;
			} else if(password2 != password) {
				alert('There is a password miss-match!'); 
				form_obj.password2.focus();
				return false;
			}
			break;
	
		case 'order_form':
			
			name = checkString(form_obj.name.value,0);
			agent_code = checkString(form_obj.agent_code.value,0);
			today_date = checkString(form_obj.today_date.value,0);
			email = checkString(form_obj.email.value,1);
			approval_code = checkString(form_obj.approval_code.value,0);
			mail_approved = checkString(form_obj.mail_approved.value,0);
			
			if(name == '') {
				alert('Please fill out your name!'); 
				form_obj.name.focus();
				return false;
			} else if(agent_code == '') {
				alert('Please fill out your agent code!'); 
				form_obj.agent_code.focus();
				return false;
			} else if(today_date == '') {
				alert('Please fill out todays date!'); 
				form_obj.today_date.focus();
				return false;
			} else if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			} else if(approval_code == '') {
				alert('Please fill out your approval code!'); 
				form_obj.approval_code.focus();
				return false;
			} else if(mail_approved == '') {
				alert('Please fill out the amount of mail approved!'); 
				form_obj.mail_approved.focus();
				return false;
			}
			break;
	
		case 'login_request':
			
			//username = checkString(form_obj.username.value,0);
			email = checkString(form_obj.email.value,1);
			
			/*if(username == '') {
				alert('Please fill out your username!'); 
				form_obj.username.focus();
				return false;
			} else */if(!email)  {
				alert('Please fill out a correct email address!'); 
				form_obj.email.focus();
				return false;
			} 
			break;
	
	}

}

function checkString(path,arrayNumber) {
	var newPath = trim(path);
	if(arrayNumber == 1) {
		if (!validate(newPath)){
			return false;
		} else {
			return newPath;	
		}
	} else {
		if(newPath.length<1) return ""; else return newPath
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function validate(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   //var address = newPath;
   if(reg.test(address) == true) {
      //alert('Invalid Email Address');
      return address;
   }
}

function birthdayCheck(formname) {
	var form_obj = document.forms[formname];
	if(form_obj.birthdate.checked== false) {
		form_obj.month.disabled = true;	
		form_obj.day.disabled = true;	
		form_obj.year.disabled = true;	
	} else {
		form_obj.month.disabled = false;	
		form_obj.day.disabled = false;	
		form_obj.year.disabled = false;		
	}
}