// JavaScript Document
/*$(function() { 
   //为页面中所有拥有rel属性的button元素绑定overlay效果
    $("button[rel]").overlay({
							   expose: {    //启用expose效果
            color: '#BAD0DB',       //expose颜色
            opacity: 0.7,            //expose透明度
            closeSpeed: 1000     //expose关闭速度
        },
        finish: {top: 'center'} ,   //设置消失方向
		closeOnClick: false					
		});
	    
	
}).load();*/

$(function(){ 
		var $first_div = $('#first_div'); 
		var $loading = $('#loading'); 
		var $finish = $('#finish');
		var $errorinfor = $('#errorinfor'); 
		
		var $retrieve = $('#retrieve');             
		$retrieve.click(function(){

				var csrf = $('input[name=YII_CSRF_TOKEN]').attr("value");
				var username_email = $('#username_email').val();
				var captcha 	= $('#captcha').val();
			
			    $('#first_div').hide();
				$('#loading').show();
				
				email_retrieve_by_ajax( csrf, username_email, captcha );
				return false;
							      	
		});	
		$(document).keypress(function(e){
                     if(e.keyCode == '13') {
                          //doRetrieve()
                     }
              });
		
});
function  relode(){
	
	window.location.reload();
};

/////////////////////////////////////// ajax
function email_retrieve_by_ajax( csrf, username_email, captcha )
{
		var url_http = ('https:' == document.location.protocol ? 'https://' : 'http://');//alex modified
		//url_http = "http://";
	$.ajax(
	{
		url: 			url_http + window.location.host + '/passport/ajax/retrieve',
		data: 			{'username_email' : username_email, 'captcha' : captcha, 'YII_CSRF_TOKEN' : csrf },
		dataType: 		'json',
		type: 			'post',
		
		beforeSend: function( XMLHttpRequest )
		{
		},
		success: function ( data )
		{	
			if ( data.result == "OK" )
			{
				$('#infotext').html( data.message + "<br/>Email: " + data.email );
				$('#finish').show();
				$('#loading').hide();
			}
			else
			{
				$('#errortext').html( data.message );
				$('#errorinfor').show();
				$('#loading').hide();
			}
		},
		error: function ( XMLHttpRequest, textStatus, errorThrown )
		{
			$('#errortext').html( 'Ajax Failed: '+textStatus );
			$('#errorinfor').show();
			$('#loading').hide();
		},
		complete: function(XMLHttpRequest, textStatus)
		{
		/*
			if ( textStatus == "error" )
			{
				$('#errortext').html( 'Ajax Failed!' );
				$('#errorinfor').show();
				$('#loading').hide();
			}
		*/
		}
	});
}
