// EasyTip for Objects v4.0 16/7/2004 - supports IE & Moz & Opera
var offsetxpoint=-60;
var offsetypoint=20;
var ie=document.all?true:false;
var ns6=(document.getElementById && !document.all) ? true:false;
var moz=(document.getElementById && !document.all) ? true:false;
var enabletip=false;
var firsttime=true;
var voteObj=false;
var mx=0;
var my=0;
document.write("<div id='dhtmltooltip' style='position:absolute;top:0px;left:0px;visibility:hidden'>rien</div>");
if (ie||ns6) var tipobj=document.getElementById('dhtmltooltip');
start_capture();

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//--------------------------------------------
// get the top|left position of an object
//--------------------------------------------
function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=='left')? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=='left')? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
//--------------------------------------------
// convert color to decimal
//--------------------------------------------
function dehexize(color)
{ 
	var colorArr = new Array(3)
	for (i=1; i<7; i++)
	{
		for (j=0; j<16; j++)
		{ 
			if (color.charAt(i) == hx[j])
			{ 
				if (i%2 !=0) 
					colorArr[Math.floor((i-1)/2)]=eval(j)*16; 
				else 
					colorArr[Math.floor((i-1)/2)]+=eval(j); 
			} 
		} 
	} 
	return colorArr; 
} 
//--------------------------------------------
// convert a 1-byte number to hex
//--------------------------------------------
function convertToHex(x)	
{
	if (x<0) x=0
	if (x>255) x=255
	st = '' + hx[Math.floor(x/16)] + hx[x%16]
	return st
}
//--------------------------------------------
// create a hexArray for other functions
//--------------------------------------------
function createHexArray()
{
	this.length = 16;
	for (var i=0;i<=9;i++) this[i] = i;
	this[10] = 'A';
	this[11] = 'B';
	this[12] = 'C';
	this[13] = 'D';
	this[14] = 'E';
	this[15] = 'F';
	return this;
}
hx = new createHexArray();




//================================================
// main
//================================================

function showTip(obj, thetext){
if (firsttime)
{
	document.onmousemove=positiontip;
	firsttime=false;
}
if (ns6||ie){
	if (thetext.length<100) {thewidth=180;} else {thewidth=240;}
	if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
	if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor

	caption = obj.innerText
	if (caption=='(*)' || caption==null || caption=='') caption='Ghi ch&#250;'
	tipobj.innerHTML = "<div style='font:11px Verdana;color:#404000;border:1px solid #0080FF;background-color:#E6F2FF;padding:1px;text-align:justify;width:"+thewidth+"'><div style='color:#FFFFFF;background-color:#0080FF;padding:3px 1px;width:"+(thewidth-4)+"px'>&#187; <b>"+caption+"</b></div><div style='padding:3px'>"+thetext+"</div></div>";
	enabletip=true
	return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideTip()
{
	if (!moz && !ie) return;
	enabletip=false;
	tipobj.style.visibility="hidden";
	tipobj.style.left="-1000px";
	tipobj.style.backgroundColor='';
	tipobj.style.width='';
}


/*
	Add mouse_move effects for images, tables
		- GRAY & ALPHA effects for images
		- HOVER effect for table's rows
		- TRANSIENT effect for links
*/
function hilightIt(obj)
{
	if (!ie && !moz) return;
	//if (!obj) return;
	if (obj.style.MozOpacity && obj.style.MozOpacity<1) 
	{
		obj.style.MozOpacity = obj.style.MozOpacity*1+0.1;
		hilighting=setTimeout('hilightIt(obj)', 50);
	}
	else if (obj.filters &&  obj.filters.alpha.opacity<100) 
	{
		obj.filters.alpha.opacity += 10;
		hilighting=setTimeout('hilightIt(obj)', 50);
	}
}
function jsetOpacity(obj, value)
{
	if (moz) obj.style.MozOpacity=value/100;
	else if (ie) obj.filters.alpha.opacity=value;
}
function jgetOpacity(obj, save)
{
	if (save)
	{
		if (moz) obj.myOp=obj.style.MozOpacity;
		else if (ie) obj.myOp=obj.filters.alpha.opacity;
	}
	else
	{
		if (moz) obj.style.MozOpacity=obj.myOp;
		else if (ie) obj.filters.alpha.opacity=obj.myOp;
	}
}


function slowhigh(which2){
	imgobj=which2
	jgetOpacity(imgobj, true);
	highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2){
	cleartimer()
	jgetOpacity(imgobj, false);
}


function cleartimer(){
	if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
	if (moz && cur2.style.MozOpacity<1)
	cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (ie && cur2.filters.alpha.opacity<100)
	cur2.filters.alpha.opacity+=10
	else if (window.highlighting)
	clearInterval(highlighting)
}


function visual_effects()
{
	var imgs = document.getElementsByTagName('IMG');
	for (var i=0; i<imgs.length; i++)
	{
		if (imgs[i].className=='gray')
		{
			jsetOpacity(imgs[i], 70);
			imgs[i].onmouseover = function() {if(ie)this.filters.gray.enabled=false;slowhigh(this);}
			imgs[i].onmouseout = function() {if(ie)this.filters.gray.enabled=true;slowlow(this);}
		}
		if (imgs[i].className=='alpha')
		{
			jsetOpacity(imgs[i], 40);
			imgs[i].onmouseover = function() {slowhigh(this);}
			imgs[i].onmouseout = function() {slowlow(this);}
		}
	}

	var hover = document.getElementsByTagName('TABLE');
	for (var j=0; j<hover.length; j++)
	{
		if (hover[j].getAttribute('hover')!='yes') {continue;}
		rows = hover[j].getElementsByTagName('TR');
		for (var i=0; i<rows.length; i++)
		{
			if (rows[i].getElementsByTagName('TD').length>0 && rows[i].getAttribute('hover')!='no')
			{
				rows[i].style.cursor = 'hand'
				rows[i].onmouseover = function() {setPointer(this, '#D0EAF4')}
				rows[i].onmouseout = function() {setPointer(this, '')}
				rows[i].onclick = function(e) {links = this.getElementsByTagName('A');if (links[0] && !(moz?e:event).shiftKey) {location=links[0].href;}}
			}
		}
	}

	var link = document.getElementsByTagName('A');
	for (var i=0; i<link.length; i++)
	{
		if (link[i].className=='transient')
		{
			link[i].onmouseover = function() {fade(this.uniqueID, 20, '#0000FF', '#FF0000')}
			link[i].onmouseout = function() {fade(this.uniqueID, 20, '#FF0000', '#0000FF')}
			link[i].style.color = '#0000FF';
		}
	}

	if (document.getElementById('maintext'))
	{
		var imgs = document.getElementById('maintext').getElementsByTagName('IMG');
		for (var i=0; i<imgs.length; i++) fixImg(imgs[i]);
	}
}

function newImg(img)
{
	//var iImg = img.cloneNode(true);
	var iImg = document.createElement('img');
	iImg.src = img.src;
	iImg.width = img.width;
	iImg.height = img.height;
	iImg.className = img.className;
	iImg.onclick = img.onclick;
	iImg.myWidth = img.myWidth;
	iImg.myHeight = img.myHeight;
	iImg.style.cursor = img.style.cursor;
	return iImg;
}
function fixImg(img)
{
	var resized = false;
	if ((img.width>180 || img.width>200) && (img.className=='floatLeft' || img.className=='floatRight'))
	{
		var sx = img.width/img.height;
		img.myWidth = img.width;
		img.myHeight = img.height;
		img.onclick = function() {openImage(this, img.myWidth, img.myHeight);}
		
		img.width = (img.width>180)? 180 : 200*ratio;
		img.heigth = img.width/sx;
		img.style.cursor = 'hand';
		resized = true;
	}
	if (img.title)
	{
		var tDiv = document.createElement('div');
		var tTable = document.createElement('table');
		var tPara = document.createElement('p');
		var tText = document.createTextNode(img.title);
		var tImg = newImg(img);
	
		tDiv.width = img.width;
		tDiv.className = img.className;
		
		tPara.appendChild(tText);
		tTable.width = tDiv.width;
		
		tRow = tTable.insertRow(0);
		tCell = tRow.insertCell(0);
		tCell.appendChild(tImg);
		tRow = tTable.insertRow(1);
		tCell = tRow.insertCell(0);
		tCell.appendChild(tPara);
	
		tDiv.appendChild(tTable);
		ie?img.replaceNode(tDiv) : img.appendChild(tDiv);
	}
}

var oldColor = new Array()
function setPointer(theRow, thePointerColor)
{
	if (!theRow.style) {return false}
	if (theRow.cells) {theCells = theRow.cells} else {return false}

	var rowCellsCnt  = theCells.length
	if (thePointerColor != '')
	{
		for (c = 0; c < rowCellsCnt; c++)
		{
			oldColor[c] = theCells[c].style.backgroundColor
			theCells[c].style.backgroundColor = thePointerColor
		}
	}
	else
	{
		for (c = 0; c < rowCellsCnt; c++)
		{
			theCells[c].style.backgroundColor = oldColor[c]
		}
	}
	return true
}

function resizePhoto(newWidth)
{
	if (newWidth=='') return;
	photo = document.getElementById('photo_img');
	if (!photo.wo)
	{
		photo.wo = photo.width;
		photo.ho = photo.height;
	}
	newWidth = eval(newWidth);
	photo.width = newWidth;
	photo.height = newWidth*photo.ho/photo.wo;
	document.body.focus();
}

startColor = "#0000FF"; // MouseOut link color 
endColor = "#FF6600"; // MouseOver link color 
stepIn = 20; // delay when fading in 
stepOut = 20; // delay when fading out 
startColor = dehexize(startColor.toUpperCase());
endColor = dehexize(endColor.toUpperCase());

function setColor(r, g, b, el) {el.style.color = "#"+convertToHex(r)+convertToHex(g)+convertToHex(b)} 
function fade(el, step, s, e)
{
	s = dehexize(s)
	e = dehexize(e)
	for (var i=0; i<=step; i++)
	{
		var ps = step-i
		var pe = i
		setTimeout('setColor(Math.floor('+(s[0]*ps/step+e[0]*pe/step)+'), Math.floor('+(s[1]*ps/step+e[1]*pe/step)+'), Math.floor('+(s[2]*ps/step+e[2]*pe/step)+'), '+el+')', i*step)
	} 
}

// Add a link to the left panel
function add_link(url, logo)
{
	if (document.getElementById('friend_links'))
	{
		document.getElementById('friend_links').innerHTML = document.getElementById('friend_links').innerHTML + '<a href="'+url+'" target="_blank"><img class="alpha" src="'+logo+'" alt="<<logo>>" style="border:0px;margin:3px;width:88px;height:31px"></a><br />'
	}
}


/*
	Make a gradient-color text like a rainbow
	I rewrote for more effect, 10/7/2000
*/
function make_rainbow(text,kind)
{
	k = text.length;
	mul = 255/k;
	for (var i=0;i<k;i++)
	{
		l = i;
		if (kind>=1) l=k-i;
		color_h1 = convertToHex(parseInt(255*Math.sin(l/(k/3))));
		color_h2 = convertToHex(parseInt(mul*l));
		k>l ? j=k-l : j=0;
		color_h3 = convertToHex(parseInt(mul*j));
		document.write("<font color=\"#"+color_h3+color_h1+color_h2+"\">"+text.substring(i,i+1)+"</font>");
	}
}

function disable_submit(frm)
{
	var inp=frm.childNodes;
	for (i=0; i<inp.length; i++)
	{
		if (inp[i].type)
		if (inp[i].type.toLowerCase=='submit')
		{
			inp[i].style.fontStyle = 'italic';
			inp[i].style.color = '#808080';
			inp[i].onclick = function() {return false;}
		}
	}
}


function noSpam (user, domain) 
{
	locationstring = "mailto:" + user + "@" + domain;
	if (arguments.length>2) locationstring = locationstring + '?subject='+arguments[2];
	window.location = locationstring;
}
// Open a window with url, name. Width w and height h
function popwin(url, name, w, h)
{
	if (!w) w=400
	if (!h) h=300
	return window.open(url, name, 'toolbar=no, menubar=no, scrollbars=yes, status=no, width='+w+', height='+h)
}
function start_capture()
{
	if (mx!=0) return;
	if (window.Event)
	{
		if (document.captureEvents)document.captureEvents(Event.MOUSEMOVE);
		else window.captureEvents(Event.MOUSEMOVE);
    }
	(ns6)?window.onmousemove=mcapture:document.onmousemove=mcapture;
}

function mcapture(e)
{
	my = (ns6)?e.pageY : event.y+document.body.scrollTop;
	mx = (ns6)?e.pageX : event.x+document.body.scrollLeft;
}
// Open a window whose content is which.value
function ex_show(which)
{
	w = window.open('', 'ex', 'width=350, height=400, toolbar=no, menubar=no, scrollbars=yes')
	w.document.write(which.value)
}
function ex_save(which)
{
	ex_show(which)
	w.document.execCommand("SaveAs", null, "example.html")
	w.close();
}

function do_vote(url)
{
	if (parseInt(navigator.appVersion)<5 && navigator.appVersion.indexOf["MSIE 5"]==-1) return;
	if (url=='') return;
	if (voteObj==false)
	{
		voteObj = document.createElement('div');
		document.body.appendChild(voteObj);
		voteObj.style.backgroundColor = '#F8F0FF';
		voteObj.style.position = 'absolute';
	}
	if (arguments.length==4)
	{
		_section = arguments[0];
		_post = arguments[1];
		_author = arguments[2];
		_poster = arguments[3];
		url = '/p/user/a-vote/sc-'+_section+'/at-'+_author+'/u-'+_poster+'/pt-'+_post+'/vote-zzz.htm';
	}
	
	text = '<table style="border:1px black solid;" border="1"><tr><td><span class="gensmall">';
	text += '<a href="'+url.replace(/zzz/, '0')+'">0 - '+J4Ulang.vote_0+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '1')+'">1 - '+J4Ulang.vote_1+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '2')+'">2 - '+J4Ulang.vote_2+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '3')+'">3 - '+J4Ulang.vote_3+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '4')+'">4 - '+J4Ulang.vote_4+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '5')+'">5 - '+J4Ulang.vote_5+'</a><br />';
	text += '<a href="'+url.replace(/zzz/, '6')+'">6 - '+J4Ulang.vote_6+'</a><br />';
	text += '</span></td></tr><tr><td align=center style="border-top:1px black solid" onMouseOver="voteObj.style.visibility=\'hidden\'"><span class="gensmall"><a href="javascript:void(0)" onclick="voteObj.style.visibility=\'hidden\'">'+J4Ulang.cancel+'</a></span></td></tr>';
	text += '</table>';
	voteObj.innerHTML = text;
	voteObj.style.top = (my-50)+"px";
	voteObj.style.left = (mx-80)+"px";
	voteObj.style.visibility="visible";
}

function showhide(oid)
{
	obj = document.getElementById(oid)
	if (! obj.style) return
	if (obj.style.display != 'none')
		obj.style.display = 'none'
	else
		obj.style.display = 'block'
}

function multi_page_jump(url_bit, pages, per_page, base, text)
{
	userPage = prompt("Chuyen den mot "+text+" khac (1-"+pages+"):", "1");
	if (userPage > 0)
	{
		if (userPage < 1)		{userPage = 1;}
		if (userPage > pages)	{userPage = pages;}
		self.location = url_bit.replace(/zzz/, ((userPage-1)*per_page+base));
	}
}
function addpage(url)
{
	page = window.prompt('Enter your page (music online) for this song', 'http://')
	if (page!=null && page!='http://')
	{
		singer = window.prompt('Enter singer for this url'+"\n"+page, '');
		document.getElementById('s_page').value = page;
		document.getElementById('s_singer').value = singer;
		document.getElementById('s_form').submit()
		// location = url.replace(/\.htm/, '/page-'+escape(page)+'/singer-'+singer+'.htm')
	}
}
function switch_url(url, param) {self.location = url.replace(/zzz/, param)}
function jump(url)
{
	if (url.match(/javascript:/i))
	{
		eval(url.replace(/javascript:/, ''));
		return false;
	}
	else if (url!='')
	{
		self.location = url;
	}
}

function showmenu_create(href, icon, text)
{
	var a=document.createElement('a');
	var d=document.createElement('div');
	var i=document.createElement('img');
	var t=document.createTextNode(text);
	a.setAttribute('href', href);
	i.setAttribute('src', icon);
	i.setAttribute('style', 'border:0px;align');
	d.appendChild(i);
	d.appendChild(t);
	a.appendChild(d);
	a.zIndex = -1;
	return a;
}

function showmenu(quickhelp)
{
	if (!document.getElementById) return;
	if (!document.getElementById('menu_quicklink'))
	{
		var o=document.createElement('div');
		o.setAttribute('id', 'menu_quicklink');
		document.getElementById('td_main').appendChild(o);

		o.appendChild(showmenu_create('/page/sitemap.htm', '/images/icons/web.gif', 'Site map'));
		o.appendChild(showmenu_create('/page/sitemap.htm', '/images/icons/web.gif', 'Site map'));
		o.appendChild(showmenu_create('/page/sitemap.htm', '/images/icons/web.gif', 'Site map'));
		o.onmouseout = function() {this.style.visibility='hidden';}
		o.style.width = '150px';
		o.style.border = '1px black solid';
		o.style.backgroundColor = '#808080';
		o.style.visibility = 'hidden';
		o.style.position = 'absolute';
	}

	var menuStyle=document.getElementById('menu_quicklink').style;
	menuStyle.left = (getposOffset(document.getElementById('td_main'), 'left')+627)+'px';
	menuStyle.top = (getposOffset(document.getElementById('td_main'), 'top')+1)+'px';
	menuStyle.visibility = 'visible';
}
function openImage(vLink, vWidth, vHeight)
{
	var sLink = (typeof(vLink.src)=='undefined') ? vLink : vLink.src;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>4u.jcisio</title><body style="margin:0px;overflow:hidden">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', 'Dong lai', '" style="border:0px"></a>');
	newwin.document.writeln('</body>');
	newwin.document.close();
}
