
mouse = { x: 0, y: 0 };

$j(document).ready(function(){
	   $j().mousemove(function(e){
			mouse.x = e.pageX;
			mouse.y =  e.pageY;
	   }); 
	})



function showSwitchAccount(clientId)
{
	
	
	if($j('#switchAccount')) { $j('#switchAccount').remove(); }

	myElement = document.createElement('div');
	myElement.id = 'switchAccount';
	myElement.style.position = 'absolute';
	myElement.style.top =  (mouse.y + 0) + 'px'; 
	myElement.style.left =  (mouse.x - 100) + 'px';
	myElement.style.padding = '5px';
	myElement.style.width = '250px'; 
	//myElement.style.height = '600px'; 
	myElement.style.backgroundColor = "#ff7921"; 
	myElement.style.border = "1px solid #FFFFFF"; 
	myElement.style.zIndex = 99;
	document.body.appendChild(myElement);

	$j.ajax( 
				{ 
					type: "POST", 
					url: "processOrder.php", 
					data: "mode=showSwitchAccountForm&clientId=" + clientId, 
					success: 
						function(t) 
						{ 
							$j("div#switchAccount").empty().append(t); 
						}, 
					error: 
						function() 
						{ 
							$j("div#switchAccount").append("An error occured during processing"); 
						} 
				}); 

}


function switchAccount(accountId)
{


	$j.ajax( 
				{ 
					type: "POST", 
					url: "processOrder.php", 
					data: "mode=switchAccount&accountId=" + accountId, 
					success: 
						function(t) 
						{ 
							window.location.reload();
						}, 
					error: 
						function() 
						{ 
							$j("div#switchAccount").append("An error occured during processing"); 
						} 
				}); 


}

/*
ccc registration

*/

var accountField = 2;

function showMoreAccounts()
{
	$('accountNameRow' + accountField).style.display = 'block';
	$('accountNumberRow' + accountField).style.display = 'block';
	
	accountField++;

}



function showAccountRegistration(accounts)
{
	var serializedForm = '';

	if($('myActiveForm'))
	{
			serializedForm = Form.serialize('myActiveForm');
			
	}


	new Ajax.Updater('div1', 'processOrder.php?mode=showAccountRegistration', {asynchronous:true, evalScripts:true, parameters: { accounts: accounts } , onComplete: function() {
		if($('myActiveForm'))
		{

			Form.deserialize($('myActiveForm'), serializedForm);
			$('accounts').value = accounts;

		}
	}
	
	} );

	
}

function submitClientForm(form)
{
	var mode = $F('mode');
	var serializedForm = Form.serialize(form);

	new Ajax.Updater('div1', 'processOrder.php', {asynchronous:true, evalScripts:true, parameters:serializedForm , 
		onComplete: function() { 
				if(mode == "registerAccount")
				{
					Form.deserialize($('myActiveForm'), serializedForm);
					//alert(serializedForm);
				}
			}
	}); 
	
	return false;

}