
<script language="javascript">
   var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
   var lang=new Array();
   var attrib_icon=true;
   var products_price;
   var source="<?php echo $HTTP_GET_VARS['source'];?>";   
  <?php 
   	$languages = tep_get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) echo "lang[".$i."]=".$languages[$i]['id'].";\n";    
   ?>
    var n=lang.length;
	function startCallback_product() {
	  // make something useful before submit (onStart)
	  var error_result="";
	  var image_types=Array(".png",".jpg",".jpeg",".gif");
	  if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
	  var validate_form=false;
	  var price_break_flag=true;
	  if(action_type!=""){
		var id=0;
		if(document.new_product && document.new_product.product_id) id=document.new_product.product_id.value;
		if(document.getElementById("cPath")) category_id=document.getElementById("cPath").value;						
		var span_details=document.getElementById("span_details");
		var loadings=document.getElementById("loading");
			var frm=document.new_product;
			var address="";
			var icnt;
			var attrib_quantity=0;
			var pro_to_subs_string="";
			var error_result='';
			var attrb_splt=Array();
			var categories_image=document.getElementById('categories_image');								
			if(action_type=='new_category' || action_type=='edit_category'){				  	
			  	for(i=0;i<lang.length;i++)
			  		if(document.getElementById("categories_name["+lang[i]+"]") && document.getElementById("categories_name["+lang[i]+"]").value=="" || str_trim(document.getElementById("categories_name["+lang[i]+"]").value)=='') error_result='* <?php echo ERR_CATEGORY_NAME;?>\n';
			  	if (categories_image && categories_image.value!="" && !check_mime_type(categories_image,image_types))
					error_result+="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
				else if(categories_image && categories_image.value=="")
					validate_form=true; 
			}else if(action_type=='new' || action_type=='edit') { 
					var pro_sku=frm.products_sku.value.replace(" ");
					var shop_weight_unit = document.forms["new_product"].shop_weight_unit.value;
					//if(frm.is_attributes) frm.is_attributes.value="N";																		
					for(i=0;i<lang.length;i++){
						if(document.getElementById("products_name["+lang[i]+"]") && document.getElementById("products_name["+lang[i]+"]").value=="" || str_trim(document.getElementById("products_name["+lang[i]+"]").value)=='') error_result="* <?php echo ERR_PRODUCT_NAME;?>\n";
					}
					//desciption
					for(i=0;i<lang.length;i++){			
						var ifr=document.getElementById('if_products_description['+lang[i]+']');
						if(ifr) {
							<?php if(HTML_AREA_WYSIWYG_DISABLE=='Enable'){?>
							document.getElementById('products_description['+lang[i]+']').value=ifr.contentWindow.document.body.innerHTML;
							<?php }?>
						}
					}//description		
					var categories_error=true;
					for(i=0;i<document.getElementsByName('categories_ids[]').length;i++)
						if(document.getElementsByName('categories_ids[]')[i].checked==true) categories_error=false;
					if(categories_error==true)	
						error_result+="* <?php echo ERR_CATEGORY_SELECT;?>\n";
					if(document.getElementById("product_type")){
						var obj_pro_type=document.getElementById("product_type");
						if(obj_pro_type.value=='S' && document.getElementById("product_to_subscription_list") && document.getElementById("product_to_subscription_list").length<=0) error_result+="* <?php echo ERR_SOFTWARE_PACK_EMPTY;?>\n";  
						else if(obj_pro_type.value=='B' && document.getElementById("author_name") && isEmpty(document.getElementById("author_name"))) error_result+="* <?php echo ERR_AUTHOUR;?>\n";						
					}
					if(document.getElementById("product_to_subscripiton") && document.new_product.product_to_subscription_list){
						var n_cnt=document.new_product.product_to_subscription_list.length;
						for(i=0;i<n_cnt;i++) pro_to_subs_string+=document.new_product.product_to_subscription_list.options[i].value+"/";
						if(document.getElementById("product_to_subscripiton")) document.getElementById("product_to_subscripiton").value=pro_to_subs_string.substr(0,pro_to_subs_string.length-1);
					}
					if(document.getElementById("products_quantity") && (document.getElementById("products_quantity").value=="" || document.getElementById("products_quantity").value<=0) || str_trim(document.getElementById("products_quantity").value)=='') error_result+="* <?php echo ERR_QUANTITY;?>\n"; 						 
					if(document.getElementById('products_price').value=="" || document.getElementById('products_price').value<=0 || isNaN(document.getElementById('products_price').value))
						document.getElementById('products_price_break').checked=false;
					if(document.getElementById('products_price_break') && document.getElementById('products_price_break').checked){
						if(document.getElementById('price_break_list').length<=0)
							error_result+="* <?php echo ERR_PRICE_BREAK_EMPTY;?>\n";
						else {
							var price_splt=Array();
							var pbreaks;
							
							var pprice=document.getElementById('products_price').value;
							for (icnt=0;icnt<document.getElementById("price_break_list").length;icnt++){
								pbreaks=document.getElementById("price_break_list").options[icnt].value;
								price_splt=pbreaks.split("{#{}#}");
								if((price_splt[0]*(pprice-price_splt[1]))<0)
									price_break_flag=false;
								address+=document.getElementById("price_break_list").options[icnt].value + "/#/";
							}	
							if(address!='') document.getElementById('price_break_details').value=address;
						}
					}
					if(!price_break_flag)
						error_result+="* <?php echo ERR_NEGATIVE_PRICE_BREAK;;?>\n";
						frm.attributes_array.value="";
					//if(document.getElementById('panel_' + is_attrb).style.display!="none"){
					//if(frm.is_attributes) frm.is_attributes.value="Y";
					address="";
					row_len=document.getElementById('dynamic_table').rows.length;
					if(row_len>1){ 
								var quantity=0;
								var weight=0;
								for(i=1;i<row_len;i++){  
									var tr = document.getElementById('dynamic_table').rows[i];
									address+=tr.cells[0].innerHTML + '#' + tr.id + "#" + tr.cells[2].innerHTML + '#' +tr.cells[3].innerHTML +  '^';
									quantity = quantity + parseInt(tr.cells[2].innerHTML);
									//weight = weight + parseFloat(tr.cells[3].innerHTML);
								}
							 	if(address!="") 
									address=address.substring(0,(address.length-1));
								frm.attributes_array.value=address;
							document.getElementById('products_quantity').value=quantity;
							document.forms["new_product"].products_weight.value=weight;
							document.getElementById('products_quantity').disabled=false;
							document.forms["new_product"].products_weight.disabled=false;
						}else 
						{
							 if("<?php echo SKU_LENGTH;?>"=='true') {
								if(str_trim(pro_sku.value)==""){


									error_result+='* <?php echo TEXT_ERROR_PRODUCTS_SKU;?>\n';
								}else if(pro_sku.length!=<?php echo SKU_COUNT;?>){
									if(frm.default_sku_value && frm.default_sku_value.value>1){
										error_result+='* <?php echo TEXT_ERROR_PRODUCTS_SKU;?>\n';
									}else if(frm.default_sku_value && frm.default_sku_value.value==""){
										error_result+='Set Configuration value';
									}
								}
							}	

						}
						if(shop_weight_unit=="OZ"){
							 var check = document.forms["new_product"].products_weight.value.indexOf(".");
							 if(check!=-1){
							 	error_result+="* <?php echo addslashes(TEXT_ERROR_SHOP_WEIGHT_UNIT);?>\n";
							}
						}
						var frm1 = document.forms["new_product"].is_subscription;
						if(frm1.checked==true){
							var selected_value =document.forms["new_product"].subscription_categories_ids.selectedIndex;
  							if(selected_value<0) error_result+='Linked Subscription required';
						}
						if(isNaN(frm.products_price.value) || str_trim(frm.products_price.value=="") || (frm.products_price.value<0))
							error_result+="* <?php echo addslashes(TEXT_ERROR_NET_PRICE);?>\n";
						if(frm.products_status_chk && frm.elements["products_status"][0].checked) frm.products_status_chk.value=1;
						else if(frm.products_status_chk && frm.elements["products_status"][1].checked) frm.products_status_chk.value=0;
						var img_validate=Array();
						for (icnt=1;icnt<=5;icnt++){
			  				if (document.getElementById("products_image_"+icnt) && document.getElementById("products_image_"+icnt).value!="" && !check_mime_type(document.getElementById("products_image_"+icnt),image_types))
								error_result+="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
							else if(document.getElementById("products_image_"+icnt) && document.getElementById("products_image_"+icnt).value!="") img_validate[icnt]=true;
		  				}
					if(!img_validate.length) validate_form=true;
					if(document.getElementById("download_link").value!="") validate_form=false;
			}
	   if(action_type=='delete_category' || action_type=='move_category' || action_type=='delete' || action_type=='copy' || action_type=='move' || action_type=='attrib') validate_form=true;
	   if(error_result=="" && validate_form) {
	  	 ValidateForm();
	  	 return false;
	   }else if(error_result!=""){
	  	alert(error_result);
	  	return false;
	   }else if(error_result=="" && !validate_form) return true;		  
  	}	
  }		  
      
  function completeCallback_product(response) {
  	 var res=response;
  	 res_split=res.split("^");
  	 if(res_split[0]=='upload_error'){
  	 	alert(res_split[1]);
  	 	return false;
  	 }else ValidateForm(response);  	
  }  	  	  	        
    var option_array=new Array();
	var values_arr=new Array();
	var pname="";
	var cname="";
	var attrb_cnt=0;
	var splt=Array()
	var tax_rates = new Array();;
	var is_attrb= '<?php echo str_replace(" ","_",TEXT_IS_ATTRIBUTES);?>';	
	<?php  $options_array=tep_db_query("select products_options_id, products_options_name from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . $languages_id . "' order by products_options_sort_order");
		   while($option_result=tep_db_fetch_array($options_array)){
				$value_query=tep_db_query("select pov.products_options_values_id, pov.products_options_values_name from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov, " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . " p2p where pov.products_options_values_id = p2p.products_options_values_id and p2p.products_options_id = '" . $option_result['products_options_id'] . "' and pov.language_id = '" . $languages_id . "'");
				while($value_result=tep_db_fetch_array($value_query)){
					$options_values_array[]=array('options_id' =>$option_result["products_options_id"],
												'values_id' =>$value_result["products_options_values_id"],
												'value_name' => $value_result["products_options_values_name"]);
				}
			}
			//print_r($options_values_array);
		 	$tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
		 	while ($tax_class = tep_db_fetch_array($tax_class_query)) {
		 	 	echo 'tax_rates["' . $tax_class['tax_class_id'] . '"] = ' . tep_get_tax_rate_value($tax_class['tax_class_id']) . ';' . "\n";			 
		 	}		
			for($i=0,$n=sizeof($options_values_array); $i<$n; $i++){?>
				option_array[<?php echo $i;?>]="<?php echo $options_values_array[$i]['options_id'].'#'.$options_values_array[$i]['values_id'].'#'.$options_values_array[$i]['value_name'];?>";		
				values_arr[<?php echo $options_values_array[$i]['values_id']?>]="<?php echo $options_values_array[$i]['value_name']?>";
	<?php	}	?>	 	
	function doRound(x, places) {
  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}

function getTaxRate() {      
  if(document.getElementById('products_tax_class_id')){
	  var selected_value = document.getElementById('products_tax_class_id').selectedIndex;
	  var parameterVal = document.getElementById('products_tax_class_id').options[selected_value].value;
  }
  if ((parameterVal > 0) && (tax_rates[parameterVal] > 0)) 
    return tax_rates[parameterVal];
  else 
    return 0;
}



function show_sub(){
var frm1;
var action_type1=document.getElementById("action_type").value;

if(action_type1=='edit'){
frm1=document.forms["new_product"].is_subscription;
frm2=document.forms["new_product"].subscription_categories_ids;
if(frm1.checked==true){
//document.getElementById("show_is_sub").style.display="";
 

document.getElementById("subscription_categories_ids").disabled=false;

}
else
{
//document.getElementById("show_is_sub").style.display="none";
document.getElementById("subscription_categories_ids").disabled=true;
}
}
}   

function updateGross() {
  var taxRate = getTaxRate();
  var grossValue=0;
  if(document.getElementById("products_price")) grossValue = document.getElementById("products_price").value;

  if (taxRate > 0) {
    grossValue = grossValue * ((taxRate / 100) + 1);
  }

  document.getElementById("products_price_gross").value = doRound(grossValue, 4);
}

function updateNet() {
  var taxRate = getTaxRate();
  var netValue = document.getElementById("products_price_gross").value;

  if (taxRate > 0) {
    netValue = netValue / ((taxRate / 100) + 1);
  }

 document.getElementById("products_price").value = doRound(netValue, 4);
}
function do_quantity_check() {
  var attribute_quantity = document.forms["new_product"].attribute_quantity.value;
  var product_quantity = document.forms["new_product"].products_quantity.value;
  if (attribute_quantity > product_quantity){
   alert("Attribute Quantity exceeded");
	}
}
    function change(obj,mode,pos){
	var arr_text=Array();
	var arr_value=Array();
	var attrb_splt=Array();
	var cnt=0;
	var icnt=0;
	var parr_name="";
	var carr_name="";
	if(document.getElementById('dynamic_table') && mode==1)
	{
		if(document.getElementById('dynamic_table').rows.length>1 && (!obj.checked || (pos && document.getElementById("option_values"+pos).options.length<=0)))
		{
			obj.checked=!obj.checked;
			alert('<?php echo ERR_ATTRIBUTE?>');
			return;
		}
	}
	if(option_array.length>0){
		deleteoptions();
	  for(i=0;i<option_array.length;i++){
	 	cnt=i+1;
		attrb_splt=option_array[i].split("#");
		if(document.getElementById("option"+"["+cnt+"]") && document.getElementById("option"+"["+cnt+"]").checked){
			arr_text=attrb_splt[2];
			arr_value=attrb_splt[1];
			addoptions(arr_text,arr_value,attrb_splt[0]);
			icnt++;
		}	
	}
	check_option_exists();
  }
}

function addoptions(textArr,valueArr,nameArr){
  var option = document.createElement('option');
  option.text = textArr;
  option.value = valueArr;
  document.getElementById('options'+nameArr).style.display="";
  var optionElement = document.getElementById('option_values'+nameArr);
  try {
	optionElement.add(option, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
	optionElement.add(option); // IE only
  }
}

	function deleteoptions(){
	var attributes_array=new Array();
	 for(i=0;i<option_array.length;i++){
		splt=option_array[i].split("#");
		cname=splt[0];
		if(pname!=cname){
			attributes_array[attrb_cnt]=cname;
			attrb_cnt++;
			pname=splt[0];
		}
	}
		 var carr_name="";	
		 for(i=0;i<attributes_array.length;i++){
			carr_name=document.getElementById('option_values'+attributes_array[i]);
			if(carr_name)
				for (j = carr_name.length - 1; j>=0; j--) {
					carr_name.remove(j);
				}
		 }
	}

function check_option_exists(){
var carr_name="";
var attributes_array=new Array();
	for(i=0;i<option_array.length;i++){
		splt=option_array[i].split("#");
		cname=splt[0];
		if(pname!=cname){
			attributes_array[attrb_cnt]=cname;
			attrb_cnt++;
			pname=splt[0];
		}
	}
	 for(i=0;i<attributes_array.length;i++){
		carr_name=document.getElementById('option_values'+attributes_array[i]);
			if(carr_name && carr_name.length<=0)
				document.getElementById('options'+attributes_array[i]).style.display="none";
	}
}

function do_action(action){ 
		var frm=document.new_product;
		var error_result="";
		var del_items="";
		var sIndex=frm.attribute_list.selectedIndex;
		switch(action){
			case "edit":
			case "add":
			if(subvalidateForm()==false){
				return;
			}
			var temp=getDetails();			
			var pos;
			dateAdd=temp[1];
			dateAddText=temp[0];
				if (check_attribute_exists(dateAdd,action)){
					alert('* <?php echo addslashes(TEXT_ATTRIBUTE_ALREADY_EXISTS); ?>');
					return;
				}
				if (action=="edit") {
					if(sIndex<0) return;
						frm.attribute_list.remove(sIndex);
				}					
				var pos=get_position(dateAdd);
				var oOption = document.createElement("OPTION");
				oOption.text=dateAddText;
				oOption.value=dateAdd;
				if(frm.attribute_list.add.length==2){
				 frm.attribute_list.add(oOption,null);
				}	else {
				 frm.attribute_list.add(oOption,pos);
				}
				pos=frm.attribute_list.length;
				frm.attribute_list.selectedIndex=pos-1;
				frm.attrib_quantity.value='';
				frm.attrb_sku.value='';
				frm.attribute_status.value = '';									
				break;
				case "delete":
					frm.attribute_list.remove(sIndex);
					if (sIndex>0 && sIndex<frm.attribute_list.length-1)
						sIndex=sIndex+1;
					else if (sIndex>0)
						sIndex=sIndex-1;
					else if (sIndex>=frm.attribute_list.length) sIndex=frm.attribute_list.length-1;
					frm.attribute_list.selectedIndex=sIndex;
					do_action('select');
					break;
				case "select":
				
					var attributes=Array();
					var attrb_splt=Array();
					var values=Array();
					var skew=Array();
					if(sIndex<0) return;					
					if(sIndex>=0){ 
						skew=frm.attribute_list.options[sIndex].value.split(' ');
						skew_value=skew[1];
						document.new_product.attrb_sku.value=skew_value.substr(4);
						skew_attr_value = skew[2];
						if(skew_attr_value.substr(7)==0){
							document.new_product.attribute_status[0].checked=false;
							document.new_product.attribute_status[1].checked=true;
						}else{
							document.new_product.attribute_status[0].checked=true;
							document.new_product.attribute_status[1].checked=false;
						}
						values=skew[0].split('#');
						attributes=values[0].split('-');
						for(i=0;i<attributes.length;i++){
							attrb_splt=attributes[i].split('{');
							if(document.getElementById("option_values"+attrb_splt[0])) document.getElementById("option_values"+attrb_splt[0]).value=attrb_splt[1].substring(0,(attrb_splt[1].length-1));
						}
						document.new_product.attrib_quantity.value=values[1];
					}
				return; 
			}
		} 
				
		function getDetails(){
			var carr_name="";
			var attributes_array=new Array();
			for(i=0;i<option_array.length;i++){ 
				splt=option_array[i].split("#");
				cname=splt[0];
				if(pname!=cname){
					attributes_array[attrb_cnt]=cname;
					attrb_cnt++;
					pname=splt[0];
				}
			}
			var attrbAdd=Array();
			var attrb_text="";
			var attrb_value="";
			 for(i=0;i<attributes_array.length;i++){
				carr_name=document.getElementById('option_values'+attributes_array[i]);
				if(carr_name && carr_name.length>0){
				attrb_text+=carr_name.options[carr_name.selectedIndex].text + ',';
				attrb_value+=attributes_array[i]+'{'+carr_name.options[carr_name.selectedIndex].value+'}-';
				}
			}
			var attribute = 1;
			if(document.new_product.attribute_status[0].checked==false){
				attribute = 0;
			}else if(document.new_product.attribute_status[1].checked==false){
				attribute = 1;
			}
			attrb_text=attrb_text.substring(0,(attrb_text.length)-1)+','+document.new_product.attrib_quantity.value+' SKU:' +document.new_product.attrb_sku.value+' Status:' +attribute;
			attrb_value=attrb_value.substring(0,(attrb_value.length)-1)+'#'+document.new_product.attrib_quantity.value+' SKU:' +document.new_product.attrb_sku.value+' Status:' +attribute;
			attrbAdd[0]=attrb_text;
			attrbAdd[1]=attrb_value;
			return attrbAdd;
		}
	function subvalidateForm(){
		var frm=document.new_product;
			var error_result="";
			if(frm.attrib_quantity.value=="" || frm.attrib_quantity.value==0 || isNaN(frm.attrib_quantity.value) || frm.attrib_quantity.value<0){
				error_result='* <?php echo TEXT_QUANTITY_ERROR;?>\n';
			}
			//if(frm.attrib_weight.value=="" || frm.attrib_weight.value==0 || isNaN(frm.attrib_weight.value) || frm.attrib_weight.value<0) error_result='* <?php echo TEXT_WEIGHT_ERROR;?>\n';
			if(frm.attrb_sku.value =='' || frm.attrb_sku.value==0){
				error_result+='* <?php echo TEXT_ERROR_PRODUCTS_SKU;?>\n';
			}else if(((frm.attrb_sku.value.length)>12 || (frm.attrb_sku.value.length)<12)){
				if(frm.default_sku_value.value=="true"){
					error_result+='* <?php echo TEXT_ERROR_PRODUCTS_SKU;?>\n';
				}else if(frm.default_sku_value.value==""){
					error_result+='Set Configuration value';




				}
			}
			if(error_result!=""){
				alert(error_result);
				return false;
			}
			return true;	
		}			
		function check_attribute_exists(dateAddText,mode){
			frm=document.new_product;
			sIndex=-1;
			var dateAddvalue=dateAddText.split('#');
			if (mode=="edit") sIndex=frm.attribute_list.selectedIndex;
			for (icnt=0;icnt<frm.attribute_list.length;icnt++){
				var attrb=frm.attribute_list.options[icnt].value;
				var attrb_value=attrb.split('#');
				if(icnt!=sIndex && attrb_value[0] == dateAddvalue[0]){
					return true;
				}
			}
			return false;
		} 
		
		function get_position(dateAdd){
			frm=document.new_product;
			for (icnt=0;icnt<frm.attribute_list.length;icnt++){
				if(dateAdd<=frm.attribute_list.options[icnt].value){
					return icnt;
				}
			}
			return icnt;
		 }
		 
		function init_page(){
		
		if (document.new_product.attribute_list.options.length>0){
			document.new_product.attribute_list.selectedIndex=0;
			do_action("select");
		} 
		
		
		} 
		function do_skew_action(val){
			if(val){
				if(document.getElementById('dynamic_table').rows.length>1) {
					document.new_product.products_sku.disabled=true;
					document.new_product.products_quantity.disabled=true;
					document.new_product.products_weight.disabled=true;
				} else {
					document.new_product.products_sku.disabled=false;
					document.new_product.products_quantity.disabled=false;
					document.new_product.products_weight.disabled=false;
				}
				if(document.getElementById("attrib_list")) document.getElementById("attrib_list").style.display="";
			}else{
				document.new_product.products_sku.disabled=false;
				document.new_product.products_quantity.disabled=false;
				document.new_product.products_weight.disabled=false;
				if(document.getElementById("attrib_list")) document.getElementById("attrib_list").style.display="none";
			}	
		}			 	   
    var is_attrb= '<?php echo str_replace(" ","_",TEXT_IS_ATTRIBUTES);?>';
   	function doaction(){ 
			if(document.getElementById("panel_"+is_attrb) && document.getElementById("panel_"+is_attrb).style.display=="") {
				if(document.getElementById('dynamic_table').length>1 || document.getElementById('dynamic_table').length<=1) {
					document.new_product.products_sku.disabled=true;
					document.new_product.products_quantity.disabled=true;
				}
			} else if(document.getElementById("panel_"+is_attrb) && document.getElementById("panel_"+is_attrb).style.display=="none") { 
				if(!document.getElementById('dynamic_table').rows.length || document.getElementById('dynamic_table').rows.length<=1) {
					document.new_product.products_sku.disabled=false;
					document.new_product.products_quantity.disabled=false;
					document.new_product.products_weight.disabled=false;
				}	else {
					document.new_product.products_sku.disabled=true;
					document.new_product.products_quantity.disabled=true;
					document.new_product.products_weight.disabled=true;
				}
			}	
	 }	  	 	     	 	  	 	  	
	 function show_duplicate(type){
	 	if(type=='dup')
			document.getElementById('dub_prd').style.display='';
		else
		   document.getElementById('dub_prd').style.display='none';
	 }
	 function show_attributes(obj){ 
	    if(obj.checked==true){
			document.getElementById('dublicate').style.display='none';
			document.getElementById('download').style.display='none';
		}else{
			document.getElementById('dublicate').style.display='';
			document.getElementById('download').style.display='';
		}
		
	 } 
	 function change_product_mode(obj)
	 {
	  if(obj.value=="P")
	  {
	  	document.getElementById("product_download_details").style.display="none";
		document.getElementById("show_weight_field").style.display="";
	  }
	  else
	  {
	  	document.getElementById("product_download_details").style.display="";
		document.getElementById("show_weight_field").style.display="none";
		}	
	 }	
	 function load_images() { //v3.0
	  var d=document; 
  	  var a=load_images.arguments;	  
	  d.url_list=new Array();
		for(i=1; i<=a.length; i++){ 
			d.url_list[i]=a[i-1];
		}
	}
	function load_titles() { //v3.0
	  var d=document; 
  	  var a=load_titles.arguments;
	  d.title_list=new Array();
		for(i=1; i<=a.length; i++){ 
			d.title_list[i]=a[i];
		}
	}
	function set_image(index){
		var d=document; 
		var dest=d.getElementById("imgContainer");
		if (d.url_list[index] && dest){
			dest.src=d.url_list[index];
		}	
	}	
	//products price break start 
	function do_price_break(obj){
		if(document.getElementById('products_price').value==0 || isNaN(document.getElementById('products_price').value) || document.getElementById('products_price').value<=0) {
			obj.checked=false;
			alert('* <?php echo TEXT_ERROR_NET_PRICE?>');
		} else {	
			if(obj.checked)
				document.getElementById('price_break').style.display="";
			else 
				document.getElementById('price_break').style.display="none";	
		}		
	}
	function do_price_select(mode) { 
		var error_msg='';
		var quantity;
		var dis_price;
		var price;
		var pos;
		if(mode=='add' || mode=='update'){
			if(document.getElementById('quantity').value==0 || isNaN(document.getElementById('quantity').value))
				error_msg+="* <?php echo ERR_PRODUCTS_QUANTITY;?>\n";
			else if(document.getElementById('quantity').value<=1)
				error_msg+="* <?php echo ERR_QUANTITY;?>\n";
				
			if(document.getElementById('discount_price').value<=0 || isNaN(document.getElementById('discount_price').value))
				error_msg+="* <?php echo ERR_DISCOUNT_PRICE;?>\n"; 
			if(parseFloat(document.getElementById('products_price').value) < parseFloat(document.getElementById('discount_price').value))
				error_msg+="* <?php echo ERR_DISC_PRICE;?>";
		}
		if(error_msg!='') {
			alert(error_msg); 
			return false; 
		} else {	
			quantity=document.getElementById('quantity').value; 
			dis_price=document.getElementById('discount_price').value; 
			price=document.getElementById('products_price').value; 
			
			switch (mode) {
				case 'add':
				case 'update':
				  var amt;
				  var option = document.createElement('OPTION'); 
				  var taxRate = getTaxRate();
				  amt=(quantity*(price-dis_price));
				  if (taxRate > 0) {
					amt = amt * ((taxRate / 100) + 1);
				  }
				  if(amt<=0) {
				  	alert('* <?php echo ERR_PRICE_BREAK;?>');
					return;
				  }		
				  option.text = quantity + " for " + doRound(amt,4); 
				  option.value = quantity + "{#{}#}" + dis_price; 
				  var optionElement = document.getElementById('price_break_list');
				  pos=optionElement.length;
				  if(get_already_exists(quantity,mode)) {
					alert('* <?php echo ERR_PRICE_ALREADY_EXISTS;?>\n');
					return;
				  }
				  	if (mode=="update") { 
					if(sIndex<0) return;
						pos=sIndex;
						optionElement.remove(sIndex);						
					}	
									
					if(optionElement.add.length==2){
						optionElement.add(option,null);
					}	else {
					 optionElement.add(option,pos);
					}
					pos=document.getElementById('price_break_list').length;
					document.getElementById('price_break_list').selectedIndex=pos-1;
				  	document.getElementById('quantity').value="";
					document.getElementById('discount_price').value="";
					document.getElementById('cal_price').innerHTML="";
				break;	
				case 'select':
					sIndex=document.getElementById('price_break_list').selectedIndex;
					if(sIndex<0) return;
					var value=document.getElementById('price_break_list').options[sIndex].value;
					var splt_array=value.split("{#{}#}");
					document.getElementById('quantity').value=splt_array[0];
					document.getElementById('discount_price').value=splt_array[1];
				break;
				case 'delete':
					sIndex=document.getElementById('price_break_list').selectedIndex;
					if(sIndex<0) return;
					document.getElementById('price_break_list').remove(sIndex);	
					pos=document.getElementById('price_break_list').length;
					document.getElementById('price_break_list').selectedIndex=pos-1;
				  	document.getElementById('quantity').value="";
					document.getElementById('discount_price').value="";
				break;
				
			}
		}
	}
	
	function get_already_exists(dateAddText,mode){
	frm=document.new_product;
	sIndex=-1;
	if (mode=="update") sIndex=frm.price_break_list.selectedIndex;
	for (icnt=0;icnt<frm.price_break_list.length;icnt++){
		var attrb=frm.price_break_list.options[icnt].value;
		var attrb_array=attrb.split('{#{}#}');
		if(icnt!=sIndex && attrb_array[0] == dateAddText){
			return true;
		}
	}
	return false;
} 
function do_price_change(){
	var price=document.getElementById('products_price').value;
	var disc_price=document.getElementById('discount_price').value;
	var quantity=document.getElementById('quantity').value;
	var amt;	
	if(document.getElementById('quantity').value!='' && !isNaN(document.getElementById('quantity').value) && document.getElementById('discount_price').value!='' && !isNaN(document.getElementById('discount_price').value)){
		 amt=quantity *(price-disc_price);
		 var taxRate = getTaxRate();
		 if (taxRate > 0)  amt = amt * ((taxRate / 100) + 1);		 
		document.getElementById('cal_price').innerHTML=" Total Price: " + doRound(amt, 4) ;
	}
}
function show_price_break(){
var action_type1=document.getElementById("action_type").value;

if(action_type1=='edit'){
	if(document.getElementById('products_price_break').checked)
		document.getElementById('price_break').style.display='';
	else 
		 document.getElementById('price_break').style.display="none";
}
}
function update_price_break(){
	if((document.getElementById('products_price').value) && document.getElementById('products_price_break').checked){
		var price_array=Array();
		var price_element="";
		var optionElement;
		var quantity;
		var dis_price;
		var price=document.getElementById('products_price').value;
		var pos;
		var price_break;
		optionElement=document.getElementById('price_break_list');
		for(i=0;i<optionElement.length;i++){
			//price_element=document.getElementById('products_price_break')[i].value;
			price_element+=optionElement[i].value+'/#/';
		}			
		while(optionElement.options.length>0){
			optionElement.remove(optionElement.options.length - 1);
		}
		hh=price_element.split('/#/');
		for (j=0;j<(hh.length-1);j++){
			price_array=hh[j].split("{#{}#}");
			quantity=price_array[0];
			dis_price=price_array[1];
			pos=i;
			price_break=(quantity*(price-dis_price))
				  var taxRate = getTaxRate();
				  if (taxRate > 0) {
					price_break = price_break * ((taxRate / 100) + 1);
				  }
			price_break=doRound(price_break, 4) ;
			
		    var option = document.createElement('OPTION'); 
		    option.text = quantity + " for " + price_break; 
		    option.value = hh[j];
					if(optionElement.add.length==2){
						optionElement.add(option,null);
					}	else {
					 optionElement.add(option,pos);
					}
		}
	}
}
function do_breaks_hover_change(action,mode,obj){
	if(mode==1){
		obj.src=img_src+"template/" + action + "_hover.gif";
	} else if(mode==2){
		obj.src=img_src+"template/" + action + ".gif";
	}
}

function do_change_customers(mode){
	var rest_flag=true;	
	var g_cnt=document.new_product.elements["restrict_to_groups[]"].length;
	var c_cnt=document.new_product.elements["restrict_to_customers[]"].length;
	if(mode=='1'){
		for(i=0;i<g_cnt;i++){
			if(document.new_product.elements["restrict_to_groups[]"][i].checked){
				rest_flag=false;
				for(j=0;j<c_cnt;j++){
					document.new_product.elements["restrict_to_customers[]"][j].checked=false;
					document.new_product.elements["restrict_to_customers[]"][j].disabled=true;
				}
			}
		}
		if(rest_flag){
			for(j=0;j<c_cnt;j++){
				document.new_product.elements["restrict_to_customers[]"][j].checked=false;
				document.new_product.elements["restrict_to_customers[]"][j].disabled=false;
			}	
		}
			
	} else if(mode==2){	    
		for(i=0;i<c_cnt;i++){
			if(document.new_product.elements["restrict_to_customers[]"][i].checked){
				rest_flag=false;
				for(j=0;j<g_cnt;j++){
					document.new_product.elements["restrict_to_groups[]"][j].checked=false;
					document.new_product.elements["restrict_to_groups[]"][j].disabled=true;
				}	
			}	
		}	
		if(rest_flag){
			for(j=0;j<g_cnt;j++){
				document.new_product.elements["restrict_to_groups[]"][j].checked=false;
				document.new_product.elements["restrict_to_groups[]"][j].disabled=false;
			}
		}
	}
 }
function show_restrict() {
var action_type1=document.getElementById("action_type").value;

	if(action_type1=='edit'){
		for(i=0;i<document.new_product.elements["restrict_to_groups[]"].length;i++){
			if(document.new_product.elements["restrict_to_groups[]"][i].checked){
				for(j=0;j<document.new_product.elements["restrict_to_customers[]"].length;j++){
					document.new_product.elements["restrict_to_customers[]"][j].checked=false;
					document.new_product.elements["restrict_to_customers[]"][j].disabled=true;
				}	
			return;
			}
		}
		for(i=0;i<document.new_product.elements["restrict_to_customers[]"].length;i++){
			if(document.new_product.elements["restrict_to_customers[]"][i].checked){
				for(j=0;j<document.new_product.elements["restrict_to_groups[]"].length;j++){
					document.new_product.elements["restrict_to_groups[]"][j].checked=false;
					document.new_product.elements["restrict_to_groups[]"][j].disabled=true;
				}	
			return;
			}
		}
	}			
}
function do_change_product(obj){
	var soft_span=document.getElementById("span_software_pack");
	var book_span=document.getElementById("span_book");
	var span_general=document.getElementById("span_general");
	if(obj){
	   if(obj.value=='S' && soft_span && book_span && span_general){
	   	 soft_span.style.display="";
	   	 span_general.style.visibility=book_span.style.visibility="hidden";
	   }else if(obj.value=='B' && book_span && soft_span && span_general){
	   	  soft_span.style.display="none";
	   	  book_span.style.visibility="visible";
	   	  span_general.style.visibility="hidden";
	   }else if(soft_span && book_span && span_general){
	   	 book_span.style.visibility="hidden";
	   	 soft_span.style.display="none";
	   	 span_general.style.visibility="visible";
	   }
	}	
 }
 
 function isEmpty(ctlName){
			var value;
			if (ctlName && ctlName.length>0 && ctlName[0]){
				for (icnt=0;icnt<ctlName.length;icnt++){
					value=ctlName[icnt].value.trim();
					if (value=="") return true;						
				}
			} else if(ctlName) {
				value=ctlName.value.trim();
				if (value=="") return true;
			}
			return false;
  }
  function do_subscription(mode){
  	var subscription_select=document.getElementById("subscription_selection");  	
  	var software_subscription=document.new_product.elements["software_subscription[]"];
  	var num_users=document.getElementById("num_users");  	
  	var numuser_selected=true;
  	var select_subscription_text_string="";
  	var select_subscription_value_string="";
  	if(software_subscription && (mode=='add' || mode=='edit'))
			if(software_subscription && software_subscription.length>0){
  				for(i=0;i<software_subscription.length;i++)
  					if(software_subscription[i]) software_subscription[i].checked=false;
  			}else if(software_subscription) software_subscription.checked=false;  
  	if(mode!=""){
  		if(mode=='add' && subscription_select){
  			subscription_select.style.display="";
  			if(document.new_product.product_to_subscription_list) document.new_product.product_to_subscription_list.selectedIndex=-1; 				
			if(num_users) num_users.value="";  				
  		}else if(mode=='edit' && document.new_product.product_to_subscription_list && document.new_product.product_to_subscription_list.selectedIndex>=0){
			subscription_select.style.display="";
			var values=document.new_product.product_to_subscription_list.options[document.new_product.product_to_subscription_list.selectedIndex].value;
			if(values!=""){
				values_split=values.split(",");
				if(software_subscription.length>0){
					for(i=0;i<software_subscription.length;i++)
					  for(j=0;j<values_split.length-1;j++)
 						if(software_subscription[i].value==values_split[j]) software_subscription[i].checked=true;
				}else if(software_subscription){
					for(j=0;j<values_split.length-1;j++)
					  if(values_split[j]==software_subscription.value) software_subscription.checked=true;
				}
				if(values_split.length>0 && values_split[values_split.length-1]!="") num_users.value=values_split[values_split.length-1];
			}
  		}else if(mode=='delete'){
  			if(document.new_product.product_to_subscription_list && document.new_product.product_to_subscription_list.selectedIndex>=0)
  			  document.new_product.product_to_subscription_list.remove(document.new_product.product_to_subscription_list.selectedIndex);
  			subscription_select.style.display="none";
  		}else if(mode=='save' && software_subscription){
			if(software_subscription.length>0){
				var subscription_selected=false;
				for(i=0;i<software_subscription.length;i++){
					if(software_subscription[i] && software_subscription[i].checked){
						subscription_selected=true;
						if(document.getElementById("id_"+software_subscription[i].value)) {
							select_subscription_text_string+=document.getElementById("id_"+software_subscription[i].value).innerHTML+",";
							select_subscription_value_string+=software_subscription[i].value+",";							
						}
					}
				}
			}else if(software_subscription.checked && software_subscription.checked){
				subscription_selected=true;
				if(document.getElementById("id_"+software_subscription.value)) {
					select_subscription_text_string+=document.getElementById("id_"+software_subscription.value).innerHTML+",";
					select_subscription_value_string+=software_subscription.value+",";					
				}
			}
			var subscription_raw_value=0;
			if(select_subscription_value_string!="") subscription_raw_value=select_subscription_value_string.substr(0,select_subscription_value_string.length-1);
			if(num_users && (isEmpty(num_users) || num_users.value==0)) numuser_selected=false;
			else if(num_users && num_users.value>0) {
				select_subscription_text_string+=num_users.value + " users";
				select_subscription_value_string+=num_users.value;	
			}
			if(!subscription_selected) alert("<?php echo ERR_SUBSCRIPTION_SELECT;?>");
  			else if(!numuser_selected) alert("<?php echo ERR_NUM_USERS;?>");
  			else if(dupilcate_subscription_exists(subscription_raw_value)) alert("<?php echo ERR_SOFTWAREPACK_ALREADY_EXISTS;?>");  			
  			else if(document.new_product.product_to_subscription_list && document.new_product.product_to_subscription_list.selectedIndex>=0){  				  			
  					document.new_product.product_to_subscription_list.options[document.new_product.product_to_subscription_list.selectedIndex].text=select_subscription_text_string;
  					document.new_product.product_to_subscription_list.options[document.new_product.product_to_subscription_list.selectedIndex].value=select_subscription_value_string;
  					subscription_select.style.display="none";
  			}else {
  				var oOption = document.createElement("OPTION");
  				var pos=0;
				oOption.text=select_subscription_text_string;
				oOption.value=select_subscription_value_string;				
				if(document.new_product.product_to_subscription_list.add.length==2)
				 	document.new_product.product_to_subscription_list.add(oOption,null);
				else 
				 	document.new_product.product_to_subscription_list.add(oOption,pos);
				subscription_select.style.display="none";				
	  		}
  		}else if(mode=='close') subscription_select.style.display="none";  		
  	}  	
  }		
  function dupilcate_subscription_exists(subscription_list){
  	 var ret_flag=false;
  	 var product_to_subscription_list=document.new_product.product_to_subscription_list;
  	 if(subscription_list!="" && product_to_subscription_list){
  	 	n=product_to_subscription_list.length;
  	 	for(i=0;i<n;i++){
  	 		vals=product_to_subscription_list.options[i].value;
			vals=vals.substr(0,vals.lastIndexOf(","));
  	 		if(product_to_subscription_list.selectedIndex!=i && !ret_flag && vals==subscription_list) ret_flag=true;  	 		
  	 	}
  	 }
  	 return ret_flag;
  }  
  function do_actions(action,id,category_id,book_id){
 		if(action=='get_details') document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif'); 		
		var res_display=document.getElementById("res_display");
		if(document.getElementById("image_type")) document.getElementById("image_type").value='';
		var chk_cid=document.getElementById("cPath");		
		var chk_pid=document.getElementById("product_id");
		if(!id && action=='new_category' &&  chk_cid && chk_cid.value>0) id=chk_cid.value;
		if((action=='edit_category' || action=='delete_category' || action=='move_category')  && chk_cid && chk_pid && document.getElementById("data_"+chk_pid.value+"_"+chk_cid.value) && document.getElementById("head_"+chk_pid.value+"_"+chk_cid.value)) {			
			document.getElementById("data_"+chk_pid.value+"_"+chk_cid.value).style.display="";
			document.getElementById("head_"+chk_pid.value+"_"+chk_cid.value).style.display="none";	
		}
		var c_obj=document.getElementById("cPath");
		if((action=='get_details') && c_obj && document.getElementById("span_details_"+c_obj.value)) {
			if(document.getElementById("img_save_"+c_obj.value)) document.getElementById("img_save_"+c_obj.value).style.visibility="hidden";
			document.getElementById("span_details_"+c_obj.value).innerHTML="";
		}
		/*if(c_obj && c_obj.value!=category_id) {
			if(document.getElementById("panel_"+c_obj.value+"_content")) document.getElementById("panel_"+c_obj.value+"_content").innerHTML="";
			toggle_category_panel(c_obj.value,0);
		}*/
 	 	if(category_id>0 && document.new_product && document.new_product.product_id){
			var old_ids=document.new_product.product_id.value;
			if(c_obj) var old_cate_id=c_obj.value;
			var pre_data_id=document.getElementById("data_"+old_ids+"_"+old_cate_id);
			var pre_head=document.getElementById("head_"+old_ids+"_"+old_cate_id);
			if((action!='attrib' && action!='category_pos_up' && action!='category_pos_down' && action!='new_product') && document.getElementById("span_details_"+category_id)) {				
				document.getElementById("span_details_"+category_id).innerHTML="";
				if(document.getElementById("img_save_"+category_id)) document.getElementById("img_save_"+category_id).style.visibility="hidden";
			}
			var loadings=document.getElementById("loading");
			if(loadings) loadings.style.display="none";
			if(category_id>0 && action=='get_details' && pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
		}
		if(category_id>0 && id>0 && document.new_product && document.new_product.product_id && document.new_product.product_id.value=="") document.new_product.product_id.value=id;
		//else if(id>0 && document.new_product && c_obj && (action!='pos_down' && action!='pos_up')) c_obj.value=id;
		else if(id>0 && document.new_product && c_obj && (action!='pos_down' && action!='pos_up' && action!='category_pos_up' && action!='category_pos_down')) c_obj.value=id;
		if(category_id>0 && id>0 && document.new_product.product_id.value>0 && document.new_product.product_id.value!=id){
			   var head=document.getElementById("head_"+id+"_"+old_cate_id);
			   if(head && head.style.display=="") head.style.display="none";
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";
			   document.new_product.product_id.value=id;
		}
		if(c_obj && category_id>0 && (action!='pos_down' && action!='pos_up' && action!='category_pos_up' && action!='category_pos_down')) c_obj.value=category_id;		
		var img_div=document.getElementById("img_save_"+id);
		if(!category_id && document.getElementById("span_details_"+id) && action!='new_category' && (action!='pos_down' && action!='pos_up' && action!='set_flag' && action!='category_pos_up' && action!='category_pos_down')) 			
			document.getElementById("span_details_"+id).innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";		
 	 	if(action){
 	 		if(!category_id && c_obj) var cid=c_obj.value;
 	 		var span_details=document.getElementById("span_details");
			var data_id=document.getElementById("data_"+id+"_"+category_id);
			var head=document.getElementById("head_"+id+"_"+category_id);
			var action_type=document.getElementById("action_type");
			var img_save=document.getElementById("img_save");
			var img_new=document.getElementById("img_new");
			if(action=='pos_down' || action=='pos_up' || action=='set_flag' || action=='category_pos_up' || action=='category_pos_down'){}
			else if(span_details && category_id>0) span_details.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 		if(img_new && (action=='new_category' || action=='edit_category' || action=='delete_category' || action=='move_category') && img_div) img_div.style.visibility="visible";
 	 		if(img_new && (action=='edit_category' || action=='delete_category' || action=='move_category')){ 
 	 			img_new.href='javascript:do_actions(\'new_category\''+","+id+');'; 	 			
 	 			if(document.getElementById("link_category")) document.getElementById("link_category").href='javascript:do_actions(\'new_category\''+","+id+');';
 	 		}
 	 		if(img_new && (action=='get_details' && category_id>0) || (action=='new_product' || action=='edit_product' || action=='delete_product' || action=='copy_product' || action=='move_product') && (action=='attrib' || action=='go_session')){ 	 			
 	 			img_new.href="javascript:do_actions('new_product'"+","+id+","+category_id+");"; 	 			
 	 			if(document.getElementById("link_product")) document.getElementById("link_product").href="javascript:do_actions('new_product'"+","+id+","+category_id+");";
			}
 	 		switch(action){
 	 			case 'get_details':
					if(document.getElementById('image_type')) document.getElementById('image_type').value="true";
					var tr1=document.getElementById("img_ids");
					var imgsrc;
					var node;
					if(tr1)
					for(var j=0;j<tr1.cells.length;j++){
						td=tr1.cells[j];
						imgsrc='';
						for(var i=0;i<td.childNodes.length;i++){
							node=td.childNodes[i];
							if(node.tagName=='IMG'){
								imgsrc=node.src;
								if(imgsrc==img_src+'template/img_edit_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_edit.gif';
								else if(imgsrc==img_src+'template/img_trash_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_trash.gif';
								else if(imgsrc==img_src+'template/img_copy_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_copy.gif';
								else if(imgsrc==img_src+'template/img_move_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_move.gif';
								else if(imgsrc==img_src+'template/img_attrib_hover.gif')
								   td.childNodes[i].src = img_src+'template/img_attrib.gif';
								break;
							}
						}
					}
				 if(head && span_details){ 	 			 	 	 			    	 			    	 			    	 			   
 	 			   if(head.style.display==""){ 	 			   	   	 			   	   	 			   	   	 			   	   	 			   	  
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none";
 	 			   	  	data_id.style.display="";
 	 			   	  }else 
 	 			   	  	span_details.style.display="";												 	 			   	   	 			   	  	 			   	  	
 	 			   }else {
	 	 			 	if(head) head.style.display=="";
	 	 			 	if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="none";	 	 			 			 	 	 			  	 		 	 		 	 			 		 	 			 	
	 	 			 	if(!category_id) {
	 	 			 		if(img_div) img_div.style.visibility="hidden";
	 	 			 		command="<?php echo tep_href_link($file_name,'action=get_category_details');?>&cID="+cid;
	 	 			 	}else command="<?php echo tep_href_link($file_name,'action=get_details');?>&pID="+id+"&cID="+category_id;		 	 			 	
 	 			   }
 	 			 }else {
 	 			 	if(pre_head && pre_head.style.display=="") {
 	 			 		pre_head.innerHTML="";
 	 			 		pre_head.style.display="none";	
 	 			 	} 	 			 	
 	 			 	if(data_id && data_id.style.display=="")   data_id.style.display="none";
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 			 	 	 	 			 	  	 			
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	} 	 			 	 				
					if(!category_id) {
						if(img_div) img_div.style.visibility="hidden";
						command="<?php echo tep_href_link($file_name,'command=fetch_sub_list');?>&show_order=AN&cID="+cid;
					}else command="<?php echo tep_href_link($file_name,'action=get_details');?>&pID="+id+"&cID="+category_id;						
 	 			 }
 	 			 if(action_type) action_type.value='get_details';
 	 			break;
 	 			case 'new_category':
 	 					if(action_type) action_type.value='new_category';
 	 					if(cid && document.getElementById("img_save_"+cid)) document.getElementById("img_save_"+cid).style.visibility="";
						if(span_details) span_details.style.display='none';
 	 					command="<?php echo tep_href_link($file_name,'action=edit_category');?>&chk_ID="+cid;
 	 			break;
 	 			case 'edit_category':
 	 					if(action_type) action_type.value='edit_category';
 	 					if(document.new_product.product_id) document.new_product.product_id.value="";
 	 					command="<?php echo tep_href_link($file_name,'action=edit_category');?>&cID="+id; 	 	 	 					 	 			
 	 			break;
 	 			case 'delete_category':
 	 					if(action_type) action_type.value='delete_category';
 	 					if(document.new_product.product_id) document.new_product.product_id.value="";
 	 					command="<?php echo tep_href_link($file_name,'action=delete_category');?>&cID="+id; 	 	 	 					 	 			
 	 			break;
				case 'move_category':
 	 					if(action_type) action_type.value='move_category';
 	 					if(document.new_product.product_id) document.new_product.product_id.value="";
 	 					command="<?php echo tep_href_link($file_name,'action=move_category');?>&cID="+id;
 	 			break;
 	 			case 'new_product': 
 	 					if(!category_id && document.getElementById("cPath")) category_id=document.getElementById("cPath").value;
 	 					if(action_type) action_type.value='new';
 						command="<?php echo tep_href_link($file_name,'action=edit_product');?>&cID="+category_id; 
				break; 	 			 	 	
 	 			case 'edit_product':
						description_expand=false;
 	 					if(action_type) action_type.value='edit';
 	 					command="<?php echo tep_href_link($file_name,'action=edit_product');?>&pID="+id+"&cID="+category_id; 	 	 	 					 	 			
				break;
 	 			case 'delete_product':
 	 					if(action_type) action_type.value='delete';
 	 					command="<?php echo tep_href_link($file_name,'action=delete_product');?>&pID="+id+"&cID="+category_id;
 	 			break;
 	 			case 'copy_product':
 	 					if(action_type) action_type.value='copy';
 	 					command="<?php echo tep_href_link($file_name,'action=copy_product');?>&pID="+id+"&cID="+category_id; 	 	 	 					 	 			
 	 			break;
 	 			case 'move_product':
 	 					if(action_type) action_type.value='move';
 	 					command="<?php echo tep_href_link($file_name,'action=move_product');?>&pID="+id+"&cID="+category_id; 	 	 	 					 	 			
 	 			break;
				case 'attrib':
					if(action_type) action_type.value='attrib';
 	 					command="<?php echo tep_href_link($file_name,'action=attrib');?>&pID="+id+"&cID="+category_id;
				break;
				case 'add_attrib':
					  document.location.href="products_attributes.php?command=from_products_setup&product_id="+id+"&category_id="+category_id;
					  command='';
				break;
				case 'pos_down':
				case 'pos_up':
					if(action_type) action_type.value=action;
					var s_order=document.new_product.sort_order;
					if(chk_cid) var cat_id=chk_cid.value;
					if(head) var tbl_tr_obj=head.parentNode.parentNode;
					var pos_cnt=0;																																	
					pos=action;
					command="<?php echo tep_href_link($file_name);?>?pID="+id+"&pos="+category_id+"&action="+pos+"&cPath="+cat_id;					
					if(s_order) s_order.value=pos;
				break;
				case 'category_pos_up':
				case 'category_pos_down':
					if(pre_head && pre_data_id){
						pre_head.style.display="none";
						pre_head.innerHTML="";
						pre_data_id.style.display="";
					}
					if(action_type) action_type.value=action;
					var s_order=document.new_product.category_sort_order;
					if(chk_cid) var cat_id=chk_cid.value;
					var tbl_tr_obj="";
					if(document.getElementById("tr_id_"+cat_id)) tbl_tr_obj=document.getElementById("tr_id_"+cat_id);
					if(tbl_tr_obj && (action=='category_pos_up' && tbl_tr_obj.rowIndex==0) || (action=='category_pos_down' && tbl_tr_obj.parentNode.rows.length==parseInt(tbl_tr_obj.rowIndex)+1)) return;
					var pos_cnt=0;					
					command="<?php echo tep_href_link($file_name);?>?pos="+category_id+"&action="+action+"&cPath="+cat_id;										
					if(s_order) s_order.value=action;
				break;
				case 'set_flag':
					if(img_src){ 	 					
 	 					var data_flag_img=document.getElementById("data_flag_"+document.getElementById("cPath").value+"_"+document.getElementById("product_id").value); 	 					
 	 					var head_flag_img=document.getElementById("head_flag_"+document.getElementById("cPath").value+"_"+document.getElementById("product_id").value);
 	 					if(img_src+"template/icon_active.gif"==data_flag_img.src){
 	 						data_flag_img.src=head_flag_img.src=img_src+"template/icon_inactive.gif"; 	 						 	 						
 	 						command="<?php echo tep_href_link($file_name,'action=setflag');?>&pID="+document.getElementById("product_id").value+"&flag=0";
 	 					}else if(img_src+"template/icon_inactive.gif"==data_flag_img.src){
 	 						data_flag_img.src=head_flag_img.src=img_src+"template/icon_active.gif";
 	 						command="<?php echo tep_href_link($file_name,'action=setflag');?>&pID="+document.getElementById("product_id").value+"&flag=1";
 	 					}
 	 				}
				break;
				case 'close':
 	 			  if(head && data_id){
 	 			  	head.style.display="none";
 	 			  	head.innerHTML="";
 	 			  	data_id.style.display="";
 	 			  	command="";
 	 			  }
				break;
 	 		} 	 	
 	 		if(command!="") do_get_command(command);
 	 	} 	 
	  }
	  function print_details(action,result){
 	 	var no_result="";
 	 	if(result.substr(0,15)=='No Record Found') no_result="No Record Found";
 	 	else if(result!='' && result.length>0 && action!='edit' && result.substr(0,15)!='No Record Found'){ 	 		 	 		
			splt_str=result.split("{}");
 	 		var  categories_id="";
 	 		var  categories_name=""; 	 		 								 	 		
 	 		var  product_id="";
			var  product_name="";
			var  product_description="";
			var  product_quantity="";
			var  product_price="";
			var  product_date_added="";
			var  product_last_modified="";		
			var  product_status="";			
			var  product_image="";			
			var  sort_order="";
			var  product_date_available="";
									
 	 		categories_id=splt_str[0];
 	 		categories_name=splt_str[1]; 		
 	 		product_id=splt_str[2];
			product_name=splt_str[3];
			product_description=splt_str[4];
			product_quantity=splt_str[5];
			product_price=splt_str[6];
			product_date_added=splt_str[7];
			product_last_modified=splt_str[8];
			product_status=splt_str[9];
			product_image=splt_str[10];
			sort_order=splt_str[11];
			product_date_available=splt_str[12];
 	 	}
 	 	var c_obj=document.getElementById("cPath");
 		if(document.new_product && document.new_product.product_id) var id=document.new_product.product_id.value;
 		if(document.new_product && c_obj) var category_id=c_obj.value;
 		var span_details=document.getElementById("span_details");
 		var head=document.getElementById("head_"+id+"_"+category_id);
 		var data_id=document.getElementById("data_"+id+"_"+category_id);
 		var res_display=document.getElementById("res_display");
		var img_save=document.getElementById("img_save");
		if(img_save) img_save.style.visibility="";
		var require_image=product_image;
		if("<?php echo $file_name;?>"=='products_mainpage.php') require_image='small/'+product_image;
 	 	switch(action){
 	 		case 'get_details':
 	 		if(head  && no_result!="")
				head.innerHTML=no_result;
 	 		else if(head && no_result==""){
	 	 		if(head && data_id)	{
					head.style.display="";
					data_id.style.display="none";
				}
				var row_total=0;
				var row_index=0
				if(document.getElementById("id_product_list_"+category_id)) row_total=document.getElementById("id_product_list_"+category_id).rows.length;				
				if(data_id.parentNode.parentNode) row_index=data_id.parentNode.parentNode.rowIndex;
				if(data_id) data_id.innerHTML='<img id="head_flag_'+category_id+'_'+product_id+'" src="images/template/'+((product_status==0)?'icon_inactive.gif':'icon_active.gif')+'" alt="" border="0"><img src="images/pixel_trans.gif" alt="" border="0" height="10" width="5">'+product_name;				
				head.innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0' class='openContent'>"+
				'<tr heigth="40" class="openContent_top">'+
				  '<td width="10"></td>'+
				  '<td width="20" valign="middle" align="center"><img id="data_flag_'+category_id+'_'+product_id+'" onmouseover="javascript:this.style.cursor=\'pointer\';" onclick="javascript:do_actions(\'set_flag\''+','+product_id+','+category_id+');" src="images/template/'+((product_status==0)?"icon_inactive.gif":"icon_active.gif")+'"></td>'+
				  '<td width="40" valign="middle" align="center">'+((sort_order!= "")?'<a href="javascript:do_actions(\'pos_up\','+product_id+','+sort_order+');"><img '+((row_index==0)?'style="display:none;"':'')+' id="up_'+product_id+'" alt="Up" title="Up" border="0" src="images/template/img_arrow_up.gif"></a>&nbsp;<a href="javascript:do_actions(\'pos_down\','+product_id+','+sort_order+');"><img '+((row_index==(row_total-1))?'style="display:none;"':'')+' id="down_'+product_id+'" alt="Down" title="Down" border="0" src="images/template/img_arrow_down.gif"></a>':'')+'</td>'+
				  '<td align="left" onclick="javascript:do_actions(\'close\''+','+product_id+','+category_id+');" style="cursor:pointer;cursor:hand;" valign="middle" width="390" class="main">'+product_name+'</td>'+
				  "<td width='200' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:100px;height:30px;display:inline;position:relative;'>"+
				  	 "<tr class='img_move' id='img_ids'>"+
						 "<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+(("<?php echo $file_name;?>"=="events_mainpage.php")?"<td width='10%' onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);' onclick='javascript:change_class(this,1);do_actions("+'go_session'+","+product_id+","+category_id+");'><img alt='Sessions' title='Sessions' id='img_move' src='images/template/img_message.gif'></td>":"")+
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'edit_product\''+','+product_id+','+category_id+');"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'+
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'delete_product\''+','+product_id+','+category_id+');"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>'+
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'copy_product\''+','+product_id+','+category_id+');"><img alt="Copy" title="Copy" id="img_copy" src="images/template/img_copy.gif"></td>'+					
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'move_product\''+','+product_id+','+category_id+');"><img alt="Move" title="Move" id="img_move" src="images/template/img_move.gif"></td>'+
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'attrib\''+','+product_id+','+category_id+');">'+((attrib_icon)?"<img alt='Attributes' title='Attributes' id='img_attributes' src='images/template/img_attrib.gif'>":"")+'</td>'+						 					 
						 '<td width="10%" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);" onclick="javascript:change_class(this,1);do_actions(\'add_attrib\''+','+product_id+','+category_id+');"><img alt="Add Attribute" title="Add Attribute" id="img_sms" src="images/template/img_sms.gif"></td>'+
						 '<td class="cell_bg_popm_right" width="10">&nbsp;</td>'+
				  	 "</tr>"+
				  	"</table>"+
				  "</td>"+
				  '<td width="330" align="right" onclick="javascript:do_actions(\'close\''+','+product_id+','+category_id+');" style="cursor:pointer;cursor:hand;">&nbsp;</td>'+
				  "<td width='90' align='right'>&nbsp;"+
					  "<span  id='img_save' name='img_save' style='visibility:hidden'><input type='image' id='product_save_button_"+product_id+"' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;"+
					  '<a href="javascript:do_actions(\'get_details\''+','+product_id+','+category_id+')"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a>&nbsp;&nbsp;</span>'+
				  "</td>"+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
				  "<td colspan='8' class='main'><span id='span_details'>"+
				  	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='20'>&nbsp;</td>"+
				  			"<td width='130' valign='top' align='left'><img src='../images/"+require_image+"' border='0' width='100'></td>"+
				  			"<td width='300' valign='top'>"+
				  				"<table width='100%' border='0' cellspacing='5' cellpadding='0' class='main'>"+
				  					((product_date_added)?"<tr>"+
				  						"<td align='left' nowrap='nowrap' width='50%' valign='top'><?php echo TEXT_DATE_ADDED;?></td>"+
				  						"<td align='left' nowrap='nowrap' width='50%' valign='top'>"+product_date_added+"</td>"+
				  					"</tr>":"")+
				  					((product_last_modified)?"<tr>"+
				  						"<td align='left' nowrap='nowrap' width='50%'><?php echo TEXT_LAST_MODIFIED;?></td>"+
				  						"<td align='left' nowrap='nowrap' width='50%'>"+product_last_modified+"</td>"+
				  					"</tr>":"")+
				  					((product_quantity>0)?"<tr>"+
				  						"<td align='left' width='50%' nowrap='true'><?php echo TEXT_QUANTITY;?></td>"+
				  						"<td align='left' width='50%' nowrap='true'>"+product_quantity+"</td>":"")+
				  					"</tr>"+
				  					((product_price)?"<tr>"+
				  						"<td align='left' width='50%' nowrap='true'><?php echo TEXT_PRODUCTS_PRICE_INFO;?></td>"+
				  						"<td align='left' width='50%' nowrap='true'>"+product_price+"</td>"+
				  					"</tr>":"")+
				  				"</table>"+
				  			"</td>"+
				  			"<td align='left' valign='top' class='main'><div style='width:100%;height:100;overflow:auto;'>"+
				  			  	product_description	+
				  			"</div></td>"+
				  		"</tr><tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></td></tr>"+
				  	"</table></span>"+
				  "</td>"+
			"</table>";			
			 if(document.getElementById('action_type')) document.getElementById('action_type').value="";
			 block_time=false;
 	 		} 	 	
 	 	break;
 	 	case 'delete_success':			  	    	  	    	
			 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 		
			 }			 				
			 if(res_display){ 	    	 	
 	    	 	res_display.innerHTML="<?php echo TEXT_PRODUCT_DELETED_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 }
			 if(result !='' && result > 0){
				 toggle_category_panel(result,0,true);
				 toggle_category_panel(result,1,true);
			 }
 	 	break;
		case 'attrib_success':
			 if(res_display){
 	    	 	res_display.style.display=""; 	    	 	
 	    	 	res_display.innerHTML="<?php echo TEXT_PRODUCT_ATTRIB_MOVED_SUCCESS;?>"; 	    	 	 	    	 	
 	    	 	if(head && data_id) {
 	    	 		head.style.display="none";
 	    	 		data_id.style.display="";
 	    	 	} 	    	 	 
 	    	 }
		break;	 
 	 	case 'copy_error':
 	 	case 'copy_success': 	 		 
 	    	 if(res_display){ 	    	 	
 	    	 	var res="";
 	    	 	if(action=='copy_error') {
 	    	 		res_display.style.display=""; 	    	 		
 	    	 		res_display.innerHTML="<?php echo ERROR_CANNOT_LINK_TO_SAME_PRODUCT_CATEGORY;?>";
 	    	 	}else if(action=='copy_success') { 	    	 		 	    	 		 	    	 		 
 	    	 		res_display.innerHTML="<?php echo TEXT_PRODUCT_COPIED_SUCCESS;?>";
 	    	 		res_display.style.display=""; 	    	 			  	 		    
	  	 		    if(result==category_id){
	  	 		    	toggle_category_panel(result,0,true);	  	 		    	  	 		    	  	 		    	  	 		    
	  	 		    	toggle_category_panel(result,1,true);
	  	 		    }else
	  	 		    	toggle_category_panel(result,0);	  	 		    	  	 		    	  	 		    	  	 		    	  	 		    	
	  	 		    
 	    	 	}  	    	 	
 	    	 	if(head && data_id) {
 	    	 		head.style.display="none";
 	    	 		data_id.style.display="";
 	    	 	} 	    	 	 
 	    	 }
 	 	break;
 	    case 'move_success': 	    	 	    	  	    	 
 	    	 if(res_display){ 	    	 	 	    	 	
 	    	 	//toggle_category_panel(result,0,true);	  	 		    	  	 		    	  	 		    	  	 		    
	  	 		//toggle_category_panel(result,1,true);
 	    	 	if(result!=category_id){	  	 		
	  	 		    toggle_category_panel(category_id,0,true);
	  	 		    toggle_category_panel(result,0);
 	    	 	}
 	    	 	res_display.innerHTML="<?php echo TEXT_PRODUCT_MOVED_SUCCESS;?>";
 	    	 	res_display.style.display=""; 	    	 	
 	    	 } 	    	 
 	    break;
 	    case 'category_sort_order_success':
		case 'category_sort_order_error':
			if(document.new_product.category_sort_order) var s_order=document.new_product.category_sort_order.value;
			var row_total=0;
			var row_index=0;
			if(action=='category_sort_order_success'){
			   if(document.getElementById("tr_id_"+category_id)) {
				var tbl_obj=document.getElementById("tr_id_"+category_id);
				var up_href=document.getElementById("category_up_"+category_id);
			    var down_href=document.getElementById("category_down_"+category_id);			    
			    if(up_href && down_href && result>0){
					up_href.href="javascript:do_actions('category_pos_up',"+category_id+","+result+")";
					down_href.href="javascript:do_actions('category_pos_down',"+category_id+","+result+")";
			    }
				var x=1;
				if(s_order && s_order!="" && s_order=="category_pos_up") x=-1;								
				var row=tbl_obj;
				var index=row.rowIndex;
				var count=tbl_obj.parentNode.rows.length;				
				if (x==-1 && index==0) return;
				if (x==1 && index==count-1) return;
				if (x==-1){
				   row.parentNode.insertBefore(row,row.parentNode.rows[index-1]);
				} else {
					if (index==row.parentNode.rows.length-2)
						row.parentNode.appendChild(row);
					else
						row.parentNode.insertBefore(row,row.parentNode.rows[index+2]);
				}																 							
  		      }
  		      row_total=(count)-1;				
			  row_index=tbl_obj.rowIndex;
			  up_href.style.display=down_href.style.display="";
  		      if(row_index==0) up_href.style.display="none";
			  else if(up_href && row_index>0 && row_index<row_total) up_href.style.display="";
			  if(row_index==row_total && down_href) down_href.style.display="none";
			  else if(row_index>0 && row_index!=row_total && down_href) down_href.style.display="";			   			   					            	            	      		               	      	    	 	 			  
			}else if(action=='category_sort_order_error'){
				res_display.style.display=""; 	    	 	
			    res_display.innerHTML="<?php echo ERROR_IN_DATABASE_TRY_AGAIN;?>"; 	    	 	 	    	 	 	    	 	 	    	 	 
			}
			if(img_save) img_save.style.visibility="hidden";    					
		break; 	     	    			
		case 'sort_order_success':
		case 'sort_order_error':
			if(document.new_product.sort_order) var s_order=document.new_product.sort_order.value;
			if(img_save) img_save.style.visibility="hidden";
			var row_total=0;
			var row_index=0
			if(action=='sort_order_success'){			  			   
			   if(head)  {
				var tbl_obj=head.parentNode.parentNode;				
				var up_href=document.getElementById("up_"+id);
			    var down_href=document.getElementById("down_"+id);
			    if(up_href && down_href && result>0){
					up_href.parentNode.href="javascript:do_actions('pos_up',"+id+","+result+")";
					down_href.parentNode.href="javascript:do_actions('pos_down',"+id+","+result+")";
			    }
				var x=1;
				if(s_order && s_order!="" && s_order=="pos_up") x=-1;								
				var row=tbl_obj;
				var index=row.rowIndex;
				var count=tbl_obj.parentNode.rows.length;
				if (x==-1 && index==0) return;
				if (x==1 && index==count-1) return;
				if (x==-1){
				   row.parentNode.insertBefore(row,row.parentNode.rows[index-1]);
				} else {
					if (index==row.parentNode.rows.length-2)
						row.parentNode.appendChild(row);
					else
						row.parentNode.insertBefore(row,row.parentNode.rows[index+2]);
				}																 							
  		      }
  		      if(document.getElementById("id_product_list_"+category_id)) row_total=(document.getElementById("id_product_list_"+category_id).rows.length)-1;				
			  if(data_id && data_id.parentNode.parentNode) row_index=data_id.parentNode.parentNode.rowIndex;
			  if(up_href && down_href) {
			  	up_href.style.display=down_href.style.display="";
  		      	if(row_index==0) up_href.style.display="none";
			  	else if(row_index>0 && row_index<row_total) up_href.style.display="";
			  	if(row_index==row_total) down_href.style.display="none";
			  	else if(row_index>0 && row_index!=row_total) down_href.style.display="";
			  }
			}else if(action=='sort_order_error'){
				res_display.style.display=""; 	    	 	
			    res_display.innerHTML="<?php echo ERROR_IN_DATABASE_TRY_AGAIN;?>"; 	    	 	 	    	 	 	    	 	 	    	 	 
			}
		break;		
		case 'new_product':						
			var pID=0;
			if(document.getElementById("product_id")) pID=document.getElementById("product_id").value;
			if(categories_id){
				if(document.getElementById("id_product_list_"+categories_id)){
					var tab_obj=document.getElementById("id_product_list_"+categories_id);
					var row=tab_obj.insertRow(tab_obj.rows.length);
					var row_cell=row.insertCell(0);
					row_cell.innerHTML='<div id="data_'+product_id+'_'+categories_id+'"><img src="images/template/'+((product_status==0)?'icon_inactive.gif':'icon_active.gif')+'" border="0"><img src="images/pixel_trans.gif" alt="" border="0" height="10" width="5">'+product_name+'</div><div id="head_'+product_id+'_'+categories_id+'" style="display:none;"></div>';												
				}
				if(row){
					row.onclick=function () {((document.getElementById("head_"+product_id+"_"+categories_id) && document.getElementById("head_"+product_id+"_"+categories_id).style.display=='none')?do_actions('get_details',product_id,categories_id):'')};
					row.style.height="15px";
					if(row.rowIndex%2==0) row.className="dataTableRowOdd";
					else row.className="dataTableRowEven";
					row.onmouseover=function (){rowOverEffect(this)};
					row.onmouseout=function (){rowOutEffect(this)};
				}
				if(res_display){
		    	 	res_display.innerHTML="<?php echo TEXT_PRODUCT_INSERTED_SUCCESS;?>";
	 	    	 	res_display.style.display=""; 	    	 	
 				}
			}
			if(!document.getElementById("data_"+pID+"_"+categories_id)) do_actions('get_details',categories_id);
			else do_actions('get_details',pID,categories_id);
		break;
		case 'copy_details':			
			if(result=='copy_success') result="<?php echo TEXT_PRODUCT_COPIED_SUCCESS;?>";
			if(res_display){							
				res_display.innerHTML=result;
				res_display.style.display="";
			}
		break;
		case 'new_main_category':
		case 'new_category':			
			if(result!="") result_splt=result.split('{}');
			if(document.getElementById("new_category")) document.getElementById("new_category").style.display="none";						
			var img_ids = document.getElementById('img_ids');
			var p_id="";
			var c_name="";
			var c_id="";
			if(result_splt[0]) p_id=result_splt[0];
			if(result_splt[1]) c_name=result_splt[1];
			if(result_splt[2]) c_id=result_splt[2];		
			var tbl_obj=document.getElementById("search_result_details").childNodes[0];
			if(document.getElementById("search_result_details").childNodes.length>1) tbl_obj=document.getElementById("search_result_details").childNodes[1];
			if(action=='new_category' && c_id>0){				
				var tbl_obj=document.getElementById("parent_"+c_id);
				var tbl_obj=document.getElementById("tr_id_"+c_id).parentNode;
				if(document.getElementById("span_details_"+c_id)) document.getElementById("span_details_"+c_id).innerHTML="";
				toggle_category_panel(c_id,0,true);
				toggle_category_panel(c_id,1,true);
				return;	
			}
			var row_obj=tbl_obj.insertRow(tbl_obj.rows.length);	
			var row_cell=row_obj.insertCell(0);
				row_cell.innerHTML='<table id="parent_'+p_id+'" border="0" cellpadding="10" cellspacing="0" width="100%">'+
				'<tr id="tr_id_'+p_id+'">'+
				'<td valign="top">'+
				'<input id="panel_'+p_id+'_pgno" value="1" type="hidden">'+
				'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
					'<tbody><tr height="20">'+
					'<td>'+
					'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						'<tbody><tr>'+
							'<td class="contentTitle1" style="cursor: pointer;" onclick="javascript:toggle_category_panel('+p_id+',1);"><span id="span_category_'+p_id+'" style="background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; padding-right: 5px;">'+c_name+'</span></td><td align="right" width="15"><a href="javascript:toggle_category_panel('+p_id+',0);"><img src="images/template/panel_down.gif" id="panel_'+p_id+'_img" border="0"></a></td>'+
						'</tr>'+
					'</tbody></table>'+
					'</td>'+
				'</tr><tr height="5"><td></td>'+
				'</tr><tr><td style="padding-left: 15px;">'+
				'<div id="panel_'+p_id+'_content" style="display: none;"></div>'+				
				'</td></tr></tbody></table></td></tr></table>';
				if(action=='new_main_category' && category_id>0) toggle_category_panel(category_id,0,true);
					do_actions('get_details');
		break;
		case 'edit_category':
			if(result!=""){
				result_splt=result.split("{}");
				if(result_splt[0] && document.getElementById("span_category_"+result_splt[0]))
				document.getElementById("span_category_"+result_splt[0]).innerHTML=result_splt[1];
				if(result_splt[2]!="" && document.getElementById("span_details_"+result_splt[0])){
					document.getElementById("span_details_"+result_splt[0]).innerHTML=result_splt[2];
					if(document.getElementById("img_save_"+result_splt[0])){
						var obj=document.getElementById("img_save_"+result_splt[0]).parentNode;						
						if(obj && obj.childNodes[5]) obj.childNodes[5].innerHTML="&nbsp;&nbsp;"+result_splt[1];
						document.getElementById("img_save_"+result_splt[0]).style.visibility="hidden";
						var tr1=document.getElementById("img_ids");
						if(document.getElementById("image_type")) document.getElementById("image_type").value="true";
						var imgsrc;
						var node;
						if(tr1)
						for(var j=0;j<tr1.cells.length;j++){
							td=tr1.cells[j];
							imgsrc='';
							    for(var i=0;i<td.childNodes.length;i++){
								  node=td.childNodes[i];
								  if(node.tagName=='IMG'){
									imgsrc=node.src;
										if(imgsrc==img_src+'template/img_edit_hover.gif')
										   td.childNodes[i].src = img_src+'template/img_edit.gif';
										else if(imgsrc==img_src+'template/img_trash_hover.gif')
										   td.childNodes[i].src = img_src+'template/img_trash.gif';
										else if(imgsrc==img_src+'template/img_copy_hover.gif')
										   td.childNodes[i].src = img_src+'template/img_copy.gif';
										else if(imgsrc==img_src+'template/img_move_hover.gif')
										   td.childNodes[i].src = img_src+'template/img_move.gif';
										else if(imgsrc==img_src+'template/img_attrib_hover.gif')
										   td.childNodes[i].src = img_src+'template/img_attrib.gif';
										break;
							      }
							  }
					   	  }
				  	 }
			  	 }
			}
		break;
		case 'delete_category_success':
			if(result!=""){
				if(document.getElementById("tr_id_"+result)){
					var tbl_obj=document.getElementById("tr_id_"+result).parentNode;															 				 				 				
					if(tbl_obj && result>0 && document.getElementById("tr_id_"+result)) tbl_obj.deleteRow(document.getElementById("tr_id_"+result).rowIndex);
				}
			 	if(res_display){
 	    	 		res_display.innerHTML="<?php echo TEXT_CATEGORY_DELETED_SUCCESS;?>";
 	    	 		res_display.style.display="";
 	    	 	}	
			}
		break;
		case 'move_category_success':
 			if(result!=""){
			 	var category_id=0;
			 	if(c_obj) category_id=c_obj.value;
			 	var tbl_obj=document.getElementById("tr_id_"+category_id).parentNode;
				if(tbl_obj) tbl_obj.deleteRow(document.getElementById("tr_id_"+category_id).rowIndex);								
 	    	 	if(result!==category_id){
	  	 		    toggle_category_panel(category_id,0,true);
	  	 		    toggle_category_panel(result,0);
 	    	 	}
			 	if(res_display){ 	    	 	
 	    	 		res_display.innerHTML="<?php echo TEXT_CATEGORY_MOVED_SUCCESS;?>";
 	    	 		res_display.style.display="";
 	    	 		if(result==0) reset_search();
 	    	 	}
			}
		   break;
		   
		case 'move_category_failure':
 			if(result!=""){
			 	var category_id=0;
			 	if(c_obj) category_id=c_obj.value;
			 	var tbl_obj=document.getElementById("tr_id_"+category_id).parentNode;
				if(tbl_obj) tbl_obj.deleteRow(document.getElementById("tr_id_"+category_id).rowIndex);								
 	    	 	if(result!==category_id){
	  	 		    toggle_category_panel(category_id,0,true);
	  	 		    toggle_category_panel(result,0);
 	    	 	}
			 	if(res_display){ 	    	 	
 	    	 		res_display.innerHTML="<?php echo ERROR_CANNOT_MOVE_CATEGORY_TO_PARENT; ?>";
 	    	 		res_display.style.display="";
 	    	 		if(result==0) reset_search();
 	    	 	}
			    location.href='<?php echo FILENAME_PRODUCTS_MAINPAGE; ?>';
			}
		   break;
		   
 	 	}
		if(document.getElementById('res_display') && document.getElementById('res_display').style.display=="") setTimeout("document.getElementById('res_display').style.display='none'",2500);
 	 	clearTimeout();		
	  } 
   function change_class(obj,eve){ 		
		 	var action_type=""; 
			var img_get_src=obj.childNodes[0];					
		 	var img_type="";
		 	if(eve==2 && obj) obj.style.cursor='pointer';
			if(document.getElementById("action_type")) action_type=document.getElementById("action_type").value;		   
		    if(document.getElementById("image_type").value=='true') action_type='';										
			var ret_type=false;
			var img_ids = document.getElementById('img_ids');
			if(img_get_src){
				if(img_get_src.src==img_src+'template/img_new.gif') { 
					if((action_type=="edit" || action_type=="new_category") && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_new_hover.gif';
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_new_hover.gif'){ 	
					if(action_type=="edit" || action_type=="new_category") return;
					else img_get_src.src=img_src+'template/img_new.gif';
				}	
				if(img_get_src.src==img_src+'template/img_edit.gif') {
					if((action_type=="edit" || action_type=="edit_category") && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_edit_hover.gif';
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif'){ 	
					if(action_type=="edit" || action_type=="edit_category") return;
					else img_get_src.src=img_src+'template/img_edit.gif';
				}
				if(img_get_src.src==img_src+'template/img_trash.gif') {
					if((action_type=="delete" || action_type=="delete_category") && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_trash_hover.gif';					
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif'){ 				
					if(action_type=="delete" || action_type=="delete_category") return;
					else img_get_src.src=img_src+'template/img_trash.gif';
				}				
				if(img_get_src.src==img_src+'template/img_copy.gif') {
					if(action_type=="copy" && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_copy_hover.gif';					
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_copy_hover.gif'){ 				
					if(action_type=="copy") return;
					else img_get_src.src=img_src+'template/img_copy.gif';
				}
				if(img_get_src.src==img_src+'template/img_attrib.gif') {
					if(action_type=="attrib" && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_attrib_hover.gif';
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_attrib_hover.gif'){
					if(action_type=="attrib") return;
					else img_get_src.src=img_src+'template/img_attrib.gif';
				}
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if((action_type=="move" || action_type=="move_category") && eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_move_hover.gif';
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif'){
					if(action_type=="move" || action_type=="move_category") return;
					else img_get_src.src=img_src+'template/img_move.gif';
				}
				 if(img_get_src.src==img_src+'template/img_sms.gif') {
					if( eve==1 || eve==2)
				 		img_get_src.src=img_src+'template/img_sms_hover.gif';
		    	}else if(eve==3 && img_get_src.src==img_src+'template/img_sms_hover.gif'){
					 img_get_src.src=img_src+'template/img_sms.gif';
				}
		  }
	  }
	  function product_search_validation(){
		var product_search=document.getElementById('product_search').value;
		if(product_search!=''){
			do_get_command('<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'command=product_search&product_search='); ?>'+product_search);
			document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
		}
		return false;
	}
	function product_searching(){
		var product_search=document.getElementById('product_search').value;
		if(product_search!=''){
			do_get_command('<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'command=product_search&product_search='); ?>'+product_search);
			document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
		}
	}
	function reset_search(){
	document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
	do_get_command('<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'command=reset_search'); ?>');
	document.getElementById('product_search').value="";
	}
 
 	function do_jump_list(nopen_ids){
	document.getElementById('product_search').value='';
		if (open_ids.join(",")==nopen_ids) return;
		nopen_idsb=nopen_ids.split(",");
		nopen_ids=nopen_ids.split(",");
		for (icnt=0,n=nopen_ids.length;icnt<n;icnt++){
			if(icnt>=open_ids.length || nopen_ids[icnt]!=open_ids[icnt]){
				open_cat=nopen_ids[icnt];
				nopen_ids=nopen_ids.slice(icnt);
				break;
			}
		}
		if (open_ids[icnt]) hide_cat_panel(open_ids[icnt]);
		if(icnt<=open_ids.length && open_ids[nopen_ids.length-1]==nopen_ids[nopen_ids.length-1]) {
			hide_cat_panel(open_ids[nopen_ids.length]);
			open_ids=nopen_idsb;
		} else {
			open_ids=nopen_idsb;
			show_cat_panel(open_cat);
			do_page_fetch('fetch_sub_list_open','',open_cat,1,icnt);
		}
	}
  	function do_page_fetch(cmd,params,category,page,level){		
		command="<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'do=1');?>&command="+cmd;		
		if(document.getElementById("img_new") && category){
			document.getElementById("img_new").href="javascript:do_actions(\'new_category\',"+category+");";
			if(document.getElementById("link_category")) document.getElementById("link_category").href="javascript:do_actions(\'new_category\',"+category+");";
			if(document.getElementById("link_product")) document.getElementById("link_product").href="javascript:do_actions(\'new_product\',"+category+");";
		}		
		if(cmd=="fetch_sub_list" && document.getElementById("cPath") && document.getElementById("product_id")) {
			c_ids=document.getElementById("cPath").value;
			p_ids=document.getElementById("product_id").value;
			if(document.getElementById("data_"+p_ids+"_"+c_ids)) document.getElementById("data_"+p_ids+"_"+c_ids).style.display="";
			if(document.getElementById("head_"+p_ids+"_"+c_ids)) {
				document.getElementById("head_"+p_ids+"_"+c_ids).style.display="none";	
				document.getElementById("head_"+p_ids+"_"+c_ids).innerHTML="";
			}			
			if(c_ids && document.getElementById("category_details_"+c_ids)) document.getElementById("category_details_"+c_ids).style.display="none";								
		}				
		if(document.getElementById("cPath")) document.getElementById("cPath").value=category;
		//if(params!='') document.getElementById("show_sort_order").value=params;
		show_order=document.getElementById("show_sort_order");
		if ((cmd=="fetch_sub_list" || cmd=="fetch_sub_list_open") && show_order.value!=""){
			if(document.getElementById('new_category'))document.getElementById('new_category').innerHTML = "";
			//command=command+"&cID="+category+"&level="+ level+"&show_order="+show_order.value;
			command=command+"&cID="+category+"&level="+ level+"&show_order="+show_order.value;
			if (cmd=="fetch_sub_list_open") command=command+"&open_ids="+open_ids.join(",");
			if(document.getElementById("panel_"+category+"_content")) document.getElementById("panel_"+category+"_content").innerHTML=document.getElementById("ajax_load_img").innerHTML;
		} else if (cmd=="fetch_all_list"){ 
			show_order.value=params;
			command=command+"&cID=-1&page=1&level=1&open_ids="+open_ids.join(",")+"&show_order="+params;
			hide_cpopup(true);
			 if(!document.getElementById("panel_"+open_ids[0]+"_content")){
			 	  cmd = "do_sort_list" ;
				  command="<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'do=1');?>&command="+cmd;
				  command=command+"&cID=-1&page=1&level=1&open_ids="+open_ids.join(",")+"&show_order="+params;
			}else	
				document.getElementById("panel_"+open_ids[0]+"_content").innerHTML=document.getElementById("ajax_load_img").innerHTML;
				
		} else {
			if (page=='next') {
				pgCombo=document.getElementById("page_"+category);
				selIndex=pgCombo.selectedIndex+1;
				if (selIndex>=pgCombo.options.length) return;
				pgCombo.selectedIndex=selIndex;
			} else if (page=='prev'){ 
				pgCombo=document.getElementById("page_"+category);
				selIndex=pgCombo.selectedIndex-1;
				if (selIndex<0) return;
				pgCombo.selectedIndex=selIndex;
			}  
			page=document.getElementById("page_"+category).value;
			command=command+'&page='+page+'&'+params+"&show_order="+show_order.value;
			document.getElementById("panel_"+category+"_contentp").innerHTML=document.getElementById("ajax_load_img").innerHTML;
		}
		// 
			var c_ids=0;
			var p_ids=0;
			if(document.getElementById("cPath")) c_ids=document.getElementById("cPath").value;
			if(document.getElementById("product_id")) p_ids=document.getElementById("product_id").value;				
			if(document.getElementById("data_"+p_ids+"_"+c_ids)) document.getElementById("data_"+p_ids+"_"+c_ids).style.display="";
			if(document.getElementById("head_"+p_ids+"_"+c_ids)) {
				document.getElementById("head_"+p_ids+"_"+c_ids).style.display="none";
				document.getElementById("head_"+p_ids+"_"+c_ids).innerHTML="";	
			}
		//
		do_get_command(command);
		
	}
  var previous_non_categories_products_id='';
  function do_result(result){ 
	var token=result.split('^');
	switch(token[0]){
	case 'product_search':
		document.getElementById('search_result_details').innerHTML=token[1];
		return;
		break;
	case 'reset_search':
		document.getElementById('search_result_details').innerHTML=token[1];
		return;
		break;
	case 'load_non_category_details':
		var non_products_id=token[1];
		document.getElementById('non_category_product_'+non_products_id).style.display='none';
		document.getElementById('ajax_non_category_product_'+non_products_id).style.display='';
		document.getElementById('ajax_non_category_product_'+non_products_id).innerHTML=token[2];
		return;
		break;
	case 'delete_non_product':
		document.getElementById('non_category_product').innerHTML=token[1];
		return;
		break;
	}			
		if (result=="") return; 
close_non_product_category(previous_non_categories_products_id);
		if(result.substr(0,7)=='command'){
			result_splt=result.split("{}");
			command="";
			category_id="";
			for (icnt=0;icnt<result_splt.length;icnt++){
				command_splt=result_splt[icnt].split("||");
				switch (command_splt[0]){
					case 'category':
						category_id=command_splt[1];						

						break;
					case 'command':
						command=command_splt[1];
						break;
					case "page":
						if(document.getElementById("panel_"+category_id+"_pgno"))
						   document.getElementById("panel_"+category_id+"_pgno").value=command_splt[1];
						break;
					case "result":						
						if (command=="fetch_sub_products"){
							document.getElementById("panel_"+category_id+"_contentp").innerHTML=command_splt[1];
						} else { 				
							if(!document.getElementById("panel_"+category_id+"_content")){ 
								document.getElementById("search_result_details").innerHTML=command_splt[1];
							}else{ 
							    document.getElementById("panel_"+category_id+"_content").innerHTML=command_splt[1];
								}
						}
				}
			}
	 	 }else  if(result.length>1){
		 	var res_display=document.getElementById("res_display");
		 	var span_product="";
		 	var span_category="";
		 	var action_type="";
		 	if(document.getElementById("cPath")) var category_id=document.getElementById("cPath").value;		 			 			 	
		 	if(document.getElementById("product_id").value) var pID=document.getElementById("product_id").value;
		 	if(document.getElementById("action_type"))  action_type=document.getElementById("action_type").value;
		 	if(document.getElementById("span_details_"+category_id)) span_category=document.getElementById("span_details_"+category_id);
		 	if(document.getElementById("span_details")) span_product=document.getElementById("span_details");
		 	if(document.getElementById("img_save")) var img_save=document.getElementById("img_save");
		 	if(document.getElementById("img_save_"+category_id)) var img_category=document.getElementById("img_save_"+category_id);
		 	if(action_type=='new_category' && document.getElementById("search_result_details")&&  result!="" && document.getElementById("new_category")){
				if(pID && action_type=='new_category' && document.getElementById("span_details") && span_category.innerHTML=="") {
					document.getElementById("span_details").innerHTML=result;
					document.getElementById("span_details").style.display="";
					if(img_save) img_save.style.visibility="";
					if(img_category) img_category.style.visibility="hidden";
				}else if(action_type=='new_category'  && span_category.innerHTML!=""){
					if(span_category) span_category.innerHTML=result;
					else if(document.getElementById("new_category")){
						document.getElementById("new_category").innerHTML=result;
						document.getElementById("new_category").style.display = "";
						if(document.getElementById("img_save_close_category")) document.getElementById("img_save_close_category").style.display="";
					}
					if(document.getElementById('save_button_'+category_id)) document.getElementById('save_button_'+category_id).style.display = '';
				}else if(result.indexOf("^")>0 || result.indexOf("{}")>0 || result.indexOf("||")>0 || document.getElementById("span_details_"+category_id) && document.getElementById("span_details_"+category_id).style.display==""){}
				else{
					document.getElementById("new_category").innerHTML=result;
					document.getElementById("new_category").style.display = "";
					if(document.getElementById("img_save_close_category")) document.getElementById("img_save_close_category").style.display="";					
				}
			}
		 	result_split=result.split('^');
		 	res=result;
		 	splt="";
		 	if(result_split.length>1){
		 		splt=result_split[0];
			 	res=result_split[1];
		 	 }		 	 
		    if(splt=='get_details') print_details('get_details',res);
		    else if(splt=='service_search')
				document.getElementById('search_result_details').innerHTML=res;			
			else if(splt=='reset_search')
				document.getElementById('search_result_details').innerHTML=res;			
			 else if(splt=='new_main_category') print_details('new_main_category',res);
			 else if(splt=='new_category') print_details('new_category',res);
			 else if(splt=='edit_category') print_details('edit_category',res);			 	
			 else if(splt=='move_category_success') print_details('move_category_success',res);
			 else if(splt=='sort_order_success') print_details('sort_order_success',res);
			 else if(splt=='sort_order_error') print_details('sort_order_error',res);
			 else if(splt=='delete_category_success') print_details('delete_category_success',res);
			 else if(splt=='category_sort_order_success') print_details('category_sort_order_success',res);
			 else if(splt=='category_sort_order_error') print_details('category_sort_order_error',res);			 
			 else if(splt=='new_product') print_details('new_product',res);			 				 
			 else if(splt=='copy_details') print_details('copy_details',res);
			 else if(splt=='move_success') print_details('move_success',res);
			 else if(splt=='delete_success') print_details('delete_success',res);
			 else if(splt=='copy_error') print_details('copy_error',res);
			 else if(splt=='copy_success') print_details('copy_success',res);
			 else if(splt=='move_category_failure') print_details('move_category_failure',res);
			
			 else if(result.substr(0,14)=='attrib_success') print_details('attrib_success',result.substr(14));	
			 		 
			 else if(splt=='diff_category') {
	 	 			result_splt=res.split('#'); 	 			
	 	 			if(result_splt[0]>0)  toggle_category_panel(result_splt[0],0,true);
	 	 	}else if(res!="" && (!document.getElementById("data_"+pID+"_"+category_id)) || action_type=='edit_category' || action_type=='delete_category' || action_type=='move_category') {
					// For Services Present on Category
					if(document.getElementById('save_button_'+category_id))
					if(action_type == 'delete_category' && document.getElementById('has_services_'+category_id) && document.getElementById('has_services_'+category_id).value >0)document.getElementById('save_button_'+category_id).style.display = 'none';
					else document.getElementById('save_button_'+category_id).style.display = '';
					if(span_category) span_category.innerHTML=res;
					else if(document.getElementById("new_category")){
						document.getElementById("new_category").innerHTML=res;
						document.getElementById("new_category").style.display = "";
						if(document.getElementById("img_save_close_product")) document.getElementById("img_save_close_product").style.display="";
						if(document.getElementById("img_save_close_category")) document.getElementById("img_save_close_category").style.display="";
					}
					if(splt=='new') {
						if(document.getElementById("action_type")) document.getElementById("action_type").value='new';
						else if(document.getElementById("img_save_"+category_id)) document.getElementById("img_save_"+category_id).style.visibility="visible";
					}
	 	 	}else if(action_type=='new' || action_type=='edit' || action_type=='delete' || action_type=='copy' || action_type=='move' || action_type=='attrib'){		 	 		
		 	 		if(span_product && span_category && span_category.innerHTML==""){
		 	 			span_product.innerHTML=res;
		 	 			if(img_save) img_save.style.visibility="visible";		 	 					 	 			
		 	 		}else if(action_type=='new' && span_category && span_category.innerHTML!=""){
		 	 			if(span_category)span_category.innerHTML=res;		 	 			
		 	 			if(img_save) img_save.style.visibility="visible";
		 	 			if(document.getElementById('save_button_'+category_id)) document.getElementById('save_button_'+category_id).style.display = '';		 	 			
		 	 		}									
					action_flag="";
			}
			if((action_type=='new' || action_type=='edit' || splt=='new')){
				if(action_type=='edit' && document.getElementById("products_price")) updateGross();
				if(img_category && !img_save) img_category.style.visibility="visible";
				init(action_type);
			}
		}	 	 	 
	 }
	 function init(action_type) {
		toggle_panel('Cost','false','','0');
		toggle_panel('Stock','false','','0');
		toggle_panel('Price_Breaks','false','','0');
		toggle_panel('Image','false','','0');
		toggle_panel('Attribute_Inventory_control','false','','0');
		toggle_panel('Linked_Subscription','false','','0');
		show_sub();
		change();
		show_price_break();					
		if(action_type=='edit' && document.new_product.elements["restrict_to_groups[]"]){
			var g_cnt=document.new_product.elements["restrict_to_groups[]"].length;
			var c_cnt=document.new_product.elements["restrict_to_customers[]"].length;
			var customer_found=false;
			var group_found=false;
			for(i=0;i<c_cnt;i++)
			  if(!customer_found && document.new_product.elements["restrict_to_customers[]"][i].checked) customer_found=true;
			for(j=0;j<g_cnt;j++)
			  if(!group_found && document.new_product.elements["restrict_to_groups[]"][j].checked) group_found=true;										
			if(customer_found && !group_found) do_change_customers('2');
			else if(group_found && !customer_found) do_change_customers('1');
		}
	 }
	 function editor_init(){
		<?php $languages = tep_get_languages();
			 if (HTML_AREA_WYSIWYG_DISABLE=='Enable') {
				 for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
				 	if(document.getElementById("products_description[<?php echo $languages[$i]['id']; ?>]"))
			 			initEditor('products_description[<?php echo $languages[$i]['id']; ?>]');
	  	<?php 	 }
			  }?>
	 }
	 
	 function focus_non_category_product(non_categories_products_id){	 
		 if(previous_non_categories_products_id!='')
		 	close_non_product_category(previous_non_categories_products_id);
		 document.getElementById('ajax_non_category_product_'+non_categories_products_id).style.display='';
		 document.getElementById('ajax_non_category_product_'+non_categories_products_id).innerHTML=document.getElementById("ajax_load_img").innerHTML;
		 do_get_command('<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'command=load_non_category_details&non_categories_products_id='); ?>'+non_categories_products_id);
		 previous_non_categories_products_id=non_categories_products_id; 
	 }
	 function close_non_product_category(non_categories_products_id){
	 	if(document.getElementById('ajax_non_category_product_'+non_categories_products_id) && document.getElementById('non_category_product_'+non_categories_products_id)){ 
	 	document.getElementById('ajax_non_category_product_'+non_categories_products_id).innerHTML='';
	 	document.getElementById('ajax_non_category_product_'+non_categories_products_id).style.display='none';
		document.getElementById('non_category_product_'+non_categories_products_id).style.display='';
		}
	 }
	 function delete_non_product(non_products_id){
	 	do_get_command('<?php echo tep_href_link(FILENAME_PRODUCTS_MAINPAGE,'command=delete_non_product&non_products_id='); ?>'+non_products_id);
	 }
	 function do_hover_change(element,mode){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
		element.mode=mode;
	}
		
	function save_attribute(){
		var product_option=document.new_product.elements["sel_product_option_value[]"];			
		var error="";
		var checked_option=false;
		var attribute_insert_string="";
		var attrb_text="";
		var frm=document.new_product;
		if(product_option){			
			var options_value=Array();	
			var pos=0;
			if(product_option && product_option.length){
			  for(o=0;o<product_option.length;o++){
				if(product_option[o] && product_option[o].checked){
					checked_option=true;
					var option_name_value_id=0;
					var option_name_value_text="";
					var option_id=0;
					if(product_option[o]) option_id=product_option[o].value;				
					var option_name_obj=document.getElementById("option_name_value_"+option_id);
					if(option_name_obj){
						option_name_value_text=option_name_obj.options[option_name_obj.selectedIndex].text;
						option_name_value_id=option_name_obj.options[option_name_obj.selectedIndex].value;
						option_value_id_split=option_name_value_id.split("##");
						option_value_id=option_value_id_split[1];
					}
					if(option_name_value_text!=""){
						attribute_insert_string+=option_id+"##"+option_value_id+"{{}}";
						attrb_text+=option_name_value_text+",";
					}
				}
			  }
			}else if(product_option && product_option.checked) {
				    checked_option=true;
					var option_name_value_id=0;
					var option_name_value_text="";
					var option_id=0;
					if(product_option) option_id=product_option.value;				
					var option_name_obj=document.getElementById("option_name_value_"+option_id);
					if(option_name_obj){
						option_name_value_text=option_name_obj.options[option_name_obj.selectedIndex].text;
						option_name_value_id=option_name_obj.options[option_name_obj.selectedIndex].value;
						option_value_id_split=option_name_value_id.split("##");
						option_value_id=option_value_id_split[1];
					}
					if(option_name_value_text!=""){
						attribute_insert_string+=option_id+"##"+option_value_id+"{{}}";
						attrb_text+=option_name_value_text+",";
					}
			}
			if(!checked_option) error+="<?php echo ERR_SELECT_OPTIONS_CHECKBOX;?>\n";
			if(document.getElementById("attrib_quantity") && (isEmpty(document.getElementById("attrib_quantity")) || !isNumeric(document.getElementById("attrib_quantity").value,1))) error+="<?php echo ERR_QUANTITY_EMPTY;?>\n";
			if(document.getElementById("attrb_sku") && isEmpty(document.getElementById("attrb_sku"))) error+="<?php echo ERR_ATTRIBUTE_SKU_EMPTY;?>\n";
			if("<?php echo SKU_LENGTH;?>"=='true' && document.getElementById("attrb_sku")){ 
				if(document.getElementById("attrb_sku").value.length!='<?php echo SKU_COUNT;?>')
				error+="* <?php echo TEXT_ERROR_PRODUCTS_SKU;?>\n";
			}
			//if(document.getElementById("attrib_quantity") && document.getElementById("attrib_quantity").value>0 && !check_quantity(document.getElementById("attrib_quantity").value)) error+="<?php echo TEXT_QUANTITY_MISMATCH;?>\n";		
			var attribute_status=document.new_product.elements["attribute_status"];
			attribute_value=attribute_insert_string+((document.getElementById("attrib_quantity"))?document.getElementById("attrib_quantity").value:0)+"##"+((document.getElementById("attrb_sku"))?document.getElementById("attrb_sku").value:0)+"##"+((attribute_status && attribute_status[0].checked)?1:0);
			attribute_text=attrb_text.substr(0,(attrb_text.length)-1)+','+((document.getElementById("attrib_quantity"))?document.getElementById("attrib_quantity").value:0)+' SKU:' +((document.getElementById("attrb_sku"))?document.getElementById("attrb_sku").value:'')+' Status:' +((attribute_status && attribute_status[0].checked)?1:0);
			if(!validate_insertattribute(attribute_text)) error+="* <?php echo TEXT_ATTRIBUTE_ALREADY_EXISTS;?>\n";
		 	if(error!="") alert(error);
		 	else {
		 		var pro_quantity=0;
				var oOption = document.createElement("option");
				var update_option_array=Array();	
				var pvalue=Array();
				var quan;		
				if(oOption){
					oOption.text=attribute_text;
					oOption.value=attribute_value;
					if(frm.attribute_list && frm.attribute_list.selectedIndex>=0){
					   	frm.attribute_list.options[frm.attribute_list.selectedIndex].text=attribute_text;
						frm.attribute_list.options[frm.attribute_list.selectedIndex].value=attribute_value;
					}else {
						if(frm.attribute_list.add.length==2)
				 			frm.attribute_list.add(oOption,null);
						else
				 			frm.attribute_list.add(oOption,pos);
				 		if(document.getElementById("img_delete")) document.getElementById("img_delete").style.display="";
					}
					var aobj=document.getElementById('attribute_list');
					for(alcnt=0;alcnt<aobj.length;alcnt++){
						quan=aobj[alcnt].value.substr(aobj[alcnt].value.lastIndexOf('{{}}')+4);
						pvalue=quan.split('##'); 
						pro_quantity=parseInt(pro_quantity) + parseInt(pvalue[0]);
					}
					document.getElementById('products_quantity').value=pro_quantity;
				}
				if(document.getElementById("span_attribute_details")) document.getElementById("span_attribute_details").style.display="none";
				if(document.getElementById("div_save_close")) document.getElementById("div_save_close").style.visibility="hidden";
		 	}
	   }
	}
	
	function validate_insertattribute(attribute_text){
		var obj=document.getElementById("attribute_list");
		var already_exists=true;
		if(obj){
			var a_count=obj.length;
			var pvalue=Array();
			var quan;
			var attrb_length_exists=false;
			for(a=0;a<a_count;a++){
 				if(obj.selectedIndex!=a){
 					replace_obj_sku=obj[a].text.substr(0,obj[a].text.lastIndexOf(','));
 					replace_attrib_sku=attribute_text.substr(0,attribute_text.lastIndexOf(','));
					if(already_exists && (obj[a].text==attribute_text || replace_obj_sku==replace_attrib_sku)) already_exists=false;
					if(!attrb_length_exists && (obj[a].text.length>200 || attribute_text.length>200)) attrb_length_exists=true;
 				}	
			}
			if(attrb_length_exists && document.getElementById("horiz_scroll")) document.getElementById("horiz_scroll").style.overflow="auto";
			else if(!attrb_length_exists && document.getElementById("horiz_scroll")) document.getElementById("horiz_scroll").style.overflow="";									
		}
		return already_exists;
	}
	function ValidateForm(response){		
		 var frm=document.new_product;
 	 	 var action_type=frm.action_type.value;
		 var cID="";	 
 	 	 if(action_type!='new_category' && document.getElementById("cPath") && document.getElementById("cPath").value>0) cID=document.getElementById("cPath").value;
 	 	 if(response && action_type=='new_category') {
			cID=response;
 	 	 	action_type='edit_category';	
 	 	 } 
 	 	 var pID="";
 	 	 if(action_type!='new' && !pID && frm.product_id && frm.product_id.value>0) pID=frm.product_id.value;
 	 	 if(response>0 && action_type=='new'){
 	 	 	pID=response;
 	 	 	action_type='edit';
 	 	 }
		 if((action_type=='new' || action_type=='edit') && document.getElementById("actions") && document.getElementById("actions").value!="") {
		 	document.getElementById("actions").value="";
			if(document.getElementById("new_category")) document.getElementById("new_category").style.display="none";
		 }
 	 	 command="<?php echo tep_href_link($file_name);?>?cID="+cID+"&pID="+pID;
 	 	 	if(action_type=='new_category' || action_type=='edit_category')
 	 	 		command+="&action=update_category"; 	 	 	
 	 	 	if(action_type=='delete_category' || action_type=='move_category') 
 	 	 		command+="&action="+action_type+"_confirm";			 	 	 			
 	 	 	if(action_type=='new' || action_type=='edit')
				command+="&action=update_product";
		 	if(action_type=='delete' || action_type=='copy' || action_type=='move' || action_type=='attrib')
				command+="&action="+action_type+"_confirm";
		if(command!=""){ 
			do_post_command('new_product',command);
		    if((action_type=='new' || action_type=='edit') && document.getElementById("actions") && document.getElementById("actions").value!="" && document.getElementById("new_category")) document.getElementById("new_category").innerHTML="";
			if(source=='products_expected') location.href='products_expected.php';
			return false;	
		}
	}
	function check_quantity(quantity){
		var obj=document.getElementById("attribute_list");
		var products_quantity=document.getElementById("products_quantity").value;
		var list_count=0;
		if(obj){
			var a_count=obj.length;
			for(a=0;a<a_count;a++){
				if(obj[a].value!=""){
					splt_list=obj[a].value.split("{}");
					splt_list_split=splt_list[splt_list.length-1].split('##');
					if(splt_list_split[0]) list_count+=parseInt(splt_list_split[0]);
				}
			}
		}
		list_count=parseInt(parseInt(quantity)+parseInt(list_count));
		if(list_count>products_quantity) return false;
		else return true;
	}
	function show_add_attribute()
	{
		var frm=document.new_product;
		frm.attrib_quantity.value='';
		frm.attrb_sku.value='';
		frm.attribute_status = '';
		frm.current_action.value='';
		frm.current_edit_id.value='';
		document.getElementById("option_list").style.display="";
	}
	function clear_attrib_details()
	{
	
		var frm=document.new_product;
		frm.attrib_quantity.value='';
		frm.attrb_sku.value='';
		frm.attribute_status.value = '';
		frm.current_action.value='';
		frm.current_edit_id.value='';
		document.getElementById("option_list").style.display="none";
	}
	function do_add_attribute(action,attribute_id){
		/*var span_attribute=document.getElementById("span_attribute_details");
		var obj=document.getElementById("attribute_list");
		var sel_check=document.new_product.elements["sel_product_option_value[]"];		
		if(mode){
			switch(mode){
				case 'add':
				  if(span_attribute){
				  	span_attribute.style.display="";
				  	if(obj) obj.selectedIndex=-1;
				  }
				  if(sel_check){
				  	var n=sel_check.length;
				  	if(n){
					  	for(ch=0;ch<n;ch++){
					  		//sel_check[ch].checked=false;
					  		//if(document.getElementById("option_name_value_"+sel_check[ch].value)) document.getElementById("option_name_value_"+sel_check[ch].value).disabled=true;
					  		if(document.getElementById("attrib_quantity")) document.getElementById("attrib_quantity").value="";
							if(document.getElementById("attrb_sku")) document.getElementById("attrb_sku").value="";
							if(document.getElementById("attribute_status")){
								var obj=document.new_product.elements["attribute_status"];
								if(obj[0]) obj[0].checked=true;
							}
					  	}
				  	}else {
			  			//sel_check.checked=false;
				  		//if(document.getElementById("option_name_value_"+sel_check.value)) document.getElementById("option_name_value_"+sel_check.value).disabled=true;
				  		if(document.getElementById("attrib_quantity")) document.getElementById("attrib_quantity").value="";
						if(document.getElementById("attrb_sku")) document.getElementById("attrb_sku").value="";
						if(document.getElementById("attribute_status")){
							var obj=document.new_product.elements["attribute_status"];
							if(obj[0]) obj[0].checked=true;
						}
				  	}
				  }
				  if(document.getElementById("div_save_close")) document.getElementById("div_save_close").style.visibility="visible";
				break;
				case 'edit':
					if(document.getElementById("span_attribute_details")) document.getElementById("span_attribute_details").style.display="";
					var select_option=document.new_product.elements["sel_product_option_value[]"];					
					if(!select_option) return;					
					n=select_option.length;
					if(n){							
						for(so=0;so<n;so++){
							select_option[so].checked=false;						
							if(select_option[so] && !select_option[so].checked && document.getElementById("option_name_value_"+select_option[so].value)) document.getElementById("option_name_value_"+select_option[so].value).disabled=true;
						}
					}else {
						select_option.checked=false;						
						if(select_option && !select_option.checked && document.getElementById("option_name_value_"+select_option.value)) document.getElementById("option_name_value_"+select_option.value).disabled=true;
					}
					if(obj.length>0){
						var pos=obj.options.selectedIndex;

						if(obj[pos] && obj[pos].value!=""){
							option_values=obj[pos].value;
							option_values_split=option_values.split("{{}}");
							for(i=0;i<option_values_split.length-1;i++) {							  
							  obj_split=option_values_split[i].split("##");
							  option_id=obj_split[0];			
							  option_value_id=obj_split[1];
							  if(select_option.length){					
								   for(so=0;so<select_option.length;so++)
								      if(select_option[so].value==option_id) {
								      	select_option[so].checked=true;
								      	if(document.getElementById("option_name_value_"+select_option[so].value)) document.getElementById("option_name_value_"+select_option[so].value).disabled=false;
								      }
							  }else if(select_option.value==option_id) {
							  	select_option.checked=true;
							  	if(document.getElementById("option_name_value_"+select_option.value)) document.getElementById("option_name_value_"+select_option.value).disabled=false;
							  }
							  var select_option_value=document.getElementById("option_name_value_"+option_id);
							  if(select_option_value.length){
								  n=select_option_value.length;
								  for(sov=0;sov<n;sov++)
									if(select_option_value[sov] && select_option_value.options[sov].value==option_id+'##'+option_value_id) select_option_value.selectedIndex=sov;
					   		  }else if(select_option_value && select_option_value.options[0].value==option_id+'##'+option_value_id) select_option_value.selectedIndex=sov;
							}
							if(option_values_split[option_values_split.length-1]!=""){
								    qty_sku_split=option_values_split[option_values_split.length-1].split("##");
									if(document.getElementById("attrib_quantity")) document.getElementById("attrib_quantity").value=qty_sku_split[0];
									if(document.getElementById("attrb_sku")) document.getElementById("attrb_sku").value=qty_sku_split[1];
									if(document.getElementById("attribute_status")){
										var obj=document.new_product.elements["attribute_status"];
										if(obj[0] && qty_sku_split[2]==1) obj[0].checked=true;
										else if(obj[1] && qty_sku_split[2]==0) obj[1].checked=true;
									}
							}														
						}
					 if(document.getElementById("div_save_close")) document.getElementById("div_save_close").style.visibility="visible";	
				  }	
				break;
				case 'delete':
				  if(obj && obj.selectedIndex>=0){				  	 
				  	 obj.remove(obj.selectedIndex);	
					 var quan;var pvalue=Array();var pro_quantity=0;	
						var aobj=document.getElementById('attribute_list');
						for(alcnt=0;alcnt<aobj.length;alcnt++){
							quan=aobj[alcnt].value.substr(aobj[alcnt].value.lastIndexOf('{{}}')+4);
							pvalue=quan.split('##'); 
							pro_quantity=parseInt(pro_quantity) + parseInt(pvalue[0]);
						}
					document.getElementById('products_quantity').value=pro_quantity;
				  	 if(obj.length==0 && document.getElementById("img_delete")) {
				  	 	document.getElementById("img_delete").style.display="none";
				  	 	if(document.getElementById("horiz_scroll")) document.getElementById("horiz_scroll").style.overflow="";				  	 	
				  	 } 
				  }else return;
				  if(document.getElementById("div_save_close")) document.getElementById("div_save_close").style.visibility="hidden";
				  if(document.getElementById("span_attribute_details")) document.getElementById("span_attribute_details").style.display="none";
				break;
				case 'close':
					if(document.getElementById("span_attribute_details")) document.getElementById("span_attribute_details").style.display="none";
					if(document.getElementById("div_save_close")) document.getElementById("div_save_close").style.visibility="hidden";
				break;				
			}
		}*/
		var frm=document.new_product;
		var error_result="";
		var del_items="";
		var sIndex=1;
		switch(action){
			case "edit":
			case "add":
			action=frm.current_action.value;
			if(action=="") action="add";
			if(subvalidateForm() == false){
				return;
			} 
			var temp=getDetails();
			var pos;

			dateAddText=temp[0];
			text_arr=dateAddText.split('#');
			dateAddValue = temp[1];
			value_arr=dateAddValue.split('#');
			if(value_arr[1]=="")
			{
				alert("<?php echo TEXT_ATTRIBUTE_ERROR;?>");
				return;
			}
			if (check_attribute_exists(value_arr[1],action)){
				alert('* <?php echo addslashes(TEXT_ATTRIBUTE_ALREADY_EXISTS); ?>');
				return;
			 }
				if (action=="edit") { 
					var i,j,k;
					ids = value_arr[1]; 
					var row_index = document.getElementById(frm.current_edit_id.value).rowIndex;
					var r1 = document.getElementById('dynamic_table').deleteRow(row_index); 
					var r=document.getElementById('dynamic_table').insertRow(row_index);
				}
				else if(action=="add")
				{
					var i,j,k;
					var len=document.getElementById('dynamic_table').rows[0].cells.length;
					var r=document.getElementById('dynamic_table').insertRow(-1);
				}
				r.className="attributes-odd";
				ids =value_arr[1];
				r.id=ids;
				//r.onclick=function(){ do_add_attribute('select', ids ); };
				//r.style.cursor='pointer;';
				//r.onmousemove=function() { rowOverEffect(this); };
				for(j=0;j<text_arr.length;j++){ 
					c1=r.insertCell(j); 
					c1.className="smallText";
					c1.innerHTML=text_arr[j]; 
				}
				c1=r.insertCell(j); 
				c1.innerHTML='<td valign="top" align="center"><a href="javascript:do_add_attribute(\'select\',\'' + ids + '\');"><?php echo tep_image(DIR_WS_IMAGES.'template/img_copy.gif',IMAGE_ADD_ATTRIBUTE)?></a>&nbsp;<a href="javascript:do_add_attribute(\'delete\',\'' + ids + '\')"><?php echo tep_image(DIR_WS_IMAGES.'template/img_trash.gif',IMAGE_DELETE_ATTRIBUTE) ?></a></span></td>';
				c1.className="smallText";
				clear_attrib_details();

				break;
				case "delete":
					id = attribute_id;
					var row_index_id = document.getElementById(id).rowIndex;					
					var r=document.getElementById('dynamic_table').deleteRow(row_index_id);					
					clear_attrib_details();
					break;
				case "select": 
					id = attribute_id;
					var row_index_id = document.getElementById(id).rowIndex;
					var r=document.getElementById('dynamic_table').rows[row_index_id];					
					document.new_product.attrb_sku.value=r.cells[0].innerHTML;
					values=id;
					attributes=values.split('-');
					for(i=0;i<attributes.length;i++){
						attrb_splt=attributes[i].split('{');
						document.getElementById("option_values"+attrb_splt[0]).value=attrb_splt[1].substring(0,(attrb_splt[1].length-1));
					}
					document.new_product.attrib_quantity.value=r.cells[2].innerHTML;
					if(r.cells[3].innerHTML==0){
						document.new_product.attribute_status[0].checked=false;
						document.new_product.attribute_status[1].checked=true;
					}else{
						document.new_product.attribute_status[0].checked=true;
						document.new_product.attribute_status[1].checked=false;
					}
					frm.current_action.value='edit';
					frm.current_edit_id.value=id;
					document.getElementById("option_list").style.display="";
					break;


			}
			do_skew_action(document.getElementById("is_attributes").checked);
	}		
function getDetails(){
			var carr_name="";
			var attrbAdd=Array();
			var attrb_text="";
			var attrb_value="";
			 for(i=0;i<attributes_array.length;i++){
				carr_name=document.getElementById('option_values'+attributes_array[i]);
				if(carr_name.length>0){
				attrb_text+=document.getElementById('text'+attributes_array[i]).innerHTML + ' : ' + carr_name.options[carr_name.selectedIndex].text + ',';
				attrb_value+=attributes_array[i]+'{'+carr_name.options[carr_name.selectedIndex].value+'}-';
				}
			}
			var attribute = 1;
			if(document.new_product.attribute_status[0].checked==false){
				attribute = 0;
			}else if(document.new_product.attribute_status[1].checked==false){
				attribute = 1;
			}
			attrb_value=attrb_value.substring(0,(attrb_value.length)-1);
			attrb_value=sorting(attrb_value);
			attrb_text=document.new_product.attrb_sku.value+'#'+attrb_text.substring(0,(attrb_text.length)-1)+'#'+document.new_product.attrib_quantity.value+'#' +attribute;
			attrb_value=document.new_product.attrb_sku.value+'#'+attrb_value+'#'+document.new_product.attrib_quantity.value+'#' +attribute;
			attrbAdd[0]=attrb_text;
			attrbAdd[1]=attrb_value;
			return attrbAdd;
		}
		
		function check_attribute_exists(dateAddText,mode){ 
		if(mode=='edit')
			return false;
	    
		var id_exist = document.getElementById(dateAddText);
			if(id_exist)
				return true;
			else
				return false;
		} 
		
		function get_position(dateAdd){
			frm=document.new_product;
			for (icnt=0;icnt<frm.attribute_list.length;icnt++){
				if(dateAdd<=frm.attribute_list.options[icnt].value){
					return icnt;
				}
			}
			return icnt;
		 }
function sorting(temp){
   
var sort_array = Array();
split_array =temp.split('-');


 for(i=0;i<split_array.length;i++)
 	for(j=i;j<split_array.length;j++)
		 if(split_array[i][0]>split_array[j][0]){
		 t=split_array[j];
		 split_array[j]=split_array[i];
		 split_array[i]=t;
		 } 
var sort_split_array = '';
 for(i=0;i<split_array.length;i++)
 	sort_split_array = sort_split_array + split_array[i] + '-';
sort_split_array = sort_split_array.substring(0,(sort_split_array.length)-1);





return sort_split_array;	


}		 
	function att_details(option_id,obj_split){
		if(document.getElementById("price["+option_id+"]")) document.getElementById("price["+option_id+"]").value=obj_split[1];
		if(document.getElementById("products_options_sort_order["+option_id+"]")) document.getElementById("products_options_sort_order["+option_id+"]").value=obj_split[2];
		if(document.getElementById("product_attributes_one_time["+option_id+"]")) document.getElementById("product_attributes_one_time["+option_id+"]").value=obj_split[3];
		if(document.getElementById("products_attributes_weight_prefix["+option_id+"]")) {
			if(obj_split[4]=='+') document.getElementById("products_attributes_weight_prefix["+option_id+"]").selectedIndex=0;
			else document.getElementById("products_attributes_weight_prefix["+option_id+"]").selectedIndex=1;
		}
		if(document.getElementById("products_attributes_weight["+option_id+"]")) document.getElementById("products_attributes_weight["+option_id+"]").value=obj_split[5];
		if(document.getElementById("products_attributes_units["+option_id+"]")) document.getElementById("products_attributes_units["+option_id+"]").value=obj_split[6];
		if(document.getElementById("products_attributes_units_price["+option_id+"]")) document.getElementById("products_attributes_units_price["+option_id+"]").value=obj_split[7];
	}
	function isNumeric(value,minimumValue,maximumValue){
			value=parseFloat(value);
			if (isNaN(value)) return false;
			if (value<minimumValue) return false;
			if (maximumValue>0 && value>maximumValue) return false;
			return true;
	}
	
	function isEmpty(ctlName){
			var value;
			if (ctlName && ctlName.length>0 && ctlName[0]){
				for (icnt=0;icnt<ctlName.length;icnt++){
					value=ctlName[icnt].value.trim();
					if (value=="") return true;						
				}
			} else if(ctlName) {
				value=ctlName.value.trim();
				if (value=="") return true;
			}
			return false;
	}
	</script>

