if (!JS_OXIMO) { var JS_OXIMO = new Object(); }

JS_OXIMO = {

	init: function(){
  		// do basic form features
  		JS_OXIMO.formInit();
  		
  		// login shizzle
  		JS_OXIMO.loginClick();
  	},
  	
  	
	/**
	 * 	Make numbers pretty!
	 */
	 beautifyCurrency: function (vValue){
		   aDigits = vValue.toFixed(2).split(".");
		   aDigits[0] = aDigits[0].split("").reverse().join("").replace(/(\d{3})(?=\d)/g, "$1 ").split("").reverse().join("");
		   if(aDigits[1] == 0) return aDigits[0];
		   else return aDigits.join(",");
	},
	
	
	/**
	 * Close thickbox with a delay and refresh the parent
	 */
	closeThickbox: function(delay, refresh){
		// refresh parameter
		if(refresh == null) refresh = true;
		
		// set delay
		setTimeout(function(){
			
			// reload parent
			if(refresh) parent.location.reload();
			
			// close thickbox
			parent.tb_remove();
		}, delay);
	},
	
	
 	/**
 	 * This function well add a enterkey event to every input/select element
 	 * and a onclick event for every <a class="button"> element within the form tag.
	 * Both events will submit the form
	 */ 	
  	formInit: function()
  	{
		$('form').each(function()
		{
			var formId = this.id;
			$('#'+ formId +' input:visible, #'+ formId +' select:visible').each(function()
			{
				var classes = $(this).attr("class").split(" ");
				if(jQuery.inArray('no-submit', classes) == -1){	
					$(this).bind("keypress", function(e) {	
						if(e.keyCode == 13) $('#'+formId).submit();
					});
				}
			}); 
			
			// check for a A element with class 'button' in the form and use it as submit				
			$('#'+formId+' a.button').each(function()
			{
				var classes = $(this).attr("class").split(" ");
				if(jQuery.inArray('no-submit', classes) == -1)
				{	
					$(this).bind("click", function(e) {
						e.preventDefault();
						$('#'+formId).submit();
					});
				}
			});
		});
	},
	
	
	/**
	 *	When clicked in the password or login field and the value is "gebruikersnaam" or "password" then make the field empty
	 */
	loginClick: function(){
		$('#login_username, #login_password').bind('focus', function(){
			if($(this).val() == 'E-mailadres' || $(this).val() == 'Gebruikersnaam' || $(this).val() == 'Wachtwoord') $(this).val('');
		});
	},
	
	
	/**
	 * end of the object
	 */
	_eoo: true
}

jQuery(function($) {
	JS_OXIMO.init();
});

