// JavaScript Document

function element_fade_opacity(element,to,rate,callback){
	
	// ie sucks so only make it fancy if it is another browser
	
	if(!document.all){

		$('#'+element).animate( {opacity: to},rate, function(){ eval(callback); } );
		
	}

}

function validate_signup(){
	
	// ie sucks so only make it fancy if it is another browser
	
	if(!document.all){
	
		$('#error_signup_f_name').css({"display": "block"});
		$('#error_signup_l_name').css({"display": "block"});
		$('#error_signup_email').css({"display": "block"});
		
		element_fade_opacity('error_signup_f_name',0,1,null);
		element_fade_opacity('error_signup_l_name',0,1,null);
		element_fade_opacity('error_signup_email',0,1,null);
		
	}

	var form_valid = true;

	if(!document.getElementById('signup_f_name').value){
		
		if(!document.all){
	
			element_fade_opacity('error_signup_f_name',100,1000,null);
			
		} else {
			
			alert("First name is required!");
			
		}
		
		form_valid = false;
	
	}
	
	if(!document.getElementById('signup_l_name').value){
		
		if(!document.all){
			
			element_fade_opacity('error_signup_l_name',100,1000,null);
		
		} else {
			
			alert("Last name is required!");
			
		}
		
		form_valid = false;
	
	}
	
	if(!valid_email('signup_email')){
		
		if(!document.all){
			
			element_fade_opacity('error_signup_email',100,1000,null);
		
		} else {
			
			alert("Email name is invalid!");
			
		}
		
		form_valid = false;
	
	}
	
	if(!form_valid){
	
		return false;
		
	}

}

function validate_login(){
	
	// ie sucks so only make it fancy if it is another browser
	
	if(!document.all){
	
		$('#error_login_username').css({"display": "block"});
		$('#error_login_password').css({"display": "block"});
		
		element_fade_opacity('error_login_username',0,1,null);
		element_fade_opacity('error_login_password',0,1,null);
		
	}

	var form_valid = true;

	if((!document.getElementById('username').value) || (document.getElementById('username').value == 'USERNAME')){
	
		if(!document.all){
			
			element_fade_opacity('error_login_username',100,1000,null);
			
		} else {
			
			alert("Username is invalid!");
			
		}
		
		form_valid = false;
	
	}
	
	if((!document.getElementById('password').value) || (document.getElementById('password').value == 'PASSWORD')){
		
		if(!document.all){
			
			element_fade_opacity('error_login_password',100,1000,null);
			
		} else {
			
			alert("Password is invalid!");
			
		}
		
		form_valid = false;
	
	}
	
	if(!form_valid){
	
		return false;
		
	}

}

function valid_email(element){

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.getElementById(element).value;
   
	if(reg.test(address) == false) {
   		
		return false;
	  
	} else {
   
		return true;
   
	}
   
}
