var r_browser = false;
function getHTTPObject()
{
	var xhr = false;
	if (window.XMLHttpRequest)
	{
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				xhr = false;
			}
		}
	}
	return xhr;
}
var request;

/************************Js Clean up code start function*******************************/

function changePropertyDropdown(product_id,accessory_id,relatedprd_id,attribute_id,selectedproperty_id)
{
	var propArr = new Array();
	var property_data = "";
	var suburl = "";
	var subatthtml = "";
	var layout = "";
	var prefix;
	if(document.getElementById('isAjaxBoxOpen'))
	{
		layout = document.getElementById('isAjaxBoxOpen').value;
	}
	
	var preprefix = "";
	if(layout=="viewajaxdetail")
	{
		preprefix = "ajax_";
	}
	if(accessory_id!=0)
	{
		prefix = preprefix+"acc_";
	} else if(relatedprd_id!=0) {
		prefix = preprefix+"rel_";
	} else {
		prefix = preprefix+"prd_";
	}
		
	var commonid = prefix+product_id + '_' + accessory_id + '_' + attribute_id;
	if(document.getElementById('subattdata_'+commonid))
	{
		subatthtml = document.getElementById('subattdata_'+commonid).value;
	}
	suburl = suburl + "&subatthtml="+subatthtml;
	suburl = suburl + "&product_id="+product_id;
	suburl = suburl + "&attribute_id="+attribute_id;
	suburl = suburl + "&accessory_id="+accessory_id;
	suburl = suburl + "&relatedprd_id="+relatedprd_id;
	
	if(document.getElementsByName('property_id_'+commonid+'[]'))
	{
		var propName = document.getElementsByName('property_id_'+commonid+'[]');
		var sel_i=0;
		for(var p=0;p<propName.length;p++)
		{
			if(propName[p].type=='checkbox')
			{
				if(propName[p].checked)
				{
					propArr[sel_i++] = propName[p].value;
				}
			} else {
				if(propName[p].selectedIndex)
				{
					propArr[sel_i++] = propName[p].options[propName[p].selectedIndex].value;
				}
			}
		}
		//alert("property " + propArr);
		property_data = propArr.join(",");
		suburl = suburl + "&property_id=" + property_data;
	}
	var url = site_url+"index2.php?option=com_redshop&view=product&task=displaySubProperty&isAjaxBox="+layout;
	url = url + suburl;
	//alert('');
//	url = 'http://localhost/redshop/index2.php?option=com_redshop&view=product&task=displaySubProperty&isAjaxBox=&subatthtml={property_title} <br />{subproperty_dropdown}&product_id=1724&attribute_id=308&accessory_id=0&relatedprd_id=0&property_id=605';
	request = getHTTPObject();
	request.onreadystatechange=function() {
		// if request object received response
		if(document.getElementById('property_responce'+commonid))
		{
			document.getElementById('property_responce'+commonid).style.display = 'none';
		}
		
		if(request.readyState == 4)
		{	
			if(document.getElementById('property_responce'+commonid))
			{
				document.getElementById('property_responce'+commonid).innerHTML=request.responseText;
				document.getElementById('property_responce'+commonid).style.display = 'block';

				for(var p=0;p<propArr.length;p++)
				{
					var property_id = propArr[p];
					var scrollercommonid = commonid+'_'+property_id;
//					alert('divsubimgscroll'+commonid+'_'+property_id);
					if(document.getElementById('divsubimgscroll'+scrollercommonid))
					{
						var scrollhtml = document.getElementById('divsubimgscroll'+scrollercommonid).innerHTML;
						if(scrollhtml!="")
						{
							var imgs = scrollhtml.split('#_#');
							var unique = "isFlowers"+scrollercommonid; 
							unique =  new ImageScroller('isFlowersFrame'+scrollercommonid,'isFlowersImageRow'+scrollercommonid);
							var subpropertycommonid = 'subproperty_id_'+scrollercommonid;
							var subinfo = '';
							for(i=0;i<imgs.length;i++)
							{
								subinfo = imgs[i].split('`_`');
								var subproperty_id = subinfo[1];
								unique.addThumbnail(subinfo[0],"javascript:setSubpropImage('"+product_id+"','"+subpropertycommonid+"','"+subproperty_id+"');calculateTotalPrice('"+product_id+"','"+relatedprd_id+"');displayAdditionalImage('"+product_id+"','"+accessory_id+"','"+relatedprd_id+"','"+property_id+"','"+subproperty_id+"');","","",subpropertycommonid+"_subpropimg_"+subproperty_id);
							}
							unique.setThumbnailHeight(50);
							unique.setThumbnailWidth(50);
							unique.setThumbnailPadding(5);
							unique.setScrollType(0);
							unique.enableThumbBorder(false);
							unique.setClickOpenType(1);
							unique.setThumbsShown(NOOF_THUMB_FOR_SCROLLER);
							unique.setNumOfImageToScroll(1);
							unique.renderScroller();
						}
					}
				}
			}
			displayAdditionalImage(product_id,accessory_id,relatedprd_id,selectedproperty_id,0);
			calculateTotalPrice(product_id,relatedprd_id);
		}
	}
	request.open("GET", url, true);
	request.send(null);
}

function collectAttributes(product_id,accessory_id,relatedprd_id)
{
	var prefix;
	var attrArr = new Array();
	var allpropArr = new Array();
	var tolallsubpropArr = new Array();
	var mainprice = 0;
	var price_without_vat = 0;
	var old_price = 0;
	var isStock = true;
	var setPropEqual = true;
	var setSubpropEqual = true;
	var acc_error = "";
	var layout = "";
	
	
	
	if(document.getElementById('isAjaxBoxOpen'))
	{
		layout = document.getElementById('isAjaxBoxOpen').value;
	}
	
	var preprefix = "";
	if(layout=="viewajaxdetail")
	{
		preprefix = "ajax_";
	}
	
	if(accessory_id!=0)
	{
		prefix = preprefix+"acc_";
		if(document.getElementById('accessory_id_'+product_id+'_'+accessory_id))
		{
			mainprice = parseFloat(document.getElementById('accessory_id_'+product_id+'_'+accessory_id).getAttribute('accessoryprice'));
			price_without_vat = parseFloat(document.getElementById('accessory_id_'+product_id+'_'+accessory_id).getAttribute('accessorywithoutvatprice'));
		}
		old_price = mainprice;
	} else if(relatedprd_id!=0)
	{
		prefix = preprefix+"rel_";
		if(document.getElementById('main_price'+product_id))
		{
			mainprice = parseFloat(document.getElementById('main_price'+product_id).value);
		}
		if(document.getElementById('product_price_excluding_price'+product_id))
		{
			price_without_vat = parseFloat(document.getElementById('product_price_excluding_price'+product_id).value);
		}
		if(document.getElementById('product_old_price'+product_id))
		{
			old_price = parseFloat(document.getElementById('product_old_price'+product_id).value);
		}
	} else {
		prefix = preprefix+"prd_";
		if(document.getElementById('main_price'+product_id))
		{
			mainprice = parseFloat(document.getElementById('main_price'+product_id).value);
		}
		if(document.getElementById('product_price_excluding_price'+product_id))
		{
			price_without_vat = parseFloat(document.getElementById('product_price_excluding_price'+product_id).value);
		}
		if(document.getElementById('product_old_price'+product_id))
		{
			old_price = parseFloat(document.getElementById('product_old_price'+product_id).value);
		}
	}
	var commonid = prefix+product_id + '_' + accessory_id;
	var commonstockid = prefix+product_id;
//	alert("mainprice = " + mainprice);
	if(document.getElementsByName('attribute_id_'+commonid+'[]'))
	{
		var attrName = document.getElementsByName('attribute_id_'+commonid+'[]');
		for(var i=0;i<attrName.length;i++)
		{
			attrArr[i] = attrName[i].value;
		}
	}
	if(USE_STOCKROOM==1 && isStock)
	{
		isStock = checkProductStockRoom(1,commonstockid);
	}
	if(attrArr.length<=0 && AJAX_CART_BOX==1)
	{
		if(document.getElementById("requiedAttribute"))
		{
			acc_error = document.getElementById("requiedAttribute").value;
		}
	}

	for(var i=0;i<attrArr.length;i++)
	{
		var attribute_id = attrArr[i];
		commonid = prefix+product_id + '_' + accessory_id + '_' + attribute_id;
		var propId = document.getElementById('property_id_'+commonid);
		if(propId)
		{
			setPropertyImage(product_id,'property_id_'+commonid);
			var propName = document.getElementsByName('property_id_'+commonid+'[]');
			
			var seli=0;
			var propArr = new Array();
			/******Collect property start*******/
			for(var p=0;p<propName.length;p++)
			{
				if(propName[p].type=='checkbox')
				{
					if(propName[p].checked && propName[p].value!=0)
					{
						propArr[seli++] = propName[p].value;
					}
				} else {
					if(propName[p].selectedIndex && propName[p].options[propName[p].selectedIndex].value!=0)
					{
						propArr[seli++] = propName[p].options[propName[p].selectedIndex].value;
					}
				}
			}
			//alert("propArr = " + propArr.length);
			if(propArr.length>0)
			{
				allpropArr[i] = propArr.join(",,");
			}
			//alert(" propArr.length = " + propArr.length);
			// required check
			if(propId.getAttribute('required')==1 && propArr.length==0)
			{
				acc_error +=  document.getElementById('att_lebl').innerHTML + " " + decodeURIComponent(propId.getAttribute('attribute_name').replace("/\+/g", " ")) +"\n";
			}
			/******Collect property Price start*******/
			if(setPropEqual && setSubpropEqual)
			{
				var oprandElementId = 'property_id_'+commonid+'_oprand';
				var priceElementId = 'property_id_'+commonid+'_proprice';
				var retProArr = calculateSingleProductPrice(mainprice,oprandElementId,priceElementId,propArr);
				//setPropEqual = retProArr[0];
				mainprice = retProArr[1];
				
				var retProArr = calculateSingleProductPrice(old_price,oprandElementId,priceElementId,propArr);
				old_price = retProArr[1];
				
				var priceElementId = 'property_id_'+commonid+'_proprice_withoutvat';
				var retProArr = calculateSingleProductPrice(price_without_vat,oprandElementId,priceElementId,propArr);
				price_without_vat = retProArr[1];
			}
			/******Collect property Price end*******/
			
			/******Collect property end*******/
			
			/******Collect subproperty start*******/
			var isSubproperty = false;
			var allsubpropArr = new Array();
			
			for(var p=0;p<propArr.length;p++)
			{
				var property_id = propArr[p];
				
				var stockElementId = 'property_id_'+commonid+'_stock'+property_id;
				if(USE_STOCKROOM==1 && document.getElementById(stockElementId) && accessory_id==0)
				//if(USE_STOCKROOM==1 && document.getElementById(stockElementId) && isStock && accessory_id==0)
				{
					isStock = checkProductStockRoom(document.getElementById(stockElementId).value,commonstockid);
				}
				
				var subcommonid = prefix+product_id + '_' + accessory_id + '_' + attribute_id + '_' + property_id;
				if(document.getElementById('subproperty_id_'+subcommonid))
				{
					setSubpropertyImage(product_id,'subproperty_id_'+subcommonid);
					isSubproperty = true;
					var subpropName = document.getElementsByName('subproperty_id_'+subcommonid+'[]');
					seli=0;
					var subpropArr = new Array();
					for(var sp=0;sp<subpropName.length;sp++)
					{
						if(subpropName[sp].type=='checkbox')
						{
							if(subpropName[sp].checked && subpropName[sp].value)
							{
								subpropArr[seli++] = subpropName[sp].value;
							}
						} else {
							
							if(subpropName[sp].selectedIndex && subpropName[sp].options[subpropName[sp].selectedIndex].value)
							{
								subpropArr[seli++] = subpropName[sp].options[subpropName[sp].selectedIndex].value;
							}
						}
					}
					
					for(var sp=0;sp<subpropArr.length;sp++)
					{	
						var stockElementId = 'subproperty_id_'+subcommonid+'_stock'+subpropArr[sp];
						if(USE_STOCKROOM==1 && document.getElementById(stockElementId) && accessory_id==0)
						//if(USE_STOCKROOM==1 && document.getElementById(stockElementId) && isStock && accessory_id==0)
						{	
							isStock = checkProductStockRoom(document.getElementById(stockElementId).value,commonstockid);
						}
					}
					// required check
					if(document.getElementById('subproperty_id_'+subcommonid).getAttribute('required')==1 && subpropArr.length==0)
					{
						acc_error +=  document.getElementById('att_lebl').innerHTML + " " + decodeURIComponent(document.getElementById('subproperty_id_'+subcommonid).getAttribute('subattribute_name').replace("/\+/g", " ")) +"\n";
					}
					/******Collect subproperty Price start*******/
					if(setPropEqual && setSubpropEqual)
					{
						var oprandElementId = 'subproperty_id_'+subcommonid+'_oprand';
						var priceElementId = 'subproperty_id_'+subcommonid+'_proprice';
						var retSubArr = calculateSingleProductPrice(mainprice,oprandElementId,priceElementId,subpropArr);
						//setSubpropEqual = retSubArr[0];
						mainprice = retSubArr[1];
						
						var retSubArr = calculateSingleProductPrice(old_price,oprandElementId,priceElementId,subpropArr);
						old_price = retSubArr[1];
						
						var priceElementId = 'subproperty_id_'+subcommonid+'_proprice_withoutvat';
						var retSubArr = calculateSingleProductPrice(price_without_vat,oprandElementId,priceElementId,subpropArr);
						price_without_vat = retSubArr[1];
					}
					
					/******Collect subproperty Price end*******/
					allsubpropArr[p] = subpropArr.join("::");
				}
			}
			tolallsubpropArr[i] = allsubpropArr.join(",,");
			/******Collect subproperty end*******/
		}
	}
	if(allpropArr.length==0)
	{
		attrArr = new Array();
	}
	//alert("mainprice = " + mainprice);
//	alert("attrArr = " + attrArr + "allpropArr = " + allpropArr + "tolallsubpropArr = " + tolallsubpropArr);

	if(accessory_id!=0)
	{
		if(document.getElementById("acc_attribute_data")){
			document.getElementById("acc_attribute_data").value = attrArr.join("##");
		}
		if(document.getElementById("acc_property_data")){
			document.getElementById("acc_property_data").value = allpropArr.join("##");
		}
		if(document.getElementById("acc_subproperty_data")){
			document.getElementById("acc_subproperty_data").value = tolallsubpropArr.join("##");
		}
		if(document.getElementById("accessory_price")){
			document.getElementById("accessory_price").value = mainprice;
		}
		if(document.getElementById("accessory_price_withoutvat")){
			document.getElementById("accessory_price_withoutvat").value = price_without_vat;
		}
	} else {
		if(document.getElementById("attribute_data")){
			document.getElementById("attribute_data").value = attrArr.join("##");
		}
		if(document.getElementById("property_data")){
			document.getElementById("property_data").value = allpropArr.join("##");
		}
		if(document.getElementById("subproperty_data")){
			document.getElementById("subproperty_data").value = tolallsubpropArr.join("##");
		}
		if(document.getElementById("tmp_product_price")){
			document.getElementById("tmp_product_price").value = mainprice;
		}
		if(document.getElementById("productprice_notvat")){
			document.getElementById("productprice_notvat").value = price_without_vat;
		}
		if(document.getElementById("tmp_product_old_price")){
			document.getElementById("tmp_product_old_price").value = old_price;
		}
	}
	if(document.getElementById("requiedAttribute")){
		document.getElementById("requiedAttribute").value = acc_error;
	}
}

function checkProductStockRoom(stockAmount,commonstockid)
{	//alert("commonstockid" + commonstockid+ " Amount " +stockAmount);
	var isStock = true;
	if(document.getElementById('pdaddtocart'+commonstockid))
	{
		if(stockAmount > 0)
		{
			document.getElementById('pdaddtocart'+commonstockid).style.display = 'block';
			isStock = true;
		} else {
			document.getElementById('pdaddtocart'+commonstockid).style.display = 'none';
			isStock = false;
		}
	}
	if(document.getElementById('stockaddtocart'+commonstockid))
	{
		if(stockAmount > 0)
		{
			document.getElementById('stockaddtocart'+commonstockid).style.display = 'none';
			document.getElementById('stockaddtocart'+commonstockid).innerHTML = "";
		} else {
			document.getElementById('stockaddtocart'+commonstockid).style.display = 'block';
			document.getElementById('stockaddtocart'+commonstockid).innerHTML = PRODUCT_OUTOFSTOCK_MESSAGE;
		}
	}
	if(document.getElementById('stockQuantity'+commonstockid))
	{
		if(stockAmount > 0)
		{
			if(document.getElementById('stockQuantity'+commonstockid).style.display=='none')
				document.getElementById('stockQuantity'+commonstockid).style.display = 'block';
		} else {
			document.getElementById('stockQuantity'+commonstockid).style.display = 'none';
		}
	}
	return isStock;
}

function calculateSingleProductPrice(price,oprandElementId,priceElementId,elementArr)
{
	var setEqual = true;
	for(var i=0;i<elementArr.length;i++)
	{
		var id = elementArr[i];

		var oprand=document.getElementById(oprandElementId+id).value;
		var subprice=document.getElementById(priceElementId+id).value;
		
		if(oprand=="-"){
			price -= parseFloat(subprice);
		}else  if(oprand=="+"){
			price += parseFloat(subprice);
		}else  if(oprand=="*"){
			price *= parseFloat(subprice);
		}else  if(oprand=="/"){
			price /= parseFloat(subprice);
		}else if(oprand=="="){
			price = parseFloat(subprice);
			setEqual = false;
			break;
		}
	}
	var retArr = new Array();
	retArr[0] = setEqual;
	retArr[1] = price;
	return retArr;
}

// calculate attribute price
function calculateTotalPrice(product_id,relatedprd_id)
{
	if(product_id==0 || product_id=="")
	{
		alert("Product ID is missing");
		return false;
	}
	var mainprice = 0;
	var price_without_vat = 0;
	var old_price = 0;
	var accfinalprice_withoutvat = 0;
	var product_old_price = 0;
	// accessory price add
	var accfinalprice = collectAccessory(product_id,relatedprd_id);
	if(document.getElementById('accessory_price_withoutvat'))
	{
		accfinalprice_withoutvat = parseFloat(document.getElementById('accessory_price_withoutvat').value);
	}
	
	collectAttributes(product_id,0,relatedprd_id);
	if(document.getElementById('tmp_product_price'))
	{
		mainprice = parseFloat(document.getElementById('tmp_product_price').value);
	}
	if(document.getElementById('hidden_subscription_prize'))
	{
		mainprice = parseFloat(mainprice) + parseFloat(document.getElementById('hidden_subscription_prize').value);
	}
	if(document.getElementById('productprice_notvat'))
	{
		price_without_vat = parseFloat(document.getElementById('productprice_notvat').value);
	}
	if(document.getElementById('tmp_product_old_price'))
	{
		old_price = parseFloat(document.getElementById('tmp_product_old_price').value);
	}
	
	// end
    // setting wrapper price
    setWrapperComboBox();
    var wprice = 0;
    if(document.getElementById("wrapper_price"))
    {
    	wprice = document.getElementById("wrapper_price").value;
    }
    var wrapper_price_withoutvat = 0;
    if(document.getElementById("wrapper_price_withoutvat"))
    {
    	wrapper_price_withoutvat = document.getElementById("wrapper_price_withoutvat").value;
    }
    // end wrapper
//    alert("main price = " + mainprice + " : aacc = " + accfinalprice + " : wrapp = " + wprice);
    final_price_f = parseFloat(mainprice) + parseFloat(accfinalprice) + parseFloat(wprice);
    
    product_price_without_vat = parseFloat(price_without_vat) + parseFloat(accfinalprice_withoutvat) + parseFloat(wrapper_price_withoutvat);
    
    product_old_price = parseFloat(old_price) + parseFloat(accfinalprice) + parseFloat(wprice);
    
    savingprice = parseFloat(product_old_price) - parseFloat(final_price_f);
    
	if(SHOW_PRICE=='1' && USE_AS_CATALOG!='1' && DEFAULT_QUOTATION_MODE!='1')
	{ 
		if(!final_price_f)
		{
			final_price = getPriceReplacement(final_price_f);
		} else {
			final_price = number_format(final_price_f,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
		}		
	} else {
		final_price = getPriceReplacement(final_price_f);
	}
	if(SHOW_PRICE=='1' && USE_AS_CATALOG!='1' && DEFAULT_QUOTATION_MODE!='1')
	{
		if(document.getElementById('produkt_kasse_hoejre_pris_indre'+product_id))
		{
			document.getElementById('produkt_kasse_hoejre_pris_indre'+product_id).innerHTML = 	final_price;
		}
		if(document.getElementById('display_product_discount_price'+product_id))
		{
			document.getElementById('display_product_discount_price'+product_id).innerHTML = 	final_price;
		}
		if(document.getElementById('display_product_price_without_vat'+product_id))
		{
			if(!product_price_without_vat)
			{
				product_price_without_vat = getPriceReplacement(product_price_without_vat);
			} else {
				product_price_without_vat = number_format(product_price_without_vat,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
			}
			document.getElementById('display_product_price_without_vat'+product_id).innerHTML = product_price_without_vat;
		}
		if(document.getElementById('display_product_old_price'+product_id))
		{
			if(!product_old_price)
			{
				product_old_price = getPriceReplacement(product_old_price);
			} else {
				product_old_price = number_format(product_old_price,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
			}
			document.getElementById('display_product_old_price'+product_id).innerHTML = 	product_old_price;
		}
		if(document.getElementById('display_product_saving_price'+product_id))
		{
			savingprice = number_format(savingprice,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
			document.getElementById('display_product_saving_price'+product_id).innerHTML = 	savingprice;
		}
	}
}

//Accessory data collect start 
function collectAccessory(product_id,relatedprd_id)
{
	if(product_id==0 || product_id=="")
	{
		alert("Product ID is missing");
		return false;
	}
	var layout = "";
	var prefix = "";
	var acc_subatt_price_final = 0;
	var acc_price_total = 0;
	var acc_price_withoutvat = 0;
	var acc_sub_price_withoutvat = 0;
	var price = 0; 
	var selid = 0;
	var tmpprice = 0;
	var myaccall = new Array();
	var myattall = new Array();
	var mypropall = new Array();
	var mysubpropall = new Array();
	
	
	if(document.getElementById('isAjaxBoxOpen'))
	{
		layout = document.getElementById('isAjaxBoxOpen').value;
	}
	if(layout=="viewajaxdetail")
	{
		prefix = "ajax_";
	}
	// elements
	if(document.getElementsByName("accessory_id_"+prefix+product_id+"[]"))
	{
		dcatt=document.getElementsByName("accessory_id_"+prefix+product_id+"[]");
		if(document.getElementById("giftcard_id"))
		{
			if(document.getElementById("giftcard_id").value>0)
			{
				if(dcatt.length==0)
				{
					return true;
				}
			}
		}
		var total_accessory=(dcatt.length);
		for(j=0;j<total_accessory;j++)
		{
			var my_acc_fprice = 0;
			var my_acc_withoutvat_price = 0;
			var accessory_id=dcatt[j].value;
			var commonid = prefix+product_id+'_'+accessory_id;
			var accchkchecked=0;
			var attribute_id = 0;
			acc_chk = document.getElementById("accessory_id_"+commonid);
			if(document.getElementById("attribute_id_"+commonid))
			{
				attribute_id = document.getElementById("attribute_id_"+commonid);
			}
			accchkchecked = dcatt[j].checked;
			
			if(accchkchecked)
			{
				myaccall[selid] = accessory_id;
				collectAttributes(product_id,accessory_id,relatedprd_id);
				if(document.getElementById("accessory_price"))
				{
					my_acc_fprice = parseFloat(document.getElementById("accessory_price").value);
				}
				if(document.getElementById("accessory_price_withoutvat"))
				{
					my_acc_withoutvat_price = parseFloat(document.getElementById("accessory_price_withoutvat").value);
				}				
				if(document.getElementById("acc_attribute_data"))
				{
					myattall[selid] = document.getElementById("acc_attribute_data").value;
				}
				if(document.getElementById("acc_property_data"))
				{
					mypropall[selid] = document.getElementById("acc_property_data").value;
				}
				if(document.getElementById("acc_subproperty_data"))
				{
					mysubpropall[selid] = document.getElementById("acc_subproperty_data").value;
				}
				selid++;
			}
			acc_price_total += parseFloat(my_acc_fprice);
			acc_price_withoutvat += parseFloat(my_acc_withoutvat_price);
		}
		acc_subatt_price_final += parseFloat(acc_price_total);
		acc_sub_price_withoutvat += parseFloat(acc_price_withoutvat);
//		if(myaccall.length>0)
//		{
			if(document.getElementById("accessory_data"))
			{
				document.getElementById("accessory_data").value=myaccall.join("@@");
			}
			if(document.getElementById("acc_attribute_data"))
			{
				document.getElementById("acc_attribute_data").value = myattall.join("@@");
			}
			if(document.getElementById("acc_property_data"))
			{
				document.getElementById("acc_property_data").value=mypropall.join("@@");
			}
			if(document.getElementById("acc_subproperty_data"))
			{
				document.getElementById("acc_subproperty_data").value=mysubpropall.join("@@");
			}
			if(document.getElementById("accessory_price"))
			{
				document.getElementById("accessory_price").value=acc_subatt_price_final;
			}
			if(document.getElementById("accessory_price_withoutvat"))
			{
				document.getElementById("accessory_price_withoutvat").value=acc_sub_price_withoutvat;
			}
//		}
	}
	return acc_subatt_price_final;
}

// formatting number
function number_format (number, decimals, dec_point, thousands_sep) 
{
    
    var n = number, prec = decimals;
    
    // converting price
    n *= CURRENCY_CONVERT;
    
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);        return (Math.round(n*k)/k).toString();
    };
 
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
 
    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
     var abs = toFixedFix(Math.abs(n), prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);    } else {
        s = s.replace('.', dec);
    }
 
    var decPos = s.indexOf(dec);    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';    }
   
    
    // setting final price with currency Symbol
    var display_price = "";
    
    
    
    if(CURRENCY_SYMBOL_POSITION == 'front'){
			display_price =  CURRENCY_SYMBOL_CONVERT+s;
	}else if(CURRENCY_SYMBOL_POSITION == 'behind'){
			display_price =  s+CURRENCY_SYMBOL_CONVERT;
	}else if(CURRENCY_SYMBOL_POSITION == 'none'){
			display_price =  s;
	}else{
			display_price =  CURRENCY_SYMBOL_CONVERT+s;
	} 
    
    return display_price;
}

function getPriceReplacement(product_price) 
{
	var ret = "";
	if(SHOW_PRICE=="0")
	{
		url = PRICE_REPLACE_URL;
		if(url=="")
		{
			url = "#";
		}
		ret = "<a href='"+url+"'>" + PRICE_REPLACE + "</a>";
	}
	if(SHOW_PRICE=="1" && product_price==0)
	{
		url = ZERO_PRICE_REPLACE_URL;
		if(url=="")
		{
			url = "#";
		}
		ret = "<a href='" + url + "'>" + ZERO_PRICE_REPLACE + "</a>";
	}
	return ret;
}

function setWrapper(id,price,price_withoutvat,product_id)
{
	if(document.getElementById("wrapper_id"))
	{
		document.getElementById("wrapper_id").value = id;
	}
	if(document.getElementById("sel_wrapper_id"))
	{
		document.getElementById("sel_wrapper_id").value = id;
	}
	document.getElementById("wrapper_price").value = price;
	document.getElementById("wrapper_price_withoutvat").value = price_withoutvat;
	calculateTotalPrice(product_id,0);
}	

function setPropImage(product_id,propertyObj,selValue)
{
	var propName = document.getElementById(propertyObj);
	if(propName)
	{
		if(propName.type=='checkbox')
		{
			var propNameObj = document.getElementsByName(propertyObj+"[]");
			for(var p=0;p<propNameObj.length;p++)
			{
				var newval = propNameObj[p].value;
				if(newval==selValue)
				{
					propNameObj[p].checked = true;
				}
			}
		} else {
			for(var p=0;p<propName.options.length;p++)
			{
				var newval = propName.options[p].value;
				if(newval==selValue)
				{
					propName.options[p].selected = true;
				}
			}
		}
	}
}	

function setSubpropImage(product_id,subpropertyObj,selValue)
{
	var subpropName = document.getElementById(subpropertyObj);
	if(subpropName)
	{
		if(subpropName.type=='checkbox')
		{
			var subpropNameObj = document.getElementsByName(subpropertyObj+"[]");
			for(var p=0;p<subpropNameObj.length;p++)
			{
				var newval = subpropNameObj[p].value;
				if(subpropNameObj[p].value==selValue)
				{
					subpropNameObj[p].checked = true;
				}
			}
		} else {
			for(var p=0;p<subpropName.options.length;p++)
			{
				var newval = subpropName.options[p].value;
				if(subpropName.options[p].value==selValue)
				{
					subpropName.options[p].selected = true;
				}
			}
		}
	}
}

function setPropertyImage(product_id,propertyObj)
{
	var selValue=0;
	var propName = document.getElementById(propertyObj);
	if(propName)
	{
		if(propName.type=='checkbox')
		{
			var propNameObj = document.getElementsByName(propertyObj+"[]");
			for(var p=0;p<propNameObj.length;p++)
			{
				var borderstyle = "";
//				var borderpadding = "";
				selValue = propNameObj[p].value;
				if(propNameObj[p].checked)
				{
					borderstyle = "1px solid";
//					borderpadding = "7px";
				}
				if(document.getElementById(propertyObj+"_propimg_"+selValue))
				{
					document.getElementById(propertyObj+"_propimg_"+selValue).style.border = borderstyle;
//					document.getElementById(propertyObj+"_propimg_"+selValue).style.padding = borderpadding;
				}
			}
		} else {
			for(var p=0;p<propName.length;p++)
			{
				var borderstyle = "";
//				var borderpadding = "";
				selValue = propName[p].value;
				if(propName[propName.selectedIndex].value==selValue)
				{
					borderstyle = "1px solid";
//					borderpadding = "7px";
				}
				if(document.getElementById(propertyObj+"_propimg_"+selValue))
				{
					document.getElementById(propertyObj+"_propimg_"+selValue).style.border = borderstyle;
//					document.getElementById(propertyObj+"_propimg_"+selValue).style.padding = borderpadding;
				}
			}
			
		}
	}
}	

function setSubpropertyImage(product_id,subpropertyObj,selValue)
{
	var selValue=0;
	var subpropName = document.getElementById(subpropertyObj);
	if(subpropName)
	{
		if(subpropName.type=='checkbox')
		{
			var subpropNameObj = document.getElementsByName(subpropertyObj+"[]");
			for(var p=0;p<subpropNameObj.length;p++)
			{
				var borderstyle = "";
//				var borderpadding = "";
				selValue = subpropNameObj[p].value;
				if(subpropNameObj[p].checked)
				{
					borderstyle = "1px solid";
//					borderpadding = "7px";
				}
				if(document.getElementById(subpropertyObj+"_subpropimg_"+selValue))
				{
					document.getElementById(subpropertyObj+"_subpropimg_"+selValue).style.border = borderstyle;
//					document.getElementById(subpropertyObj+"_subpropimg_"+selValue).style.padding = borderpadding;
				}
			}
		} else {
			for(var p=0;p<subpropName.length;p++)
			{
				var borderstyle = "";
//				var borderpadding = "";
				selValue = subpropName[p].value;
				if(subpropName[subpropName.selectedIndex].value==selValue)
				{
					borderstyle = "1px solid";
//					borderpadding = "7px";
				}
				if(document.getElementById(subpropertyObj+"_subpropimg_"+selValue))
				{
					document.getElementById(subpropertyObj+"_subpropimg_"+selValue).style.border = borderstyle;
//					document.getElementById(subpropertyObj+"_subpropimg_"+selValue).style.padding = borderpadding;
				}
			}
			
		}
	}
}

function displayAdditionalImage(product_id,accessory_id,relatedprd_id,selectedproperty_id,selectedsubproperty_id)
{
	var suburl = "&product_id=" + product_id;
	suburl = suburl + "&accessory_id=" + accessory_id;
	suburl = suburl + "&relatedprd_id=" + relatedprd_id;
	suburl = suburl + "&property_id=" + selectedproperty_id;
	suburl = suburl + "&subproperty_id=" + selectedsubproperty_id;
	
	if(accessory_id!=0)
	{
		prefix = "acc_";
		product_id = accessory_id;
	} else if(relatedprd_id!=0)
	{
		prefix = "rel_";
	} else {
		prefix = "prd_";
	}
	
	if(document.getElementById(prefix+"main_imgwidth"))
	{
		suburl = suburl + "&main_imgwidth=" + parseInt(document.getElementById(prefix+"main_imgwidth").value);
	}
	if(document.getElementById(prefix+"main_imgheight"))
	{
		suburl = suburl + "&main_imgheight=" + parseInt(document.getElementById(prefix+"main_imgheight").value);
	}
	var changehref = 0;
	if(document.getElementById('a_main_image'+product_id))
	{
		var tmphref =  document.getElementById('a_main_image'+product_id).href;
//		newhref = reverseString(tmphref);
		tmphref = tmphref.split("");
		var newhref = tmphref.reverse();
		newhref = newhref.join("");
		tmphref = newhref.split(".");
		tmphref = tmphref[0].split("");
//		newhref = reverseString(tmphref);
		newhref = tmphref.reverse();
		newhref = newhref.join("");
		
		if(newhref=="jpg" || newhref=="jpeg" || newhref=="png" || newhref=="gif" || newhref=="bmp")
		{
			changehref = 1;
		}
	}
	
	var url = site_url+"index2.php?option=com_redshop&view=product&task=displayAdditionImage";
	url = url + suburl;
//	alert(url);
	request = getHTTPObject();
	request.onreadystatechange=function() {
		// if request object received response
		if(request.readyState == 4)
		{
			var txtresponse = request.responseText;
			var arrResponse = txtresponse.split("`_`");
			if(document.getElementById('additional_images'+product_id) && arrResponse[1]!="")
			{
				document.getElementById('additional_images'+product_id).innerHTML=arrResponse[1];
			}
			if(document.getElementById('a_main_image'+product_id))
			{
				if(arrResponse[2]!="" && changehref==1)
				{
					document.getElementById('a_main_image'+product_id).href=arrResponse[2];
				}
				if(arrResponse[3]!="")
				{
					document.getElementById('a_main_image'+product_id).title=arrResponse[3];
				}
				if(arrResponse[4]!="")
				{
					document.getElementById('a_main_image'+product_id).innerHTML=arrResponse[4];
				}
				$$($$(document.links).filter(function(el) {
					return el.rel && el.rel.test(/^lightbox/i);
				})).slimbox({/* Put custom options here */}, null, function(el) {
					return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
				});
			}
//			alert(arrResponse[6]);
			if(document.getElementById('stockImage'+product_id) && arrResponse[5]!="")
			{
				document.getElementById('stockImage'+product_id).src=arrResponse[5];
			}
			if(document.getElementById('stockImageTooltip'+product_id) && arrResponse[6]!="")
			{
				document.getElementById('stockImageTooltip'+product_id).innerHTML=arrResponse[6];
			}
			if(document.getElementById('ProductAttributeMinDelivery'+product_id) && arrResponse[7]!="")
			{
				document.getElementById('ProductAttributeMinDelivery'+product_id).innerHTML=arrResponse[7];
			}
		}
	}
	request.open("GET", url, true);
	request.send(null);
}

function setWrapperComboBox()
{
	if(document.getElementById("wrapper_id") && document.getElementById("sel_wrapper_id"))
	{
		document.getElementById("sel_wrapper_id").value = document.getElementById("wrapper_id").value;
	}
	var obj = document.getElementsByName("w_price");
	var id = 0;
	if(document.getElementById("sel_wrapper_id"))
	{
		id = document.getElementById("sel_wrapper_id").value;
	}
	var wprice = 0;
	var wprice_withoutvat = 0;
	if(document.getElementById("wrapper_check") && document.getElementById("wrapper_check").checked)
	{
		if(id!=0)
		{
			wprice = document.getElementById("w_price"+id).value;
			wprice_withoutvat = document.getElementById("w_price_withoutvat"+id).value;
		}
	}
	if(document.getElementById("wrapper_price"))
	{
		document.getElementById("wrapper_price").value = wprice;
	}
	if(document.getElementById("wrapper_price_withoutvat"))
	{
		document.getElementById("wrapper_price_withoutvat").value = wprice_withoutvat;
	}
	for(i=0;i<obj.length;i++)
	{
		var tmpval = obj[i].id.substr(7);//obj[i].value;
		if(document.getElementById("wrappertd"+tmpval))
		{
			if(tmpval==id)
			{
				document.getElementById("wrappertd"+tmpval).style.border = "1px solid";
				document.getElementById("wrappertd"+tmpval).style.padding = "7px";
			} else {
				document.getElementById("wrappertd"+tmpval).style.border = "";
				document.getElementById("wrappertd"+tmpval).style.padding = "";
			}
		}
	}
}

/*
 * ajax function for calculatin of discount
 */
function discountCalculation()
{
	var calHeight=0,calWidth=0,calDepth=0,calRadius=0,proid=0,calUnit='cm',globalcalUnit='cm',total_area='',price_per_area=0,price_per_piece=0,output="",price_total=0;
	
	if(document.getElementById('product_id')){
		proid = document.getElementById('product_id').value;
	}
	
	if(document.getElementById('calc_height')){
		calHeight = document.getElementById('calc_height').value;
		if(calHeight==""){
			alert("Please Insert Height");
			return false;
		}
			
	}
	
	if(document.getElementById('calc_width')){
		calWidth = document.getElementById('calc_width').value;
		if(calWidth==""){
			alert("Please Insert Width");
			return false;
		}
	}
	
	if(document.getElementById('calc_depth')){
		calDepth = document.getElementById('calc_depth').value;
		if(calDepth==""){
			alert("Please Insert Depth");
			return false;
		}
	}
	
	if(document.getElementById('calc_radius')){
		calRadius = document.getElementById('calc_radius').value;
		if(calRadius==""){
			alert("Please Insert Radius");
			return false;
		}
	}
	
	if(document.getElementById('discount_calc_unit')){
		calUnit = document.getElementById('discount_calc_unit').value;
		if(calUnit==0){
			alert("Please Insert Unit");
			return false;
		}
	}
	
	if(document.getElementById('calc_unit')){
		globalcalUnit = document.getElementById('calc_unit').value;	
	}
	
	
	
	http=getHTTPObject();
	
	if (http==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	
	//alert("calHeight"+calHeight+"calWidth"+calWidth+"calDepth"+calDepth+"calRadius"+calRadius);
	
	http.open("GET", site_url+"index.php?option=com_redshop&view=cart&task=discountCalculator&product_id="+proid+"&calcHeight="+calHeight+"&calcWidth="+calWidth+"&calcDepth="+calDepth+"&calcRadius="+calRadius+"&calcUnit="+calUnit+"&tmpl=component", true);
	http.send(null);
	
	http.onreadystatechange = function(){
		if(http.readyState == 4 ) {
			
			var areaPrice = http.responseText;
			
			//var areaPrice = responce.split("~");
			areaPrice = areaPrice.replace(/^\s+|\s+$/g,"");
			
			if(areaPrice == "fail"){
				
				alert("Not Available");
				return false;
			}else{
				
				areaPrice = areaPrice.split("\n");
							
				// get quantity
				
				var eld = document.getElementsByName('quantity');
				for(var g=0;g<eld.length;g++){
					
					if(eld[g].id == 'ajax_quantity'+proid){
						 
						qty = eld[g].value; 
					}else{
						if(eld[g].id == 'quantity'+proid){
							 
							qty = eld[g].value; 
						}
					}
				}
				// end
				
				
				total_area = areaPrice[0];
				
				price_per_area = areaPrice[1];
				
				price_per_piece = areaPrice[2];				
				
				price_excl_vat = areaPrice[7];
				
				// format numbers	
				var formatted_price_per_area = number_format(price_per_area,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
				
				var formatted_price_per_piece = number_format(price_per_piece,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
				
				if(qty<=0)
					qty = 1;
				
				price_total = parseFloat(price_per_piece)*qty;
				
				var formatted_price_total = number_format(price_total,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
				
				
				output = areaPrice[3] + total_area+"<br />";
				output += areaPrice[4] + formatted_price_per_area+"<br />";
				output += areaPrice[5] + formatted_price_per_piece+"<br />";
				output += areaPrice[6] +formatted_price_total;			
					
				if(document.getElementById('discount_cal_final_price'))
				{
					document.getElementById('discount_cal_final_price').innerHTML =	output;
				}		
				
				if(document.getElementById('main_price'+proid))
				{
					var product_main_price = document.getElementById('main_price'+proid).value;
					
					calculateTotalPrice(proid,0);				
					
					if(SHOW_PRICE=='1' && USE_AS_CATALOG!='1' && DEFAULT_QUOTATION_MODE!='1'){
						
						if(document.getElementById('produkt_kasse_hoejre_pris_indre'+proid))
						{							
							var product_total = final_price_f-parseFloat(product_main_price)+parseFloat(price_total);
							//var product_price_excl_vat = (product_main_price*qty)-(price_excl_vat*qty);
							var product_price_excl_vat = price_total-price_excl_vat*qty;
							formatted_price_total = number_format(product_total,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
							
							formatted_product_price_excl_vat = number_format(product_price_excl_vat,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
							
							document.getElementById('produkt_kasse_hoejre_pris_indre'+proid).innerHTML = 	formatted_price_total;
							
							document.getElementById('display_product_discount_price_excl_vat'+proid).innerHTML = 	formatted_product_price_excl_vat;
							
						}
						
						// set product main price as price total for dynamic price change
						document.getElementById('main_price'+proid).value	=	price_total;
					}
				}
			}
		}
	};
}

function setProductUserFieldImage(id,prodid,value1,ele)
{
	var imgLength = document.getElementsByClassName('imgClass_'+prodid);
	
	for(var i=0;i<imgLength.length;i++)
	{	
		removeClass(imgLength[i],'selectedimg');
	}
	if(document.getElementById(id+'_'+prodid))
	{
		document.getElementById(id+'_'+prodid).value = value1;
		ele.className += ' selectedimg';
	}
	if(document.getElementById('ajax'+id+'_'+prodid))
	{
		document.getElementById('ajax'+id+'_'+prodid).value = value1;		
	}
	if(document.getElementById(id))
	{
		document.getElementById(id).value = value1;
	}
}

function removeClass(ele,cls) 
{
	if (hasClass(ele,cls)) {
	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	ele.className=ele.className.replace(reg,' ');
	}
}

function hasClass(ele,cls) 
{
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

/*
 * function to support ie too
 */
function getElementsByClassName(xx)
{
	var rl=new Array();
	var ael=document.all?document.all:document.getElementsByTagName('*')
	for(i=0,j=0;i<ael.length;i++)
	{
		if((ael[i].className==xx))
		{
			rl[j]=ael[i];
			j++;
		}
	}
	return rl;
}

function displayAddtocartForm(frmCartName,product_id,relatedprd_id,frmUserfieldName)
{
	var str = '';
	var elem = "";
	
	if(document.getElementById(frmUserfieldName))
	{
		elem = document.getElementById(frmUserfieldName).elements;
	}
	if(product_id==0 || product_id=="")
	{
		alert("Product ID is missing");
		return false;
	}

	var arrcheckbox = new Array();
	var fieldname = new Array();
	var arSelected = new Array(); 
	var fieldNamefrmId = "";

	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type=="checkbox" && elem!= "" || elem[i].type=="radio" && elem!= "" )
		{
			if(elem[i].checked==true)
			{
				arrcheckbox[i]=elem[i].value;
				fieldname[i]= elem[i].name;
				var elements = document.getElementById(frmCartName).elements;
				fieldNamefrmId = reverseString(elem[i].id);
				fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));	
				for(var j = 0; j < elements.length; j++)
				{
//					if(elem[i].name == elements[j].name)
					if(fieldNamefrmId == elements[j].name)
					{
						var strval = elements[j].value;
						
						if(strval.search(arrcheckbox[i])==-1)
						{
							if(elements[j].value!="")
								elements[j].value += ",";	
							elements[j].value += arrcheckbox[i];
						}
					}	
				}
			}
		}else if(elem[i].type=="select-one" )
		{
			arrcheckbox[i]=elem[i].value;
			fieldname[i]= elem[i].name;
			var elements = document.getElementById(frmCartName).elements;
			for(var j = 0; j < elements.length; j++)
			{
				fieldNamefrmId = elem[i].id;
				//if(elem[i].name == elements[j].name)
				if(fieldNamefrmId == elements[j].name)
				{
					var strval = elements[j].value;
					if(strval.search(arrcheckbox[i]))
						elements[j].value += arrcheckbox[i];
				}	
			}
		} else if( elem[i].type == "select-multiple")
		{
			var ob = elem[i];
			elements = document.getElementById(frmCartName).elements;
		
			for (var t = 0; t < ob.options.length; t++)
			{
				if (ob.options[ t ].selected)
				{
					for(var j = 0; j < elements.length; j++)
					{
						fieldNamefrmId = elem[i].id;
						//if(elem[i].name == elements[j].name)
						if(fieldNamefrmId == elements[j].name)
						{
							var strval = elements[j].value;
							if(strval.search(String (ob.options[ t ].value))==-1)
							{
								if(elements[j].value!="")
									elements[j].value += ",";
								elements[j].value += (String (ob.options[ t ].value));
							}
						}
					}
				}
			}
		}
	}

	var cal_el = getElementsByClassName('calendar');

	var cal_fieldNamefrmId = "";
	for ( cal_i=0;cal_i<cal_el.length;cal_i++ ) 
	{
		// do stuff here with myEls[i]
		var calImgId = cal_el[cal_i].id;
		arr =  calImgId.split("_img");
		n = arr.length;
		var calName = arr[0];
		if(calName!="" && calName.search(frmCartName))
		{
			if(document.getElementById(calName).value!="")
			{
				cal_fieldNamefrmId = reverseString(calName);
				cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
	//			if(document.getElementById(cal_fieldNamefrmId))
	//			document.getElementById(cal_fieldNamefrmId).value = document.getElementById(calName).value;
				var frm_name = String(frmCartName);
				var elements = document.getElementById(frm_name).elements;
				var cfieldName = String(cal_fieldNamefrmId+'_'+product_id);
				
				for(var j = 0; j < elements.length; j++)
				{
					if(cal_fieldNamefrmId == elements[j].name)
					{
						elements[j].value = document.getElementById(cfieldName).value;
					}	
				}
			}
		}
	}
	if(document.getElementById(frmCartName) && document.getElementById('requiedAttribute'))
	{
		document.getElementById('requiedAttribute').value = document.getElementById(frmCartName).requiedAttribute.getAttribute('reattribute');
	}
	
	//get selected attribute,property,subproperty data and total price
	calculateTotalPrice(product_id,relatedprd_id);

	//set selected attribute,property,subproperty data and total price to Add to cart form
	if(!setAddtocartForm(frmCartName,product_id)){
		return false;
	}
	
	return true;
}

function setAddtocartForm(frmCartName,product_id)
{
	var frm = document.getElementById(frmCartName);
		
	if(document.getElementById('Itemid'))
	{
		frm.Itemid.value = document.getElementById('Itemid').value;
//		alert("Itemid= " + frm.Itemid.value);
	}
	if(document.getElementById('attribute_data'))
	{
		frm.attribute_data.value = document.getElementById('attribute_data').value;
//		alert("attribute_data= " + frm.attribute_data.value);
	}
	if(document.getElementById('property_data'))
	{
		frm.property_data.value = document.getElementById('property_data').value;
//		alert("property_data= " + frm.property_data.value);
	}
	if(document.getElementById('subproperty_data'))
	{
		frm.subproperty_data.value = document.getElementById('subproperty_data').value;
//		alert("subproperty_data= " + frm.subproperty_data.value);
	}
	if(document.getElementById('accessory_data'))
	{
		frm.accessory_data.value = document.getElementById('accessory_data').value;
//		alert("accessory_data= " + frm.accessory_data.value);
	}
	if(document.getElementById('acc_attribute_data'))
	{
		frm.acc_attribute_data.value = document.getElementById('acc_attribute_data').value;
//		alert("acc_attribute_data= " + frm.acc_attribute_data.value);
	}
	if(document.getElementById('acc_property_data'))
	{
		frm.acc_property_data.value = document.getElementById('acc_property_data').value;
//		alert("acc_property_data= " + frm.acc_property_data.value);
	}
	if(document.getElementById('acc_subproperty_data'))
	{
		frm.acc_subproperty_data.value = document.getElementById('acc_subproperty_data').value;
//		alert("acc_subproperty_data= " + frm.acc_subproperty_data.value);
	}
	if(document.getElementById('accessory_price'))
	{
		frm.accessory_price.value = document.getElementById('accessory_price').value;
//		alert("accessory_price= " + frm.accessory_price.value);
	}
	if(document.getElementById('requiedAttribute'))
	{
		frm.requiedAttribute.value = document.getElementById('requiedAttribute').value;
//		alert("requiedAttribute= " + frm.requiedAttribute.value);
	}
	if(document.getElementById('sel_wrapper_id'))
	{
		frm.sel_wrapper_id.value = document.getElementById('sel_wrapper_id').value;
//		alert("sel_wrapper_id= " + frm.sel_wrapper_id.value);
	}
	
	
	if(document.getElementById('calc_height')){
		var calHeight = document.getElementById('calc_height').value;
		
		if(calHeight==""){
			alert("Please Insert Height");
			return false;
		}else{
			frm.calcHeight.value = calHeight;
		}
			
	}
	
	if(document.getElementById('calc_width')){
		var calWidth = document.getElementById('calc_width').value;
		if(calWidth==""){
			alert("Please Insert Width");
			return false;
		}else{
			frm.calcWidth.value = calWidth;
		}
	}
	
	if(document.getElementById('calc_depth')){
		var calDepth = document.getElementById('calc_depth').value;
		if(calDepth==""){
			alert("Please Insert Depth");
			return false;
		}else{
			frm.calcDepth.value = calDepth;	
		}
	}
	
	if(document.getElementById('calc_radius')){
		var calRadius = document.getElementById('calc_radius').value;
		if(calRadius==""){
			alert("Please Insert Radius");
			return false;
		}else{
			frm.calcRadius.value = calRadius;
		}
	}
	
	if(document.getElementById('discount_calc_unit')){
		calUnit = document.getElementById('discount_calc_unit').value;
		if(calUnit==0){
			alert("Please Insert Unit");
			return false;
		}else{
			frm.calcUnit.value = calUnit;
		}
	}
	if(document.getElementById('hidden_subscription_id'+product_id) && document.getElementById('p_subscription')){
		subId = document.getElementById('hidden_subscription_id'+product_id).value;
		if(subId==0){
			alert("Please Select Your Subscription Plan");
			return false;
		}else{
			frm.subscription_id.value = subId;
		}
	}
	return true;
}

function checkAddtocartValidation(frmCartName,product_id,relatedprd_id,frmUserfieldName,totAttribute,totAccessory,totUserfield)
{
	if(product_id==0 || product_id=="")
	{
		alert("Product ID is missing");
		return false;
	}
	var prop_id_cart = "";
	var prop_id_cart_value = "";
	var subprop_id_cart = "";
	var subprop_id_cart_value = "";
	var attr_id ="";
	var subattr_id ="";
	var att_required = "";
	var att_name = "";
	var att_name_lebl = "";
	var att_error = "";
	var att_error_alert = false;
	var attreq = false;
	
	var arr_attr_id = new Array();
	var arr_subattr_id =new Array();
	var sel_i=0;
	var sub_sel_i=0;
	// User field validation
	if(AJAX_CART_BOX==0)
	{
		var ret = userfieldValidation("extrafields"+product_id);
		if(!ret)
		{
			return false;
		}
		var requiedAttribute = document.getElementById(frmCartName).requiedAttribute.value;
		if(requiedAttribute!=0 && requiedAttribute!="")
		{
			alert(requiedAttribute);
			return false;
		}
//		alert('going to cart');
		document.getElementById(frmCartName).submit();
		
	} else {
			
		/* 
		 * count total attribute + extra fields
		 * Where natt = number of total attribute
		 * And nextra = number of extra fields 
		 */
		var ntotal = parseInt(totAttribute) + parseInt(totAccessory) + parseInt(totUserfield);
		// submit form from product detail page
		/* 
		 * ntotal = count total attribute + extra fields 
		 * if attribute is not available then cart will submit directly
		 * 
		 */ 
		if(ntotal>0)
		{
			displayAjaxCartdetail(frmCartName,product_id,relatedprd_id,totAttribute,totAccessory,totUserfield);
		} else {
			submitAjaxCartdetail(frmCartName, product_id, relatedprd_id, totAttribute, totAccessory, totUserfield);
		}
	}
	//alert('bye***');
}

function displayAjaxCartdetail(frmCartName,product_id,relatedprd_id,totAttribute,totAccessory,totUserfield)
{
	if(product_id==0 || product_id=="")
	{
		alert("Product ID is missing");
		return false;
	}
	var layout = "";
	if(document.getElementById('isAjaxBoxOpen'))
	{
		layout = document.getElementById('isAjaxBoxOpen').value;
	}
	var attdata=0,setatt=1,qty=1,setacc=0;
	// get form
	var formname = document.getElementById(frmCartName);
	
	// get multiple extra fields attributes
	var extrafields = document.getElementsByName('extrafields'+product_id+'[]');
	
	// intialized Userfield Name( comma seprated ) 
	var extrafieldNames = "";
	var previousfieldName = "";
	var fieldNamefrmId = "";
	var chk_flag = false;
	var rdo_previousfieldName = "";
	var rdo_fieldNamefrmId = "";
	var rdo_flag = false;
	var imgfieldNamefrmId = "";
	var selmulti_fieldNamefrmId = "";
	
	for(var ex=0;ex<extrafields.length;ex++){
		
		if(!extrafields[ex].value && extrafields[ex].type=='text'){
			extrafieldNames += extrafields[ex].id ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}	
		}
		else if(!extrafields[ex].value && extrafields[ex].type=='select-one'){
			extrafieldNames += extrafields[ex].id ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}	
		}
		else if(!extrafields[ex].value && extrafields[ex].type=='hidden'){
			imgfieldNamefrmId = reverseString(extrafields[ex].id);
			imgfieldNamefrmId = reverseString(imgfieldNamefrmId.substr(imgfieldNamefrmId.indexOf("_")+1));
			extrafieldNames += imgfieldNamefrmId ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}
		}
		else if(extrafields[ex].type=='checkbox')
		{	
			fieldNamefrmId = reverseString(extrafields[ex].id);
			fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
			
			if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && chk_flag==false)
			{
				extrafieldNames += previousfieldName+",";
			}
			
			if(previousfieldName != fieldNamefrmId)
			{	
				previousfieldName = fieldNamefrmId;
				chk_flag = false;

			}
			if(extrafields[ex].checked || chk_flag== true)
			{	chk_flag = true;
				continue; }
			if((ex == (extrafields.length-1) && chk_flag==false) || (extrafields[ex+1].type!='checkbox' && chk_flag==false)){
				extrafieldNames += previousfieldName+",";
			}
			
		}
		else if(extrafields[ex].type=='radio')
		{	
			
			rdo_fieldNamefrmId = reverseString(extrafields[ex].id);
			rdo_fieldNamefrmId = reverseString(rdo_fieldNamefrmId.substr(rdo_fieldNamefrmId.indexOf("_")+1));
			
			if(rdo_previousfieldName != "" && rdo_previousfieldName!=rdo_fieldNamefrmId && rdo_flag==false)
			{
				extrafieldNames += rdo_previousfieldName+",";
			}
			
			if(rdo_previousfieldName != rdo_fieldNamefrmId)
			{	
				rdo_previousfieldName = rdo_fieldNamefrmId;
				rdo_flag = false;
			}
			if(extrafields[ex].checked || rdo_flag== true)
			{	
				rdo_flag = true;
				continue; }
			else if((ex == (extrafields.length-1) && rdo_flag==false) || (extrafields[ex+1].type!='radio' && rdo_flag==false)){
				extrafieldNames += rdo_previousfieldName+",";
			}	
		}
		else if(extrafields[ex].type=='select-multiple')
		{	
			
			selmulti_fieldNamefrmId = reverseString(extrafields[ex].id);
			selmulti_fieldNamefrmId = reverseString(selmulti_fieldNamefrmId.substr(selmulti_fieldNamefrmId.indexOf("_")+1));
			
			if(extrafields[ex].value)
				{	
					continue; }
				else{
					extrafieldNames += selmulti_fieldNamefrmId+",";
				}	
		}
		
			
	}
	/* for calender type
	 * user field
	 */
	var cal_el = getElementsByClassName('calendar');

	var cal_fieldNamefrmId = "";
	for ( cal_i=0;cal_i<cal_el.length;cal_i++ ) {
		// do stuff here with myEls[i]
		 var calImgId = cal_el[cal_i].id;
		 
		 arr =  calImgId.split("_img");
		 n = arr.length;
		 var calName = arr[0];

		if(calName!="")
		{
		 if(document.getElementById(calName).value=="")
		 {
			cal_fieldNamefrmId = reverseString(calName);
			cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
			extrafieldNames += ","+cal_fieldNamefrmId+",";
		 }
		}
	}
	// End
	var subscription_data= "";
	if(document.getElementById('hidden_subscription_id')){
		
		subId = document.getElementById('hidden_subscription_id').value;
		if(subId==0 || subId==""){
			alert("Please Select Your Subscription Plan");
			return false;
		}
		subscription_data = "&subscription_id="+subId;
	}
	
	var params = "";
	request = getHTTPObject();
	if(document.getElementById('quantity'+product_id).value)
	{
  		var product_quantity = document.getElementById('quantity'+product_id).value;
	}
	var requiedAttribute = document.getElementById(frmCartName).requiedAttribute.value;
	var requiedAccessory = document.getElementById(frmCartName).accessory_data.value;

	if(requiedAttribute=="")
	{
		totAttribute = 0;
	}
	if(requiedAccessory!="")
	{
		totAccessory = 0;
	}
	if(extrafieldNames!="")
	{
		totUserfield = 0;
	}
//	alert("totAttribute=" + totAttribute + "totAccessory=" + totAccessory + "totUserfield=" + totUserfield);
	var ntotal = parseInt(totAttribute) + parseInt(totAccessory) + parseInt(totUserfield);

	if(ntotal==0)
	{
		submitAjaxCartdetail(frmCartName, product_id, relatedprd_id, totAttribute, totAccessory, totUserfield);
	}
	else if(layout=="viewajaxdetail")
	{
		submitAjaxCartdetail(frmCartName, product_id, relatedprd_id, totAttribute, totAccessory, totUserfield);
	}
	else 
	{
		var sel_data = "&property_data=" + encodeURIComponent(document.getElementById(frmCartName).property_data.value);
		sel_data = sel_data + "&subproperty_data=" + encodeURIComponent(document.getElementById(frmCartName).subproperty_data.value);
		sel_data = sel_data + "&accessory_data=" + encodeURIComponent(document.getElementById(frmCartName).accessory_data.value);
		sel_data = sel_data + "&acc_property_data=" + encodeURIComponent(document.getElementById(frmCartName).acc_property_data.value);
		sel_data = sel_data + "&acc_subproperty_data=" + encodeURIComponent(document.getElementById(frmCartName).acc_subproperty_data.value);
		sel_data = sel_data + "&sel_wrapper_id=" + encodeURIComponent(document.getElementById(frmCartName).sel_wrapper_id.value);
		
		var params = "option=com_redshop&view=product&pid="+ product_id +"&relatedprd_id="+relatedprd_id+"&layout=viewajaxdetail&product_quantity="+product_quantity+"&tmpl=component&nextrafield="+totUserfield+"&extrafieldNames="+extrafieldNames+subscription_data+sel_data;
	
		var url = site_url+"index.php?" + params;
//		alert(url);
		
		request.onreadystatechange=function() 
		{
			if(request.readyState == 4 && request.status == 200) 
			{
				var responce = request.responseText;
				
				document.attbox = new MooPrompt('', responce ,{
					buttons: 0,				
					width:500,
					height:600,	
					vertical: 'middle', 
					horizontal: 'center', 
					overlay: true,
					showCloseBtn: true,					
					effect: 'grow',
					boxId:'detailBox'	
						
				});
				
				$$($$(document.links).filter(function(el) {
					return el.rel && el.rel.test(/^lightbox/i);
				})).slimbox({/* Put custom options here */}, null, function(el) {
					return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
				});
		
				var el = document.getElementsByClassName('calendar');
					
				for ( i=0;i<el.length;i++ ) {
					// do stuff here with myEls[i]
					 var calImgId = el[i].id;
					 arr =  calImgId.split("_img");
					 n = arr.length;
					 var calName = arr[0];
					 var realname = calName.split("ajax");
					  
					 if((calImgId.search('ajax')!=-1) && (extrafieldNames.search(realname[0]) !=-1) )
					 {
						 window.addEvent('domready', function() {Calendar.setup({
							 inputField     :    calName,     // id of the input field
							 ifFormat       :    "%d-%m-%Y",      // format of the input field
		
							 button         :    el[i].id,  // trigger for the calendar (button ID)
							align          :    "Tl",           // alignment (defaults to "Bl")
							singleClick    :    true
						});});
					 }
					}
			}
		}
	}
	
	request.open("POST", url, true);
	request.send(params);
}

function submitAjaxCartdetail(frmCartName,product_id,relatedprd_id,totAttribute,totAccessory,totUserfield)
{	
	var frm = document.getElementById(frmCartName);
	
	var proid = 0;
	var priceval = 0;
	var mainpri = 0;
	var proppri = 0;
	var attpric = 0;
	var accpric = 0;
	var propcartid = 0;
	var subpropcartid = 0;
	var wrapperdata = "";
	var accdata = "";
	var attdata = "";
	var subattdata =  "";
	var qty = 1;
	var id = '';
	var set=false;
	// calculator variables
	var calHeight=0,calWidth
	
	
	// get multiple extra fields attributes
	var extrafields = document.getElementsByName('extrafields'+product_id+'[]');
	
	// intialize defaults
	var extrafieldName = "";
	var extrafieldVal = "";
	var extrafieldpost = "";

	var previousfieldName = "";
	var fieldNamefrmId = "";
	var chk_flag = false;
	var rdo_previousfieldName = "";
	var rdo_fieldNamefrmId = "";
	var rdo_flag = false;
	
	var selmulti_fieldNamefrmId = "";
	
	var ret = userfieldValidation("extrafields"+product_id);
	if(!ret)
	{
		return false;
	}
	var requiedAttribute = document.getElementById(frmCartName).requiedAttribute.value;
	
	if(requiedAttribute!=0 && requiedAttribute!="")
	{
		alert(requiedAttribute);
		return false;
	}
	
	for(var ex=0;ex<extrafields.length;ex++){
		
		if(extrafields[ex].type=='checkbox')
		{
			fieldNamefrmId = reverseString(extrafields[ex].id);
			fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
			if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && extrafieldVal!="")
			{
				extrafieldpost += "&"+previousfieldName + "="+extrafieldVal;
			}
			if(previousfieldName != fieldNamefrmId)
			{	
				extrafieldVal = "";
				previousfieldName = fieldNamefrmId;
			}
			if(extrafields[ex].checked)
			{	
				if(extrafieldVal!="")
					extrafieldVal += ",";
				extrafieldVal += extrafields[ex].value; 
			}
			if(ex == (extrafields.length-1) && extrafieldVal!=""){
				extrafieldpost += "&"+fieldNamefrmId + "="+extrafieldVal;
			}
			if(ex<(extrafields.length-1))
			{
				if((extrafields[ex+1].type != 'checkbox') && extrafieldVal != "")
					extrafieldpost += "&"+fieldNamefrmId + "="+extrafieldVal;	
			}
		}
		else if(extrafields[ex].type=='radio')
		{	
			
			rdo_fieldNamefrmId = reverseString(extrafields[ex].id);
			rdo_fieldNamefrmId = reverseString(rdo_fieldNamefrmId.substr(rdo_fieldNamefrmId.indexOf("_")+1));
			
			if(rdo_previousfieldName != "" && rdo_previousfieldName!=rdo_fieldNamefrmId && rdo_flag==false)
			{
				extrafieldpost += "&"+rdo_previousfieldName + "="+extrafieldVal;
			}
			
			if(rdo_previousfieldName != rdo_fieldNamefrmId)
			{	
				extrafieldVal= "";
				rdo_previousfieldName = rdo_fieldNamefrmId;
				rdo_flag = false;
				if(extrafields[ex].checked || rdo_flag== true)
				{	
					rdo_flag = true;
					extrafieldpost += "&"+rdo_previousfieldName + "="+extrafields[ex].value;
					continue; }
			}
			else
			{
				if(extrafields[ex].checked || rdo_flag== true)
				{	
					rdo_flag = true;
					extrafieldpost += "&"+rdo_fieldNamefrmId + "="+extrafields[ex].value;
					continue; }
			}	
		}
		else if(extrafields[ex].type=='select-multiple')
		{	
			var ob = extrafields[ex];
			extrafieldVal = "";
			selmulti_fieldNamefrmId = reverseString(extrafields[ex].id);
			selmulti_fieldNamefrmId = reverseString(selmulti_fieldNamefrmId.substr(selmulti_fieldNamefrmId.indexOf("_")+1));
			for (var t = 0; t < ob.options.length; t++)
			{
				if (ob.options[ t ].selected)
				{
					var strval = extrafieldVal;
					if(strval.search(String (ob.options[ t ].value))==-1)
					{
						if(extrafieldVal!="")
							extrafieldVal += ",";
						extrafieldVal += (String (ob.options[ t ].value));
					}
				}
			}
			
			if(extrafieldVal)
			{	
				extrafieldpost += "&"+selmulti_fieldNamefrmId + "="+extrafieldVal;
			}	
		}else if(extrafields[ex].type=='hidden'){
			imgfieldNamefrmId = reverseString(extrafields[ex].id);
			imgfieldNamefrmId = reverseString(imgfieldNamefrmId.substr(imgfieldNamefrmId.indexOf("_")+1));
			
			extrafieldName = imgfieldNamefrmId ; 	// make Id as Name
			extrafieldVal = extrafields[ex].value;	// get extra field value
			extrafieldpost += "&"+extrafieldName + "="+extrafieldVal;
			extrafieldVal = "";
		}
		else
		{
			if(extrafields[ex].id.search('ajax')!=-1)
			{
				var tmpName = extrafields[ex].id.split('ajax');
				var cal_fieldNamefrmId = "";
				cal_fieldNamefrmId = reverseString(tmpName[1]);
				cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
				
				extrafields[ex].id = cal_fieldNamefrmId;
			}
			

			extrafieldName = extrafields[ex].id ; 	// make Id as Name
			extrafieldVal = extrafields[ex].value;	// get extra field value
			extrafieldpost += "&"+extrafieldName + "="+extrafieldVal;			
		}
	}
	var cal_el = getElementsByClassName('calendar');

	var cal_fieldNamefrmId = "";
	for ( cal_i=0;cal_i<cal_el.length;cal_i++ ) 
	{
		// do stuff here with myEls[i]
		var calImgId = cal_el[cal_i].id;
		 
		arr =  calImgId.split("_img");
		n = arr.length;
		var calName = arr[0];

		if(calName!="" && calName.search(product_id))
		{
			if(document.getElementById(calName).value!="")
			{
				cal_fieldNamefrmId = reverseString(calName);
				cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
				extrafieldpost += "&"+cal_fieldNamefrmId + "=" +document.getElementById(calName).value;
			}
		}
	}
	// End
	var subscription_data= "";
	if(document.getElementById('hidden_subscription_id'+product_id)){
		
		subId = document.getElementById('hidden_subscription_id'+product_id).value;
		if(subId==0 || subId==""){
			alert("Please Select Your Subscription Plan");
			return false;
		}
		subscription_data = "&subscription_id="+subId;
	}
	if(document.getElementById('giftcard_id'))
	{
		id = "&giftcard_id="+product_id;
		
		if(document.getElementById('reciver_email'))
			id+= "&reciver_email="+document.getElementById('reciver_email').value;
		if(document.getElementById('reciver_name'))
			id+= "&reciver_name="+document.getElementById('reciver_name').value;
	} else {
		id = "&product_id="+product_id;
	}
		
	request=getHTTPObject();
	
	var params ="option=com_redshop&view=cart&task=add&tmpl=component&ajax_cart_box=1";
	params = params + "&Itemid="+frm.Itemid.value +	id;
	params = params + "&category_id="+frm.category_id.value;
	params = params + "&attribute_data="+frm.attribute_data.value;
	params = params + "&property_data="+frm.property_data.value;
	
	params = params + "&subproperty_data="+frm.subproperty_data.value;
	params = params + "&attribute_price="+frm.attribute_price.value;
	params = params + "&requiedAttribute="+frm.requiedAttribute.value;
	
	params = params + "&accessory_data="+frm.accessory_data.value;
	params = params + "&acc_attribute_data="+frm.acc_attribute_data.value;
	params = params + "&acc_property_data="+frm.acc_property_data.value;
	params = params + "&acc_subproperty_data="+frm.acc_subproperty_data.value;
	params = params + "&accessory_price="+frm.accessory_price.value;
	
	params = params + "&product_price="+frm.product_price.value;
	params = params + "&main_price="+frm.main_price.value;
	params = params + "&sel_wrapper_id="+frm.sel_wrapper_id.value;
	params = params + "&quantity=" + frm.quantity.value;
	
	if(document.getElementById('calc_height'))
	{
		params = params + "&calcHeight=" + frm.calcHeight.value;
	}
	if(document.getElementById('calc_width'))
	{
		params = params + "&calcWidth=" + frm.calcWidth.value;
	}
	if(document.getElementById('calc_depth'))
	{
		params = params + "&calcDepth=" + frm.calcDepth.value;
	}
	if(document.getElementById('calc_radius'))
	{
		params = params + "&calcRadius=" + frm.calcRadius.value;
	}
	if(document.getElementById('calc_unit'))
	{
		params = params + "&calcUnit=" + frm.calcUnit.value;
	}
	params = params + subscription_data + extrafieldpost;	
	var url = site_url+"index.php?"+params;
	
	if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
		request.open("POST", url, true);
	else
		request.open("POST", url, false);
	
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");
	var aj_flag = true;
	request.onreadystatechange = function() 
	{
		if(request.readyState == 4) 
		{
			var responce = request.responseText;
			
			responce = responce.split("`");
			
			if(responce[1]=="0")
			{
				alert(responce[2]); //alert last message
				return false;
			}
			else
			{
				if(document.attbox)
				{
					document.attbox.close();	
				}
			}
				
			// cart module						
			if(document.getElementById('mod_cart_empty_ajax'))			
				document.getElementById('mod_cart_empty_ajax').style.display = "none";
			
			if(document.getElementById('mod_cart_total_pro_ajax'))			
				document.getElementById('mod_cart_total_pro_ajax').style.display = "block";
			
			if(document.getElementById('mod_cart_total_txt_ajax') && responce[2])
				document.getElementById('mod_cart_total_txt_ajax').style.display = "block";			
			
			if(document.getElementById('mod_cart_total_pro_value_ajax') && responce[1])			
				document.getElementById('mod_cart_total_pro_value_ajax').innerHTML = responce[1];
			
			if(document.getElementById('mod_cart_total_value_ajax') && responce[2])
				document.getElementById('mod_cart_total_value_ajax').innerHTML = number_format(responce[2],PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
			
			// checkout button show/hide
			if(document.getElementById('mod_cart_checkout'))
				document.getElementById('mod_cart_checkout').style.display = "none";
			
			if(document.getElementById('mod_cart_checkout_ajax'))
				document.getElementById('mod_cart_checkout_ajax').style.display = "block";
			
			if(document.getElementById('mod_cart_products') && responce[3])
			{
				if(document.getElementById('mod_cart_total_txt_product'))
					document.getElementById('mod_cart_total_txt_product').style.display = "block";
				
				var products = responce[3].split("_#");
				var str_product = "";
				for(var p=0;p<products.length;p++)
				{					
					str_product += products[p] + "<br />";
				}
				document.getElementById('mod_cart_products').innerHTML = str_product;
				if(document.getElementById('mod_cart_total_pro_value_ajax') && responce[1])			
					document.getElementById('mod_cart_total_pro_value_ajax').innerHTML = products.length;
			}
			// End
			var newurl = site_url+"index.php?option=com_redshop&view=product&pid="+product_id+"&r_template=cartbox&tmpl=component";
			
			request_inner=getHTTPObject();
			request_inner.onreadystatechange = function()
			{
				if(request_inner.readyState == 4 && request_inner.status==200 && aj_flag) 
				{
					var responcebox = request_inner.responseText;
					aj_flag = false;
					document.ajaxbox = new MooPrompt( '' , responcebox  ,{
						buttons: 0,
						width:500,
						height:150,
						overlay: false,
						delay:3000,
						showCloseBtn: true,						
						effect: 'grow',
						boxId:'cartBox'
					});
				}
			}
			request_inner.open("GET", newurl, true);
			request_inner.send(null);
		}
	}
	
	request.send(params);
}


/************************Js Clean up code function end *********************************/

var  ind=0;
var ida = 0;

// to select all attribute including accessory  when selecting dropdown
var restempindex = 0;
var atmp=0;
// end

// sub attribute dropdown selection
var subtmp=0;
var final_price_f	=	0;

/*
 * function shows attribute listing 
 * if attribute is available
 */
function ajaxCartSave(str,natt,nacc,nextra){
	
	// int variables
	var proid = 0,attdata=0,setatt=1,qty=1,setacc=0;
	// get form
	var formname = document.getElementById(str);
	
	// ajax box for accessory to show in box depends on selection in detail page
	if(document.getElementById('accessory_show_ajax_box')){
		var accessory_show_ajax = document.getElementById('accessory_show_ajax_box');
		setacc= accessory_show_ajax.value;		
	}
		
	//if(str.split("_")[1])
//		proid =	str.split("_")[1];
	
	// getting attribute data	
	if(formname.attribute_data){
		// get attribute data
		attdata = formname.attribute_data.value;
		
		// split attributedata to count att
		var attdata = attdata.split(",");
		
		for(var a=0;a<attdata.length;a++){
			// set attribute to view or not			
			if(attdata[a] != 0 )
			{	
				setatt = 0;
				break;
			}
			else
				setatt = 1;
		}
	}
	
	// end
	
	// get multiple extra fields attributes
	var extrafields = document.getElementsByName('extrafields'+proid+'[]');
	
	// intialized Userfield Name( comma seprated ) 
	var extrafieldNames = "";
	var previousfieldName = "";
	var fieldNamefrmId = "";
	var chk_flag = false;
	var rdo_previousfieldName = "";
	var rdo_fieldNamefrmId = "";
	var rdo_flag = false;
	var imgfieldNamefrmId = "";
	var selmulti_fieldNamefrmId = "";
	
	for(var ex=0;ex<extrafields.length;ex++){
		
		if(!extrafields[ex].value && extrafields[ex].type=='text'){
			extrafieldNames += extrafields[ex].id ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}	
		}
		else if(!extrafields[ex].value && extrafields[ex].type=='select-one'){
			extrafieldNames += extrafields[ex].id ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}	
		}
		else if(!extrafields[ex].value && extrafields[ex].type=='hidden'){
			imgfieldNamefrmId = reverseString(extrafields[ex].id);
			imgfieldNamefrmId = reverseString(imgfieldNamefrmId.substr(imgfieldNamefrmId.indexOf("_")+1));
			extrafieldNames += imgfieldNamefrmId ; 	// make Id as Name
			if((extrafields.length-1) != ex){
				extrafieldNames += ',';
			}
		}
		else if(extrafields[ex].type=='checkbox')
		{	
			fieldNamefrmId = reverseString(extrafields[ex].id);
			fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
			
			if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && chk_flag==false)
			{
				extrafieldNames += previousfieldName+",";
			}
			
			if(previousfieldName != fieldNamefrmId)
			{	
				previousfieldName = fieldNamefrmId;
				chk_flag = false;

			}
			if(extrafields[ex].checked || chk_flag== true)
			{	chk_flag = true;
				continue; }
			if((ex == (extrafields.length-1) && chk_flag==false) || (extrafields[ex+1].type!='checkbox' && chk_flag==false)){
				extrafieldNames += previousfieldName+",";
			}
			
		}
		else if(extrafields[ex].type=='radio')
		{	
			
			rdo_fieldNamefrmId = reverseString(extrafields[ex].id);
			rdo_fieldNamefrmId = reverseString(rdo_fieldNamefrmId.substr(rdo_fieldNamefrmId.indexOf("_")+1));
			
			if(rdo_previousfieldName != "" && rdo_previousfieldName!=rdo_fieldNamefrmId && rdo_flag==false)
			{
				extrafieldNames += rdo_previousfieldName+",";
			}
			
			if(rdo_previousfieldName != rdo_fieldNamefrmId)
			{	
				rdo_previousfieldName = rdo_fieldNamefrmId;
				rdo_flag = false;
			}
			if(extrafields[ex].checked || rdo_flag== true)
			{	
				rdo_flag = true;
				continue; }
			else if((ex == (extrafields.length-1) && rdo_flag==false) || (extrafields[ex+1].type!='radio' && rdo_flag==false)){
				extrafieldNames += rdo_previousfieldName+",";
			}	
		}
		else if(extrafields[ex].type=='select-multiple')
		{	
			
			selmulti_fieldNamefrmId = reverseString(extrafields[ex].id);
			selmulti_fieldNamefrmId = reverseString(selmulti_fieldNamefrmId.substr(selmulti_fieldNamefrmId.indexOf("_")+1));
			
			if(extrafields[ex].value)
				{	
					continue; }
				else{
					extrafieldNames += selmulti_fieldNamefrmId+",";
				}	
		}
		
			
	}
	/* for calender type
	 * user field
	 */
	
	var cal_el = getElementsByClassName('calendar');

	var cal_fieldNamefrmId = "";
	for ( cal_i=0;cal_i<cal_el.length;cal_i++ ) {
		// do stuff here with myEls[i]
		 var calImgId = cal_el[cal_i].id;
		 
		 arr =  calImgId.split("_img");
		 n = arr.length;
		 var calName = arr[0];

		if(calName!="")
		{
		 if(document.getElementById(calName).value=="")
		 {
			cal_fieldNamefrmId = reverseString(calName);
			cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
			extrafieldNames += ","+cal_fieldNamefrmId+",";
		 }
		}
	}
	// End

	//if((setatt == 0  || natt == 0 ) && (setacc == 0 || nacc == 0 )&& (extrafieldNames == "" || nextra == 0)){
//		
//		submitCart(str);
//		return;
//	}
	
	/*if(formname.product_id)
		proid = formname.product_id.value;*/
	var subscription_data= "";
	if(document.getElementById('hidden_subscription_id')){
		
		subId = document.getElementById('hidden_subscription_id').value;
		if(subId==0 || subId==""){
			alert("Please Select Your Subscription Plan");
			return false;
		}
		subscription_data = "&subscription_id="+subId;
	}	
		
	http=getHTTPObject();
		
	if (http==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url = site_url + "index.php";	
	var params = "option=com_redshop&view=product&pid="+ proid +"&attribute=1&viewatt="+setatt+"&viewacc="+setacc+"&tmpl=component&nextrafield="+nextra+"&extrafieldNames="+extrafieldNames+subscription_data;
	alert(url);
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		
		if(http.readyState == 4 && http.status == 200) {
			
			var responce = http.responseText;
			
			
			
			var tmpresponce = responce;
			
			var tmpuserfield = responce;
						
			var att_form_addcart_ajax = tmpresponce.slice(tmpresponce.indexOf("<span id='attribute_ajax_addtocart_form_span'>"),tmpresponce.indexOf("<span id='cart_ajax_form'></span></span>"));
					
			var user_field_data_ajax = tmpuserfield.slice(tmpuserfield.indexOf("<span id='product_userfield_addtocart_start'>"),tmpuserfield.indexOf("<span id='product_userfield_addtocart_end'></span></span>"));
					
			
			var att_data_ajax = responce.slice(responce.indexOf("<span id='attribute_ajax_span'>"),responce.indexOf("<span id='cart_attribute_box'></span></span>"));
					
			
			var att_final_ajax = user_field_data_ajax + att_data_ajax + "<br/>"+ att_form_addcart_ajax  ;  	
			
			document.attbox = new MooPrompt('', responce ,{
				buttons: 0,				
				width:500,
				height:600,	
				vertical: 'middle', 
				horizontal: 'center', 
				overlay: true,
				showCloseBtn: true,
				
				effect: 'grow'
					
					
			});
	
			var el = document.getElementsByClassName('calendar');
				
			for ( i=0;i<el.length;i++ ) {
				// do stuff here with myEls[i]
				 var calImgId = el[i].id;
				 arr =  calImgId.split("_img");
				 n = arr.length;
				 var calName = arr[0];
				 var realname = calName.split("ajax");
				  
				 if((calImgId.search('ajax')!=-1) && (extrafieldNames.search(realname[0]) !=-1) )
				 {
					 window.addEvent('domready', function() {Calendar.setup({
				         inputField     :    calName,     // id of the input field
				         ifFormat       :    "%d-%m-%Y",      // format of the input field
	
				         button         :    el[i].id,  // trigger for the calendar (button ID)
				        align          :    "Tl",           // alignment (defaults to "Bl")
				        singleClick    :    true
				    });});
				 }
				}
		}
	}
	http.send(params);	
}

/*
 * function submit attribute using ajax pop-up
 */
function submitCart(str)
{	
	var formname = document.getElementById(str);
		
	var proid = 0;
	var priceval = 0;
	var mainpri = 0;
	var proppri = 0;
	var attpric = 0;
	var accpric = 0;
	var propcartid = 0;
	var subpropcartid = 0;
	var wrapperdata = "";
	var accdata = "";
	var attdata = "";
	var subattdata =  "";
	var propid = 0;
	var qty = 1;
	var id = '';
	var set=false;
	// calculator variables
	var calHeight=0,calWidth=0,calDepth=0,calRadius=0,calUnit='cm';
	
	/*if(formname.product_id)
		proid = formname.product_id.value;*/
	
	if(str.split("_")[1])
		proid =	str.split("_")[1];
	//var formname = document.getElementById("addtocartscroll"+str);
	
	// extra fields value getting
	
	// get multiple extra fields attributes
	var extrafields = document.getElementsByName('extrafields'+proid+'[]');
	
	// intialize defaults
	var extrafieldName = "";
	var extrafieldVal = "";
	var extrafieldpost = "";

	var previousfieldName = "";
	var fieldNamefrmId = "";
	var chk_flag = false;
	var rdo_previousfieldName = "";
	var rdo_fieldNamefrmId = "";
	var rdo_flag = false;
	
	var selmulti_fieldNamefrmId = "";
	
	for(var ex=0;ex<extrafields.length;ex++){
		
		if(extrafields[ex].type=='checkbox')
		{
			fieldNamefrmId = reverseString(extrafields[ex].id);
			fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
			if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && extrafieldVal!="")
			{
				extrafieldpost += "&"+previousfieldName + "="+extrafieldVal;
			}
			if(previousfieldName != fieldNamefrmId)
			{	
				extrafieldVal = "";
				previousfieldName = fieldNamefrmId;
			}
			if(extrafields[ex].checked)
			{	
				if(extrafieldVal!="")
					extrafieldVal += ",";
				extrafieldVal += extrafields[ex].value; 
			}
			if(ex == (extrafields.length-1) && extrafieldVal!=""){
				extrafieldpost += "&"+fieldNamefrmId + "="+extrafieldVal;
			}
			if(ex<(extrafields.length-1))
			{
				if((extrafields[ex+1].type != 'checkbox') && extrafieldVal != "")
					extrafieldpost += "&"+fieldNamefrmId + "="+extrafieldVal;	
			}
		}
		else if(extrafields[ex].type=='radio')
		{	
			
			rdo_fieldNamefrmId = reverseString(extrafields[ex].id);
			rdo_fieldNamefrmId = reverseString(rdo_fieldNamefrmId.substr(rdo_fieldNamefrmId.indexOf("_")+1));
			
			if(rdo_previousfieldName != "" && rdo_previousfieldName!=rdo_fieldNamefrmId && rdo_flag==false)
			{
				extrafieldpost += "&"+rdo_previousfieldName + "="+extrafieldVal;
			}
			
			if(rdo_previousfieldName != rdo_fieldNamefrmId)
			{	
				extrafieldVal= "";
				rdo_previousfieldName = rdo_fieldNamefrmId;
				rdo_flag = false;
				if(extrafields[ex].checked || rdo_flag== true)
				{	
					rdo_flag = true;
					extrafieldpost += "&"+rdo_previousfieldName + "="+extrafields[ex].value;
					continue; }
			}
			else
			{
				if(extrafields[ex].checked || rdo_flag== true)
				{	
					rdo_flag = true;
					extrafieldpost += "&"+rdo_fieldNamefrmId + "="+extrafields[ex].value;
					continue; }
			}	
		}
		else if(extrafields[ex].type=='select-multiple')
		{	
			var ob = extrafields[ex];
			extrafieldVal = "";
			selmulti_fieldNamefrmId = reverseString(extrafields[ex].id);
			selmulti_fieldNamefrmId = reverseString(selmulti_fieldNamefrmId.substr(selmulti_fieldNamefrmId.indexOf("_")+1));
			for (var t = 0; t < ob.options.length; t++)
			{
				if (ob.options[ t ].selected)
				{
					var strval = extrafieldVal;
					if(strval.search(String (ob.options[ t ].value))==-1)
					{
						if(extrafieldVal!="")
							extrafieldVal += ",";
						extrafieldVal += (String (ob.options[ t ].value));
					}
				}
			}
			
			if(extrafieldVal)
			{	
				extrafieldpost += "&"+selmulti_fieldNamefrmId + "="+extrafieldVal;
			}	
		}else if(extrafields[ex].type=='hidden'){
			imgfieldNamefrmId = reverseString(extrafields[ex].id);
			imgfieldNamefrmId = reverseString(imgfieldNamefrmId.substr(imgfieldNamefrmId.indexOf("_")+1));
			
			extrafieldName = imgfieldNamefrmId ; 	// make Id as Name
			extrafieldVal = extrafields[ex].value;	// get extra field value
			extrafieldpost += "&"+extrafieldName + "="+extrafieldVal;
			extrafieldVal = "";
		}
		else
		{
			if(extrafields[ex].id.search('ajax')!=-1)
			{
				var tmpName = extrafields[ex].id.split('ajax');
				var cal_fieldNamefrmId = "";
				cal_fieldNamefrmId = reverseString(tmpName[1]);
				cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));
				
				extrafields[ex].id = cal_fieldNamefrmId;
			}
			

			extrafieldName = extrafields[ex].id ; 	// make Id as Name
			extrafieldVal = extrafields[ex].value;	// get extra field value
			extrafieldpost += "&"+extrafieldName + "="+extrafieldVal;			
		}
	}
		var cal_el = getElementsByClassName('calendar');

				var cal_fieldNamefrmId = "";
				for ( cal_i=0;cal_i<cal_el.length;cal_i++ ) {
					// do stuff here with myEls[i]
					 var calImgId = cal_el[cal_i].id;
					 
					 arr =  calImgId.split("_img");
					 n = arr.length;
					 var calName = arr[0];

					if(calName!="" && calName.search(proid))
					{
					 if(document.getElementById(calName).value!="")
					 {
						cal_fieldNamefrmId = reverseString(calName);
						cal_fieldNamefrmId = reverseString(cal_fieldNamefrmId.substr(cal_fieldNamefrmId.indexOf("_")+1));

						extrafieldpost += "&"+cal_fieldNamefrmId + "=" +document.getElementById(calName).value;
					 }
					}
				}
	// End

	/*if(document.getElementById('quantity'+proid))
		qty = document.getElementById('quantity'+proid).value;*/
	
	if(document.getElementById('giftcard_id')){
		id = "&giftcard_id="+proid;
		
		 /* giftcart reciver information (email,name)*/
		
		if(document.getElementById('reciver_email'))
			id+= "&reciver_email="+document.getElementById('reciver_email').value;
		if(document.getElementById('reciver_name'))
			id+= "&reciver_name="+document.getElementById('reciver_name').value;
		
	}else{
		id = "&product_id="+proid;
	}
	
	// get quantity
	for(var g=0;g<formname.elements.length;g++){
		
		if(formname.elements[g].name == 'quantity')
			qty = formname.elements[g].value;
	}

	var eld = document.getElementsByName('quantity');
	for(var g=0;g<eld.length;g++){
		
		if(eld[g].id == 'ajax_quantity'+proid){
			 
			qty = eld[g].value; 
		}
	}
	// end
	
	if(formname.product_price)
		priceval = formname.product_price.value;
	
	if(formname.main_price)
		mainpri = formname.main_price.value;
	
	if(formname.property_price)
		proppri = formname.property_price.value;
	
	if(formname.attribute_price)
		attpric = formname.attribute_price.value;
	
	if(formname.accessory_price)
		accpric = formname.accessory_price.value;
	
	if(formname.sel_wrapper_id)
		wrapperdata = "&sel_wrapper_id=" +formname.sel_wrapper_id.value;
	
	if(formname.property_id_cart)
		propcartid = formname.property_id_cart.value;
	
	if(formname.subproperty_id_cart)
		subpropcartid = formname.subproperty_id_cart.value;
	
	if(formname.accessory_data)
		accdata = formname.accessory_data.value;
	
	if(formname.attribute_data)
		attdata = formname.attribute_data.value;
	
	if(formname.subattribute_data)
		subattdata = formname.subattribute_data.value;

	if(formname.property_id)
		propid = formname.property_id.value;
	
	/*
	 * discount calculator
	 */
	if(document.getElementById('calc_height')){
		calHeight = document.getElementById('calc_height').value;
		
		if(calHeight==""){
			alert("Please Insert Height");
			return false;
		}else{
			formname.calcHeight.value = calHeight;
		}
			
	}
	
	if(document.getElementById('calc_width')){
		var calWidth = document.getElementById('calc_width').value;
		if(calWidth==""){
			alert("Please Insert Width");
			return false;
		}else{
			formname.calcWidth.value = calWidth;
		}
	}
	
	if(document.getElementById('calc_depth')){
		var calDepth = document.getElementById('calc_depth').value;
		if(calDepth==""){
			alert("Please Insert Depth");
			return false;
		}else{
			formname.calcDepth.value = calDepth;	
		}
	}
	
	if(document.getElementById('calc_radius')){
		var calRadius = document.getElementById('calc_radius').value;
		if(calRadius==""){
			alert("Please Insert Radius");
			return false;
		}else{
			formname.calcRadius.value = calRadius;
		}
	}
	
	if(document.getElementById('discount_calc_unit')){
		calUnit = document.getElementById('discount_calc_unit').value;
		if(calUnit==0){
			alert("Please Insert Unit");
			return false;
		}else{
			formname.calcUnit.value = calUnit;
		}
	}
	var subscription_data = "";
	if(document.getElementById('hidden_subscription_id')){
		subId = document.getElementById('hidden_subscription_id').value;
		if(subId==0 || subId==""){
			alert("Please Select Your Subscription Plan");
			return false;
		}else{
			formname.subscription_id.value = subId;
		}
		subscription_data = "&subscription_id="+subId;
	}
	// End
	
	http=getHTTPObject();
	
	if (http==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url = site_url+"index.php";
	var params = "option=com_redshop&view=cart&task=add&" +
				"ajax_cart_box=1"+
				id+
				"&product_price="+priceval+
				"&quantity=" + qty +
				"&main_price= " + mainpri +
				"&property_price= " + proppri +
				"&attribute_price= " + attpric + 
				"&accessory_price= " + accpric +
				"&property_id_cart= " + propcartid +
				"&subproperty_id_cart= " + subpropcartid +
				"&accessory_data= " + accdata +
				"&attribute_data= " + encodeURIComponent(attdata) +
				wrapperdata+
				"&property_id= " + propid +
				"&subattribute_data= " + encodeURIComponent(subattdata) +
				"&calcHeight= " + calHeight +
				"&calcWidth= " + calWidth +
				"&calcDepth= " + calDepth +
				"&calcRadius= " + calRadius +
				"&calcUnit= " + calUnit +
				subscription_data+
				extrafieldpost;
		
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");	
	http.send(params);
	
	http.onreadystatechange = function() {	//Call a function when the state changes.
		if(http.readyState == 4 ) {
					
			var responce = http.responseText;
			
			// split responce to get variables
			responce = responce.split("`");
			if(responce[1]=="0")
			{
				alert(responce[2]); //alert last message
				return false;
			}
			else
			{
				if(document.attbox)
					document.attbox.close();	
			}
				
			// cart module						
			if(document.getElementById('mod_cart_empty_ajax'))			
				document.getElementById('mod_cart_empty_ajax').style.display = "none";
			
			if(document.getElementById('mod_cart_total_pro_ajax'))			
				document.getElementById('mod_cart_total_pro_ajax').style.display = "block";
			
			if(document.getElementById('mod_cart_total_txt_ajax') && responce[2])
				document.getElementById('mod_cart_total_txt_ajax').style.display = "block";			
			
			if(document.getElementById('mod_cart_total_pro_value_ajax') && responce[1])			
				document.getElementById('mod_cart_total_pro_value_ajax').innerHTML = responce[1];
			
			if(document.getElementById('mod_cart_total_value_ajax') && responce[2])
				document.getElementById('mod_cart_total_value_ajax').innerHTML = number_format(responce[2],PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
			
			// checkout button show/hide
			if(document.getElementById('mod_cart_checkout'))
				document.getElementById('mod_cart_checkout').style.display = "none";
			
			if(document.getElementById('mod_cart_checkout_ajax'))
				document.getElementById('mod_cart_checkout_ajax').style.display = "block";
			
			if(document.getElementById('mod_cart_products') && responce[3])
			{
				if(document.getElementById('mod_cart_total_txt_product'))
					document.getElementById('mod_cart_total_txt_product').style.display = "block";
				
				var products = responce[3].split("_#");
				var str_product = "";
				for(var p=0;p<products.length;p++)
				{					
					str_product += products[p] + "<br />";
				}
				document.getElementById('mod_cart_products').innerHTML = str_product;
				if(document.getElementById('mod_cart_total_pro_value_ajax') && responce[1])			
					document.getElementById('mod_cart_total_pro_value_ajax').innerHTML = products.length;
			}
			// End
			
			http.open("GET", site_url+"index.php?option=com_redshop&view=product&pid="+proid+"&template=cartbox&tmpl=component", true);
			http.send(null);
			
			http.onreadystatechange = function(){
				if(http.readyState == 4 ) {
					var responcebox = http.responseText;
					
					document.ajaxbox = new MooPrompt( '' , responcebox  ,{
						buttons: 0,
						width:500,
						height:150,
						overlay: false,
						delay:3000
							
					});
				}
				
			}
		}
	}
			
}


function att_subatt_obj()
{
	this.arr_attr_id = new Array();
	this.arr_subattr_id = new Array();	
}

function getSelectedAttribute(obj,productid)
{
	// Attribute data collect start 
	var arr_attr_id =  new Array();
	var arr_subattr_id = new Array();
	var sel_i=0;
	var sub_sel_i=0;
	
	if(document.getElementById('attribute_set_id')){	
		if(document.getElementById('attribute_set_id').value > 0)
		{	
			attributeid = document.getElementById('attribute_set_id').value;
		
			attr_type = document.getElementsByName(attributeid+"attribute_id[]").type;
			
			if(document.getElementsByName(attributeid+"attribute_id[]"))
			{
				dcatt=document.getElementsByName(attributeid+"attribute_id[]");
	
				var total_attribute=(document.getElementsByName(attributeid+"attribute_id[]").length);
	
				for(j=0;j<total_attribute;j++)
				{
					
					arr_attr_id[sel_i++]= dcatt[j].value;
					
					if(document.getElementsByName("subatt_image["+j+"]"))
					{
						dcsubatt=document.getElementsByName("subatt_image["+j+"]");
						var total_subattribute=(document.getElementsByName("subatt_image["+j+"]").length);
										
						for(k=0;k<total_subattribute;k++)
						{				
							arr_subattr_id[sub_sel_i++] =dcsubatt[k].value;
					
						}
					}
								
				}
			}
		
		}
			
	}
	
	if(document.getElementsByName(productid+"attribute_id[]"))
	{	
		dcatt=document.getElementsByName(productid+"attribute_id[]");
		var total_attribute=(document.getElementsByName(productid+"attribute_id[]").length);
		
		for(j=0;j<total_attribute;j++)
		{
			attr_type =dcatt[j].type;
			
			if(attr_type=='checkbox')
			{
				if(dcatt[j].checked)
				{
					arr_attr_id[sel_i++] = dcatt[j].value;
				}
			}
			else
			{
				for(var mul_attr=0;mul_attr<dcatt[j].options.length;mul_attr++)
				{
					if(dcatt[j].options[mul_attr].selected)
						arr_attr_id[sel_i++] = dcatt[j].options[mul_attr].value;
				}	
			}
			
			if(document.getElementsByName("subatt_image["+j+"]"))
			{
					
				dcsubatt=document.getElementsByName("subatt_image["+j+"]");
				var total_subattribute=(document.getElementsByName("subatt_image["+j+"]").length);
				
				for(k=0;k<total_subattribute;k++)
				{	
					subattr_type =dcsubatt[k].type;
					
					if(subattr_type=='checkbox')
					{
						if(dcsubatt[k].checked)
						{
							arr_subattr_id[sub_sel_i++] = dcsubatt[k].value;
						}
					}
					else
					{
						for(var mul_attr=0;mul_attr<dcsubatt[k].options.length;mul_attr++)
						{
							if(dcsubatt[k].options[mul_attr].selected)
								arr_subattr_id[sub_sel_i++] = dcsubatt[k].options[mul_attr].value;
						}	
					}
				}
			}
			
			// End			
		}
	}
	// Attribute data collect end  
	//update object variable value
	obj.arr_attr_id = arr_attr_id;
	obj.arr_subattr_id = arr_subattr_id;
}

/***********************delete *************************/

