// JavaScript Document
$(document).ready(function() {
	var options = { 
		target:     '#dealer_contact', 
		url:        'http://www.biblesoft.com/new/contact/formSubmit.asp', 
		success:    function() { 
			//$("dealer_contact").html("Your order has been submitted.");
			//alert("success!");
		} 
	}; 						   	
	
	function checkIt(){
		var toReturn;
		
		$.ajax({
		   type: "GET",
		   url: "includes/checkInfo.asp",
		   data: "password=" + $("#password").val(),
		   success: function(data){
			   var message//, redirect
			   //alert(data);
			   if(data == "false" || data.length < 1){
					message = "<img src='../images/exclamation.png' />";
					//redirect = "";
					toReturn = false;
			   }
			   else{
					message = "<img src='../images/accept.png' />";	
					 
					$("input#password").val("");
					window.location = data + ".asp?loggedIn=true";
    				toReturn = true;
			   }
			   $("div#passCheck").html(message);
			   return toReturn;
			}
			
		 });
	}
	
	$("input#password").focus( function () { 
		checkIt();		
	} );
	
	$("input#password").blur( function () { 
		checkIt();		
	} );
	
	$("input#password").change( function () { 
		checkIt();		
	} );
	
	$("input#password").keyup( function () { 
		checkIt();		
	} );
	
	$("#dealer_contact").validate({
		rules: {
		    StoreName: "required",
			ContactPerson: "required",
			csz: "required",
			Phone: "required",
			email: {
				required:true,
				email: true
			},
			Emailagain: {
				required:true,
				equalTo:"#email"
			},
			poNum: "required",
			contact_type: "required",
			contact_text: {
				required: true,
				minLength: 10
			}
		},
		messages: {
			StoreName: "&nbsp;",
			ContactPerson: "&nbsp;",
			csz: "&nbsp;",
			Phone: "&nbsp;",
			email: "&nbsp;",
			Emailagain: "must match email",
			poNum: "&nbsp;",
			contact_type: "&nbsp;",
			contact_text: "must be at least 10 characters"
		},	
		success: "valid",
		submitHandler: function(form) {
			$(form).ajaxSubmit(options);
		}
	});

	
});
