/*
 This set of source codes is protected by international copyright laws...
 No copying is allowed. 
 http://www.mp34store.com
 Copyright (C) 2007. All Rights Reserved.
*/


		
			var gnNoOfRecords=100;	// Maximum no of records marking system supports.
			var gsMarkedRecordNo;
			var gnNoOfMarkedRecords=0;
			var gnMarked=new Array(gnNoOfRecords);
			var gsMarkedRecordsName="MARKEDRECORDS";
			var gsSelectedIndexName="SELECTEDINDEX";
			var gsSelectedOPIndexName="SELECTEDOPINDEX";			
			var gsShoppingCartName="ShoppingCart";
			var gsOPMarked="OPMARKED";	
			
			var gsShoppingCartName_status="ShoppingCart_status";
			var gsShoppingCartName_total_no="ShoppingCart_nTotalNo";
			var gsShoppingCartName_total_product_cost="ShoppingCart_nTProductCost";
			var gsShoppingCartName_total_sh_cost="ShoppingCart_nTSHCost";

																
			var gnSelectedIndex=0;
			var gnSelectedOPIndex=0;			
			var gnInitedMarkedSystem=0;
			
			function GetCookieVersion()
			{
			     return "Cookie Version 1.00";
			}
      function setCookie(sName,sValue,oExpires,sPath,sDomain,bSecure)
      {
       				 sCookie=sName+"="+encodeURIComponent(sValue);
      				 
      				 document.cookie=sCookie;
      }
			function getCookie(sName)
			{
			 				 var sRE="(?:;)?"+sName+"=([^;]*);?";
							 var oRE=new RegExp(sRE);
							 
							 if (oRE.test(document.cookie)) {
							 		return decodeURIComponent(RegExp["$1"]);
							 }
							 else
							 {
							 		 return null;
							 }
			}
			function deleteCookie(sName)
			{
  				 setCookie(sName,"");
			}

			function InitMarkedRecords()
			{
          for (i=0;i<gnNoOfRecords;i++)
          {
          	    gnMarked[i]=0;
          }
          gnNoOfMarkedRecords=0
			}
			
			function CheckRecordMarked(nMarkedIndex)
			{
			  if ((nMarkedIndex<0)||(nMarkedIndex>=gnNoOfRecords)) return -1;
			  return gnMarked[nMarkedIndex];
			}

			function InitMarkedRecordsSystem()
			{
			 				 var sValue;
							 var sNewNo=new Array(10);
							 var sNewNoLen=0;
							 var nRecordIndex;
							 var sExtracted;
//alert("New Version InitMarkedRecordsSystem()");
							 // Initialize Data
			 				 InitMarkedRecords();
							 
							 // Retrive Cookie from system
							 sValue=getCookie(gsMarkedRecordsName);
							 						
													
// All debug checks here-----------------------
/*
alert(getCookie(gsMarkedRecordsName));
alert(getCookie(gsSelectedIndexName));			
alert(getCookie(gsSelectedOPIndexName));			
	*/												
/*
gsSelectedIndexName
							 	  setCookie(gsMarkedRecordsName,"");
							 		setCookie(gsSelectedIndexName,0);	
							 		setCookie(gsSelectedOPIndexName,0);	
*/																										 
																								 
							 // Update gnMarked with value from sValue;							 						 
							 if (!((sValue==null)||(sValue==undefined)))
							 {
							     //alert("svalue length >0 ");								 
    							 //document.write("***"+sValue.length+"!");
    							 for (i=0;i<sValue.length;i++)
    							 {
    							 	   if (sValue.charAt(i)==',') {
													sExtracted=sValue.substr(i-sNewNoLen,sNewNoLen);
													nRecordIndex=sExtracted.valueOf();
												  //document.write(nRecordIndex);
													// =============
													// Upgate array
													// =============
													gnMarked[nRecordIndex]=1;
										
													// Reset value
    											sNewNoLen=0;    
    									 }
    									 else
    									 {
    											sNewNoLen++
    									 }
    							 }

									 
									 // ==========================
    							 // Update gnNoOfMarkedRecords
									 // ==========================										 
									 gnNoOfMarkedRecords=0;
    							 for (i=0;i<gnNoOfRecords;i++)
									 {
									      if (gnMarked[i]!=0)
									          gnNoOfMarkedRecords++;
									 
									 }						
							 }
							 else
							 {
							 	   // Do nothing more
							 }			

							 // -----------------------------------------------------
							 //  Special handling
							 // -----------------------------------------------------
							 if (getCookie(gsOPMarked)==null)
							 {							 				 
											 setCookie(gsOPMarked,"@");
							 }
							 
							 if ((getCookie(gsSelectedIndexName)==null)||(getCookie(gsSelectedOPIndexName)==null)||(getCookie(gsMarkedRecordsName)==null))
							 {
							    //alert("Set cookie values to null");									 
							    //alert(getCookie(gsOPMarked));
							 	  setCookie(gsMarkedRecordsName,"");
									if ((getCookie(gsSelectedIndexName)==null)||(getCookie(gsSelectedIndexName)==undefined))
									{
									//alert("Reseting gsSelectedIndexName to 0 (A)");
							 		   setCookie(gsSelectedIndexName,0);
									}	
							 		setCookie(gsSelectedOPIndexName,0);	
									//setCookie(gsOPMarked,"@");

									gnSelectedIndex=getCookie(gsSelectedIndexName).valueOf();
									gnSelectedOPIndex=0;									
							 }
							 else
							 {
							      gnSelectedIndex=getCookie(gsSelectedIndexName).valueOf();
							      gnSelectedOPIndex=getCookie(gsSelectedOPIndexName).valueOf();
							 }
							 
							 if (getCookie(gsShoppingCartName)==null)
							 {
							 	   setCookie(gsShoppingCartName,"*");
							 }
							 gnInitedMarkedSystem=1;
			}
			
			function ResetShoppingCart()
			{
			      return setCookie(gsShoppingCartName);			 
			}	
			function RetriveDataShoppingCart()
			{
			      return getCookie(gsShoppingCartName);	 
			}								
			function UpdateShoppingCart(sValue)
			{
			      setCookie(gsShoppingCartName,sValue);			 
			}
			
			function UpdateOPCookie(szString)
			{
			      setCookie(gsOPMarked,szString);			 
			}			
			function RetriveOPCookie()
			{
			      return getCookie(gsOPMarked);	 
			}					
			function GetFormattedSCRegData(ProductCode,nNo)
			{
			    var sValue,nIndex;
					
					// OP					
					nIndex=SearchOPByItemCode(ProductCode);
					if (nIndex>=0)
					{
					    //sValue=ProductCode+"|"+aFMD[(nIndex*aRecordSize)+14]+"|"+aFMD[(nIndex*aRecordSize)+1]+",";	
					    sValue=ProductCode+"|"+aFMD[(nIndex*aRecordSize)+14]+"|"+aFMD[(nIndex*aRecordSize)+1]+"|"+nNo+"|"+aFMD[(nIndex*aRecordSize)+9]+"|";
					    //sValue=ProductCode+"|"+aFMD[(nIndex*aRecordSize)+14]+"|"+aFMD[(nIndex*aRecordSize)+1]+"|"+nNo+"|"+aFMD[(nIndex*aRecordSize)+9]+"|",",";									
					} 
					else // MP3
					{
					   nIndex=SearchMP34ByItemCode(ProductCode);
						 if (nIndex>=0)
						 {
					     sValue=ProductCode+"|"+Column[(nIndex*nRecordSize)+28]+"|"+Column[(nIndex*nRecordSize)+5]+"|"+nNo+"|"+Column[(nIndex*nRecordSize)+22]+"|";							 
					     //sValue=ProductCode+"|"+Column[(nIndex*nRecordSize)+28]+"|"+Column[(nIndex*nRecordSize)+5]+"|"+nNo+"|"+Column[(nIndex*nRecordSize)+22]+"|",",";							 
						 }
						 else
						 {
						    alert("Error searching for records");
						 }					   
					}																																				
			    return sValue;
			}
			
			function AppendShoppingCart(ProductCode,nNo)
			{
			      var oValue;
						
						// Supposed to verify product code and nNo
						// return 0;   // if failed
						
						// Retrive old value
			      oValue=getCookie(gsShoppingCartName);


						if (oValue=="*")
						{

						    oValue=GetFormattedSCRegData(ProductCode,nNo);
						}
						else
						{										
  						  // Append value;
  						  oValue+=GetFormattedSCRegData(ProductCode,nNo);							
						}
						
						// update registry with value
			      setCookie(gsShoppingCartName,oValue);
						
						return 1;			 
			}			

		 
			function GetSelectedIndex() 
			{ 
			//alert("Cookie");
     			return getCookie(gsSelectedIndexName);					
   	  }
		
			//function GetSelectedIndex() { return gnSelectedIndex; }			
			function UpdateSelectedIndex(nIndex) { setCookie(gsSelectedIndexName,nIndex)	}

			function GetSelectedOPIndex() { return gnSelectedOPIndex; }
			function UpdateSelectedOPIndex(nIndex) { setCookie(gsSelectedOPIndexName,nIndex);	}			

			function DisplayMarkedArray()
			{
			 				 if (gnInitedMarkedSystem==0) alert("Marked System not initialized...");
			 				 document.write("<br>"+"No of marked records: "+gnNoOfMarkedRecords);
			 				 document.write("<br>"+"-----------------------------------"+"<br>");
			 				 for (i=0;i<gnNoOfRecords;i++)
							 {
							      if (+gnMarked[i])
							 			    document.write(i+": "+gnMarked[i]+" ");							 
							 }
			}
			
			function AppendMarkedCookieRecords(nIndex)
			{												 	 
			 				 if (gnInitedMarkedSystem==0) alert("Marked System not initialized...");							 
			  			 if ((nIndex<0)||(nIndex>=gnNoOfRecords)) return -1;
							 if (gnMarked[nIndex]==0)
							 {
     							 var sValue;							 
//alert("Appending to 1");
							 		 gnMarked[nIndex]=1;
									 gnNoOfMarkedRecords++;
 
        						// Update Cookie with sequential completed string
        					  sValue=getCookie(gsMarkedRecordsName);
//alert(sValue);	
								    if (sValue==null)
											  sValue=nIndex+",";
										else									
        						    sValue=sValue+nIndex+",";
//alert(sValue);											
        						setCookie(gsMarkedRecordsName,sValue);									 									 
							 }
							 else
							 {
							 		 alert("record already marked");
							 }
			}
			function UnMarkCookieRecords(nIndex)
			{
  				 if (gnInitedMarkedSystem==0) alert("Marked System not initialized...");			
			    var sValue="";
			    if ((nIndex<0)||(nIndex>=gnNoOfRecords)) return -1;
  			  if (gnMarked[nIndex]==1)
  			  {
					 	 gnMarked[nIndex]=0;
						 for (i=0;i<gnNoOfRecords;i++)
						 {
						 		 if (gnMarked[i]==1)
								 {
								 		sValue=sValue+i+",";			 // AppendCookieValue
								 }
						 }						 					
						 setCookie(gsMarkedRecordsName,sValue);
  					 gnNoOfMarkedRecords--;	
  			  }		
  			 else
  			 {
  			 		 alert("record already unmarked");
  			 }								
			}
			function GetNoOfMarkedRecord() {return gnNoOfMarkedRecords};
			
			function RetriveMarkedCookieRecords()
			{
			 		 // Pass back string from Cookie
					 return getCookie(gsMarkedRecordsName);
			}
			function ResetMarkedCookieRecords()
			{
			 				 if (gnInitedMarkedSystem==0) alert("Marked System not initialized...");					
			 				 // Delete Cookie Records
							 // Delete Array records
							 // Reset gnNoOfMarkedRecords
							 for (i=0;i<gnNoOfRecords;i++)
							 {
							 		 gnMarked[i]=0;
							 }
							 gnNoOfMarkedRecord=0;
							 gnSelectedIndex=0;										 
							 deleteCookie(gsMarkedRecordsName);
							 deleteCookie(gsSelectedIndexName);	
							 deleteCookie(gsSelectedOPIndexName);
							 deleteCookie(gsOPMarked);
							 //deleteCookie(gsShoppingCartName);
							 UpdateShoppingCart("*");
				 
			}
			
        function MarkRecord()
				{
					 var sPath;
					
//					alert(nCurIndex); 
 					 AppendMarkedCookieRecords(nCurIndex);						
					 //UpdateSelectedIndex(nCurIndex);		
			     sPath="MP3Selector.htm?"+nCurIndex;				
					 window.location=sPath;						
				}
				function UnmarkRecord()
				{
					 var sPath;
 					 UnMarkCookieRecords(nCurIndex);
						
					 //UpdateSelectedIndex(nCurIndex);		 
			     sPath="MP3Selector.htm?"+nCurIndex;				
					 window.location=sPath;					
				}
				

				   var sData,nPtr,nPurchases=0;
					 var nStart,nEnd;
					 var aCart=new Array();
					 var nCartCount=0;;
					 var aCartFields=new Array();
					 var nNoOfFields=5;
					 var nTotalItems=0,nTotalCost=0,nTotalWeight=0,nSubTotalCost=0,nOriginalSHF=0,nTotalListedCost=0;
					 var nCompositeSPSH=0;
					 var nTemp;
           var aShipFromSource=new Array(0,0,0,0,0);
           var aWeightFromSource=new Array(0,0,0,0,0);					 
					 var nWeightRange= new Array("200","300","400","500","750","1000","1500","2000","3000", "4000","5000","10000","20000","1000000");

					 var nSingPostCost= new Array("9.99","14.99","22.49","25","33","40","60","90","100","140","180","275","550","2000");
					 var nSingPostCost2= new Array("7.40","10.8","14.40","17.90","26.65","35.40","52.90","70.40","100","125","160","250","500","2000");
					 var nSpeedPostCost= new Array("54.85","54.85","54.85","54.85","67.05","67.05","79.25","91.45","115.80","140.20","164.55","154.55","229.60","2000");					// 2 to 4 days 

					 var nDHLCost= new Array("80","80","80","80","95","95","110","130","160","195","230","300","450","2000");					 
					 var nFECost = new Array("","","","","","","","","","","","","","2000");			
					 var nUPSCost= new Array("","","","","","","","","","","","","","2000");	
					 var nTNTCost= new Array("","","","","","","","","","","","","","2000");	
					 var nEMSCost= new Array("","","","","","","","","","","","","","2000");
					 var aLA_FE = new Array("9.99","11.49","12.99","12.99","13.99","13.99","13.99","14.99","14.99", "16.99","19.99","39.99","69.99","2000");
					 var aLA_UPS = new Array("9.99","11.49","12.99","12.99","13.99","13.99","13.99","14.99","14.99", "16.99","19.99","39.99","69.99","2000");
					 var aMethod4 = new Array("9.99","11.49","12.99","12.99","13.99","13.99","13.99","14.99","14.99", "16.99","19.99","39.99","69.99","2000");						 					 
					 var aMethod5 = new Array("9.99","11.49","12.99","12.99","13.99","13.99","13.99","14.99","14.99", "16.99","19.99","39.99","69.99","2000");						 					 
					 var nSubListedPrice,nSubCost,nSubSH,nSHT;
					 var nTotalWt_2=0;
					 var nTemp2;
					 var nSg2US=1.5;
					 var nChoseShippingMethod=0;
					 var nMethodShippingCost=0;
					 var nSPSH=0;
					 var aSL=new Array("California (via Federal Express)<br>[5 to 15 days]","Singpaore (via SingPost [post-office])<br>[7 to 15 days]","Method 3 (via UPS)<br>[5 to 15 days]","Method 4","Method 5");
					 var aSHCost=new Array(0,0,0,0,0);
					 var aSHCostWtM=new Array(0,0,0,0,0);
					 var aSH_Weight=new Array(0,0,0,0,0);
					 var nIndex;
					 var nTotalSH_Original;
					 var nTotalSH_Weight;

												 
        // ------------------------------------------------------
        //  Miscellaneous routines
        // ------------------------------------------------------						
					function lowervalue(a,b)
					{
					  if (a<b)
						    return a;
						else
						    return b; 
					}	
					function Savings(a,b)
					{
					     return (a-b).toFixed(2);
					}				
					function SavingsPercent(a,b)
					{
					    if (b==0) return 0;
					    return (100*((a-b)/b)).toFixed(2);
					}			

        // ---------------------------------------
        //  Update array with correct data
        // ---------------------------------------			
				function UpdateDataArray()
				{
				   UpdateWithExchangeRate();
				}
				
				function UpdateWithExchangeRate()
				{																
          for (i=0;i<aLA_FE.length;i++)
  				{
  				 		aLA_FE[i]*=nSg2US;
  						aLA_UPS[i]*=nSg2US;
  						aMethod4[i]*=nSg2US;
  						aMethod5[i]*=nSg2US;														
  				}
				}
									


        // ------------------------------------------------------
        //  
        // ------------------------------------------------------						
				function DetermineWeightFromSingapore()
				{
            nPositingIndex=0;
            while (nPositingIndex<nWeightRange.length)
            {
             			if (nTotalWt_2<=nWeightRange[nPositingIndex])
            			{
            			   break;
            			}
                  nPositingIndex++;
            }		
						//nCompositeSPSH=(nSingPostCost[nPositingIndex]/nSg2US).toFixed(2);
						
						//aSHCostWtM[1]=nCompositeSPSH;
	
				}
				
        // ------------------------------------------------------
        //  Return S/H cost broken down by various shipping methods
        // ------------------------------------------------------						
				function DetermineSHCost_ByMethodNWeight(nSHMethod)
				{
				    if (aWeightFromSource[nSHMethod]==0) return 0;
            nPositingIndex=0;
            while (nPositingIndex<nWeightRange.length)
            {						
             			if (aWeightFromSource[nSHMethod]	<=nWeightRange[nPositingIndex])     //
             			//if (aSH_Weight[nSHMethod]	<=nWeightRange[nPositingIndex])     //
            			{
            			   break;
            			}
                  nPositingIndex++;
            }		
//document.write("Method "+nSHMethod+" : "+aWeightFromSource[nSHMethod]+"##"+nPositingIndex+"@@ "+nWeightRange[nPositingIndex]+"<br>");
						switch(nSHMethod)
						{
						   case 0:							 
							     return (aLA_FE[nPositingIndex]);
							     break;
						   case 1:
									 if (nChoseShippingMethod==0)
									 {
						       	  return ((nSingPostCost[nPositingIndex]/nSg2US).toFixed(2));										 
									 }							 
							     else if (nChoseShippingMethod==1)
									 {
									   return ((nSpeedPostCost[nPositingIndex]/nSg2US).toFixed(2));		
									 }
							     else if (nChoseShippingMethod==2)
									 {
									   return ((nDHLCost[nPositingIndex]/nSg2US).toFixed(2));		
									 }									 
									 else
									 {
						       	  return (-1);										 
									 }
							 
							     break;
						   case 2:
							     return (aLA_UPS[nPositingIndex]);	
							     break;
						   case 3:
							     return (aMethod4[nPositingIndex]);	
							     break;
						   case 4:
							     return (aMethod5[nPositingIndex]);	
							     break;
							 default:
							     return -1;
							     break;									 									 									 									 
						}
						
            return -1;
				}
					
					

					
					// ---------------------------------------
					//  Savings off listed price
					// ---------------------------------------
					function DisplayTotalPriceSavings()
					{
    					var nSavings,nPercent;
    					
    					nSavings=nTotalListedCost-nTotalCost;
    					nPercent=nSavings/nTotalListedCost;
    					nPercent*=100;
							
    					document.write("<br><u style='font-size:20px'>Products</u>");
    					document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");				
							document.write("<tr><th>Items</th><th>Price (US$)</th></tr>");
    					document.write("<tr><td class=desc>Total listed price</td><td align=right><strike style='color:black'>"+"US$"+nTotalListedCost.toFixed(2)+"</strike></td></tr>");		
    					document.write("<tr><td class=desc>Your price</td><td align=right><b style='font-size:24px;color:red'>"+"US$"+nTotalCost.toFixed(2)+"</b></td></tr>");
    					document.write("<tr><td class=desc>Total savings</td><td align=right>You saved <b style='color:blue'>"+"US$"+nSavings.toFixed(2)+"</b><br>or <b style='color:blue'>"+nPercent.toFixed(2)+"%</b> off</td></tr>");		
																		
    					document.write("");				
    					document.write("");				
    					document.write("</table>");																																			
					}		
					
					

					// ---------------------------------------
					//  Savings off listed price
					// ---------------------------------------
					function DisplaySHSavings()
					{
    					var nSavings,nPercent;
							var nTotalWeightSHCost;
    				
						  //nTotalWeightSHCost=DetermineSHCost_ByMethodNWeight(1);
    					nSavings=(aSHCost[1]-nTotalWeightSHCost);
    					nPercent=(nTotalSH_Original-nTotalSH_Weight)/nTotalSH_Original;
    					nPercent*=100;
							
    					document.write("<br><u style='font-size:20px'>Additional savings from Shipping and Handling due to multiple-item purchase</u>");
						
    					document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");
									
							document.write("<tr><th>Items</th><th>Price (US$)</th></tr>");
    					document.write("<tr><td class=desc>Total no of items purchased</td><td align=right>"+nTotalItems+"</td></tr>");		
    					document.write("<tr><td class=desc>Total weight (grams)</td><td align=right>"+nTotalWeight+"</td></tr>");
    					document.write("<tr><td class=desc>Average S/H cost per KG</td><td align=right>"+"US$"+((nTotalSH_Weight*1000)/nTotalWeight).toFixed(2)+"</td></tr>");
    					document.write("<tr><td class=desc>Average S/H cost per item</td><td align=right>"+"US$"+((nTotalSH_Weight)/nTotalItems).toFixed(2)+"</td></tr>");																
    					document.write("<tr><td class=desc>Original S/H cost </td><td align=right><strike style='color:black'>"+"US$"+nTotalSH_Original+"</strike></td></tr>");		
    					document.write("<tr><td class=desc>Composite weighted S/H Cost</td><td align=right><b style='font-size:24px;color:red'>"+"US$"+nTotalSH_Weight+"</b></td></tr>");
    					document.write("<tr><td class=desc>S/H savings</td><td align=right>You saved <b style='color:blue'>"+"US$"+(nTotalSH_Original-nTotalSH_Weight).toFixed(2)+"</b><br>or additional <b style='color:blue'>"+nPercent.toFixed(2)+"%</b> off</td></tr>");		
																			
    					document.write("");				
    					document.write("");				
    					document.write("</table>");																																										
					}		
					
					function DisplayTotalSavings()
					{
    					var nSavings,nPercent,nOriginalCost,nFinalCost=0;
							var nTotalWeightSHCost;
							
    				
						  //nTotalWeightSHCost=DetermineSHCost_ByMethodNWeight(1);
							nOriginalCost=+nTotalSH_Original+nTotalListedCost;
							//alert(nTotalCost);
							//alert(nTotalSH_Weight);							
							nFinalCost= +nTotalCost;
							nFinalCost+=+nTotalSH_Weight;
							nFinalCost=+nFinalCost.toFixed(2);
							//alert(nFinalCost);
							//nFinalCost=nFinalCost;


							nSavings = +nTotalListedCost+ +nTotalSH_Original- +nTotalCost- +nTotalSH_Weight;
							nSavings = + nSavings.toFixed(2);
							//alert(nSavings);
    					nPercent=+nSavings/(+nOriginalCost);
    					nPercent*=100;
							nPercent= +nPercent.toFixed(2);
							
    					document.write("<br><u style='font-size:20px'>Total savings purchasing from <i>The MP3/MP4 Store</i><Br>(after factoring in product and shipping/handling cost)</u>");
						
    					document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");
									
							document.write("<tr><th>Items</th><th>Price (US$)</th></tr>");
    					document.write("<tr><td class=desc>Total no of items purchased</td><td align=right>"+nTotalItems+"</td></tr>");		
    					document.write("<tr><td class=desc>Total weight (grams)</td><td align=right>"+nTotalWeight+"</td></tr>");
    					//document.write("<tr><td class=desc>Average S/H cost per KG</td><td align=right>"+"US$"+((nTotalSH_Weight*1000)/nTotalWeight).toFixed(2)+"</td></tr>");
    					//document.write("<tr><td class=desc>Average S/H cost per item</td><td align=right>"+"US$"+((nTotalSH_Weight)/nTotalItems).toFixed(2)+"</td></tr>");																
    					document.write("<tr><td class=desc>Original total cost </td><td align=right><strike style='color:black'>"+"US$"+nOriginalCost.toFixed(2)+"</strike></td></tr>");		
   					  document.write("<tr><td class=desc>Final total product cost (after deduction)</td><td align=right><b >"+"US$"+nTotalCost.toFixed(2) +"</b></td></tr>");
   					  document.write("<tr><td class=desc>Final total S/H cost (after deduction)</td><td align=right><b >"+"US$"+ nTotalSH_Weight+"</b></td></tr>");
    					document.write("<tr><td class=desc>Final total Cost (after deduction)</td><td align=right><b style='font-size:24px;color:red'>"+"US$"+ +nFinalCost+"</b></td></tr>");
    					document.write("<tr><td class=desc>Total savings</td><td align=right>You saved <b style='color:blue'>"+"US$"+nSavings+"</b><br>or additional <b style='color:blue'>"+nPercent+"%</b> off</td></tr>");		
																			
    					document.write("");				
    					document.write("");				
    					document.write("</table>");																																										
					}							
					
					// ---------------------------------------
					//
					// ---------------------------------------										
					function DisplaySHSavingsFromSingapore()
					{
    					var nSavings,nPercent;
							var nTotalWeightSHCost;
    				
						  nTotalWeightSHCost=DetermineSHCost_ByMethodNWeight(1);
    					nSavings=(aSHCost[1]-nTotalWeightSHCost);
    					nPercent=nSavings/aSHCost[1];
    					nPercent*=100;
							
    					document.write("<br><u style='font-size:20px'>Additional savings from worldwide single-shipment multiple-item purchase<br>(shipped from Singapore via SingPost: 2 business days + 5-12 days)</u>");
						
    					document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");				
							document.write("<tr><th>Items</th><th>Price (US$)</th></tr>");
    					document.write("<tr><td class=desc>Original S/H cost </td><td align=right><strike style='color:black'>"+"US$"+aSHCost[1].toFixed(2)+"</strike></td></tr>");		
    					document.write("<tr><td class=desc>Composite S/H Cost</td><td align=right><b style='font-size:24px;color:red'>"+"US$"+nTotalWeightSHCost+"</b></td></tr>");
    					document.write("<tr><td class=desc>S/H savings</td><td align=right>You saved <b style='color:blue'>"+"US$"+nSavings.toFixed(2)+"</b><br>or additional <b style='color:blue'>"+nPercent.toFixed(2)+"%</b> off</td></tr>");		
									
    					document.write("</table>");																																										
					}												
					
											
					// -----------------------------------------------------------------
					//  Display breakdowns of statistics via different shipping methods
					// -----------------------------------------------------------------
					function DisplayShippingBreakdowns()
					{

							 var nSubWeight=0,nIndividualSH=0,nWeight=0;

              																			
							 document.write("<br><u style='font-size:20px'>Shipping Breakdown</u><br>");
							 										 
							 //
							 // Calculate no of items and sub-total-weight
							 //
               for (i=0;i<nPurchases;i++)
               {
                 if (aCartFields[(i*nNoOfFields)+4]=="sah/sah1.htm")
              	 {
              	   aShipFromSource[0]+= +aCartFields[(i*nNoOfFields)+3];
              		 aWeightFromSource[0]+=  (+aCartFields[(i*nNoOfFields)+1]* +aCartFields[(i*nNoOfFields)+3]);

              	 }
                 else if (aCartFields[(i*nNoOfFields)+4]=="sah/sah2.htm")
              	 {
              	   aShipFromSource[1]+=  +aCartFields[(i*nNoOfFields)+3];
              		 aWeightFromSource[1]+= (+aCartFields[(i*nNoOfFields)+1]* +aCartFields[(i*nNoOfFields)+3]);
									 
						 
              	 }	
                 else if (aCartFields[(i*nNoOfFields)+4]=="sah/sah3.htm")
              	 {
              	   aShipFromSource[2]+=  +aCartFields[(i*nNoOfFields)+3];							 
              		 aWeightFromSource[2]+= (+aCartFields[(i*nNoOfFields)+1]* +aCartFields[(i*nNoOfFields)+3]);

              	 }	
                 else if (aCartFields[(i*nNoOfFields)+4]=="sah/sah4.htm")
              	 {
              	   aShipFromSource[3]+=  +aCartFields[(i*nNoOfFields)+3];							 
              		 aWeightFromSource[3]+= (+aCartFields[(i*nNoOfFields)+1]* +aCartFields[(i*nNoOfFields)+3]);

              	 }								 							 						 
              	 else
              	 {
              	   aShipFromSource[4]+=  +aCartFields[(i*nNoOfFields)+3];							 
              		 aWeightFromSource[4]+= (+aCartFields[(i*nNoOfFields)+1]* +aCartFields[(i*nNoOfFields)+3]);

              	 }								 
              }
													
							//
							//  Calculate total cost for each shipping method
							//													
							for (i=0;i<aSHCostWtM.length;i++)
							{ 
							    aSHCostWtM[i]=DetermineSHCost_ByMethodNWeight(i);
							}								 

  						//
							//   Calculate sub-total
							//
							for (i=0;i<aSHCostWtM.length;i++)
							{
							    nWeight+=+aSHCostWtM[i];
									nSubWeight+=+aSHCost[i];
							}							
							
							//
							// Display break-down table
							//
              document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");					
              document.write("<tr><th>Shipping Data</th><th>No of items</th><th >Total weight<br>(gms)</th><th>S/H<br>(Individual pieces)<Br>(US$)</th><th>S/H<br>Weight Method<br>(US$)</th><th>Via cheapest<br>chosen S/H<br>Carrier<br>(US$)</th><th>Savings<br>(US$)</th><th>Savings<br>(%)</th></tr>");							 			 			

              var aShippingMethod=new Array("","","","","");
							
							//
							// Update shipping method
							//
               for (i=0;i<aSHCost.length;i++)
               {							    									
									if (i==1)  // ship from Singapore
									{
									   switch (nChoseShippingMethod)
										 {
										   case 0:
									        aShippingMethod[i]=aSL[i];
													break;
										   case 1:
									        aShippingMethod[i]="Singapore (via SpeedPost)<br>[2 business days + 2-4 days]";
													break;
										   case 2:
									        aShippingMethod[i]="Singapore (DHL)<br>[1 business day + 4 days]";
													break;													
											 default:
											    aShippingMethod[i]="unknown"
											    break;													
										 }
									}
									else
									{
									   aShippingMethod[i]=aSL[i];
									}
							 }	
							 						
               //
							 //
							 //
							 var nNewTotalSHCost=0,nSavings=0;							
               for (i=0;i<aSHCost.length;i++)
               {

       
			            if ((i==1)&&(nChoseShippingMethod!=0))
									{
									    nTemp3= aSHCostWtM[i];   																	
									}
									else
			            		nTemp3=((aSHCost[i]<=aSHCostWtM[i])?aSHCost[i]:aSHCostWtM[i]);
									
									nNewTotalSHCost+=+nTemp3;
									nSavings+= +(+aSHCost[i]-nTemp3);
									
									if (aShipFromSource[i]!=0)
									{
              	      document.write("<tr><td class=desc>"+ aShippingMethod[i]+"</td>");
											
    									//nTemp3=nTemp3.toFixed(2);
               		    document.write("<td align=right>"+" "+aShipFromSource[i]+"</td>");
               		    document.write("<td align=right>"+" "+ aWeightFromSource[i]+"</td>");
               		    document.write("<td align=right>"+aSHCost[i].toFixed(2)+"</td>");
               		    //document.write("<td align=right>"+aSH_Weight[i]	+"</td>");
               		    document.write("<td align=right>"+aSHCostWtM[i]+"</td>");									
               		    //document.write("<td align=right>"+lowervalue(aSHCost[i],aSHCostWtM[i])+"</td>");	
               		    document.write("<td class=sh1 align=right>"+nTemp3+"</td>");	
               		    //document.write("<td align=right>"+nSavings+"</td>");
               		    //document.write("<td align=right>"+SavingsPercent(aSHCost[i],aSHCostWtM[i])+"</td></tr>");																																																																										
               		    document.write("<td align=right>"+Savings(aSHCost[i],nTemp3)+"</td>");
               		    document.write("<td align=right>"+SavingsPercent(aSHCost[i],nTemp3)+"</td></tr>");
									}																																																																										
              }

							
							nTotalSH_Original=nSubWeight.toFixed(2);
							nTotalSH_Weight=nWeight.toFixed(2);
																							
							document.write("<tr><td align=center class=total>Total</td><td class=total></td><td class=total></td><td align=right class=total>"+nSubWeight.toFixed(2)+"</td><td class=total align=right>"+nWeight.toFixed(2)+"</td><td class=total align=right>"+lowervalue(nSubWeight.toFixed(2),nWeight.toFixed(2))+"</td><td align=right class=total>"+nSavings.toFixed(2)+"</td><td align=right class=total>"+((100*nSavings)/nWeight).toFixed(2)+"</td></tr>");
        
							document.write("</table>");															
					}										
		function DisplayTitleBlock(szTitleMessage)
		{

			 document.write('<div width=100% align=center style="background-color:lightblue">');
		   document.write('<span style="font-size:24px;font-face:impact">The MP3/MP4 Store</span>');
			 document.write('<br>['+szTitleMessage+']');			 
			 document.write('</div>');
		}			
		function DisplaySHSavings_Message()
		{
		   document.write('<div style="color:red;font-size:12px;color:blue">');
		   document.write('<br># There may be additional savings off the listed shipping and handling (S/H) fee if mutliple items are purchased together.');
		   document.write('<br>@ The listed shipping and handling (S/H) fee for shipment from Singapore is for shipment via the most economical SingPost (1 to 2 weeks including signature service and insurance). Faster deliveries via difference couriers are available at a higher price.');
			 document.write('<br>1 "Ship from 1" refers from goods shipping from the state of California via Federal Express (to 48 states USA only).');
			 document.write('<br>2 "Ship from 2" refers from goods shipping from the Asia (Singapore) via Singapore Post (& local post-offices) to world-wide locations.');
			 document.write('<br>3 "Ship from 3" refers from goods shipping from the state of California via UPS (to 48 states USA only).');
			 
		   document.write('</div>');					 					 
		}			
		
		function UpdateShoppingCartTotalData(nStatus,nNoOfItems,nTotalProductCost,nTotalSH,nTotalCost)
		{
/*
			var gsShoppingCartName_status="ShoppingCart_status";
			var gsShoppingCartName_total_no="ShoppingCart_nTotalNo";
			var gsShoppingCartName_total_product_cost="ShoppingCart_nTProductCost";
			var gsShoppingCartName_total_sh_cost="ShoppingCart_nTSHCost";
			
			      return getCookie(gsShoppingCartName);	 
			}								
			function UpdateShoppingCart(sValue)
			{
			      setCookie(gsShoppingCartName,sValue);					
*/		
		   setCookie(gsShoppingCartName_status,nStatus);		
		   if (nNoOfItems!=null) setCookie(gsShoppingCartName_total_no,nNoOfItems);		
		   if (nTotalProductCost!=null) setCookie(gsShoppingCartName_total_product_cost,nTotalProductCost);		
		   if (nTotalSH!=null) setCookie(gsShoppingCartName_total_sh_cost,nTotalSH);		
			 			 			 			 
		   return 0;
		}
		
		var aSC=new Array(0,0,0,0,0,0);
		function RetriveShoppingCartData(nDataIndex)
		{
		  // 0: Status
			// 1: Total no of products
			// 2: Total product cost
			// 3: Total SH
			// 4: Total cost
		 	//
			//  Update data to choosen variable
			//
			
			aSC[0]=getCookie(gsShoppingCartName_status);
			aSC[1]=getCookie(gsShoppingCartName_total_no);
			aSC[2]=getCookie(gsShoppingCartName_total_product_cost);
			aSC[3]=getCookie(gsShoppingCartName_total_sh_cost);
			aSC[4]= +aSC[3] + +aSC[2];
	

		  return 0;						 
		}		
		
        // ------------------------------------------------------
        //  Display
        // ------------------------------------------------------												 
				function DisplayShoppingCart(bModifiable)
				{		 			 
					 nStart=0;					 
					 nPtr=0;

					 if (bModifiable==null) bModifiable=0;
					 
           document.write("<hr><u style='font-size:20px'>Selected items in Shopping Cart:</u><br>");					 
					// ------------------------------------------------------
					//  Retrive data from shopping cart cookie
					// ------------------------------------------------------
					 aCart=RetriveDataShoppingCart();		
					 while (nPtr<aCart.length)
					 {							
							// Extract fields (delimited by |)
							// Record separated by ,							
							if (aCart.substr(nPtr,1)=="|")
							{
								 aCartFields[nCartCount++]=aCart.substr(nStart,nPtr-nStart);
								 
								 nStart=nPtr+1;
							   nPurchases++;								 
							}
							//else if (aCart.substr(nPtr,nPtr-nStart)==",")
							else if (aCart.substr(nPtr,1)==",")
							{
								 //aCartFields[nCartCount++]=aCart.substr(nStart,nPtr-nStart);
							   nStart=nPtr+1;
							}														
							nPtr++;
					 }
					 
					 
					 //
					 // Calculate no of different items purchased (multiple purchase of same item is counted as 1)
					 //
					 nPurchases/=nNoOfFields;
					
					// ------------------------------------------------------
					//  Display break-down table of purchases
					// ------------------------------------------------------					 
					document.write("<table style='border-color:black;border-width:3px;border-style:solid'>");				
					document.write("<tr style='background-color:cyan'><th>S/N</th><th>Desc</th><th>Product<br>Code</th><th>Unit<br>Wt</th><th>Price<br>(US$)</th><th>Qty<br><input type=button value='Recalculate' id='recalculate' onclick='updateqty()'");
					if (bModifiable==0)
					{
					   document.write(' disabled=true ');
					}					
					document.write("></th><th>Total<br>Cost<br>(US$)</th><th>Savings<br>(%)</th><th>S/H<br>(US$)<br><span style='font-size:10px'>#@</span></th><th>"+"Total Cost<br>(US$)"+"</th><th>Ship<br>Fm</th></tr>");							 
					//document.write("<tr style='background-color:cyan'><th>S/N</th><th>Desc</th><th>Product Code</th><th>Weight</th><th>Price</th><th>Qty</th><th>Total Cost</th><th>Total Listed Price</th><th>S/H</th><th>"+"Total Cost"+"</th><th>Fm</th></tr>");							 
					
					// 
					//  Display by individual items
					// 
					var szProductCode;
					
					for (i=0;i<nPurchases;i++)
					{
					    nSubListedPrice=0;
							nSubCost=0;
							nSubSH=0;
							nSHT=0;
							
						  szProductCode=aCartFields[(i*nNoOfFields)+0];

				
							nIndex=SearchOPByItemCode(szProductCode);
			
              if (nIndex==-1)
							{
						
							   // Supposed to check again MP3 codes					
								 nIndex=SearchMP34ByItemCode(szProductCode);
								 if (nIndex==-1)
								 {		
							       document.write("unable to find for code :"+aCartFields[(i*nNoOfFields)+0]);
								 }
								 else
								 {
      							nTemp=aCartFields[(i*nNoOfFields)+3].valueOf();
      							nTotalItems  +=+nTemp;
      
      							nSubCost=aCartFields[(i*nNoOfFields)+2].valueOf()*aCartFields[(i*nNoOfFields)+3].valueOf();
      							nTotalCost   +=+nSubCost;  
      
      							nTemp=aCartFields[(i*nNoOfFields)+3].valueOf()*aCartFields[(i*nNoOfFields)+1].valueOf();
      							nTotalWeight +=+nTemp;
  									
  									//
  									//  Update total weight for each shipping method
  									//
  									if (Column[(nIndex*nRecordSize)+22]=="sah/sah1.htm")
  									{									
  									 nSHT=1;
  									 aSH_Weight[0]+= +nTemp;									 
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah2.htm")
  									{									
  									 nSHT=2;
  									 nTotalWt_2+= +nTemp;
  									 aSH_Weight[1]+= +nTemp;
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah3.htm")
  									{									
  									 nSHT=3;
  									 aSH_Weight[2]+= +nTemp;									 
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah4.htm")
  									{									
  									 nSHT=4;
  									 aSH_Weight[3]+= +nTemp;									 
  									}
  									else
  									{
  									 nSHT=9;
  									 aSH_Weight[4]+= +nTemp;									 
  									}				

  									//
  									//  Calculate cost of each shipping method
  								  //
  									if (aCartFields[(i*nNoOfFields)+3].valueOf()==1)
  									{
        							nSubSH=1*Column[(nIndex*nRecordSize)+6];     // 1 X SH1
        							nOriginalSHF +=+nSubSH;
  										
  										if (Column[(nIndex*nRecordSize)+21]=="sah/sah2.htm")
  										{ 
  											nSPSH+= +nSubSH;
  										}											
  									}
  									else
  									{
  									  nTemp2=(aCartFields[(i*nNoOfFields)+3] - +1);
  									  nSubSH  =  1*Column[(nIndex*nRecordSize)+6];
        							
  										nSubSH +=  (nTemp2 * +Column[(nIndex*nRecordSize)+6])  ;  // SH1 + (N-1)X SH2    <------Use original (without multiple-item savings)
  										//nSubSH +=  (nTemp2 * +Column[(nIndex*nRecordSize)+23])  ;  // SH1 + (N-1)X SH2    <------ Used adjusted (with savings)
  										
        							nOriginalSHF += +nSubSH;																																														
  									}						   
  												
  									//
  									//  Update original S/H charges (individual piece purchase without regards for weight)
  									//
  									if (Column[(nIndex*nRecordSize)+22]=="sah/sah1.htm")
  									{									
  									 aSHCost[0] += +nSubSH;
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah2.htm")
  									{									
  									 aSHCost[1] +=+nSubSH;
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah3.htm")
  									{									
  									 aSHCost[2] +=+nSubSH;
  									}
  									else if (Column[(nIndex*nRecordSize)+22]=="sah/sah4.htm")
  									{									
  									 aSHCost[3] +=+nSubSH;
  									}
  									else
  									{
  									 aSHCost[4] +=+nSubSH;
  									}													
  																							
  									//
  									// Update total listed price
  									//
      							nSubListedPrice=aCartFields[(i*nNoOfFields)+3]*Column[(nIndex*nRecordSize)+19];				 // No x listed-price
      							nTotalListedCost +=+nSubListedPrice;		
  
  									//
  									// Update total cost of products (excludes S/H) to buyers
  									//									
      							nSubTotalCost=aCartFields[(i*nNoOfFields)+3].valueOf()*aCartFields[(i*nNoOfFields)+2].valueOf();					    																						
																		 
								 }
								 

	 					     document.write("<tr><td>"+(i+1)+"</td>");
								 document.write("<td class=desc>"+Column[(nIndex*nRecordSize)+1]+"</td>");
								 document.write("<td align=right >"+aCartFields[(i*nNoOfFields)+0]+"</td>");
								 document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+1]+"</td>");
								 document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+2]+"</td>");
							   document.write("<td align=right>"+'<input ');
                  if (bModifiable==0)
                  {
                    document.write(' disabled=true ');
                  }								 
								 document.write('type="text" size=10 id="purchase_qty'+i+'" value="'+aCartFields[(i*nNoOfFields)+3]+'">'+"</td>");
									 
								 //document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+3]+"</td>");
								 document.write("<td class=sh1 align=right>"+nSubCost.toFixed(2)+"</td>");
								 document.write("<td align=right>save "+(((+nSubListedPrice-nSubCost)*100)/+nSubListedPrice).toFixed(2)+"%</td>");
								 //document.write("<td align=right>"+nSubListedPrice.toFixed(2)+"</td>");								 
								 document.write("<td class=sh1 align=right>"+nSubSH.toFixed(2)+"</td>");
								 document.write("<td class=sh2 align=right>"+(nSubSH+nSubCost).toFixed(2)+"</td>");
								 document.write("<td align=right>"+nSHT+"</td>");

								 //document.write("<td>"+'<input type="checkbox" id="" value="" onclick="tohomepage()">'+"</td></tr>");												 
							}
							else
							{				 									 									 																									
    							nTemp=aCartFields[(i*nNoOfFields)+3].valueOf();
    							nTotalItems  +=+nTemp;
    
    							nSubCost=aCartFields[(i*nNoOfFields)+2].valueOf()*aCartFields[(i*nNoOfFields)+3].valueOf();
    							nTotalCost   +=+nSubCost;  
    
    							nTemp=aCartFields[(i*nNoOfFields)+3].valueOf()*aCartFields[(i*nNoOfFields)+1].valueOf();
    							nTotalWeight +=+nTemp;
									
									//
									//  Update total weight for each shipping method
									//
									if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah1.htm")
									{									
									 nSHT=1;
									 aSH_Weight[0]+= +nTemp;									 
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah2.htm")
									{									
									 nSHT=2;
									 nTotalWt_2+= +nTemp;
									 aSH_Weight[1]+= +nTemp;
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah3.htm")
									{									
									 nSHT=3;
									 aSH_Weight[2]+= +nTemp;									 
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah4.htm")
									{									
									 nSHT=4;
									 aSH_Weight[3]+= +nTemp;									 
									}
									else
									{
									 nSHT=9;
									 aSH_Weight[4]+= +nTemp;									 
									}		
									
									//
									//  Calculate cost of each shipping method
								  //
									if (aCartFields[(i*nNoOfFields)+3].valueOf()==1)
									{
      							nSubSH=1*aFMD[(nIndex*aRecordSize)+2];     // 1 X SH1
      							nOriginalSHF +=+nSubSH;
										
										if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah2.htm")
										{ 
											nSPSH+= +nSubSH;
										}											
									}
									else
									{
									  nTemp2=(aCartFields[(i*nNoOfFields)+3] - +1);
									  nSubSH  =  1*aFMD[(nIndex*aRecordSize)+2];
      							
										nSubSH +=  (nTemp2 * +aFMD[(nIndex*aRecordSize)+2])  ;  // SH1 + (N-1)X SH2    <------Use original (without multiple-item savings)
										//nSubSH +=  (nTemp2 * +aFMD[(nIndex*aRecordSize)+6])  ;  // SH1 + (N-1)X SH2    <------ Used adjusted (with savings)
										
      							nOriginalSHF += +nSubSH;																																														
									}						   
												
									//
									//  Update original S/H charges (individual piece purchase without regards for weight)
									//
									if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah1.htm")
									{									
									 aSHCost[0] += +nSubSH;
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah2.htm")
									{									
									 aSHCost[1] +=+nSubSH;
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah3.htm")
									{									
									 aSHCost[2] +=+nSubSH;
									}
									else if (aFMD[(nIndex*aRecordSize)+9]=="sah/sah4.htm")
									{									
									 aSHCost[3] +=+nSubSH;
									}
									else
									{
									 aSHCost[4] +=+nSubSH;
									}													
																							
									//
									// Update total listed price
									//
    							nSubListedPrice=aCartFields[(i*nNoOfFields)+3]*aFMD[(nIndex*aRecordSize)+3];				 // No x listed-price
    							nTotalListedCost +=+nSubListedPrice;		

									//
									// Update total cost of products (excludes S/H) to buyers
									//									
    							nSubTotalCost=aCartFields[(i*nNoOfFields)+3].valueOf()*aCartFields[(i*nNoOfFields)+2].valueOf();					    																						
					        

									document.write("<tr><td>"+ (i+1) + "</td>");
									document.write("<td class=desc>"+aFMD[(nIndex*aRecordSize)+0]+"</td>");
									document.write("<td align=right >"+aCartFields[(i*nNoOfFields)+0]+"</td>");
									document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+1]+"</td>");
									document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+2]+"</td>");
								  document.write("<td align=right>"+'<input ');
                  if (bModifiable==0)
                  {
                    document.write(' disabled=true ');
                  }													
									document.write('size=10 type="text" id="purchase_qty'+i+'" value="'+aCartFields[(i*nNoOfFields)+3]+'">'+"</td>");									
									//document.write("<td align=right>"+aCartFields[(i*nNoOfFields)+3]+"</td>");
									document.write("<td class=sh1 align=right>"+nSubCost.toFixed(2)+"</td>");
									document.write("<td align=right>save "+(((+nSubListedPrice-nSubCost)*100)/+nSubListedPrice).toFixed(2)+"%</td>");
									//document.write("<td align=right>"+nSubListedPrice.toFixed(2)+"</td>");									
									document.write("<td class=sh1 align=right>"+nSubSH.toFixed(2)+"</td>");
									document.write("<td class=sh2 align=right>"+(nSubSH+nSubCost).toFixed(2)+"</td>");
								  document.write("<td align=right>"+nSHT+"</td>");
	
						 				
							}		
							
							//
							//  Display individual purchased item summary
							//																			
					 }		 
					 //
					 // Display total purchased summary
					 //
					 document.write("<tr style='background-color:red'><td class='total'>-</td><td align=center class='total'>Total</td><td class='total'>-</td><td class='total' align=right>"+nTotalWeight+"gms </td><td  class='total' align=right>"+"-"+"</td><td  class='total'align=right>"+nTotalItems+"</td><td  class='total'align=right> US$"+nTotalCost.toFixed(2)+"</td><td  class='total' align=right>save "+((100*(+nTotalListedCost-nTotalCost))/+nTotalListedCost).toFixed(2)+"%</td><td class='total'>US$"+nOriginalSHF.toFixed(2)+"</td><td class='total'>US$"+(nOriginalSHF+nTotalCost).toFixed(2)+"</td></tr>");
					 //document.write("<tr style='background-color:red'><td class='total'>-</td><td align=center class='total'>Total</td><td class='total'>-</td><td class='total' align=right>"+nTotalWeight+"gms </td><td  class='total' align=right>"+"-"+"</td><td  class='total'align=right>"+nTotalItems+"</td><td  class='total'align=right> US$"+nTotalCost.toFixed(2)+"</td><td  class='total' align=right>US$"+nTotalListedCost.toFixed(2)+"</td><td class='total'>US$"+nOriginalSHF.toFixed(2)+"</td><td class='total'>US$"+(nOriginalSHF+nTotalCost).toFixed(2)+"</td></tr>");

					 document.write("</table>");
					 
					 if (bModifiable==0)
					 {
					    //recalculate.disabled=true;
							//
							//  Better to insert codes when creating sources (although it would be a little bit messy)
							//
					 }
				}


  			function RemoveBlank(szvalue)
  			{
  			   var szNewValue="";								 
  					 var nLen,hhh;
  					
  					 nLen=szvalue.length;							
  					 hhh=0;
  					 while (hhh<nLen)
  				 { 
  				 	  if (szvalue.substr(hhh,1)==" ")
  						{
  						   //
  							 //alert(" == ");
  						}
  						else
  						{
  						   szNewValue+=szvalue.substr(hhh,1);
  						}
  						hhh++;
  				 }								 
  				 return szNewValue;
  			}			
					
				function updateqty()
				{
				   var aQty = new Array(0,0,0,0,0,0,0,0,0,0);

					 // update to cookies
			    if (nPurchases>=1) aQty[0]=RemoveBlank(purchase_qty0.value);
			    if (nPurchases>1) aQty[1]=RemoveBlank(purchase_qty1.value);
			    if (nPurchases>2) aQty[2]=RemoveBlank(purchase_qty2.value);
			    if (nPurchases>3) aQty[3]=RemoveBlank(purchase_qty3.value);
			    if (nPurchases>4) aQty[4]=RemoveBlank(purchase_qty4.value);
			    if (nPurchases>5) aQty[5]=RemoveBlank(purchase_qty5.value);
			    if (nPurchases>6) aQty[6]=RemoveBlank(purchase_qty6.value);
			    if (nPurchases>7) aQty[7]=RemoveBlank(purchase_qty7.value);
			    if (nPurchases>8) aQty[8]=RemoveBlank(purchase_qty8.value);
			    if (nPurchases>9) aQty[9]=RemoveBlank(purchase_qty9.value);
			    if (nPurchases>10) aQty[10]=RemoveBlank(purchase_qty10.value);
			    if (nPurchases>11) aQty[11]=RemoveBlank(purchase_qty11.value);
			    if (nPurchases>12) aQty[12]=RemoveBlank(purchase_qty12.value);
			    if (nPurchases>13) aQty[13]=RemoveBlank(purchase_qty13.value);
			    if (nPurchases>14) aQty[14]=RemoveBlank(purchase_qty14.value);
			    if (nPurchases>15) aQty[15]=RemoveBlank(purchase_qty15.value);
			    if (nPurchases>16) aQty[16]=RemoveBlank(purchase_qty16.value);
			    if (nPurchases>17) aQty[17]=RemoveBlank(purchase_qty17.value);
			    if (nPurchases>18) aQty[18]=RemoveBlank(purchase_qty18.value);
			    if (nPurchases>19) aQty[19]=RemoveBlank(purchase_qty19.value);
			    if (nPurchases>20) aQty[20]=RemoveBlank(purchase_qty20.value);
			    if (nPurchases>21) aQty[21]=RemoveBlank(purchase_qty21.value);
			    if (nPurchases>22) aQty[22]=RemoveBlank(purchase_qty22.value);
			    if (nPurchases>23) aQty[23]=RemoveBlank(purchase_qty23.value);
			    if (nPurchases>24) aQty[24]=RemoveBlank(purchase_qty24.value);
			    if (nPurchases>25) aQty[25]=RemoveBlank(purchase_qty25.value);
			    if (nPurchases>26) aQty[26]=RemoveBlank(purchase_qty26.value);
			    if (nPurchases>27) aQty[27]=RemoveBlank(purchase_qty27.value);
			    if (nPurchases>28) aQty[28]=RemoveBlank(purchase_qty28.value);
			    if (nPurchases>29) aQty[29]=RemoveBlank(purchase_qty29.value);

/*
			    if (nPurchases>=1) aQty[0]=purchase_qty0.value;
			    if (nPurchases>1) aQty[1]=purchase_qty1.value;
			    if (nPurchases>2) aQty[2]=purchase_qty2.value;
			    if (nPurchases>3) aQty[3]=purchase_qty3.value;
			    if (nPurchases>4) aQty[4]=purchase_qty4.value;
			    if (nPurchases>5) aQty[5]=purchase_qty5.value;
			    if (nPurchases>6) aQty[6]=purchase_qty6.value;
			    if (nPurchases>7) aQty[7]=purchase_qty7.value;
			    if (nPurchases>8) aQty[8]=purchase_qty8.value;
			    if (nPurchases>=9) aQty[9]=purchase_qty9.value;
			    if (nPurchases>10) aQty[10]=purchase_qty10.value;
			    if (nPurchases>11) aQty[11]=purchase_qty11.value;
			    if (nPurchases>12) aQty[12]=purchase_qty12.value;
			    if (nPurchases>13) aQty[13]=purchase_qty13.value;
			    if (nPurchases>14) aQty[14]=purchase_qty14.value;
			    if (nPurchases>15) aQty[15]=purchase_qty15.value;
			    if (nPurchases>16) aQty[16]=purchase_qty16.value;
			    if (nPurchases>17) aQty[17]=purchase_qty17.value;
			    if (nPurchases>18) aQty[18]=purchase_qty18.value;
			    if (nPurchases>19) aQty[19]=purchase_qty19.value;
			    if (nPurchases>20) aQty[20]=purchase_qty20.value;
			    if (nPurchases>21) aQty[21]=purchase_qty21.value;
			    if (nPurchases>22) aQty[22]=purchase_qty22.value;
			    if (nPurchases>23) aQty[23]=purchase_qty23.value;
			    if (nPurchases>24) aQty[24]=purchase_qty24.value;
			    if (nPurchases>25) aQty[25]=purchase_qty25.value;
			    if (nPurchases>26) aQty[26]=purchase_qty26.value;
			    if (nPurchases>27) aQty[27]=purchase_qty27.value;
			    if (nPurchases>28) aQty[28]=purchase_qty28.value;
			    if (nPurchases>29) aQty[29]=purchase_qty29.value;
*/					
					
          // Check data
					function ValidQuantityValue(szvalue)
					{
              function isDigit(n) 
							{
                if((n < "0") || ("9" < n)) {
                			return false
                }
                else {
                		 return true
                }
              }

							
							// Remove Blanks
/*							
							var szNewValue;

				      szNewValue=RemoveBlank(szvalue);
							
							// supposed to 
							alert(szNewValue);
*/							
							//
							// Verify all digits
							//
							var nLen,hhh;
							
							nLen=szvalue.length;	hhh=0;
							while (hhh<nLen) if (isDigit(szvalue.substr(hhh++,1))==false) return -1;
							
							
					    return 0; // verified only contains digits
					}
					
					function VerfiyQtyValue()
					{
					    for (i=0;i<nPurchases;i++)
							{
							 		if (ValidQuantityValue(aQty[i])<0)
									{
									
									    return -1;
									}
									if (aQty[i]>99)
									{
									   alert("Quantity not supposed to exceed 99...."); 
										 return -1;
									}
							}
							
					 		return 0;
					}
					
          // [supposed to verify that data is numeric and is within range of 99 (or other amount) pieces]
          if (VerfiyQtyValue()<0)
          {
					 	 alert("Invalid quantity value, please enter again and 'Recalculate' again");   

             // suppoed to reupdate with old unmodified value
						 
						 //return -1;
						 self.location="shopping_cart.htm";
						 return -1; 
          }					 

					// ---------------------------------------
					//  Reset cookie
					// ---------------------------------------	
					var nNewTotalQty=0;
					var yyy;
					
          UpdateShoppingCart("*");
					 	
					// ---------------------------------------
					//  Reupdate cookies with new value
					// ---------------------------------------
					for (yyy=0;yyy<nPurchases;yyy++)
					{
				     	//alert(aQty[yyy]);
					    if (aQty[yyy]>=0)
							{
							    nNewTotalQty++;
									
									// [Update cookie here]
							    if (aQty[yyy]>0)
									{ 
									   AppendShoppingCart(aCartFields[(yyy*nNoOfFields)+0],aQty[yyy]);
									}		
									else
									{
									   // drop from shopping cart [not updating to cart]
										 //alert("droped");
									} 																
							}		
							else
							{
							    //alert(" aQty[yyy] <0");
							}					
					}

					// ---------------------------------------
					//
					// ---------------------------------------												
          //																			 
          // refresh
          //
          // self.history.go(0);   //<----should be http://www.mp34store.com/
					self.location="shopping_cart.htm";
				}		
						
						
/*
 This set of source codes is protected by international copyright laws...
 No copying is allowed. 
 http://www.mp34store.com
 Copyright (C) 2007. All Rights Reserved.
*/				