var _xmlhttp = null;

function get_xmlhttp () {
    if (window.XMLHttpRequest) {
	xmlhttp = new XMLHttpRequest();
	if (typeof xmlhttp.overrideMimeType != 'undefined') { 
	    xmlhttp.overrideMimeType('text/html'); 
	}
    } else if (window.ActiveXObject) {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
	alert('Perhaps your browser does not support xmlhttprequests?');
    }
    return xmlhttp;
}

function getObj (id) {
    return document.getElementById (id);
}

//var _counters = http_read_s ('?action=ajax&int=counters');

function scroll_vpos () {
    if (document.all) {
        if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
        else
            scrollX = document.documentElement.scrollLeft;

        if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
        else
            scrollY = document.documentElement.scrollTop;
    } else {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }

    return scrollY;
}


function toggle_loading (vis) {
    _divdqdo = getObj ('divdqdo');
    // move the object based on scroller position
    _divdqdo.style.top = scroll_vpos () + 3 + 'px';
    
    if (vis) 
	_divdqdo.style.visibility = 'visible';	
    else
	_divdqdo.style.visibility = 'hidden';    
}

function http_read (url, holder) {
    toggle_loading (1);
    if (_xmlhttp && _xmlhttp.readyState != 0) {
	_xmlhttp.abort ();
    }

    _xmlhttp = get_xmlhttp ();
    _xmlhttp.open ("GET", url, true);
    _xmlhttp.send (null);
    _xmlhttp.onreadystatechange = function () {
	if (_xmlhttp.readyState == 4 && _xmlhttp.responseText) {
	    getObj (holder).innerHTML = _xmlhttp.responseText;
	    toggle_loading (0);
	}
    }
    
    return false;
}

function http_read_s (url) {
    toggle_loading (1);
    if (_xmlhttp && _xmlhttp.readyState != 0) {
	_xmlhttp.abort ();
    }

    _xmlhttp = get_xmlhttp ();
    result = '';
    
    _xmlhttp.open ("GET", url, false);
    _xmlhttp.send (null);
    _xmlhttp.onreadystatechange = function () {
	if (_xmlhttp.readyState == 4 && _xmlhttp.responseText) {
	    result = _xmlhttp.responseText;
	}
    }
    result = _xmlhttp.responseText;
    toggle_loading (0);
    
    return result;
}


function SetCookie (cookieName, cookieValue, nDays) {
    var today = new Date ();
    var expire = new Date ();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime (today.getTime () + 3600000*24*nDays);
    document.cookie = cookieName + "=" + escape (cookieValue) + ";expires=" + expire.toGMTString ();
}

function ReadCookie (cookieName) {
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf (cookieName);
    if (ind == -1 || cookieName == "") return ""; 
    var ind1 = theCookie.indexOf (';', ind);
    if (ind1 == -1) ind1 = theCookie.length; 
    return unescape (theCookie.substring (ind + cookieName.length + 1, ind1));
}

function property_debug (obj) {
    _info = '';
    for (style in obj.style) {
        _info += style + ': '

        if (typeof (obj.style[style]) != 'function')
            _info += obj.style[style]
        else
            _info += ' function';
        _info += "; "
    }

    alert (_info);
}

function opener (url) {
    toggle_loading (1);
    window.location = url;
}

function loader_absolute_pos () {
    var _divdqdo = getObj ('divdqdo');
    if (typeof (_divdqdo) != 'undefined')
	_divdqdo.style.top = scroll_vpos () + 3 + 'px';
}

function highlight_on (obj) {
    // record original border
    _highlight_border = obj.style.border;

    // set border
    obj.style.border = '1px solid #FF0000';

    return true;
}

function highlight_off (obj) {
    // restore border
    obj.style.border = _highlight_border;
    obj.style.border = '1px solid #969696';

    return true;
}

function change_currency () {
    _form = document.forms['currency'].currency;
    _currency = _form.options[_form.selectedIndex].value;

    SetCookie ('currency', _currency, 30);
    document.currency.submit ();
}

function change_sort () {
    _form = document.forms['sort'].sort;
    _sort = _form.options[_form.selectedIndex].value;

    SetCookie ('sort', _sort, 30);
    document.sort.submit ();
}

function change_view () {
    _form = document.forms['view'].view;
    _view = _form.options[_form.selectedIndex].value;

    SetCookie ('view', _view, 30);
    document.view.submit ();
}

