var validpages = new Array("productlist", "brand_detail", "home", "search", "productlist_home");
var http_cart;
var cart_isWorking = false;
var exp, js_ProductId ;
function getHTTPObject()
{
	if (window.XMLHttpRequest)// code for Mozilla, etc.
  	{
  		xmlhttp=new XMLHttpRequest()
		exp = 'mz' ;
  	}
	else if (window.ActiveXObject)// code for IE
  	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  		exp = 'ie' ;
  	}
	return xmlhttp;
}

function viewCart(view_in)
{
	//alert(view_in);
	if(view_in == 'checkout')
	{
		shipCountry = document.frmcheckout.vSCountry.options[document.frmcheckout.vSCountry.selectedIndex].value ;
		shipState = document.frmcheckout.vSState.options[document.frmcheckout.vSState.selectedIndex].value ;

		extrapara = "&shipCountry="+shipCountry+"&shipState="+shipState ;

		if(shipState == "Other")
		{
			shipStateOther = document.frmcheckout.vSState1.value ;
			extrapara += "&shipStateOther="+shipStateOther ;
		}
	}

	var url = "mode=Viewcart"+"&view_in="+view_in;
	//alert(url);
	if(view_in == 'checkout')
	{
		url = url+extrapara ;
	}
	jo_sendViewCartData(url);
}

function handleHttpResponse_viewCart(xmlDocument)
{
	no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
	viewin = xmlDocument.getElementsByTagName('viewin').item(0).firstChild.data;
	finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
	totalweight = xmlDocument.getElementsByTagName('totalweight').item(0).firstChild.data;
	tot_no = parseInt(no);
	if(viewin == 'popup')
	{
		var show_data ='';
		focus_qty_index = -1;	
		show_data += ' <div class="popup-cart-title"><div class="top-cart-checkout"><div class="welcome-guest">&nbsp;</div><div class="your-cart"><a title="Your Cart" href="#" onclick="javascript:viewCart(\'popup\');return false;">&nbsp;</a></div><div class="checkout"><a title="Checkout" href="'+ checkout_url +'checkout.html">&nbsp;</a></div><div class="cart-items" ><span id="topcartinfo">Item(s) : '+tot_no+', '+finalsubtotal+'</span><br /></div></div><img src="images/close-popup.png" style="cursor:pointer;vertical-align:middle; margin:15px 0 15px 15px;" id="icon_close" title="Close"  onclick="closeViewCart_div();" > Your shopping cart </div>';
		show_data += '<div class="popup-cart-infobox">';

		show_data += '<table width="99%" style="margin:auto;" align="center" cellspacing="1" cellpadding="0" class="cart-table">';
		if(getAdvantageMsg(finalsubtotal, totalweight) != "")
			show_data += '<tr><td colspan="5" class="msg-cart-window"><span>'+getAdvantageMsg(finalsubtotal, totalweight)+'</span></td></tr>';
			
		show_data += '<tr><th width="10%" valign="top" align="center">Code</th><th width="10%" valign="top" align="center">Site</th><th width="50%" valign="top" align="left">Item</th>';
		show_data += '<th width="25%" valign="top" align="center">Quantity</th><th width="15%" valign="top" align="center" style="text-align:right">Price</th></tr>';
		if(parseInt(no) > 0)
		{
			if(parseInt(no) > 0)
			{
				var sub_total = 0.00;
				for(i=0;i<tot_no;i++)
				{
					vAttributeText = '';
					attributetextcnt = xmlDocument.getElementsByTagName('attributetextcnt').item(i).firstChild.data ;
					AttText = xmlDocument.getElementsByTagName('attributetext').item(i).firstChild.data ;
					atcnt = 0;
					if(attributetextcnt > 0)
					{
						AtextArr = AttText.split("||");
						//alert(AtextArr[0]) ;
						for(a=0; a < AtextArr.length; a++)
						{
							if(AtextArr[a] != '----')
							{
								vAttributeText += '<li>'+AtextArr[a]+'</li>' ;
								atcnt++;
							}
						}
					}
					if(vAttributeText !='')
						vAttributeText = '<ul class="popup_attribute">'+vAttributeText+'</ul>';

					if(js_ProductId==xmlDocument.getElementsByTagName('productid').item(i).firstChild.data)
						focus_qty_index = i;
					if(((i) % 2 ) == 0)
					{
						design_class = 'alt-back' ;
					}
					else
					{
						design_class = '' ;
					}

					show_data += '<tr class="'+design_class+'"><td valign="top" align="center">'+xmlDocument.getElementsByTagName('productid').item(i).firstChild.data+'</td><td align="center" valign="top">'+xmlDocument.getElementsByTagName('sitecode').item(i).firstChild.data+'</td><td valign="top" align="left"><a href="'+xmlDocument.getElementsByTagName('url').item(i).firstChild.data+'" >'+xmlDocument.getElementsByTagName('vproductname').item(i).firstChild.data+'</a>'+vAttributeText+'</td><td valign="top" align="center"><input type"text" style="vertical-align:middle;text-align:center" name="qty_'+i+'" id="qty_'+i+'" value="'+xmlDocument.getElementsByTagName('qty').item(i).firstChild.data+'" size="4" />&nbsp;<input type="image" src="images/remove.png" style="vertical-align:middle;" name="btnremove_"'+i+'" value="Remove" onclick="setLoadingImagePosition(\'topcartdisplayloading\');removeItem('+i+', \'popup\');" /></td><td valign="top" align="center" style="text-align:right" ><span class="errormsg">$'+xmlDocument.getElementsByTagName('fprice').item(i).firstChild.data+'</span></td></tr>';				
				}
			}
		}
		else
		{
			var sub_total = '0.00';

			show_data += '<tr><td  valign="middle" align="center" colspan="4"><table width="99%" style="margin:auto;" align="center" cellspacing="1" cellpadding="0" border="0"><tr><td width="100%" style="text-align:left" style="padding-right:5px;"><b>Your shopping cart is empty.</b></td></tr></table>';
			show_data += '</td></tr>';
		}
		show_data += '</table>';
		show_data += '<table width="99%" style="margin:auto" align="center" cellspacing="1" cellpadding="0" border="0"><tr><td width="100%" style="text-align:right" colspan="2" style="padding:5px;" class="cart-bottom-total"><B>Subtotal:&nbsp;</B> <b>'+finalsubtotal+'</b></td></tr><tr><td height="50" width="40%" style="text-align:left"><input type="image" src="images/hide-cart.png" onclick="closeViewCart_div();" >&nbsp;<input type="image" src="images/update-quantity.png" name="btnupdate" value="Update Quantity"  onclick="setLoadingImagePosition(\'topcartdisplayloading\');updateItemQty('+tot_no+', \'popup\');"  /></td><td align="right" width="60%"><span id="topcartdisplayloading" style="display:none"><img src="images/loading.gif" /></span><input type="image" src="images/continue-shopping.png" name="" value="Continue-shopping" onclick="continueShopping();">&nbsp;<input type="image" src="images/checkout.png" name="btncheckout" id="btncheckout" value="Checkout" onclick="window.location=\''+checkout_url+'checkout.html\'"/></td></tr></table>';
		show_data += ' </div><div class="popup-cart-bot-curv">&nbsp;</div>';
		
		document.getElementById('viewCart').style.display = '';
		document.getElementById('viewCart').innerHTML = show_data;
		document.getElementById('topcartinfo').innerHTML = 'Item(s) : '+tot_no+', '+finalsubtotal;

		if(focus_qty_index>=0){
			elef = 'qty_0';
			document.getElementById(elef).focus();
			document.getElementById(elef).select();
		}
		else if(tot_no > 0)
		{
			elef = 'qty_0';
			document.getElementById(elef).focus();
			document.getElementById(elef).select();
		}
		
	}
	else if(viewin == 'checkout')
	{
		var show_data ='';
		tax = xmlDocument.getElementsByTagName('tax').item(0).firstChild.data;
		grandtotal = xmlDocument.getElementsByTagName('grandtotal').item(0).firstChild.data;
		grandtotalval = xmlDocument.getElementsByTagName('grandtotalval').item(0).firstChild.data;
		discounttotal = xmlDocument.getElementsByTagName('discounttotal').item(0).firstChild.data;
		groupdiscount = xmlDocument.getElementsByTagName('groupdiscount').item(0).firstChild.data;
		discounttotalval = xmlDocument.getElementsByTagName('discounttotalval').item(0).firstChild.data;
		groupdiscountval = xmlDocument.getElementsByTagName('groupdiscountval').item(0).firstChild.data;
		totalweight = xmlDocument.getElementsByTagName('totalweight').item(0).firstChild.data;

		show_data += '<table width="100%" style="margin:auto;" border="0" cellpadding="0" cellspacing="1">' ;
		if(getAdvantageMsg(finalsubtotal, totalweight) != "")
			show_data += '<tr><td align="left" colspan="7"><span class="msg-checkout">'+getAdvantageMsg(finalsubtotal, totalweight)+'</span></td></tr>' ;
		
		show_data += '<tr class="heading">';
		show_data += '<td align="center"></td>';
		show_data += '<td align="center">Site</td>';
		show_data += '<td colspan="2">Items</td>';
		show_data += '<td align="right">Price</td>';
		show_data += '<td align="center">Quantity</td>';
		show_data += '<td align="right">Total</td>' ;
		show_data += '</tr>' ;
		if(parseInt(no) > 0)
		{
			if(parseInt(no) > 0)
			{
				for(i=0;i<tot_no;i++)
				{
					vAttributeText = '';
					attributetextcnt = xmlDocument.getElementsByTagName('attributetextcnt').item(i).firstChild.data ;
					AttText = xmlDocument.getElementsByTagName('attributetext').item(i).firstChild.data ;
					
					if(attributetextcnt > 0)
					{
						AtextArr = AttText.split("||");
	
						for(a=0; a < AtextArr.length; a++)
						{
							if(AtextArr[a] != '----')
								vAttributeText += '<li>'+AtextArr[a]+'</li>' ;
						}
					}
					if(vAttributeText !='')
						vAttributeText = '<ul class="attribute">'+vAttributeText+'</ul>';
					freeshipping = xmlDocument.getElementsByTagName('freeshipping').item(i).firstChild.data;

					show_data += '<tr class="item-rec">';
					show_data += '<td align="center"><img src="images/icon-remove.png" onclick="javascript:if(confirm(\'Do you want to delete this item from cart?\')){removeItem('+i+', \'checkout\');}else{return false;}" style="cursor:pointer;" title="Remove Item"/></td>';
					
					show_data += '<td align="center">'+xmlDocument.getElementsByTagName('sitecode').item(i).firstChild.data+'</td>';
					show_data += '<td>';
					show_data += '<img src="'+xmlDocument.getElementsByTagName('image').item(i).firstChild.data+'" alt="'+xmlDocument.getElementsByTagName('vproductname').item(i).firstChild.data+'" height="40" style="float:left; margin: 0 15px 0 0" /> </td><td>'+xmlDocument.getElementsByTagName('vproductname').item(i).firstChild.data+'<br>Item Code : '+xmlDocument.getElementsByTagName('productid').item(i).firstChild.data+'<br>' ;
					if(vAttributeText != "----")
					{
						show_data += vAttributeText ;
					}
					else
						show_data +='<br>';
					if(freeshipping == 'Y')
					{
						show_data += '<span class="freeshipping">Free Shipping</span>';
					}
					show_data += '</td>' ;
					show_data += '<td align="right">$'+xmlDocument.getElementsByTagName('fprice').item(i).firstChild.data+'</td>' ;
					show_data += '<td align="center"><input type="text"  name="qty_'+i+'" id="qty_'+i+'" value="'+xmlDocument.getElementsByTagName('qty').item(i).firstChild.data+'"  size="4" style="text-align:center"></td>';
					show_data += '<td align="right">$'+xmlDocument.getElementsByTagName('ftotal').item(i).firstChild.data+'</td>' ;
					show_data += '</tr>' ;
				}

				document.getElementById('UpdateQtyButton').style.display = '';
			}
			
		}
		else
		{
			document.getElementById('UpdateQtyButton').style.display = 'none';
			show_data += '<tr><td colspan="6" height="10"></td></tr><tr><td  valign="middle" align="center" colspan="4"><table width="99%" style="margin:auto;" align="center" cellspacing="1" cellpadding="0" border="0"><tr><td width="100%" style="text-align:left" style="padding-right:5px;"><b>Your shopping cart is empty.</b></td></tr></table></td></tr>';
		}
		show_data += '</table>' ;

		document.getElementById('topcartinfo').innerHTML = 'Item(s) : '+tot_no+', '+finalsubtotal;
		
		document.getElementById('checkoutProducts').innerHTML = show_data;
		document.getElementById('topchecksubtotal').innerHTML = finalsubtotal;
		document.getElementById('subtotal').value = finalsubtotal ;
		document.getElementById('productTotal').value = tot_no ;
		
		document.getElementById('subTotalBottom').innerHTML = finalsubtotal;
		document.getElementById('taxval').innerHTML = tax;
		document.getElementById('finalGrandtotal').value = grandtotalval ;

		document.getElementById('grandTotalBottom').innerHTML = grandtotal ;
		
		if(discounttotalval > 0)
			document.getElementById('discountval').innerHTML = '-'+discounttotal ;
		else
			document.getElementById('discountval').innerHTML = discounttotal ;
		
		document.getElementById('qualified_discount').innerHTML =  '<img src="images/your-qualified-discount.png" alt="your qualified discount" /><br><span class="subtotal" id="topchecksubtotal"> $'+ groupdiscountval + '</span>';
		
		if(groupdiscountval > 0)
			document.getElementById('qualifiedDiscountBottom').innerHTML = '-$'+groupdiscountval ;
		else
			document.getElementById('qualifiedDiscountBottom').innerHTML = '$'+groupdiscountval ;

		document.getElementById('totalWeight').value = totalweight;
		
		if(Trim(document.getElementById('vSZip').value) == '')
			showCartTotal(''); //showShippingRate();
			
		if(getAdvantageMsg(finalsubtotal, totalweight) != "")
			document.getElementById('msg_offer_1').innerHTML='<div class="msg-checkout-bottom">'+ getAdvantageMsg(finalsubtotal, totalweight) + '</div>';
		else
			document.getElementById('msg_offer_1').innerHTML='';
	}
	
	showload = document.getElementById('loadingId').value ;
	hidebtn = document.getElementById('imgHIdeId').value ; 
	

	if(showload != '')
	{
		document.getElementById(showload).style.display = 'none';
		document.getElementById('loadingId').value = '';
	}
	if(hidebtn != '')
	{
		document.getElementById(hidebtn).style.display = '';
		document.getElementById('imgHIdeId').value = '' ;
	}
	{
		showload = document.getElementById('loadingId').value ;
		hidebtn = document.getElementById('imgHIdeId').value ; 
		if(showload != '')
		{
			document.getElementById(showload).style.display = '';
		}
		if(hidebtn != '')
		{
			document.getElementById(hidebtn).style.display = 'none';
		}
	}
}

function continueShopping()
{
	cur_pg = document.getElementById('requestpg').value ;
	hide_flg = 0;

	for(i=0;i < validpages.length; i++)
	{
		if(validpages[i] == cur_pg)
			hide_flg = 1;
	}

	if(hide_flg == 1)
		closeViewCart_div();
	else
		window.location = site_url+'products.html' ;
}
function removeItem(index_no, fromsource)
{
	var url = "mode=RemoveItem&index_no="+index_no+"&fromsource="+fromsource;
	//alert(url);
	jo_sendRemoveItemData(url);
}
function handleHttpResponse_removeCart(xmlDocument)
{
	var fromsource = xmlDocument.getElementsByTagName('fromsource').item(0).firstChild.data;
	
	if(fromsource == 'popup')
	{
		viewCart('popup');
	}
	else
	{
		
		no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
		finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
		tot_no = parseInt(no);

		totalweight = xmlDocument.getElementsByTagName('totalweight').item(0).firstChild.data;
		tax = xmlDocument.getElementsByTagName('tax').item(0).firstChild.data;
		grandtotal = xmlDocument.getElementsByTagName('grandtotal').item(0).firstChild.data;
		grandtotalval = xmlDocument.getElementsByTagName('grandtotalval').item(0).firstChild.data;
		discounttotal = xmlDocument.getElementsByTagName('discounttotal').item(0).firstChild.data;
		groupdiscount = xmlDocument.getElementsByTagName('groupdiscount').item(0).firstChild.data;
		discounttotalval = xmlDocument.getElementsByTagName('discounttotalval').item(0).firstChild.data;
		groupdiscountval = xmlDocument.getElementsByTagName('groupdiscountval').item(0).firstChild.data;
		
		document.getElementById('topcartinfo').innerHTML = tot_no+' Item(s) /  '+finalsubtotal;

		
		document.getElementById('topchecksubtotal').innerHTML = finalsubtotal;
		document.getElementById('productTotal').value = tot_no ;
		
		document.getElementById('subTotalBottom').innerHTML = finalsubtotal;
		document.getElementById('taxval').innerHTML = tax;
		document.getElementById('finalGrandtotal').value = grandtotalval ;
		document.getElementById('grandTotalBottom').innerHTML = grandtotal ;
		
		if(discounttotalval > 0)
			document.getElementById('discountval').innerHTML = '-'+discounttotal ;
		else
			document.getElementById('discountval').innerHTML = discounttotal ;
		
		document.getElementById('qualified_discount').innerHTML =  '<img src="images/your-qualified-discount.png" alt="your qualified discount" /><br><span class="subtotal" id="topchecksubtotal"> $'+ groupdiscountval + '</span>';
		
		if(groupdiscountval > 0)
			document.getElementById('qualifiedDiscountBottom').innerHTML = '-$'+groupdiscountval ;
		else
			document.getElementById('qualifiedDiscountBottom').innerHTML = '$'+groupdiscountval ;
		
		document.getElementById('totalWeight').value = totalweight;
		
		viewCart('checkout');
		
		if(Trim(document.getElementById('vSZip').value) != '')
			showShippingRate();
	}
}

////////////////////////////////////////////////////////
function handleHttpResponse_cartData(xmlDocument)
{
	no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
	finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
	tot_no = parseInt(no);
	document.getElementById('topcartinfo').innerHTML = '<strong>Item(s) : '+tot_no+', '+finalsubtotal + '</strong>';
	//alert(document.getElementById('topcartinfo').innerHTML);
}
///////////////////////////////////////////////////////

function addItem(iProductId, ProAttrId, qty, attrOn)
{
	js_ProductId = iProductId;
	if(attrOn != 0 && js_attribute_arr[iProductId])
	{
		//alert(js_attribute_arr[iProductId][0].vAttributeText);
		show_attributes = ''
		show_attributes += '<table width="100%" cellspacing="0" cellpadding="0" border="0" class="popup-infobox">' ;
		//show_attributes += '<tr><td class="popup-title">Please select product attributes<a name="attr_focus" id="attr_focus"></a> </td><td width="2%" class="popup-title"><img align="right"  src="images/close-pop.jpg" style="cursor:pointer;float:right" title="Close" onclick="hidePopupBox(\'hc_popup_box\');" ></td></tr>' ;
		show_attributes += '<tr><td>&nbsp;</td></tr>';
		//alert(js_attribute_arr[iProductId].length);return false;
		
		ln = js_attribute_arr[iProductId].length ;
		for(i=0 ; i < ln; i++)
		{
			show_attributes += '<tr><td align="center" colspan="2">';
			show_attributes += '<select name="iProAttrId_'+iProductId+'_'+i+'" id="iProAttrId_'+iProductId+'_'+i+'" style="width:200px; margin-bottom:7px;">';
			show_attributes += '<option value=""><--- '+js_attribute_arr[iProductId][i].vAttributeText+' ---></option>';
			
			opln = js_attribute_arr[iProductId][i].option.length ;
			
			for(j=0 ; j < opln; j++)
			{
				show_attributes += '<option value="'+js_attribute_arr[iProductId][i].option[j].value+'">'+js_attribute_arr[iProductId][i].option[j].text+'</option>';
			}
			
			show_attributes += '</select>';
			show_attributes += '</td></tr>';
		}
		show_attributes += '<tr><td>&nbsp;</td></tr>';
		show_attributes += '<tr><td align="center" colspan="2">';
		//show_attributes += '<img src="images/icon-close.png" style="cursor:pointer;vertical-align:middle; margin-left:10px;" id="icon_close" title="Close" onclick="hidePopupBox(\'hc_popup_box\');" />&nbsp&nbsp;<input type="button" value="Save And Add" style="cursor:pointer;vertical-align:middle; margin-left:10px;" id="save_attr" title="Save"  onclick="addItemWithAttribute('+iProductId+' , '+ln+' , '+qty+');" />';
		show_attributes += '<a href="#" id="save_attr" style="float:left; margin-left:210px;" onclick="javascript:addItemWithAttribute('+iProductId+' , '+ln+' , '+qty+');return false;"><img src="images/add-to-cart.png"></a><input type="image" style="float:left; margin-left:5px;" src="'+site_url+'images/btn-cancel.png" onclick="hidePopupBox(\'hc_popup_box\');return false;">';
		show_attributes += '</tr></td>';
		show_attributes += '<tr><td colspan=2>&nbsp;</td></tr>';
		show_attributes += '</table><div class="popup-bot-curv">&nbsp;</div>';
		
		title = "Please select product attributes";
		showdeadcenterdiv(450, 250, 'hc_popup_box', title, show_attributes); // Below was original.
		
		return false;
	}
	else
	{
		if(document.frmShopping.elements['iProAttrId'] != undefined)
		{
			//ln = document.frmShopping.elements['iProAttrId'].length ;
			ln = document.getElementById('attributeTotal').value ;
			//alert(document.getElementById('attributeTotal').value) ;return false;
			
			attrstring = '&attributelength='+ln;
			
			for(i=0 ; i < ln; i++)
			{
				attrstring += '&attrbute_'+i+'='+document.frmShopping.elements['iProAttrId_'+i].value ;
			}
			
			var url ="mode=AddItemWithAttribute&iProductId="+iProductId+"&qty="+qty+attrstring ;
		}
		else
		{
			var url ="mode=AddItem&iProductId="+iProductId+"&ProAttrId="+ProAttrId+"&qty="+qty ;
		}
	}
	//alert(url);
	jo_sendAddItemData(url);
}
function handleHttpResponse_addCart(xmlDocument)
{
	var itemaddstatus = xmlDocument.getElementsByTagName('itemaddstatus').item(0).firstChild.data;
	no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
	finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
	tot_no = parseInt(no);
	
	document.getElementById('topcartinfo').innerHTML = 'Item(s) : '+tot_no+', '+finalsubtotal;

	if(itemaddstatus == 1)
		msgtext = "Product Added Succesfully.";
	else
		msgtext = "Product not Available.";

	msg = "";
	msg += '<table border="0" width="100%" cellspacing="1" cellpadding="2" class="popup-infobox">' ;
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '<tr><td align="center" class="errormsg">'+msgtext+'</td></tr>' ;
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '<tr><td align="center">';
	msg += '<input type="image" src="'+site_url+'images/btn-close.png" onclick="hidePopupBox(\'hc_popup_box\');return false;">&nbsp;<input type="image" src="'+site_url+'images/viewcart.gif" onclick="hidePopupBox(\'hc_popup_box\');viewCart(\'popup\');return false;">';
	msg += '</tr></td>';
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '</table><div class="popup-bot-curv">&nbsp;</div>';

	title = "Alert";
	showdeadcenterdiv(450, 250, 'hc_popup_box', title, msg); // Below was original.
}

function addItemWithAttribute(iProductId, ProAttrIdln , qty)
{
	attrstring = '&attributelength='+ProAttrIdln;
	for(i=0 ; i < ProAttrIdln; i++)
	{
		ele = 'iProAttrId_'+iProductId+'_'+i ;
		attrstring += '&attrbute_'+i+'='+document.getElementById(ele).value ;
	}
	
	js_ProductId = iProductId;
	var url = "mode=AddItemWithAttribute&iProductId="+iProductId+"&qty="+qty+attrstring ;
	//alert(url);
	jo_sendAddItemAttributeData(url);
}
function handleHttpResponse_addCartAttribute(xmlDocument)
{
	var itemaddstatus = xmlDocument.getElementsByTagName('itemaddstatus').item(0).firstChild.data;
	no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
	//alert(no);
	finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
	tot_no = parseInt(no);
	document.getElementById('topcartinfo').innerHTML = 'Item(s) : '+tot_no+', '+finalsubtotal;

	if(itemaddstatus == 1)
		msgtext = "Product Added Succesfully.";
	else
		msgtext = 	"Product not Available.";

	msg = "";
	msg += '<table align="center" border="0" width="350" cellspacing="1" cellpadding="2" class="popup-infobox">' ;
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '<tr><td align="center" class="errormsg">'+msgtext+'</td></tr>' ;
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '<tr><td align="center">';
	msg += '<input type="image" src="'+site_url+'images/btn-close.png" onclick="hidePopupBox(\'hc_popup_box\');return false;">&nbsp;<input type="image" src="'+site_url+'images/viewcart.gif" onclick="hidePopupBox(\'hc_popup_box\');viewCart(\'popup\');return false;">';
	msg += '</tr></td>';
	msg += '<tr><td>&nbsp;</td></tr>';
	msg += '</table><div class="popup-bot-curv">&nbsp;</div>';

	title = "Alert";
	showdeadcenterdiv(450, 250, 'hc_popup_box', title, msg); // Below was original.
}

/* Update Only Quantity */
function updateItemQty(tot, fromsource) //updateItemQty(index_no, qty)
{
	qty_val = new Array();
	extra = '';
	
	for(i=0;i<tot;i++)
	{
		ele = 'qty_'+i  ;
		qty_val[i] = document.getElementById(ele).value ;
		extra += '&'+ele+'='+qty_val[i];
	}
	
	var url = "mode=UpdateItemQty&total="+tot+extra+"&fromsource="+fromsource;
	//alert(url);
	jo_sendUpdateItemData(url);
}
function handleHttpResponse_updateCartQty(xmlDocument)
{
	var fromsource = xmlDocument.getElementsByTagName('fromsource').item(0).firstChild.data;
	if(fromsource == 'popup')
	{
		viewCart('popup');
	}
	else
	{
		// Added to update discount as per the final order total
		// Condition modified by Azad Jain on 09-Jun-11
		if(document.frmcheckout.couponInSession.value != '')
			applyCouponCode(document.frmcheckout.couponInSession.value, 'checkout');
		////////////////////////////////////////////////////////////////////////

		no = xmlDocument.getElementsByTagName('totrec').item(0).firstChild.data;
		finalsubtotal = xmlDocument.getElementsByTagName('finalsubtotal').item(0).firstChild.data;
		tot_no = parseInt(no);

		totalweight = xmlDocument.getElementsByTagName('totalweight').item(0).firstChild.data;
		
		tax = xmlDocument.getElementsByTagName('tax').item(0).firstChild.data;
		grandtotal = xmlDocument.getElementsByTagName('grandtotal').item(0).firstChild.data;
		grandtotalval = xmlDocument.getElementsByTagName('grandtotalval').item(0).firstChild.data;
		discounttotal = xmlDocument.getElementsByTagName('discounttotal').item(0).firstChild.data;
		groupdiscount = xmlDocument.getElementsByTagName('groupdiscount').item(0).firstChild.data;
		discounttotalval = xmlDocument.getElementsByTagName('discounttotalval').item(0).firstChild.data;
		groupdiscountval = xmlDocument.getElementsByTagName('groupdiscountval').item(0).firstChild.data;
		
		document.getElementById('topcartinfo').innerHTML = tot_no+' Item(s) /  '+finalsubtotal;

		
		document.getElementById('topchecksubtotal').innerHTML = finalsubtotal;
		document.getElementById('productTotal').value = tot_no ;
		
		document.getElementById('subTotalBottom').innerHTML = finalsubtotal;
		document.getElementById('taxval').innerHTML = tax;
		document.getElementById('finalGrandtotal').value = grandtotalval ;
		document.getElementById('grandTotalBottom').innerHTML = grandtotal ;
		
		if(discounttotalval > 0)
			document.getElementById('discountval').innerHTML = '-'+discounttotal ;
		else
			document.getElementById('discountval').innerHTML = discounttotal ;
		
		document.getElementById('qualified_discount').innerHTML =  '<img src="images/your-qualified-discount.png" alt="your qualified discount" /><br><span class="subtotal" id="topchecksubtotal"> $'+ groupdiscountval + '</span>';
		
		if(groupdiscountval > 0)
			document.getElementById('qualifiedDiscountBottom').innerHTML = '-$'+groupdiscountval ;
		else
			document.getElementById('qualifiedDiscountBottom').innerHTML = '$'+groupdiscountval ;
		
		document.getElementById('totalWeight').value = totalweight;

		viewCart('checkout');
		if(Trim(document.getElementById('vSZip').value) != '')
			showShippingRate();
	
	}
}

/* To Add Coupon Discount */
function applyCouponCode(couponcode, fromsource)
{
	var url = site_url+"ajax_cart.php?mode=AddCoupon&couponcode="+couponcode+"&fromsource="+fromsource ;
	
	//alert(url);
	//return false ;
	if(!cart_isWorking)
	{
		http_cart = getHTTPObject();
		cart_isWorking = true;
		http_cart.onreadystatechange=handleHttpResponse_addcoupon;
  		http_cart.open("GET", url, true);
		//http_cart.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset= UTF-8");
	  	http_cart.send(null);
	}
	return false;
}
function handleHttpResponse_addcoupon()
{
	if (http_cart.readyState == 4)
	{
		cart_isWorking = false;
		if (http_cart.responseText.indexOf('invalid') == -1) 
		{
			//alert(http_cart.responseText);
			var xmlDocument = http_cart.responseXML;
			var fromsource = xmlDocument.getElementsByTagName('fromsource').item(0).firstChild.data;
			var couponmsg = xmlDocument.getElementsByTagName('couponmsg').item(0).firstChild.data;
			var addstatus = xmlDocument.getElementsByTagName('addstatus').item(0).firstChild.data;
			
			if(addstatus == 1)
			{
				var couponcode = xmlDocument.getElementsByTagName('couponcode').item(0).firstChild.data;
				document.getElementById('couponInSession').value = couponcode ;
				document.getElementById('deleteCoupon').style.display = '' ;
			}

			document.getElementById('couponMsg').style.display = '' ;
			document.getElementById('couponMsgValue').innerHTML = couponmsg ;
			
			
			if(fromsource == 'popup')
			{
				viewCart('popup');
			}
			else
			{
				viewCart('checkout');
			}
		}
	}
}
/* To Remove Coupon Discount */

function removeCouponCode(couponcode, fromsource)
{
	var url = site_url+"ajax_cart.php?mode=RemoveCoupon&couponcode="+couponcode+"&fromsource="+fromsource ;
	
	//alert(url);
	//return false ;
	if(!cart_isWorking)
	{
		http_cart = getHTTPObject();
		cart_isWorking = true;
		http_cart.onreadystatechange=handleHttpResponse_removecoupon;
  		http_cart.open("GET", url, true);
		//http_cart.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset= UTF-8");
	  	http_cart.send(null);
	}
}
function handleHttpResponse_removecoupon()
{
	if (http_cart.readyState == 4)
	{
		cart_isWorking = false;
		if (http_cart.responseText.indexOf('invalid') == -1) 
		{
			var xmlDocument = http_cart.responseXML;
			var fromsource = xmlDocument.getElementsByTagName('fromsource').item(0).firstChild.data;
			var couponmsg = xmlDocument.getElementsByTagName('couponmsg').item(0).firstChild.data;
			
			document.getElementById('couponMsg').style.display = '' ;
			document.getElementById('couponMsgValue').innerHTML = couponmsg ;
			document.getElementById('deleteCoupon').style.display = 'none' ;
			if(fromsource == 'popup')
			{
				viewCart('popup');
			}
			else
			{
				viewCart('checkout');
			}
		}
	}
}


/* For Shipping Method   */
function change_shipping_method(shipmethod, fromsource)
{
	var url = site_url+"ajax_cart.php?mode=ChangeShipping&shipmethod="+shipmethod+"&fromsource="+fromsource ;
	
	//alert(url);
	
	if(!cart_isWorking)
	{
		http_cart = getHTTPObject();
		cart_isWorking = true;
		http_cart.onreadystatechange=handleHttpResponse_changeshipping ;
  		http_cart.open("GET", url, true);
		//http_cart.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset= UTF-8");
	  	http_cart.send(null);
	}
}
function handleHttpResponse_changeshipping()
{
	if (http_cart.readyState == 4)
	{
		cart_isWorking = false;
		if (http_cart.responseText.indexOf('invalid') == -1) 
		{
			var xmlDocument = http_cart.responseXML;
			var fromsource = xmlDocument.getElementsByTagName('fromsource').item(0).firstChild.data;
			var shiprateval = xmlDocument.getElementsByTagName('shiprateval').item(0).firstChild.data;
			var shiprateprice = xmlDocument.getElementsByTagName('shiprateprice').item(0).firstChild.data;
			
			if(fromsource == 'popup')
			{
				viewCart('popup');
			}
			else
			{
				document.getElementById('shippingrateval').innerHTML = shiprateval ;
				document.getElementById('ses_shipping_cost').value = shiprateprice ;
				viewCart('checkout');
			}
		}
	}
}

function closeViewCart_div()
{
	//cart_isWorking = false;
	document.getElementById('viewCart').style.display='none';
}

function closeAttribute_div()
{
	document.getElementById('attribute_selection').style.display='none';
}

function setLoadingImagePosition(idVal)
{
	document.getElementById('loadingId').value = idVal ;
}
function setImageToHideWhileAction(imgId)
{
	document.getElementById('imgHIdeId').value = imgId ;
}
function getAdvantageMsg(final_sub_total, totalweight)
{
	customer_purchase_limit = parseFloat(50);
	free_shipping_limit = parseFloat(70);
	
	on_order_offer1 = parseFloat(450);
	on_order_offer1_limit = parseFloat(500);
	
	on_order_offer2 = parseFloat(925);
	on_order_offer2_limit = parseFloat(1000);
	
	on_order_offer3 = parseFloat(2400);
	on_order_offer3_limit = parseFloat(2500);
	
	final_sub_total = parseFloat(final_sub_total.replace("$","").replace(",",""));
	
	if(final_sub_total > 0.00)
	{	
		var data ='';
		
		if(final_sub_total >= on_order_offer3 && final_sub_total < on_order_offer3_limit)
		{
			offer_amt = getCurrencySymbol()+ Math.ceil(on_order_offer3_limit - final_sub_total);
			data += 'Add '+ offer_amt +' more to your cart and get qualified for 15% special discount.&nbsp;';
		}
		else if(final_sub_total >= on_order_offer3_limit)
		{
			data += 'You are eligible for 15% special discount.&nbsp;';
		}
		else if(final_sub_total >= on_order_offer2 && final_sub_total < on_order_offer2_limit)
		{
			offer_amt = getCurrencySymbol()+ Math.ceil(on_order_offer2_limit - final_sub_total);
			data += 'Add '+ offer_amt +' more to your cart and get qualified for 10% special discount.&nbsp; ';
		}
		else if(final_sub_total >= on_order_offer2_limit && final_sub_total < on_order_offer3_limit)
		{
			data += 'You are eligible for 10% special discount.&nbsp; ';
		}
		else if(final_sub_total >= on_order_offer1 && final_sub_total < on_order_offer1_limit)
		{
			offer_amt = getCurrencySymbol()+ Math.ceil(on_order_offer1_limit - final_sub_total);
			data += 'Add '+ offer_amt +' more to your cart and get qualified for 5% special discount.&nbsp; ';
		}
		else if(final_sub_total >= on_order_offer1_limit && final_sub_total < on_order_offer2_limit)
		{
			data += 'You are eligible for 5% special discount.&nbsp;';
		}
		else if(final_sub_total > customer_purchase_limit && final_sub_total < free_shipping_limit)
		{
			offer_amt = getCurrencySymbol()+ Math.ceil(free_shipping_limit - final_sub_total);
			data += 'Add '+ offer_amt +' more to your cart and take free shipping advantage.&nbsp; ';
		}
		if(final_sub_total > free_shipping_limit && totalweight < 20)
		{
			data += 'You are eligible for free shipping.';
		}	
		data = data;
	}
	else			
		data = "";
			
	return data;
 }
function getCurrencySymbol()
{
	return "$";		
}
