
/* IE only */
/*
DD_roundies.addRule('.cnt80,.cnt20,.cp-alert', '4px', true);
DD_roundies.addRule('.first-level-tab li', '4px 4px 0 0', true);
DD_roundies.addRule('.cont-border', '0 4px 4px 4px', true);
*/

var currentPage;	

$(function(){
	$('#conectare input:first').focus();
	$('#conectare li.alt').addClass('check');
	
	//  pentru checkboxu frumos
	$('.check').click(function(e){
		e.stopImmediatePropagation();
		if (e.target.nodeName != "A") {
			if ($(this).find('label').hasClass('checked')) {
				$(this).find('label').removeClass('checked');
				$(this).find('input').removeAttr('checked');
			}
			else {
				$(this).find('label').addClass('checked');
				$(this).find('input').attr('checked', 'checked');
			}
		}
		if(e.target.nodeName == "LABEL" || e.target.nodeName == "INPUT")
			return false;
	});
		

	$('body').everyTime(100, 'timer', function(i) {
		historycheck();
	});	
})

function historycheck()
{
	var section = document.location.href.split('#')[1];
	
	if (section == "/forgot-password/")	{		
		show_forgot_password_tab();
	}else if(section == "/notice/password_change_ok/"){
		show_password_change_ok_tab();
	}else if(section == "/notice/password_change_bad/"){
		show_password_change_bad_tab();
	}else if(section == "/notice/email_confirm_ok/"){
		show_email_confirm_ok();
	}else if(section == "/notice/email_confirm_bad/"){
		show_email_confirm_bad();	
	}else if(section == "/error/"){
		show_error();
	}else{
		if( $('.termeni').size() == 0 )
			hide_modal();
	}
}

function hide_modal(){
	$.modal.close();
}


/*
	Show error if username or password is not correct.
*/
function show_error(){
	if ($("#error_tab").css('display') == 'none') {
		$('#error_tab').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#ok";
			}
			
			
		});
	} 
}

function show_forgot_password_tab(){
	if ($("#recuperare").css('display') == 'none') {
		$('#recuperare').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#";
			}
			
			
		});
		$('#recuperare').find('input:first').focus();
		
		/*
		 * Validate the forgot password form
		 */
		$("#forgot-password-form").validate({
	   		errorElement: "span",
	   		errorClass: "err",
	   		submitHandler: function(form) {
				$("#forgot-password-form span.err").remove();
			   	$(form).ajaxSubmit(function(data){
					if(data=="BAD"){
						$('<span class="err">Adresa e-mail introdusă nu se regăseşte în baza noastră de date.</span>').insertAfter("#r_mail");
					}else{
						$("#recuperare").empty();
						$('<h3>&#350;I ADVERTISERII MAI UIT&#258;</h3><p style="margin-top:80px;">Acum c&#259; ne-ai spus adresa pentru care &#355;i-ai uitat parola, &icirc;&#355;i vom trimite imediat un e-mail cu un link pentru generarea unei parole noi.</p>').appendTo($("#recuperare"));
					}
				});
	   		},
			invalidHandler: function(form, validator) {
	      		var errors = validator.numberOfInvalids();
			},
			rules: {
			    r_mail: { 
			    	required: true,
					email: true
			   	}
	  		},
			messages: {
			    r_mail: {
					required: "Te rog introdu adresa de e-mail cu care te-ai înregistrat.",
					email: "Adresa introdusă de tine nu pare să fie validă. Mai încearcă odată."
					}
			},
			errorPlacement: function(error, element) {
				$(error).appendTo(element.parent());
			}	
			
		});
		
	}
}


function show_password_change_ok_tab(){
	if ($("#recuperare_ok").css('display') == 'none') {
		$('#recuperare_ok').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#ok";
			}
			
			
		});
	}
}
function show_password_change_bad_tab(){
	if ($("#recuperare_bad").css('display') == 'none') {
		$('#recuperare_bad').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#ok";
			}
			
			
		});
	}
}


function show_email_confirm_ok(){
	if ($("#email_confirm_ok").css('display') == 'none') {
		$('#email_confirm_ok').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#ok";
			}
			
			
		});
	}
}

function show_email_confirm_bad(){
	if ($("#email_confirm_bad").css('display') == 'none') {
		$('#email_confirm_bad').modal({
			closeHTML: ('<a class="modal_inchide" href="#" title="&Icirc;nchide (ESC)"></a>'),
			opacity: 87,
			overlayCss: {
				opacity: .87,
				background: 'url(assets/img/overlay.png)'
			},
			containerCss: {
				width: 479,
				height: 279,
				padding: '0',
				backgroundColor: 'transparent'
			},
			onClose: function(){
				document.location.href="#ok";
			}
			
			
		});
	}
}