function reset(theid)
{
	document.getElementById(theid).innerHTML='';
}
function hide(theid)
{
	document.getElementById(theid).style.display='none';
}
function show(theid)
{
	if (document.getElementById(theid))
		document.getElementById(theid).style.display='';
	else if (window.opener.document.getElementById(theid))
		window.opener.document.getElementById(theid).style.display='';
	
}
function getstyle(theid)
{
	return (document.getElementById(theid).className);
}
function setstyle(theid, classname)
{
	document.getElementById(theid).className=classname;
}
function sethtml(theid, html)
{
	document.getElementById(theid).innerHTML=html;
}
function gethtml(theid)
{
	return document.getElementById(theid).innerHTML;
}
function setsrc(theid, src)
{
	if (document.getElementById(theid))
		document.getElementById(theid).src=src;
}
function getsrc(theid)
{
	return document.getElementById(theid).src;
}
function setvalue(theid, value)
{
	document.getElementById(theid).value=value;
}
function getvalue(theid)
{
	if (document.getElementById(theid))
		return document.getElementById(theid).value;
	else
		return 0;
}
function getselectvalue(theid)
{
	if (document.getElementById(theid))
	{
		var the_sel = document.getElementById(theid);
		var the_value = the_sel.options[the_sel.selectedIndex].value;
		return the_value;
	}
	else
		return 0;
}
function toggle_display(theid)
{
	if (document.getElementById(theid).style.display=='none')
		show(theid);
	else
		hide(theid);
}

var newwindow = '';
function popup(url, width, height)
{
	if (!width)
		width=610;
	if (!height)
		height=400;
	url = "/popup.php?p="+url;
	newwindow = window.open(url, 'popup', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width='+width+',height='+height);
	if (window.focus) {newwindow.focus()}
	return false;
}

function print(url, width, height)
{
	if (!width)
		width=610;
	if (!height)
		height=400;
	url = "/print.php?p="+url;
	newwindow = window.open(url, 'print', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width='+width+',height='+height);
	if (window.focus) {newwindow.focus()}
	return false;
}

function load_map(store_id)
{
	url = "store_map&sid="+store_id;
	return popup(url, 0, 625);
}

function load_product(store_id)
{
	url = "store_product&sid="+store_id;
	return popup(url);
}

function load_store(product_id)
{
	url = "product_store&pid="+product_id;
	return popup(url);
}

function load_stock(product_id, order_id)
{
	url = "stock&pid="+product_id+"&oid="+order_id+"&type=a";
	return popup(url);
}

function load_invoice(order_id, email)
{
	if (!email)
		email=0;
	url = "invoice&oid="+order_id+"&email="+email;
	return print(url, 0, 600);
}

function load_image(file_name)
{
	url = "file&file1="+file_name;
	return popup(url, 0, 550);
}

function redirect(url)
{
	window.location.replace(url);
}

function load(divId,url,param,noclear)
{
	if (!noclear)
		noclear=0;
	ajax_loadContent(divId,url,param,noclear);
}

function loadvalue(divId,url,param)
{
	ajax_loadContent(divId,url,param,0,1);
}

function loadparent(divId,url,param,noclear)
{
	if (!noclear)
		noclear=0;
	ajax_loadContentParent(divId,url,param,noclear);
}

function toggle_product_checkbox(the_box)
{
	var the_form = the_box.form;
	for (var i=0; i<the_form["item_id[]"].length; i++)
	{
		the_form["item_id[]"][i].checked=the_box.checked;
	}
}

function add_option(existing, selected, desc)
{
	var the_form = existing.form;
	var text_string = new Array();
	if (the_form[desc].value)
	{
		text_string = the_form[desc].value.split("|");
	}
	if (existing.selectedIndex>=0)
	{
		theValue = existing.options[existing.selectedIndex].value;
		selectedid = existing.selectedIndex;
		existing.remove(selectedid);
		
		oOption = document.createElement("OPTION");
		oOption.text = theValue;
		oOption.value = theValue;
		text_string[text_string.length] = theValue;
		
		var failed = 0;

		for (var i=0; i<selected.options.length; i++)
		{
			if (selected.options[i].value == theValue)
			{
				failed=1;
				break;
			}
		}
		if (failed==0)
		{
			selected.options.add(oOption) ;
			the_form[desc].value=text_string.join("|");
		}
		
		if (selectedid < existing.options.length)
			existing.selectedIndex = selectedid;
		else
			existing.selectedIndex = selectedid-1;
		existing.focus();
	}
}

function remove_option(existing, selected, desc)
{
	var the_form = existing.form;
	var text_string = the_form[desc].value.split("|");

	if (selected.selectedIndex>=0)
	{
		theValue = selected.options[selected.selectedIndex].value;
		selectedid = selected.selectedIndex;
		selected.remove(selectedid);
		
		oOption = document.createElement("OPTION");
		oOption.text = theValue;
		oOption.value = theValue;
		text_string[text_string.length] = theValue;
		
		var failed = 0;

		for (var i=0; i<existing.options.length; i++)
		{
			if (existing.options[i].value == theValue)
			{
				failed=1;
				break;
			}
		}
		if (failed==0)
		{
			existing.options.add(oOption);
			var new_string = new Array();
			for (var i=0; i<text_string.length; i++)
			{
				if (text_string[i]!=theValue)
				{
					new_string[new_string.length] = text_string[i];
				}
			}
			the_form[desc].value=new_string.join("|");
		}
		
		if (selectedid < selected.options.length)
			selected.selectedIndex = selectedid;
		else
			selected.selectedIndex = selectedid-1;
		selected.focus();
	}
}
