﻿$(document).ready(function() {
	var link = $('.li_link');
	var ol = $('#li_overlay');
	var win = $('#li_window');
	var hdr = $('#li_header');
	var rwin = $('#reset_window');
	var c = $('#cancel');
	var rc = $('#r_cancel');
	var elogout = 'http://www.aecci.com/scripts/elogout.php';
	var li_winWidth = $('#li_window').width();
	var li_winHeight = $('#li_window').height();
	var li_hdrWidth = $('#li_header').width();
	var li_hdrHeight = $('#li_header').height();
	var reset_winHeight = $('#reset_window').height();
	var reset_winWidth = $('#reset_window').width();
	var docH = $(document).height();
	var url = location.hostname;
		if (url = 'localhost') {
			url = 'localhost/mysite';
		};
	$('#li_overlay').css('height', docH);

	var hide = function(){
		$(win).hide("slide", { direction: "up" }, 1000, function(){
			$(hdr).fadeOut(200, function(){
				$(ol).fadeOut(1000);
			});
		});
		$('#eerror').html('');
	};
	
	$(link).click(function(evt){
		evt.preventDefault();
		$(ol).fadeTo(1, .60).fadeIn(500, function(){
			$(hdr).fadeIn(900, function() {
			$(win).show("slide", { direction: "up" }, 1000);
			});
		});
  		var de = document.documentElement;
		var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
		$("#li_window").css({
			left: (w - li_winWidth)/2 + 'px' ,
			top: ((h - li_winHeight)/2)-92 + 'px'
		});
		$("#li_header").css({
			left: (w - li_hdrWidth)/2 + 'px' ,
			top: ((h - li_hdrHeight)/2)-173 + 'px'
		});
	}); //end click
	$('#login').submit(function(sbmit) {
		sbmit.preventDefault();
		var url = location.hostname;
		if (url = 'localhost') {
			url = 'localhost/mysite';
		};
		var lidata = $(this).serialize();
		$.post('http://www.aecci.com/scripts/jslogin.php', lidata, processdata);
		function processdata(data) {
			if (data == 'li0') {
				hide();
				$.cookie('login', 'employee', { path: '/' });
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'li1') {
				hide();
				$.cookie('login', 'employee');
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'li2') {
				hide();
				$.cookie('login', 'employee');
				location = 'http://www.aecci.com/employee/employee_home.php';			
			} else if (data == 'li3') {
				hide();
				$.cookie('login', 'employee');
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'f') {
				$('#eerror').html('Incorrect login information.  Please try again.');
			} else if (data == 'b') {
				$('#eerror').html('You must enter a username & password.');
			} else if (data == 'u') {
				$('#eerror').html('You must enter a username.');
			} else if (data == 'p') {
				$('#eerror').html('You must enter a password.');
			} else if (data == 'r') {
				$(win).hide("slide", { direction: "up" }, 1000, function() {
					$(rwin).show("slide", { direction: "up" }, 1000);
				}); //end reset password transition
				var de = document.documentElement;
				var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
				var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
				$('#reset_window').css({
					left: (w - reset_winWidth)/2 + 'px' ,
					top: ((h - reset_winHeight)/2)-92 + 'px'
				}); //end reset_window position 
			} //end password reset if
		} //end processdata
	}); //end submit
	$('#reset').submit(function(sbmit) {
		sbmit.preventDefault();
		var un = $('#username').val();
		var p = $('#password').val();
		var np = $('#npi').val();
		var cp = $('#cpi').val();
		var rdata = {
			user_name: un,
			pass: p,
			new_pass: np,
			confirm_pass: cp
		}
		$.post('http://www.aecci.com/scripts/js_rlogin.php', rdata, processrdata);
		function processrdata(data) {
			if (data == 'li0') {
				hide();
				$.cookie('login', 'employee');
				$.cookie('pr', 'true');
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'li1') {
				hide();
				$.cookie('login', 'employee');
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'li2') {
				hide();
				$.cookie('login', 'employee');
				location = 'http://www.aecci.com/employee/employee_home.php';
			} else if (data == 'e') {
				$('#r_eerror').html('You must enter your new password.');
			} else if (data == 'x') {
				$('#r_eerror').html('The two passwords do not match.');
			}
		} //end processdata
	}); //end reset submit
	$(c).click(hide);
	$(rc).click(hide);
	$(ol).click(hide);
	$('#elogout').click(function() {
		var lo_data = '';
		$.post(elogout, lo_data, process_LOData);
		function process_LOData(data) {
			if (data == 'lo') {
				$.cookie('login', null, { path: '/', expires: -1 });
				$.cookie('intro_cookie', null, { path: '/', expires: -1 });
				location = 'http://www.aecci.com';
			};
		};
	});
}); //end ready