function final_price_calc(product_id) {
	var product_cost = document.getElementById("hidden_product_cost_" + product_id).value;
	var price_type = document.getElementById("update_price_type_" + product_id).value;
	var price_value = document.getElementById("update_price_value_" + product_id).value;
	var final_price = 0.00;
	
	product_cost = parseFloat(product_cost);
	price_value = parseFloat(price_value);

	if(price_type == "MP") 
		final_price = product_cost / (1 - (price_value / 100));
	else if(price_type == "MF")
		final_price = (product_cost + price_value);
	else if(price_type == "S")
		final_price = price_value;
		
	document.getElementById("final_price_" + product_id).value = final_price.toFixed(2);
	return;
}

function show(id) {
	var state = document.getElementById(id).style.display;
	if (state == 'block') {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'block';
	}
}
function payment_form_toggle(content_id, select_id) {
	value = document.getElementById(select_id).value;
	if(value == 0)
		document.getElementById(content_id).style.display = 'block';
	else 
		document.getElementById(content_id).style.display = 'none';
}
function purchase_form_toggle(content_id, select_id) {
	value = document.getElementById(select_id).value;
	if(value == 0)
		document.getElementById(content_id).style.display = 'block';
	else 
		document.getElementById(content_id).style.display = 'none';
}
function purchase_form_warehouse_toggle(content_id, select_id) {
	value = document.getElementById(select_id).value;
	if(value == "IP")
		document.getElementById(content_id).style.display = 'block';
	else if(value == "DS")
		document.getElementById(content_id).style.display = 'none';
}
function check_list(the_form, list_name) {
	var selectbox = the_form.selectall;
	var listbox = the_form[list_name];
	
	var check_value;
	if(selectbox.checked == true)
		check_value = true;
	else
		check_value = false;
	
	
	var size = listbox.length;
	if(!size) {
		listbox.checked = check_value; 
	} else {
		for(var i = 0; i < size; i++) {
			the_form[list_name][i].checked = check_value;
		}
	}
	return;
}


function uncheck(the_form, list_name) {
	var selectbox = the_form.selectall;
	var listbox = the_form[list_name];
	
	var check_value = true;
	var size = listbox.length;
	if(!size) {
		if(listbox.checked == false) 
			check_value = false;
	} else {
		for(var i = 0; i < size; i++) {
			if(listbox[i].checked == false) {
				check_value = false;
				break;
			}
		}
	}
	selectbox.checked = check_value;
	return;
}

function jumplink(jumpform, cururl) 
 {
	var newIndex = jumpform.category.selectedIndex; 
	if ( newIndex == 0 ) { 
	
	} else { 
		var mylink = cururl + jumpform.category.options[ newIndex ].value; 
		
		document.location.href( mylink ); 
	}

 }

function print_popup(mylink, autoprint)
 {
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, 'print_window', 'width=760,height=400,scrollbars=yes,toolbar=yes');
if(autoprint) {
	window.print();
	window.close();
}
return false;

 } 
function graph_popup(mylink, mygraph)
 {
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, mygraph, 'width=740,height=444,scrollbars=no,toolbar=no');
return false;

 } 

function product_sku_search_popup(mylink, textbox_id, extra_vars)
 {
	if (! window.focus)return true;
	
	var href;
	
	if (typeof(mylink) == 'string')
	   href= mylink + "&textbox_id=" + textbox_id;
	   if(typeof(extra_vars) == 'string') {
			href = href + extra_vars;
	   }
	else
	   href= mylink.href;
	
	window.open(href, 'sku_search_window', 'width=660,height=400,scrollbars=yes,toolbar=yes');
	return false;
 
}

function product_sku_return_value(textbox_id, product_sku)
 {
	window.opener.document.getElementById(textbox_id).value = product_sku;
	window.close();
	return true;
}


function deleteRecord(url){
	if (confirm('Are you sure you want to delete this record(s)?\nThis operation cannot be undone.'))
		document.location.href=url;
}


