/**********************************************************
* TFE MODULE
* Package : TFE
* Version: 1.0
* copyright 2009 Derek Lee Bronston/theConspiracy
* Author : Derek Lee Bronston dereklee@theconspiracy5.com
***********************************************************/

var TFE = {
	/**
	* This Methond hanldes retrieving content via ajax 
	*
	*/
	GetContent:function()
	{
		
	},
	
	/**
	* This Method handles toggleing divs
	*/
	ToggleMe:function(div)
	{
		$(document).ready(function(){
			//alert(div);
			$('#'+div).toggle("fast",function callback() {
				
			});
		});
	},
	
	/**
	* This Method handles the opening of a modal window, the window must be set up 
	* prior in tfe_setup.js
	*/
	OpenModalWindow:function(div)
	{
		$('#'+div).dialog('open');
	},
	
	CompleteRecipientTable:function()
	{
		var message = 'Just checking that you are sure you want to move on. If so click OK.';
		var conf = confirm(message);
		if(conf)
		{
			window.location = '/writenote/stepthree/';
		}
	},
	
	UserDeleteOrder:function(orderId)
	{
		var message = 'Are you sure you want to delete this order? It is not un-doable';
		var conf = confirm(message);
		if(conf)
		{
			//window.location = '/writenote/stepthree/';
		}
	},
	
	OpenOverlay:function()
	{
		$(function() {
			// if the function argument is given to overlay, it is assumed to be the onBeforeLoad event listener
			$("a[rel]").overlay(function() {
			
				// grab wrapper element inside content
				var wrap = this.getContent().find("div.wrap");

				// load only for the first time it is opened
				if (wrap.is(":empty")) {
					wrap.load(this.getTrigger().attr("href"));
				}
			});
		});
	},
	/**
	* Handles both login and logout of the user
	*/
	UserLogin:function()
	{
		//GET USER VALUES
		var user = $("#username").val();
		var password = $("#password").val();
		//SEND DATA	
		$.post('/myaccount/profile/user_login',{email:user,pass:password},function(data){
			if(data == 'successful login') /// SUCCESS MESSAGING, SET LOGIN BUTTON
			{
				alert('Welcome!!');
				$("#login_button").html("LOGOUT");
				$("#username").val('');
				$("#password").val('');
			}
			else //EITEHR NOT SUCCESSFUKL OR LOGOUT
			{
				if(data == 0 || data == 'bad login')
				{
					alert('Sorry no deal');	
				} 
				else//This user logged out
				{
					alert('Come back soon!');
					$("#login_button").html("LOGIN");
				}
			}
		});
	},
	
	UserRegister:function()
	{
		
	},
	
	/**
	*	This metod handles looking for a passowrd match with a users email. It emails user
	* 	their email upon success, and gives an error message upon failure. 
	*/
	ForgotPassword:function()
	{
		//SHOW LOADER
		$("#loader").html('<img src="images/ajax-loader.gif">');
		//GET EMAIL VALUE 
		userEmail = $("#email").val();
		//CHECK DB VIA CONTROLLEr
		$.post('/forgot/email_password',{email:userEmail},function(data){
			if(data == 'found')//DISPLAY PROPER MESSAGING
			{
				$("#loader").html("Please check your email.");	
			}
			else
			{
				$("#loader").html("Sorry this email address did not match any passwords in our system.");	
			}
		});
	},
	
	LoggedInAction:function(where)
	{
		$.get('/myaccount/profile/check_user_login',function(data){
			if(data == 'yes')
			{
				window.location = where;
			}
			else
			{
				alert('Sorry you need to be logged in to go there.');
			}
		});
	},
	
	DoNothing:function()
	{
		
	},
	
	GeTimeStamp:function()
	{
		var ts = Math.round(new Date().getTime()/1000);
		return ts;
	}
}
