/*!
 * Copyright (c) 2007-2010 Bractus, Inc.
 * 10538 Eastborne Ave #102, Los Angeles, California, 90024, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Bractus ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Bractus.
 */
var signupButton;
function init(e){
	 signupButton = new YAHOO.widget.Button("signup_button");
	var oPushButton2 = new YAHOO.widget.Button("cancel_button");
	$j('#hideShowLinkReg').click( function(){$j('#FAQ_REG').toggle('blind'); });
}
/*
Check duplicate emails, if find, disables signup button.
*/
var checkDuplicate = function(event, control){

		pattern = /^([a-zA-Z0-9_\-\.])+@(([0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5])|((([a-zA-Z0-9\-])+\.)+([a-zA-Z\-])+))$/;
		if (this.value != '' && ! pattern.test(this.value)) {

			   $j("#sendEmail").html( this.value+" is not a valid email address").css("color","red");
			   $j("#email1").effect("highlight");
   			   return false;
		}
		$j('#sendEmail').html('');
		YAHOO.util.Connect.asyncRequest('GET', '?checkEmail='+this.value+'&empty=true',
                    	{success: handleEmailCheck, failure: handleFailure});


	}
var handleEmailCheck = function(o) {
			var response = o.responseText;

			if (response!=''){
				var email = Dom.get('email1');
				response = response.split("<!")[0];
				signupButton.set("disabled", true);

				$j('#sendEmail').show();

				if (response.indexOf("This")!=-1){
					response += $j("#resetPasswordB").html();
				}
				$j("#sendEmail").html( response).css("color","red");
				$j("#sendEmail").effect("highlight");

			}else{

				signupButton.set("disabled", false);

			}
};
var handleFailure = function(o) {
			//alert("Submission failed: " + o.status);
};

var handleResetSuccess = function(o) {
			var response = o.responseText;

			if (response!=''){
				alert(response);
			}
}
/*
Sends emails messasge to given email address which contains url to reset password.
*/
function sendResetPassword(){
	var email = Dom.get('email1').value;
	YAHOO.util.Connect.asyncRequest('POST', '${url}?resetPassword='+email+'&empty=true',
                    	{success: handleResetSuccess, failure: handleFailure});
    return false;
}
YAHOO.util.Event.on('email1', 'change', checkDuplicate, true);
YAHOO.util.Event.onAvailable('signup', init);

