
<script language="javascript">
	var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
	function service_search_validation(){
		var service_search=document.getElementById('service_search').value;		
		if(str_trim(service_search)!="" && str_trim(service_search)!=null){
			do_get_command('<?php echo tep_href_link(FILENAME_SERVICES_MAINPAGE,'command=service_search&service_search='); ?>'+service_search);
			document.getElementById('search_result_details').innerHTML=document.getElementById('ajax_load_img').innerHTML;
		}
		return false;
	}
	function service_searching(){
		var service_search=document.getElementById('service_search').value;
		if(service_search!=''){
			do_get_command('<?php echo tep_href_link(FILENAME_SERVICES_MAINPAGE,'command=service_search&service_search='); ?>'+service_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_SERVICES_MAINPAGE,'command=reset_search'); ?>');
		document.getElementById('service_search').value="";
	}
 	function do_jump_list(nopen_ids){
	document.getElementById('service_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_SERVICES_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";			
			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;		
		show_order=document.getElementById("show_sort_order");
		if (cmd=="fetch_sub_list" || cmd=="fetch_sub_list_open"){
			if(document.getElementById('new_category'))document.getElementById('new_category').innerHTML = "";
			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_SERVICES_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=='previous'){
				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;
		}
		do_get_command(command);
	}
	function do_result(result){	
		if (result=="") return; 
		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 && span_category.innerHTML!=""){
					span_category.innerHTML=result;
					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 = "";
				}
			}
		 	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=='delete_category_success') print_details('delete_category_success',res);		 	
			 else if(splt=='sort_order_error') print_details('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(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 = '';
					span_category.innerHTML=res;
					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.display="";
					}
	 	 	}else if(action_type=='new' || action_type=='edit' || action_type=='delete' || action_type=='copy' || action_type=='move'){		 	 		
					if(span_product && span_category && span_category.innerHTML==""){
		 	 			span_product.innerHTML=res;
		 	 			if(img_save) img_save.style.visibility="";		 	 			
		 	 		}else if(action_type=='new' && span_category && span_category.innerHTML!=""){
		 	 			span_category.innerHTML=res;		 	 			
		 	 			if(img_save) img_save.style.visibility="";
		 	 			if(document.getElementById('save_button_'+category_id)) document.getElementById('save_button_'+category_id).style.display = '';		 	 			
		 	 		}
					get_booking_list(splt);
					action_flag="";
			}
			if((action_type=='new' || action_type=='edit' || splt=='new') && !block_time ){
					if(img_category && !pID) img_category.style.visibility="";
					<?php $languages = tep_get_languages();
					    if (HTML_AREA_WYSIWYG_DISABLE=='Enable') {
						 for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
						 	if(document.getElementById("service_description["+<?php echo $languages[$i]['id']; ?>+"]"))					 		
					 			initEditor('service_description[<?php echo $languages[$i]['id']; ?>]');
			  	   <?php 	}
					  }?>
				toggle_panel('Bookings','false','','0');
				toggle_panel('Fees','false','','0');
				toggle_panel('Blocked_Out_Time','false','','0');
				toggle_panel('Loadings','false','','0');
				toggle_panel('Conditions','false','','0');
				if(document.getElementById("no_booking_stime_h")) do_check_control(1);
			}
		}
   }  
  var lang=new Array();
  var attrib_icon=false;
  var selectedTab;
  var selected_book_id;
  var block_time=false;
  var prev_id="";
  var no_book_text="";
  var action_flag="";
  var new_cnt=0;
  var bk_obj=new Array();
  <?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 doaction(){}
  function show_duplicate(type){
	 	if(type=='dup')
			document.getElementById('dub_prd').style.display='';
		else
		   document.getElementById('dub_prd').style.display='none';
	 } 
  function startCallback_service() {
	 // make something useful before submit (onStart)
	 	var image_types=Array(".png",".jpg",".jpeg",".gif");
		var error_result="";
		var address="";
		var count=0;
		var frm=document.forms["new_product"];
		var id=0;
		var category_id=0;
		var validate_form=false;				
		if(frm && frm.service_id) id=frm.service_id.value;
		if(frm.secPath) var category_id=frm.secPath.value;
		var span_details=document.getElementById("span_details");
		if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
		var categories_image=document.getElementById('services_categories_image');
		if(action_type=='new_category' || action_type=='edit_category'){				
			for(i=0;i<n;i++) if(document.getElementById("services_categories_name["+lang[i]+"]") && (document.getElementById("services_categories_name["+lang[i]+"]").value=="" ||  isEmpty(document.getElementById("services_categories_name["+lang[i]+"]")))) 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'){
			// if category is selected
		var error_flag=true;
		var sc_count=document.getElementsByName('service_categories_ids[]').length;
		for(i=0;i<sc_count;i++)
			if(document.getElementsByName('service_categories_ids[]')[i].checked==true)	
				error_flag=false;
			 if (error_flag==true)
				error_result+='<?php echo addslashes(TEXT_ERR_SELECT_CATEGORY); ?>\n';
			if (frm.elements["service_name["+lang[1]+"]"])
			  for (icnt=0;icnt<lang.length;icnt++){
				obj=frm.elements["service_name["+lang[icnt]+"]"];
				if (isEmpty(obj)) error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_ALL_SERVICES_NAME); ?>\n";						
			 }else if(frm.elements["service_name["+lang[0]+"]"] && isEmpty(frm.elements["service_name["+lang[0]+"]"])) 				 	
				error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SERVICES_NAME); ?>\n";					 				 					
			if(!isDate(frm.service_date_available.value,false)) error_result+='<?php echo sprintf(addslashes(TEXT_INVALID_DATE_AVAILABLE),EVENTS_DATE_FORMAT);?>\n';
			if (isEmpty(frm.service_total_time) || parseInt(frm.max_bookings.value)<parseInt(frm.service_total_time.value))
				error_result+='<?php echo TEXT_SERVICES_BOOKING_MIN_MAX;?>\n';				
			if (isEmpty(frm.service_total_time) || !isNumeric(frm.service_total_time.value,1))
				error_result+='<?php echo ERR_BOOKING_DAY_MIN;?>\n';
			if (isEmpty(frm.max_bookings) || !isNumeric(frm.max_bookings.value,1))
				error_result+='<?php echo ERR_BOOKING_DAY_MAX;?>\n';
			if(frm.booking_granular.disabled==false && frm.booking_type){
				if(frm.booking_type.value=='H' && frm.booking_granular.value>12) error_result+='<?php echo ERR_BOOKING_GRANULAR_GREATER_HOUR;?>\n';
				else if(frm.booking_type.value=='M' && frm.booking_granular.value>60) error_result+='<?php echo ERR_BOOKING_GRANULAR_GREATER_MIN;?>\n';
			}	
			if(!frm.sel_service_avilable.checked && !frm.include_resource.checked)
		 		error_result+="<?php echo tep_db_input(TEXT_ERR_SELECT_ANYONE_TYPE); ?>\n";		 		    	
			if(frm.booking_granular.disabled==false && (isEmpty(frm.booking_granular) || !isNumeric(frm.booking_granular.value,1)))
				error_result+='<?php echo ERR_BOOKING_GRANULAR;?>\n';
			if(frm.booking_granular && frm.booking_granular.disabled==false){				
				if(frm.service_total_time && frm.service_total_time.value%frm.booking_granular.value>0 && frm.booking_type)			  
					error_result+='<?php echo ERR_BOOKING_MINS_MIN;?>\n';					
				if(frm.service_total_time && frm.max_bookings && frm.max_bookings.value%frm.service_total_time.value>0)
					error_result+='<?php echo ERR_BOOKING_MINS_MIN_MAX;?>\n';
			}
			var res_chk=false;
			for(i=0;i<frm.elements["include_resource_arr[]"].length;i++) if(frm.elements["include_resource_arr[]"][i].checked) res_chk=true; 
			if(frm.include_resource.checked==true && !res_chk)
				error_result+='<?php echo ERR_SELECT_RESOURCE_NAME;?>\n';
			if(!frm.include_resource.checked && !isNumeric(frm.quantity.value,1,-1))
				error_result+='<?php echo ERR_QUANTITY;?>\n';
			if(!isNumeric(frm.pending_period.value,0,-1) || !isNumeric(frm.pending_period.value,1))
				error_result+='<?php echo ERR_PENDING_PERIOD;?>\n';
			if(!isNumeric(frm.service_renewal_start.value,0,-1) || !isNumeric(frm.service_renewal_start.value,1))
				error_result+='<?php echo ERR_RENEWAL_START;?>\n';
			if(!isNumeric(frm.service_renewal_end.value,0,-1) || !isNumeric(frm.service_renewal_end.value,1))
				error_result+='<?php echo ERR_RENEWAL_END;?>\n';
			var error_found=false;
			for(i=0;i<n;i++){
			   if (!error_found && document.getElementById("service_image_"+lang[i]) && document.getElementById("service_image_"+lang[i]).value!=""){
				  	 if(document.getElementById("service_image_"+lang[i]).value!="" && !check_mime_type(document.getElementById("service_image_"+lang[i]),image_types)) {
				  		error_result+='<?php echo ERR_IMAGE_UPLOAD_TYPE;?>';
				  		error_found=true;
				  	 }
			  	}
			}
			address="";
			for (icnt=0;icnt<frm.loading_date_list.length;icnt++) 
				address+=frm.loading_date_list.options[icnt].value + "/";						
			frm.loading_dates.value=address;			
	 }
	 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_service(response) {  	 	
  	 	var res=response;
  	 	res_split=res.split("^");
  	 	if(res_split[0]=='upload_error'){
  	 		alert(res_split[1]);
  	 		return false;
  	 	}else  ValidateForm(response);
  } 	  	
//Js Upload End

		var tax_rates = new Array();
		var lang=new Array();
		<?php
			$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 ($j=0, $n=sizeof($languages); $j<$n; $j++) {
				echo "lang[".$j."]=".$languages[$j]['id'].";\n"; 
			}			                                                                                                                                            
		?> 
	function validate_image(){
		var image_types=Array(".png",".jpg",".jpeg",".gif");
		var frm = document.new_product_category;
		var error = "";
		if (frm.elements["services_categories_image"].value!="" && !check_mime_type(frm.elements["services_categories_image"],image_types))
			error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
	 	if(error!=""){
			alert(error);
			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;
		}
		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 get_time_field(ctlName){
			var t_hour=parseInt(document.new_product.elements[ctlName+"_h"].value,10);
			var t_min=parseInt(document.new_product.elements[ctlName+"_m"].value,10);
			var t_day=document.new_product.elements[ctlName+"_d"].value;
			if (t_day=="AM" && t_hour==12) t_hour=00;
			if (t_day=="PM" && t_hour==12) t_hour=12;
			if (t_day=="PM" && t_hour<12) t_hour=t_hour+12;
			if (t_hour<10) t_hour="0"+t_hour;
			if (t_min<10) t_min="0"+t_min;
			return t_hour+":"+t_min;
		}
		
		function get_time(ctlName){
			var t_hour=parseInt(document.new_product.elements[ctlName+"_h"].value,10);
			var t_min=parseInt(document.new_product.elements[ctlName+"_m"].value,10);
			var t_day=document.new_product.elements[ctlName+"_d"].value;
			if(t_min<10) 
			{	
				st_min=t_min.toString();
				t_min=0 + st_min;
			}
			return t_hour+":"+t_min+t_day;
		     }
		     		
				
function subvalidateBookingform()
		{
		var error="";
		var frm=document.forms["new_product"];
		
		tempStartDate=date_format(frm.no_booking_sdate.value,'','Y-m-d');
		tempEndDate=date_format(frm.no_booking_edate.value,'','Y-m-d');
		if(tempStartDate>tempEndDate)
			error+="<?php echo tep_db_input(ERR_LESS_END_DATE);?>\n";
	   var recurring_option="";
	 for(icnt=0;icnt<frm.loading_recurring_type.length;icnt++){
	     if (frm.loading_recurring_type[icnt].checked==true){
	    	 recurring_option=frm.loading_recurring_type[icnt].value;
	     	 break;
		 }
	 }
	 if(document.getElementById("daily_check") && document.getElementById("daily_check").checked==true) recurring_option='DD';
	 else if(document.getElementById("weekly_check") && document.getElementById("weekly_check").checked==true) recurring_option='WW';
	 if (recurring_option=="") error+="<?php echo tep_db_input(TEXT_ERR_NO_RECURRING_TYPE); ?>\n";
	 	 
	 if (recurring_option=="DD"){
	 	if(isNaN(parseInt(frm.loading_daily_days.value))==true || frm.loading_daily_days.value==""  || parseInt(frm.loading_daily_days.value)<=0)	    
	     	error+="<?php echo tep_db_input(TEXT_ERR_DAILY_DAYS); ?>\n";
	 }
	 if (recurring_option=="WW"){
	    if (isNaN(parseInt(frm.loading_weekly_weeks.value))==true || frm.loading_weekly_weeks.value==""  || parseInt(frm.loading_weekly_weeks.value)<=0){
	      error+="<?php echo tep_db_input(TEXT_ERR_WEEKLY_WEEKS); ?>\n";}
		  ctl=frm.elements["loading_week_days[]"];
	    for(icnt=0;icnt<ctl.length;icnt++){
	       if (ctl[icnt].checked==true) break;
	    }
	    if (icnt>=ctl.length)
	       error+="<?php echo tep_db_input(TEXT_ERR_WEEKLY_DAYS); ?>\n";
	      
	 }
	 if (recurring_option=="MD"){
	    if (isNaN(parseInt(frm.loading_monthly_days.value))==true || frm.loading_monthly_days.value==""  || parseInt(frm.loading_monthly_days.value)<=0){
	      error+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_DAYS); ?>\n";}
	    if (isNaN(parseInt(frm.loading_monthly_months.value))==true || frm.loading_monthly_months.value==""  || parseInt(frm.loading_monthly_months.value)<=0 ){
	      error+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_MONTHS); ?>\n";}
	 }
	 if (recurring_option=="MM"){
	    if (isNaN(parseInt(frm.loading_monthly_week_months.value))==true || frm.loading_monthly_week_months.value==""  || parseInt(frm.loading_monthly_week_months.value)<=0){
	      error+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_WEEKMONTHS); ?>\n";}
         }
	 if (recurring_option=="YD"){
	    if (isNaN(parseInt(frm.loading_yearly_month_days.value))==true || frm.loading_yearly_month_days.value==""  || parseInt(frm.loading_yearly_month_days.value)<=0){
	      error+="<?php echo tep_db_input(TEXT_ERR_YEARLY_MONTHDAYS); ?>\n";}
         }

		 if(!isDate(frm.no_booking_sdate.value,false)) 
			error+='<?php echo ERR_NO_BOOK_SDATE;?> \n';
		 if(!isDate(frm.no_booking_edate.value,false)) 
			error+='<?php echo ERR_NO_BOOK_EDATE;?> \n';
		if(isNaN(parseInt(frm.loading_price.value)))
			 error+='<?php echo ERR_LOADING_PRICE;?>\n';
	if(error!="")
	{
	alert(error);
	return false;
	}	
	else 
	return true;
}				

function validateBookingform()
{

var error=false;
var error_result="";
var frm=document.forms["new_product"];
tempStartDate=date_format(frm.no_booking_sdate.value,'','Y-m-d');
tempEndDate=date_format(frm.no_booking_edate.value,'','Y-m-d');
 if(tempStartDate>tempEndDate) {
	error_result+="<?php echo tep_db_input(ERR_LESS_END_DATE);?>\n";
	error=true;
 }
var recurring_option="";
var obj=frm.elements["recurring_type"];
	 if(document.getElementById('daily_div').style.display=="")
		recurring_option="DD";
	 else if(document.getElementById('week_div').style.display=="") recurring_option="WW";
	 else if(document.getElementById('month_div').style.display=="") {
		if(obj[0].value=='MD' && obj[0].checked) recurring_option="MD";
		else if(obj[1].value=='MM' && obj[1].checked) recurring_option="MM";
	 }else if(document.getElementById('year_div').style.display=="") {
		if(obj[2].value=='YD' && obj[2].checked) recurring_option="YD";
	    else if(obj[3].value=='YY' && obj[3].checked) recurring_option="YY";
	 }	 	 
	 if (recurring_option==""){
	    error_result+="<?php echo tep_db_input(TEXT_ERR_NO_RECURRING_TYPE); ?>\n";
	 	error=true;
	 }
	 if (recurring_option=="DD"){
	    if (isNaN(parseInt(frm.daily_days.value))==true || frm.daily_days.value==""  || parseInt(frm.daily_days.value)<=0){
	    	error_result+="<?php echo tep_db_input(TEXT_ERR_DAILY_DAYS); ?>\n";
			error=true;
		}
	 }
	 if (recurring_option=="WW"){
	    if (isNaN(parseInt(frm.weekly_weeks.value))==true || frm.weekly_weeks.value==""  || parseInt(frm.weekly_weeks.value)<=0){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_WEEKLY_WEEKS); ?>\n";
		  error=true;
		}
		ctl=frm.elements["no_booking_week_days[]"];
	    for(icnt=0;icnt<ctl.length;icnt++){
	       if (ctl[icnt].checked==true) break;
	    }
	    if (icnt>=ctl.length) {
	       error_result+="<?php echo tep_db_input(TEXT_ERR_WEEKLY_DAYS); ?>\n";
		   error=true;
		}
	 }
	 if (recurring_option=="MD"){
	    if (isNaN(parseInt(frm.monthly_days.value))==true || frm.monthly_days.value==""  || parseInt(frm.monthly_days.value)<=0){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_DAYS); ?>\n";
		  error=true;
		  }
	    if (isNaN(parseInt(frm.monthly_months.value))==true || frm.monthly_months.value==""  || parseInt(frm.monthly_months.value)<=0 ){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_MONTHS); ?>\n";
		  error=true;
		  }
	 }
	 if (recurring_option=="MM"){
	    if (isNaN(parseInt(frm.monthly_week_months.value))==true || frm.monthly_week_months.value==""  || parseInt(frm.monthly_week_months.value)<=0){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_MONTHLY_WEEKMONTHS); ?>\n";
		  error=true;
		  }
         }
	 if (recurring_option=="YD"){
	    if (isNaN(parseInt(frm.yearly_month_days.value))==true || frm.yearly_month_days.value==""  || parseInt(frm.yearly_month_days.value)<=0){
	      error_result+="<?php echo tep_db_input(TEXT_ERR_YEARLY_MONTHDAYS); ?>\n";
		  error=true;
		  }
         }
	if(!isDate(frm.no_booking_sdate.value,false)) {
		error_result+='<?php echo ERR_NO_BOOK_SDATE;?>\n';
		error=true;
		}
	 if(!isDate(frm.no_booking_edate.value,false)) {
		error_result+='<?php echo ERR_NO_BOOK_EDATE;?>\n';
		error=true;	
		}	 
	if(error) {
		alert(error_result);
		return false;
	}	
	else 
		return true;
}

		function doRound(x, places) {
		  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
		}
		
				function getTaxRate() {
				  var selected_value = document.forms["new_product"].service_tax_class_id.selectedIndex;
				  var parameterVal = document.forms["new_product"].service_tax_class_id[selected_value].value;
				  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
					return tax_rates[parameterVal];
				  } else {
					return 0;
				  }
				}
		 
				function updateGross() {
				  var taxRate = getTaxRate();
				  var grossValue = document.forms["new_product"].service_costs_net.value;
				
				  if (taxRate > 0) {
					grossValue = grossValue * ((taxRate / 100) + 1);
				  }
				
				  document.forms["new_product"].service_costs_gross.value = doRound(grossValue, 4);
				}
		
				
				function updateNet() {
				  var taxRate = getTaxRate();
				  var netValue = document.forms["new_product"].service_costs_gross.value;
				
				  if (taxRate > 0) {
					netValue = netValue / ((taxRate / 100) + 1);
				  }
				  document.forms["new_product"].service_costs_net.value = doRound(netValue, 4);
				}
				function tep_convert_format(time){
				 split_time=time.split(":");
				 hour=split_time[0];
				 minute=split_time[1];
				 if(hour>0){
				   if(hour==12)
				   hour='00';
				 }
				 return hour+":"+minute;
				}
				function get_diff_minutes(stime,etime){
					splt1=stime.split(":");
					splt2=etime.split(":");
					sdate=new Date(1980,1,1,parseInt(splt1[0],10),parseInt(splt1[1],10));
					edate=new Date(1980,1,1,parseInt(splt2[0],10),parseInt(splt2[1],10));
					diff= new Date();
					diff.setTime(Math.abs(edate.getTime() - sdate.getTime()));
                    timediff = diff.getTime();
					hours = Math.floor(timediff / (1000 * 60 * 60)); 
                    timediff -= hours * (1000 * 60 * 60);
					if(hours)
					return hours;
					else return 0;
				}
		        
				function check_date_exists(dateAdd,mode){
					frm=document.new_product;
					sIndex=-1;
					if (mode=="edit") sIndex=frm.no_booking_date_list.selectedIndex;
					for (icnt=0;icnt<frm.no_booking_date_list.length;icnt++){
						if(icnt!=sIndex && frm.no_booking_date_list.options[icnt].text == dateAdd){
							return true;
						}
					}
					return false;
				} 
				
				function check_date_exists_load(dateAdd,mode){
					frm=document.new_product;
					sIndex=-1;
					if (mode=="edit") sIndex=frm.loading_date_list.selectedIndex;
					for (icnt=0;icnt<frm.loading_date_list.length;icnt++){
						if(icnt!=sIndex && frm.loading_date_list.options[icnt].text == dateAdd){
							return true;
						}
					}
					return false;
				} 
			function clear_block_content(obj)
			{
				frm=document.new_product;
				var recurring_type=document.new_product.elements["recurring_type"];
				if(recurring_type[0].checked){
					if(document.getElementById("monthly_weeks")) document.getElementById("monthly_weeks").disabled=true;								
					if(document.getElementById("monthly_week_days")) document.getElementById("monthly_week_days").disabled=true;
					if(document.getElementById("monthly_week_months")) document.getElementById("monthly_week_months").disabled=true;
					if(document.getElementById("monthly_days")) document.getElementById("monthly_days").disabled=false;					
					if(document.getElementById("monthly_months")) document.getElementById("monthly_months").disabled=false;
				}else if(recurring_type[1].checked){
					if(document.getElementById("monthly_days")) document.getElementById("monthly_days").disabled=true;					
					if(document.getElementById("monthly_months")) document.getElementById("monthly_months").disabled=true;
					if(document.getElementById("monthly_weeks")) document.getElementById("monthly_weeks").disabled=false;
					if(document.getElementById("monthly_week_days")) document.getElementById("monthly_week_days").disabled=false;
					if(document.getElementById("monthly_week_months")) document.getElementById("monthly_week_months").disabled=false;
				}else if(recurring_type[2].checked){
					if(document.getElementById("yearly_months")) document.getElementById("yearly_months").disabled=false;
					if(document.getElementById("yearly_month_days")) document.getElementById("yearly_month_days").disabled=false;
					if(document.getElementById("yearly_weeks")) document.getElementById("yearly_weeks").disabled=true;
					if(document.getElementById("yearly_week_days")) document.getElementById("yearly_week_days").disabled=true;
					if(document.getElementById("yearly_week_months")) document.getElementById("yearly_week_months").disabled=true;													
				}else if(recurring_type[3].checked){
					if(document.getElementById("yearly_months")) document.getElementById("yearly_months").disabled=true;
					if(document.getElementById("yearly_month_days")) document.getElementById("yearly_month_days").disabled=true;
					if(document.getElementById("yearly_weeks")) document.getElementById("yearly_weeks").disabled=false;
					if(document.getElementById("yearly_week_days")) document.getElementById("yearly_week_days").disabled=false;
					if(document.getElementById("yearly_week_months")) document.getElementById("yearly_week_months").disabled=false;
				}
				for(i=0;i<frm.recurring_type.length;i++){
					if(frm.recurring_type[i].checked){
						frm.rec_type.value=frm.recurring_type[i].value;
					}
				}	
			}
		 
			function clear_load_content(action)
			{
				frm=document.new_product;
				var load_recurring_type=document.new_product.elements["loading_recurring_type"];
			//Daily
					frm.loading_daily_days.value='';
			//Weekly
					frm.loading_weekly_weeks.value='';
					ctl=frm.elements["loading_week_days[]"];
					for(icnt=0;icnt<ctl.length;icnt++)
						   ctl[icnt].checked=false ;						
			//Monthly Days
					frm.loading_monthly_days.value='';
					frm.loading_monthly_months.value='';
			//Monthly Months
					frm.loading_monthly_week_months.value='';
					frm.loading_monthly_week_days.value=0; 
					frm.loading_monthly_weeks.value=0;
			//Yearly Months
					frm.loading_yearly_month_days.value='';
					frm.loading_yearly_months.value=0;
			//Yearly Years
					frm.loading_yearly_weeks.value=0;
					frm.loading_yearly_week_days.value=0;
					frm.loading_yearly_week_months.value=0; 
				if(!action) frm.loading_price.value='';
				frm.loading_type.value='C';
				if(load_recurring_type[0].checked){
					if(document.getElementById("loading_monthly_weeks")) document.getElementById("loading_monthly_weeks").disabled=true;								
					if(document.getElementById("loading_monthly_week_days")) document.getElementById("loading_monthly_week_days").disabled=true;
					if(document.getElementById("loading_monthly_week_months")) document.getElementById("loading_monthly_week_months").disabled=true;
					if(document.getElementById("loading_monthly_days")) document.getElementById("loading_monthly_days").disabled=false;					
					if(document.getElementById("loading_monthly_months")) document.getElementById("loading_monthly_months").disabled=false;
				}else if(load_recurring_type[1].checked){
					if(document.getElementById("loading_monthly_days")) document.getElementById("loading_monthly_days").disabled=true;					
					if(document.getElementById("loading_monthly_months")) document.getElementById("loading_monthly_months").disabled=true;
					if(document.getElementById("loading_monthly_weeks")) document.getElementById("loading_monthly_weeks").disabled=false;
					if(document.getElementById("loading_monthly_week_days")) document.getElementById("loading_monthly_week_days").disabled=false;
					if(document.getElementById("loading_monthly_week_months")) document.getElementById("loading_monthly_week_months").disabled=false;
				}else if(load_recurring_type[2].checked){
					if(document.getElementById("loading_yearly_months")) document.getElementById("loading_yearly_months").disabled=false;
					if(document.getElementById("loading_yearly_month_days")) document.getElementById("loading_yearly_month_days").disabled=false;
					if(document.getElementById("loading_yearly_weeks")) document.getElementById("loading_yearly_weeks").disabled=true;
					if(document.getElementById("loading_yearly_week_days")) document.getElementById("loading_yearly_week_days").disabled=true;
					if(document.getElementById("loading_yearly_week_months")) document.getElementById("loading_yearly_week_months").disabled=true;													
				}else if(load_recurring_type[3].checked){
					if(document.getElementById("loading_yearly_months")) document.getElementById("loading_yearly_months").disabled=true;
					if(document.getElementById("loading_yearly_month_days")) document.getElementById("loading_yearly_month_days").disabled=true;
					if(document.getElementById("loading_yearly_weeks")) document.getElementById("loading_yearly_weeks").disabled=false;
					if(document.getElementById("loading_yearly_week_days")) document.getElementById("loading_yearly_week_days").disabled=false;
					if(document.getElementById("loading_yearly_week_months")) document.getElementById("loading_yearly_week_months").disabled=false;
				}
			}
		function get_position(dateAdd){
			frm=document.new_product;
			for (icnt=0;icnt<frm.no_booking_date_list.length;icnt++){
				if(dateAdd<=frm.no_booking_date_list.options[icnt].value){
					return icnt;
				}
			}
			return icnt;
		 }
		 function get_load_position(dateAdd){
			frm=document.new_product;
			for (icnt=0;icnt<frm.loading_date_list.length;icnt++){
				if(dateAdd<=frm.loading_date_list.options[icnt].value){
					return icnt;
				}
			}
			return icnt;
		 }
		 function get_id(val) {
		 	selected_book_id=val.id;
		 }
		 		
		function save_blocked_detail() {
		    if(document.getElementById('show_details') && document.getElementById('show_details').style.display=='none') return;
		    var get_dates='';
			var rec_detail=get_rec_details();
			var no_booking_stime=get_time_field("no_booking_stime");
			var no_booking_etime=get_time_field("no_booking_etime");
			var no_booking_sdate="";
			var no_booking_edate="";			
			if(document.getElementById("no_booking_sdate")) no_booking_sdate=document.getElementById("no_booking_sdate").value;
			if(document.getElementById("no_booking_edate")) no_booking_edate=document.getElementById("no_booking_edate").value;			
			new_cnt++;
			command='<?php echo tep_href_link(FILENAME_SERVICES_MAINPAGE,'action=save_new_blocked_detail');?>&no_book_text='+no_book_text+'&rec_detail='+rec_detail+'&sdate='+no_booking_sdate+'&edate='+no_booking_edate+'&stime='+no_booking_stime+'&etime='+no_booking_etime+"&new_cnt=" + new_cnt;
			var validate=validateBookingform();
			if(!validate)
				return;
			else {
				if(document.getElementById("tbl_obj")) {
				  if(document.getElementById("tbl_obj")) var table_obj=document.getElementById("tbl_obj");				  
				  var temp=getDetails();
				  var dateAdd="";
				  var dateAddText="";
				  var index=0;
				  dateAdd=temp[0];
				  dateAddText=temp[1];
				  if(document.getElementById("nb_dates")) get_dates=document.getElementById("nb_dates").value;
				  var error=false;
				  if(get_dates!=""){
					  get_dates_split=get_dates.split("{}");
					  for(i=0;i<get_dates_split.length;i++){
					    if(!error && get_dates_split[i]==dateAdd) {
					    	alert("<?php echo TEXT_DATE_ALREADY_EXISTS;?>");
					    	error=true;
					    }
					 }
				  }
				  var sel_count=document.getElementById("sel_count");
				  var sel_nb_dates_id=document.getElementById("sel_nb_dates_id");
				  index=sel_count.value;
				  if(!error && table_obj && index=="" && sel_nb_dates_id.value==""){
				  	 var tr_obj=table_obj.insertRow(table_obj.rows.length);
				  	 var rw_cel=tr_obj.insertCell(0);					     				 
    				 tr_obj.style.height="15px";
    				 tr_obj.id="tr_"+tr_obj.rowIndex;
					 if(tr_obj.rowIndex%2==0) tr_obj.className="dataTableRowOdd";
					 else tr_obj.className="dataTableRowEven";
					 tr_obj.onmouseover=function (){rowOverEffect(this)};
					 tr_obj.onmouseout=function (){rowOutEffect(this)};
					 tr_obj.onclick=function (){javascript:do_add_block('edit',dateAdd,tr_obj)};
    				 rw_cel.innerHTML=dateAddText;
    				 if(document.getElementById("nb_dates"))
    				   document.getElementById("nb_dates").value=document.getElementById("nb_dates").value+((document.getElementById("nb_dates").value!="")?'{}':'')+dateAdd;
				  }	else if(!error && table_obj && index!="" && sel_nb_dates_id.value!="" && document.getElementById("tr_"+index)){
					 var tr_obj=document.getElementById("tr_"+index);
					 var td_obj=tr_obj.cells[0];
					 td_obj.innerHTML=dateAddText;
					 tr_obj.onclick=function (){javascript:do_add_block('edit',dateAdd,tr_obj);};
					 document.getElementById("nb_dates").value=document.getElementById("nb_dates").value.replace(sel_nb_dates_id.value,dateAdd);
					 sel_count.value="";
					 sel_nb_dates_id.value="";
				  }
				}
				if(table_obj && table_obj.rows.length>3 && document.getElementById("div_nb_date_list")) document.getElementById("div_nb_date_list").style.height="80";
				if(table_obj.rows.length>0 && document.getElementById("img_delete")) document.getElementById("img_delete").style.display="";
			}
			close_blocked_detail();
		 }
		 function new_loading(){
		 	clear_load_content();
		 	document.getElementById('loading_daily_days').value='';
		 	document.getElementById('save_button').href="javascript: do_date_action_load('add');";
			open_loads('D');
		 }
		 
		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 open_loads(mode){
		 document.getElementById('load_daily').style.display='none';
		 document.getElementById('load_monthly').style.display='none';
		 document.getElementById('load_yearly').style.display='none';
		 document.getElementById('load_weekly').style.display='none';
		 document.getElementById('daily_check').checked=false;
		 document.getElementById('monthly_check').checked=false;
		 document.getElementById('weekly_check').checked=false;
		 document.getElementById('yearly_check').checked=false;
		 document.getElementById('date_id').style.display='';
		 document.getElementById('load_check_condition').style.display='';
		 document.getElementById('loading_price_id').style.display='';
		 document.getElementById('load_check_condition').style.display='';
		 document.getElementById("loading_recurring_type_option").style.display="";
		 document.getElementById('date_id').style.display='';
		 var load_recurring_type=document.new_product.elements["loading_recurring_type"];
		 	switch(mode){
				case 'D':
					document.getElementById('load_daily').style.display='';
					document.getElementById('daily_check').checked=true;
					break;
				case 'W':
					document.getElementById('load_weekly').style.display='';
					document.getElementById('weekly_check').checked=true;
					break;
				case 'M':
					document.getElementById('load_monthly').style.display='';
					document.getElementById('monthly_check').checked=true;
					if(load_recurring_type[0]) load_recurring_type[0].checked=true;
					break;
				case 'Y':
					document.getElementById('load_yearly').style.display='';
					document.getElementById('yearly_check').checked=true;
					if(load_recurring_type[2]) load_recurring_type[2].checked=true;
					break;
			}			
		 }
		 
		 function get_rec_details()
				{
				var frm=document.new_product;
				var selectedweekdays="";
				var selecteddays=""
				var dateAdd=Array();
				var dayArray=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
				var monthArray=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
				var placeArray=new Array('first','second','third','fourth');
				type=frm.rec_type.value;
				if(type=="DD")
					{
					var recurring_detail=frm.daily_days.value;
				}
				else if(type=="WW")
					{
					 ctl=frm.elements["no_booking_week_days[]"];
					 for(icnt=0;icnt<ctl.length;icnt++){
					   if (ctl[icnt].checked==true) 
					   		{
							selectedweekdays+=(ctl[icnt].value-1)+",";	
							selecteddays+=dayArray[icnt]+",";
							}
	    				}
						
						selecteddays=selecteddays.substring(0,((selecteddays.length)-1));
						weekdays=selectedweekdays.substring(0,((selectedweekdays.length)-1));
						
					var recurring_detail=frm.weekly_weeks.value+";"+weekdays;
				}
				else if(type=="MD")
				{
					var recurring_detail=frm.monthly_days.value+";"+frm.monthly_months.value;
					}
				else if(type=="MM")
				{
					var recurring_detail=frm.monthly_weeks.value+";"+frm.monthly_week_days.value+";"+frm.monthly_week_months.value;
					}
				else if(type=="YD")
				{
					var recurring_detail=frm.yearly_months.value+";"+frm.yearly_month_days.value;
					}
				else if(type=="YY")
				{
					var recurring_detail=frm.yearly_weeks.value+";"+frm.yearly_week_days.value+";"+frm.yearly_week_months.value;			
					}
				return recurring_detail;
			}
			function do_add_block(mode,id,tr_index) {				
				switch (mode){
					case 'add':
					var table_obj=document.getElementById("tbl_obj");
					if(table_obj){
						var n=table_obj.rows.length;
						for(i=0;i<n;i++){
					      if(i % 2 ==0)  cls_name="dataTableRowEven";
						  else  cls_name="dataTableRowOdd"; 
					      if(table_obj.rows[i]) table_obj.rows[i].className=cls_name;	
					    }
					}	
					var sel_count=document.getElementById("sel_count");					
				    var sel_nb_dates_id=document.getElementById("sel_nb_dates_id");
				    var recurring_type_open_divs=document.new_product.elements["recurring_type_open_divs"];
				    if(sel_count && sel_nb_dates_id) sel_count.value=sel_nb_dates_id.value="";
					block_time=true;
					action_flag="new";
					if(document.getElementById('show_details')) document.getElementById('show_details').style.display="";
					if(recurring_type_open_divs[0]) recurring_type_open_divs[0].checked=true;
					open_divs('D');
					if(document.getElementById("daily_days")) document.getElementById("daily_days").value="";		 	
				 	if(document.getElementById("no_booking_sdate") && document.getElementById("no_booking_edate")) document.getElementById("no_booking_sdate").value=document.getElementById("no_booking_edate").value="<?php echo format_date($current_date);?>";		 	
				 	if(document.getElementById("no_booking_stime_h") && document.getElementById("no_booking_stime_m") && document.getElementById("no_booking_stime_d") && document.getElementById("no_booking_etime_h") && document.getElementById("no_booking_etime_m") && document.getElementById("no_booking_etime_d"))
						document.getElementById("no_booking_stime_h").selectedIndex=document.getElementById("no_booking_stime_m").selectedIndex=document.getElementById("no_booking_stime_d").selectedIndex=document.getElementById("no_booking_etime_h").selectedIndex=document.getElementById("no_booking_etime_m").selectedIndex=document.getElementById("no_booking_etime_d").selectedIndex=0;
		 			if(document.getElementById("weekly_weeks")) document.getElementById("weekly_weeks").value="";
		 			if(document.new_product.elements["no_booking_week_days[]"]){
		 				var obj=document.new_product.elements["no_booking_week_days[]"];
		 				for(i=0;i<obj.length;i++) obj[i].checked=false; 				
		 			}
		 			if(document.getElementById("monthly_week_months") || document.getElementById("monthly_months") || document.getElementById("yearly_month_days") || document.getElementById("monthly_days")) document.getElementById("monthly_days").value=document.getElementById("yearly_month_days").value=document.getElementById("monthly_months").value=document.getElementById("monthly_week_months").value=""; 			
		 			if(document.getElementById("yearly_months") || document.getElementById("yearly_week_months") || document.getElementById("monthly_week_days") || document.getElementById("monthly_weeks") || document.getElementById("yearly_week_months") || document.getElementById("yearly_week_days") || document.getElementById("yearly_weeks")) document.getElementById("monthly_weeks").selectedIndex=document.getElementById("monthly_week_days").selectedIndex=document.getElementById("yearly_week_months").selectedIndex=document.getElementById("yearly_weeks").selectedIndex=document.getElementById("yearly_week_days").selectedIndex=document.getElementById("yearly_week_months").selectedIndex=document.getElementById("yearly_months").selectedIndex=0;
					break;
					case 'edit':						
						document.getElementById('show_details').style.display='';						
						if(document.getElementById("sel_count")) document.getElementById("sel_count").value=tr_index.rowIndex;						
						if(document.getElementById("sel_nb_dates_id")) document.getElementById("sel_nb_dates_id").value=id;
						if(id.length>7){
							id_split=id.split("#");
							if(id_split.length>0){
							  document.new_product.no_booking_sdate.value=id_split[0];
							  document.new_product.no_booking_edate.value=id_split[1];
						 	  var st=get_field(id_split[2],'no_booking_stime');
							  var et=get_field(id_split[3],'no_booking_etime');
							  var rec_type=id_split[4];
						  	  var rec_details=id_split[5];
							}
						}else {
						  document.new_product.no_booking_sdate.value=bk_obj[tr_index.rowIndex].start_date;
						  document.new_product.no_booking_edate.value=bk_obj[tr_index.rowIndex].end_date;
						  var st=get_field(bk_obj[tr_index.rowIndex].start_time,'no_booking_stime');
						  var et=get_field(bk_obj[tr_index.rowIndex].end_time,'no_booking_etime');
						  var rec_type=bk_obj[tr_index.rowIndex].rec_type;	
						  var rec_details=bk_obj[tr_index.rowIndex].rec_detail;
						}											
					    select_rec_details(rec_type,rec_details);
					    var table_obj=document.getElementById("tbl_obj");
					    var cls_name="dataTableRowEven";
					    var n=table_obj.rows.length;
					    for(i=0;i<n;i++){
					      if(i % 2 ==0)  cls_name="dataTableRowEven";
						  else  cls_name="dataTableRowOdd"; 
					      if(table_obj.rows[i]) table_obj.rows[i].className=cls_name;	
					    }
					    if(tr_index) tr_index.className="block_date_selected";
						clear_block_content();						  							  							 					   
					break;
					case 'delete':
						if(document.getElementById("tbl_obj")) var table_obj=document.getElementById("tbl_obj");
						if(table_obj && document.getElementById("sel_count") && document.getElementById("sel_count").value!="" && document.getElementById("sel_nb_dates_id") && document.getElementById("sel_nb_dates_id").value!="" && document.getElementById("nb_dates") && document.getElementById("nb_dates")!=""){
						   var sel_cnt=document.getElementById("sel_count").value;
						   if(table_obj.rows.length==1) sel_cnt=0;
						   table_obj.deleteRow(sel_cnt);						   
						   document.getElementById("nb_dates").value=document.getElementById("nb_dates").value.replace(document.getElementById("sel_nb_dates_id").value,"");
						   document.getElementById("sel_nb_dates_id").value=document.getElementById("sel_count").value="";									   																			
						} 
						if(document.getElementById("tbl_obj")  && document.getElementById("tbl_obj").rows.length==0 && document.getElementById("div_nb_date_list"))
							document.getElementById("div_nb_date_list").style.height="";					
						if(table_obj.rows.length==0 && document.getElementById("img_delete")) document.getElementById("img_delete").style.display="none";
						close_blocked_detail();
					break;
				}
			}
			
		 function confirm_delete(service_id, no_book_id){
		 	if(document.getElementById('head_'+no_book_id)) document.getElementById('head_'+no_book_id).style.display="none";
			if(document.getElementById('show_details_'+no_book_id)) {
				document.getElementById('show_details_'+no_book_id).style.display='';
				document.getElementById('show_details_'+no_book_id).innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
			}
			block_time=true;
			command='<?php echo tep_href_link(FILENAME_SERVICES_MAINPAGE,'action=confirm_delete_blocked_detail');?>&service_id='+service_id+'&no_book_id='+selected_book_id;
			do_get_command(command);
		 }	
		 function close_blocked_detail() {
		 	if(prev_id!="") {
				if(document.getElementById('head_'+prev_id)) document.getElementById('head_'+prev_id).style.display="";
				if(document.getElementById('show_details_'+prev_id)) 
					document.getElementById('show_details_'+prev_id).style.display="none";
			}
		 	if(document.getElementById('show_details')) document.getElementById('show_details').style.display="none";
		 	if(document.getElementById("daily_days")) document.getElementById("daily_days").value="";		 	
		 	if(document.getElementById("no_booking_sdate") && document.getElementById("no_booking_edate")) document.getElementById("no_booking_sdate").value=document.getElementById("no_booking_edate").value="<?php echo format_date($current_date);?>";		 	
		 	if(document.getElementById("no_booking_stime_h") && document.getElementById("no_booking_stime_m") && document.getElementById("no_booking_stime_d") && document.getElementById("no_booking_etime_h") && document.getElementById("no_booking_etime_m") && document.getElementById("no_booking_etime_d"))
				document.getElementById("no_booking_stime_h").selectedIndex=document.getElementById("no_booking_stime_m").selectedIndex=document.getElementById("no_booking_stime_d").selectedIndex=document.getElementById("no_booking_etime_h").selectedIndex=document.getElementById("no_booking_etime_m").selectedIndex=document.getElementById("no_booking_etime_d").selectedIndex=0;
 			if(document.getElementById("weekly_weeks")) document.getElementById("weekly_weeks").value="";
 			if(document.new_product.elements["no_booking_week_days[]"]){
 				var obj=document.new_product.elements["no_booking_week_days[]"];
 				for(i=0;i<obj.length;i++) obj[i].checked=false; 				
 			}
 			if(document.getElementById("monthly_week_months") || document.getElementById("monthly_months") || document.getElementById("yearly_month_days") || document.getElementById("monthly_days")) document.getElementById("monthly_days").value=document.getElementById("yearly_month_days").value=document.getElementById("monthly_months").value=document.getElementById("monthly_week_months").value=""; 			
 			if(document.getElementById("yearly_months") || document.getElementById("yearly_week_months") || document.getElementById("monthly_week_days") || document.getElementById("monthly_weeks") || document.getElementById("yearly_week_months") || document.getElementById("yearly_week_days") || document.getElementById("yearly_weeks")) document.getElementById("monthly_weeks").selectedIndex=document.getElementById("monthly_week_days").selectedIndex=document.getElementById("yearly_week_months").selectedIndex=document.getElementById("yearly_weeks").selectedIndex=document.getElementById("yearly_week_days").selectedIndex=document.getElementById("yearly_week_months").selectedIndex=document.getElementById("yearly_months").selectedIndex=0; 			 			 		
		 }
		 function close_delete_detail(id) {
		 	if(document.getElementById('head_'+id)) document.getElementById('head_'+id).style.display="";
		 	if(document.getElementById('show_details_'+id)) document.getElementById('show_details_'+id).style.display="none";
		 }
		 function do_increment(frm,mode) {
			if(mode!="") {
				if(mode=='d')
					var t_value=31;
				else if(mode=='m')
					var t_value=12;
				else if(mode=='w')
					var t_value=7;	
					
				if(frm.value!="" && parseInt(frm.value)<t_value && !frm.disabled) {
					var day_value=frm.value;
					frm.value=parseInt(day_value)+1;
				} else if(frm.disabled!=true)
					frm.value=1;
			}	
		 }
		 function do_decrement(frm) {
			if(frm.value!="" && parseInt(frm.value)>1) {
				var day_value=frm.value;
				frm.value=parseInt(day_value)-1;
			}
			else
				frm.value=1;
		 }
		 function select_rec_details(rec_type,rec_detail) {		 	
		 	if(rec_type!="") {
				var frm=document.new_product;
				var chk_obj=frm.elements["recurring_type_open_divs"];
				var recurring_array=rec_detail.split(';');
					var open_div = rec_type.substr(0,1);
					open_divs(open_div);
				if(rec_type=="DD")
				{ 
					frm.daily_days.value=rec_detail;
					if(chk_obj[0]) chk_obj[0].checked=true;
					
				}else if(rec_type=="WW"){
					frm.weekly_weeks.value=recurring_array[0];
					selected_days=recurring_array[1].split(',');
					ctl=frm.elements["no_booking_week_days[]"];
					for(icnt=0;icnt<ctl.length;icnt++)
					   ctl[icnt].checked=false;
					for(icnt=0;icnt<selected_days.length;icnt++)
					   ctl[selected_days[icnt]].checked=true;
					if(chk_obj[1]) chk_obj[1].checked=true;
				}else if(rec_type=="MD"){
					frm.recurring_type[0].checked=true;
					frm.monthly_days.value=recurring_array[0];
					frm.monthly_months.value=recurring_array[1];
					if(chk_obj[2]) chk_obj[2].checked=true;
				}else if(rec_type=="MM"){
					frm.recurring_type[1].checked=true;
					frm.monthly_weeks.value=recurring_array[0];
					frm.monthly_week_days.value=recurring_array[1];
					frm.monthly_week_months.value=recurring_array[2];
					if(chk_obj[2]) chk_obj[2].checked=true;
				}else if(rec_type=="YD"){
					frm.recurring_type[2].checked=true;
					frm.yearly_months.value=recurring_array[0];
					frm.yearly_month_days.value=recurring_array[1];
					if(chk_obj[3]) chk_obj[3].checked=true;
				}else if(rec_type=="YY"){
					frm.recurring_type[3].checked=true;
					frm.yearly_weeks.value=recurring_array[0];
					frm.yearly_week_days.value=recurring_array[1];
					frm.yearly_week_months.value=recurring_array[2];
					if(chk_obj[3]) chk_obj[3].checked=true;
				}
			}
		 }
			function do_date_action(action,start){ 				
				var frm=document.new_product;
				var error_result="";				
					if(start!=1) var sIndex=frm.no_booking_date_list.selectedIndex;	
					if(start==1){
						sIndex=0;
						if(frm.no_booking_date_list.options.length >0) frm.no_booking_date_list.options[sIndex].selected=true;
						else{
							open_divs('D');
						 return;
						 }
					}
					switch(action){
						case "edit":
						case "add":
					var temp=getDetails();
					var pos;
					dateAdd=temp[0];
					dateAddText=temp[1];
					if(validateBookingform()==false)
							return;
							if (check_date_exists(dateAddText,action)){
								alert('<?php echo addslashes(TEXT_DATE_ALREADY_EXISTS); ?>');
								return;
							}
							if (action=="edit") frm.no_booking_date_list.remove(sIndex);														
							var pos=get_position(dateAdd);
							var oOption = document.createElement("OPTION");
							oOption.text=dateAddText;
							oOption.value=dateAdd;
							if(frm.no_booking_date_list.add.length==2)
								 frm.no_booking_date_list.add(oOption,null);
							else
								 frm.no_booking_date_list.add(oOption,pos);
								 
								pos=frm.no_booking_date_list.length;
								frm.no_booking_date_list.selectedIndex=pos-1;
								clear_block_content();					
							break;
						case "delete":
							if (sIndex<0) return;
							frm.no_booking_date_list.remove(sIndex);
							if (sIndex>0 && sIndex<frm.no_booking_date_list.length-1)
								sIndex=sIndex+1;
							else if (sIndex>0)
								sIndex=sIndex-1;
							else if (sIndex>=frm.no_booking_date_list.length) sIndex=frm.no_booking_date_list.length-1;
							frm.no_booking_date_list.selectedIndex=sIndex;
								do_date_action('select');
							if(sIndex<0)
								{
									frm.daily_days.value='';
									frm.weekly_weeks.value='';
									frm.monthly_days.value='';
									frm.monthly_months.value='';
									frm.monthly_week_months.value='';
									frm.yearly_month_days.value='';
								}
							break;
						case "select":
							if (sIndex<0) return;
								frm.daily_days.value='';
								frm.weekly_weeks.value='';
								frm.monthly_days.value='';
								frm.monthly_months.value='';
								frm.monthly_week_months.value='';
								frm.yearly_month_days.value=''; 
								frm.monthly_weeks.value=0;
								frm.monthly_week_days.value=0;
								frm.yearly_months.value=0;
								frm.yearly_weeks.value=0;
								frm.yearly_week_days.value=0;
								frm.yearly_week_months.value=0; 
								ctl=frm.elements["no_booking_week_days[]"];
								for(icnt=0;icnt<ctl.length;icnt++)
								   ctl[icnt].checked=false;								
							var blocked_date=frm.no_booking_date_list.options[sIndex].value.split("#");
							frm.no_booking_sdate.value=blocked_date[0];
							frm.no_booking_edate.value=blocked_date[1];	
							no_booking_stime=get_field(blocked_date[2],"no_booking_stime");
							no_booking_etime=get_field(blocked_date[3],"no_booking_etime");
							frm.recurring_type.value=blocked_date[4];
							for(icnt=0;icnt<frm.recurring_type.length;icnt++){
	 						   if(frm.recurring_type[icnt].value==blocked_date[4]){
	 						    frm.recurring_type[icnt].checked=true;
	  						 	break;
							  }
							 }  
							recurring_detail=blocked_date[5];
							var recurring_array=recurring_detail.split(';');
							if(start==1){
								var open_div = frm.recurring_type.value.substr(0,1);
								open_divs(open_div);
							}
							if(frm.recurring_type.value=="DD")
							{ 
								frm.daily_days.value=recurring_detail;
								}
								else if(frm.recurring_type.value=="WW"){
								frm.weekly_weeks.value=recurring_array[0];
								selected_days=recurring_array[1].split(',');
								ctl=frm.elements["no_booking_week_days[]"];
								for(icnt=0;icnt<selected_days.length;icnt++){
								   ctl[selected_days[icnt]].checked=true ;
								} 
							}else if(frm.recurring_type.value=="MD"){
								frm.monthly_days.value=recurring_array[0];
								frm.monthly_months.value=recurring_array[1];
							}
							else if(frm.recurring_type.value=="MM"){
								frm.monthly_weeks.value=recurring_array[0];
								frm.monthly_week_days.value=recurring_array[1];
								frm.monthly_week_months.value=recurring_array[2];
							}
							else if(frm.recurring_type.value=="YD"){
								frm.yearly_months.value=recurring_array[0];
								frm.yearly_month_days.value=recurring_array[1];
							}
							else if(frm.recurring_type.value=="YY"){
								frm.yearly_weeks.value=recurring_array[0];
								frm.yearly_week_days.value=recurring_array[1];
								frm.yearly_week_months.value=recurring_array[2];
							} 						
						return; 
					}
				} 
				
			function do_date_action_load(action){
				var frm=document.new_product;
				var error_result="";
				var sIndex=frm.loading_date_list.selectedIndex;
				var pos;
				switch(action){
						case "edit":
						case "add":
						var temp=getDetails_load();
						dateAdd=temp[0];
						dateAddText=temp[1];
						if(subvalidateBookingform()==false)
							return;
							if (check_date_exists_load(dateAddText,action)){
								alert('<?php echo addslashes(TEXT_DATE_ALREADY_EXISTS); ?>');
								return;
							}
							if (action=="edit")  frm.loading_date_list.remove(sIndex);							
							var pos=get_load_position(dateAdd);
							var oOption = document.createElement("OPTION");
							oOption.text=dateAddText;
							oOption.value=dateAdd;
							if(frm.loading_date_list.add.length==2)
							 frm.loading_date_list.add(oOption, null);
							else  
							 frm.loading_date_list.add(oOption,pos);							
							
							pos=frm.loading_date_list.length;
							frm.loading_date_list.selectedIndex=pos-1;
							clear_load_content();

							close_loaded_details();
							break;
						case "delete":
							if (sIndex<0) return;
							frm.loading_date_list.remove(sIndex);
							close_loaded_details(); 
							if (sIndex>0 && sIndex<frm.loading_date_list.length-1)
								sIndex=sIndex+1;
							else if (sIndex>0)
								sIndex=sIndex-1;
							else if (sIndex>=frm.loading_date_list.length) sIndex=frm.loading_date_list.length-1;
							frm.loading_date_list.selectedIndex=sIndex;
								do_date_action_load('select');
							if(sIndex<0)
								{
									frm.loading_daily_days.value='';
									frm.loading_weekly_weeks.value='';
									frm.loading_monthly_days.value='';
									frm.loading_monthly_months.value='';
									frm.loading_monthly_week_months.value='';
									frm.loading_yearly_month_days.value='';
									frm.loading_price.value='';
									ctl=frm.elements["loading_week_days[]"];
										for(icnt=0;icnt<ctl.length;icnt++){
								  		 ctl[icnt].checked=false; 
								} 
								}
							break;
						case "select":
							if (sIndex<0) return;
							document.getElementById('trash_button').style.display='';
							document.getElementById('save_button').href="javascript: do_date_action_load('edit');";
							var load_recurring_type=document.new_product.elements["loading_recurring_type"];
								frm.loading_daily_days.value='';
								frm.loading_weekly_weeks.value='';
								frm.loading_monthly_days.value='';
								frm.loading_monthly_months.value='';
								frm.loading_monthly_week_months.value='';
								frm.loading_yearly_month_days.value=''; 
								frm.loading_monthly_weeks.value=0;
								frm.loading_monthly_week_days.value=0;
								frm.loading_yearly_months.value=0;
								frm.loading_yearly_weeks.value=0;
								frm.loading_yearly_week_days.value=0;
								frm.loading_yearly_week_months.value=0; 
								frm.loading_price.value='';
								frm.loading_type.value=0;
								ctl=frm.elements["loading_week_days[]"];
								for(icnt=0;icnt<ctl.length;icnt++)
								   ctl[icnt].checked=false;								
							var blocked_date=frm.loading_date_list.options[sIndex].value.split("#");
							frm.loading_sdate.value=blocked_date[0];
							frm.loading_edate.value=blocked_date[1];
							no_booking_stime=get_field(blocked_date[2],"loading_stime");
							no_booking_etime=get_field(blocked_date[3],"loading_etime");
							frm.loading_recurring_type.value=blocked_date[4];
							frm.loading_type.value=blocked_date[7];
							if(frm.loading_type.value == 'P'){
								frm.loading_price.setAttribute('maxlength',3);
								frm.loading_price.value=blocked_date[6];
								document.getElementById('price_label').innerHTML = 'Percentage: ';
							}else if(frm.loading_type.value == 'C'){
								frm.loading_price.setAttribute('maxlength',7);
								frm.loading_price.value=blocked_date[6];
								document.getElementById('price_label').innerHTML = 'Loading Price: ';
							}
							for(icnt=0;icnt<frm.loading_recurring_type.length;icnt++){
	 						  if(frm.loading_recurring_type[icnt].value==blocked_date[4]){
	 						    frm.loading_recurring_type[icnt].checked=true;
	  						 	break;
							  }
							 } 						 
							 recurring_detail=blocked_date[5];
							 var recurring_array=recurring_detail.split(';');
							 if(frm.loading_recurring_type.value=="DD")
							 {
								frm.loading_daily_days.value=recurring_detail;
								open_loads('D');
							 }	else if(frm.loading_recurring_type.value=="WW"){
								frm.loading_weekly_weeks.value=recurring_array[0];
								selected_days=recurring_array[1].split(',');
								ctl=frm.elements["loading_week_days[]"];
								for(icnt=0;icnt<selected_days.length;icnt++){
								   ctl[selected_days[icnt]].checked=true ;
								} 
								open_loads('W');
							}	
							else if(frm.loading_recurring_type.value=="MD"){
								frm.loading_monthly_days.value=recurring_array[0];
								frm.loading_monthly_months.value=recurring_array[1];
								open_loads('M');
							}
							else if(frm.loading_recurring_type.value=="MM"){
								open_loads('M');
								if(load_recurring_type[1]) load_recurring_type[1].checked=true;
								clear_load_content('select');
								frm.loading_monthly_weeks.value=recurring_array[0];
								frm.loading_monthly_week_days.value=recurring_array[1];
								frm.loading_monthly_week_months.value=recurring_array[2];
							}
							else if(frm.loading_recurring_type.value=="YD"){
							open_loads('Y');
								frm.loading_yearly_months.value=recurring_array[0];
								frm.loading_yearly_month_days.value=recurring_array[1];
							}
							else if(frm.loading_recurring_type.value=="YY"){
								open_loads('Y');
								if(load_recurring_type[3]) load_recurring_type[3].checked=true;
								clear_load_content('select');
								frm.loading_yearly_weeks.value=recurring_array[0];
								frm.loading_yearly_week_days.value=recurring_array[1];
								frm.loading_yearly_week_months.value=recurring_array[2];
							} 
						return;
					}
					if(document.getElementById('loading_date_list').length>0)
						document.getElementById('loading_date_list').style.display="";
				} 
	function doRound(x, places) {
	  return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
	}
				
	function dollarAmount(Num) {
		var sym_left="<?php echo $currencies->currencies[$currency]['symbol_left'];?>";
		var sym_right="<?php echo $currencies->currencies[$currency]['symbol_right'];?>";
		
		if (typeof(Num)=="number") {
			Num=doRound(Num,2);
			Num=""+Num;
		} else {
			Num=""+doRound(parseFloat(Num),2);
		}
		
		dec = Num.indexOf(".");
		end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00");
		Num = "" + parseInt(Num);
	
		var temp1 = "";
		var temp2 = "";
		
		if (end.length == 2) end += "0";
		if (end.length == 1) end += "00";
		if (end == "") end += ".00";
	
		var count = 0;
		for (var k = Num.length-1; k >= 0; k--) {
		var oneChar = Num.charAt(k);
		if (count == 3 && oneChar!="-") {
		temp1 += ",";
		temp1 += oneChar;
		count = 1;
		continue;
		}
		else {
		temp1 += oneChar;
		count ++;
		   }
		}
		for (var k = temp1.length-1; k >= 0; k--) {
		var oneChar = temp1.charAt(k);
		temp2 += oneChar;
		}
		temp2 = sym_left + temp2 + end + sym_right;
		return temp2;
	
					}
				
				function getDetails_load()
				{
				var frm=document.new_product; 
				var loading_selectedweekdays="";
				var loading_selecteddays=""
				var loading_dateAdd=Array();
				var loading_dayArray=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
				var loading_monthArray=new Array('Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec');
				var loading_placeArray=new Array('first','second','third','fourth');
				for(i=0;i<frm.loading_recurring_type.length;i++){
		 		   if(frm.loading_recurring_type[i].checked==true){
					var type=frm.loading_recurring_type[i].value;
					break;
				   }
		 		}
				if(document.getElementById("daily_check") && document.getElementById("daily_check").checked) type='DD'; 
				if(document.getElementById("weekly_check") && document.getElementById("weekly_check").checked) type='WW';
				loading_no_booking_stime=get_time_field("loading_stime");
				loading_no_booking_etime=get_time_field("loading_etime")
				loading_no_booking_stime_text=get_time("loading_stime");
				loading_no_booking_etime_text=get_time("loading_etime");
				loading_price=frm.loading_price.value;
				loading_type=frm.loading_type.value;
				if(frm.loading_type.value=='P')
					lprice=loading_price+" %";
				else lprice=dollarAmount(loading_price);	
				var loading_datetime=" from " + frm.loading_sdate.value + " to "+ frm.loading_edate.value + ((frm.booking_type.value=='H' || frm.booking_type.value=='M')?" bet., " + loading_no_booking_stime_text + " to " + loading_no_booking_etime_text:"" )+ " & price is "+ lprice;
				if(type=="DD")
					{					
						var loading_recurring_detail=frm.loading_daily_days.value;
						var loading_recurring_text="Every " + frm.loading_daily_days.value + " days " + loading_datetime;
					}
				else if(type=="WW")
					{
					 ctl=frm.elements["loading_week_days[]"];
					 for(icnt=0;icnt<ctl.length;icnt++){
					   if (ctl[icnt].checked==true) 
					   		{
							loading_selectedweekdays+=(ctl[icnt].value-1)+",";	
							loading_selecteddays+=loading_dayArray[icnt]+",";		   
							}
	    				}
						loading_selecteddays=loading_selecteddays.substring(0,((loading_selecteddays.length)-1));
						loading_weekdays=loading_selectedweekdays.substring(0,((loading_selectedweekdays.length)-1));
					var loading_recurring_detail=frm.loading_weekly_weeks.value+";"+loading_weekdays;
					var loading_recurring_text="Every " + frm.loading_weekly_weeks.value + " week(s) on " + loading_selecteddays + loading_datetime;
				}
				else if(type=="MD")
				{
					var loading_recurring_detail=frm.loading_monthly_days.value+";"+frm.loading_monthly_months.value;
					var loading_recurring_text="Day " + frm.loading_monthly_days.value + " of every " + frm.loading_monthly_months.value  + " months " + loading_datetime;
					}
				else if(type=="MM")
				{
					var loading_recurring_detail=frm.loading_monthly_weeks.value+";"+frm.loading_monthly_week_days.value+";"+frm.loading_monthly_week_months.value;
					var loading_recurring_text="The " + loading_placeArray[frm.loading_monthly_weeks.value] + " " + loading_dayArray[frm.loading_monthly_week_days.value]  + " of every " + frm.loading_monthly_week_months.value + " months "+ loading_datetime;
					}
				else if(type=="YD")
				{
					var loading_recurring_detail=frm.loading_yearly_months.value+";"+frm.loading_yearly_month_days.value;
					var loading_recurring_text="For every " + loading_monthArray[frm.loading_yearly_months.value] + " " + frm.loading_yearly_month_days.value + " "  + loading_datetime;
					}
				else if(type=="YY")
				{
					var loading_recurring_detail=frm.loading_yearly_weeks.value+";"+frm.loading_yearly_week_days.value+";"+frm.loading_yearly_week_months.value;			
					var loading_recurring_text="The " + loading_placeArray[frm.loading_yearly_weeks.value] + " " + loading_dayArray[frm.loading_yearly_week_days.value] + " of " + loading_monthArray[frm.loading_yearly_week_months.value] + loading_datetime; 
					}
					
				loading_dateAdd[0]=frm.loading_sdate.value+"#"+frm.loading_edate.value+"#"+loading_no_booking_stime+"#"+loading_no_booking_etime+"#"+type+"#"+loading_recurring_detail+"#"+loading_price+"#"+loading_type;
				loading_dateAdd[1]=loading_recurring_text;
				return loading_dateAdd;
			}

				
				function get_field(time_value,ctlName)
				{
				
				var day_session="";
				time_array=time_value.split(":");
				if(time_array[0]==12)
					time_array[0]=parseInt(time_array[0])+12;
				
				if(time_array[0]==00)
				{
					time_array[0]=12;
					day_session="AM";
					}
				if(time_array[0]>12)
				{
					day_session="PM";
					time_array[0]=time_array[0]-12;
						if(time_array[0]<10)
							time_array[0]="0"+time_array[0];
					
				}
				else
					day_session="AM";	
			document.new_product.elements[ctlName+"_h"].value=time_array[0];
			document.new_product.elements[ctlName+"_m"].value=time_array[1];
			document.new_product.elements[ctlName+"_d"].value=day_session;	
				return document.new_product.elements[ctlName+"_h"].value+":"+document.new_product.elements[ctlName+"_m"].value+":"+document.new_product.elements[ctlName+"_d"].value;
				
				}  
			function get_booking_list(book_text) {
				if(book_text) {
					var book_array=new Array();
					book_array=book_text.split('**');
					var tr_res="";
					var dayArray=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
					var monthArray=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
					var placeArray=new Array('first','second','third','fourth');
					var selecteddays="";
					var type;
					var i="";
					var obj_class="";
					for(i=0;i<book_array.length;i++) {
						var book_obj_value=new Array();
						var dateAdd="";
						book_obj_value=book_array[i].split('{}');
						book_obj={"book_id":book_obj_value[0],"start_date":book_obj_value[1],"end_date":book_obj_value[2],"start_time":book_obj_value[3],"end_time":book_obj_value[4],"stime":book_obj_value[5],"etime":book_obj_value[6],"rec_type":book_obj_value[7],"rec_detail":book_obj_value[8]};
						bk_obj[i]={"book_id":book_obj_value[0],"start_date":book_obj_value[1],"end_date":book_obj_value[2],"start_time":book_obj_value[3],"end_time":book_obj_value[4],"stime":book_obj_value[5],"etime":book_obj_value[6],"rec_type":book_obj_value[7],"rec_detail":book_obj_value[8]};
						dateAdd=book_obj_value[1]+"#"+book_obj_value[2]+"#"+book_obj_value[3]+"#"+book_obj_value[4]+"#"+book_obj_value[7]+"#"+book_obj_value[8];
						var datetime=" from " + book_obj.start_date + " to "+ book_obj.end_date + ((book_obj.stime!="")?" bet., " + book_obj.stime + " to " + book_obj.etime:'');
						type=book_obj.rec_type; 
						if(type=="DD") 							
							var recurring_text="Every " + book_obj.rec_detail + " days " + datetime;							
						else if(type=="WW") {
							var type_array=(book_obj.rec_detail).split(';');
							var day_detail=type_array[1].split(',');
							var selecteddays="";
							for(icnt=0;icnt<day_detail.length;icnt++) selecteddays+=dayArray[day_detail[icnt]]+",";		   														
							selecteddays=selecteddays.substring(0,((selecteddays.length)-1));
							var recurring_text="Every " + type_array[0] + " week(s) on " + selecteddays + datetime;
						}else if(type=="MD"){
							var type_array=(book_obj.rec_detail).split(';');
							var recurring_text="Day " + type_array[0] + " of every " + type_array[1]  + " months " + datetime;
						}else if(type=="MM"){
							var type_array=(book_obj.rec_detail).split(';');
							var recurring_text="The " + placeArray[type_array[0]] + " " + dayArray[type_array[1]]  + " of every " + type_array[2] + " months "+ datetime;
						}else if(type=="YD"){
							var type_array=(book_obj.rec_detail).split(';');
							var recurring_text="For every " + monthArray[type_array[0]] + " " + type_array[1] + " "  + datetime;
						}else if(type=="YY"){
							var type_array=(book_obj.rec_detail).split(';');
							var recurring_text="The " + placeArray[type_array[0]] + " " + dayArray[type_array[1]] + " of " + monthArray[type_array[2]] + datetime; 
						}
						if(i%2==0)  obj_class="dataTableRowEven";
						else obj_class="dataTableRowOdd";
					    tr_res+='<tr class="' + obj_class+ '" onclick="do_add_block(\'edit\',\'' + dateAdd + '\',this'+');" id="tr_' + i + '" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);" ><td>'+recurring_text+'</td></tr>';
					    if(document.getElementById("img_delete")) document.getElementById("img_delete").style.display="";
					  }
					   if(document.getElementById("div_tbl")) document.getElementById("div_tbl").innerHTML='<table border="0" cellspacing="0" class="main" cellpadding="0" width="100%" id="tbl_obj">'+tr_res+'</table>'; 
					   no_book_text=book_text;
					}
					var table_obj=document.getElementById("tbl_obj");						
					if(table_obj && table_obj.rows.length>4 && document.getElementById("div_nb_date_list")) document.getElementById("div_nb_date_list").style.height="80";
				}
				function getDetails()
				{
				var frm=document.new_product;
				var selectedweekdays="";
				var selecteddays="";
				var dateAdd=Array();
				var dayArray=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
				var monthArray=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
				var placeArray=new Array('first','second','third','fourth');
		 	    var obj=frm.elements["recurring_type"];
				if(document.getElementById('daily_div').style.display=="")
					type="DD";
				else if(document.getElementById('week_div').style.display=="") type="WW";
				else if(document.getElementById('month_div').style.display=="") {
					if(obj[0].value=='MD' && obj[0].checked) type="MD";
					else if(obj[1].value=='MM' && obj[1].checked) type="MM";
				}else if(document.getElementById('year_div').style.display=="") {
					if(obj[2].value=='YD' && obj[2].checked) type="YD";
				    else if(obj[3].value=='YY' && obj[3].checked) type="YY";
				}
				no_booking_stime=get_time_field("no_booking_stime");
				no_booking_etime=get_time_field("no_booking_etime");
				no_booking_stime_text=get_time("no_booking_stime");
				no_booking_etime_text=get_time("no_booking_etime");
				var datetime=" from " + date_format(frm.no_booking_sdate.value,'','') + " to "+ date_format(frm.no_booking_edate.value,'','') +((frm.booking_type.value=='H' || frm.booking_type.value=='M')? " bet., " + no_booking_stime_text + " to " + no_booking_etime_text:"");
				if(type=="DD")
				{
					var recurring_detail=frm.daily_days.value;
					var recurring_text="Every " + frm.daily_days.value + " days " + datetime;
				}else if(type=="WW")
					{
					 ctl=frm.elements["no_booking_week_days[]"];
					 for(icnt=0;icnt<ctl.length;icnt++){
					   if (ctl[icnt].checked==true) 
					   		{
							selectedweekdays+=(ctl[icnt].value-1)+",";	
							selecteddays+=dayArray[icnt]+",";		   
							}
	    				}
						
						selecteddays=selecteddays.substring(0,((selecteddays.length)-1));
						weekdays=selectedweekdays.substring(0,((selectedweekdays.length)-1));
						
					var recurring_detail=frm.weekly_weeks.value+";"+weekdays;
					var recurring_text="Every " + frm.weekly_weeks.value + " week(s) on " + selecteddays + datetime;
				}
				else if(type=="MD")
				{
					var recurring_detail=frm.monthly_days.value+";"+frm.monthly_months.value;
					var recurring_text="Day " + frm.monthly_days.value + " of every " + frm.monthly_months.value  + " months " + datetime;
					}
				else if(type=="MM")
				{
					var recurring_detail=frm.monthly_weeks.value+";"+frm.monthly_week_days.value+";"+frm.monthly_week_months.value;
					var recurring_text="The " + placeArray[frm.monthly_weeks.value] + " " + dayArray[frm.monthly_week_days.value]  + " of every " + frm.monthly_week_months.value + " months "+ datetime;
					}
				else if(type=="YD")
				{
					var recurring_detail=frm.yearly_months.value+";"+frm.yearly_month_days.value;
					var recurring_text="For every " + monthArray[frm.yearly_months.value] + " " + frm.yearly_month_days.value + " "  + datetime;
					}
				else if(type=="YY")
				{
					var recurring_detail=frm.yearly_weeks.value+";"+frm.yearly_week_days.value+";"+frm.yearly_week_months.value;			
					var recurring_text="The " + placeArray[frm.yearly_weeks.value] + " " + dayArray[frm.yearly_week_days.value] + " of " + monthArray[frm.yearly_week_months.value] + datetime; 
					}
					
				dateAdd[0]=date_format(frm.no_booking_sdate.value,'','')+"#"+date_format(frm.no_booking_edate.value,'','')+"#"+no_booking_stime+"#"+no_booking_etime+"#"+type+"#"+recurring_detail;
				dateAdd[1]=recurring_text;
				return dateAdd;
			}
				
				function isDate(dateStr,formDate) {
					var format='<?php echo EVENTS_DATE_FORMAT;?>';
					switch(format){
						case 'd-m-Y':
							var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
							var matchArray = dateStr.match(datePat); // is format OK?
							if (matchArray == null) {
							return false;
							}
							day= matchArray[1];
							month = matchArray[3];
							year = matchArray[5];
							break;
				
						case 'm-d-Y':
							var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
							var matchArray = dateStr.match(datePat); // is format OK?
							if (matchArray == null) {
							return false;
							}
							
							month = matchArray[1];
							day= matchArray[3];
							year = matchArray[5];
							break;
				
						default:
							var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
							var matchArray = dateStr.match(datePat); // is format OK?
							if (matchArray == null) {
							return false;
							}
							
							year = matchArray[1];
							month = matchArray[3];
							day= matchArray[5];
							break;
					}
					if (matchArray == null) {
						return false;
					}
					if (formDate){
						var temp=Array();
						if (month.length<2) month="0"+month;
						if (day.length<2) day="0"+day;
						format=format.replace("d",day);
						format=format.replace("m",month);
						format=format.replace("Y",year);
						temp[0]=year+"-"+month+"-"+day;
						temp[1]=format
						return temp;
					}
					// parse date into variables
					if (month < 1 || month > 12) { // check month range
					return false;
					}
				
					if (day < 1 || day > 31) {
					return false;
					}
				
					if ((month==4 || month==6 || month==9 || month==11) && day==31) {
					return false;
					}
				
					if (month == 2) { // check for february 29th
						var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
						if (day > 29 || (day==29 && !isleap)) {
							return false;
						}
					}
					return true; 
				}
				
				function do_booking_buffer(buffer_check){ 
				   	var box_buffer=document.getElementById('book_minute');
				   	var sel_buffer=document.getElementById('sel_book_buffer');
				   	if(sel_buffer)sel_buffer.checked=buffer_check;
				   	if(box_buffer && !buffer_check) box_buffer.style.display='none';
						else if(box_buffer && buffer_check) box_buffer.style.display='';	
				}	
								
				function do_check_control(mode){
					var frm=document.new_product;
					var boolean;
					var frm_sph1=document.getElementById("spHours1");
					var frm_sph2=document.getElementById("spHours2");
					var frm_sph3=document.getElementById("spHours3");
					if (mode==0 || mode==1){ // booking_type
						boolean=false;
						if(frm.booking_type.value=='D') boolean=true;
						frm.span_days.disabled=boolean;
						if (frm.booking_type.value=="M")
							frm_sph1.innerHTML=frm_sph2.innerHTML=frm_sph3.innerHTML="<?php echo TEXT_MINS;?>";
						else if (frm.booking_type.value=="H")
							frm_sph1.innerHTML=frm_sph2.innerHTML=frm_sph3.innerHTML="<?php echo TEXT_HOURS;?>";
						else if (frm.booking_type.value=="D")							
							frm_sph1.innerHTML=frm_sph2.innerHTML=frm_sph3.innerHTML="<?php echo TEXT_DAYS;?>";						
					    	do_time_enable("no_booking_stime",true);
						 	do_time_enable("no_booking_etime",true);						 	
						if(frm.booking_type.value!="D"){
					     	var frm_ro=document.getElementById("recurring_type_option").style.display;
						 	do_time_enable("no_booking_stime",false);
						 	do_time_enable("no_booking_etime",false);	
							frm_ro="none";
					      }    
						 	do_time_enable("loading_stime",true);
						 	do_time_enable("loading_etime",true);	
						if(frm.booking_type.value!="D"){ //  && (frm.include_loadings.checked)
					     	var frm_loading_bo=document.getElementById("loading_recurring_type_option").style.display;
						 	do_time_enable("loading_stime",false);
						 	do_time_enable("loading_etime",false);	
							/*if(frm.include_loadings.checked)
								frm_loading_bo="";
							else
								frm_loading_bo="none";*/
							frm_loading_bo="";
					      }    
					  }
						
					if (mode==0 || mode==2){ //no booking start time
						boolean=!frm.no_booking_time.checked;
						frm.no_booking_sdate.disabled=boolean;
						frm.no_booking_edate.disabled=boolean;
						if (!boolean && frm.booking_type.value=="D") boolean=true;
						do_time_enable("no_booking_stime",boolean);
						do_time_enable("no_booking_etime",boolean);
						if(boolean=frm.no_booking_time.checked)
							document.getElementById("recurring_type_option").style.display="";
						else
							document.getElementById("recurring_type_option").style.display="none";						
					}
					if (mode==0){
						ctl=frm.elements["no_booking_week_days[]"];
						for (icnt=0;icnt<ctl.length;icnt++){
							if (ctl[icnt].checked){
								frm.no_booking_week.checked=true;
								break;
							}
						}
					}
				   if (mode==0 || mode==6){
				      boolean = frm.resource_price.checked;
				      frm.service_tax_class_id.disabled=boolean;
						frm.service_costs_net.disabled=boolean;
						frm.service_costs_gross.disabled=boolean;
						if(frm.resource_price && boolean) frm.resource_price.value='Y';
						else if(frm.resource_price && !boolean) frm.resource_price.value='N';
				   }
				  if (mode==7){
				      	boolean=!frm.include_resource.checked;
						if(!boolean)
						{							
							if(frm.sel_service_avilable) frm.sel_service_avilable.checked=boolean;
							if(frm.quantity && document.getElementById("m_purchase")) frm.quantity.style.display=document.getElementById("m_purchase").style.display="none";
							if(document.getElementById("display_resource")) document.getElementById("display_resource").style.display="";
							frm.quantity.disabled=true;
							frm.resource_price.disabled=false;
							if(document.getElementById("multiple_purchase")){
								 document.getElementById("multiple_purchase").checked=boolean;
								 document.getElementById("multiple_purchase").disabled=!boolean;								 
							}
							if(frm.include_resource) frm.include_resource.value='Y';  
						}else {
							document.getElementById("display_resource").style.display="none";
							frm.quantity.disabled=false;
							frm.resource_price.checked=false;
							frm.resource_price.disabled=true;
							frm.service_tax_class_id.disabled=false;
							frm.service_costs_net.disabled=false;
							frm.service_costs_gross.disabled=false;
							if(document.getElementById("multiple_purchase")) document.getElementById("multiple_purchase").disabled=!boolean;
							if(frm.include_resource) frm.include_resource.value='N';
						}
				  }
				  if (mode==0 || mode==8){
				  boolean=!frm.include_loadings.checked;
						frm.no_booking_sdate.disabled=boolean;
						frm.no_booking_edate.disabled=boolean;
						if (!boolean && frm.booking_type.value=="D") boolean=true;
						do_time_enable("loading_stime",boolean);
						do_time_enable("loading_etime",boolean);
						if(frm.include_loadings.checked){
							document.getElementById("loading_recurring_type_option").style.display="";
							document.getElementById('loading_date_list').style.display='';
							document.getElementById('loading_operation').style.display='';
						}else{
							document.getElementById('loading_date_list').style.display='none';
							document.getElementById("loading_recurring_type_option").style.display="none";
							document.getElementById('loading_operation').style.display='none';
						}
				  }
				 if(mode==9 && frm.sel_service_avilable){
				 	if(frm.sel_service_avilable.checked){
				 		frm.include_resource.checked=false;
				 		if(frm.quantity && document.getElementById("m_purchase")) frm.quantity.style.display=document.getElementById("m_purchase").style.display="";
				 		do_check_control(7);
				 	}else if(!frm.sel_service_avilable.checked && frm.quantity && document.getElementById("m_purchase")) frm.quantity.style.display=document.getElementById("m_purchase").style.display="none";
				 }
				}
				function do_time_enable(name,enable){
					document.new_product.elements[name+"_h"].disabled=enable;
					document.new_product.elements[name+"_m"].disabled=enable;
					document.new_product.elements[name+"_d"].disabled=enable;
				}
				
				function close_loaded_details(){
				document.getElementById('loading_date_list').selectedIndex=-1;
				document.getElementById('load_check_condition').style.display='none';
				document.getElementById("loading_recurring_type_option").style.display="none";
				document.getElementById('date_id').style.display='none';
				}
				
				function init_page(){
					updateGross();
					do_check_control(0);
					if (document.new_product.no_booking_date_list.options.length>0){
						document.new_product.no_booking_date_list.selectedIndex=0;
					do_date_action("select");
					} 
					if (document.new_product.loading_date_list.options.length>0){
						document.new_product.loading_date_list.selectedIndex=0;
					do_date_action_load("select");
					} 
				}
	function getKeyCode(e){
		if (window.event)
		return window.event.keyCode;
		else if (e)
		return e.which;
		else
		return null;
	}
	function keyRestrict(e) {
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) return true;
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		if(key>47 && key<58 || key==0 || key==8)
			return true;
		else
			return false;
	}	
	function do_change_event(e){
		if(e.value == 'C'){
			document.getElementById('loading_price').setAttribute('maxlength',7);
			document.getElementById('price_label').innerHTML = 'Loading Price: ';
		}	
		else if(e.value == 'P')	{
			document.getElementById('loading_price').setAttribute('maxlength',3);
			document.getElementById('price_label').innerHTML = 'Percentage: ';
		}	
		document.getElementById('loading_price').value = '';	
	}
	  
function open_divs(mode){
	 var type = mode;
	 var recurring_type_open_divs_obj=document.new_product.recurring_type_open_divs;
	 var recurring_type=document.new_product.elements["recurring_type"];	 
	switch (type){
		case 'D':
				document.getElementById('rec_type').value='DD';
			    recurring_type_open_divs_obj[0].checked=recurring_type_open_divs_obj[0].checked;			    
			    recurring_type_open_divs_obj[1].checked=recurring_type_open_divs_obj[2].checked=recurring_type_open_divs_obj[3].checked=false;
				document.getElementById('daily_div').style.display='';
				document.getElementById('week_div').style.display='none';
				document.getElementById('month_div').style.display='none';
				document.getElementById('year_div').style.display='none';
				break;
		case 'W':
				recurring_type_open_divs_obj[1].checked=recurring_type_open_divs_obj[1].checked;
			    recurring_type_open_divs_obj[0].checked=recurring_type_open_divs_obj[2].checked=recurring_type_open_divs_obj[3].checked=false;
				document.getElementById('week_div').style.display='';
				document.getElementById('daily_div').style.display='none';
				document.getElementById('month_div').style.display='none';
				document.getElementById('year_div').style.display='none';
				break;
		case 'M':				
				recurring_type_open_divs_obj[2].checked=recurring_type_open_divs_obj[2].checked;			    
			    recurring_type_open_divs_obj[0].checked=recurring_type_open_divs_obj[1].checked=recurring_type_open_divs_obj[3].checked=false;
				document.getElementById('month_div').style.display='';
				document.getElementById('daily_div').style.display='none';
				document.getElementById('week_div').style.display='none';
				document.getElementById('year_div').style.display='none';
				if(recurring_type[0]) recurring_type[0].checked=true;
				break;
	 	case 'Y':
 				recurring_type_open_divs_obj[3].checked=recurring_type_open_divs_obj[3].checked;
		    	recurring_type_open_divs_obj[0].checked=recurring_type_open_divs_obj[1].checked=recurring_type_open_divs_obj[2].checked=false;
				document.getElementById('year_div').style.display='';
				document.getElementById('month_div').style.display='none';
				document.getElementById('daily_div').style.display='none';
				document.getElementById('week_div').style.display='none';
				if(recurring_type[2]) recurring_type[2].checked=true;				
				break;
	}
	clear_block_content();
}
function changeStyle(element,mode){
	if (selectedTab && selectedTab.id==element.id) return;	
}

var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
    var lang=new Array();
    var file_name="<?php echo $file_name;?>";
    <?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;		   	  	  	            
	var attributes_array=new Array();
	var values_arr=new Array();
	var pname="";
	var cname="";
	var attrb_cnt=0;
	var splt=Array()
	var tax_rates = new Array();
	<?php
		$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";			
	?>
	function doRound(x, places) {
  		return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
	}
	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=""; 				
			return false;	
		}
	}
 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(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!='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 && c_obj.value=="") 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(action!='pos_down' &&  action!='pos_up' && 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!='go_session')) c_obj.value=category_id;
		var img_div=document.getElementById("img_save_"+id);
		if(!category_id && document.getElementById("span_details_"+id) && action!='new_category') 			
			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=='go_session'){}
			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="";
 	 		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.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':
 	 					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 'pos_down':
				case 'pos_up':
					var s_order=document.new_product.sort_order;
					if(document.new_product.cPath) var cat_id=document.new_product.cPath.value;
					if(head) var tbl_tr_obj=head.parentNode.parentNode;																									
					var pos_cnt=0;																																	
					pos="pos_up";
					if(action=='delete_product') pos="pos_down";
					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;
					if(tbl_tr_obj && (tbl_tr_obj.rowIndex==0 && pos=='pos_up' || tbl_tr_obj.parentNode.rows.length==tbl_tr_obj.rowIndex+1 && pos=='pos_down')) return;
				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 'go_session':
					location.href="<?php echo tep_href_link(FILENAME_SESSIONS,tep_get_all_get_params());?>&cPath="+category_id+"&eID="+id;
					return false;
				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="";
		if(c_obj) category_id=c_obj.value;
		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";
				}
				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 align='left' valign='middle' width='390' class='main'>"+product_name+"</td>"+
				  "<td width='470' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='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 class="cell_bg_popm_right" width="10">&nbsp;</td>'+
				  	 "</tr>"+
				  	"</table>"+
				  "</td>"+
				  "<td width='240' align='right' 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;'+
				  "</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 'sort_order_success':
		case 'sort_order_error':
			if(document.new_product.sort_order) var s_order=document.new_product.sort_order.value;															
			if(action=='sort_order_success'){			  			   
			   if(head)  {
				var tbl_obj=head.parentNode.parentNode;
				var up_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
			    var down_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[2];			    
			    var new_pos=result.substr(result.indexOf('sort_order_success'));			    
			    if(up_href && down_href && new_pos){
					up_href.href="javascript:do_actions("+'pos_down'+","+id+","+new_pos+")";
					down_href.href="javascript:do_actions("+'pos_up'+","+id+","+new_pos+")";
			    }
				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]);
				}																 							
  		      }			   			   					            	            	      		               	      	    	 	 			  
			}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 class="openContent" 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;
						obj.childNodes[3].innerHTML=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="";
 	    	 	}	
			}
		   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_SERVICES_CATEGORY_TO_PARENT;?>";
						res_display.style.display="";
					}
					location.href='<?php echo FILENAME_SERVICES_MAINPAGE; ?>';	
				}
			   break;
		   
 	 	}
		if(document.getElementById('res_display') && document.getElementById('res_display').style.display=="") setTimeout("document.getElementById('res_display').style.display='none'",2000);
 	 	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';
				}
		  }
	  }
	 function do_close_new_category(){ 
	 	if(document.getElementById("new_category")) document.getElementById("new_category").style.display='none';
		return false;
	 } 	
</script>