var Signup = function()
{
//privat

	var SaveCallback = function(response, status)
	{  
        	Util.StopWaiting();
    		
	if ((jQuery.trim(response) == "OK") || (jQuery.trim(response).substring(0, 12) == "FAILURE: FTP"))
	{	
		if (jQuery.trim(response).substring(0, 12) == "FAILURE: FTP")
			{
				alert("Photo upload failed. We upload later");
			}
           	 display_popup("Your profile has been saved.");
		

            	if  (this.next == "exitlink") {
                	document.location.href = '/mybottlenotes'
               		 return 0;
           		 }
			if (this.next)
			{
				Usermanage.Redirect("profile");
			}
			else
			{
				Usermanage.Redirect("tryRedirect");
			}
		

		if((jQuery("#profileTab #twitterid").val() != "") && (jQuery("#profileTab #twitterpublishind")[0].checked == true))
			{
				signUp4tweets(jQuery("#profileTab #twitterid").val());
				
			}	
	
		}
		else
		{
			if (jQuery.trim(response) == "FAILURE: DUPLICATE EMAIL")
			{
				alert("Sorry, this email is already in use. Please, choose another one");
				return;
			}
			if (jQuery.trim(response) == "FAILURE: DUPLICATE USERNAME")
			{
				alert("Sorry, this username is already in use. Please, choose another one");
				return;
			}
			if (jQuery.trim(response) == "FAILURE: DUPLICATE TWITTER ID")
			{
				alert("Sorry, this twitter id  is already  in use. Please choose another one.");
				jQuery("#profileTab #twitterid").focus();
				return;
			}

			if (this.next)
			{
				alert("Save failure");
			}
			else
			{
				if (confirm("Save failure, continue?"))
				{
					Usermanage.Redirect();
				}
			}
		}
	};

//public
return {
	ToTab: function()
	{
		alert("Sigin first");
		return;
	},
    
    sande: function(){
//  alert("data");
      this.Next("exitlink");
//      display_popup("Your profile has been saved.");  
    },

	Next: function(next)
	{ 
	 	if (!is21year(jQuery("#profileTab #year").val(),jQuery("#profileTab #month").val()-1,jQuery("#profileTab #day").val()))
		{
			alert("You must be 21 years old to register at Bottlenotes");
			return;
		}
		if (next == undefined)
		{
			next = true;
		}

		if (Usermanage.ValidateFields(1) == false)
		{
			return;
		}
				

		if (jQuery.trim(jQuery("#profileTab #pass1").val()) != jQuery.trim(jQuery("#profileTab #pass2").val()))
		{
			alert("Password information doesn't match. Try again please");
			jQuery("#profileTab #pass2").focus();
			return;
		}
       
	
		var data = "ajax=true&request=11&"
			+ Usermanage.GetAddress("#profileTab")
			+ "&month=" + jQuery("#profileTab #month").val()
			+ "&day=" + jQuery("#profileTab #day").val()
			+ "&year=" + jQuery("#profileTab #year").val()
			+ "&sex=" + jQuery("#profileTab #sex").val()
			+ "&username=" + jQuery.trim(jQuery("#profileTab #username").val())
			+ "&email=" + jQuery.trim(jQuery("#profileTab #email").val())
			+ "&pass1=" + jQuery.trim(jQuery("#profileTab #pass1").val())
			+ "&photo=" + jQuery("#profileTab #photo").attr("photo")
			+ "&optPrivacy=" + jQuery("#profileTab #optPrivacy")[0].checked
			+ "&dailysipopt=" + jQuery("#profileTab #dailysipopt")[0].checked
			+  "&twitterpublishind=" + jQuery("#profileTab #twitterpublishind")[0].checked
			+ "&twitterid=" + jQuery("#profileTab #twitterid").val()
			+ "&display_name=" + jQuery.trim(jQuery("#profileTab input[name='display_name']:checked").val())
			+"&website="+ $.trim($("#website").val())
			+"&facebookid="+ $.trim($("#facebookid").val())
			+"&publicprofile="+ jQuery("#publicprofile")[0].checked
                        +"&is_generic="+ jQuery("#is_generic").val()
			+ "&source=" + jQuery("#profileTab #source").val()
			;
 

		jQuery.ajax(
		{
			url: "/sign-up",
			type: "post",
			data: data,
            beforeSend: Util.StartWaiting,
			numTab: 2,
			next: next,
			success: SaveCallback
		});
	}
};
}();


	function signUp4tweets(twitterId)
	{
		jQuery.ajax({
                                    url: "/signUp/twit",
                                    type: "POST",
                                    data: "ajax=true&twitterid=" + twitterId ,
                                    success:  function(response,status)
					{	
					if(jQuery.trim(response) == 0)
					   {
						window.open("/reg/twit","Twitter","width=650,height=500,resizable=yes,scrollbars=yes,toolbar=yes,location=yes, status=yes,directories=yes,menubar=yes");     	  
					   }
																   
					}
					

                    });
	
	}






