//
// (C) Trurl McByte
//
var xmlHttp=null;
var gh_db_obj_id_counter=0;
var gh_db_loading= new Image();
gh_db_loading.src="/ghdb/loading.gif";
var gh_db_timers = new Array();
//

function gh_db_show(event,obj,url,result_holder,status_holder,skin,width,height,clickonly,hidetime) {

    if(!event) event = window.event;
    var holder = document.getElementById(result_holder);
    var holder_status = document.getElementById(status_holder);
    if(!hidetime) hidetime=2000;

    var x = gh_db_getAtrax(event,obj,ghdb_GetData,holder_status,holder);
    x.xmlHttp.open("GET",url,true);
    x.xmlHttp.send(null);
    return false;

    function ghdb_GetData(event,handler,holder_result) {
	var obj = gh_db_parse_html(event,handler,holder_result,skin,'html',width,height,clickonly,hidetime);
	holder_result.innerHTML='';
	holder_result.appendChild(obj.reply);
	ghdb_htabs_init(holder_result);
	return false;
    }
}



function gh_la2_showtip_img2(obj,event,url,width,height) {
    var ret=gh_db_createlayer(obj.parentNode,event);
    ret.innerHTML='<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>'+
    '<td><img src="http://forums.goha.ru/se/ramka/top-left.jpg" border="0" width="9px" height="35px" /></td>'+
    '<td onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
    '<img src="http://forums.goha.ru/se/ramka/top1.jpg" border="0" width="'+(width-23)+'px" height="35px" /></td><td>'+
    '<img src="http://forums.goha.ru/se/ramka/top2.jpg" alt="Close" border="0" width="23px" height="35px" '+
    ' style="cursor: pointer;" onclick="return gh_db_close_seek(this,event);" /></td>'+
    '<td><img src="http://forums.goha.ru/se/ramka/top-right.jpg" border="0" width="9px" height="35px" /></td>'+
    '</tr><tr>'+
    '<td><img src="http://forums.goha.ru/se/ramka/left.jpg" border="0" width="9px" height="'+height+'px" /></td>'+
    '<td colspan="2"><img border="0" src="'+url+'" width="'+width+'px" height="'+height+'px" /></td>'+
    '<td><img src="http://forums.goha.ru/se/ramka/right.jpg" border="0" width="9px" height="'+height+'px" /></td>'+
    '</tr><tr>'+
    '<td><img src="http://forums.goha.ru/se/ramka/bottom-left.jpg" border="0" width="9px" height="18px" /></td>'+
    '<td colspan="2"><img src="http://forums.goha.ru/se/ramka/bottom.jpg" border="0" width="'+width+'px" height="18px" /></td>'+
    '<td><img src="http://forums.goha.ru/se/ramka/bottom-right.jpg" border="0" width="9px" height="18px" /></td>'+
    '</tr></tbody></table>';
    ret.style.zIndex=100;
    gh_db_center_obj(ret);
}


function gh_db_show_page(event,obj,url,result_holder,status_holder,skin,width,height,clickonly,hidetime) {

    if(!event) event = window.event;
    var holder = document.getElementById(result_holder);
    var holder_status = document.getElementById(status_holder);
    if(!hidetime) hidetime=2000;

    var x = gh_db_getAtrax(event,obj,ghdb_GetData,holder_status,holder);
    x.xmlHttp.open("GET",url,true);
    x.xmlHttp.send(null);
    return false;

    function ghdb_GetData(event,handler,holder_result) {
	var obj = gh_db_parse_html(event,handler,holder_result,skin,'html',width,height,clickonly,hidetime);
	document.title = obj.title;
	holder_result.innerHTML='';
	holder_result.appendChild(obj.reply);
	ghdb_htabs_init(holder_result);
	if(obj.sonload) eval(obj.sonload);
	return false;
    }
}

function gh_db_showtip(obj,event,skin,width,height,clickonly,hidetime,stime) {
    if(stime==null) stime=300;
    if(!obj.id) obj.id = 'ghdb_'+obj.tagName+'_'+(++gh_db_obj_id_counter);
    if(stime==0) return gh_db_showtip_now(obj,event,skin,width,height,clickonly,hidetime,stime);
    obj.onmouseout = function (e) {
	if(gh_db_timers[obj.id+'_tooltip_pre'] && gh_db_timers[obj.id+'_tooltip_pre']!='disabled')
	clearTimeout(gh_db_timers[obj.id+'_tooltip_pre']); return false; }
    gh_db_timers[obj.id+'_tooltip_pre']=setTimeout(function () { return gh_db_showtip_now(obj,event,skin,width,height,clickonly,hidetime,stime); },stime);
    return false;
}

function gh_db_showtip_now(obj,event,skin,width,height,clickonly,hidetime,stime) {
    if (!event) event = window.event;
    if(stime==null) stime=300;
    if(obj.tagName != 'A') return false;
    var ext=/^.+\.([^.]+)$/.exec(obj.href);
    if(!event) event = window.event;
    if(ext != null) ext = ext[1];
    else ext = '';
    if(!obj.id) obj.id = 'ghdb_'+obj.tagName+'_'+(++gh_db_obj_id_counter);
    if(!hidetime) hidetime=2000;

    if(event!=null) {
	var x = event.x || event.layerX;
	var y = event.y || event.layerY;
    } else {

    }

    if(gh_db_timers[obj.id+'_tooltip'] && gh_db_timers[obj.id+'_tooltip']!='disabled') clearTimeout(gh_db_timers[obj.id+'_tooltip']);
    if(event.type == 'mouseover') {
	if(clickonly!=-1) 
	 obj.onclick = function (e) {
	    var tooltip=gh_db_ObjById(obj.id+'_tooltip');
	    if(!tooltip) return gh_db_showtip(obj,e,skin,width,height,clickonly,hidetime,stime);
	    if(gh_db_timers[tooltip.id] && gh_db_timers[tooltip.id]=='disabled') {
		    gh_db_timers[tooltip.id]=setTimeout('gh_db_closetip("'+tooltip.id+'")',100);
		    gh_db_closetip(tooltip.id);
		    return false;
	    }
	    gh_db_timers[tooltip.id]='disabled';
	    gh_db_showtip(obj,e,skin,width,height,clickonly,hidetime,stime);
	    return false;
	 }
	if(clickonly==1) return false;
	if(hidetime>0) {
	    if(!gh_db_timers[obj.id+'_tooltip'] || gh_db_timers[obj.id+'_tooltip']!='disabled') {
		obj.onmouseout = function (e) { gh_db_timers[obj.id+'_tooltip']=setTimeout('gh_db_closetip("'+obj.id+'_tooltip")',hidetime,stime); return false; }
	    }
	} else gh_db_timers[obj.id+'_tooltip']='disabled';
    }
    if(event.type == 'click') {
	obj.onmouseout = null;
	gh_db_timers[obj.id+'_tooltip']='disabled';
    }
    var tooltip=gh_db_ObjById(obj.id+'_tooltip');
    if(tooltip == null) {
	tooltip = gh_db_createlayer(obj.parentNode,obj.id+'_tooltip',x,y);
	    if(hidetime>0) {
		tooltip.onmouseover = function (e) {
		    if(gh_db_timers[tooltip.id] && gh_db_timers[tooltip.id]=='disabled') return false;
		    clearTimeout(gh_db_timers[tooltip.id]); return false; }
		tooltip.onmouseout = function (e) {
		    if(gh_db_timers[tooltip.id] && gh_db_timers[tooltip.id]=='disabled') return false;
		    gh_db_timers[tooltip.id]=setTimeout('gh_db_closetip("'+tooltip.id+'")',hidetime,stime); return false; }
	    }

	tooltip.innerHTML='<img src="'+gh_db_loading.src+'" border="0">Loading...';
	if(ext=='jpg' || ext=='gif' || ext=='png') {
	    var img = new Image();
	    img.onload = function(e) {
		document.body.style.cursor='auto';
		obj.style.cursor='pointer';
		return gh_db_skin(e,img,obj.title?obj.title:img.src,tooltip,skin,ext,width,height,clickonly,hidetime,stime); }
	    img.src=obj.href;
	    obj.style.cursor='wait';
	    document.body.style.cursor='wait';
	    return false;
	} else {
	     var x = gh_db_getAtrax(event,obj,gh_db_pfunc_html,tooltip,tooltip,ext,skin,width,height,clickonly,hidetime,stime);
	     var xurl=obj.href;
	     xurl=xurl.replace('/db/','/ghdb/');
	     x.xmlHttp.open("GET",xurl,true);
//	     x.xmlhttp.setRequestHeader('Accept-Charset','windows-1251;q=1.0');
	     x.xmlHttp.send(null);
	    return false;
	}
	
    } else { tooltip.style.display='block'; gh_db_position_obj(tooltip,0,0); };
    return false;
}


function gh_db_showtip_now_force(obj,event,url,skin,width,height,clickonly,hidetime,stime) {
    if (!event) event = window.event;
    if(stime==null) stime=300;
    var ext=/^.+\.([^.]+)$/.exec(url);
    if(!event) event = window.event;
    if(ext != null) ext = ext[1];
    else ext = '';
    if(!obj.id) obj.id = 'ghdb_'+obj.tagName+'_'+(++gh_db_obj_id_counter);
    if(!hidetime) hidetime=-1;

    if(event!=null) {
	var x = event.x || event.layerX;
	var y = event.y || event.layerY;
    }

    var tooltip=gh_db_ObjById(obj.id+'_tooltip');
    if(tooltip == null) {
	tooltip = gh_db_createlayer(obj.parentNode,obj.id+'_tooltip',x,y);
    }
    tooltip.innerHTML='<img src="'+gh_db_loading.src+'" border="0">Loading...';
	if(ext=='jpg' || ext=='gif' || ext=='png') {
	    var img = new Image();
	    img.onload = function(e) {
		document.body.style.cursor='auto';
		obj.style.cursor='pointer';
		return gh_db_skin(e,img,obj.title?obj.title:img.src,tooltip,skin,ext,width,height,clickonly,hidetime,stime); }
	    img.src=url;
	    obj.style.cursor='wait';
	    document.body.style.cursor='wait';
	    return false;
	} else {
	     var x = gh_db_getAtrax(event,obj,gh_db_pfunc_html,tooltip,tooltip,ext,skin,width,height,clickonly,hidetime,stime);
	     var xurl=url;
	     xurl=xurl.replace('/db/','/ghdb/');
	     x.xmlHttp.open("GET",xurl,true);
	     x.xmlHttp.send(null);
	    return false;
	}
    return false;
}




function gh_db_gettable(obj,event,skin,width,height,clickonly,hidetime,stime) {
	     var holder_result=gh_db_ObjById('outtable');
	     var holder_status=gh_db_ObjById('status');
	     var ext='xml';
	     var x = gh_db_getAtrax(event,obj,gh_db_pfunc_xml,holder_status,holder_result,ext,skin,width,height,clickonly,hidetime,stime);
	     x.xmlHttp.open("GET",obj.href,true);
	     x.xmlHttp.send(null);
	    return false;
}

function gh_db_createlayer(obj,id,x,y) {
 var tooltip = document.createElement("div");
 tooltip.id=id;
 tooltip.style.zIndex = 0;
 tooltip.style.position = "absolute";
 if(obj.currentStyle) {
   tooltip.style.left = "auto";
   tooltip.style.top = "auto";
 } else {
   tooltip.style.top = y + "px";
   tooltip.style.left = x + "px";
 }
 obj.appendChild(tooltip);
 if(obj.offsetLeft==0 || tooltip.offsetLeft == obj.offsetLeft)  tooltip.style.left = (x+5)+'px';
 if(obj.offsetTop==0 || tooltip.offsetTop == obj.offsetTop)  tooltip.style.top = (y+5)+'px';
 tooltip.style.left = (tooltip.offsetLeft+5) + "px";
 tooltip.style.top = (tooltip.offsetTop+5) + "px";
 return tooltip;
}

function gh_db_closetip(obj_id) {
    var tooltip=gh_db_ObjById(obj_id);
    if(tooltip != null && tooltip.style) tooltip.style.display='none';
    if(gh_db_timers[tooltip.id] && gh_db_timers[tooltip.id]=='disabled') gh_db_timers[tooltip.id]='0';
    return false;
}


function gh_db_skin(event,obj,title,tooltip,skin,ext,width,height,icon) {
    var resize=0; var ratio=1;
    if(!skin) skin=1;
    var rwidth = width;
    var rheight = height;
    if(!width)  if(obj.width && obj.width > 800) width=800; else width=obj.width;
    else ratio=obj.width/width;
    if(!height) if(obj.height && obj.height > 600) height=800; else height=obj.height;
    else if(ratio==1) ratio=obj.height/height;

    if(obj.height/ratio > height) ratio=obj.height/height;
    if(obj.width/ratio > width) ratio=obj.width/width;

    if(width < obj.width || height < obj.height) {
	height = Math.round(obj.height / ratio);
	width = Math.round(obj.width / ratio);
	resize=1;
    }
//alert(width+'x'+height+'||'+obj.width+'x'+obj.height);

    var objcode='';
    // oops
    if(obj.style.display=='none') { obj.parentNode.removeChild(obj); return false; } //selfdestruct

    if(!width || !height) {
	objcode='<table border="0"';
	if(width) objcode += (' width="'+width+'px"');
	if(height) objcode += ( 'height="'+height+'px"')
	objcode += '><tr><td';
	if(width) objcode += (' width="'+width+'px"');
	if(height) objcode += (' height="'+height+'px"')
	objcode += ('>'+obj.innerHTML+"</td></tr></table>");
	tooltip.innerHTML=objcode;
	ghdb_htabs_init(tooltip);
	if(tooltip.offsetWidth != undefined && tooltip.offsetWidth!=0) width = tooltip.offsetWidth;
	else if(rwidth!=0) width = rwidth;
	if(tooltip.offsetHeight != undefined && tooltip.offsetHeight!=0) height = tooltip.offsetHeight;
	else if(rheight!=0) height = rheight;
    }
    objcode='';
    tooltip.innerHTML=objcode;
    if(ext=='jpg' || ext=='gif' || ext=='png') {
	if(resize ==1 ) objcode += ('<a href="'+obj.src+'" target="_blank">');
	objcode += ('<img border="0" border="0" src="'+obj.src+'" width="'+width+'px" height="'+height+'px"/>');
	if(resize ==1 ) objcode += ('</a>');
    } else {
	objcode += obj.innerHTML;
    }
    //params: skin, width, height, title, objcode, tooltip_id, icon
    tooltip.innerHTML=gh_db_skin_apply(skin, width, height, title, objcode, tooltip.id, icon);
    tooltip.style.zIndex=100;
    tooltip.style.width=width + 'px';
    ghdb_htabs_init(tooltip);
    gh_db_position_obj(tooltip,25,15);
    return false;
}


function gh_db_skin_apply(skin, width, height, title, objcode, tooltip_id, icon) {
    switch(skin) {
	case 1:
	    return '<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>'+
	'<td><img src="/ghdb/skins/'+skin+'/top-left.jpg" border="0" width="9px" height="35px" /></td>'+
	'<td onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
	'<img src="/ghdb/skins/'+skin+'/top1.jpg" border="0" width="'+(width-23)+'px" height="35px" />'+
	'</td><td><img src="/ghdb/skins/'+skin+'/top2.jpg" alt="Close" border="0" width="23px" height="35px" '+
	' style="cursor: pointer;" onclick="return gh_db_closetip(\''+tooltip_id+'\');" /></td>'+
	'<td><img src="/ghdb/skins/'+skin+'/top-right.jpg" border="0" width="9px" height="35px" /></td>'+
	'</tr><tr><td><img src="/ghdb/skins/'+skin+'/left.jpg" border="0" width="9px" height="'+height+'px" '+
	'/></td><td colspan="2" width="'+width+'px" height="'+height+'px" bgcolor="#cec8bc">'+objcode+
	'</td><td><img src="/ghdb/skins/'+skin+'/right.jpg" border="0" width="9px" height="'+height+'px" '+
	'/></td></tr><tr>'+
	'<td><img src="/ghdb/skins/'+skin+'/bottom-left.jpg" border="0" width="9px" height="18px" /></td>'+
	'<td colspan="2"><img src="/ghdb/skins/'+skin+'/bottom.jpg" border="0" width="'+width+'px" '+
	'height="18px" /></td><td><img src="/ghdb/skins/'+skin+'/bottom-right.jpg" border="0" width="9px" height="18px" />'+
	'</td></tr></tbody></table>';
	case 2:
	    return '<style>'+
		'#'+tooltip_id+' .tooltip a{text-decoration:none;} '+
		'#'+tooltip_id+' .tooltip a:hover{text-decoration:underline;} '+
		'#'+tooltip_id+' .tooltip table{border-spacing:0;border-collapse:collapse;} '+
		'#'+tooltip_id+' .tooltip td, '+
		'#'+tooltip_id+' .tooltip th{background:url(/ghdb/skins/'+skin+'/tooltip.png);font-family:Verdana,sans-serif;font-size:12px;line-height:17px;color:white;} '+
		'#'+tooltip_id+' .tooltip th{padding:3px;vertical-align:top;} '+
		'#'+tooltip_id+' .tooltip td{padding:8px 4px 1px 9px;vertical-align:top;} '+
		'#'+tooltip_id+' .tooltip b{font-size:14px;line-height:19px;font-weight:normal;} '+
		'#'+tooltip_id+' .tooltip div.indent{padding-left:.6em;} '+
		'#'+tooltip_id+' .tooltip td th, '+
		'#'+tooltip_id+' .tooltip td td{background:none;} '+
		'#'+tooltip_id+' .tooltip td th{padding:0 0 0 4em;text-align:right;font-weight:normal;} '+
		'#'+tooltip_id+' .tooltip td td{padding:0;} '+
		'#'+tooltip_id+' .tooltip p{position:absolute;left:-44px;top:-1px;width:44px;height:44px;background:4px 4px no-repeat;margin:0;padding:0;} '+
		'#'+tooltip_id+' .tooltip p div{width:44px;height:44px;background-image:url(/ghdb/skins/'+skin+'/icon_border_medium.png);} '+
		'#'+tooltip_id+' .tooltip table.shrink b{font-size:12px;line-height:15px;} '+
		'#'+tooltip_id+' .tooltip table.shrink td, '+
		'#'+tooltip_id+' .tooltip table.shrink th{font-size:10px;line-height:14px;} '+
		'#'+tooltip_id+' .socket-1{padding-left:26px;background:url(/ghdb/skins/'+skin+'/socket_meta.gif) no-repeat left center;} '+
		'#'+tooltip_id+' .socket-2{padding-left:26px;background:url(/ghdb/skins/'+skin+'/socket_red.gif) no-repeat left center;} '+
		'#'+tooltip_id+' .socket-4{padding-left:26px;background:url(/ghdb/skins/'+skin+'/socket_yellow.gif) no-repeat left center;} '+
		'#'+tooltip_id+' .socket-8{padding-left:26px;background:url(/ghdb/skins/'+skin+'/socket_blue.gif) no-repeat left center;} '+
		'#'+tooltip_id+' .socket-16{padding-left:26px;background:url(/ghdb/skins/'+skin+'/socket_prismatic.gif) no-repeat left center;} '+
		'#'+tooltip_id+' a.moneyitem, '+
		'#'+tooltip_id+' a.moneysocketmeta, '+
		'#'+tooltip_id+' a.moneysocketred, '+
		'#'+tooltip_id+' a.moneysocketyellow, '+
		'#'+tooltip_id+' a.moneysocketblue{text-decoration:none!important;border-bottom:1px solid transparent;} '+
		'#'+tooltip_id+' a.moneyitem:hover, '+
		'#'+tooltip_id+' a.moneysocketmeta:hover, '+
		'#'+tooltip_id+' a.moneysocketred:hover, '+
		'#'+tooltip_id+' a.moneysocketyellow:hover, '+
		'#'+tooltip_id+' a.moneysocketblue:hover{border-bottom:1px solid white;} '+
		'#'+tooltip_id+' .moneyitem, '+
		'#'+tooltip_id+' .moneygold, '+
		'#'+tooltip_id+' .moneysilver, '+
		'#'+tooltip_id+' .moneycopper, '+
		'#'+tooltip_id+' .moneyalliance, '+
		'#'+tooltip_id+' .moneyhorde, '+
		'#'+tooltip_id+' .moneyarena, '+
		'#'+tooltip_id+' .moneyachievement, '+
		'#'+tooltip_id+' .moneysocketmeta, '+
		'#'+tooltip_id+' .moneysocketred, '+
		'#'+tooltip_id+' .moneysocketyellow, '+
		'#'+tooltip_id+' .moneysocketblue{color:white;background:no-repeat right center;} '+
		'#'+tooltip_id+' .moneyitem{padding-right:18px;} '+
		'#'+tooltip_id+' .moneygold{padding-right:15px;background-image:url(/ghdb/skins/'+skin+'/money_gold.gif);} '+
		'#'+tooltip_id+' .moneysilver{padding-right:15px;background-image:url(/ghdb/skins/'+skin+'/money_silver.gif);} '+
		'#'+tooltip_id+' .moneycopper{padding-right:15px;background-image:url(/ghdb/skins/'+skin+'/money_copper.gif);} '+
		'#'+tooltip_id+' .moneyalliance{padding-right:12px;background-image:url(/ghdb/skins/'+skin+'/money_alliance.gif);} '+
		'#'+tooltip_id+' .moneyhorde{padding-right:17px;background-image:url(/ghdb/skins/'+skin+'/money_horde.gif);} '+
		'#'+tooltip_id+' .moneyarena{padding-right:18px;background-image:url(/ghdb/skins/'+skin+'/money_arena.gif);} '+
		'#'+tooltip_id+' .moneyachievement{padding-right:13px;background-image:url(/ghdb/skins/'+skin+'/money_achievement.gif);} '+
		'#'+tooltip_id+' .moneysocketmeta{padding-right:18px;background-image:url(/ghdb/skins/'+skin+'/socket_meta.gif);} '+
		'#'+tooltip_id+' .moneysocketred{padding-right:18px;background-image:url(/ghdb/skins/'+skin+'/socket_red.gif);} '+
		'#'+tooltip_id+' .moneysocketyellow{padding-right:18px;background-image:url(/ghdb/skins/'+skin+'/socket_yellow.gif);} '+
		'#'+tooltip_id+' .moneysocketblue{padding-right:18px;background-image:url(/ghdb/skins/'+skin+'/socket_blue.gif);} '+
		'#'+tooltip_id+' .q{color:#ffd100!important;} '+
		'#'+tooltip_id+' .q0, #'+tooltip_id+' .q0 a{color:#9d9d9d!important;} '+
		'#'+tooltip_id+' .q1, #'+tooltip_id+' .q1 a{color:#fff!important;} '+
		'#'+tooltip_id+' .q2, #'+tooltip_id+' .q2 a{color:#1eff00!important;} '+
		'#'+tooltip_id+' .q3, #'+tooltip_id+' .q3 a{color:#0070dd!important;} '+
		'#'+tooltip_id+' .q4, #'+tooltip_id+' .q4 a{color:#a335ee!important;} '+
		'#'+tooltip_id+' .q5, #'+tooltip_id+' .q5 a{color:#ff8000!important;} '+
		'#'+tooltip_id+' .q6, #'+tooltip_id+' .q6 a{color:#e5cc80!important;} '+
		'#'+tooltip_id+' .q7, #'+tooltip_id+' .q7 a{color:#e5cc80!important;} '+
		'#'+tooltip_id+' .q8, #'+tooltip_id+' .q8 a{color:#ffff98!important;} '+
		'#'+tooltip_id+' .q9, #'+tooltip_id+' .q9 a{color:#71d5ff!important;} '+
		'#'+tooltip_id+' .q10, #'+tooltip_id+' .q10 a{color:#f00!important;} '+
		'#'+tooltip_id+' .tooltip { max-width: '+width+'; }'+
		'</style>'+
		'<div class="tooltip" style="float: left; padding-top: 1px; width: '+width+'px; height: '+height+'px">'+
		'<table><tr><td>'+objcode+'</td><th style="background-position: right top;"/></tr><tr><th '+
		'style="background-position: left bottom;"/><th style="background-position: right bottom;"/></tr></table></div>';
	default:
	case 3:
	    return '<table border="0" width="'+(width+2)+'px" cellpadding="6" cellspacing="1" class="tborder"><tbody><tr>'+
		'<td align="left" valign="middle" class="thead" '+
		'onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
		'<img src="/ghdb/skins/'+skin+'/closebtn.gif" alt="Close" border="0" style="cursor: pointer; float:right; padding: 6px 11px 6px 11px; border:0;" '+
		'onclick="return gh_db_closetip(\''+tooltip_id+'\');" />'+(icon?'<img src="'+icon+'" alt="" width="32px" height="32px" hspace="5" vspace="1" '+
		'border="0" align="middle" style="border: 1px solid #e0dcd4;"/>':'&nbsp;&nbsp;')+title+
		'</td></tr><tr><td class="alt1" align="left">'+objcode+
		'</td></tr></tbody></table>';
	case 4:
	    return '<table border="0" width="'+(width+2)+'px" cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial, sans-serif; font-size: 11px;" '+
		'summary="'+title+'"><caption style="display:none">'+title+'</caption><tbody><tr>'+
		'<td align="left" valign="middle" background="/ghdb/skins/'+skin+'/header.gif" style="color:#00588f; font-size:16px; padding: 2px 2px 2px 2px;" '+
		'onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
		'<img src="/ghdb/skins/'+skin+'/btnclose.gif" alt="Close" border="0" align="right" hspace="5" vspace="5" style="cursor: pointer;" '+
		'onclick="return gh_db_closetip(\''+tooltip_id+'\');" />'+(icon?'<img src="'+icon+'" alt="" width="32px" height="32px" hspace="10" vspace="10" '+
		'border="0" align="middle" />':'&nbsp;&nbsp;')+title+'</td></tr><tr><td style="margin: 0px; padding: 5px;" align="left" '+
		'background="/ghdb/skins/'+skin+'/ddline.gif" style="list-style-image: url(/ghdb/skins/'+skin+'/li.gif);">'+objcode+
		'</td></tr><tr style="height: 3px;"><td background="/ghdb/skins/'+skin+'/ddfooter.gif"><img src="/ghdb/skins/'+skin+'/ddfooter.gif" hspace="0" '+
		'vspace="0" border="0" /></td></tr></tbody></table>';
	case 5:
	    return '<table border="0" width="'+(width+2)+'px" cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial, sans-serif; font-size: 11px;" '+
		'summary="'+title+'"><caption style="display:none">'+title+'</caption><tbody><tr>'+
		'<td align="left" valign="middle" style="color: #00588f; font-size:16px; padding: 2px 2px 2px 2px; background-color: #e0dcd4; '+
		'border: 1px solid #a29f77; -moz-border-radius: 5px; -webkit-border-radius: 5px;" '+
		'onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
		'<img src="/ghdb/skins/'+skin+'/btnclose.gif" alt="Close" border="0" align="right" hspace="5" vspace="5" style="cursor: pointer;" '+
		'onclick="return gh_db_closetip(\''+tooltip_id+'\');" />'+(icon?'<img src="'+icon+'" alt="" width="32px" height="32px" hspace="10" vspace="10" '+
		'border="0" align="middle" />':'&nbsp;&nbsp;')+title+'</td></tr><tr><td style="margin: 0px; padding: 5px; background-color: #e0dcd4; '+
		'border: 1px solid #a29f77;-moz-border-radius: 5px; -webkit-border-radius: 5px; '+
		'list-style-image: url(/ghdb/skins/'+skin+'/li.gif);" align="left">'+objcode+
		'</td></tr></tbody></table>';
	case 6:
	    return '<style>'+
		'#'+tooltip_id+' .thead { background-color: #7f94a3; color: #efebdf;} </style>'+
		'<table border="0" width="'+(width+2)+'px" cellpadding="0" cellspacing="0" style="font-family: Arial, Tahoma, sans-serif; font-size: 13px;'+
		'color: #050505; border: 1px solid #6a7287; -moz-border-radius: 5px; -webkit-border-radius: 5px;"><tbody><tr style="background-color: #7f94a3;">'+
		'<td align="left" valign="middle"  style="color: #efebdf; font-size: 16px; background-color: #7f94a3; margin: 5px;" '+
		'onmouseover="gh_db_mover(this,this.parentNode.parentNode.parentNode.parentNode);">'+
		'<img src="/ghdb/skins/'+skin+'/closebtn.gif" alt="Close" border="0" style="cursor: pointer; float:right; padding: 16px 11px 16px 11px; border:0;" '+
		'onclick="return gh_db_closetip(\''+tooltip_id+'\');" />'+(icon?'<img src="'+icon+'" alt="" width="32px" height="32px" hspace="10" vspace="10" '+
		'border="0" align="middle" style="border: 1px solid #e0dcd4;"/>':'&nbsp;&nbsp;')+title+
		'</td></tr><tr><td style="margin: 5px; padding: 5px; background-color: #efebe2; '+
		'list-style-image: url(/ghdb/skins/'+skin+'/li.gif);" align="left">'+objcode+
		'</td></tr></tbody></table>';
    }
    return 'woot';
}

function gh_db_close_seek(obj,e) {
  var obj_pid = obj.parentNode;
  var lim = 0;
  while(lim<30) {
      lim = lim + 1;
      if(obj_pid.style && (obj_pid.style.position == 'absolute' || obj_pid.style.position == 'relative')) { 
	obj_pid.style.display="none";
	break;
      }
      if(obj_pid.parentNode == document) break;
      obj_pid = obj_pid.parentNode;
  }
}



function gh_db_getAtrax(event,obj,pfunc,holder_status,holder_result,ext,skin,width,height,clickonly,hidetime,stime)
{
  var atrax = new Object;
  if(typeof(_)!='function'){var _ = function (msgid) { return msgid; }}
  atrax.ajax=1;
  atrax.processing=0;
  atrax.holder_status = holder_status;
  atrax.holder_result = holder_result;
  atrax.xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    atrax.xmlHttp=new XMLHttpRequest();
    }
  catch (e) {
    // Internet Explorer
    try {
      atrax.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e) {
      atrax.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }

  if (atrax.xmlHttp==null) {
    atrax.holder_status.innerHTML=_("Your browser does not support AJAX!");
    atrax.ajax=0;
  }
  atrax.xmlHttp.onreadystatechange=function () 
  { 
    if (atrax.xmlHttp.readyState==1) {
	    atrax.processing=1;
	    atrax.holder_status.innerHTML = _('Loading data...');
	    document.body.style.cursor='wait';
    }
    else if (atrax.xmlHttp.readyState==2) {
	    atrax.processing=1;
	    atrax.holder_status.innerHTML=_("Loaded");
    }
    else if (atrax.xmlHttp.readyState==3) {
	    atrax.processing=1;
	    atrax.holder_status.innerHTML=_("Prepearing data to show");
    }
    else if (atrax.xmlHttp.readyState==4) {
	document.body.style.cursor='auto';
	if (atrax.xmlHttp.status==200) {
	    atrax.holder_status.innerHTML="Done";
	    pfunc(event,atrax.xmlHttp,holder_result,skin,ext,width,height,clickonly,hidetime,stime);
	} else {
	    atrax.holder_result.innerHTML='';
	    atrax.holder_status.innerHTML=_("Error: ") + _(atrax.xmlHttp.statusText);
	}
	atrax.processing=0;
    }
    else {
	document.body.style.cursor='auto';
	atrax.holder_status.innerHTML=_("Error: ") + _(atrax.xmlHttp.statusText);
	atrax.holder_result.innerHTML=atrax.xmlHttp.responseText;
      //obj.appendChild(atrax.holder_result);

    }
  }

  return atrax;
}


function gh_db_pfunc_xml(event,handler,holder_result,skin,ext,width,height,clickonly,hidetime,stime) {
	if(handler.responseXML==null) {
	    holder_result.innerHTML="oops...";
	    return;
	}
	var limit=10;
	var xmldoc = handler.responseXML;
	var root = xmldoc.getElementsByTagName('table').item(0);
	var th = holder_result.insertRow(-1);
	for (var iNode = 0; iNode < root.childNodes.length && iNode < limit ; iNode++) {
	    var rr = holder_result.insertRow(-1);
	    var node = root.childNodes.item(iNode);
	    for (var i = 0; i < node.childNodes.length; i++) {
		var sibl = node.childNodes.item(i);
		if(sibl.tagName != undefined) {
		    if(iNode==1) {
			var thcell=th.insertCell(-1);
			thcell.innerHTML="<b>"+sibl.tagName+"</b>";
		    }
		    var cell = rr.insertCell(-1);
		    if(sibl.childNodes.item(0) && sibl.childNodes.item(0).data != undefined) {
			cell.innerHTML =  sibl.childNodes.item(0).data + "|" + iNode + "|" + i;
		    }
		}
	    }
	}
}


function gh_db_mover(header,tooltip) {
  header.style.cursor="move";
  header.onmousedown = function (e) {
    var m = gh_db_getMouse(e);
    tooltip.style.zIndex = parseInt(tooltip.style.zIndex) + 1;
    var dragXoffset = m.X - parseInt(tooltip.style.left);
    var dragYoffset = m.Y - parseInt(tooltip.style.top);
    document.onmouseup = function () {
	document.onmousemove=null;
	document.onmouseup=null;
        tooltip.style.zIndex = parseInt(tooltip.style.zIndex) - 1;
    }
    document.onmousemove = function (em) {
	var m = gh_db_getMouse(em); 
	tooltip.style.left = m.X - dragXoffset + 'px';
	tooltip.style.top = m.Y - dragYoffset + 'px';
	return false;
    }
    return false;
  }
}

function gh_db_getMouse(e) {
 var m = new Object;
 if(e==null) e = window.event;
 m.X=0;
 m.Y=0;
 if(document.all&&!window.opera) {
    m.X = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    m.Y = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
 } else {
    m.X = e.pageX;
    m.Y = e.pageY;
 }
// alert('X='+m.X+'|Y='+m.Y);
 return m;
}

function gh_db_ObjById(id) {
    if (document.getElementById) return document.getElementById(id);
    if (document.all) return document.all[id];
    if (document.layers) return document.layers[id];
    return null;
}

function gh_db_center_obj(obj) {

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

    obj.style.left=((myWidth-obj.offsetWidth)/2 + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft))+'px';
    obj.style.top=((myHeight-obj.offsetHeight)/2 +  (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px';
}

function gh_db_position_obj(obj,dx,dy) {

  var myWidth = 0, myHeight = 0;
  var objWidth = 0, objHeight = 0;
  var sx=getBodyScrollLeft(); //(document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  var sy=getBodyScrollTop(); //(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth; myHeight = window.innerHeight;
    objWidth = parseInt(obj.style.left); objHeight = parseInt(obj.style.top);
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    objWidth = parseInt(obj.style.left); objHeight = parseInt(obj.style.top);
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
    objWidth = parseInt(obj.style.left); objHeight = parseInt(obj.style.top);
  }

    if(myWidth + sx - (objWidth + obj.offsetWidth) < dx) {
	obj.style.left=(objWidth - obj.offsetWidth + dx)+'px';
    } else {
	obj.style.left=(objWidth + dx)+'px';
    }
    if(myHeight + sy - (objHeight + obj.offsetHeight) > dy) {
	obj.style.top=(objHeight + dy)+'px';
    } else {
	if((objHeight-obj.offsetHeight)<sy) obj.style.top=sy + 'px';
	else obj.style.top=(objHeight - obj.offsetHeight - dy)+'px';
    }
}

function gh_db_collent_form_data(form) {

  var els = form.elements;
  var data=""; var i=0; var y=0;
  for(i=0; i<els.length; i++){
//  alert(els[i].type);
    switch(els[i].type){
	    case "select-one" :
		    data = data + (data?"&":"") + encodeURI(els[i].name) + "=" + els[i].options[els[i].selectedIndex].value; 
		    break;
	    case "select-multiple" :
		    for(y=0; y < els[i].length; y++ ) {
			if(els[i].options[y].selected) {
			    data = data + (data?"&":"") + encodeURI(els[i].name) + "=" +
				encodeURI(els[i].options[y].value);
			}
		    }
		    break;
	    case "textarea":
	    case "hidden":
	    case "password":
	    case "text":
		data = data + (data?"&":"") + encodeURI(els[i].name) + "=" + encodeURI(els[i].value);
		break;
	    case "submit":
	    case "button":
		break;
	    case "checkbox":
	    case "radio":
		if(els[i].checked==true) data = data + (data?"&":"") + encodeURI(els[i].name) + "=true";
		break;
	}
  }
  return data;

}

function gh_db_strip_tags(str) {
   return str.replace(/&lt;\/?[^&gt;]+&gt;/gi, "");
}

ghdb_getElByClass = function(obj,type,cname) {
	var els = obj.getElementsByTagName(type);
	var el = null;
	var res = new Array();
	for(var i=0,j=els.length; i<j; i++) {
	    if(els[i].className==cname) res.push(els[i]);
	}
	return res;
    }

function ghdb_htabs_init(obj) {
    var panels=ghdb_getElByClass(obj,'tbody','tabHolder');
    for(var i=0,j=panels.length; i<j; i++) {
	if(panels[i].childNodes.length < 3) continue;
	var tabs = new Array();
	for(var ti=0,tj=panels[i].childNodes.length; ti<tj; ti++) {
	    if(panels[i].childNodes[ti].tagName!='TR') continue;
	    tabs.push(panels[i].childNodes[ti]);
	}

	for(var ti=0,tj=tabs.length; ti<tj; ti++) {
	    if(ti%2) {
		if(ti!=1) tabs[ti].style.display='none';
		else tabs[ti].style.display='block';
	    } else {
		tabs[ti].style.cursor='pointer';
		eval('tabs[ti].onclick=function(e) { return ghdb_htabs_select(this,'+ti+'); };');
	    }
	}
    }
}

function ghdb_htabs_select(obj,idx) {
	var tabs = new Array();
	for(var ti=0,tj=obj.parentNode.childNodes.length; ti<tj; ti++) {
	    if(obj.parentNode.childNodes[ti].tagName!='TR') continue;
	    tabs.push(obj.parentNode.childNodes[ti]);
	}
	for(var ti=0,tj=tabs.length; ti<tj; ti++) {
	    if(ti%2) {
		if(ti!=(idx+1)) tabs[ti].style.display='none';
		else tabs[ti].style.display='block';
	    }
	}
}

function gh_db_pfunc_html(event,handler,holder_result,skin,ext,width,height,clickonly,hidetime,stime) {
	if(skin==undefined) skin=1;
	var obj = gh_db_parse_html(event,handler,holder_result,skin,ext,width,height,clickonly,hidetime,stime);
	gh_db_skin(event,obj.reply,obj.title,holder_result,skin,ext,width,height,obj.icon);
	return false;
}

function getBodyScrollTop()
{
  return self.pageYOffset || 
    (document.documentElement && document.documentElement.scrollTop) || 
    (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || 
    (document.documentElement && document.documentElement.scrollLeft) || 
    (document.body && document.body.scrollLeft);
}

function gh_db_parse_html(event,handler,holder_result,skin,ext,width,height,clickonly,hidetime,stime) {
	    var obj = new Object();
	    obj.icon='';
	    var rstr = handler.responseText.toString();
	    obj.title = rstr.substring(rstr.indexOf('<title>')+7,rstr.indexOf('</title>'));
	    if(rstr.indexOf('<link rel="SHORTCUT ICON" href="') > -1) {
		obj.icon = rstr.substring(rstr.indexOf('<link rel="SHORTCUT ICON" href="')+32,rstr.indexOf('<body'));
		obj.icon = obj.icon.substring(0,obj.icon.indexOf('"'));
	    }
            if(rstr.indexOf('<!-- body -->') > -1 && rstr.indexOf('<!-- /body -->') > -1) {
                rstr = rstr.substring(rstr.indexOf('<!-- body -->'),rstr.indexOf('<!-- /body -->'));
            } else  if(rstr.indexOf('<body') > -1 && rstr.indexOf('</body') > -1) {
                rstr = rstr.substring(rstr.indexOf('<body'),rstr.indexOf('</body'));
	    }
            if(rstr.indexOf('<body onload=') > -1) {
		obj.sonload=rstr.replace(/<body onload="/,'');
		obj.sonload=obj.sonload.substring(0,obj.sonload.indexOf('">'));
	    }
	    rstr = rstr.replace(/<body[^>]*>/,'');
	    rstr = rstr.replace(/<a href=\"\/ghdb\//g,'<a onmouseover="gh_db_showtip(this,event,'+skin+','+width+','+height+','+clickonly+','+hidetime+');" href="/ghdb/');
	    obj.reply = document.createElement("div");
	    obj.reply.innerHTML=rstr;
	    return obj;
}


