var ie = document.all ? true:false

if(!ie)
    document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) 
{
    if(ie) 
    {
        mouseX = event.clientX + document.body.scrollLeft;
        mouseY = event.clientY + document.body.scrollTop;
    } 
    else 
    {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }  

    if(mouseX < 0)
        mouseX = 0;
    if(mouseY < 0)
        mouseY = 0;
}

function setHomePage(src)
{
    src.style.behavior = 'url(#default#homepage)';
    src.setHomePage('http://www.maklitel.co.il');
}

function addFavorite(src)
{
    window.external.AddFavorite(location.href, document.title);
}

var win;

function openWindow(url, name, params)
{
	win = window.open(url, name, params);
	win.focus();
	
	return win;
}

function closeWindow()
{
    window.close();
}

function openFloat(url, name, width, height)
{
    win = openWindow(url, name, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=' + width + ', height=' + height);
    if ((win.width != width) || (win.height != height))
		win.resizeTo(width, height)
}

function openPrint(url, name)
{
    openWindow(url + '&print=1', name, 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=800, height=600');
}

function openExport(url)
{
	document.location = url + '&export=1';
}

function printPage()
{
    window.print();
}

function changeImages() 
{
    if(document.images)
    {
        for(var i = 0; i < changeImages.arguments.length; i += 2) 
            document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
    }
}

var clickedRow;
var clickedRowColor;

function rowOver(row)
{
    if (row == clickedRow)
        row.style.background = '#e20a16';
    else
        row.style.background = '#d0cce0';

    //document.body.style.cursor = 'hand';
}

function rowOut(row, color)
{
    if (row == clickedRow)
        row.style.background = '#e20a16';
    else
        row.style.background = color;

    //document.body.style.cursor = 'default';
}

function rowClick(row, color)
{
    if (clickedRow != null)
        clickedRow.style.background = clickedRowColor;
    row.style.background = '#e20a16';

    clickedRow = row;
    clickedRowColor = color;
}

function sortOver(col)
{
    document.body.style.cursor = 'arrow'; //'hand';
}

function sortOut(col)
{
    document.body.style.cursor = 'default';
}

function sortClick(col, url)
{
    col.style.borderLeftColor = 'buttonshadow';
    col.style.borderTopColor = 'buttonshadow';
    col.style.borderRightColor = 'buttonhighlight';
    col.style.borderBottomColor = 'buttonhighlight';

    if (url != '') 
        window.location = url;
}

function layerShow(id, x, y)
{
	document.all[id].style.display = '';
	
	if (document.all[id].style.position == 'absolute')
	{
        document.all[id].style.left = x;
        document.all[id].style.top = y;
	}
}

function layerHide(id)
{
	document.all[id].style.display = 'none';
}

function layerToggle(id)
{
	if(document.all[id].style.display)
		layerShow(id, mouseX, mouseY);
	else
		layerHide(id);
}

function layerVisible(id)
{
	return (!document.all[id].style.display);
}

function layerChangeContent(id, text) 
{
    if (ie4) 
        document.all[id].innerHTML = text;
    else
    {
        var obj = document.layers[id].document;
        obj.open();
        obj.write(text);
        obj.close();
    }
}

function initTable(oElement) 
{
	resizeTable(oElement);
	oElement.firstChild.syncTo = oElement.lastChild.uniqueID;
	oElement.firstChild.syncDirection = "horizontal";
	oElement.attachEvent("onresize", function () {
		resizeTable(oElement);
	});
}

function resizeTable(oElement) 
{
	var head = oElement.firstChild;
	var headTable = head.firstChild;
	var body = oElement.lastChild;
	var bodyTable = body.firstChild;
	
	body.style.height = Math.max(0, oElement.clientHeight - head.offsetHeight);
	
	var scrollBarWidth = body.offsetWidth - body.clientWidth;

	// set width of the table in the head
	headTable.style.width = Math.max(0, Math.max(bodyTable.offsetWidth + scrollBarWidth, oElement.clientWidth));

	// go through each cell in the head and resize
	var headCells = headTable.rows[0].cells;
	var bodyCells = bodyTable.rows[0].cells;

	for (var i = 0; i < bodyCells.length; i++)
		headCells[i].style.width = bodyCells[i].offsetWidth + 1;
}