/* Useful JS lib's    */

  function addOption(selectId, val, txt, selectedValue) {
    var objOption = new Option(txt, val);
    if (val == selectedValue)
    	objOption.selected = true;
     document.getElementById(selectId).options.add(objOption);
   }

function spCheckAll(chkAll)
{
	$("input.killmy").attr('checked', chkAll);
	$("input.killmy").trigger('change');
}

$(document).ready(function(){
	$('input.killmy').change(function(){	SetToKill(this.checked, this.value); });
	$('input#select_all').click(function(){	spCheckAll(this.checked) });
});
/********* pager ********/
var aChkedIds=new Array();
function SetToKill(bState, iValue)
{
	if(bState)
	{
		aChkedIds[iValue]=iValue;
	}
	else
	{
		delete aChkedIds[iValue];
	}
}
/********* pager ********/
opened="";
function spHide(idStr)
{

        Object=document.getElementById(idStr);
        if(Object!=null)Object.style.display="none"

}
function spShow(idStr) {

        Object=document.getElementById(idStr);
        if(Object!=null)Object.style.display="block"
}
function spTicSingle(idStr) {

        Object=document.getElementById(idStr);
        if(Object.style.display=="block")
            {
             Object.style.display='none'
            return false
            }
                        else
             {
             Object.style.display='block'
             return false
             }

}
function spTic(idStr) {

        Object=document.getElementById(idStr);
        if(Object.style.display=="block")
            {
             Object.style.display='none'
            return false
            }
                        else
             {
             Object.style.display='block'
             return false
             }

}
function spSetHtml(idStr, ValueStr) {

        Object=document.getElementById(idStr);
        Object.innerHTML=ValueStr;

}
/*
function imgChange(newsrcStr, idStr) {

        Object=document.getElementById(idStr);
        Object.src=newsrcStr;

}
function imagePopUp(igStr, bigUrl)
{
	imgSrc=document.getElementById('image_show').src;
	window.open(bigUrl,'','scrollbars=no,innerWidth=440,innerHeight=660, width=440,height=660')
}
var bigUrl;
// Interval ID for search function
var searchID;
var searchString='';
function rtSearch(MySearchString)
{
	spShow('search_wait');
	window.clearTimeout(searchID);
	searchString=MySearchString;
	searchID=window.setTimeout('DynSearch()', 500, MySearchString);
}
function rtUSearch(MySearchString)
{
	spShow('search_wait');
	window.clearTimeout(searchID);
	searchString=MySearchString;
	searchID=window.setTimeout('DynUSearch()', 500, MySearchString);
}
function rtSearchStock(MySearchString)
{
	spShow('search_wait');
	window.clearTimeout(searchID);
	searchString=MySearchString;
	searchID=window.setTimeout('DynSearchStock()', 500, MySearchString);
}

function DynSearch()
{
	window.clearTimeout(searchID);
	//alert(searchString);//catSelect
	parentSelect=document.getElementById('catSelect');
	ProdSearch=document.getElementById('prod_search');
	xajax_ProdSearch(parentSelect.value,false, ProdSearch.value);
	spHide('search_wait');
}

function DynUSearch()
{
	window.clearTimeout(searchID);
	//alert(searchString);//catSelect
	//parentSelect=document.getElementById('catSelect');
	UserSearch=document.getElementById('user_search');
	xajax_UserSearch( UserSearch.value);
	spHide('search_wait');
}
function DynSearchStock()
{
	window.clearTimeout(searchID);
	parentSelect=document.getElementById('catSelect');
	ProdSearch=document.getElementById('prod_search');
	xajax_ProdSearchStock(parentSelect.value,false, ProdSearch.value);
	spHide('search_wait');
}
function SetValueById(idStr, valueStr)
{

	Object=document.getElementById(idStr);
	if(Object!=null)Object.value=valueStr;

}

function SetZixById(idZStr, valueZStr)
{
	Object=document.getElementById(idZStr);
	if(Object!=null)Object.style.zIndex=valueZStr;
}
function GetValueById(idStr)
{

	Object=document.getElementById(idStr);
	valueStr=Object.value;
	return valueStr;

}
function SetInnerHTMLById(idStr, valueStr)
{

	Object=document.getElementById(idStr);
	if(Object!=null)Object.innerHTML=valueStr;

}

function createRequestObject()
{
	var ro;

	if (window.XMLHttpRequest) {  ro = new XMLHttpRequest(); }
	else {
		ro = new ActiveXObject('Msxml2.XMLHTTP');
		if(!ro) { ro = new ActiveXObject('Microsoft.XMLHTTP'); }
	}

	return ro;
}
function imgChange(newsrcStr, idStr) {

	Object=document.getElementById(idStr);
	Object.src=newsrcStr;

}
function imagePopUp(igStr, bigUrl)
{
	imgSrc=document.getElementById('image_show').src;
	window.open(bigUrl,'','scrollbars=no,innerWidth=440,innerHeight=660, width=440,height=660')
}
var bigUrl;
var zIx=1500;

var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;

var dragobj = null;

function falsefunc() { return false; } // used to block cascading events

function init()
{
	document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
	update();
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{
	if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

	if (e)
	{
		if (e.pageX || e.pageY)
		{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			mousex = e.pageX;
			mousey = e.pageY;
			algor = '[e.pageX]';
			if (e.clientX || e.clientY) algor += ' [e.clientX] '
		}
		else if (e.clientX || e.clientY)
		{ // works on IE6,FF,Moz,Opera7
			mousex = e.clientX + document.body.scrollLeft;
			mousey = e.clientY + document.body.scrollTop;
			algor = '[e.clientX]';
			if (e.pageX || e.pageY) algor += ' [e.pageX] '
		}
	}
}

function update(e)
{
	getMouseXY(e); // NS is passing (event), while IE is passing (null)

	//document.getElementById('span_browser').innerHTML = navigator.appName;
	//document.getElementById('span_winevent').innerHTML = window.event ? window.event.type : '(na)';
	//document.getElementById('span_autevent').innerHTML = e ? e.type : '(na)';
	//document.getElementById('span_mousex').innerHTML = mousex;
	//document.getElementById('span_mousey').innerHTML = mousey;
	//document.getElementById('span_grabx').innerHTML = grabx;
	//document.getElementById('span_graby').innerHTML = graby;
	//document.getElementById('span_orix').innerHTML = orix;
	//document.getElementById('span_oriy').innerHTML = oriy;
	//document.getElementById('span_elex').innerHTML = elex;
	//document.getElementById('span_eley').innerHTML = eley;
	//document.getElementById('span_algor').innerHTML = algor;
	//document.getElementById('span_dragobj').innerHTML = dragobj ? (dragobj.id ? dragobj.id : 'unnamed object') : '(null)';
}

function grab(context)
{
	document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
	dragobj = context;
	dragobj.style.zIndex = zIx+10; // move it to the top
	document.onmousemove = drag;
	document.onmouseup = drop;
	grabx = mousex;
	graby = mousey;
	elex = orix = dragobj.offsetLeft;
	eley = oriy = dragobj.offsetTop;
	update();
}

function drag(e) // parameter passing is important for NS family
{
	if (dragobj)
	{
		elex = orix + (mousex-grabx);
		eley = oriy + (mousey-graby);
		dragobj.style.position = "absolute";
		dragobj.style.left = (elex).toString(10) + 'px';
		dragobj.style.top  = (eley).toString(10) + 'px';
	}
	update(e);
	return false; // in IE this prevents cascading of events, thus text selection is disabled
}

function drop()
{
	if (dragobj)
	{
		dragobj.style.zIndex = zIx;
		dragobj = null;
	}
	update();
	document.onmousemove = update;
	document.onmouseup = null;
	document.onmousedown = null;   // re-enables text selection on NS
}
*/