// changes the form action depending on the fields completed

$(document).ready(function()
{
	$("#loginForm").submit(function(){
		
		var isValid=true;
		var WOC="https://ijb.citysprint.co.uk/cs/ijb.htm?sunxp=1&company=WestOne&action=hkbookquote&";
		var BC="http://www.groundcontroller.com/W1Home.asp?";
		var msg=new Array();
		
		if($("#password").val()=="")
		{
			msg.push("Please enter a password.");
			isValid=false;
		}
		
		if(($("#account_number").val()=="" && $("#username").val()=="") || ($("#account_number").val()!="" && $("#username").val()!=""))
		{
			msg.push("Please enter either an Account Number or Username.");
			isValid=false;
		}
		else if($("#account_number").val()!="")
		{
 			$("#loginForm").attr('action',WOC+"username="+$("#account_number").val()+"&password="+$("#password").val());
		}
		else if($("#username").val()!="")
		{
			$("#loginForm").attr('action',BC);
 		}
		
		
		
		if(isValid){
			$("#loginForm").attr('method','POST');
			var newWindow = window.open("/loading.html", "newWindow", "width=960,height=750,toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,titlebar=no");
			if(newWindow.blur){newWindow.focus();};
 		}
		else
		{
			alert(msg.join('\n'));
		}
 
		return isValid;
	})	

});