$(document).ready(function(){


	
	$('#memberapp #email, #ileeta #email, #corporateMemb #email').blur(function(){
		$.getJSON("emailCheck.php?email=" + $('#email').val() ,   function(json){
			if(json.exists){
				alert ("The email is already taken, please choose another one.");
			}
		});
	});

	
	
	$("#renew, #memberapp, #ileeta, #conferenceSponsor, #corporateMemb, #vendor, #donate, #instructor, #conferenceSignUp").submit(function(){
		
		var message = "Please fill in all fields with *";
		
		if($('#firstName').val() == ''){
			alert(message);
			return false;
		}
		
		if($('#lastName').val() == ''){
			alert(message);
			return false;
		}

		if($('#email').val() == ''){
			alert(message);
			return false;
		}

		if($('#address').val() == ''){
			alert(message);
			return false;
		}
		
		if($('#city').val() == ''){
			alert(message);
			return false;
		}
		
		if($('#zip').val() == ''){
			alert(message);
			return false;
		}
		
		if($('#country').val() == "United States"  && $('#state').val() == "") {
			alert(message);
			return false;	
		}
		
		if($('#country').val() == "Canada"  && $('#state').val() == "") {
			alert(message);
			return false;	
		}	
		
		if($('#agency').val() == ''){
			alert(message);
			return false;
		}
		
		if($('#contact').val() == ''){
			alert(message);
			return false;
		}
		
		if( $('#dateOfBirthMonth').val() != "" &&  !isNumeric($('#dateOfBirthMonth').val())){
			alert('Date has to be numeric value');
			return false;	
		}	
		if( $('#dateOfBirthDay').val() != "" &&  !isNumeric($('#dateOfBirthDay').val())){
			alert('Date has to be numeric value');
			return false;	
		}	
		if( $('#dateOfBirthYear').val() != "" &&  !isNumeric($('#dateOfBirthYear').val())){
			alert('Date has to be numeric value');
			return false;	
		}	
		

		if( $('#gender').val() == '2' && $.trim($('#maleLetter').val()) == ''){
			alert(message);
			return false;
		}

		if(!isValidEmailAddress($('#email').val())){
			alert('Email address is not a valid one, please enter a valid address.');
			return false;
		}
	
		
		return true;
		
	});

	




	$('#conferenceSponsor1, #donate1').submit(function(){

		var message = "Please fill in all fields with *";
		if($('#product').val() == -1){
			alert('You have missed to choose your level of Sponsorship.')
			return false;
		}

		if($('#donation').val() != ''){
			if(!isNumeric($('#donation').val())){
				alert('Donation has to be a numeric value.')
				return false;
			}
		}
		
		
		if($('#value').val() != ''){
			if(!isNumeric($('#value').val())){
				alert('Value has to be a numeric value.')
				return false;
			}

		}
		if($('#value').val() == ''){
			alert('You must fill in a value.');
			return false;
		}
		
		return true;
	});

	
	$('#instructor1').submit(function(){
		var message = "Please fill in all fields with *";
		
		if($('#title').val() == ''){
			alert(message);
			return false;
		}
		if($('#outline').val() == ''){
			alert(message);
			return false;
		}
		if($('#description').val() == ''){
			alert(message);
			return false;
		}
		if($('#bio').val() == ''){
			alert(message);
			return false;
		}
		return true;
	});


	$('#corporateMemb1').submit(function(){
		var message = "Please fill in all fields with *";
		
		if($('#contact').val() == ''){
			alert(message);
			return false;
		}
		return true;
	});
	$('#corporateMemb1').submit(function(){
		var message = "Please fill in all fields with *";
		
		if($('#showSponsorInfo').attr('checked') == true && $('#contact').val() == ''){
			alert(message);
			return false;
		}
		return true;
	});

	

	$("#signed").submit(function(){
		
		if($('#signCheck').attr('checked') == false){
			alert('You must sign the values.');
			return false;
		}
	});




function isNumeric(form_value) 
{ 
    if (form_value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
} 

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}


	
	
	
});