var totalTickerWidth = 0;

function ToggleLogin() {
    if (document.getElementById('login').style.display == 'none') {
    	document.getElementById('login').style.display = '';
    } else {
    	document.getElementById('login').style.display = '';
    }
}

function clearSpot(val, def) {
    if (document.getElementById(val).value == def) {
    	document.getElementById(val).value = '';
    }
}

function checkSpot(val, def) {
    if (document.getElementById(val).value == '') {
    	document.getElementById(val).value = def;
    }
}

var requiredString = 'user,pass';

function checkSubmit() {
    rSarray = requiredString.split(',');
    for(i = 0; i < rSarray.length; i++) {
    	if (document.getElementById(rSarray[i]).value == '') {
    		alert('Please make sure all of the required fields have valid information and try again.');
    		return false;
    	}
    }
    return true;
}

function TogglePass() {
    Element.hide('passShow');
    Element.show('pass');
    $('pass').focus();
}

function TogglePassBack() {
    if ($('pass').value == '') {
    	Element.show('passShow');
    	Element.hide('pass');
    }
}

function ToggleForgotPass() {
    if ($('forgotPassword').style.display == 'none') {
    	new Effect.Appear('forgotPassword');
    } else {
    	new Effect.Fade('forgotPassword');
    }
}

var resCheckForgotPass = function(t) {
    //alert(t.responseText); //return;
    if (t.responseText.substr(0, 5) == 'Error') {
    	alert(t.responseText); 
    	return;
    } else {
    	$('emailForgot').value = '';
    	aType = 'succe'; alert('You\'re password has been reset and your login information is being sent to you.  Please allow up to 5 minutes for it to be delivered.  If you haven\'t received it after that time please contact us at support@lovetheaction.com');
    	ToggleForgotPass();
    }
}

function checkForgotPass() {
    var em = $('emailForgot').value;
    if (em != '') {
    	var sendVals = 'em='+escape(em);
    	new Ajax.Request('/js/ajax/fPassword.ajax.php', {method:'post', postBody:sendVals, onComplete:resCheckForgotPass});
    } else {
    	aType = 'error'; alert('Error: Please make sure you enter your email address into the field before pressing Submit, and try again.');
    }
    return false;
}

var resCheckUsername = function(t) {
    //alert(t.responseText); return;
    if (t.responseText.substr(0, 5) == 'Error') {
    	alert(t.responseText); return;
    } else {
    	if (t.responseText == 1) {
    		$('username').value = '';
    		$('username').focus();
    		alert('Sorry but that username is not available.  Please try again, remember usernames can only be made up of letters and numbers.');
    	}
    }
}

function checkUsername() {
    if (($('username').value != '') && ($('username').value != 'Username?')) {
    	var sendVals = '&us='+escape($('username').value);
    	new Ajax.Request('/js/ajax/checkUsername.php', {method:'post', postBody:sendVals, onComplete:resCheckUsername});
    }
}

var resSignUp = function(t) {
    if (escape(t.responseText).substr(3, 5) == 'Error') {
    	alert(t.responseText); 
    	refreshCaptcha();
    	return;
    } else {
    	$('nameFirst').value = '';
    	$('nameLast').value = '';
    	$('email').value = '';
    	$('username').value = '';
    	$('zip').value = '';
    	signup();
    	alert('You have signed up and should receive an email in the next 5-10 minutes.  If you don\'t please use the contact form to let us know and we will help get you verified.');
    }
}

function refreshCaptcha() {
    Recaptcha.reload();
    $('recaptcha_response_field').value = '';
}

function checkSubmitSU() {
	signUpNow();
	return false;
}

function signUpNow() {
    var nf = $('nameFirst').value;
    var nl = $('nameLast').value;
    var em = $('email').value;
    var us = $('username').value;
    var zi = $('zip').value;
    if ((nf != '') && (nl != '') && (em != '') && (us != '') && (zi != '')) {
    	if (Recaptcha.get_response() != '') {
    		var sendVals = 'nf='+escape(nf)+'&nl='+escape(nl)+'&em='+escape(em)+'&us='+escape(us)+'&zi='+escape(zi)+'&recaptcha_challenge_field='+escape(Recaptcha.get_challenge())+'&recaptcha_response_field='+escape(Recaptcha.get_response());
    		new Ajax.Request('/classes/fpSignUp.php', {method:'post', postBody:sendVals, onComplete:resSignUp});
    	}
    } else {
    	alert('Error: Please make sure you enter information into all of the required fields, and try again.');
    }
}
