// JavaScript Document

function globe_preloadImages()
{
	MM_preloadImages(
		"/image/globe34_hover.png");
}
function local_onChangeSiteStyle(value, exuri, redir_url)
{
	uri = redir_url + "?locale=";
	uri += document.getElementById("site_lang").value;
	uri += "&style=" + value;
	uri += "&exuri=" + exuri;
	window.location = uri;
}

function local_onChangeSiteLang(value, exuri, redir_url)
{
	if(value != "none")
	{
		uri = redir_url + "?locale=";
		uri += value;
		uri += "&style=" + document.getElementById("site_style").value;
		uri += "&exuri=" + exuri;
		window.location = uri;
	}
}

base_registerBodyOnLoadCall("globe_preloadImages()");
var g_karaoke_search_on_change_control;
var g_karaoke_search_on_change_iframeid;
var g_karaoke_search_on_change_timeout = false;


// sumbit form
function search_submit_k01()
{
	var sform = document.forms.mainsearch;
	search_submit_k02(sform, 'search');
}

function search_submit_k02(sform, search_url)
{
	var url = search_url + "?";
	url += "querymod=" + sform.s.value;
	url += "&";
	url += "querytxt=" + sform.query.value;
	url += "&";
	var typea = new Array();
	if(sform.scp.checked)
		typea.push("p");
	if(sform.sct.checked)
		typea.push("t");
	if(sform.scl.checked)
		typea.push("l");
	type = typea.join(',');
	if(type == '')
		type = "p,t,l";
	url += "querytyp=" + type;
	window.location = url;
}

function karaoke_search_on_change(control, iframeid)
{
	if(!g_karaoke_search_on_change_timeout)
	{
		g_karaoke_search_on_change_timeout = true;
		g_karaoke_search_on_change_control = control;
		g_karaoke_search_on_change_iframeid = iframeid;
		setTimeout('karaoke_search_on_change_timeout()', '300');
	}
}
function karaoke_search_on_change_timeout()
{
	g_karaoke_search_on_change_timeout = false;
	control = g_karaoke_search_on_change_control;
	iframeid = g_karaoke_search_on_change_iframeid;
	
	iframe = document.getElementById(iframeid);
	query = control.value;
	if(query == "")
	{
		iframe.style.display = "none";
	}
	else
	{
		if(iframe.style.display == "none")
		{
			if (control != null && iframe != null)
			{
				var left = findPosX(control.offsetParent);
				var top = findPosY(control.offsetParent);
				top = top + 50;
				iframe.style.left = left + "px";
				iframe.style.top  = top + "px";
			}			
			iframe.style.display = "block";
		}
		iframe.src = "/search_assistant_iframe?query=" + query;
	}
}


// JavaScript Document

function asMOv(idx)
{
	if(idx != asid)
	{
		document.getElementById("as1"+idx).className = "as1-h as1";
		document.getElementById("as2"+idx).className = "as2-h as2";
		document.getElementById("as3"+idx).className = "as3-h as3";
	}
}
function asMOu(idx)
{
	if(idx == asid)
	{
		document.getElementById("as1"+idx).className = "as1 as1-sel";
		document.getElementById("as2"+idx).className = "as2 as2-sel";
		document.getElementById("as3"+idx).className = "as3 as3-sel";
	}
	else
	{
		document.getElementById("as1"+idx).className = "as1";
		document.getElementById("as2"+idx).className = "as2";
		document.getElementById("as3"+idx).className = "as3";
	}
}
function asMDo(idx)
{document.getElementById("as1"+idx).className = "as1-a as1-h as1";
document.getElementById("as2"+idx).className = "as2-a as2-h as2";
document.getElementById("as3"+idx).className = "as3-a as3-h as3";}
function asMUp(idx)
{document.getElementById("as1"+idx).className = "as1-h as1";
document.getElementById("as2"+idx).className = "as2-h as2";
document.getElementById("as3"+idx).className = "as3-h as3";}
function asLoad()
{idx=0; while(asLoadItem(idx)){idx++};}
function asLoadItem(idx)
{if(!asLoadSubItem("as1", idx, "as1")) return false;
if(!asLoadSubItem("as2", idx, "as2")) return false;
if(!asLoadSubItem("as3", idx, "as3")) return false;return true;}
function asLoadSubItem(prfx, idx, clName)
{elem = document.getElementById(""+prfx+idx); if(elem == null) return false;
elem.className = clName; return true;}
// JavaScript Document
var acctimea = new Array();
var gtra = new Array();

function music_imgsrc_array()
{
	var karaokeimgsrca = new Array();
	karaokeimgsrca['performer.ico.16']	= "p1n";
	karaokeimgsrca['song.ico.16'] 		= "s1n";
	karaokeimgsrca['open.ico.16'] 		= "sp1%";
	karaokeimgsrca['save.ico.16'] 		= "sd1%";
	karaokeimgsrca['lyrics.ico.16'] 		= "sl1%";
	karaokeimgsrca['chord.ico.16'] 		= "sc1%";
	karaokeimgsrca['info.ico.16'] 		= "si1%";
	karaokeimgsrca['fun.ico.16'] 			= "f1%";
	karaokeimgsrca['songexc.ico.16'] 	= "se1%";
	return karaokeimgsrca;
}


function tr_movr(ev, listid, line)
{
	elem = document.getElementById("tr-"+listid+"-"+line); if(elem == null) return false;
	if((line % 2) == 0)
	{
		elem.className = "item0-tr-over";
	}
	else
	{
		elem.className = "item1-tr-over";
	}
	elem.style.cursor = "pointer";
}
function tr_mout(ev, listid, line)
{
	elem = document.getElementById("tr-"+listid+"-"+line); if(elem == null) return false;
	if((line % 2) == 0)
	{
		elem.className = "item0-tr";
	}
	else
	{
		elem.className = "item1-tr";
	}
	elem.style.cursor = "auto";
}

	function list_onLoad()
	{
		karaokeimgsrca = music_imgsrc_array();
		for (var id in karaokeimgsrca)
		{
			MM_preloadImages(music_imgsrc(id, 'h'));
			MM_preloadImages(music_imgsrc(id, 'p'));
		}
		GMTtoLocal2(acctimea, "acctime");
		list_eventHand();
	}

	function img_MouseDown(prefix, index)
	{
		name = "" + prefix;
		name = name + "." + index;
		MM_swapImage(name, '',img_getPressImage(prefix),1);
	}

	function img_MouseOut()
	{
		MM_swapImgRestore();
//		self.status = "";
	}

	function img_MouseOver(prefix, index)
	{
		name = "" + prefix;
		name = name + "." + index;
		MM_swapImage(name, '',img_getHoverImage(prefix),1);
//		window.status = img_getStatusText(prefix);
	}

	function img_MouseUp(prefix, index)
	{
		name = "" + prefix;
		name = name + "." + index;
		MM_swapImage(name, '',img_getHoverImage(prefix),1);
	}
	
	function img_getHoverImage(prefix)
	{
		if(prefix == "saveImg")
			return music_imgsrc('save.ico.16', 'h'); 
		else if(prefix == "openImg")
			return music_imgsrc('open.ico.16', 'h'); 
		else if(prefix == "lyricsImg")
			return music_imgsrc('lyrics.ico.16', 'h'); 
		else if(prefix == "chordImg")
			return music_imgsrc('chord.ico.16', 'h'); 
		else if(prefix == "infoImg")
			return music_imgsrc('info.ico.16', 'h'); 
		else if(prefix == "funImg")
			return music_imgsrc('fun.ico.16', 'h'); 
		else if(prefix == "funNotImg")
			return music_imgsrc('funnot.ico.16', 'h'); 
		else if(prefix == "songExc")
			return music_imgsrc('songexc.ico.16', 'h'); 
	}

	function img_getPressImage(prefix)
	{
		if(prefix == "saveImg")
			return music_imgsrc('save.ico.16', 'p'); 
		else if(prefix == "openImg")
			return music_imgsrc('open.ico.16', 'p'); 
		else if(prefix == "lyricsImg")
			return music_imgsrc('lyrics.ico.16', 'p'); 
		else if(prefix == "chordImg")
			return music_imgsrc('chord.ico.16', 'p'); 
		else if(prefix == "infoImg")
			return music_imgsrc('info.ico.16', 'p'); 
		else if(prefix == "funImg")
			return music_imgsrc('fun.ico.16', 'p'); 
		else if(prefix == "funNotImg")
			return music_imgsrc('funnot.ico.16', 'p'); 
		else if(prefix == "songExc")
			return music_imgsrc('songexc.ico.16', 'p'); 
	}
	
	function img_getStatusText(prefix)
	{
		if(prefix == "saveImg")
			return statusbar_saveImg;
		else if(prefix == "openImg")
			return statusbar_openImg;
		else if(prefix == "lyrics")
			return statusbar_lyricsImg;
	}


   function _d(songid)
   {
		self.status = img_getStatusText("saveImg");
     	strurl = basekaraokescripturl;
		strurl = strurl + "/download.php";
		strurl = strurl + "?p_lang=" + p_lang;
		strurl = strurl + "&p_songid=" + songid;
      strurl = strurl + "&p_style=$p_style" + p_style;
		
      window.location.href = strurl;
   }

   function _o(songid)
   {
		self.status = img_getStatusText("openImg");
     	strurl = basekaraokescripturl;
		strurl = strurl + "/open.php";
		strurl = strurl + "?p_lang=" + p_lang;
		strurl = strurl + "&p_songid=" + songid;
      strurl = strurl + "&p_style=$p_style" + p_style;
		
      window.location.href = strurl;
   }

   function _o2(songid)
   {
     	strurl = basekaraokescripturl;
		strurl = strurl + "/open2.php";
		strurl = strurl + "?p_lang=" + p_lang;
		strurl = strurl + "&p_songid=" + songid;
      strurl = strurl + "&p_style=$p_style" + p_style;
      window.location.href = strurl;
   }

   function _fun(songid)
   {
		self.status = img_getStatusText("funImg");
		strurl = "";
//     	strurl = basekaraokescripturl;
		strurl = strurl + "/fun.php?";
		strurl = strurl + "r=ToggleFun";
//		strurl = strurl + "lang=" + gLang;
		strurl = strurl + "&songid=" + songid;
//      strurl = strurl + "&style=" + gStyle;
      strurl = strurl + "&ruri=" + gRuri;
		
      window.location.href = strurl;
   }

	function music_imgsrc(id)
	{
		a=music_imgsrc.arguments;
		if(a.length >= 2)
		{
			subtype = a[1];
		}
		else
		{
			subtype = "";
		}
		var imgsrc = music_imgsrc_array();
		var str = imgsrc[id];
		return "i?" +  str.replace("%", subtype);
	}
	
	
	
	function doc_onmouseover(e)
	{
		if (!e) var e = window.event;
		var element = e.target;
		if(!element)
			element = e.srcElement;
		var tr = null;
		if(element.nodeName == "IMG")
		{
			img_onmouseover(e, element);			
		}
		while(element){
			if(element.nodeName == "TR"){tr = element; break; }
				element = element.parentNode;	}
		if(tr)
		{
			if(tr.id.substr(0, 4) == "tr--")
			{
				i = tr.id.substr(4);
				tr_movr(e, "", i);
			}
		}
	}
	function doc_onmouseout(e)
	{
		if (!e) var e = window.event;
		var element = e.target;
		if(!element)
			element = e.srcElement;
		if(element.nodeName == "IMG")
		{
			img_onmouseout(e, element);			
		}
		var tr = null;
		while(element){
			if(element.nodeName == "TR"){tr = element; break; }
				element = element.parentNode;	}
		if(tr)
		{
			if(tr.id.substr(0, 4) == "tr--")
			{
				i = tr.id.substr(4);
				tr_mout(e, "", i);
			}
		}
	}
	function doc_onmousedown(e)
	{
		if (!e) var e = window.event;
		var element = e.target;
		if(!element)
			element = e.srcElement;
		var tr = null;
		if(element.nodeName == "IMG")
		{
			img_onmousedown(e, element);			
		}
		while(element){
			if(element.nodeName == "TR"){tr = element; break; }
				element = element.parentNode;	}
		if(tr)
		{
			if(tr.id.substr(0, 4) == "tr--")
			{
				i = tr.id.substr(4);
				tr_mdwn(e, "", i);
			}
		}
	}
	function doc_onmouseup(e)
	{
		if (!e) var e = window.event;
		var element = e.target;
		if(!element)
			element = e.srcElement;
		var tr = null;
		if(element.nodeName == "IMG")
		{
			img_onmouseup(e, element);			
		}
/*		while(element){
			if(element.nodeName == "TR"){tr = element; break; }
				element = element.parentNode;	}
		if(tr)
		{
			if(tr.id.substr(0, 4) == "tr--")
			{
				i = tr.id.substr(4);
				tr_mdwn(e, "", i);
			}
		}*/
	}

function img_onmouseover(e, element)
{
	var a = element.id.split(".");
	img_MouseOver(a[0], a[1]);
}

function img_onmouseout(e, element)
{
	var a = element.id.split(".");
	img_MouseOut(a[0], a[1]);
}

function img_onmousedown(e, element)
{
	var a = element.id.split(".");
	img_MouseDown(a[0], a[1]);
}

function img_onmouseup(e, element)
{
	var a = element.id.split(".");
	img_MouseUp(a[0], a[1]);
}


function list_eventHand()
{
	document.onmouseover 	= doc_onmouseover;
	document.onmouseout 		= doc_onmouseout;
	document.onmousedown		= doc_onmousedown;
	document.onmouseup		= doc_onmouseup;
	if(document.captureEvents) document.captureEvents(Event.MOUSEOVER);
	if(document.captureEvents) document.captureEvents(Event.MOUSEOUT);
	if(document.captureEvents) document.captureEvents(Event.MOUSEDOWN);
	if(document.captureEvents) document.captureEvents(Event.MOUSEUP);
}

function open_kar_file(file)
{
	if(parent.play_frame)
	{
		href = "/" + file;
		parent.play_frame.location.href = href;
	}
	else
	{
		thispage = window.location.href;
		window.location.href = thispage + "&frame_play=" + file;
	}
}

function tr_mdwn(ev, listid, line)
{
	if(mouse_isLeftButton(ev))
	{
		window.location.href=gtra[line];
	}
}


base_registerBodyOnLoadCall("list_onLoad()");
// JavaScript Document


var g_docsize;
var g_scrolly = 0;
var g_ytimeout = 100;

function autoscroll_onLoad()
{
	g_docsize = new lib_doc_size();
	var autoscrollbox = document.getElementById('LayerAutoScrollActiveBox');
	if(autoscrollbox)
	{
		autoscrollbox.style.left = g_docsize.frameW - autoscrollbox.offsetWidth - 20;
		autoscrollbox.style.top = g_scrolly + g_docsize.frameH - autoscrollbox.offsetHeight - 20;
	}
}
	
function autoscroll_start()
{
	totalW = document.body.offsetWidth - 20;
	totalH = document.body.offsetHeight - 5;
	g_scrolly = getYScroll();
	var autoscrollstart = document.getElementById('AutoScrollStart');
	autoscrollstart.style.display = "none";
	var autoscrollstop = document.getElementById('AutoScrollStop');
	autoscrollstop.style.display = "inline";
	var autoscrollbox = document.getElementById('LayerAutoScrollActiveBox');
	autoscrollbox.style.left = g_docsize.frameW - autoscrollbox.offsetWidth - 20 + "px";
	autoscrollbox.style.top = g_scrolly + g_docsize.frameH - autoscrollbox.offsetHeight - 20 + "px";
	autoscrollbox.style.display = "block";
	autoscrollbox.style.position = "absolute";
	autoscrollbox.style.position = "absolute";
	autoscrollbox.style.zIndex = 99;
	autoscroll_step();
}


function autoscroll_step()
{
	if(g_scrolly < 0)
		return;
	g_scrolly = getYScroll();
	g_scrolly++;
	scroll(0, g_scrolly);
	if(g_scrolly < (g_docsize.y2 - g_docsize.frameH - 30) )
	{
		setTimeout('autoscroll_step()', g_ytimeout);
	}
	else
	{
		autoscroll_stop();
	}
	var autoscrollbox = document.getElementById('LayerAutoScrollActiveBox');
	autoscrollbox.style.left = g_docsize.frameW - autoscrollbox.offsetWidth - 20 + "px";
	autoscrollbox.style.top = g_scrolly + g_docsize.frameH - autoscrollbox.offsetHeight - 20 + "px";
}

function autoscroll_stop()
{
	var autoscrollbox = document.getElementById('LayerAutoScrollActiveBox');
	autoscrollbox.style.display = "none";
	var autoscrollstart = document.getElementById('AutoScrollStart');
	autoscrollstart.style.display = "inline";
	var autoscrollstop = document.getElementById('AutoScrollStop');
	autoscrollstop.style.display = "none";
	
	g_scrolly = -1;
}
	
function autoscroll_setvelocity(velocity)
{
	if(velocity > 1000)
	{
		alert("Velocity cannot be greater than 1000");
	}
	else if(velocity < 1)
	{
		alert("Velocity cannot be lesser than 1");
	}
	else if(velocity >= 1 && velocity <= 1000)
	{
		g_ytimeout = 10000 / velocity;
	}
	else
	{
		alert("Velocity must be a numeric value between 1 and 1000");
	}
}

function getXScroll() {return (document.all)?document.body.scrollLeft:window.pageXOffset;}
function getYScroll() {return (document.all)?document.body.scrollTop:window.pageYOffset;}


base_registerBodyOnLoadCall("autoscroll_onLoad()");
/* super karlib.js */

