// JavaScript Document

	$(document).ready(function() {
							   
		$('#sysreq, #registerbut, #downfree').fancybox({
			'padding'			: 0,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'overlayColor'		: '#000',
			'overlayOpacity'	: '0.8',
			'titleShow'			: false,
			'centerOnScroll'	: true,
			'onComplete'		: function(){$(document).unbind('keydown.fb');}
		});
		
		$('#pass, #passr').focus(function(){
			$(this).removeClass('pass');
		});
			
		$('#pass, #passr').blur(function(){
			if($(this).val()=='') $(this).addClass('pass');
		});
		
		$('#passrr').focus(function(){
			$(this).removeClass('passre');
		});
			
		$('#passrr').blur(function(){
			if($(this).val()=='') $(this).addClass('passre');
		});
		
		$('#login-but-ch').click(function() {
			var img = '<img src="images/ajax-loader.gif" alt="" />';
			var email = $('input#email').val();
			var pass = $('input#pass').val();
			$('#inline-login .loadingimg').html(img);
			$.post('actions/login.php', {em:email,pa:pass}, function(data){
				if(data.err=="0"){
					window.location.href = data.url; 
				}
				else {
					$("#inline-login .loadingimg").html(data.errtxt);
				}
			}, "json");
		});
		
		$('#email, #pass').keypress(function(e) {
			if(e.keyCode == 13) {
				var img = '<img src="images/ajax-loader.gif" alt="" />';
				var email = $('input#email').val();
				var pass = $('input#pass').val();
				$('#inline-login .loadingimg').html(img);
				$.post('actions/login.php', {em:email,pa:pass}, function(data){
					if(data.err=="0"){
						window.location.href = data.url; 
					}
					else {
						$("#inline-login .loadingimg").html(data.errtxt);
					}
				}, "json");
				return false;
			}
		});
		
		$('#account').click(function() {
			if($(this).attr("checked")) {
				$('.rpass').hide();
				$('#register-but-ch').html('Login');
			}
			else {
				$('.rpass').show();
				$('#register-but-ch').html('Register');
			}
		});
		
		$('#register-but-ch').click(function() {
			var img = '<img src="images/ajax-loader.gif" alt="" />';
			var email = $('input#emailr').val();
			var pass = $('input#passr').val();
			var passr = $('input#passrr').val();
			var check = $('input#account').attr("checked");
			if(check) {
				$("#inline-register .loadingimg").html(img);
				$.post('actions/login2.php', {em:email,pa:pass}, function(data){
					if(data.err=="0"){
						$("#inline-register .loadingimg").html("<font color='green'>Your account has been successfully verified!</font>");
						window.location.href = "http://www.comodo.com/home/data-storage-encryption/online-storage-thank-you.php"; 
					}
					else {
						$("#inline-register .loadingimg").html(data.errtxt);
					}
				}, "json");
			}
			else {
				$("#inline-register .reg").html(img);
				$.post('actions/register.php', {em:email,pa:pass,repa:passr}, function(data){
					if(data.err=="0"){
						$("#inline-register .loadingimg").html("<font color='green'>Your account has been successfully created!</font>");
						window.location.href = data.url;
					}
					else {
						$("#inline-register .loadingimg").html(data.errtxt);
					}
				}, "json");
			}
		});
		
		$('#emailr, #passr, #passrr').keypress(function(e) {
			if(e.keyCode == 13) {
				var img = '<img src="images/ajax-loader.gif" alt="" />';
				var email = $('input#emailr').val();
				var pass = $('input#passr').val();
				var passr = $('input#passrr').val();
				var check = $('input#account').attr("checked");
				if(check) {
					$("#inline-register .loadingimg").html(img);
					$.post('actions/login2.php', {em:email,pa:pass}, function(data){
						if(data.err=="0"){
							$("#inline-register .loadingimg").html("<font color='green'>Your account has been successfully verified!</font>");
							window.location.href = "http://www.comodo.com/home/data-storage-encryption/online-storage-thank-you.php"; 
						}
						else {
							$("#inline-register .loadingimg").html(data.errtxt);
						}
					}, "json");
				}
				else {
					$("#inline-register .reg").html(img);
					$.post('actions/register.php', {em:email,pa:pass,repa:passr}, function(data){
						if(data.err=="0"){
							$("#inline-register .loadingimg").html("<font color='green'>Your account has been successfully created!</font>");
							window.location.href = data.url;
						}
						else {
							$("#inline-register .loadingimg").html(data.errtxt);
						}
					}, "json");
				}
			}
		});

	});
	
