// ------------------------------------------------ CONSTANTS

/* URL to PayPal's Developer Sandbox */
var SANDBOX_URL = 'https://www.sandbox.paypal.com/';

/* URL to PayPal's Developer Central */
var DEVELOPER_CENTRAL_URL = 'http://developer.paypal.com/';

/* URL to the category detail page */
var CATEGORY_DETAIL_URL = 'categoryDetail.aspx';

/* URL to the shipping page */
//var SHIPPING_URL = 'shipping.aspx';
var SHIPPING_URL = 'orderform.aspx';

/* URL to the shopping cart page */
var VIEW_CART_URL = 'ShoppingBasket.aspx';

/* URL to the receipt page */
var RECEIPT_URL = 'receipt.aspx';

/* URL to the admin order details page */
var ORDER_DETAILS_URL = 'orderDetails.aspx';

/* 
 * URL to the express checkout page in the Sanbox.
 * Note: this URL is invalid in that it does not have a value for 
 * the token parameter.
 * Note: not sure if the URL contains the subdomain www or not
 */
var EXPRESS_CHECKOUT_URL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=';

/* Window names */
var SANDBOX_WINDOW = 'Sanbox';
var DEVELOPER_CENTRAL_WINDOW = 'DeveloperCentral';


// ------------------------------------------------ FUNCTIONS

/*
 * Open a new browser window and display the 
 * given resource at the given URL. You may 
 * overload this method and optionally include 
 * a name for the new window and/or a list of 
 * features attributes to give to the window. This 
 * function could be written as: 
 *
 * openWindow(theURL[, theName[, features]])
 *
 * theURL: URL of the resource to display [required]
 * theName: name assigned to the window [optional]
 * features: comma delimited list of window features [optional]
 */
function openWindow(theURL)
{
	var DEFAULT_WIDTH	= 720;
	var DEFAULT_HEIGHT	= 540;
	var DEFAULT_NAME	= '';
	var DEFAULT_FEATURES = 'width='+DEFAULT_WIDTH+',height='+DEFAULT_HEIGHT+'scrollbars,resizable,status,toolbar,location,menubar,directories';

	var _URL = theURL;
	var _name = DEFAULT_NAME;
	var _features = DEFAULT_FEATURES;
	
	for (var i = 1; i < openWindow.arguments.length; i++)
	{
		if (1 == i && openWindow.arguments[i]) _name = openWindow.arguments[i];
		if (2 == i && openWindow.arguments[i]) _features = openWindow.arguments[i];
	}

	window.open(_URL, _name, _features);
}

/*
 * Convenience method for opening the PayPal Developer's Sandbox 
 * in a new window
 */
function openSandbox()
{
	openWindow(SANDBOX_URL, SANDBOX_WINDOW);
}

/*
 * Convenience method for opening Developer Central in a new window
 */
function openDeveloperCentral()
{
	openWindow(DEVELOPER_CENTRAL_URL, DEVELOPER_CENTRAL_WINDOW);
}

/*
 * Redirect to the resource at the given URL
 */
function redirect(theURL)
{
	document.location.href = theURL;
}

/*
 * Simulates "Continue Shopping" functionality by simply redirecting to 
 * the category detail page
 */
function continueShopping()
{
	redirect(CATEGORY_DETAIL_URL);
}

/*
 * Supresses call to delete an item from the cart as it is not functionaly 
 * supported in this release
 */
function deleteFromCart()
{
	return null;
}

/*
 * Supresses call to update the quantity of an item in the cart as it is 
 * not funcationly supported in this release
 */
function updateCart()
{
	return null;
}

/*
 * Simulate checking out a shopping cart. Redirects to the shipping page.
 */
function checkout()
{
	redirect(SHIPPING_URL);
}

/*
 * Simulate canceling the current order and redirect to the view cart page.
 */
function cancelOrder()
{
	redirect(VIEW_CART_URL);
}

/*
 * Suppresses call to place order and redirects to the receipt page.
 */
function placeOrder()
{
	redirect(RECEIPT_URL);
}

/*
 * Convenience method for checking out in the express checkout flow. This method 
 * opens a new window to the log in page in the Sandbox.
 */
function expressCheckout()
{
	openWindow(EXPRESS_CHECKOUT_URL, SANDBOX_WINDOW);
}

/*
 * Suppresses call to cancel order and redirects to order details page
 */
function cancelRefund()
{
	redirect(ORDER_DETAILS_URL);
}

/*
*JS method added 4/26/05 to make ccselection prefill cc number for customer
*/

function ccSelect(value)
{
	switch (value){
	
	case "visa":
	document.billingForm.DPcreditCardNumber.value = "4032031500171078";
	document.billingForm.DPcvv2code.value = "847";
	break;
	
	case "discover":
	document.billingForm.DPcreditCardNumber.value = "6011538925111703";
	document.billingForm.DPcvv2code.value = "915";
	break;
	
	case "mastercard":
	document.billingForm.DPcreditCardNumber.value = "5110670559050196";
	document.billingForm.DPcvv2code.value = "421";
	break;
	
	case "amex":
	document.billingForm.DPcreditCardNumber.value = "345310297866151";
	document.billingForm.DPcvv2code.value = "1451";
	break;
	
	
	}

}

function C_IsNumeric(vstrNumber, vblnIntegerValueOnlyFlag)
	{
		var vblnIntegerValueOnlyFlag;
		
		if (C_IsNothing(vblnIntegerValueOnlyFlag))
		{
			vblnIntegerValueOnlyFlag = false
		}
	
		for (i=0; i< vstrNumber.length; i++)
		{
			if (isNaN(parseFloat(vstrNumber.charAt(i))))			 
			{
				if (!((!vblnIntegerValueOnlyFlag) && vstrNumber.charAt(i) == "."))
				{
					return false;
					break;
				}
			}
		}
		
		return true;
	}
	
function C_IsNothing(vstrToBeEvaluated)
	{
		return ((typeof(vstrToBeEvaluated) == "undefined") || (vstrToBeEvaluated == null) || (vstrToBeEvaluated.toString() == ""))	
	}

//set focus to control on form
function CF_SetFocus(robjControl)
{
	try
	{
		if(robjControl.type != "hidden" &&
			! robjControl.disabled &&
			! robjControl.readOnly )
		{
			robjControl.focus();
		}
	}
	catch(ex)
	{
	
	}
}