/*
 * jQuery custom scripts for Archer
 * http://www.archerfg.com/
 *
 * Copyright (c) 2010
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2010-10-06 (Wed, 6 October 2010)
 * Revision: 1
 */





/* Custom functions
------------------------------------------------- */
function popup(url,w,h,type) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var popupProps = "width=" + w + ",height=" + h + ",left=" + winl + ",top=" + wint;
	
	switch(type) {
		case "full":
			popupProps += "fullscreen=yes,resizable=1,status=1,menubar=1,toolbar=1,scrollbars=1,location=1,directories=1";
			break; 
		
		case "basic":
			popupProps += "resizable=1,toolbar=1,scrollbars=1,location=1";
			break; 
		
		case "scroll":
			popupProps += "scrollbars=1";
			break;
		
		default:
			popupProps += "";
	}
	
	window.open(url, "popup", popupProps);
}

function verify(formid) {
	if(document.getElementById(formid)) {
		var theForm = document.getElementById(formid);
		var error = 0;
		
		if(theForm.code.value != "BL2J2A") {
			alert("You must type the correct code to continue.");
			theForm.code.focus();
			return false;
		}
		return true;
	}
}

function noenter() {
	return !(window.event && window.event.keyCode == 13);
}

function toCurrency(val) {
	val=""+Math.round(100*val); 
	var dec_point=val.length-2;
	var first_part=val.substring(0,dec_point);
	var second_part=val.substring(dec_point,val.length);
	var result=first_part+"."+second_part;
	return result;
}

jQuery.fn.set_amount = function() {
	
	// show or hide submit button
	this.val() ? $("#submit").removeClass("disabled") : $("#submit").addClass("disabled");
	this.val() ? $("#submit").attr("disabled", "") : $("#submit").attr("disabled", "disabled");
	
};
/* -------------------------------------------------
                             end custom functions */





/* UI Candy
------------------------------------------------- */
$(document).ready(function(){
	
	$('a[rel="external"]').attr("target","_blank");
	
	$('a[rel="close"]').click(function() {
		window.close();
		return false;
	});
	
	$("#amount").change(function()   { $("#amount").set_amount(); });
	$("#amount").keydown(function()  { $("#amount").set_amount(); });
	$("#amount").keypress(function() { $("#amount").set_amount(); return noenter(); });
	$("#amount").keyup(function()    { $("#amount").set_amount(); });
	
	$("#payment").submit(function() {
		
		// prevent non-integers and negative numbers
		if(isNaN($("#amount").val().replace(/,/, ''))) {
			alert("Numbers only, please");
			
			$("#amount").focus();
			
			return false;
		}
		else if($("#amount").val().replace(/,/, '') < 0) {
			alert("Positive numbers only, please");
			
			$("#amount").focus();
			
			return false;
		}
		
		$("#amount").val(toCurrency($("#amount").val().replace(/,/, '')));
		
		return true;
	});
});
/* -------------------------------------------------
                                     end UI Candy */





