// JavaScript Document
$(document).ready(function(){
	//register user	
	$("#registernow").click(function(){
		$("#register").fadeIn("slow");
		$("#signin").css({"display":"none"});
	});
	
	//switch back to sign in
	$(".signinnow").click(function(){
		$("#register").css({"display":"none"});
		$("#forgetpassword").css({"display":"none"});
		$("#signin").fadeIn("slow");
	});
	
	//textfield checks
	$("#remail2").blur(function() {
		//alert("bluring");								
	});
	$("#remail").focusout(function(){
		$("#emailcheck").css({"display":"visible"});
	});
	//register user
	
	$("#registerbtn").click(function(){
		//alert('press');
		if($('#terms:checked').val()){
			var tou = "TRUE";
		}else{
			var tou = "FALSE";
		}
		var fn 		= $('#firstname').val();
		var ln		= $('#lastname').val();
	  	var e1	 	= $('#remail1').val();
		var e2	 	= $('#remail2').val();
		var p1	 	= $('#rpassword1').val();
		var p2	 	= $('#rpassword2').val();
		var cty		= $('#city').val();
		var st		= $('#state').val();
		var cntry	= $('#country').val();
		var terms  	= tou;
		var errors = new Array;
		
		if(fn==""){
			errors.push("\rPlease enter your first name");
		}
		if(ln==""){
			errors.push("\rPlease enter your last name");
		}
		if((e1=="")&&(e2=="")){
			errors.push("\rPlease enter both email and confirmation email");
		}
		if( ((e1!=e2))){
			errors.push("\rYour email and confirmation email addresses do not match");
		}
		if((p1=="")&&(p2=="")){
			errors.push("\rPlease enter both password and confirmation password");
		}
		if( ((p1!=p2))){
			errors.push("\rYour password and confirmation password do not match");
		}
		/*if(cty==""){
			errors.push("\rPlease enter your city");
		}
		if(st==""){
			errors.push("\rPlease choose your state");
		}
		if(cntry==""){
			errors.push("\rPlease choose your country");
		}*/
		if(tou!="TRUE"){
			errors.push("\rYou must agree with the terms of use to continue");
		}
		if(errors.length==0){
			//proceed
		}else{
			//alert errors
			
			var aVal = "";
			$.each(errors, function(key, value) { 
				aVal += value;
			});
			/*$(".overlayerpop").fadeIn("fast");
			$("#alertpop").fadeIn("fast");
			$("#alertmessage").html(aVal); */
			alert(aVal);
			return false;
		}
		
		
		var register = 
		'fn=' + fn
		+ '&ln=' + ln
		+ '&e=' + e1 
		+ '&pw=' + p1
		+ '&cty=' +cty
		+ '&st=' +st
		+ '&cntry=' +cntry; 
		
		$.ajax({  
			url: "http://www.lifestream.tv/LIFE/register_user.php",   
         	type: "GET",  
			data: register,       
        	cache: false,  
        	//success  
            success: function (data) {
				if(data == "success"){ 
				alert("You have been registered successfully");
				$("#register").css({"display":"none"});
				$("#forgetpassword").css({"display":"none"});
				$("#signin").fadeIn("slow");
				}else{
				alert(data);
				}
			}
		});	
		
	});
	
	//forgot password
	$("#forgetpasslink").click(function(){
		$("#forgetpassword").fadeIn("slow");
		$("#signin").css({"display":"none"});
	
	});
	
	$("#forgotbtn").click(function(){
		var email = 'file='+$('#femail').val();
		$(this).css({"opacity":"0.5"});
		$(this).css({"cursor":"wait"});
		
		$.ajax({  
			url: "http://www.omnimediacast.net/getpass.php",   
         	type: "GET",  
			data: email,       
        	cache: false,  
        	//success  
            success: function (data) {   
				if(data == "success"){             
                	$("#emailsent").slideDown("slow");
					//$("#forgetprep").fadeOut("slow");
					$("#forgetprep").slideUp("slow");
					$("#forgotbtn").css({"opacity":"1"});
					$("#forgotbtn").css({"cursor":"pointer"});
				}else{
					$("#forgotbtn").css({"opacity":"1"});
					$("#forgotbtn").css({"cursor":"pointer"});
					alert('Sorry, the email address you entered is not on file. Please try again.');
				}
		 	}         
        });/**/
	 });
});//end script
