//This array will contain the skus to check for duplicates before checkout. 

var orderItemSkus = new Array();
var overseaStates;
var priorityOnlyStates;
	
function skudetail(skuid,color,skudesc,size) {
	this.skuid = skuid;
	this.color = color;
	this.size = size;
	this.skudesc = skudesc;
}

function checkDuplicate()
{
	var msgDesc="";
	var hash = new Object();
	var outstring = "";
	var dupeFound = false;
	

	for (i = 0; i < orderItemSkus.length; i++){
		if (hash[orderItemSkus[i].skuid.toLowerCase()] != 1)
		{
			hash[orderItemSkus[i].skuid.toLowerCase()] = 1;
		}
		else 
		{

			msgDesc = orderItemSkus[i].skudesc  + ' '  + orderItemSkus[i].skuid + ' ' +  orderItemSkus[i].color  + ' '  + orderItemSkus[i].size;  
            outstring = outstring + msgDesc + '\n';
		    dupeFound = true;
           }
	}
	if (dupeFound == true)
		{
		alert ('The following item appears in your shopping bag more than once.  Please remove the duplicate line items and then update the total quantity you wish to purchase of that item. \n\n' + outstring );
		}
	return dupeFound;
}

function checkQuantity()
{
	var isQuantityNumeric = true;
	var form = document.ShopCartForm;
	
 
	if (form.quantity[0]) {
		for (s = 0; s < form.orderItemId.length; s++)
		{
		
			if (form.quantity[s].value == '')
				isQuantityNumeric = false;
				
			for (y = 0; y < form.quantity[s].value.length; y++)
			{
				if ((!parseInt(form.quantity[s].value.charAt(y))) && !(form.quantity[s].value.charAt(y) == '0'))
		
					isQuantityNumeric = false;
			}
		
			if ((!isQuantityNumeric) || (form.quantity[s].value < 1))
				isQuantityNumeric = false;
		
		}
	}
	else {
		if (form.quantity.value == '')
			isQuantityNumeric = false;
			
		for (y = 0; y < form.quantity.value.length; y++)
		{
			if ((!parseInt(form.quantity.value.charAt(y))) && !(form.quantity.value.charAt(y) == '0'))
	
				isQuantityNumeric = false;
		}
	
		if ((!isQuantityNumeric) || (form.quantity.value < 1))
			isQuantityNumeric = false;
	
	}

	return isQuantityNumeric;
}

function ContinueShopping()
{

	if (checkDuplicate()){
	return;
	}
	
	history.go(-2)
	//document.location.href = "http://<%=request.getHeader("Host")%>/webapp/wcs/stores/servlet/Home?storeId=<%=storeId%>&langId=<%=languageId%>&catalogId=<%=catalogId%>";
}

// *********************************************************************
//Shipping Method Display Logic
//Below is the logic in displaying the shipping options to the user
// *********************************************************************
function displayShipMethods (addressField1, addressField2, state)
{
	// Initially, disable all the shipping methods.
	if (document.getElementById("shipping_method_GR") != null)
 	   document.getElementById("shipping_method_GR").style.display='none';       
	if (document.getElementById("shipping_method_ND") != null)
    	document.getElementById("shipping_method_ND").style.display='none';
    if (document.getElementById("shipping_method_SD") != null)
    	document.getElementById("shipping_method_SD").style.display='none';
    if (document.getElementById("shipping_method_PM") != null)
    	document.getElementById("shipping_method_PM").style.display='none';
    if (document.getElementById("shipping_method_UB") != null)
    	document.getElementById("shipping_method_UB").style.display='none';
    if (document.getElementById("shipping_method_PO") != null)
   		document.getElementById("shipping_method_PO").style.display='none';
   	if (document.getElementById("shipping_method_SO") != null)	
    	document.getElementById("shipping_method_SO").style.display='none';
    if (document.getElementById("shipping_method_NO") != null)
    	document.getElementById("shipping_method_NO").style.display='none';
    
    //**********************************
    // Call actual pobox method
    //**********************************
    if (isPOBoxAddress(addressField1 + " " + addressField2))
    {
            if (overseaStates != null && overseaStates.indexOf(state) > -1) {
            	if (document.getElementById("shipping_method_PO") != null)
            		document.getElementById("shipping_method_PO").style.display='block';
            } else if (priorityOnlyStates != null && priorityOnlyStates.indexOf(state) > -1) {
            	if (document.getElementById("shipping_method_PM") != null)
            		document.getElementById("shipping_method_PM").style.display='block';
            } else {
            	if (document.getElementById("shipping_method_UB") != null)
            		document.getElementById("shipping_method_UB").style.display='block';
            }
            
    }
    else if (state != "")
    {
            if (priorityOnlyStates != null && priorityOnlyStates.indexOf(state) > -1) {
            	if (document.getElementById("shipping_method_PM") != null)
            		document.getElementById("shipping_method_PM").style.display='block';
            } 
            else if (overseaStates != null && overseaStates.indexOf(state) > -1) {
            	if (document.getElementById("shipping_method_SO") != null)
            		document.getElementById("shipping_method_SO").style.display='block';
            	if (document.getElementById("shipping_method_NO") != null)
            		document.getElementById("shipping_method_NO").style.display='block';
            }
            else
            {
            	if (document.getElementById("shipping_method_GR") != null)
            		document.getElementById("shipping_method_GR").style.display='block';
            	if (document.getElementById("shipping_method_ND") != null)
            		document.getElementById("shipping_method_ND").style.display='block';
            	if (document.getElementById("shipping_method_SD") != null)
            		document.getElementById("shipping_method_SD").style.display='block';
            }
    }
    else // there needs to be extra checking of field values and any preselections.
    {
		if (document.getElementById("shipping_method_GR") != null)
			document.getElementById("shipping_method_GR").style.display='block';
		if (document.getElementById("shipping_method_ND") != null)
            document.getElementById("shipping_method_ND").style.display='block';
        if (document.getElementById("shipping_method_SD") != null)
            document.getElementById("shipping_method_SD").style.display='block';
    }
    
    // Preselect first available shipmode when user change address.
    
    if (document.AddAddressForm != null){
    	resetShipmodeSelection(document.AddAddressForm);
    }
    if (document.QuickCheckout != null){
    	resetShipmodeSelection(document.QuickCheckout);
    }    
}



