try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function auto_tag(tag_name) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var el = document.getElementsByTagName(tag_name);
			set_auto_tag(el);
		});
	}
}

function set_auto_tag (el) {
	for (var i=0; i<el.length; i++) {
	    if (el[i].target == '_blank'){
			el[i].className+=" onw";
	    }
	}
}

//auto_tag("A");

isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isMSIE=document.all && document.all.item //Microsoft Internet Explorer 4+
isNetscape4=document.layers //Netscape 4.*
isOpera=window.opera //Opera
isOpera5=isOpera && isDOM //Opera 5+
isMSIE5=isDOM && isMSIE && !isOpera //MSIE 5+
isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera

//var windowW = 0;
//var windowH = 0;

var windowW = document.documentElement.offsetWidth;
var windowH = document.documentElement.offsetHeight;

/*
if (isMSIE || isMSIE5) {
  windowW = document.body.offsetWidth;
  windowH = document.body.offsetHeight;
} else {
  windowW = window.innerWidth;
  windowH = window.innerHeight;

}
*/

var obj;

function getLayer(layerName, parentLayerName){
  if(isDOM){ return document.getElementById(layerName); }
  if(isMSIE){ return document.all[layerName]; }
  if(isNetscape4){ return eval('document.layers[layerName]'); }
  return false;
}

function ts(e,what) {
  mousex = e.clientX;
  mousey = e.clientY;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY) {
    mousex = e.pageX;
    mousey = e.pageY;
  } else if (e.clientX || e.clientY) {
    mousex = e.clientX;
    mousey = e.clientY;
    if (isMSIE || isMSIE5) {
      mousex += document.body.scrollLeft;
      mousey += document.body.scrollTop;
    }
  }
  
  if (obj) tc();
  
  if($(what)){
    obj = $(what);
    if(obj){
      var objW = Element.getWidth(obj);
      if ((mousex + objW) > windowW - 30) {
        obj.style.left = windowW - objW - 30;
      } else {
        obj.style.left = mousex;
      }
      
      obj.style.top = mousey + 20;
      
      if(isNetscape4)
        obj.style.visibility = 'show';
      else
        obj.style.visibility = 'visible';
		  obj.style.display = 'block';
    }
   }
  return true;
}

function tc(){
  if(obj){
    if(isNetscape4)
      obj.style.visibility = 'hide';
    else
      obj.style.visibility='hidden';
		obj.style.display = 'none';
  }
  return true
}

function p(x, y, z) {
	for (a = 0; a < arguments.length; a++) {
		arguments[a] = arguments[a].split('');
		arguments[a] = arguments[a].reverse();
		arguments[a] = arguments[a].join('');
	}
	document.location.href = "mailto:" + x + "@" + y + "." + z;
}
function p_u(x, y, z) {
	c = arguments;
	for (b = 0; b < c.length; b++) {
        if (b == 3) continue;
		c[b] = c[b].split(',');
		c[b] = c[b].reverse();
		for (a = 0; a < c[b].length; a++)
			c[b][a] = String.fromCharCode(c[b][a] - 10);
		c[b] = c[b].join('');
	}
	document.location.href = "mailto:" + c[0] + "@" + c[1] + "." + c[2] + "?subject=" + c[3] + "";

}

var win = null;
function nwin(mypage,myname,w,h,scroll){LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;TopPosition = (screen.height) ? (screen.height-h)/2 : 0;settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

function file_size($size){
    var $s = $size;
    var $ext = ['á','Êá','Ìá','Ãá','Òá','Ïá','Ýá'];
    var $cnt = 0;
	while(Math.floor($s/1024)){
		if (!$ext[$cnt]) break;
		$s = $s/1024;
		$cnt++;
	}
	$s = Math.floor($s*10)/10;
	return $s+' '+$ext[$cnt];
}

function p_by_id(id){
	if (document.getElementById) {
		return parent.document.getElementById(id);
	}
	else if (document.all){
		return parent.document.all[id];
	}

	return false;
}
/*
*/

function get_frame(name){
	return document.frames?document.frames[name]:document.getElementById(name).contentWindow;
}

function setCookie (name, value) {
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : '/';
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires)) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function getCookie(name) {
  var prefix = name + "=";
  var cookieStartIndex = document.cookie.indexOf(prefix);
  if (cookieStartIndex == -1) return null;
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
  if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function EventBinder(eventsHash){
	for (elementName in eventsHash){
		for(eventName in eventsHash[elementName]){
			Event.observe(elementName, eventName, eventsHash[elementName][eventName], false);
		}
	}
}


function addToFileQueue(id,ext_id) {
    if (id == 0) return;
	_add_link(id,ext_id);
}

function _add_link(id,ext_id){
	var obj = new ag_server();
	obj.set_code("download_link");
	obj.set_param("action","add");
	obj.set_param("ext_id",id);
	obj.set_param("ext_type",ext_id);
	obj.on_load(_add_link_result);
	obj.load();
}

function _add_link_result(obj){
    if(obj.get('result')){
		_dl_bar_blink(obj.get('total'));
    }
}

function _dl_bar_blink(total){
    if (!$('bar_queue_vip_num')) return;
	$('bar_queue_vip_num').innerHTML = total;
	$('bar_queue_vip_num_tooltip').innerHTML = total;
	$('bar_queue_vip_bg').style.backgroundImage = 'url(/i_bar/dl_added.gif)';
}

function get_pressed_char(e){
    var keynum = 0;
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	return keynum;
}

