function setBrowserDisabled(id, state)
{
	var img = document.getElementById(id);
	var lnk = document.getElementById(id + "_link");

	if (lnk) {
		if (state) {
			lnk.setAttribute("realhref", lnk.getAttribute("href"));
			lnk.removeAttribute("href");
		} else {
			if (lnk.getAttribute("realhref"))
				lnk.setAttribute("href", lnk.getAttribute("realhref"));
		}
	}
}


function include(filename)
{
	var ext = /^.+\.([^.]+)$/.exec(filename);
	filetype = ext == null ? "" : ext[1];

	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script');
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src", filename);
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
	}
	if (typeof fileref!="undefined") {
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function run_js(name)
{
	var the_div = document.getElementById(name);
	if(the_div != null) {
		var arr_scripts = the_div.getElementsByTagName('script');
		for(i in arr_scripts) {
			eval(arr_scripts[i].innerHTML);
		}
	}
}


function getBrowserHTML(id, target_form_element, type, prefix)
{
	var option = prefix + "_" + type + "_browser_callback", cb, html;

	if (!cb)
		return "";

	html = "";
	html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">';
	html += '<span id="' + id + '" title="' + ss.getLang('browse') + '"></span></a>';

	return html;
}


_link_url 				= _ad_url;
_gfx_url 				= _ad_image;
_obj_width 				= '1024';
_obj_height 			= '35';


function swap_display(main_div_id, second_div_id)
{
	var main_div = document.getElementById(main_div_id);
	if (second_div_id) var second_div = document.getElementById(second_div_id);
	if (main_div) {
		main_div.style.display = (main_div.style.display=="none") ? "block" : "none";
		if (second_div) second_div.style.display = (main_div.style.display=="none") ? "block" : "none";
	}
}


var _obj_offset 		= 0;
var _obj_scroll_enabled = 1;


function _add_load_event(handler) {
  if (window.addEventListener) {
    window.addEventListener('load', handler, false);
  }
  else if (document.addEventListener) {
    document.addEventListener('load', handler, false);
  }
  else if(window.attachEvent) {
    window.attachEvent('onload', handler);
  }
}


function startScrolling()
{
	if (ready() == true) {
		window.clearInterval(myPause)
		myInterval = setInterval("autoScroll()",speed)
	}
}


function _escapeHTML(s)
{
  s = s.replace('<', '&lt;');
  s = s.replace('>', '&gt;');
  s = s.replace('&', '&amp;');
  s = s.replace('"', '&quot;');
  return s;
}


function ajaxObject()
{
	// will return an XMLHttprequest object
	if (window.XMLHttpRequest) {
		obj = new XMLHttpRequest(); // Mozilla, Safari, IE7...
	} else if (window.ActiveXObject) { // IE
		Try.these(
			function(){ obj = new ActiveXObject("Msxml2.XMLHTTP"); },
			function(){ obj = new ActiveXObject("Microsoft.XMLHTTP"); }
		);
	}
	return obj;
}


function autoScroll()
{
	for (ii = 0; ii < kk; ii++) {
		myTop[ii] = myTop[ii] - 1

	if (myTop[ii] == -(pic[ii].height)) {
		hhh = 0
		for (nnn=0;nnn<kk;nnn++){
			if (nnn!=ii){
				hhh = hhh + pic[nnn].height
			}
		}
		myTop[ii] =  hhh
	}
		document.images[ii].style.top = myTop[ii]
	}
	mode = 1
}


function _strip_get_style()
{
  var _ad_engine = -1;
    if (window.navigator.appName == "Microsoft Internet Explorer") {
       if (document.documentMode)
          _ad_engine = document.documentMode;
       else {
          _ad_engine = 5;
          if (document.compatMode) {
             if (document.compatMode == "CSS1Compat")
                _ad_engine = 7;
          }
       }
    }

    if (_ad_engine == 5 || _ad_engine == 7) {
    var _adeng__iestyle =
      "z-index: 32701; height: 35px; \n"+
      "width: expression( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth )  ;\n" +
      "overflow: hidden;\n" +
      "position: absolute;\n" +
      "right: auto;\n" +
      "bottom: auto;\n" +
      "visibility: visible;\n"+
       "left: expression( ( -0 - this.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' ) !important;\n" +
      "top: expression( ( -0 - adHandler_strip_overlay.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' ) !important;\n";

    var _adeng__styleSheetObj = document.createStyleSheet();
    _adeng__styleObj=_adeng__styleSheetObj.owningElement || _adeng__styleSheetObj.ownerNode;
    _adeng__styleObj.setAttribute("type", "text/css");
    _adeng__styleSheetObj.addRule("#adHandler_strip_overlay", _adeng__iestyle);
    return "";
  } else {
    return "z-index: 32701; position: fixed; left: 0px; bottom: 0px; width: 100%; height: 35px; overflow: hidden; visibility: visible;";
  }
}


function stop()
{
	if (mode == 1) {
		window.clearInterval(myInterval)
	}
	if (mode == 0) {
		window.clearInterval(myPause)
	}
}


function _strip_init()
{
  var _adeng__style = _strip_get_style();
  var s_html="";
  var _adeng__div = document.createElement('div');
  _adeng__div.id = 'adHandler_strip_overlay';
  _adeng__div.setAttribute('class', 'adHandler_strip_overlay');

  s_html = '<div id="adHandler_strip_inner" style="position: relative; height: 35px; white-space: nowrap; overflow: visible;" onmouseover="_obj_scroll_enabled = 0" onmouseout="_obj_scroll_enabled = 1">';

  s_html += '<a href="' + _escapeHTML(_link_url) + '" style="white-space: nowrap" target="' + _target + '">';
  for(var i = 0; i < 4; i++)
  {
      s_html += '<img border="0" width="' + _obj_width + '" height="' + _obj_height + '" style="display: inline" src="' + _escapeHTML(_gfx_url) + '" />';
  }
  s_html += '</a>';

  s_html += '</div>';

  _adeng__div.innerHTML = s_html;
  _adeng__div.setAttribute('style', _adeng__style);

  var _adeng__out_div=document.createElement('div');
  var _adeng__out_div_style="z-index: 37200; height: 35px; width: 100%; overflow: visible; visiblity: visible;";
  _adeng__out_div.setAttribute('style', _adeng__out_div_style);
  _adeng__out_div.setAttribute('id',"adHandler_strip_out_div_style");

  if(navigator.userAgent.search('MSIE') != -1)
  {
    var _adeng__styleSheetObj=document.createStyleSheet();
    _adeng__styleObj=_adeng__styleSheetObj.owningElement || _adeng__styleSheetObj.ownerNode;
    _adeng__styleObj.setAttribute("type", "text/css");
    _adeng__styleSheetObj.addRule("#adHandler_strip_out_div_style", _adeng__out_div_style);
  }
  _adeng__out_div.appendChild(_adeng__div);
  document.body.appendChild(_adeng__out_div);

  if(_obj_scroll_enabled)
    setInterval('_strip_scroll()', 50);
}


function GetXmlHttpObject()
{
    var xmlHttp=null;

    try
    {
		xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
		try
		{
		    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
    return xmlHttp;
}


function date_format(val)
{

	var objDate = new Date(val*1000);

	var date = parseInt(objDate.getDate(), 10);
	if(date < 10) {
		date = '0' + date;
	}

	var month = parseInt(objDate.getMonth() + 1, 10);
	if(month < 10) {
		month = '0' + month;
	}

	var year  = objDate.getFullYear();

	var hours = parseInt(objDate.getHours(), 10);
	if(hours < 10) {
		hours = '0' + hours;
	}

	var minutes = parseInt(objDate.getMinutes(), 10);
	if(minutes < 10) {
		minutes = '0' + minutes;
	}

	return (date + '.' + month + '.' + year + ' ' + hours + ':' + minutes);
}

function showhide(obj, e, visible, hidden, tipwidth)
{
	if (ie4||ns6) {
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
	}
	if (tipwidth!="") {
		dropmenuobj.widthobj=dropmenuobj.style;
		dropmenuobj.widthobj.width=tipwidth;
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover") {
		obj.visibility=visible;
	}
	else if (e.type=="click") {
		obj.visibility=hidden;
	}
}


function iecompattest()
{
 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
_add_load_event(_strip_init);


function _strip_scroll()
{
  if(_obj_scroll_enabled)
  {
    if(_obj_offset >= _obj_width)
      _obj_offset = 0;
    else
      _obj_offset += 2;

    _adeng__div = document.getElementById('adHandler_strip_inner');
    _adeng__div.style.left = -_obj_offset + 'px';
  }
}


function substr_count(haystack, needle, offset, length) {
    var pos = 0, cnt = 0;

    if (isNaN(offset)) offset = 0;
    if (isNaN(length)) length = 0;
    offset--;

    while ( (offset = haystack.indexOf(needle, offset+1)) != -1 ) {
        if(length > 0 && (offset+needle.length) > length){
            return false;
        } else{
            cnt++;
        }
    }

    return cnt;
}
