// JavaScript Document
var cmsg;

var mlnum = $.getURLParam("@mlnum");
	
	if(mlnum){
		$.cookie('vowTrackProperty', mlnum, { expires: 1,path: '/' });	
	}

	if($.cookie("vow_user")){
		window.open("http://"+location.host+"/vow/index.php?overlord=vowStart","_self");
	}
	

/*$.ajax({
			type: "POST",
			url: "http://"+location.host+"/vow/index.php?overlord=vowCheckCookie",
			success: function(data){
				if(data=="1") window.open("http://"+location.host+"/vow/index.php?overlord=vowStart","_self");
			}
	});
	*/
	
$(document).ready(function() {
	
	$("#vowLogin").click(function() {
		var form = $("#VowLoginForm").serialize();
		$.ajax({
			type: "POST",
			url: "http://"+location.host+"/vow/index.php?"+form,
			success: function(data){
				if(data==1) window.open("http://"+location.host+"/vow/index.php?overlord=vowStart","_self");
				else if(data==2) window.open("http://"+location.host+"/vow/admin/index.php?overlord=vowStartAgent","_self");
				else if(data==3) alert("Your Login Failed. This could mean that you do not have any clients in the system, you are logging in from the wrong domain or are not setup for VOW.");
				else alert("Your login failed. This could mean the following.\n\n1. Your credentials were incorrect. Click the password retrieval link to have your password emailed to you.\n\n2. You are not registered for this website. Please create an account by using the signup form on this page or by clicking the Sign Up link.");
			}
		}); 
	});
	
	$("#vowExePassword").click(function() {
		$("#vowLoginForm").hide();
		$("#vowPasswordForm").show();
	});
	
	$("#vowExeLogin").click(function() {
		$("#vowLoginForm").show();
		$("#vowPasswordForm").hide();
	});
	
	$("#vowGetPassword").click(function() {
		var form = $("#VowPasswordRetrival").serialize();
		$.ajax({
			type: "POST",
			url: "http://"+location.host+"/vow/index.php?"+form,
			success: function(data){
				if(data){ 
					alert(data);
					$("#vowLoginForm").show();
					$("#vowPasswordForm").hide();
				} else alert("Could not retrieve your password This could mean the following.\n\n1. Your credentials were incorrect and you are not registered for this website.\nPlease create an account by using the signup form on this page or by clicking the Sign Up link.");
			}
		}); 
	});
	
	$("#vowEXEValidation").click(function() {
		var form = $("#VowClientValidation").serialize();
		$.ajax({
			type: "POST",
			url: "http://"+location.host+"/vow/index.php?"+form,
			success: function(data){
				if(data) alert("Your account has been validated, please login");
				else alert("Your account could not be validated");
			}
		}); 
	});
	
	
});
function VowSignUpFormFn(){
	var form = $("#validateform").serialize();
	$.ajax({
		type: "POST",
		url: "http://"+location.host+"/vow/index.php?"+form,
		success: function(data){
			var em = $("#client_email").val();
			$("#mlstxt").html("<h2>Thank You</h2><p class=\"note\">Your registration is almost complete! Please check your <a href=\"mailto:"+em+"\">"+em+"</a> email account. You should receive a validation email containing a link to confirm your registration. Please click this link and then login using the \"Already A Member?\" form located to the right, thank you.</p>");
			$("#VowSignUpArea").html("");
			
			window.scrollTo(0, 300)
			//alert("");
			
		}
	}); 	
}
function vowCheckEmail(email){
	$.ajax({
		type: "POST",
		url: "http://"+location.host+"/vow/index.php?overlord=vowCheckEmail&client_email="+email,
		 async: false,
		success: function(data){
			if(data==1) cmsg = "Email already in use. If you have signed up for the Home Evaluations on this site, you are already signed up, please use that email and password to login to start your search";
			else cmsg = "";
		}
	}); 
}
