// JavaScript Document
// Javascripts - Scripts on the productArea - online productSection - Cart
// Sleeping Giant Studios, LLC
// Created by David Ellenwood - 01/09/2007


// general function to open a pop-up window
function openCenteredWindow(fileLocation, winName, winDressing, winWidth, winHeight)
{
	if (winWidth == null) winWidth = 500;
	if (winHeight == null) winHeight = 350;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	var features = 'height='+winHeight+',width='+winWidth+',top='+winTop+',left='+winLeft+','+winDressing;
	
	win = window.open(fileLocation, winName, features)
	
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


// ~~~~ Shopping Cart specific scripts ~~~~ 

function confirmCartQuantities(){
	var i;
	var formElements = document.viewCartForm.elements;
	if (formElements) {
		var eName;
		var proceed = true;
		var intTotal = 0; 
		for(i=0; i<formElements.length; i++){
			eName = formElements[i].name;
			eValue = formElements[i].value;
			if(eName.indexOf("_Qty") > -1){
				if(eValue!='0' && !Number(eValue)){
					proceed=false;
					window.alert("Please make sure all item quantities are numbers and greater than or equal to 0.");
				}
			}
		}
	} else {
		proceed = false;
		alert('Error: Form viewCartForm does not exist. Please contact the administrator by email at support@begiant.com');
	}
	return proceed;
}



function modifyCartItems() {
	var varForm =document.getElementById('viewCartForm');	
	if (varForm) {	
		if(confirmCartQuantities()){
			varForm.submit();
		}
	} else {
		alert('Error: Form viewCartForm does not exist. Please contact the administrator by email at support@begiant.com');
	}
}



function checkout() {
	document.viewCartForm.elements['action'].value="PrepareOrder"
	if(confirmCartQuantities()){
		document.viewCartForm.submit();
	}
}



function continueShopping() {
	if(confirmCartQuantities()){
		document.viewCartForm.elements['goto'].value="Browse";
		document.viewCartForm.submit();
	}
}


function SubmitSpecificForm(frmName) {
	var varForm = document.getElementById(frmName);	
	
	if (varForm) {
		varForm.submit();
	} else {
		alert('Error: Form ' + frmName + ' does not exist. Please contact the administrator by email at support@begiant.com');
	}
}


function removeCartItem(intOrderDetailID) {
	var varForm =document.getElementById('viewCartForm');	
	if (varForm) {
		if(confirmCartQuantities()){
			document.getElementById(intOrderDetailID + '_Qty').value = '0';
			//varForm.elements['' + intOrderDetailID + '_Qty'].value = '0';
		}
	} else {
		alert('Error: Form viewCartForm does not exist. Please contact the administrator by email at support@begiant.com');
	}
}

function editCartItemQuantity(intOrderDetailID, intQty) {
	var varForm =document.getElementById('viewCartForm');	
	if (varForm) {
		if(confirmCartQuantities()){
			document.getElementById(intOrderDetailID + '_Qty').value = intQty;
			window.alert('The updated quantity and the totals can be\nreviewed after clicking the "Update Cart" button');		
		} else {
			window.alert('Please make sure that all quantities in the cart are valid');
		}		

	} else {
		alert('Error: Form viewCartForm does not exist. Please contact the administrator by email at support@begiant.com');
	}
}


