// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_moz    = ( (navigator.product == 'Gecko')  && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_kon    = (uagent.indexOf('konqueror') != -1);

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );

/**
* Gets element by specified id
* id    needed object ID
**/
function _obj( id ) {

	 return document.getElementById ? document.getElementById(id) : null

}

function $( id ){

	return document.getElementById ? document.getElementById(id) : null

}

function is_defined( variable ) {
	return (typeof(window[variable]) != 'undefined');
}

function pause( millis ) {
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while( curDate-date < millis );
}


function _href( page ) {
	location.href = page;
}

function _noBubbling( e ) {

	e = _fixE( e );
	if (e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
    return false;

}

function _fixE( e ) {
	if (is_ie) e = event;
	if (!e) var e = window.event;
	return e;
}

function getEventTag( e ) {

	e = _fixE( e );
	if (is_ie) {
		return e.srcElement.nodeName.toLowerCase();
	} else if (e.target.nodeName) {
		return e.target.nodeName.toLowerCase();
	} else {
		return e.target.tagName.toLowerCase();
	}

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {

    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);

    if (begin == -1) {

        begin = dc.indexOf(prefix);
        if (begin != 0) return null;

    } else {

        begin += 2;

    }

    var end = document.cookie.indexOf(";", begin);

    if (end == -1) {

        end = dc.length;

    }

    return unescape(dc.substring(begin + prefix.length, end));

}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session) (days)!!!
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime(today.getTime());

	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name+'='+escape(value) +
		((expires) ? ';expires='+expires_date.toGMTString() : '') +
		((path) ? ';path=' + path : '') +
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie( name, path, domain ) {

    if (getCookie(name)) {

        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";

    }

}

function setLanguage( lang ) {

	if (getCookie('ads-lang') != lang) {
		setCookie( 'ads-lang', lang, 180 );
		window.location.reload( false );
	}

}

function setSkin( skin ) {

	if (getCookie('ads-skin') != skin) {
		setCookie( 'ads-skin', skin, 180 );
		window.location.reload( false );
	}

}

function showMessage( txt ) {

	if (txt) floatMessage = txt;
	obj = _obj('float-message');
	if (!obj) {
		document.write("<div id=\"float-message\" style=\"display: none\">");
		document.write("<div id=\"float-title\" align=\"right\"><span style=\"position:relative; left: -100px;\"><b>"+floatMessageTitle+"</b></span><span align=\"right\" style=\"cursor: pointer;\" onclick=\"hide('float-message');\"><b>x</b></span></div>");
		document.write("<div id=\"float-message-text\">"+floatMessage+"</div>");
		document.write("</div>");
		obj = _obj('float-message');
	} else {
		_obj('float-message-text').innerHTML = floatMessage;
	}

	if (floatMessage != '') {
		show('float-message');
	}

	obj.style.left =  Math.ceil((document.body.clientWidth - obj.clientWidth - 2) / 2) + "px";
	//setTimeout("hide('float-message');", 10000);

}

function show( id ) {
	obj = _obj( id );
	if (obj.style.display = 'none') {
		obj.style.display = '';
	}
}

function hide( id ) {
	obj = _obj( id );
	if (obj.style.display != 'none') {
		obj.style.display = 'none';
	}
}

function show_hide( id , save_to_cookie) {
    obj = _obj( id );
    if (obj.style.display == 'none') {
        obj.style.display = '';
        if (save_to_cookie) setCookie('ads-hide-'+id );
    } else {
        obj.style.display = 'none';
        if (save_to_cookie) setCookie('ads-hide-'+id, '1', 365);
    }
}

function check_uncheck( element ) {

	if (element.checked) element.checked = false;
	else element.checked = true;

}

//return pressed key
//only on event onkeypress

var global_key = null;

function getKey( e ) {

    if (!e) var e = window.event;
    global_key = e.whith ? e.whith : e.keyCode;

    //global_key = String.fromCharCode(global_key).toLowerCase();

	return global_key;

}

function listenKey() { document.onkeydown = getKey; }
function nolistenKey() { document.onkeydown = ''; global_key = null; }

function getStyle( id ) {

	var obj = _obj( id );
	if( window.getComputedStyle ) {
  		return window.getComputedStyle( obj, null );
	} else if( obj.currentStyle ) {
  		return obj.currentStyle;
	}

	return null;

}

function getBounds( element ) {

	var left = element.offsetLeft;
	var top = element.offsetTop;

	for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}

	return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};

}

function getPageScroll() {

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;

}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func) {

	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
    	window.onload = func;
	} else {
		window.onload = function() {
		    oldonload();
		    func();
		}
	}

}

function executeJS() {

	/*if (document.body.clientHeight < 450) {
		_obj('HTML').style.height = "450px";
	}*/

	if (is_defined('floatMessage')) { showMessage(); }
	if (window.buildFloatAttachments != null) { buildFloatAttachments(); }

}