//Global variable to check if form has already been submitted
			var IsFormSubmitted = false;
			
			function onDeleteClick(id)
			{
				//Check if form is already submitted
				if( IsFormSubmitted )
				{
					return false;
				}
				
				/*if( validateAllQuantities() )
				{*/
				var bClicked = confirm('Are you sure you want to delete this item from your shopping cart?');
				if(bClicked)
				{
					IsFormSubmitted = true;
				}
				return bClicked;
				/*}
				else
				{
					return false;
				}*/
			}
			
			function onMoveToWishListClick(id)
			{
				//Check if form is already submitted
				if( IsFormSubmitted )
				{
					return false;
				}

				if( !IsCustomerLoggedIn )
				{
					alert("You must log in to add this item to your wish list.");
					return false;
				}
				else
				{
					if( validateAllQuantities() )
					{
						IsFormSubmitted = true;
						return true;
					}
					else
					{
						return false;
					}
				}
			}

			function SetOnShoppingCartQtyFocus(e) {
				var key;
				if (window.event) {
					key = e.keyCode;
				}
				else if (e.which) {
					key = e.which;
				}
				if (key == 13) {
					ControlToSubmit = "ShoppingCart";
					if (SubmitOnLostFocus()) {
						return true;
					}
				}
			}
			
			//Validate the quantity and submit.
			function validateQtyAndSubmit(e)
			{
				var key;
				if( window.event ) 
				{
					key = e.keyCode;
				}
				else if( e.which )
				{
					key = e.which;
				}				
				if( key != 13 ) 
				{
					return maskInteger(e);
				}
				else
				{
				    //If it is the enter key , detach the onblur event for now so that
				    //validateAllQuantities() function wont be called twice .
				    window.event.srcElement.onblur = null;
				}

				var canSubmit = validateAllQuantities();
				if( canSubmit )
				{
					IsFormSubmitted = true;
					__doPostBack('UpdateQty','');
				}
				else
				{
					return false;
				}
			}
			function SubmitOnLostFocus() 
			{
			    var textBox = event.srcElement;
                var hiddenField = textBox.parentElement.children['lastQty'];
                if(parseInt(hiddenField.value) != parseInt(textBox.value))
                {
			        //var canSubmit = validateAllQuantities();
				    //if( canSubmit )
				   // {
					    IsFormSubmitted = true;
					    __doPostBack('UpdateQty','');
				    //}
			    }
			}
            function StoreChangedQty()
            {
                var textBox = event.srcElement;
                var hiddenField = textBox.parentElement.children['lastQty'];
                hiddenField.value = textBox.value;
            }
			//Validate the uom and submit.
			function validateUOMAndSubmit()
			{
				if( validateAllQuantities() )
				{
					IsFormSubmitted = true;
					__doPostBack('UpdateQty','');
				}
				else
				{
					return false;
				}
			}
		
		//Generic Function to Check whether the field value is Numeric
            function isNumericQty(fieldValue)
            {
	            
	            var strValue = String(fieldValue);
	            var len	= strValue.length;
	            if(len>0)
	            {
		            for(var i=0; i < len; i++)
		            {
			            var charCode = strValue.charCodeAt(i); 
			            if((charCode < 48 || charCode > 57))
			            {
				            return false;
			            }
		            }
		            return true;
	            }	
	            return false;
            }		
		    function ContainsProduct(ProductId,arrList)
		    {
		        for(var i=0;i< arrList.length;i++)
				{
		            if(arrList[i][0] == ProductId)
					{
		                return true;
		            }
		        }
		        return false;
		    }
		    
		    function ReturnProductQuantityData(ProductId,arrList)
			{
		        for(var i=0;i< arrList.length;i++)
				{
		            if(arrList[i][0] == ProductId)
					{
		                return arrList[i][1];
		            }
		        }
		        return false;
		    }
		    
		    function SetProductQuantityData(ProductId,qty,arrList){
		        for(var i=0;i< arrList.length;i++){
		            if(arrList[i][0] == ProductId){
		                arrList[i][1] = qty;
		            }
		        }
		    }
		    function GetLineItemQtyBoxwithMaxQty(ProductId,arrList){
		        var MaxQtyBox;
		        var MaxQty;
		        
		         for(var i=0;i< arrList.length;i++){
		            if(arrList[i][0] == ProductId){
		                if(i==0){
		                    MaxQtyBox = arrList[i][2];
		                    MaxQty    = arrList[i][2].value;
		                }else{
		                    if(arrList[i][2].value > MaxQty){
		                        MaxQtyBox = arrList[i][2];
		                        MaxQty    = arrList[i][2].value;
		                    }
		                }
		            }
		        }
		        return MaxQtyBox;
		    }
		    var srcElementId ;	
			//Validate the quantity for all the quantity fields.
			function validateAllQuantities() {

				if (ControlToSubmit == "loginWidgetSubmit") {

					if (loginWidgetSetFocus())
						ControlToSubmit = "";

					return false;
				}
				
				//Check if form is already submitted
				if( IsFormSubmitted )
				{
					return false;
				}
                var qtyonOrder = new Array();
                
				//Products is sent using RegisterClientScript method of cs class.		
			    var maxQtyForProduct = new Array(2);
			    var arrItemAtpQtys = new Array();
			    //If the onblur event for the quantity text box is detached ,
			    //attach it again here.
			    
				for(i=0; i < Products.length; i ++)
				{
					//get the Qty field
					//alert("Lines_ctl0" + i + "_BLine_ctl00_Qty");
				    //mismatch while comparing name of the control with qtyfieldId 
				    if (i < 9)
				    {	
					    var qtyfieldId = "Lines_ctl0" + parseInt(i+1) + "_BLine_ctl00_Qty";
					    var uomfieldId = "Lines_ctl0" + parseInt(i+1) + "_BLine_ctl00_UnitList";
					}
					else
					{
					    var qtyfieldId = "Lines_ctl" + parseInt(i+1) + "_BLine_ctl00_Qty";
					    var uomfieldId = "Lines_ctl" + parseInt(i+1) + "_BLine_ctl00_UnitList";					
					}					
					
					try
					{
					    	    
					   		         
						var qtyfield = document.getElementById(qtyfieldId);						
						var uomfield = document.getElementById(uomfieldId);			
						
						if( !isNumericQty( qtyfield.value) )
						{						    
							alert("The entered quantity for the order line is not valid. You must edit the \"Quantity\" before you can continue.");
							field.focus();
							return false;						
						}	
						var qty = parseInt(qtyfield.value, 10);
						
						var newQty = qty;
						if(Products[i].Status != "Active"){
						    if(!ContainsProduct(Products[i].Id ,qtyonOrder ))
							{
					            qtyonOrder[qtyonOrder.length] = new Array(Products[i].Id,qty,qtyfield);
					            newQty = qty;
					        }
							else
							{    					        
					            var ProductQty = ReturnProductQuantityData(Products[i].Id ,qtyonOrder);
					            if(ProductQty != null )
								{
					                var oldQty =  ProductQty;
					                newQty =  oldQty + qty;
					                SetProductQuantityData(Products[i].Id ,newQty,qtyonOrder);
					            }
					        }
					    }
						//sachin
						//var uom = uomfield.value;
						//Hardcoded each value for the time being
						var uom = '{6AA23C56-7A4F-11D2-84B0-0000F80627E2}';
						var prd = Products[i];
						prd.SelectedUOM = GetSelectedUOM(prd, uom);	
						
						if(arrItemAtpQtys[Products.Id] == null)
					    {
					        arrItemAtpQtys[Products.Id] = Products[i].SelectedUOM.MaxQty;
					    }
					    else
					    {
					        var MaxQty =  parseInt(Products[i].SelectedUOM.MaxQty);
					        if(parseInt(arrItemAtpQtys[Products.Id]) < MaxQty)
					        {
					            arrItemAtpQtys[Products.Id] = Products[i].SelectedUOM.MaxQty;
					        }
					    }
					    				
						if( qty < prd.SelectedUOM.MinQty )
						{						
							alert("The entered quantity for the order line is less than the minimum quantity ("+prd.SelectedUOM.MinQty+") allowed. You must edit the \"Quantity\" before you can continue.");
							qtyfield.focus();
							AttachOnBlurEvent();
							return false;							
						}
						if( qty > prd.SelectedUOM.MaxQtyPerLine)
						{
						    alert("The entered quantity for the order line item "+prd.ItemName+" is more than the maximum quantity ("+prd.SelectedUOM.MaxQtyPerLine+") allowed per line. You must edit the \"Quantity\" before you can continue.");
							qtyfield.focus();
							AttachOnBlurEvent();
							return false;
						}
						if( newQty > prd.SelectedUOM.MaxQty  && prd.Status != "Active")
						{						
							alert("The entered quantity for the order line item "+prd.ItemName+" is more than the maximum quantity ("+arrItemAtpQtys[Products.Id]+") allowed. You must edit the \"Quantity\" before you can continue.");
							//debugger
							if(srcElementId == null )
							{
							    srcElementId = window.event.srcElement.id;
							}
							if(window.event.srcElement.type == "text" && window.event.srcElement.id == srcElementId)
			                {
			                    window.event.srcElement.focus();
            			    }
							AttachOnBlurEvent();
							return false;
						}
						
						
					}
					catch(e)
					{
						alert("The entered quantity for the order line is not valid. You must edit the \"Quantity\" before you can continue catch.");
						qtyfield.focus();
                        AttachOnBlurEvent()
						return false;
					}
				}
				return true;
			}		
			
			function AttachOnBlurEvent()
			{
			    
			    if(window.event.srcElement.onblur ==  null && window.event.srcElement.type == "text")
			    {
			        window.event.srcElement.onblur =  function(){SubmitOnLostFocus()}
			        
			    }
			}
			
			function launchModalWindow(url)
			{
				var retVal = validateAllQuantities();
				if( retVal ) 
					ShowCustomModalDialog(url, 500, 520,true);
				else
					return false;	
			}

			//define the product object.
			function Product()
			{
				this.Id = null;
				this.SelectedUOM = null;
				this.UOMDetails = new Array();
			}
			
			//define the product object.
			function UOMDetail()
			{
				this.UOMID = "";
				this.MinQty = 1;
				this.MaxQty = 1;
			}
			
			//get selected UOM
			function GetSelectedUOM(product, uomID)
			{
				//Get the selected UOM
				var uomData;
				for(var i=0; i<product.UOMDetails.length; i++)
				{
					uomData = product.UOMDetails[i];
					if(uomData != null && uomData.UOMID == uomID)
					{
						return uomData;
					}
				}
			}
			
			//To Enabe and Disable the fields in GiftOption page - START
            function EnableDisableGiftOptionFields(IsDisabled)
            {
                if(IsDisabled == 'false')
                {
                    document.forms[0].RecipientName.disabled = false;
                    document.forms[0].SenderName.disabled = false;
                    document.forms[0].Message.disabled = false;
                    
                }
                else
                {
                    if(document.forms[0].hdnIsRadioSelected.value == 'false')
                    {
                        document.forms[0].RecipientName.disabled = true;
                        document.forms[0].SenderName.disabled = true;
                        document.forms[0].Message.disabled = true;
                    }
                }
                
            }
            //To Enabe and Disable the fields in GiftOption page - END
