function shoppingCart(){

 /* this array contains all items's infomation in format of
  itemName,unitPrice,quantity,itemName,unitPrice,quantity,... etc.
  it will be converted to a string when submit to server
  
 */
	this.cartArray = new Array();

 /* a flag to enforce customer recalulate totol
 price since Tax and shipping will be added */

	this.calulated = false; 
    this.totalItems = 0;  // counter for shopping cart
    this.subTotal = 0;
	this.checkOutWindowStr = ""
	this.checkOutWindow = null;
	this._URL = null;
    
}
shoppingCart.prototype.viewCart = function(URL_){
	
	var STR = "";
  this.calulated = false;
  this.subTotal = 0;
   if( this.totalItems <=0)
		STR = this.emptyPage();
  else{
	this.totalItems = 0;
	STR += '<html><body  leftmargin="10" topmargin="70">';
	STR += '<div align = left><center>';
	STR += '<FORM Name ="cart" method ="post" action ="cgi-bin/test.pl" onsubmit = "return top.checkOrder()" >';
	STR += '<table class=eng_8 width="70%" border=1  cellspacing="0" cellpadding="4" height="140" bgcolor="#FFFFFF" bordercolorlight="#7F7F7F" bordercolordark="#ffffff">';
	STR += '<style>.eng_8{; font-size:9pt}a:link {color:#808080; text-decoration:none}a:hover {color:#000000}a:visited {color:#000000; text-decoration:none}</style>';
	STR += '<tr bgcolor="#1573D0" align="center">'; 
    STR += '<td height="28"><font color="#FFFFFF" face="Verdana"><b>Remove</b></td>\n';
	STR += '<td height="28"><font color="#FFFFFF" face="Verdana"><b>Product Name</b></td>\n';
	STR += '<td height="28"><font color="#FFFFFF" face="Verdana"><b>Unit Price</b></td>\n';
    STR += '<td height="28"><font color="#FFFFFF" face="Verdana"><b>Quantity</b></td>\n';
    STR += '<td height="28"><font color="#FFFFFF" face="Verdana"><b>Sub Total</b></td>\n'
    
	STR += '</tr>';
		 /****  Write Shopping Cart Body ********/
	for( var i = 0, j = 0; i < this.cartArray.length -1;){
	
	if( this.cartArray[ i+2 ] <=0) // quantity is 0, remove item
	 {
 	   STR += '<input type = "hidden" name ="'+ this.cartArray[i];
	   STR += '" value = 0 >';
	   i+=3;
	   j++;
	   continue;
	  }
	STR += '<TR align="center"><td height="28" ><font color="#999999" font-size:9pt face="Verdana"><a href="#"><img src="../images/logo_remove.gif" border="0" onClick ="javascript:document.cart.elements['+ j++ + '].value=0;top._con.updateCart()"></a></font></td>\n';
	STR += '<td height="28" ><font color="#000000" font-size:9pt face="Verdana">' +  this.cartArray[i++]  + '&nbsp;</font></td>\n';  //write item name
	STR += '<td height="28" ><font color="#000000" font-size:9pt face="Verdana">$' + this.cartArray[i++]  + '&nbsp;</font></td>\n'; //write item unit price
    STR += '<td height="28" ><font color="#000000" font-size:9pt face="Verdana"><input type="text" name="' +this.cartArray[i-2] + '" size="4" value="' + this.cartArray[i] + '"></font></td>\n';	//write item quantity
	//this.totalItems += parseInt(this.cartArray[i]);
	//alert("ddd" + this.cartArray[i]);
    STR += '<td height="28" ><font color="#000000" font-size:9pt face="Verdana">$' + 100* this.cartArray[i-1] * this.cartArray[i] /100 +  '&nbsp;</font></td>\n'; //write & count sub-total
  
	this.subTotal += this.cartArray[i-1] * this.cartArray[i];
	i++;
	this.totalItems++;
	STR += '</TR>\n'
	}
STR += '<tr><td  colspan=5 align="center" height="28"><font color="#000000" font-size:9pt face="Verdana">';
STR +=  '<a href="#" onClick = \'javascript:top._con.continueShopping(';
STR += ');\'><img src="../images/buy_continue.gif" border="0"></a>&nbsp;&nbsp; ';                                                                         
STR +=   '<a href="#" onClick = "javascript:top._con.updateCart()"><img src="../images/buy_update.gif" border="0">&nbsp;&nbsp;';
//STR += '<a href="#"><img src="../images/but_clear.gif" border="0"></a>&nbsp;&nbsp;';
STR += '<a href="#" ONCLICK = "javascript:top._con.checkOut(true)"><img src="../images/buy_checkout_next.gif" border="0"></a>';
STR += '</TD/tr>';
 
 //  if(!checkOut_){
     STR += '<tr><td  colspan=5 align="left" height="28"><font color="#000000"  font-size:9pt face="Verdana">The secure server will encrypt your information. If you received an error message';
	STR += ' when you tried to use our secure server, please using our standard server. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    STR +=  '<a href="#" onClick = "javascript:top._con.checkOut(false)"><img src="../images/STDCHK1.gif" border="0"></a>&nbsp;&nbsp; ';
	//STR += '<INPUT TYPE = BUTTON VALUE = "Standard Check Out" ONCLICK = >';
	
    STR += '</tr></table></form></div>';
    STR += '</BODY></HTML>'
	//}
	//else
	//return STR;
	
   }
   //alert(STR);
   var _doc =  top.frames[1].document;
    _doc.open();
    _doc.write(STR);
    _doc.close();
}

shoppingCart.prototype.updateCart = function(){
//	alert(this.totalItems);

for( i = 0; i < this.cartArray.length -1;){
  
   eval('this.cartArray[i+2] = top.frames[1].document.forms[0].' + this.cartArray[i] + '.value');
	  if((this.cartArray[i+2] < 1)||(isNaN(this.cartArray[i+2]))) 
	      this.cartArray[i+2] = 0;
	   i+=3;
}
this.viewCart(false);

}

shoppingCart.prototype.addToCart = function( itemName_, itemPrice_,URL_){
//if( URL_ == "undefined") this._URL = null;
//else this._URL = URL_;
this._URL = (URL_ == "undifined") ? null : URL_;
if(this.cartArray.length > 0){
   for( var j = 0; j<this.cartArray.length; j+=3)
         if(this.cartArray[j] == itemName_){ 
		   this.cartArray[j+2]++;
		   if(this.cartArray[j+2]==1)
		       ++this.totalItems;
		   this.viewCart(this._URL);
			return;
		}
     }
 this.cartArray = this.cartArray.concat( itemName_ ,itemPrice_,1);
 ++this.totalItems;
// alert(this.totalItems);
this.viewCart(this._URL);
}
shoppingCart.prototype.emptyPage = function(){
  var str = "<html><body><h4><center>Your shopping cart is empty.\nPlease check it later.</b></h4><SCRIPT LANGUAGE=\"JavaScript\">setTimeout(\"self.location.replace('content_home.htm')\",2500);</SCR";
     str += "IPT></body></html>";
	 return str;
	 }

shoppingCart.prototype.continueShopping = function(){
	//alert( this._URL);
	if( this._URL == null)
  top.frames[1].location.replace("content_home.htm");
	else{
	var str = "<html><frameset border=0 frameBorder=0 frameSpacing=0 ";
		str += "cols=\"25%,*\"><frame name=\"prodnav\" src=\"productsnav.htm\"";
		str += " scrolling = \"no\" target=\"_self\">";
		str += "<frame name=\"prodcontent\" src=\"";
		str += this._URL +"\" target=\"_self\"></frameset></html>";
	top.frames[1].document.write(str);
	}
}

shoppingCart.prototype.checkOut = function(secure_){
	
	
	var ord = "";
	for(var i=0; i<this.cartArray.length;i++){
		ord +=this.cartArray[i];
		ord += ",";
	}
	if(secure_){
   var addr =  "https://suntendy-usacom.secure.powweb.com/eversion/";
   var pr ="width=720,height = 350,status=yes, toolbar=no,resizable=yes,scrollbars=yes";
   var ss = 'window.open(\'' + addr + 'check.htm'+'?'+ ord +'\',\'na\',\'' + pr+'\' )'
   var STD = eval(ss);
  // this.cartArray.length = 0;
	}
	else{
		
   var SS ="top.frames[1].location.replace(\"check.htm?" + ord +"\")";
   eval(SS);

	}
  
}



