// JavaScript Document
function load_script(filename){
	var head= document.getElementsByTagName('head')[0];
	var script= document.createElement('script');
	script.type= 'text/javascript';
	script.src= filename+'.js';
	head.appendChild(script);
}
function centering(obj_id){
	if($.browser.opera) {
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
	}else{
		windowHeight = $(window).height();
		windowWidth = $(window).width();
	};

	$pHeight = $(obj_id).height();
	$pWidth = $(obj_id).width();
	$tHeight = $(obj_id).height();
	
	projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - ($pHeight/2);
	if(projectedTop < 0) projectedTop = 0 + $tHeight;
	
	$(obj_id).css({
		'top': projectedTop,
		'left': (windowWidth/2) + $scrollPos['scrollLeft'] - ($pWidth/2)
	});

}
var $scrollPos;
var active_holder;
function overlayshow(show){
	$('#overlay').css({"width":$(window).width(), "height":$(document).height()});
	if(show)
		$('#overlay').css("display","block");
	else
		$('#overlay').css("display","none");
}
function show_overlay(){
	_resizeOverlay();
	$('#overlay').show();
}
$(window).load(function(){
	$scrollPos = _getScroll();
	$(window).scroll(function(){ $scrollPos = _getScroll(); centering(active_holder); });
	$(window).resize(function(){ _resizeOverlay(); $scrollPos = _getScroll(); centering(active_holder); });
});
function _getScroll(){
	if (self.pageYOffset) {
		scrollTop = self.pageYOffset;
		scrollLeft = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;	
	}else{
		scrollTop = 0;
		scrollLeft = 0;
	}
	
	return {scrollTop:scrollTop,scrollLeft:scrollLeft};
};

function _resizeOverlay() {
	$('#overlay').css({
		'height':$(document).height(),
		'width':$(window).width()
	});
};

$(document).ready(function(){
    maxWidth = 130;
    minWidth = 55;	

    $("ul#cols li div.point").hover(
      function(){
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
      },
      function(){
	  	$(this).animate({width: minWidth+"px"}, { queue:false, duration:400 });
      }
    );

    $("#header_menu li.parent").hover(
      function(){
		$(this).toggleClass('mover');
		$(this).children('#submenu').show(50);
      },
      function(){
		$(this).toggleClass('mover');
		$(this).children('#submenu').hide(50);
      }
    );
});

function today_date(){
	var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

	var monthNames = new Array("January","February","March","April","May","June","July",
							   "August","September","October","November","December");
	
	var dt = new Date();
	var y  = dt.getYear();
	
	// Y2K compliant
	if (y < 1000) y +=1900;
	D = dt.getDate();
	th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';

	cur_date = (dayNames[dt.getDay()] + ", " + monthNames[dt.getMonth()] + " " + D + th + ", " + y);

	$('#span_date').html(cur_date);
}

function timeclock(){
	document.clock_form.Action.disabled=true;
	formdata = $('#clock_form').serialize();
	$.post('timeclock_employee.html?mode=punch', formdata, function(data){
		$('#timeclock').html(data);
	});
	return false;
}
function timecard(){
	formdata = $('#card_form').serialize();
	$.post('timeclock_employee.html?mode=timecard', formdata, function(data){
		$('#timeclock').html(data);
	});
	return false;
}
function goto_sl(){
	window.location.href = "https://www.shutterlending.com/?af="+afid;
	return false;
}
function ps_log(){
	$('#info_loader').show();
	active_holder = '#testing_';
	show_overlay();
	$('#info_text').hide();
	centering(active_holder);
	$('#testing_').show();

	formdata = $("#login_form").serialize();
	$.post('paystub_login.html?ajx=1', formdata, function(data){
		if(data.indexOf("window.location.href") != -1){
			$('#info_text').html("you will now be redirected to ShutterLending.com ....");
			$('#info_text').show();
			centering(active_holder);
		}else{
			$('#testing_').hide();
			overlayshow(false);
		}
		eval(data);
	});
	return false;
}
function check_start(){
	error = '';
	employer_id = $('#employer_id').val();
	employee_id = $('#employee_id').val();
	employee_zip = $('#employee_zip').val();
	
	if(employer_id == '')
		error += 'Employer ID - Entry needed.\n';
	else if(!employer_id.toUpperCase().match(/[A-Z]{4}/))
		error += 'Employer ID - Incorrect format. (4 characters)\n';
	else if(employer_id.length != 4)
		error += 'Employer ID - Incorrect format. (4 characters)\n';

	if(employee_id == '')
		error += 'Employee ID - Entry needed.\n';
	else if(!employee_id.match(/[0-9]{9}/))
		error += 'Employee ID - Incorrect format. (9 digits)\n';
	else if(employee_id.length != 9)
		error += 'Employee ID - Incorrect format. (9 digits)\n';
	
	if(employee_zip == '')
		error += 'Employee Zip - Entry needed.\n';
	else if(!employee_zip.match(/[0-9]{5}/))
		error += 'Employee Zip - Incorrect format. (5 digits)\n';
	else if(employee_zip.length != 5)
		error += 'Employee Zip - Incorrect format. (5 digits)\n';

	if(!($('#agree').is(':checked')))
		error += 'Wage Assignment Policy - Check it to continue.\n';

	if(error == ''){
		$('#info_loader').show();
		active_holder = '#testing_';
		$('#info_text').hide();
		show_overlay();
		centering(active_holder);
		$('#testing_').show();

		formdata = $("#reg_form").serialize();
		$.post('paystub_register.html?ajx=1', formdata, function(data){
			if(data.indexOf("window.location.href") != -1){
				$('#info_text').html("you will now be redirected to ShutterLending.com ....");
				$('#info_text').show();
				centering(active_holder);
			}else{
				$('#testing_').hide();
				overlayshow(false);
			}
			eval(data);
		});
	}else{
		alert('There are some errors:\n'+error);
	}
	return false;
}
