$(document).ready(function(){

$("a[id^='apply_']").live("click" , function(event){
			
			event.preventDefault();
			
			var id=$(this).attr('id');
			var arr=new Array();
			arr=id.split("_");
			var longId=arr[1];
			var link=$('#link').val();
			var base = base_url+'careers/applyPosition';
			$.post(base,{longId: longId,link:link},function(data){
					
				$(data).modal(data);
				
			});
    });
$("#forgotPassword").live("click" , function(event){

			$.modal.close();
			event.preventDefault();
			var base = base_url+'careers/forgotPassword';
			$.post(base,function(data){
					
				$(data).modal(data);
				
			});

    });
	$('#actmobileNo').live("blur" , function(event){
		
		var mobileNo=$('#actmobileNo').val();	
		$("#simplemodal-container").css("height","auto");
		$("#simplemodal-container").css("max-height","230px");	
		if ($('#actmobileNo').val() == "")
		{
			$("#actmobileNo").focus();
			$("#actmobileNoError").hide().html(invalidImage+"Enter Mobile Number").show("slow");
			
		}
		else
		{
			var re_mobileNo = /^[9,8,7]\d{9}$/;
			if (!re_mobileNo.test($.trim($('#actmobileNo').val()))) 
			{
				$("#actmobileNo").focus();
				$("#actmobileNoError").hide().html(invalidImage+"Enter valid Mobile Number").show("slow");
			}
			else
			{
				var base = base_url+'careers/checkmobileNoAvailability';
				$.post(base,{mobileNo: mobileNo},function(data){
					if (data == 1)
					{
						$("#actmobileNoError").html("").show("slow");
						
					}
					else
					{	
						$('#actmobileNoError').css('color', '#FF0000');
						$("#actmobileNoError").hide().html(invalidImage+mobileNo+" is not registered number.").show("slow");
						return;
						
					}
				});
				
			}	
		}
		 
	});
	$("#sendActivationCode").live("click" , function(event){
		
		$("#simplemodal-container").css("height","auto");
		$("#simplemodal-container").css("max-height","230px");	
		if ($('#actmobileNo').val() == "")
		{
			$("#actmobileNo").focus();
			$("#actmobileNoError").hide().html(invalidImage+"Enter Mobile Number").show("slow");
			
		}
		else
		{
			var re_mobileNo = /^[9,8,7]\d{9}$/;
			if (!re_mobileNo.test($.trim($('#actmobileNo').val()))) 
			{
				$("#actmobileNo").focus();
				$("#actmobileNoError").hide().html(invalidImage+"Enter valid Mobile Number").show("slow");
			}
			else
			{
				var mobileNo=$('#actmobileNo').val();
				var base = base_url+'careers/checkmobileNoAvailability';
				$.post(base,{mobileNo: mobileNo},function(data){
					if (data == 1)
					{
						$("#actmobileNoError").html("").show("slow");
						$("#actmobileNo").attr("disabled",true);
						$("#sendActivationCode").attr("disabled",true);
						$("#loader1").css("display","block");
						
						var base = base_url+'careers/sendActivationCodeDirectMobile';
						$.post(base,{mobileNo: mobileNo},function(data){
							$("#loader1").css("display","none");
							/*
							$("#tr1").css("display","table-row");
							$("#tr2").css("display","table-row");*/
							$("#actDiv").show();
							$('#activationCode').focus();
						});
						
					}
					
					else
					{	
						$('#actmobileNoError').css('color', '#FF0000');
						$("#actmobileNoError").hide().html(invalidImage+mobileNo+" is not registered number.").show("slow");
						validateAllFlag=1;
					}
				});
			}	
		}
		
		
	});
	$('#activationCode').live("blur" , function(event){
		
		if ($('#activationCode').val() == "")
		{
			$("#activationCode").focus();
			$("#activationCodeError").hide().html(invalidImage+"Enter Activation Number").show("slow");
			
		}
		else
		{
			$("#activationCodeError").html("").show("slow");
		}
		 
	});
	$("#verifyActivationCode").live("click" , function(event){
			
			$("#simplemodal-container").css("height","auto");
			$("#simplemodal-container").css("max-height","230px");	
		if ($('#activationCode').val() == "")
		{
			$("#activationCode").focus();
			$("#activationCodeError").hide().html(invalidImage+"Enter Activation Number").show("slow");
			return;
			
		}
		else
		{
			$("#verifyActivationCode").html("").show("slow");
			$("#activationCode").attr("disabled",true);
			$("#verifyActivationCode").attr("disabled",true);
			$("#loader2").css("display","block");
			var activationCode=$('#activationCode').val();
			var mobileNo=$('#actmobileNo').val();	
			var base = base_url+'careers/verifyActivationCodeDirectMobile';
			$.post(base,{activationCode: activationCode,mobileNo: mobileNo},function(data){
				
				$("#loader2").css("display","none");
				if(data==1)
				{
					setTimeout('go_to_private_page()', 3000); 
				}
				else
				{
					$("#activationCodeError").hide().html(invalidImage+"Please specify valid activation Code").show("slow");
					$("#activationCode").attr("disabled",false);
					$("#verifyActivationCode").attr("disabled",false);
					return;
				}
			});

			
		}	
		
	});
/*
	$("#userName").blur();
	$("#userName").live("blur" , function(event){
		
		if ($.trim($('#userName').val()) == "")
		{
			$("#userNameTextError").hide().html("Enter Mobile number or email Id").show("slow");
			
		}
		else
		{
			$("#userNameTextError").html("");
			
		}
	 });
	$("#password").live("blur" , function(event){
		
		if ($.trim($('#password').val()) == "")
		{
			$("#passwordTextError").hide().html("Enter your password").show("slow");
			return;
		}
		else
		{
			$("#passwordTextError").html("");
			return;
		}
	 });*/
	$("#check").live("click" , function(event){
								
			$("#simplemodal-container").css("height","auto");
			$("#simplemodal-container").css("max-height","230px");	
			var validateAllFlag = 0;
			if ($.trim($('#userName').val()) == "")
			{
				$("#userNameTextError").hide().html("Enter Mobile number or email Id").show("slow");
				validateAllFlag=1;
			}
			else
			{
				$("#userNameTextError").html("");
				
			}		
			if ($.trim($('#password').val()) == "")
			{
				$("#passwordTextError").hide().html("Enter your password").show("slow");
				validateAllFlag=1;
			}
			else
			{
				$("#passwordTextError").html("");
				
			}
			if (validateAllFlag == 1)
			{
				return false;
			}
			else
			{
				var link=$('#fulllink').val();
				var position=$('#position').val();
				var username=$('#userName').val();
				var password=$('#password').val();
				var base = base_url+'careers/checkUser';
				$.post(base,{position: position,username:username,password:password},function(data){
						
					if(data == 0)
					{
						$("#passwordTextError").hide().html("Invalid Details!!").show("slow");
						return false;
					}
					else
					{
						window.location=link;
					}
					
				});	
			}
		});										  
});		

function go_to_private_page()
{
	window.location = base_url+'careers/Available-Openings';
}

