
 <script language="javascript">
    var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
	 var lang=new Array();
    var attrib_icon=false;
	<?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_subscription() {
	   // make something useful before submit (onStart)
	   var error_result="";
	   var image_types=Array(".png",".jpg",".jpeg",".gif");
	   if(document.getElementById("action_type")) var action_type=document.getElementById("action_type").value;
	   var validate_form=false;
	   var frm=document.new_product;
	   var categories_image=document.getElementById('subscription_categories_image');
	   if(action_type!=""){		
	     if(action_type=='new_category' || action_type=='edit_category'){		 					  	
				  	for(i=0;i<lang.length;i++)
				  		if(document.getElementById("categories_name["+lang[i]+"]") && document.getElementById("categories_name["+lang[i]+"]").value=="" || str_trim(document.getElementById("categories_name["+lang[i]+"]").value)=="") error_result='* <?php echo ERR_CATEGORY_NAME;?>\n';
				  	if (categories_image && categories_image.value!="" && !check_mime_type(categories_image,image_types))
						error_result+="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
					else if(categories_image && categories_image.value=="")
						validate_form=true;		 
		 }else if(action_type=='new' || action_type=='edit'){
		 	    var frm_subscription_type=frm.subscription_type.options[frm.subscription_type.selectedIndex].value;																
				if (frm.elements["subscription_name["+lang[0]+"]"]){
				   for (icnt=0;icnt<lang.length;icnt++){					 
					 if ( (str_trim(frm.elements["subscription_name["+lang[icnt]+"]"].value)==null) || (str_trim(frm.elements["subscription_name["+lang[icnt]+"]"].value)=="") ){
					   error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_NAME); ?>";
					   break;
					 }					 
				   }
				 } else if( (str_trim(frm.subscription_name.value)==null) || (str_trim(frm.subscription_name.value)=="") )
				 	  error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_NAME); ?>";				 		
				 if (error_result==''){
					var categories_error=true;
						for(i=0;i<document.getElementsByName("subscription_categories_ids[]").length;i++)
							if(document.getElementsByName("subscription_categories_ids[]")[i].checked==true)
								categories_error=false;	
					if(categories_error==true)
						error_result="<?php echo tep_db_input(TEXT_ERR_SELECT_CATEGORY); ?>";
					else if(str_trim(frm.subscription_pending_period.value)=="")
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_PENDING_PERIED_EMPTY); ?>";
					else if(isNaN(parseInt(frm.subscription_pending_period.value)))
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_PENDING_PERIED_NUMBER); ?>";
					else if(str_trim(frm.subscription_renewal_start.value)=="")
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_START_EMPTY); ?>";
					else if(isNaN(parseInt(frm.subscription_renewal_start.value)))
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_START_NUMBER); ?>";
					else if(frm.subscription_renewal_end.value=="")
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_END_EMPTY); ?>";
					else if(isNaN(parseInt(frm.subscription_renewal_end.value)))
						error_result="<?php echo tep_db_input(TEXT_ERR_EMPTY_SUBSCRIPTION_RENEWAL_END_NUMBER); ?>";
					else if(frm_subscription_type=='P' && document.getElementById("support_minutes") && (document.getElementById("support_minutes").value<=0 || document.getElementById("support_minutes").value=="")) error_result="<?php echo tep_db_input(SUPPORT_MINUTES_SHOULD_NOT_EMPTY); ?>";
					else if(frm_subscription_type=='C' || frm_subscription_type=='S') {
						var txt_deliveries=frm.txt_deliveries.value;
						var txt_deliveries_name = frm.txt_deliveries_name.value;
					    var txt_deliveries_perday=frm.txt_perday.value; 
						if(txt_deliveries<=0 || txt_deliveries=="" || isNaN(txt_deliveries))
							error_result+="<?php echo ERR_DELIVERIES_COUNT;?>\n";							
						if(txt_deliveries_name == "")
							error_result+="<?php echo ERR_DELIVERIES_NAME;?>\n";						
						if(frm_subscription_type=='C' && (txt_deliveries_perday<=0 || txt_deliveries_perday=="" || isNaN(txt_deliveries_perday)))
							error_result+="<?php echo ERR_DELIVERIES_PERDAYS;?>";							
					}
				}
				if (frm.elements["subscription_image"] && frm.elements["subscription_image"].value!="" && !check_mime_type(frm.elements["subscription_image"],image_types))
				 	error_result+="<?php echo ERR_IMAGE_UPLOAD_TYPE;?>";
			    else if(frm.elements["subscription_image"].value=="") 
	  				validate_form=true; 	    							 	   	   		
		 }
	  }	
	  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_subscription(response) {
	    ValidateForm(response);
    }  	
    var lang=new Array();
    <?php 
    $languages = tep_get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
    	echo "lang[".$i."]=".$languages[$i]['id'].";\n";
    }
    ?>    	
	var splt=Array()
	var tax_rates = new Array();	
	var image_types=Array(".png",".jpg",".jpeg",".gif");
		<?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 expand_new(id,category){
		command="<?php echo tep_href_link(FILENAME_SUBSCRIPTIONS_MAINPAGE,'action=edit');?>";
		//alert(command);
		do_get_command(command);
	}
		
		
	 function do_subscription_date_type(){ 
		if(document.new_product.subscription_date_type[0].checked==true){
			old_finish_date = 0;
			document.getElementById("fixed_date").style.display="none";
			check_input(false);
		} else if(document.new_product.subscription_date_type[1].checked==true || document.new_product.subscription_date_type[2].checked==true){
			old_finish_date = 0;
			document.getElementById("fixed_date").style.display="";
			document.getElementById("latest").style.display="";
			check_input(false);
		}
	}
	function do_subscription_type(confirm_err){ 
		var frm=document.forms["new_product"];
		if(document.getElementById('subscription_type')){
			var subscription_type=frm.subscription_type.options[frm.subscription_type.selectedIndex].value;
			if(subscription_type=='M' && confirm_err)
			{
				alert_err="<?php echo TEXT_SUBSCRIPTION_TYPE_CHANGE;?>";
				if(!confirm(alert_err))
				{
					switch(confirm_err)
					{
						case "B":
							frm.subscription_type.selectedIndex=0;
							break;
						case "C":
							frm.subscription_type.selectedIndex=1;
							break;
						case "S":
							frm.subscription_type.selectedIndex=2;
							break;
						case "P":
							frm.subscription_type.selectedIndex=3;
							break;
						case "M":
							frm.subscription_type.selectedIndex=4;
							break;
						default:
							frm.subscription_type.selectedIndex=0;
							break;
					}
					subscription_type=frm.subscription_type.options[frm.subscription_type.selectedIndex].value;
				}
			}
			var span_box_support=document.getElementById("box_support");
			var div_ids_deliveries=document.getElementById("box_deliveries");
			var div_ids_perday=document.getElementById("box_perday");
			if(subscription_type=='C'){
				div_ids_deliveries.style.display=div_ids_perday.style.display="";
				span_box_support.style.display="none";
			}else if(subscription_type=='S'){	
				div_ids_deliveries.style.display="";
				div_ids_perday.style.display="none"	
				span_box_support.style.display="none";
			}else if(subscription_type=='P' && span_box_support){
			   span_box_support.style.display="";
			   div_ids_deliveries.style.display=div_ids_perday.style.display="none";
			}else{
				div_ids_deliveries.style.display=div_ids_perday.style.display="none";
				span_box_support.style.display="none";
			}			
		}
	}
	var old_start_date = '';
	var old_finish_date = '';
	var old_latest_start_date = '';
	var old_forward_period = 1;

	function check_input(display_alert){
		var fixed_type = document.new_product.subscription_date_type[0];
		var flexible_type = document.new_product.subscription_date_type[1];
		var predefined_type = document.new_product.subscription_date_type[2];
		if(fixed_type.checked==true || flexible_type.checked==true || predefined_type.checked==true){
			var error_result = "";
			var currend_date = document.new_product.currend_date.value;
			if(document.new_product.subscription_start_date.value==""){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
				document.new_product.subscription_start_date.value = currend_date;
			} else if(document.new_product.subscription_start_date.value!=""){
				var date_error = true;
				if((document.new_product.subscription_start_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_product.subscription_start_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE;?>\n";
					document.new_product.subscription_start_date.value = currend_date;
				}
			}
			
			var start_date_time = 0;
			var finish_date_time = 0;
			var latest_start_date_time = 0;
			if(document.new_product.subscription_start_date.value != ""){
				var date_error = true;
				if((document.new_product.subscription_finish_date.value).indexOf("-")!=-1){
					date_error = isValidDate(date_format(document.new_product.subscription_finish_date.value,'','Y-m-d'));
				} else {
					date_error = false;
				}
				if(!(date_error)){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
					document.new_product.subscription_finish_date.value = document.new_product.subscription_start_date.value;
				}else{
					 start_date_time = date_format(document.new_product.subscription_start_date.value,'','',true).getTime();
					 finish_date_time = date_format(document.new_product.subscription_finish_date.value,'','',true).getTime();
				}
			}
			if(start_date_time>finish_date_time){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n";
				document.new_product.subscription_finish_date.value=document.new_product.subscription_start_date.value;
			}
			if(document.new_product.subscription_finish_date.value==""){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_FINISH_DATE;?>\n";
				document.new_product.subscription_finish_date.value = document.new_product.subscription_start_date.value;
			} 
			
			var period = document.new_product.subscription_period.value;
			if(isNaN(parseInt(period))){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_ATTENDANCE_PERIOD;?>";
				document.new_product.subscription_period.value=1;
			}		
			if(period < 0){
				if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_BEGINS_GREATER_ATTENDANCE_PERIOD;?>";
				document.new_product.subscription_period.value=1;
			}
			
			if(flexible_type.checked==true || predefined_type.checked==true){
				if(document.new_product.subscription_latest_start_date.value==""){
					if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
					document.new_product.subscription_latest_start_date.value = document.new_product.subscription_start_date.value;
				} else if(document.new_product.subscription_latest_start_date.value!=""){
					var date_error = true;
					if((document.new_product.subscription_latest_start_date.value).indexOf("-")!=-1){
						date_error = isValidDate(date_format(document.new_product.subscription_latest_start_date.value,'','Y-m-d'));
					} else {
						date_error = false;
					}
					if(!(date_error)){
						if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE;?>\n";
						document.new_product.subscription_latest_start_date.value = document.new_product.subscription_start_date.value;
					} else{
						 finish_date_time = date_format(document.new_product.subscription_finish_date.value,'','',true).getTime();
						 latest_start_date_time = date_format(document.new_product.subscription_latest_start_date.value,'','',true).getTime();
					}
					if(latest_start_date_time>finish_date_time){
						if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE_EXCEED_FINISH_DATE;?>\n";
						document.new_product.subscription_latest_start_date.value=document.new_product.subscription_start_date.value;
					}
					if(latest_start_date_time<start_date_time){
						var check_start_date = date_format(document.new_product.subscription_start_date.value,'','d-m-Y');
						if(old_start_date == check_start_date)
							if(display_alert)error_result+="* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_LATEST_START_DATE;?>\n";
						document.new_product.subscription_latest_start_date.value=document.new_product.subscription_start_date.value;
					}
				}
			}
			
			if (error_result!=""){
			   alert(error_result);
			   check_input(true);
			   return false;
			}
			var latest_start_date = '';
			if(document.new_product.subscription_latest_start_date.value ==""){
				document.new_product.subscription_latest_start_date.value="00:00:0000";
				latest_start_date = date_format(document.new_product.subscription_latest_start_date.value,'d-m-Y','d-m-Y');	
			}
			var start_date = date_format(document.new_product.subscription_start_date.value,'','d-m-Y');
			var finish_date = date_format(document.new_product.subscription_finish_date.value,'','d-m-Y');
			latest_start_date = date_format(document.new_product.subscription_latest_start_date.value,'','d-m-Y');
			var forward_period = document.new_product.subscription_period.value;
			if(old_start_date != start_date || old_finish_date != finish_date || old_latest_start_date != latest_start_date || old_forward_period != forward_period){
				var date_array = Array(start_date,finish_date,latest_start_date);
				var total_days = Array(0,0,0);
				for(i=0;i<date_array.length;i++){
					var split_date = date_array[i].split("-");
					var month_array = Array();
					var leep_years = 0;
					leep_years = parseInt(split_date[2]/4);
					total_days[i] += leep_years*366;
					var non_leep_years = 0;
					non_leep_years = parseInt(split_date[2]-(split_date[2]/4));
					total_days[i] += non_leep_years*365;
					var is_leep_year = ((String)(split_date[2]/4)).indexOf(".");
					if(is_leep_year!=-1){
						month_days = Array(31,28,31,30,31,30,31,31,30,31,30,31);
					} else {
						month_days = Array(31,29,31,30,31,30,31,31,30,31,30,31);
						total_days[i] -= 366;
					}
					for(j=0;j<month_days.length;j++){
						if((j+1)<split_date[1]){
							total_days[i] += month_days[j];
						}
					}
					total_days[i] += new Number(split_date[0]);
				}
				if(fixed_type.checked == true){
					if(old_finish_date != finish_date || old_start_date != start_date){
						document.new_product.subscription_period.value = total_days[1]-total_days[0]+1;
						old_forward_period = total_days[1]-total_days[0]+1;
						old_finish_date = finish_date;
					} else if(old_forward_period != forward_period){
						var s_date = new Date();
						var split_date = document.new_product.subscription_start_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateAdd('d',to_forward_period-1,s_date).getDate();
						var month = DateAdd('d',to_forward_period-1,s_date).getMonth();
						var year = DateAdd('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day -=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
						document.new_product.subscription_finish_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_finish_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
					}
					var check_start_date_time = date_format(document.new_product.subscription_start_date.value,'','',true).getTime();
					var check_finish_date_time = date_format(document.new_product.subscription_finish_date.value,'','',true).getTime();
					if(check_start_date_time>check_finish_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_BEGIN_DATE;?>\n");
						document.new_product.subscription_finish_date.value=document.new_product.subscription_start_date.value;
						old_finish_date = start_date;
						return false;
					}
				}
				if(flexible_type.checked == true || predefined_type.checked == true){
					if(old_finish_date != finish_date || old_start_date != start_date || old_latest_start_date != latest_start_date){
						if(old_latest_start_date != latest_start_date || old_finish_date != finish_date){
							document.new_product.subscription_period.value = total_days[1]-total_days[2]+1;
							old_forward_period = total_days[1]-total_days[2]+1;
							old_finish_date = finish_date;
							old_latest_start_date = latest_start_date;
						}
						if(old_start_date != start_date || old_latest_start_date != start_date){
							if(total_days[0]>total_days[2]){
								document.new_product.subscription_latest_start_date.value = start_date;
								old_latest_start_date = latest_start_date;
							}
						}
					} else if(old_forward_period != forward_period){
						var s_date = new Date();
						var split_date = document.new_product.subscription_finish_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateSub('d',to_forward_period-1,s_date).getDate();
						var month = DateSub('d',to_forward_period-1,s_date).getMonth();
						var year = DateSub('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day +=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
						document.new_product.subscription_latest_start_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_latest_start_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
						old_finish_date = finish_date;
					}
					var check_start_date_time = date_format(document.new_product.subscription_start_date.value,'','',true).getTime();
					var check_finish_date_time = date_format(document.new_product.subscription_finish_date.value,'','',true).getTime();
					var check_latest_start_date_time = date_format(document.new_product.subscription_latest_start_date.value,'','',true).getTime();
						var s_date = new Date();
						var split_date = document.new_product.subscription_start_date.value.split("-");
						s_date.setDate(split_date[0]);s_date.setMonth(split_date[1]-1);s_date.setYear(split_date[2]);
						s_date.setMinutes(0);s_date.setSeconds(0);s_date.setHours(0);s_date.setMilliseconds(0);
						var to_forward_period = 1;
						if(forward_period != 0)to_forward_period = forward_period;
						var day = DateAdd('d',to_forward_period-1,s_date).getDate();
						var month = DateAdd('d',to_forward_period-1,s_date).getMonth();
						var year = DateAdd('d',to_forward_period-1,s_date).getYear();
						month +=1;
						//day -=1;if(day!=1)
						if(year<1000)year +=1900;
						if(day<10)day = 0+""+day;
						if(month<10)month = 0+""+month;
					if(check_latest_start_date_time>check_finish_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_LATEST_START_DATE_EXCEED_FINISH_DATE;?>\n");
						document.new_product.subscription_latest_start_date.value=document.new_product.subscription_start_date.value;
						old_latest_start_date = start_date;
						return false;
					}
					if(check_latest_start_date_time<check_start_date_time){
						//alert("* <?php echo ERR_SUBSCRIPTION_START_DATE_EXCEED_LATEST_START_DATE;?>\n");
						document.new_product.subscription_latest_start_date.value=document.new_product.subscription_start_date.value;
						old_latest_start_date = start_date;
						document.new_product.subscription_finish_date.value = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_finish_date = date_format(day+"-"+month+"-"+year,'d-m-Y','');
						old_forward_period = forward_period;
					}
				}
				old_start_date = start_date;
			}
			 return true;
		}
	}
		function DateAdd(timeU,byMany,dateObj) {
		var millisecond=1;
		var second=millisecond*1000;
		var minute=second*60;
		var hour=minute*60;
		var day=hour*24;
		var year=day*365;
	
		var newDate;
		var dVal=dateObj.valueOf();
		switch(timeU) {
			case "ms": newDate=new Date(dVal+millisecond*byMany); break;
			case "s": newDate=new Date(dVal+second*byMany); break;
			case "mi": newDate=new Date(dVal+minute*byMany); break;
			case "h": newDate=new Date(dVal+hour*byMany); break;
			case "d": newDate=new Date(dVal+day*byMany); break;
			case "y": newDate=new Date(dVal+year*byMany); break;
		}
		return newDate;
	}
	function DateSub(timeU,byMany,dateObj) {
		var millisecond=1;
		var second=millisecond*1000;
		var minute=second*60;
		var hour=minute*60;
		var day=hour*24;
		var year=day*365;
	
		var newDate;
		var dVal=dateObj.valueOf();
		switch(timeU) {
			case "ms": newDate=new Date(dVal-millisecond*byMany); break;
			case "s": newDate=new Date(dVal-second*byMany); break;
			case "mi": newDate=new Date(dVal-minute*byMany); break;
			case "h": newDate=new Date(dVal-hour*byMany); break;
			case "d": newDate=new Date(dVal-day*byMany); break;
			case "y": newDate=new Date(dVal-year*byMany); break;
		}
		return newDate;
	}
	
	 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"].subscription_tax_class_id.selectedIndex;
	  var parameterVal = document.forms["new_product"].subscription_tax_class_id[selected_value].value;
	  if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) { 
		return tax_rates[parameterVal];
	  } else {
		return 0;
	  }
	}
		
	function set_action(type) {
	 	var frm=document.new_product;
		if (type==1 && frm.wallet_payment.checked==true) {
			frm.periodic_payment.checked=false;
		} else if (type==2 && frm.periodic_payment.checked==true) {
			frm.wallet_payment.checked=false;
		}
		frm.periodic_type.disabled=!frm.periodic_payment.checked;
		frm.periodic_days.disabled=!frm.periodic_payment.checked;
	}
		
	function updateGross() { 
		  var taxRate = getTaxRate();
		  var grossValue = document.forms["new_product"].subscription_costs_net.value;
			
		  if (taxRate > 0) { 
			grossValue = grossValue * ((taxRate / 100) + 1);
		  }
		  document.forms["new_product"].subscription_costs_gross.value = doRound(grossValue, 4);
		}
		
		function updateNet() {
		  var taxRate = getTaxRate();
		  var netValue = document.forms["new_product"].subscription_costs_gross.value;
		
		  if (taxRate > 0) { 
			netValue = netValue / ((taxRate / 100) + 1);
		  }
		  document.forms["new_product"].subscription_costs_net.value = doRound(netValue, 4);
	 }
		
	 function AddField(){
		 var select_field;
		 var select_id;
		 if (document.new_product.merge_fields.selectedIndex<=-1) return;
		 select_id=document.new_product.merge_fields.options[document.new_product.merge_fields.selectedIndex].value;
		 if (select_id.length>3) return;
		 select_field="%%" + document.new_product.merge_fields.options[document.new_product.merge_fields.selectedIndex].text + "%%";
			textArea=document.new_product.message_text;
			textArea.focus();
			if (textArea.selection){
				sRange  = document.selection.createRange();
				var sText   = sRange.text;
				sRange.text = select_field;
			} else if (textArea.selectionStart || textArea.selectionStart == "0") {
				var startPos = textArea.selectionStart;
				var endPos = textArea.selectionEnd;
				textArea.value = textArea.value.substring(0, startPos)
						+ select_field + textArea.value.substring(endPos, textArea.value.length);
			} else {
				textArea.value += select_field;
			}		
	  } 
	  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;
	}
	</script>
