shoppingcartURL = "/includes/shoppingcart-smallcart.asp";

function addToCart(intProductID) {
	var pars = 'productID=' + intProductID;
	var target = 'cartpreview';
	var myAjax = new Ajax.Updater(target, shoppingcartURL, {method: 'get',	parameters: pars});
}

function enableObject(objId, state){
	obj = $(objId);
	if (obj) {
		if(state){
			obj.disabled = false;
			obj.blur();
		}
		else{
			obj.disabled = true;
		}
	}
}

function enableForm(objForm, bolEnabled) {
	if (bolEnabled)
		Element.removeClassName(objForm, "disabledform");
	else
		Element.addClassName(objForm, "disabledform");
	
	arrFormInputs = Form.getInputs(objForm);
	for (i = 0; i < arrFormInputs.length; i++) {
		enableObject(arrFormInputs[i], bolEnabled);
	}
	
	arrSelectBoxes = objForm.getElementsByTagName("SELECT");
	for (i = 0; i < arrSelectBoxes.length; i++) {
		enableObject(arrSelectBoxes[i], bolEnabled);
	}
}

function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions = "";
	if (strType == "console") 
		strOptions = "resizable,height=" + strHeight + ",width=" + strWidth;
		
	if (strType == "fixed")
		strOptions = "status,height=" + strHeight + ",width=" + strWidth;
		
	if (strType == "elastic") 
		strOptions = "toolbar,menubar,scrollbars,resizable,location,height=" + strHeight + ",width=" + strWidth;
		
	window.open(strURL, 'newWin', strOptions);
}

function guessCardType(intCardNumber) {  
	// Array to hold the permitted card characteristics
	var cards = new Array();
	
	// Define the cards we support. You may add addtional card types.
	
	//  Name:      As in the selection box of the form - must be same as user's
	//  Length:    List of possible valid lengths of the card number for the card
	//  prefixes:  List of possible prefixes for the card
	//  checkdigit Boolean to say whether there is a check digit
	
	cards[0] = {name: "Visa", 
	           length: "13,16", 
	           prefixes: "4"};
	cards[1] = {name: "MasterCard", 
	           length: "16", 
	           prefixes: "51,52,53,54,55"};
	cards[2] = {name: "DinersClub", 
	           length: "14,16", 
	           prefixes: "300,301,302,303,304,305,36,38,55"};
	cards[3] = {name: "CarteBlanche", 
	           length: "14", 
	           prefixes: "300,301,302,303,304,305,36,38"};
	cards[4] = {name: "AmEx", 
	           length: "15", 
	           prefixes: "34,37"};
	cards[5] = {name: "Discover", 
	           length: "16", 
	           prefixes: "6011,650"};
	cards[6] = {name: "JCB", 
	           length: "15,16", 
	           prefixes: "3,1800,2131"};
	cards[7] = {name: "enRoute", 
	           length: "15", 
	           prefixes: "2014,2149"};
	cards[8] = {name: "Solo", 
	           length: "16,18,19", 
	           prefixes: "6334, 6767"};
	cards[9] = {name: "Switch", 
	           length: "16,18,19", 
	           prefixes: "4903,4905,4911,4936,564182,633110,6333,6759"};
	cards[10] = {name: "Maestro", 
	           length: "16", 
	           prefixes: "5020,6"};
	cards[11] = {name: "VisaElectron", 
	           length: "16", 
	           prefixes: "417500,4917,4913"};
           
	// Make sure a card number has been inserted
	if (intCardNumber.length > 0)  {
		// Remove all the spaces from the card number
		intCardNumber = intCardNumber.replace (/\s/g, "");
		
		// We use these for holding the valid lengths and prefixes of a card type
		var prefix = new Array();
		var lengths = new Array();

		// Loop through each card type        
		for (var i = 0; i < cards.length; i++) {
			PrefixValid = false;
			
			// Load an array with the valid prefixes for this card
			prefix = cards[i].prefixes.split(",");
			
			// Now see if any of them match what we have in the card number
			for (x = 0; x < prefix.length; x++) {
				var exp = new RegExp ("^" + prefix[x]);
				if (exp.test(intCardNumber))
					PrefixValid = true;
			}
			
			// We have a valid prefix, so continue
			if (PrefixValid) {
				// See if the length is valid for this card
				lengths = cards[i].length.split(",");
				for (j = 0; j < lengths.length; j++) {
					// This is probably it
					if (intCardNumber.length == lengths[j]) {
						return cards[i].name;
					}					
				}
			}
		}   	
	}
	else {
		return false;	
	}
}   