var acon_width=0;
var acon_height=0;
var selecthouse="";
	
$(document).ready(function(){
		$('#full_wrap').animate({
			opacity: 0.8
		},100);
		
		$('#closetxt').click(function(){
			$('#apply_results').text("");
			$('#full_wrap').css("display","none");
		});
		
		$('.pos_apply').click(function(){
			$('#full_wrap').css("display","block");
			
			selind=$('.pos_apply').index(this);
			selecthouse=$('.house').eq(selind).text();
			
			acon_width=$('#apply_con').width()/2;
			acon_height=$('#apply_con').height()/2;
	
			$('#apply_con').css({
				"margin-left": "-"+acon_width+"px",
				"margin-top": "-"+acon_height+"px"
			});
		});
		
		$('#apply_form').submit(function(){
			$('#apply_results').text("Processing...");
			
			emailstr=$('#frm_email').val();
			namestr=$('#frm_name').val();
			positionstr=$('#frm_position').val();
			
			if(namestr!="")
			{
				if(CheckEmail(emailstr))
				{
					//send to php
					$.post("scripts/apply.php",{f_name: namestr, f_email: emailstr, f_position: positionstr, f_house: selecthouse},function(data){
						if(data=="sucess")
						{
							$('#apply_results').text("");
							$('#full_wrap').css("display","none");
						}
					});
				}
				else
				{
					$('#apply_results').text("Please enter a valid email address");
				}	
			}
			else
			{
				$('#apply_results').text("Please enter your full name");	
			}
			return false;
		});
});

function CheckEmail(inputemail) {
AtPos = inputemail.indexOf("@");
StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}