$(document).ready(function(){

	var pos = $('#whyChooseAnchor').offset();
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) var moveLeft = '1105px'
	else var moveLeft = '765px';
	$('#secureImgs').css( {"top":(pos.top-64) + "px", "left":moveLeft } ).fadeIn('slow');
		
	$('#form_step_1').fadeIn('slow');
	$('#continue_step_2').click(function() {
		valid = 1;
		errmsg = 'Please fix the following errors before you continue:';
		$('.step_one').each(function() {
			if(
				$(this).val() == '' || 
$('i_'+$(this).attr('name')).attr('src') == '/resource/images/none.png' ||
				$('i_'+$(this).attr('name')).attr('src') == '/resource/images/false.png' ||
				($(this).hasClass('ssn1') && $(this).val().length != 2) ||
				($(this).hasClass('phone1') && $(this).val().length != 3) ||
				($(this).hasClass('phone2')  && $(this).val().length != 4)
			) {	
				errmsg = errmsg + '\n- ' + $(this).attr('title');
				valid = 2;
			}
		});
		if(
			$('input[name=PRI_PHONE_0]').val() == '000' &&
			$('input[name=PRI_PHONE_1]').val() == '000' &&
			$('input[name=PRI_PHONE_2]').val() == '0000'
		)
		{	
				errmsg = errmsg + '\n- Home phone cannot be 000-000-0000';
				valid = 2;
		}
		if(
			$('input[name=WORK_PHONE_0]').val() == '000' &&
			$('input[name=WORK_PHONE_1]').val() == '000' &&
			$('input[name=WORK_PHONE_2]').val() == '0000'
		)
		{	
				errmsg = errmsg + '\n- Work phone cannot be 000-000-0000';
				valid = 2;
		}
		if(valid == 1)
		{
			$('#form_step_1').hide();
			$('#form_step_2').fadeIn('slow');
		}
		else
		{
			alert(errmsg);
		}
		
	});
	$('#back_step_1').click(function() {
		$('#form_step_2').hide();
		$('#form_step_1').fadeIn('slow');
	});
	$('#myform1').submit(function() {
		valid = 1;
		errmsg = 'Please fix the following errors before you continue:';
		$('.step_two').each(function() {
			if(
				$(this).val() == '' || 
$('i_'+$(this).attr('name')).attr('src') == '/resource/images/none.png' ||
				$('i_'+$(this).attr('name')).attr('src') == '/resource/images/false.png' ||
				($(this).hasClass('ssn1') && $(this).val().length != 2) ||
				($(this).hasClass('phone1') && $(this).val().length != 3) ||
				($(this).hasClass('phone2')  && $(this).val().length != 4)
			   )
			{	
				errmsg = errmsg + '\n- ' + $(this).attr('title');
				valid = 2;
			}
		});
		if(parseInt($('#paydayOne :selected').attr('title')) >= parseInt($('#paydayTwo :selected').attr('title')))
		{
			errmsg = errmsg + '\n- Your second payday cannot occur before your first payday.';
			valid = 2;
		}
		if(valid == 1)
		{
			return true;
		}
		else
		{
			alert(errmsg);
			return false;
		}
	});
	if(session != '')
	{
		$('a').each(function(){
			var href= $(this).attr('href');
			pattern =/\?/;
			ind = href.match(pattern);
			if(ind != null)
			{
				$(this).attr('href',href+'&sess='+session);
			}
			else 
			{
				$(this).attr('href',href+'?sess='+session);
			}
		});
		/*$('form').each(function(){
			if($(this).attr('id') != 'myform1')
			{
				var action= $(this).attr('action');
				ind = action.match("?=");
				if(ind != null)
				{
					$(this).attr('action',action+'&sess='+session);
				}
				else 
				{
					$(this).attr('action',action+'?sess='+session);
				}

			}
		});*/
	}
	
});