/******************************************************************************
* gshpJsBasket.js
*******************************************************************************
Fonctions js du processus de commande
*******************************************************************************
*                                                                             *
* Copyright 2006									                          *
*                                                                             *
******************************************************************************/

//	-------------------------------------------------------------------------
//	gshpChangeQuantity
//	Management of change about quantity
//	-------------------------------------------------------------------------
function gshpChangeQuantity(position)
{
	var form = document.getElementById("form_quantityForm_" + position);
	var input = document.getElementById("ctrl_quantity_" + position);
	if ((form == null) || (input == null)) {
		return false;
	}
	var quantity = parseInt(input.value, 10);
	if (isNaN(quantity)) {
		alert(objThesaurus.translate("gshpInvalidNewQuantity"));
		return false;
	}
	form.submit();
	return false;
}

//	-------------------------------------------------------------------------
//	gshpOnClickClientType
//	Management of click on client type
//	-------------------------------------------------------------------------
function gshpOnClickClientType(isIndividual, ajaxPage) 
{
	var element = document.getElementById("gshpBasketTable_clientIndividual");
	if (element != null)
		element.style.display = (isIndividual) ? "block" : "none";

	var element = document.getElementById("gshpBasketTable_clientCompany");
	if (element != null)
		element.style.display = (!isIndividual) ? "block" : "none";

	// Move of values and disabling of controls
	var eltNameList = [	"civility", "firstname", "name", "newEmail", "newEmailConfirmation", "newPassword", "newPasswordConfirmation",
							"newAddress", "newAddress1", "newAddress2", "newAddress3",
							"zip", "city", "country", "region", "regionLabel", "phone", "phone2", "mobile", 
							"companyName", "vatIntraCommunityNumber"];
	for (var ind=0; ind<eltNameList.length; ind++) {
		var eltName = eltNameList[ind];
		var eltNameIndividual = "ctrl_clientI_" + eltName;
		var eltNameCompany = "ctrl_clientC_" + eltName;
		var eltIndividual = document.getElementById(eltNameIndividual);
		var eltCompany = document.getElementById(eltNameCompany);
		
		//Updating regions list
		if(eltName == "region" ) gshpUpdateRegionsListOnClientTypeClick(ajaxPage, isIndividual, (isIndividual ? eltCompany.value : eltIndividual.value));

		// Move of value
		if ((eltName != "companyName") && (eltName != "vatIntraCommunityNumber")) {
			if ((eltIndividual != null) && (eltCompany != null)) {
				if (isIndividual == true)
				{
					if(eltName != "regionLabel") eltIndividual.value = eltCompany.value;
					eltIndividual.style.display = eltCompany.style.display;
				}
				else
				{
					if(eltName != "regionLabel") eltCompany.value = eltIndividual.value;
					eltCompany.style.display = eltIndividual.style.display;
				}
			}
		}

		// Disabling of controls
		if (eltIndividual != null)
			eltIndividual.disabled = (isIndividual == false);
		if (eltCompany != null)
			eltCompany.disabled = (isIndividual == true);
	}
}

//	-------------------------------------------------------------------------
//	gshpCheckInscriptionForm
//	Checking of inscription form
//	-------------------------------------------------------------------------
function gshpCheckInscriptionForm(formManager)
{
	// Recovery of client type
	var isIndividual = true;
	var oLstCtrlType = formManager.getControls("client.isIndividual");
	for (var ind=0; ind<oLstCtrlType.length; ind++) {
		var oCtrlType = oLstCtrlType[ind];
		var oMainInput = oCtrlType.getMainInput();
		if ((oMainInput != null) && (oMainInput.checked == true)) {
			var id 	= "" + oCtrlType.getId();
			var type= id.substr(12); // 12 for "ctrl_client_" length
			isIndividual = (type == "isIndividual");
			break;
		}
	}
	var sClientType = (isIndividual == true ? "I" : "C");

	// Confirmation
	var msgErr = "";
	// - of email
	var eltName = "ctrl_client" + sClientType + "_newEmail";
	var eltName2 =  "ctrl_client" + sClientType + "_newEmailConfirmation";
	var elt = document.getElementById(eltName);
	var elt2 = document.getElementById(eltName2);
	if ((elt != null) && (elt2 != null)) {
		if ((elt.value != elt2.value) && ((elt.value != "") || (elt2.value != ""))) {
			var msg = objThesaurus.translate("gshpDifferentEmailConfirmation");
			msgErr = msg;
			gshpShowCustomFailurePara(eltName2, true, msg);
		}
		else
			gshpShowCustomFailurePara(eltName2, false);
	}

	// - Confirmation of password
	if (msgErr == "") {
		eltName = "ctrl_client" + sClientType + "_newPassword";
		eltName2 =  "ctrl_client" + sClientType + "_newPasswordConfirmation";
		elt = document.getElementById(eltName);
		elt2 = document.getElementById(eltName2);
		if ((elt != null) && (elt2 != null)) {
			if ((elt.value != elt2.value) && ((elt.value != "") || (elt2.value != ""))) {
				var msg = objThesaurus.translate("gshpDifferentPasswordConfirmation");
				msgErr = msg;
				gshpShowCustomFailurePara(eltName2, true, msg);
			}
			else
				gshpShowCustomFailurePara(eltName2, false);
		}
	}
	
	// - phone checking
	if (msgErr == "") {
		eltName = "ctrl_client" + sClientType + "_phone";
		eltName2 =  "ctrl_client" + sClientType + "_phone2";
		eltName3 =  "ctrl_client" + sClientType + "_mobile";
		eltNameFailure = "ctrl_client" + sClientType + "_phone_failure_custom";
		elt = document.getElementById(eltName);
		elt2 = document.getElementById(eltName2);
		elt3 = document.getElementById(eltName3);
		eltFailure = document.getElementById(eltNameFailure);
		if (eltFailure != null) {
			if (elt.value == "" && elt2.value == "" && elt3.value == "") {
				var msg = objThesaurus.translate("gshp2416");
				msgErr = msg;
				gshpShowCustomFailurePara(("ctrl_client" + sClientType + "_phone"), true, msg);
			}
			else
				gshpShowCustomFailurePara(("ctrl_client" + sClientType + "_phone"), false);
		}
	}

	// Management of error (Cf ISV4-2525 for update of code)
	if (msgErr != "")
		return msgErr;
	return true;
}

//	-------------------------------------------------------------------------
//	gshpSetCarrierPrice
//	Display of shipping price
//	- radio is html element or radio id
//	-------------------------------------------------------------------------
function gshpSetCarrierPrice(radio, cost, vatCost, costDescr, zone, label, sCost, sVatCost) {
	if (sCost == null) sCost = formatCurrency(cost);
	if (sVatCost == null) sVatCost = formatCurrency(vatCost);

	var shippingCost = document.getElementById("shippingCost");
	if (shippingCost != null)
		shippingCost.value = cost;
	var shippingVatCost = document.getElementById("shippingVatCost");
	if (shippingVatCost != null)
		shippingVatCost.value = vatCost;
	var shippingCostDescr = document.getElementById("shippingCostDescr");
	if (shippingCostDescr != null)
		shippingCostDescr.value = costDescr;
	var shippingZone = document.getElementById("shippingZone");
	if (shippingZone != null)
		shippingZone.value = zone;
	var shippingLabel = document.getElementById("shippingLabel");
	if (shippingLabel != null)
		shippingLabel.value = label;
	var fatherSpan = document.getElementById("fullShippingPrice");
	if (fatherSpan == null) return;

	fatherSpan.style.display = "inline";
	var span = document.getElementById("shippingPrice");
	if (span != null)
		span.innerHTML = sCost;
	var span = document.getElementById("shippingVatPrice");
	if (span != null)
		span.innerHTML = sVatCost;

}

//	-------------------------------------------------------------------------
//	gshpCheckShippingForm
//	Checking of shipping form
//	-------------------------------------------------------------------------
function gshpCheckShippingForm(inputName)
{
	var carriers = document.forms.shipping.elements[inputName];
	if (carriers == null) return false;
	if (typeof(carriers.length) == "number") {
		for (var i=0; i<carriers.length; i++) {
			if (carriers[i].checked) return true;
		}
	} else {
		if (carriers.checked) return true;
	}

	// Management of error
	var msgErr = objThesaurus.translate("gshpChooseCarrier");
	return msgErr;
}

//	-------------------------------------------------------------------------
//	gshpCheckAddressesForm
//	Checking of addresses form
//	-------------------------------------------------------------------------
function gshpCheckAddressesForm()
{
	var shippingAddressInput = document.getElementById("shippingAddressSelect");
	var invoiceAddressInput = document.getElementById("invoiceAddressSelect");
	var hasShippingAddressInput = (shippingAddressInput != null);
	var hasInvoiceAddressInput = (invoiceAddressInput != null);

	// Management of error
	var msgErr = "";
	if(hasShippingAddressInput && shippingAddressInput.value == -1) msgErr = objThesaurus.translate("gshpChooseShippingAddress");
	if(hasInvoiceAddressInput && invoiceAddressInput.value == -1) msgErr = objThesaurus.translate("gshpChooseInvoiceAddress");
	if((hasInvoiceAddressInput && invoiceAddressInput.value == -1) && (hasShippingAddressInput && shippingAddressInput.value == -1)) msgErr = objThesaurus.translate("gshpChooseAddresses");
	if(msgErr != "") return msgErr;
	return true;
}

//	-------------------------------------------------------------------------
//	gshpCheckPaymentForm
//	Checking of payment form
//	-------------------------------------------------------------------------
function gshpCheckPaymentForm()
{
	var payments = document.forms.payment.elements.payment;
	if (payments == null) return false;
	if (typeof(payments.length) == "number") {
		for (var i=0; i<payments.length; i++) {
			if(payments[i].checked) return true;
		}
	} else {
		if (payments.checked) return true;
	}

	// Management of error
	var msgErr = objThesaurus.translate("gshpChoosePayment");
	return msgErr;
}

//	-------------------------------------------------------------------------
//	gshpInitRegionsCombo
//	Initialization of step 2 region combos
//	-------------------------------------------------------------------------
function gshpInitRegionsCombo(ajaxPage, manageClientCompany, manageClientIndividual, regionManageableCountries)
{
	isoYUILoader.onReady( function() {
		YAHOO.util.Event.onDOMReady(function () {
			var myDS = new YAHOO.util.XHRDataSource(ajaxPage);
			myDS.responseSchema = {   
				resultNode: "region",
				fields: ["oid", "label", "country"]
			};   
			myDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
			if(manageClientIndividual)
			{
				YAHOO.util.Event.onContentReady("gshpBasketTable_clientIndividual", function() {
					var individualCountryCombo = document.getElementById("ctrl_clientI_country");
					var individualRegionCombo = document.getElementById("ctrl_clientI_region");
					var individualRegionComboLabel = document.getElementById("ctrl_clientI_regionLabel");
					var individualRegionComboFailure = document.getElementById("ctrl_clientI_region_failed");
					
					YAHOO.util.Event.on(individualCountryCombo, "change", function(e) {
						myDS.sendRequest("?pageMode=ajax&ajaxFunc=getRegions&country="+individualCountryCombo.value, { 
							success : function (req,res) {
								individualRegionCombo.options.length = 0;
								individualRegionCombo.options[individualRegionCombo.options.length] = new Option("--- choisir une région ---", "");
								if (res.results[0] && regionManageableCountries.indexOf(res.results[0].country) == -1)
								{
									for(var i = 0; i < res.results.length; i++)
									{
										individualRegionCombo.options[individualRegionCombo.options.length] = new Option(res.results[i].label, res.results[i].oid);
									}
								}
								if(individualRegionCombo.options.length == 1)
								{
									individualRegionCombo.style.display = "none";
									individualRegionComboLabel.style.display = "none";
									individualRegionComboFailure.style.display = "none";
								}
								else
								{
									individualRegionCombo.style.display = "inline";
									individualRegionComboLabel.style.display = "inline";
								}
							}
						});
					});
				});
			}
			if(manageClientCompany)
			{
				YAHOO.util.Event.onContentReady("gshpBasketTable_clientCompany", function() {
					var companyCountryCombo = document.getElementById("ctrl_clientC_country");
					var companyRegionCombo = document.getElementById("ctrl_clientC_region");
					var companyRegionComboLabel = document.getElementById("ctrl_clientC_regionLabel");
					var companyRegionComboFailure = document.getElementById("ctrl_clientC_region_failed");
					
					YAHOO.util.Event.on(companyCountryCombo, "change", function(e) {
						myDS.sendRequest("?pageMode=ajax&ajaxFunc=getRegions&country="+companyCountryCombo.value, { 
							success : function (req,res) {
								companyRegionCombo.options.length = 0;
								companyRegionCombo.options[companyRegionCombo.options.length] = new Option("--- choisir une région ---", "");
								if (res.results[0] && regionManageableCountries.indexOf(res.results[0].country) == -1)
								{
									for(var i = 0; i < res.results.length; i++)
									{
										companyRegionCombo.options[companyRegionCombo.options.length] = new Option(res.results[i].label, res.results[i].oid);
									}
								}
								if(companyRegionCombo.options.length == 1)
								{
									companyRegionCombo.style.display = "none";
									companyRegionComboLabel.style.display = "none";
									companyRegionComboFailure.style.display = "none";
								}
								else
								{
									companyRegionCombo.style.display = "inline";
									companyRegionComboLabel.style.display = "inline";
								}
							}
						});
					});
				});
			}
		});
	});
}

function gshpUpdateRegionsListOnClientTypeClick(ajaxPage, isIndividual, selectedValue)
{
	var individualCountryCombo = document.getElementById("ctrl_clientI_country");
	var companyCountryCombo = document.getElementById("ctrl_clientC_country");
	var individualRegionCombo = document.getElementById("ctrl_clientI_region");
	var companyRegionCombo = document.getElementById("ctrl_clientC_region");
	
	var countryComboValue = isIndividual ? individualCountryCombo.value : companyCountryCombo.value;
	var regionCombo = isIndividual ? individualRegionCombo : companyRegionCombo;
	
	var myDS = new YAHOO.util.XHRDataSource(ajaxPage);
	myDS.responseSchema = {   
		resultNode: "region",
		fields: ["oid", "label", "country"]
	};   
	myDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
	
	myDS.sendRequest("?pageMode=ajax&ajaxFunc=getRegions&country="+countryComboValue, { 
		success : function (req,res) {
			regionCombo.options.length = 0;
			regionCombo.options[regionCombo.options.length] = new Option("--- choisir une région ---", "");
			if (res.results[0])
			{
				for(var i = 0; i < res.results.length; i++)
				{
					regionCombo.options[regionCombo.options.length] = new Option(res.results[i].label, res.results[i].oid);
					if(res.results[i].oid == selectedValue) regionCombo.selectedIndex = regionCombo.options.length - 1;
				}
			}
		}
	});
}

//	-------------------------------------------------------------------------
//	gshpInitRegionsAddressesCombo
//	Initialization of step 3 region combos
//	-------------------------------------------------------------------------
function gshpInitRegionsAddressesCombo(ajaxPage, canInvoiceElsewhere, canShipElsewhere, regionManageableCountries)
{
	isoYUILoader.onReady( function() {
		YAHOO.util.Event.onDOMReady(function () {
			var myDS = new YAHOO.util.XHRDataSource(ajaxPage);
			myDS.responseSchema = {   
				resultNode: "region",
				fields: ["oid", "label", "country"]
			};   
			myDS.responseType = YAHOO.util.XHRDataSource.TYPE_XML;
			
			YAHOO.util.Event.onContentReady("addressesTable", function() {
				if(canInvoiceElsewhere)
				{
					var invoiceCountryCombo = document.getElementById("ctrl_invoiceAddress_country");
					var invoiceRegionCombo = document.getElementById("ctrl_invoiceAddress_region");
					var invoiceRegionComboLabel = document.getElementById("ctrl_invoiceAddress_regionLabel");
					var invoiceRegionComboFailure = document.getElementById("ctrl_invoiceAddress_region_failed");
					
					YAHOO.util.Event.on(invoiceCountryCombo, "change", function(e) {
						myDS.sendRequest("?pageMode=ajax&ajaxFunc=getRegions&country="+invoiceCountryCombo.value, { 
							success : function (req,res) {
								invoiceRegionCombo.options.length = 0;
								invoiceRegionCombo.options[invoiceRegionCombo.options.length] = new Option("--- choisir une région ---", "");
								if (res.results[0] && regionManageableCountries.indexOf(res.results[0].country) == -1)
								{
									for(var i = 0; i < res.results.length; i++)
									{
										invoiceRegionCombo.options[invoiceRegionCombo.options.length] = new Option(res.results[i].label, res.results[i].oid);
									}
								}
								if(invoiceRegionCombo.options.length == 1)
								{
									invoiceRegionCombo.style.display = "none";
									invoiceRegionComboLabel.style.display = "none";
									invoiceRegionComboFailure.style.display = "none";
								}
								else
								{
									invoiceRegionCombo.style.display = "inline";
									invoiceRegionComboLabel.style.display = "inline";
								}
							}
						});
					});
				}
				
				if(canShipElsewhere)
				{
					var shippingCountryCombo = document.getElementById("ctrl_shippingAddress_country");
					var shippingRegionCombo = document.getElementById("ctrl_shippingAddress_region");
					var shippingRegionComboLabel = document.getElementById("ctrl_shippingAddress_regionLabel");
					var shippingRegionComboFailure = document.getElementById("ctrl_shippingAddress_region_failed");
					
					YAHOO.util.Event.on(shippingCountryCombo, "change", function(e) {
						myDS.sendRequest("?pageMode=ajax&ajaxFunc=getRegions&country="+shippingCountryCombo.value, { 
							success : function (req,res) {
								shippingRegionCombo.options.length = 0;
								shippingRegionCombo.options[shippingRegionCombo.options.length] = new Option("--- choisir une région ---", "");
								if (res.results[0] && regionManageableCountries.indexOf(res.results[0].country) == -1)
								{
									for(var i = 0; i < res.results.length; i++)
									{
										shippingRegionCombo.options[shippingRegionCombo.options.length] = new Option(res.results[i].label, res.results[i].oid);
									}
								}
								if(shippingRegionCombo.options.length == 1)
								{
									shippingRegionCombo.style.display = "none";
									shippingRegionComboLabel.style.display = "none";
									shippingRegionComboFailure.style.display = "none";
								}
								else
								{
									shippingRegionCombo.style.display = "inline";
									shippingRegionComboLabel.style.display = "inline";
								}
							}
						});
					});
				}
			});
		});
	});
}

//	-------------------------------------------------------------------------
//	Address manager
//	Selection of addresses
//	-------------------------------------------------------------------------
function GshpAddressManager(addressEditorUrl, clientEditorUrl, addressList, creationShippingAddressType, creationInvoiceAddressType)
{
	this._addressEditorUrl = addressEditorUrl;
	this._clientEditorUrl = clientEditorUrl;
	this._addressMap = {};
	for(var i=0;i<addressList.length;i++) {
		var record = addressList[i].split("|");
		this._addressMap[record[0]] = record;
	}
	this._states = {"invoiceAddress":"","shippingAddress":""};		// Value of selected option
	this._selectedIndex = {"invoiceAddress":0,"shippingAddress":0};	// Index of selected option

	// Types can be shipping, invoice or common
	this._creationShippingAddressType = creationShippingAddressType;
	this._creationInvoiceAddressType = creationInvoiceAddressType;
}
GshpAddressManager.prototype.protectCData = function(str)
{
	if(str == null) return "";
	str = str + "";
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	return str;
}
GshpAddressManager.prototype.onchange = function(select)
{
	var name = select.name;
	var value = select.value;
	var submitChange = this.change(name, value, select);
	if (submitChange == true)
		this.submit();
}
GshpAddressManager.prototype.change = function(name, value, select)
{
	if (select == null) select = document.getElementById(name + "Select");

	// Creation
	if(value == "new") {
		var params = "?adrType=" + name;
		if (name == "shipppingAddress")
			params += (this._creationShippingAddressType ? "&creationAdrType=" + this._creationShippingAddressType : "")
		else
		if (name == "invoiceAddress")
			params += (this._creationInvoiceAddressType ? "&creationAdrType=" + this._creationInvoiceAddressType : "")
		showModalWindow(this._addressEditorUrl + params, "addressEditor", "400", "400");

		if ((select != null) && (this._selectedIndex[name] != null))
			select.selectedIndex = this._selectedIndex[name];
		return false;
	}

	// Save of status
	this._lastAddress = name;
	this._states[name] = value;
	this._selectedIndex[name] = ((select != null) ? select.selectedIndex : 0);

	// Display
	var addressLink = document.getElementById(name + "Link");
	if(addressLink != null) {
		var display = ((value == "") || (value == "0") || (value == "-1")) ? "none" : "block";
		addressLink.parentNode.style.display = display;
	}
	var record = this._addressMap[value];
	if(record == null) 
		return true;
	var recordTitle = this.protectCData(record[1]);
	var recordSubTitle = this.protectCData(record[2]);
	if ((recordTitle == "") || (recordSubTitle == "")) {
		recordTitle = recordTitle || recordSubTitle;
		recordSubTitle = "";
	}
	var addressTitle = document.getElementById(name + "Title");
	if(addressTitle != null) addressTitle.innerHTML = recordTitle;
	var addressSubTitle = document.getElementById(name + "SubTitle");
	if(addressSubTitle != null) {
		addressSubTitle.innerHTML = recordSubTitle;
		addressSubTitle.style.display = (recordSubTitle != "") ? "block" : "none";
	}
	var addressLines = document.getElementById(name + "Lines");
	if(addressLines != null)
	{
		addressLines.innerHTML = this.protectCData(record[3].replace(/\n+$/,"")).replace(/\n/g, "<br/>");
	}
	var addressCity = document.getElementById(name + "City");
	if(addressCity != null)
	{
		addressCity.innerHTML = this.protectCData(record[4]);
	}
	var addressCountry = document.getElementById(name + "Country");
	if(addressCountry != null)
	{
		addressCountry.innerHTML = this.protectCData(record[5]);
	}
	return true;
}

GshpAddressManager.prototype.editAddress = function(a)
{
	var id = a.id;
	var lastAddress = this._lastAddress = (id.indexOf("shipping") >= 0) ? "shippingAddress" : "invoiceAddress";
	var state = this._states[lastAddress];
	showModalWindow(this._addressEditorUrl + "?address=" + state, "addressEditor", "400", "400");
	return false;
}
GshpAddressManager.prototype.editClient = function(client)
{
	showModalWindow(this._clientEditorUrl + "?client=" + client, "addressEditor", "800", "430");
	return false;
}


GshpAddressManager.prototype.submit = function()
{
	document.forms.addressesForm.submitButton.click();
}

GshpAddressManager.prototype.update = function()
{
	this.submit();
}

GshpAddressManager.prototype.create = function(oid, adrType)
{
	if ((adrType == null) || (adrType == "")) adrType = this._lastAddress;

	var select = document.getElementById(adrType + "Select");
	var option = document.createElement("option");
	option.value = oid;
	select.options.add(option);
	select.selectedIndex = select.options.length - 1;
	this.submit();
}

GshpAddressManager.prototype.remove = function(oid)
{
	var select = document.getElementById(this._lastAddress + "Select");
	select.selectedIndex = 0;
	this.submit();
}

function GshpDelayManager()
{
	this._initialized = false;
}

GshpDelayManager.prototype.init = function()
{
	if(this._initialized) return;
	this._initialized = true;
	this._productInputs = {};
	this._referenceInputs = {};
	this._referenceProducts = {};
	this._topCheckbox = document.getElementById("multiSelectionAll_Top");
	this._bottomCheckbox = document.getElementById("multiSelectionAll_Bottom");
	var i = 0;
	var lastProductOid = null;
	while(true) {
		var form = document.getElementById("selectForm_" + i);
		if(!form) break;
		i++;
		var checkbox = null;
		for(var j=0;j<form.childNodes.length;j++) {
			var child = form.childNodes[j];
			if(child.tagName == "INPUT") {
				checkbox = child;
				break;
			}
		}
		if(!checkbox) continue;
		var id = checkbox.id;
		var fields = id.split("_");
		switch(fields[0]) {
		case "multiSelectionProduct":
			this._productInputs[fields[1]] = checkbox;
			lastProductOid = fields[1];
			break;
		case "multiSelectionReference":
			this._referenceInputs[fields[1]] = checkbox;
			this._referenceProducts[fields[1]] = lastProductOid;
			break;
		}
	}
}

GshpDelayManager.prototype.selectAll = function(input)
{
	this.init();
	var checked = input.checked;
	for(var k in this._productInputs) {
		var input = this._productInputs[k];
		input.checked = checked;
	}
	for(var k in this._referenceInputs) {
		var input = this._referenceInputs[k];
		input.checked = checked;
	}
	this._topCheckbox.checked = checked;
	this._bottomCheckbox.checked = checked;
	return false;
}

GshpDelayManager.prototype.change = function()
{
	this.init();
	var referenceOids = "";
	for(var referenceOid in this._referenceInputs) {
		var checkbox = this._referenceInputs[referenceOid];
		if(checkbox.checked) {
			if(referenceOids != "") referenceOids += " ";
			referenceOids += referenceOid;
		}
	}
	var input = document.getElementById("c_references");
	input.value = referenceOids;
	var form = document.forms.expectedShippingDateForm;
	form.submit();
	return false;
}

GshpDelayManager.prototype.selectProduct = function(input)
{
	this.init();
	var checked = input.checked;
	var id = input.id;
	var fields = id.split("_");
	var productOid = fields[1];
	for(var k in this._referenceInputs) {
		if(this._referenceProducts[k] == productOid) {
			this._referenceInputs[k].checked = checked;
		}
	}
	if(!checked) {
		this._topCheckbox.checked = checked;
		this._bottomCheckbox.checked = checked;
	}
	return false;
}

GshpDelayManager.prototype.selectReference = function(input)
{
	this.init();
	var checked = input.checked;
	var id = input.id;
	var fields = id.split("_");
	var referenceOid = fields[1];
	if(!checked) {
		var checkbox = this._productInputs[this._referenceProducts[referenceOid]];
		checkbox.checked = checked;
		this._topCheckbox.checked = checked;
		this._bottomCheckbox.checked = checked;
	}
	return false;
}

var gshpDelayManager = new GshpDelayManager();
