// ©2002 American Honda Motor Co., Inc.
//******************************************************************************
// Functions used for clinet side shopping cart

// Holds the table definition
var tabdef= new String();

//Dhiraj K Sharma : Variable added for TaskID 101
var strPrintHTML ="";
strPrintHTML += '<map name=FPMap2><area href="#"';
// onClick="';
// strPrintHTML += strWhichPagePE;
strPrintHTML += '" shape="rect" coords="169, 6, 246, 24"></map>';
strPrintHTML += '<img usemap="#FPMap2" src="../images/es_1_shp_cartHDR_print.gif" width="254 height="27" border="0" />';
		
// P arrays (always holds the current information in the shopping cart)

var Pnumber
var Pdesc
var Pprice
var Pqty
var Ptooltip
var Pdiy
var Pimagepath
var Pcategory
var curr_size


 curr_size = -1
 Pnumber = new Array()
 Pdesc= new Array()
 Pprice = new Array()
 Pqty = new Array()
 Ptooltip= new Array()
 Pdiy = new Array()
 Pimagepath = new Array()
 Pcategory = new Array()

// current size of P arrays
//var curr_size=-1;
var PP= new Array();

// Arrays to hold changes
var CPnumber = new Array()
var CPqty = new Array()
var CIndex=-1;
		
var datee=new Date()

//String that holds the HTML for an empty shopping cart
var strEmptyBasketHTML ="";

//Variable added by Neeraj for Issue 353
var blnSubmit=false;
//Variable added by Neeraj for Issue 353

strEmptyBasketHTML+='<table width="255" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'
strEmptyBasketHTML+='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
strEmptyBasketHTML+='<td width="10" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="10" height="1" alt="" border="0" /></td>'
strEmptyBasketHTML+='<td width="34" height="20" bgcolor="#D2D2D2" align="left" class="label" valign="middle"><strong>Qty.</strong></td>'
strEmptyBasketHTML+='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="21" alt="" border="0" /></td>'
strEmptyBasketHTML+='<td bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="16" height="1" alt="" border="0" /></td>'
strEmptyBasketHTML+='<td width="140" height="20" bgcolor="#D2D2D2" class="label" valign="middle" align="left"><strong>Description</strong></td>'
strEmptyBasketHTML+='<td width="60" height="20" bgcolor="#D2D2D2" valign="middle" class="label" align="right"><strong>Total</strong></td>'
strEmptyBasketHTML+='<td width="2" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="3" height="1" alt="" border="0" /></td>'
strEmptyBasketHTML+='</tr><table>'


strEmptyBasketHTML+='<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="1" bgcolor="#D2D2D2"><img height="1" alt src="../images/spacer.gif" width="1" border="0"></td>'
//Modification made by Neeraj on Aug 23,2004 for Issue 305 (td align=center") starts here
strEmptyBasketHTML+='<td width="2"><img height="1" alt src="../images/spacer.gif" width="2" border="0"></td><td class="label" height="262" align="center" width="246" >'
//Modification made by Neeraj on Aug 23,2004 for Issue 305 (td align=center") ends here
strEmptyBasketHTML+='Your Shopping Cart is empty</td><td width="3"><img height="1" alt src="../images/spacer.gif" width="2" border="0"></td>'
strEmptyBasketHTML+='<td width="1"><img height="1" alt src="../images/spacer.gif" width="1" border="0"></td></tr></tbody></table>'


tabdef='<table cellspacing="0" cellpadding="0" border="0" width="255"><tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td><td width="10" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="10" height="1" alt="" border="0" /></td><td width="25" height="20" bgcolor="#D2D2D2" align="left" class="label" valign="middle"><strong>Qty.</strong></td><td width="3" bgcolor="#D2D2D2"></td><td width="6" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="6" height="1" alt="" border="0" /></td></td><td width="150" height="20" bgcolor="#D2D2D2" class="label" valign="middle"><strong>Description</strong></td><td width="65" height="20" bgcolor="#D2D2D2" valign="middle" align="right" class="label"><strong>Total</strong></td><td width="2" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr>'
	

function getPValues(Hvalue)
{

	if (curr_size == -1)
		return "";
	else
	{
		if (Hvalue == "number")
			return Pnumber;			
		if (Hvalue == "desc")
		{
			var strPValues = Pdesc[0];
			for (var j=1; j<=curr_size; j++)
			{		
				strPValues += "|";	
				strPValues += Pdesc[j];
			}
			return strPValues;
		}
		if (Hvalue == "price")
			return Pprice;
		if (Hvalue == "qty")
			return Pqty;
		if (Hvalue == "tooltip")
		{
			var strTValues = Ptooltip[0];
			for (var j=1; j<=curr_size; j++)
			{		
				strTValues += "|";	
				strTValues += Ptooltip[j];
			}
			return strTValues;
		}
			
		if (Hvalue == "diy")
			return Pdiy;
		if (Hvalue == "imagepath")
			return Pimagepath;
		if (Hvalue == "category")
			return Pcategory;
	}
}

function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//As name indicates format currency
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


// Add an item to shopping cart
// Basically invoke ADD Array function
function AddCart(iModelNo,number,desc,qty,price,tooltip,diy,imagepath,category)
{ 	

	//Dhiraj K Sharma for TaskID 101
	document.getElementById('removeImages').innerHTML = strPrintHTML;
			
	//Disable adding if price = 0
	if (price < 0.01){
	//document.getElementById("removeImages").innerHTML="<img src='../images/es_1_shp_cartHDR.gif' width='254' height='27' border='0' />"
		alert('Sorry, this item is not currently available for purchase');
		if (curr_size == -1){				
		document.getElementById("removeImages").innerHTML="<img src='../images/es_1_shp_cartHDR.gif' width='254' height='27' border='0' />"
		}
		return;				
	
	}

	
   //Disable user from adding same item to cart twice
	for ( var p=0; p<=curr_size; p++)
	{
	
		if(Pdesc[p]==desc)
		{	
		   // if accessory, see if adding same accessory with different price
		   // if so, update price (to accomodate switching from DI/DIY)
			if(category.indexOf(':A:') > -1){
   			Pprice[p] = price;
   			Pdiy[p]=diy;
				Update();
			}
			return;
		} 
	}
	
	//Update link positions (if they exist --> Should exist on LandingWithDealer for units only)
   if (document.getElementById('AddAcc' + desc) != null)
   {
	   var xAddCart = "document.getElementById('AddAcc" + desc + "').style.visibility = " + "'visible'";
	   eval(xAddCart); 
   	
	   var iPos = document.getElementById("pos").value;
	   var xPos = document.getElementById("xpos").value;
   	
	   xAddCart = "document.getElementById('AddAcc" + desc + "').style.top = " + iPos;
	   eval(xAddCart); 
   	
	   document.getElementById("pos").value = iPos*1 + 16;
	   
	   // drop buttons if too many add accessory links
	   if (document.getElementById("pos").value > 433)
	   {	      
	      var buttonPos = document.getElementById("iButtons").style.top;
	      // find position of 'px' and remove it from the position
	      buttonPos = buttonPos.substring(0,buttonPos.indexOf('px'));
	      // drop it by 16 pixels
	      document.getElementById("iButtons").style.top = parseInt(buttonPos) + 16;
	      document.getElementById("xpos").value = xPos*1 + 16
	   }
	}

	//Start REAL AddCart function
	if (curr_size == -1 )
	{ 
		curr_size= 0;	
		AddArray(number,desc,qty,price,tooltip,0,diy,imagepath,category)
		//document.getElementById("removeImages").innerHTML="<img src='../images/es_1_shp_cartHDR.gif' width='254' height='27' border='0' />"
	}
	 else
		{
			//Dhiraj K Sharma for TaskID 101
			document.getElementById('removeImages').innerHTML = strPrintHTML;

			var found=false;
			for (var loop_index=0;loop_index <=curr_size;loop_index++)
			{
				if (Pnumber[loop_index]==number)
					{ 
						if (document.getElementById) //IE or NS 5 & above
						{
							if (isNaN(eval('document.getElementById(qty).value')))
								var integer = 1
							else
								// Modified by Nisheeth on 09-25-2003
								//var integer= eval(document.getElementById(qty).value )
								var integer = getCorrectvalue ((document.getElementById(qty).value));
						}
						else //NS 4
						{
							if (isNaN(eval('document.form1.elements[qty].value')))
								var integer = 1
							else
								// Modified by Nisheeth on 09-25-2003
								//var integer= eval(document.form1.elements[qty].value )
								var integer = getCorrectvalue ((document.getElementById(qty).value));
						}
						if (isNaN(eval ('integer')))
						{
							integer = 1;
						}
						var integer2=eval(Pqty[loop_index])
						// Modified by Nisheeth on 09-26-2003
						integer2 = getCorrectvalue (integer2);
						Pqty[loop_index] = parseInt(integer) + parseInt(integer2)
						found=true;
					}
			}	
			
			if (found==false)
			{
				curr_size +=1;	
				AddArray(number,desc,qty,price,tooltip,curr_size,diy,imagepath,category)
			
			}	  
		
			
		}
	Update();		
			
	//need to clear the document for NS
	if (!document.getElementById) //NS 4
		{
			document.clear();		
		}	
		
}

// Function added by Nisheeth on 09-25-2003. As there was a problem when the user tried to add 010 as the qty it added
// 8 instead of adding 10. Also earlier when 0 was entered as quantity it used to add 0 to the cart this issue is also
// being handled through this function.
function getCorrectvalue(qty){

	if ( (qty.length)== 3) {
		if ( (qty.charAt(0) == "0") && (qty.charAt(1) == "0") && (qty.charAt(2) == "0") ) {
			qty= eval("1");
		}
	}
	
	if ((qty.length)==3) {
		if ( (qty.charAt(0) == "0") && (qty.charAt(1) == "0") && (qty.charAt(2) != "0") ) {
			qty= eval((qty.charAt(2)));
		}
	}

	if ((qty.length)==3) {
		if ( (qty.charAt(0) == "0") && (qty.charAt(1) != "0") ) {
			qty= eval((qty.charAt(1)) + (qty.charAt(2)) );
		}
	}

	if ((qty.length)==2) {
		if ( (qty.charAt(0) == "0") && (qty.charAt(1) != "0") ) {
			qty= eval((qty.charAt(1)) + (qty.charAt(2))) ;
		}
	}
	
	if ((qty.length)==2) {
		if ( (qty.charAt(0) == "0") && (qty.charAt(1) == "0") ) {
			qty= eval("1") ;
		}
	}

	if ((qty.length)==1) {
		if ( (qty.charAt(0) != "0") ) {
			qty= eval( (qty.charAt(0)) + (qty.charAt(1)) + (qty.charAt(2))) ;
		}
	}
	
	
	if ((qty.length)==1) {
		if ( (qty.charAt(0) == "0") ) {
			qty= eval("1") ;
		}
	}
	return qty;
	
}

// Add array function adds an item to the P Array

function AddArray(number,desc,qty,price,tooltip, i,diy,imagepath,category)
{
	//by senthil on 09/26 to display empty cart alert
	if (Pnumber.length >= 0)
	{
		blnArrayval = true;
	}
	else
	{
		blnArrayval = false;
	}
	
	Pnumber[i]=number;
	Pdesc[i]=desc; 
	Pprice[i]=price;
/* revisit this area and correct it
	if (document.getElementById) //IE or NS 5 & above
	{
		if (isNaN(eval('document.getElementById(qty).value')))
			Pqty[i] = 1;
		else
			// Modified by Nisheeth on 09-25-2003
			Pqty[i] = getCorrectvalue ((document.getElementById(qty).value));
	}
	else  //NS 4
	{
		if (isNaN(eval('document.form1.elements[qty].value')))
			Pqty[i] = 1;
		else
			// Modified by Nisheeth on 09-25-2003
			//Pqty[i] = eval(document.form1.elements[qty].value);
			Pqty[i] = getCorrectvalue ((document.getElementById(qty).value));
	}
	*/
	Pqty[i] = 1;
	Ptooltip[i]=tooltip;
	Pdiy[i]=diy;
	Pimagepath[i]=imagepath;
	Pcategory[i]=category;

 }


// Build cart builds the html for the shopping cart 
//handles subtotal, tax and freight
function BuildupCart()
{	

	var blnFreight ; 
	var string  ;
	var strBlankLine ;
	
	
	//blank line	
	strBlankLine="";
	strBlankLine += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
	strBlankLine += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine += '<td width="53" height="32">&nbsp;</td>'
	strBlankLine += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'	
	strBlankLine += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine += '<td width="154" height="29">&nbsp;</td>'
	strBlankLine += '<td width="41" height="29">&nbsp;</td>'  
	strBlankLine +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr>'

	//blank line2	
	strBlankLine2="";
	strBlankLine2 += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
	strBlankLine2 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine2 += '<td width="53" height="51">&nbsp;</td>'
	strBlankLine2 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'	
	strBlankLine2 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine2 += '<td width="154" height="51">&nbsp;</td>'
	strBlankLine2 += '<td width="41" height="51">&nbsp;</td>'  
	strBlankLine2 +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine2 +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr>'

	//blank line3	
	strBlankLine3="";
	strBlankLine3 += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
	strBlankLine3 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine3 += '<td width="53" height="10">&nbsp;</td>'
	strBlankLine3 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'	
	strBlankLine3 += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine3 += '<td width="154" height="10">&nbsp;</td>'
	strBlankLine3 += '<td width="41" height="10">&nbsp;</td>'  
	strBlankLine3 +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
	strBlankLine3 +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr>'

	string= "";
	string +=tabdef;
	
			
		//calculate freight by default
		blnFreight = true;
					
		for (var j=0; j<=curr_size; j++)
		{	
		var strColor =''
		if((j % 2) != 0)
			strColor= ' bgcolor="#F0F0F0" '
		else
			strColor =' '

		//determine whether to display dealer installed label in shopping cart
		var dealerinstalled =''
		if(Pdiy[j].toLowerCase( )=='false'){
			//set freight to false because of the business rule
			//that if there is a single item that is dealer installed then the all items shipped to dealer
			blnFreight = false;
			if(Pcategory[j].toLowerCase( )!='parts'){
				dealerinstalled="Dealer Installed";}
			else
				dealerinstalled="";}
		else
			dealerinstalled="";
					
		string += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string += '<td width="10" ' +  strColor + '><img src="../images/spacer.gif" width="10" height="1" alt="" border="0" /></td>'
		string += '<td width="12%" height="32" ' +  strColor + ' align="left" class="amount" valign="middle"><INPUT style="text-align:center;width:26" class="amount" size="1" maxlength="3" type="text" ID="Text' 
		string +=  Pnumber[j] + '" size="4" value=' + Pqty[j]
		string +=   ' onchange="Update1(this.form,' + "'Text" + Pnumber[j]
		string +=  "')"

		string += '"' 
		string +=   ' onkeyup="checkForUpdate(this.form,' + "'Text" + Pnumber[j]
		string +=  "')"

		string += '"' 
		string +=   ' onKeyPress="checkKeyPressed(this.form,' + "'Text" + Pnumber[j]
		string +=  "')"

		string += '" >' 
		string += '</td>'
		//string += ''
		//string += '<br>'
				
		Pdesc[j]=Pdesc[j].replace("\""," ");
		Pdesc[j]=Pdesc[j].replace("\""," ");
		
		Ptooltip[j]=Ptooltip[j].replace("\""," ");
		Ptooltip[j]=Ptooltip[j].replace("\""," ");
		
		//string += '<a href="#" onClick="eiDelete('  
		//string += "'" + Pnumber[j] + "')"
		//string += '" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'img' + j + '\',\'\',\'../images/pe/delete_on.gif\',1)"><img src="../images/pe/delete_off.gif" width="36" height="15" alt="" border="0" name="img'
		//string += j + '"></a></td>'
		
		
		string += '<td  width="3" ' +  strColor + '><a href="#" onClick="eiDelete('  
		string += "'" + Pnumber[j] + "')"
		string += '" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'img' + j + '\',\'\',\'../images/pe/es_1_shp_trashCan.gif\',1)"><img src="../images/pe/es_1_shp_trashCan.gif" width="13" height="21" alt="" border="0" name="img'
		string += j + '"></a></td>'
		string += '<td width="6" ' +  strColor + '><img src="../images/spacer.gif" width="6" height="1" alt="" border="0" /></td>'
		string += '<td width="150" height="20" ' +  strColor + '  class="label" valign="middle">'

		// MOdified by Nisheeth To not show the tooltip
		if (Ptooltip[j] != 'tooltip')
		{ 
		//Following line is added by Anil on 08/25/05 to fix issue# 217 (Tooltip forces a toolbar to appear)
		//Now tooltip will appear at left side of cursor 
		//Variable ol_hpos is being defined and initialized in include\overlib.js file
		ol_hpos = LEFT;	
		string += '<a class="bodyCopyLink" href="#"'
		string += 'onmouseover="overlib(\'' + Ptooltip[j] +  '\')", HEIGHT, 30, LEFT, ABOVE, SNAPX, 5, SNAPY, 10); return true;" onmouseout="nd(); return true;">'
		var sdisparr = Pdesc[j].split(":");
		var sdispdesc = sdisparr[1].split(";");
		string += sdisparr[0] +  '</a><br><font class="greytext">' + sdispdesc[0] + '<br />' + sdispdesc[1] + '</font>'
		//string += Pdesc[j]+ '</a>'
		}
		else
		{
		string += Pdesc[j]
		}		

		string += '<br>' + dealerinstalled + '</td><td width="65"  height="20" ' +  strColor + '  align="right" valign="middle" class="amount"><strong>'
		string += formatCurrency(round(Pqty[j]* Pprice[j])) + ''
		string += '</strong></td>'  
		string +='<td width="2" ' + strColor + '><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1" ' + strColor + '><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr>'
			
			
		}
		
		if(curr_size==0)
		{
			//blank line				
			string += strBlankLine;
			string += strBlankLine;
			string += strBlankLine3;	
		}
		else if(curr_size==1)
		{
			string += strBlankLine;
			string += strBlankLine3;
		}
		
		else
			string += strBlankLine3;
		
		
		//string +='<table cellspacing="0" cellpadding="0" border=""><tr>'
		//string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		//string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		//string +='<td width="14"><img src="../images/spacer.gif" width="14" height="1" alt="" border="0" /></td>'
		//string +='<td width="91" class="tealtext" valign="top"></td>'
		//string +='<td width="38" class="tealtext" valign="top" align="right">'
		//string +='<td><img src="../images/spacer.gif" width="12" height="1" alt="" border="0" /></td>'
		//string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		//string +='<td width="91" class="tealtext" valign="top"><a href="javascript:Update();" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'Image17\',\'\',\'../images/pe/es_2_btn_updateCart.gif\',1)"> <img src="../images/pe/es_1_btn_updateCart.gif" width="91" height="25" alt="Update Cart" border="0" name="Image17" OnClick="javascript:SetCloseFlag();" /> </a></td>'
		//string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		//string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr></table>'
		
		
		
		string +='<table cellspacing="0" cellpadding="0" border="0"><tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="5"><img src="../images/spacer.gif" width="5" height="1" alt="" border="0" /></td>'
		string +='<td width="4"><img src="../images/spacer.gif" width="4" height="1" alt="" border="0" /></td>'
		string +='<td width="120" class="tealtext" valign="top">To delete an item, click on the trash can.</td>'
		string +='<td width="1" class="tealtext" valign="top" align="right"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="21"><img src="../images/spacer.gif" width="21" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="15" height="1" alt="" border="0" /></td>'
		//string +='<td width="91" class="tealtext" valign="top"><a href="javascript:Update();" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'Image17\',\'\',\'../images/es_1_btn_updateCart.gif\',1)"> <img src="../images/es_1_btn_updateCart.gif" width="91" height="25" alt="Update List" border="0" name="Image17" /> </a></td>'
		string +='<td width="91" class="tealtext" valign="top"><a href="javascript:Update();" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'Image17\',\'\',\'../images/pe/es_2_btn_updateCart.gif\',1)"> <img src="../images/pe/es_2_btn_updateCart.gif" width="91" height="25" alt="Update Cart" border="0" name="Image17" OnClick="javascript:SetCloseFlag();" /> </a></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr></table>'

		string +='<table cellspacing="0" cellpadding="0" border="0"><tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="10" alt="" border="0" /></td>'
		string +='<td width="10"><img src="../images/spacer.gif" width="10" height="1" alt="" border="0" /></td>'
		string +='<td width="5"><img src="../images/spacer.gif" width="5" height="1" alt="" border="0" /></td>'
		string +='<td width="150" class="tealtext" valign="top"></td>'
		string +='<td width="1" class="tealtext" valign="top" align="right"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="21"><img src="../images/spacer.gif" width="21" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="91" class="tealtext" valign="top"></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr></table>'

		
		string +='<table border="0" cellspacing="0" cellpadding="0"><tr><td>'
		
		// No Subtotal, Freight and Tax for PE client side basket
		var subtotal =0;
		for (var iindex=0;iindex <=curr_size; iindex++)
		{
			subtotal += Pqty[iindex]* Pprice[iindex]
		}
		subtotal= round(subtotal)
		
		
		
		var freight = 0;
		var tax = 0;
		//Add empty lines to keep the shopping cart width intact.  - Begin
		//Blank subtotal
		
		string +='<table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="8"><img src="../images/spacer.gif" width="8" height="1" alt="" border="0" /></td>'
		string +='<td  width="175" class="amount"><strong>SubTotal</strong>'
		string +='</td>'

		string +='<td width="65" class="amount" align="right"><strong>' +  formatCurrency(subtotal) + '</strong>'
		string +='</td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'							
				
		/*
		if (localdelivery =='Y') 
		{
		//Blank Freight
		//modified by geeta for Issue#325: Added function: OnClick="javascript:SetCloseFlag();"
		
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="8"><img src="../images/spacer.gif" width="8" height="1" alt="" border="0" /></td>'
		string +='<td width="175" class="amount"><a href="javascript:openPrintPopup(\'../html/pe_faq_4.htm#shipping\',true);"  OnClick="javascript:SetCloseFlag();" class="amount"><strong>Estimated Shipping</strong></a>'
		string +='</td>'

		var roundfreight  = round(freightcharge)
		
		//Dhiraj K Sharma for TaskID 101
		strShowFreightPrintPE=roundfreight;
		
		
		string +='<td width="65" class="amount" align="right"><strong>' + formatCurrency(roundfreight) + '</strong>'
		string +='</td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'
		}
		*/
									
		//Blank TaxRate:Nisheeth MOdified on 17th April 2004. TO implement solution for Issue 203. Remove the estimated Tax value. Removed taxRate From the following line
		//Estimated Tax ' + taxrate + '%'
		
		//modified by geeta for Issue#325: Added function: OnClick="javascript:SetCloseFlag();"
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="8"><img src="../images/spacer.gif" width="8" height="1" alt="" border="0" /></td>'
		string +='<td width="175" class="amount"><a href="javascript:openPrintPopup(\'../html/pe_faq_4.htm#tax\',true);" OnClick="javascript:SetCloseFlag();" class="amount"><strong>Estimated Tax </strong> ' + '</a>'										
		string +='</a></td>'

		var tax= subtotal * taxrate / 100
		var taxRounded= round(tax)

		//Dhiraj K Sharma for TaskID 101
		strTaxAmtPE=taxRounded;
		
		string +='<td width="65" class="amount" align="right"><strong>' + formatCurrency(taxRounded) + '</strong>'
		string +='</td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'

		//Add empty lines to keep the shopping cart width intact.  - End
		
		
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="5" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="14"><img src="../images/spacer.gif" width="14" height="1" alt="" border="0" /></td>'
		string +='<td width="175"></td>'
		string +='<td width="58"></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'
		
		
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="5" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="8"><img src="../images/spacer.gif" width="8" height="1" alt="" border="0" /></td>'
		string +='<td width="175" ><img src="../images/arrow_body.gif" width="175" height="1" alt="" border="0"/></td>'
		string +='<td width="58"><img src="../images/arrow_body.gif" width="58" height="1" alt="" border="0"/></td>'
		string +='<td width="5"><img src="../images/arrow_body.gif" width="5" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/arrow_body.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'
		
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="5" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="14"><img src="../images/spacer.gif" width="14" height="1" alt="" border="0" /></td>'
		string +='<td width="175"></td>'
		string +='<td width="58"></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
		string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table></td></tr>'

		
		
		//Total
		string +='<tr><td><table cellspacing="0" cellpadding="0" border="0">'
		string +='<tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="8"><img src="../images/spacer.gif" width="8" height="1" alt="" border="0" /></td>'
		string +='<td width="175" class="total"><strong>Estimated Total</strong>'
		string +='</td>'

		var total;
		
	//	if (localdelivery =='N') 
	//	{
		total=round(subtotal + tax);
	//	}
	//	else
	//	{
	//	total=round(subtotal + roundfreight + tax);
	//	}
	
		string +='<td width="65" class="total" align="right"><strong>' + formatCurrency(total)
		string +='</strong></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1">'
			string +='<img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td>'
		string +='</tr>'
		string +='</table>'
				
		string +='</td></tr></table>'
		
	//	if (localdelivery =='N') 
	//	{
		//blank line
		string +='<table cellspacing="0" cellpadding="0" border="0">'				
		string += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string += '<td width="248" height="1" colspan="3" class="greytext">&nbsp;&nbsp;&nbsp;&nbsp;* <a href=javascript:openPrintPopup("/html/faq_4.htm#shipping",true); OnClick="javascript:SetCloseFlag();" class="greytext">Shipping will be determined at checkout</a></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td></tr></table>'
	//	}
						
		//blank line
		string +='<table cellspacing="0" cellpadding="0" border="0">'				
		string += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string += '<td width="53" height="1">&nbsp;</td>'
		string += '<td width="154" height="1">&nbsp;</td>'
		string += '<td width="41" height="1">&nbsp;</td>'  
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		string +='</td></tr></table>'
				
						
		//Checkout 	
		string +='<table cellspacing="0" cellpadding="0" border="0"><tr>'
		string +='<td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="14"><img src="../images/spacer.gif" width="14" height="1" alt="" border="0" /></td>'
		string +='<td width="91" class="tealtext" valign="top"></td>'
		string +='<td width="38" class="tealtext" valign="top" align="right">'
		string +='<td><img src="../images/spacer.gif" width="12" height="1" alt="" border="0" /></td>'
		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'

//Neeraj on Oct 12,2004 for Issue 353
		string +='<td width="91" class="tealtext" valign="top" align="right"><a href="#" onclick="javascript:if(blnSubmit==true){alert(strMsgSubmit);return false;} else{blnSubmit=true;eiSubmit();return true;};" onMouseOut="jWd_swapImgRestore()" onMouseOver="jWd_swapImage(\'Image18\',\'\',\'../images/pe/es_2_btn_checkout.gif\',1)"> <img src="../images/pe/es_2_btn_checkout.gif" width="78" height="25" alt="Begin Secure Checkout" border="0" name="Image18"  OnClick="javascript:SetCloseFlag();" /> </a></td>'
//Neeraj on Oct 12,2004 for Issue 353


		string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td></tr></table>'
				
		//blank line
		//string +='<table cellspacing="0" cellpadding="0" border="0">'				
		//string += '<tr><td width="1" bgcolor="#D2D2D2"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" /></td>'
		//string += '<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		//string += '<td width="53" height="1">&nbsp;</td>'
		//string += '<td width="154" height="1">&nbsp;</td>'
		//string += '<td width="41" height="1">&nbsp;</td>'  
		//string +='<td width="2"><img src="../images/spacer.gif" width="2" height="1" alt="" border="0" /></td>'
		//string +='<td width="1"><img src="../images/spacer.gif" width="1" height="1" alt="" border="0" />'
		//string +='</td></tr></table>'


		//string +='<table bgcolor="#D2D2D2" cellspacing="0" cellpadding="0" border="0"><tr>'
		//string +='<td><img src="../images/spacer.gif" width="253" height="1" alt="" border="0" /></td></tr></table>'
				
		string +='</td></tr></table>'

		// Put the end table
		//alert(string)

		if (document.getElementById) //IE or NS 5 & above
		{
			if (curr_size== -1)
			{
				document.getElementById("output").innerHTML=strEmptyBasketHTML;
			}
			else
			{
				document.getElementById("output").innerHTML=string;
			}
		}
		else  //NS4
		{
			if (curr_size== -1)
			{
				document.layers["output"].document.write(strEmptyBasketHTML) ;
				document.layers["output"].document.close() ;
			}
			else
			{
				document.layers["output"].document.write(string);
				document.layers["output"].document.close();
			}
		}
				
			 
}


//The function performs the delete function in the shopping cart
function DelCartItem(str)
{	
	DeleteFromP(str);  //Delete from P array first 	
	SaveCart();        //Re-Build the cart and Save it
	BuildupCart();
}


//Used by delete cart, deletes from the P array	
function DeleteFromP (str)
{
	var blnFound;   // indicates the item has been found and deleted from the cart
	var iDelPos;    // position of the link to be moved
	var iIndexDel;  // position in which to remove the item

	blnFound = false;		

   // Removes a partnum from the P array
   for (var j=0; j<=curr_size; j++)
   {
      if (Pnumber[j]==str)
      {   
         //Update link positions (if they exist)
         if (document.getElementById('AddAcc' + Pdesc[j]) != null)
         {
            var xAddCart = 'AddAcc' + Pdesc[j] + '.style.visibility = ' + '"hidden"';
            eval(xAddCart); 

            var iPos = document.all.pos.value
            var xPos = document.all.xpos.value

            document.all.pos.value = iPos*1 - 16 

            if (curr_size > 6)
            {		
               document.all.xpos.value = xPos*1 - 16
            }
            blnFound = true;
         }
         iIndexDel = j;  // set where the item should be deleted from the array
      }
      else
      {
         // for the next items left in the array
         // raise the position of the link by 16 pixels for all items after the deleted link	
         if (blnFound)
         {	
            // check if the link exists before try to move up
            if (document.getElementById('AddAcc' + Pdesc[j]) != null)
            {
               delPos = document.getElementById('AddAcc' + Pdesc[j]).style.top;
               // find position of 'px' and remove it from the position
               delPos = delPos.substring(0,delPos.indexOf('px'));
               document.getElementById('AddAcc' + Pdesc[j]).style.top = parseInt(delPos) - 16;
            }
         }
      }
   }

   // move all items down in the array from the deletion point
   for ( var p=iIndexDel; p<curr_size; p++)
   {							
      Pnumber[p]=Pnumber[p+1];
      Pdesc[p]=Pdesc[p+1]; 
      Pprice[p]=Pprice[p+1];
      Pqty[p]=Pqty[p+1];
      Ptooltip[p]=Ptooltip[p+1];
      Pdiy[p]=Pdiy[p+1];
      Pimagepath[p]=Pimagepath[p+1];
      Pcategory[p]=Pcategory[p+1];
   }

   // Decrement the Array Pointer
   curr_size--;

	//Dhiraj K Sharma : ATO Implemented : Release 40
	//Nisheeth -  Modified for Issue 638. Used the logic of eStoreShopCartParts.js file. Reduce the Array to cur size.
	Pnumber = getCurSizeArray(Pnumber);
	Pdesc = getCurSizeArray(Pdesc);
	Pprice = getCurSizeArray(Pprice);
	Pqty = getCurSizeArray(Pqty);
	Ptooltip = getCurSizeArray(Ptooltip);
	Pdiy = getCurSizeArray(Pdiy);
	Pimagepath = getCurSizeArray(Pimagepath);
	Pcategory = getCurSizeArray(Pcategory);

   //by senthil on 09/26 to display empty cart alert
   if(curr_size != -1)
   {
      blnArrayval = true;
   }
   else
   {	
	//Dhiraj K Sharma : TaskID 101	
	document.getElementById("removeImages").innerHTML="<img src='../images/es_1_shp_cartHDR.gif' width='254' height='27' border='0' />"
      blnArrayval = false;
   }
}

//Dhiraj K Sharma : ATO Implemented : Release 39
function getCurSizeArray(objArr)
{
//Nisheeth: Modified for Issue 638.  Used the logic of eStoreShopCartParts.js file. Reduces the array size to cur size and returns the reduced Array.
	var tempArr
	tempArr = new Array();
	for (var j=0; j<=curr_size; j++)
		{
		tempArr[j] = objArr[j];
		}
	return tempArr
}  
		
function round(x) { return Math.round(x*100)/100;} 
		

// Saves information into the hidden form fields	
function SaveCart()
{

	if (document.getElementById)  //IE or NS 5 & above
	{
		if (curr_size== -1)
		{
			document.getElementById("Hnumber").value =""
			document.getElementById("Hdesc").value=""
			document.getElementById("Hprice").value=""
			document.getElementById("Hqty").value=""
			document.getElementById("Htooltip").value=""
			document.getElementById("Hdiy").value=""
			document.getElementById("Himagepath").value=""
			document.getElementById("Hcategory").value=""
		}
		else
		{
			
			document.getElementById("Hnumber").value =Pnumber[0]
			document.getElementById("Hdesc").value=Pdesc[0]
			document.getElementById("Hprice").value=Pprice[0]
			document.getElementById("Hqty").value=Pqty[0]
			document.getElementById("Htooltip").value=Ptooltip[0]
			document.getElementById("Hdiy").value=Pdiy[0]
			document.getElementById("Himagepath").value=Pimagepath[0]
			document.getElementById("Hcategory").value=Pcategory[0]
			for (var j=1; j<=curr_size; j++)
			{
				document.getElementById("Hnumber").value +=   "," +Pnumber[j]
				document.getElementById("Hdesc").value +=   "|" +Pdesc[j]
				document.getElementById("Hprice").value +=   "," +Pprice[j]
				document.getElementById("Hqty").value +=   "," +Pqty[j]
				document.getElementById("Htooltip").value +=   "|" +Ptooltip[j]
				document.getElementById("Hdiy").value +=   "," +Pdiy[j]
				document.getElementById("Himagepath").value +=   "," +Pimagepath[j]
				document.getElementById("Hcategory").value +=   "," +Pcategory[j]
				
			}
		}
	}
	else  // NS 4
	{
		if (curr_size== -1)
		{
			document.form1.elements["Hnumber"].value =""
			document.form1.elements["Hdesc"].value=""
			document.form1.elements["Hprice"].value=""
			document.form1.elements["Hqty"].value=""
			document.form1.elements["Htooltip"].value=""
			document.form1.elements["Hdiy"].value=""
			document.form1.elements["Himagepath"].value=""
			document.form1.elements["Hcategory"].value=""
		}
		else
		{
			document.form1.elements["Hnumber"].value =Pnumber[0]
			document.form1.elements["Hdesc"].value=Pdesc[0]
			document.form1.elements["Hprice"].value=Pprice[0]
			document.form1.elements["Hqty"].value=Pqty[0]
			document.form1.elements["Htooltip"].value=Ptooltip[0]
			document.form1.elements["Hdiy"].value = Pdiy[0]
			document.form1.elements["Himagepath"].value = Pdiy[0]
			document.form1.elements["Hcategory"].value = Pcategory[0]
					
			for (var j=1; j<=curr_size; j++)
			{
				document.form1.elements["Hnumber"].value +=   "," +Pnumber[j]
				document.form1.elements["Hdesc"].value +=   "|" +Pdesc[j]
				document.form1.elements["Hprice"].value +=   "," +Pprice[j]
				document.form1.elements["Hqty"].value +=   "," +Pqty[j]
				document.form1.elements["Htooltip"].value +=   "|" +Ptooltip[j]
				document.form1.elements["Hdiy"].value += "," + Pdiy[j]
				document.form1.elements["Himagepath"].value += "," + Pimagepath[j]
				document.form1.elements["Hcategory"].value += "," + Pcategory[j]
			}
		}
	}
	

}


// Updates P array based on Changes in the shopping cart
function Update(str)
{
	
	// Note: When you call DeleteFromP curr_size changes
	// Be careful
	for (var k=0; k<=CIndex;k++ )
		
	 {
		var found=false;				
		for (var j=0; j<=curr_size ;j++)
		 {
			if ( Pnumber[j]==CPnumber[k] )
				if (CPqty[k]==0)
					{ 
						DeleteFromP(CPnumber[k]);
						found=true;
						// Get out : curr_size has changed!
					}
				 else
					{
						Pqty[j]=CPqty[k]
						found=true;
						// Get out : curr_size has changed
					}
							 
		 }
			 
	}	
	CIndex=-1;
	BuildupCart()
	SaveCart()
	if (!document.getElementById) //NS 4
	{
		document.clear();		
	}
}


function Update1(target, str)
{
// Prepare for Update
// Record all changes.
// Catch items already on change list
// str looks like: Text001, Text + Pnumber
// remove 'Text' from it and you get the Pnumber
	if (document.getElementById)  //IE or NS 5 & above
	{
		var qty=document.getElementById(str).value
	}
	else //NS 4
	{
		//var qty=document.form2.elements[str].value
		var qty = target.elements[str].value
	}


	if (!validateNumeric(qty)) 
	{ 
	target.elements[str].focus;
	}
	else
	{
	var string = str
	var regexp=/Text/g
	var partnum= str.replace(regexp,"")
	if (CIndex== -1)
		{
			CPnumber[0]= partnum;
			CPqty[0]=qty
			CIndex=0
		 }
	else
		{
			var found=false;
			for (var j=0; j<=CIndex;j++ )
			{
				if (CPnumber[j]== partnum)
				{
					found=true;
					CPqty[j]=qty
							
				}
						
			}
		  if (found== false)
			{
				CIndex++;
						
				CPnumber[CIndex]= partnum;
				CPqty[CIndex]=qty;					
			}
					
		}
	}
}



function RestoreCart()
{
//Function called after post back
//checks hidden elements to figure out of there are any items in the basket
//retrives the values in P array and then use build cart to create HTML
	if (document.getElementById) //IE or NS 5 & above
	{
		
		var str = trim(document.getElementById("Hqty").value)
		if (str.length != 0)
		{
			 var arr1= document.getElementById("Hnumber").value.split(",")
				 for (var j=0; j<arr1.length; j++)
					{ Pnumber [j]=arr1[j] }
			//alert(arr1.length);
			var arr1= document.getElementById("Hprice").value.split(",")
			    for (var j=0; j<arr1.length; j++)
			   	{ Pprice [j]=arr1[j]}
			var arr1= document.getElementById("Hdesc").value.split("|")
			curr_size=arr1.length -1
			//alert(curr_size);
			    for (var j=0; j<arr1.length; j++)
			   	{ Pdesc [j]=arr1[j] }
			var arr1= document.getElementById("Hqty").value.split(",")
			    for (var j=0; j<arr1.length; j++)
			   	{ Pqty [j]=arr1[j] }
			var arr1= document.getElementById("Htooltip").value.split("|")
			    for (var j=0; j<arr1.length; j++)
			   	{ Ptooltip [j]=arr1[j] }
			var arr1= document.getElementById("Hdiy").value.split(",")
				 for (var j=0; j<arr1.length; j++)
					{ Pdiy [j]=arr1[j] }
			var arr1= document.getElementById("Himagepath").value.split(",")
				 for (var j=0; j<arr1.length; j++)
					{ Pimagepath [j]=arr1[j] }
			var arr1= document.getElementById("Hcategory").value.split(",")
				 for (var j=0; j<arr1.length; j++)
					{ Pcategory [j]=arr1[j] }
					
		BuildupCart()
		blnArrayval = true;
		}
		else
		{
			PaintEmptyBasket();
			blnArrayval = false;
		}
				
	}
else  //NS 4
	{
		//var str= new String()
		str=document.forms[0].elements["Hqty"].value
		var regex=/\s/g
		str=str.replace(regex,"")
		if (str.length !=0)
		{
			var arr1= document.form1.elements["Hnumber"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pnumber[j]=arr1[j] 
			}
			var arr1=document.form1.elements["Hprice"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pprice[j]=arr1[j]
			}
			var arr1= document.form1.elements["Hdesc"].value.split("|")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pdesc[j]=arr1[j] 
			}
			var arr1= document.form1.elements["Hqty"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pqty[j]=arr1[j] 
			}
			var arr1=document.form1.elements["Htooltip"].value.split("|")
			for (var j=0; j<arr1.length; j++)
			{ 
				Ptooltip[j]=arr1[j] 
			}
			var arr1=document.form1.elements["Hdiy"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pdiy[j]=arr1[j] 
			}
			var arr1=document.form1.elements["Himagepath"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pimagepath[j]=arr1[j] 
			}
			var arr1=document.form1.elements["Hcategory"].value.split(",")
			for (var j=0; j<arr1.length; j++)
			{ 
				Pcategory[j]=arr1[j] 
			}
			curr_size=arr1.length -1
			BuildupCart()
		}
		else
			PaintEmptyBasket();

	}
}

function PaintEmptyBasket()
{
// Paint the empty basket
//Dhiraj K Sharma : TaskID 101
document.getElementById("removeImages").innerHTML="<img src='../images/es_1_shp_cartHDR.gif' width='254' height='27' border='0' />"

	if (document.getElementById) //IE or NS 5 & above
	{
			document.getElementById("output").innerHTML=strEmptyBasketHTML;
	}
	else  //NS4
	{
			document.layers["output"].document.write(strEmptyBasketHTML) ;
			document.layers["output"].document.close() ;
	}

}

function validateNumeric(string) {
    //if (!string) return false;
    var Chars = "0123456789";

    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
} 

function checkForUpdate(target, str)
{

// Prepare for Update
// Record all changes.
// Catch items already on change list
// str looks like: Text001, Text + Pnumber
// remove 'Text' from it and you get the Pnumber

	if (document.getElementById)  //IE or NS 5 & above
	{
		var qty=document.getElementById(str).value
	}
	else //NS 4
	{
		//var qty=document.form2.elements[str].value
		var qty = target.elements[str].value
	}

	if (qty != '')
	{
		if (!validateNumeric(qty)) 
		{ 
		alert('Please enter only Numeric value.')
		target.elements[str].focus();
		target.elements[str].select();
		}
	}
	
}




function checkKeyPressed(target, str) 
     {
	Update1(this.form, str);
        var keyValue;
    	if(navigator.appName.indexOf("Netscape") != -1)
	 {
            	keyValue=window.captureEvents(Event.KEYPRESS);   
         	if(keyValue.which==13)
		{
		   //alert ("Enter NS" );
		  
		   Update();
		}

	 }
	else
	 {
	   	keyValue = window.event.keyCode
		if (keyValue == 13) 
               	{
		   //alert ("Enter IE");
		   //Update1(this.form, str);
		   Update();
              	}
	 }
         return false;
    }