/* Useful JS lib's    */


$(document).ready(function(){   
	$('a.direct_to_cart').click(function(){
	var strItem  = this.id || false;
	xajax_CartsControllerAJAX('direct_to_cart', strItem);
	this.blur();
	return false;});	
	
//*	Shop cart params: 
	$('a.select_params').fancybox({
    	hideOnContentClick: true,
    	overlayShow: true,
    	overlayOpacity: 0.7,
    	zoomSpeedIn: 300,
    	zoomSpeedOut:300,
    	frameWidth:440,
    	frameHeight:370
    });
    $("a.thickbox").fancybox({
    	hideOnContentClick: true,
    	overlayShow: true,
    	overlayOpacity: 0.7,
    	zoomSpeedIn: 300,
    	zoomSpeedOut:300
    });

});

CartMenuRefresh=function() {
	xajax_CartsControllerAJAX('cartmenu_refresh');
}


function spCheckAll(sFormName, chkAll)
{
	var frmMain = document.getElementById(sFormName);
	for (var i =0; i < frmMain.elements.length; i++)
	{
		frmMain.elements[i].checked = chkAll;
	}
}


function MoveOption(objSourceElement, objTargetElement)
{
	var aryTempSourceOptions = new Array();
	var x = 0;

	//looping through source element to find selected options
	for (var i = 0; i < objSourceElement.length; i++) {
		if (objSourceElement.options[i].selected) {
			//need to move this option to target element
			var intTargetLen = objTargetElement.length++;
			objTargetElement.options[intTargetLen].innerHTML = objSourceElement.options[i].innerHTML;
			objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
		}
		else {
			//storing options that stay to recreate select element
			var objTempValues = new Option();
			objTempValues.innerHTML = objSourceElement.options[i].innerHTML;
			objTempValues.value = objSourceElement.options[i].value;
			aryTempSourceOptions[x] = objTempValues;
			x++;
		}
	}

	//resetting length of source
	objSourceElement.length = aryTempSourceOptions.length;
	//looping through temp array to recreate source select element
	for (var i = 0; i < aryTempSourceOptions.length; i++) {
		objSourceElement.options[i].innerHTML = aryTempSourceOptions[i].innerHTML;
		objSourceElement.options[i].value = aryTempSourceOptions[i].value;
		objSourceElement.options[i].selected = false;
	}
}

function ListBoxSelectAll(sSelectId)
{
	var sel=document.getElementById(sSelectId);
	for (var zxc0=0;zxc0<sel.options.length;zxc0++)
	{
		sel.options[zxc0].selected = true;
	}
}

function ListBoxSelectClear(sSelectId)
{
	var sel=document.getElementById(sSelectId);
	for (var zxc0=0;zxc0<sel.options.length;zxc0++)
	{
		sel.options[zxc0].selected = false;
	}
}

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


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 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
}
*/
