// JavaScript Document


function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13 || keycode ==3)
{
	
	login();
	
  return false;
 }
else
   return true;
}



function submitenterPop(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13 || keycode ==3)
{
	loginP();
	
  return false;
 }
else
   return true;
}




function PopTaber(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 0)
 {
	document.getElementById("passwordPop").focus();		
	
   return false;
   }
else
   return true;
   

}


function LoginBox(Load)
{
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'LoginBox',Load,LoginBoxLoader);

}




function LoginBoxLoader(Container)
{
	document.getElementById("login-container").innerHTML = Container;
	
	
}





function login()
{
	//Get Vars
	var email = document.getElementById('loginemail').value;
	var password = document.getElementById('loginPassword').value;
	
	if(email == '' || password == '' || !(checkMail(email)) )
	{
		self.location = "index.cfm?p=login";
	}
	
	else
	{
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'login',email,password,LoginDone);
	}
}





function pleaseLogin(location)
{	
		
		//Loader
		loadDash('Sorry, you must either be logged in to access this area or enter a valid login.<br />Loading login panel.<br /><br />');

		DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'loginPopup',location,loginPopup);
}




function loginPopup(container)
{
	
	//Hide Loader
	hideDash();
	
	
	//Load Form
	loadForm(container,'login');
	
	//Focus on the email field
	document.getElementById("emailPop").focus();		
}



function LoginDone(container)
{
	
	//Unloade Dash
	hideDash();
	hideForm();
	
	
	eval(container);
				
}







function displayPassword(container)
{
	//Unload Dash
	hideDash();
	
	//Load Form
	loadForm(container,'login');
}










function loginP() // used to login from the popped up div.
{

	//Get Vars
	var email = document.getElementById('emailPop').value;
	var password = document.getElementById('passwordPop').value;
	
	
	if(email == '' || password == '' || !(checkMail(email)) )
	{
		formError('Please enter a valid username/password combination.');
		
	}
	
	else
	{
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null,'login',email,password,LoginDone);
	}
}







//---------------------------------------Password - Text Conversion Trick -------------------------------------------




function swapInput()
{

	 tempInput='<input id="loginPassword" type="password" class="font-grey-small" style="width:110px;"  tabindex="2" name="loginPassword"  \ onKeyPress="return submitenter(this,event)" />';
	 
	//Swap 
	document.getElementById("loginPasswordBox").innerHTML = tempInput;
	
	//Focus
	document.getElementById("loginPassword").focus();
	
	
	
}

function loginText()
{

	//Get Current Value
	var current = document.getElementById("loginemail").value;
	
	if(current == 'Login with email')
	{
		document.getElementById("loginemail").value = '';
		document.getElementById("loginemail").className='font-grey-small';
	}
	

}




//---------------------------------------//END Password - Text Conversion Trick -------------------------------------





//------------------------------Forgot PW Code ----------------------------------------------------------------------


function showForgotPassword()
{
	//Load Dash
	loadDash('Forgot your password? No problem! Loading forgot password form.<br /><br />');
	DWREngine._execute(_ajaxConfig._cfscriptLocation,null,'forgotPassword',displayPassword);
}


function closeForgotPassword()
{
	//Unload Form
	hideForm();
}


function forgotPW(hide)
{
		
		//Vars
		var email = document.getElementById("forgotEmail").value;
		
		var valid = checkMail(email);
		
		if(!valid)
		{
			document.getElementById("showEmailMessage").style.display = 'block';
			document.getElementById("showEmailMessage").innerHTML="Please, enter a valid email address.";
		}
	
	else
	{
		
		if(hide==true)
		{
			document.getElementById("showEmailMessage").style.display = 'block';
			document.getElementById("showEmailMessage").innerHTML="Sending...";			
			
			
			DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'forgotPW',email,runJS);
		}
		
		else
		{
			document.getElementById("showEmailMessage").style.display = 'none';
		}
	}
		
}




function forgotPWCon()
{
	
	//vars
		var email = document.getElementById("forgotEmail").value;
		var VeriCode = document.getElementById("verificationCode").value;
		var Password = document.getElementById("newPassword").value;
		var Password2 = document.getElementById("confirmNewPassword").value;
	
	
	
	//Check
	if(Password != '' && Password2 != '' && VeriCode != '' && email != '')
	{
		
		if(Password == Password2)
		{
			DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'forgotPWCon',email,VeriCode,Password,runJS);
		}
		else
		{	
			document.getElementById("showEmailMessage").style.display = 'block';
			document.getElementById("showEmailMessage").innerHTML="The passwords entered do not match. Please re-enter a correct combination.";

		}
	}
	
	else
	{
			document.getElementById("showEmailMessage").style.display = 'block';
			document.getElementById("showEmailMessage").innerHTML="Please, complete the entire form.";
	}
	
	
}



//------------------------------//END Forgot PW Code ----------------------------------------------------------------------

function loadLoginOptions()
{
	DWREngine._execute(_ajaxConfig._cfscriptLocation,null,'loadLoginOptions',displayLoginOptions);
}

function displayLoginOptions(container)
{
	
	hideDash();
	loadForm(container,'optionsForm');
}






