function cart_submit(fid,isatt,natt,nextra,nacc)
{
	var prop_id_cart = "",proid=0;
	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;

	if(fid.split("_")[1])
		proid =	fid.split("_")[1];
	
	if(document.getElementById('attribute_set_id')){
		if(document.getElementById('attribute_set_id').value > 0 )
			proid = document.getElementById('attribute_set_id').value; 
	}
		
	// User field validation
	var ret = userfieldValidation("extrafields"+proid);
	if(!ret)
	{
		return false;
	}
	// Attribute data collect start
	if(document.getElementsByName(proid+"attribute_id[]"))
	{
		
		dcatt=document.getElementsByName(proid+"attribute_id[]");
				
		var total_attribute=(document.getElementsByName(proid+"attribute_id[]").length);
		var att_chk_flag = true;
		var subatt_chk_flag = true;
		var att_chk_value = "";
		var att_chk_pre_value = "";
		var att_chk_pre_name = "";
		var att_chk_pre_lebl = "";
		var att_prev_att_required = "";
		var subatt_chk_value = "";
		var subatt_chk_pre_value = "";
		var subatt_chk_value = "";
		var subatt_chk_pre_value = "";
		var subatt_chk_pre_name = "";
		var subatt_chk_pre_lebl = "";
		
		for(j=0;j<total_attribute;j++)
		{
			att_required = dcatt[j].getAttribute('required');
			att_name = unescape(dcatt[j].getAttribute('attribute_name'));
			if(document.getElementById('att_lebl'))
				att_name_lebl = document.getElementById('att_lebl').innerHTML;
			att_type = dcatt[j].type;
			if(att_type=='checkbox')
			{
				att_chk_value = dcatt[j].value.split(":");
				
				if(att_chk_pre_value == "")
				{
					att_chk_pre_value = att_chk_value[4];
					att_chk_pre_name = att_name;
					att_chk_pre_lebl = att_name_lebl;
					att_prev_att_required = att_required;
				}
				if((att_chk_pre_value !="" && att_chk_pre_value != att_chk_value[4] && att_chk_flag))
				{
					if(att_prev_att_required == "1")
					{
						att_error += att_chk_pre_lebl + " " + att_chk_pre_name +"\n";
						att_error_alert = true;
					}
					att_chk_flag = true;
					att_chk_pre_value = att_chk_value[4];
					att_chk_pre_name = att_name;
					att_chk_pre_lebl = att_name_lebl;
					att_prev_att_required = att_required;
				}
				if(att_chk_pre_value != att_chk_value[4])
				{
					att_chk_flag = true;
					att_chk_pre_value = att_chk_value[4];
					att_chk_pre_name = att_name;
					att_chk_pre_lebl = att_name_lebl;
				}
				if(att_chk_pre_value == att_chk_value[4] && dcatt[j].checked)
				{
					arr_attr_id[sel_i++] = dcatt[j].value;
					att_chk_flag = false;
				}
				if(att_chk_pre_value == att_chk_value[4] && !dcatt[j].checked && att_chk_flag)
				{
					att_chk_flag = true;
				}
				if(att_chk_pre_value == att_chk_value[4] && !dcatt[j].checked && att_chk_flag && (j+1)== total_attribute)
				{
					if(att_prev_att_required == "1")
					{
						att_error += att_chk_pre_lebl + " " + att_chk_pre_name +"\n";
						att_error_alert = true;
					}
					att_chk_flag = true;
				}
				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++)
					{
						if(dcsubatt[k].checked)
						{
							arr_subattr_id[sub_sel_i++] = dcsubatt[k].value;
						}
					}
				}
			}
			else
			{
				if(att_required == 1 && dcatt[j].value == 0 ){
					att_error += att_name_lebl + " " + att_name +"\n";
					att_error_alert = true;				
				}
		
				// setting property id
				prop_id_cart_value = dcatt[j].value.split(":");			
	
				if(prop_id_cart_value[4]){
					
					if(j>0)
						prop_id_cart += ",";				
									
					prop_id_cart += prop_id_cart_value[4];							
				}
				// End
				
				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;
				}			
				//  sub attribute Price managment
				
				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++)
					{
						// check for required attribute
						if(att_required == 1 && dcsubatt[k].value == 0 ){
											
							if(!att_error_alert)
								att_error += att_name_lebl + " " + prop_id_cart_value[1] +"\n";
							
							att_error_alert = true;				
						}
						arr_subattr_id[sub_sel_i++]=dcsubatt[k].value;
						
						subprop_id_cart_value = dcsubatt[k].value.split(":");
						
						if(subprop_id_cart_value[6]){
							
							if(j>0)
								subprop_id_cart += ",";
							
							subprop_id_cart += subprop_id_cart_value[6];							
						}
						// End
					}				
				}			
				// End			
			}
		}	
		attr_id = arr_attr_id.join(",");
		subattr_id = arr_subattr_id.join(",");
		var formname = document.getElementById(fid);
		
		formname.attribute_data.value=attr_id;
		
		formname.subattribute_data.value=subattr_id;
		
	}
	
	if(document.getElementById('calc_height')){
		var 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;
		}
	}
	if(document.getElementById('hidden_subscription_id')){
		subId = document.getElementById('hidden_subscription_id').value;
		if(subId==0){
			alert("Please Select Your Subscription Plan");
			return false;
		}else{
			formname.subscription_id.value = subId;
		}
	}
	
	// Attribute data collect end 
	
	
	
	// accessory data collect
	var acc_return = collectAccessory(proid);//accessory_datacollect(fid);
	
	if(isNaN(acc_return) == true){
		att_error +=acc_return[0];		
	}
	
	if(att_error_alert == true || isNaN(acc_return) == true){
		alert(att_error);
		return false;
	}
	/* 
	 * count total attribute + extra fields
	 * Where natt = number of total attribute
	 * And nextra = number of extra fields 
	 */
	
	var ntotal = parseInt(natt) + parseInt(nextra) + parseInt(nacc); 
	
	// submit form from product detail page
	if(AJAX_CART_BOX == 0){
		document.getElementById(fid).submit();
	}else{
		
		// if attribute set
		if(isatt){						 
			submitCart(fid);
		}else{
			
			/* 
			 * ntotal = count total attribute + extra fields 
			 * if attribute is not available then cat will submit directly
			 * 
			 */ 
			if(ntotal>0)
				ajaxCartSave(fid,natt,nacc,nextra);
			else
				submitCart(fid);
			
		}
	}
}

/*
 *	Related Product attribute data collection
 * 
 */

/*function relatedProductAttribute(relid,selindex){
	
	var tmpprice = 0,final_price=0,rel_att_total=0,rel_subatt_id,attribute_price=0,att_data="",sub_att_data="",set_price=false;
	var attribute_name = "",property_name = "",oprand = "",property_price = 0,attribute_id = 0,property_id = 0;
	var form_name="";
	var rel_att_id="related_attributerel"+selindex;
	
	rel_att_total = document.getElementById('relate_Product_att_total'+relid).value;
	
	for(var i=0;i<rel_att_total;i++){
		
		rel_att_id="related_attributerel"+relid+i;
		
		if(document.getElementById(rel_att_id)){
			
			var rel_att_box = document.getElementById(rel_att_id);
			
			var rel_att_value = rel_att_box.value; 
			
			// attribute data collect
			att_data += rel_att_value;
			
			tmp=rel_att_total-1;
			
			if(i!=tmp)
				att_data+=",";
			
			// end
			
			// a.attribute_name:ap.property_name:ap.oprand:ap.property_price:$relid:a.attribute_id:ap.property_id
			var rel_att_split = rel_att_value.split(":");
			
			attribute_name = rel_att_split[0];
			property_name = rel_att_split[1];
			oprand = rel_att_split[2];
			property_price = rel_att_split[3];
			attribute_id = rel_att_split[5];
			
			var mainproperty_id =0;
			if(rel_att_split[6])
				mainproperty_id = rel_att_split[6];
			
						
			if(oprand=="-"){
				attribute_price -= parseFloat(property_price);
			}else  if(oprand=="+"){
	      		attribute_price += parseFloat(property_price);
			}else if(oprand=="="){
	      		attribute_price = parseFloat(property_price);	      					      			
				set_price = true;
				break;
	      	}
			
			subattribute_price=0;
			
			rel_subatt_id="subatt_imagesub"+relid+i;
			
			if(document.getElementById(rel_subatt_id)){
				var rel_subatt_box = document.getElementById(rel_subatt_id);
				
				var rel_subatt_value = rel_subatt_box.value; 
				
				// sub attribute data collect
				sub_att_data += rel_subatt_value;				
				if(i!=tmp)						
					sub_att_data+=",";
				// end
				
				// property_name(1):subattribute_color_name(2):oprand(3):subattribute_color_price(4):$relid(5):$attrid(6):property_id(7):subattribute_color_id(8)
				var rel_subatt_split = rel_subatt_value.split(":");
				
				property_name = rel_subatt_split[0];
				subproperty_name = rel_subatt_split[1];
				suboprand = rel_subatt_split[2];
				subproperty_price = rel_subatt_split[3];
				var property_id =0;
				if(rel_subatt_split[6])
					property_id = rel_subatt_split[6];
				
				subproperty_id = rel_subatt_split[7];				
				
				
				if(suboprand=="-"){
					subattribute_price -= parseFloat(subproperty_price);
				}else  if(suboprand=="+"){
					subattribute_price += parseFloat(subproperty_price);
				}else if(suboprand=="="){
					if(mainproperty_id != 0 && property_id >0){
						attribute_price = parseFloat(subproperty_price);      					      			
						set_price = true;					
							break;
					}
		      	}			
				
			}
			
			
		}
		
		if(mainproperty_id != 0 && property_id >0 && set_price == false)
			attribute_price += subattribute_price;
		 
			
	}
	
	var form_id = 'addtocart_'+relid;
		
	if(document.getElementById(form_id)){
		
		form_name = document.getElementById(form_id);
		
		if(form_name.attribute_data){
			form_name.attribute_data.value = att_data;
		}
	
		if(form_name.subattribute_data){
			form_name.subattribute_data.value = sub_att_data;
		}
		
	}
	
	
	if(document.getElementById('relateProductTempPrice'+relid))
		tmpprice = document.getElementById('relateProductTempPrice'+relid).value;
	
	if(set_price == true)
		final_price = parseFloat(attribute_price);
	else
		final_price = parseFloat(tmpprice) + parseFloat(attribute_price);
	
	final_price = number_format(final_price,PRICE_DECIMAL,PRICE_SEPERATOR,THOUSAND_SEPERATOR);
	
	
	if(document.getElementById('related_product_final_price'+relid))
		document.getElementById('related_product_final_price'+relid).innerHTML = final_price; 
}*/

// End

/*
 * related product submit cart button
 */

/*function submit_related_product(relid,natt){
	
	var sub_att_data="",att_data="";
	var formid = "addtocart_"+relid;
	var msg = document.getElementById('att_lebl').innerHTML;
	if(document.getElementById(formid)){
		
		form_name = document.getElementById(formid);
		
		if(form_name.attribute_data){
			att_data = form_name.attribute_data.value;
		}
	
		if(form_name.subattribute_data){
			sub_att_data = form_name.subattribute_data.value;
		}
		
		if(att_data == 0 && natt > 0){
			alert(msg);
			return false;
		}else{			
			document.getElementById(formid).submit();
		}
	}
	
	
}*/


function validateInputNumber(objid)
{
	if(document.getElementById(objid) && (trim(document.getElementById(objid).value)=="" || isNaN(document.getElementById(objid).value)))
	{
		alert(ENTER_NUMBER);
		document.getElementById(objid).value = 1;
		return false;
	}
	return true;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function userfieldValidation(extrafieldname)
{
	/***************************************
	 * validation
	 * for 
	 * required 
	 * custom userfield 
	 ***************************************/
	if(document.getElementsByName(extrafieldname+'[]'))
	{	
		var extrafields = document.getElementsByName(extrafieldname+'[]');
		
		var extrafields_val = extrafields.value;
		
		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++){
			
			
				//alert(extrafields[ex].getAttribute('required'));
				
				extrafields_req = extrafields[ex].getAttribute('required');
				if(extrafields_req==1){
					if(extrafields[ex].type=='checkbox')
					{	
						fieldNamefrmId = reverseString(extrafields[ex].id);
						fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
						if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && chk_flag==false)
						{
							alert(extrafields[ex-1].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
							return false;
						}
						
						if(previousfieldName != fieldNamefrmId)
						{	extrafieldVal = "";
							previousfieldName = fieldNamefrmId;
						}
						
						if(extrafields[ex].checked)
						{	
							chk_flag = true;
							continue; 
						}
						if((ex == (extrafields.length-1) && chk_flag==false) || (extrafields[ex+1].type!='checkbox') && chk_flag==false ){
							alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
							return false;
						}	
					}
					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)
						{
							alert(extrafields[ex-1].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
							return false;
						}
						
						if(rdo_previousfieldName != rdo_fieldNamefrmId)
						{	
							extrafieldVal= "";
							rdo_previousfieldName = rdo_fieldNamefrmId;
							rdo_flag = false;
							if(extrafields[ex].checked)
							{	
								rdo_flag = true;
								continue; 
							}
						}
						else
						{
							if(extrafields[ex].checked || rdo_flag== true)
							{	
								rdo_flag = true;
								continue; 
							}
							if((ex == (extrafields.length-1) && rdo_flag==false) || (extrafields[ex+1].type!='radio') && rdo_flag==false ){
								alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
								return false;
							}
						}	
					}
					else
					{
						extrafields_val = extrafields[ex].value;
						if(!extrafields_val)
						{	alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
							return false;
						}
					}
				}	
		}
		
	}
	return true;
	/********************
	 *       End
	 ********************/
}
/*function getProductUserfield(objname,acclen)
{
	var Aarr = new Array();
	
	for(p=0,k=0;p<acclen;p++)
	{
		if(objname[p].checked)
		{
			Aarr[k++] = objname[p].value;
		}
	}
	
	return Aarr.join(",");
}*/
function reverseString(string)
{
	var splitext = string.split("");
	var revertext = splitext.reverse();
	var reversed = revertext.join("");
	return reversed;
}
// End

/******************************
 * get coupon or voucher
 * price
 * using ajax
 ******************************/

/*function Getgiftcodeprice()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var giftcode = '';
	giftcode = document.getElementById('coupon_input').value;
	var task = '';
	if(giftcode == '')
		return false;
	else{
		
		coupon_code = document.getElementById('coupon_code').checked;
		voucher_code = document.getElementById('voucher_code').checked;
		if(voucher_code==true)
			task = "vouchercode";
		if(coupon_code==true)
			task = "couponcode";
		
		var url= site_url+'index2.php?option=com_redshop&view=cart&task='+task+'&discount_code='+giftcode;
				
		
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	return true;
}

function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		res = xmlhttp.responseText.split('`');
		
		document.getElementById("giftcode_price").value = res[1];//res[1];
		coupon_code = document.getElementById('coupon_code').checked;
		voucher_code = document.getElementById('voucher_code').checked;
		if(voucher_code==true)
			task = "voucher";
		if(coupon_code==true)
			task = "coupon";
		if(document.getElementById("giftcode_price").value){
			if(confirm(document.getElementById('giftcode_price').value))
			{
				document.discount_form.task.value=task;
				document.discount_form.submit();
			}
		}else{
			document.discount_form.task.value=task;
			document.discount_form.submit();
		}
		
	}
}*/	
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
function changeSubscriptionPrice(subid,subval,product_id)
{
	document.getElementById('hidden_subscription_id'+product_id).value=subval;
	document.getElementById('hidden_subscription_prize').value = document.getElementById('hdn_subscribe_'+subid).value;
	calculateTotalPrice(product_id);
}

function getShippingrate()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var country_code = document.getElementById('country_code').value;
	var state_code = document.getElementById('state_code').value;
	var zip_code = document.getElementById('zip_code').value;
	var args = "country_code="+country_code+"&state_code="+state_code+"&zip_code="+zip_code;
	var url= site_url+'index2.php?option=com_redshop&view=cart&task=getShippingrate&'+args;
	var total;
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4)
		{
			response = xmlhttp.responseText.split('`');			
			if(document.getElementById('spnShippingrate'))
			{
				document.getElementById('spnShippingrate').innerHTML = response[0];
			
				if(document.getElementById('spnTotal'))
				{
					document.getElementById('spnTotal').innerHTML = response[1];
				}
			}
		}
	};
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function add_to_compare(pid,cid,cmd)
{
	xmlhttp=GetXmlHttpObject();
	var chked = document.getElementById('chk'+cid+pid);
	
	if(cmd=="remove")
		chked.checked = false;
	
	if(chked.checked)
		var cmd = 'add';
	else
		var cmd = 'remove';
	
	var args = 'pid='+pid+'&cmd='+cmd+'&cid='+cid;
	var url= site_url+'index2.php?option=com_redshop&view=product&task=addtocompare&'+args;
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4)
		{
			response = xmlhttp.responseText.split('`');	
			if(response[0]==0)
			{		
				alert(response[1]);
				chked.checked = false;
			}
			else
			{
				if(document.getElementById('divCompareProduct'))
					document.getElementById('divCompareProduct').innerHTML = response[1];
				if(document.getElementById('mod_compareproduct'))
					document.getElementById('mod_compareproduct').innerHTML = response[2];
			}
		}
	};
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function compare()
{
	var total = 0;
	if(document.getElementById('totalCompareProduct'))
		total = document.getElementById('totalCompareProduct').innerHTML;
	if(total < 2)
	{
		alert('Add 2 or More Products to Compare');
	}
	else
		document.frmCompare.submit();
}
function expand_collapse(atag,pid)
{
	if(atag)
	{
		var sign = "+";
		if(atag.innerHTML == "+")
			sign = "-";
		atag.innerHTML = sign;
			
		if(document.getElementsByName("exp_"+pid))
		{
			var expdivs = document.getElementsByName("exp_"+pid);
			var style = 'none';
			if(expdivs[0].style.display == 'none')
				var style = 'block';
			
			
			for(var i=0;i<expdivs.length;i++)
				expdivs[i].style.display = style;
		}
	}
}

function setSliderMinMax()
{
	if(document.getElementById('slider_texpricemin') && document.getElementById('texpricemin'))
	{
		document.getElementById('texpricemin').value = document.getElementById('slider_texpricemin').value;
	}
	if(document.getElementById('slider_texpricemax') && document.getElementById('texpricemax'))
	{
		document.getElementById('texpricemax').value = document.getElementById('slider_texpricemax').value;
	}
	document.orderby_form.submit();
}

function setSliderMinMaxForManufactur()
{
	if(document.getElementById('slider_texpricemin') && document.getElementById('manuf_texpricemin'))
	{
		document.getElementById('manuf_texpricemin').value = document.getElementById('slider_texpricemin').value;
	}
	if(document.getElementById('slider_texpricemax') && document.getElementById('manuf_texpricemax'))
	{
		document.getElementById('manuf_texpricemax').value = document.getElementById('slider_texpricemax').value;
	}
	document.filterby_form.submit();
}

function setSliderMinMaxForTemplate()
{
	if(document.getElementById('slider_texpricemin') && document.getElementById('temp_texpricemin'))
	{
		document.getElementById('temp_texpricemin').value = document.getElementById('slider_texpricemin').value;
	}
	if(document.getElementById('slider_texpricemax') && document.getElementById('temp_texpricemax'))
	{
		document.getElementById('temp_texpricemax').value = document.getElementById('slider_texpricemax').value;
	}
	document.template_selecter_form.submit();
}
function extrafieldValidation(frm)
{
	var extrafields  = frm.elements;
	var extrafields_val = '';

	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++){


			//alert(extrafields[ex].getAttribute('required'));

			extrafields_req = extrafields[ex].getAttribute('required');
			if(extrafields_req==1){
				if(extrafields[ex].type=='checkbox')
				{
					fieldNamefrmId = reverseString(extrafields[ex].id);
					fieldNamefrmId = reverseString(fieldNamefrmId.substr(fieldNamefrmId.indexOf("_")+1));
					if(previousfieldName != "" && previousfieldName!=fieldNamefrmId && chk_flag==false)
					{
						alert(extrafields[ex-1].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
						return false;
					}

					if(previousfieldName != fieldNamefrmId)
					{	extrafieldVal = "";
						previousfieldName = fieldNamefrmId;
					}

					if(extrafields[ex].checked)
					{
						chk_flag = true;
						continue;
					}
					if((ex == (extrafields.length-1) && chk_flag==false) || (extrafields[ex+1].type!='checkbox') && chk_flag==false ){
						alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
						return false;
					}
				}
				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)
					{
						alert(extrafields[ex-1].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
						return false;
					}

					if(rdo_previousfieldName != rdo_fieldNamefrmId)
					{
						extrafieldVal= "";
						rdo_previousfieldName = rdo_fieldNamefrmId;
						rdo_flag = false;
						if(extrafields[ex].checked)
						{
							rdo_flag = true;
							continue;
						}
					}
					else
					{
						if(extrafields[ex].checked || rdo_flag== true)
						{
							rdo_flag = true;
							continue;
						}
						if((ex == (extrafields.length-1) && rdo_flag==false) || (extrafields[ex+1].type!='radio') && rdo_flag==false ){
							alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
							return false;
						}
					}
				}
				else
				{
					extrafields_val = extrafields[ex].value;
					if(!extrafields_val)
					{	alert(extrafields[ex].getAttribute('userfieldlbl')+' '+IS_REQUIRED);
						return false;
					}
				}
			}
	}
	return true;
}
function finder_checkbox(frm)
{
		var chkboxs = frm.elements;
		
		for(var i=0;i<chkboxs.length;i++)
		{
			if(chkboxs[i].checked)
				return ;
		}
		
		if(i==chkboxs.length)
		{	
			chkboxs[0].checked = true;
			chkboxs[0].value = '0';
		}
}
function changeproductImage(product_id,imgPath,ahrefpath)
{
	if(document.getElementById('a_main_image'+product_id))
	{
		document.getElementById('a_main_image'+product_id).href=ahrefpath;
	}
	if(document.getElementById('main_image'+product_id))
	{
		document.getElementById('main_image'+product_id).src=imgPath;
	}
}
