/////////// GENERAL OBJECT /////////////////////////////
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
if (document.layers) { // Netscape
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
	document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
	document.onmousemove = captureMousePosition;
}
function CloneObject(obj){
	if(obj == null || typeof(obj) != 'object') return obj;

	if(obj.constructor == Array) {
			var temp = [];
			for(var i = 0; i < obj.length; i++) {
					if(typeof(obj[i]) == 'object')   temp.push(CloneObject(obj[i]));
					else temp.push(obj[i]);
			}
			return temp;
	}
	var temp = {};
	for(var key in obj) temp[key] = CloneObject(obj[key]);
	return temp;
}
function captureMousePosition(e) {
	var dc; //DRAG CONTAINER
	var ddiv; //DRAG HELPER DIV
	var activeCont = undefined; //STORES THE ACTIVE CONTAINER DIV
	
	ev = e || window.event;

	if (ev.pageX || ev.pageY) {
		xMousePos = ev.pageX;
		yMousePos = ev.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;		
	
	} else {
		xMousePos = ev.x+document.body.scrollLeft;
		yMousePos = ev.y+document.body.scrollTop;
		xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight+document.body.scrollTop;		
	}

	if (tr != undefined) {
		switch (tr.dragMode) {
			case 'vid':	
				deselect();	
				tr.vidMouseMove(tr.dragId);
				break;
				
			case 'pl':	
				deselect();	
				tr.plMouseMove(tr.dragId);
				break;	
				
			case 'pls':	
				deselect();	
				tr.plsMouseMove(tr.dragId);
				break;	
				
		}
	}
	
	return false;
	
}
function deselect () {
  if (document.selection)
    document.selection.empty();
  else if (window.getSelection)
    window.getSelection().removeAllRanges();
}
function g(obj) {
	var temp;
	temp = eval("document.all." + obj)
	if (temp == undefined) {
		temp = eval("document." + obj)
		if (temp == undefined) {
			temp = eval("document.getElementById('" + obj + "')")
		}
	}	
	return temp;
}	
function getBrowser () {
	var browser = navigator.userAgent.toLowerCase();
	
	if (browser.indexOf('msie') != -1) {browser = 'ie'};
	if (browser.indexOf('firefox') != -1) {browser = 'ff'};
	if (browser.indexOf('safari') != -1) {browser = 'sa'};
	if (browser.indexOf('opera') != -1) {browser = 'op'};
	
	return browser;
}	
function getClientSize () {
	var c = new Object();
	
	if (typeof(window.innerWidth) == 'number') {
		c.width = window.innerWidth+window.pageXOffset;
		c.height = window.innerHeight+window.pageYOffset;
	} else {
		c.width = document.body.clientWidth+document.body.scrollLeft;
		c.height = document.body.clientHeight+document.body.scrollTop;		
	}
	
	return c;
}
function decodeEmailText (str) {
var out = '';
var ccode;
	for (var i=0;i<str.length;i++) {
		ccode = str.charCodeAt(i) - 1
		out += String.fromCharCode(ccode);
	}	
	out = '<a href="mailto:' + out + '" class="slink" >' + out + '</a>';		
	document.write(out);
}
function HtmlDecode(s) {
	var out = "";

	if (s==null) return;
  
	var l = s.length;

	for (var i=0; i<l; i++)  {

		var ch = s.charAt(i);

		if (ch == '&') {

			  var semicolonIndex = s.indexOf(';', i+1);

		if (semicolonIndex > 0) {

					var entity = s.substring(i + 1, semicolonIndex);

					if (entity.length > 1 && entity.charAt(0) == '#')

					{

						  if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')

								ch = String.fromCharCode(eval('0'+entity.substring(1)));

						  else

								ch = String.fromCharCode(eval(entity.substring(1)));

					}

				else

				  {

						  switch (entity)

						  {

								case 'quot': ch = String.fromCharCode(0x0022); break;

								case 'amp': ch = String.fromCharCode(0x0026); break;

								case 'lt': ch = String.fromCharCode(0x003c); break;

								case 'gt': ch = String.fromCharCode(0x003e); break;

								case 'nbsp': ch = String.fromCharCode(0x00a0); break;

								case 'iexcl': ch = String.fromCharCode(0x00a1); break;

								case 'cent': ch = String.fromCharCode(0x00a2); break;

								case 'pound': ch = String.fromCharCode(0x00a3); break;

								case 'curren': ch = String.fromCharCode(0x00a4); break;

								case 'yen': ch = String.fromCharCode(0x00a5); break;

								case 'brvbar': ch = String.fromCharCode(0x00a6); break;

								case 'sect': ch = String.fromCharCode(0x00a7); break;

								case 'uml': ch = String.fromCharCode(0x00a8); break;

								case 'copy': ch = String.fromCharCode(0x00a9); break;

								case 'ordf': ch = String.fromCharCode(0x00aa); break;

								case 'laquo': ch = String.fromCharCode(0x00ab); break;

								case 'not': ch = String.fromCharCode(0x00ac); break;

								case 'shy': ch = String.fromCharCode(0x00ad); break;

								case 'reg': ch = String.fromCharCode(0x00ae); break;

								case 'macr': ch = String.fromCharCode(0x00af); break;

								case 'deg': ch = String.fromCharCode(0x00b0); break;

								case 'plusmn': ch = String.fromCharCode(0x00b1); break;

								case 'sup2': ch = String.fromCharCode(0x00b2); break;

								case 'sup3': ch = String.fromCharCode(0x00b3); break;

								case 'acute': ch = String.fromCharCode(0x00b4); break;

								case 'micro': ch = String.fromCharCode(0x00b5); break;

								case 'para': ch = String.fromCharCode(0x00b6); break;

								case 'middot': ch = String.fromCharCode(0x00b7); break;

								case 'cedil': ch = String.fromCharCode(0x00b8); break;

								case 'sup1': ch = String.fromCharCode(0x00b9); break;

								case 'ordm': ch = String.fromCharCode(0x00ba); break;

								case 'raquo': ch = String.fromCharCode(0x00bb); break;

								case 'frac14': ch = String.fromCharCode(0x00bc); break;

								case 'frac12': ch = String.fromCharCode(0x00bd); break;

								case 'frac34': ch = String.fromCharCode(0x00be); break;

								case 'iquest': ch = String.fromCharCode(0x00bf); break;

								case 'Agrave': ch = String.fromCharCode(0x00c0); break;

								case 'Aacute': ch = String.fromCharCode(0x00c1); break;

								case 'Acirc': ch = String.fromCharCode(0x00c2); break;

								case 'Atilde': ch = String.fromCharCode(0x00c3); break;

								case 'Auml': ch = String.fromCharCode(0x00c4); break;

								case 'Aring': ch = String.fromCharCode(0x00c5); break;

								case 'AElig': ch = String.fromCharCode(0x00c6); break;

								case 'Ccedil': ch = String.fromCharCode(0x00c7); break;

								case 'Egrave': ch = String.fromCharCode(0x00c8); break;

								case 'Eacute': ch = String.fromCharCode(0x00c9); break;

								case 'Ecirc': ch = String.fromCharCode(0x00ca); break;

								case 'Euml': ch = String.fromCharCode(0x00cb); break;

								case 'Igrave': ch = String.fromCharCode(0x00cc); break;

								case 'Iacute': ch = String.fromCharCode(0x00cd); break;

								case 'Icirc': ch = String.fromCharCode(0x00ce ); break;

								case 'Iuml': ch = String.fromCharCode(0x00cf); break;

								case 'ETH': ch = String.fromCharCode(0x00d0); break;

								case 'Ntilde': ch = String.fromCharCode(0x00d1); break;

								case 'Ograve': ch = String.fromCharCode(0x00d2); break;

								case 'Oacute': ch = String.fromCharCode(0x00d3); break;

								case 'Ocirc': ch = String.fromCharCode(0x00d4); break;

								case 'Otilde': ch = String.fromCharCode(0x00d5); break;

								case 'Ouml': ch = String.fromCharCode(0x00d6); break;

								case 'times': ch = String.fromCharCode(0x00d7); break;

								case 'Oslash': ch = String.fromCharCode(0x00d8); break;

								case 'Ugrave': ch = String.fromCharCode(0x00d9); break;

								case 'Uacute': ch = String.fromCharCode(0x00da); break;

								case 'Ucirc': ch = String.fromCharCode(0x00db); break;

								case 'Uuml': ch = String.fromCharCode(0x00dc); break;

								case 'Yacute': ch = String.fromCharCode(0x00dd); break;

								case 'THORN': ch = String.fromCharCode(0x00de); break;

								case 'szlig': ch = String.fromCharCode(0x00df); break;

								case 'agrave': ch = String.fromCharCode(0x00e0); break;

								case 'aacute': ch = String.fromCharCode(0x00e1); break;

								case 'acirc': ch = String.fromCharCode(0x00e2); break;

								case 'atilde': ch = String.fromCharCode(0x00e3); break;

								case 'auml': ch = String.fromCharCode(0x00e4); break;

								case 'aring': ch = String.fromCharCode(0x00e5); break;

								case 'aelig': ch = String.fromCharCode(0x00e6); break;

								case 'ccedil': ch = String.fromCharCode(0x00e7); break;

								case 'egrave': ch = String.fromCharCode(0x00e8); break;

								case 'eacute': ch = String.fromCharCode(0x00e9); break;

								case 'ecirc': ch = String.fromCharCode(0x00ea); break;

								case 'euml': ch = String.fromCharCode(0x00eb); break;

								case 'igrave': ch = String.fromCharCode(0x00ec); break;

								case 'iacute': ch = String.fromCharCode(0x00ed); break;

								case 'icirc': ch = String.fromCharCode(0x00ee); break;

								case 'iuml': ch = String.fromCharCode(0x00ef); break;

								case 'eth': ch = String.fromCharCode(0x00f0); break;

								case 'ntilde': ch = String.fromCharCode(0x00f1); break;

								case 'ograve': ch = String.fromCharCode(0x00f2); break;

								case 'oacute': ch = String.fromCharCode(0x00f3); break;

								case 'ocirc': ch = String.fromCharCode(0x00f4); break;

								case 'otilde': ch = String.fromCharCode(0x00f5); break;

								case 'ouml': ch = String.fromCharCode(0x00f6); break;

								case 'divide': ch = String.fromCharCode(0x00f7); break;

								case 'oslash': ch = String.fromCharCode(0x00f8); break;

								case 'ugrave': ch = String.fromCharCode(0x00f9); break;

								case 'uacute': ch = String.fromCharCode(0x00fa); break;

								case 'ucirc': ch = String.fromCharCode(0x00fb); break;

								case 'uuml': ch = String.fromCharCode(0x00fc); break;

								case 'yacute': ch = String.fromCharCode(0x00fd); break;

								case 'thorn': ch = String.fromCharCode(0x00fe); break;

								case 'yuml': ch = String.fromCharCode(0x00ff); break;

								case 'OElig': ch = String.fromCharCode(0x0152); break;

								case 'oelig': ch = String.fromCharCode(0x0153); break;

								case 'Scaron': ch = String.fromCharCode(0x0160); break;

								case 'scaron': ch = String.fromCharCode(0x0161); break;

								case 'Yuml': ch = String.fromCharCode(0x0178); break;

								case 'fnof': ch = String.fromCharCode(0x0192); break;

								case 'circ': ch = String.fromCharCode(0x02c6); break;

								case 'tilde': ch = String.fromCharCode(0x02dc); break;

								case 'Alpha': ch = String.fromCharCode(0x0391); break;

								case 'Beta': ch = String.fromCharCode(0x0392); break;

								case 'Gamma': ch = String.fromCharCode(0x0393); break;

								case 'Delta': ch = String.fromCharCode(0x0394); break;

								case 'Epsilon': ch = String.fromCharCode(0x0395); break;

								case 'Zeta': ch = String.fromCharCode(0x0396); break;

								case 'Eta': ch = String.fromCharCode(0x0397); break;

								case 'Theta': ch = String.fromCharCode(0x0398); break;

								case 'Iota': ch = String.fromCharCode(0x0399); break;

								case 'Kappa': ch = String.fromCharCode(0x039a); break;

								case 'Lambda': ch = String.fromCharCode(0x039b); break;

								case 'Mu': ch = String.fromCharCode(0x039c); break;

								case 'Nu': ch = String.fromCharCode(0x039d); break;

								case 'Xi': ch = String.fromCharCode(0x039e); break;

								case 'Omicron': ch = String.fromCharCode(0x039f); break;

								case 'Pi': ch = String.fromCharCode(0x03a0); break;

								case ' Rho ': ch = String.fromCharCode(0x03a1); break;

								case 'Sigma': ch = String.fromCharCode(0x03a3); break;

								case 'Tau': ch = String.fromCharCode(0x03a4); break;

								case 'Upsilon': ch = String.fromCharCode(0x03a5); break;

								case 'Phi': ch = String.fromCharCode(0x03a6); break;

								case 'Chi': ch = String.fromCharCode(0x03a7); break;

								case 'Psi': ch = String.fromCharCode(0x03a8); break;

								case 'Omega': ch = String.fromCharCode(0x03a9); break;

								case 'alpha': ch = String.fromCharCode(0x03b1); break;

								case 'beta': ch = String.fromCharCode(0x03b2); break;

								case 'gamma': ch = String.fromCharCode(0x03b3); break;

								case 'delta': ch = String.fromCharCode(0x03b4); break;

								case 'epsilon': ch = String.fromCharCode(0x03b5); break;

								case 'zeta': ch = String.fromCharCode(0x03b6); break;

								case 'eta': ch = String.fromCharCode(0x03b7); break;

								case 'theta': ch = String.fromCharCode(0x03b8); break;

								case 'iota': ch = String.fromCharCode(0x03b9); break;

								case 'kappa': ch = String.fromCharCode(0x03ba); break;

								case 'lambda': ch = String.fromCharCode(0x03bb); break;

								case 'mu': ch = String.fromCharCode(0x03bc); break;

								case 'nu': ch = String.fromCharCode(0x03bd); break;

								case 'xi': ch = String.fromCharCode(0x03be); break;

								case 'omicron': ch = String.fromCharCode(0x03bf); break;

								case 'pi': ch = String.fromCharCode(0x03c0); break;

								case 'rho': ch = String.fromCharCode(0x03c1); break;

								case 'sigmaf': ch = String.fromCharCode(0x03c2); break;

								case 'sigma': ch = String.fromCharCode(0x03c3); break;

								case 'tau': ch = String.fromCharCode(0x03c4); break;

								case 'upsilon': ch = String.fromCharCode(0x03c5); break;

								case 'phi': ch = String.fromCharCode(0x03c6); break;

								case 'chi': ch = String.fromCharCode(0x03c7); break;

								case 'psi': ch = String.fromCharCode(0x03c8); break;

								case 'omega': ch = String.fromCharCode(0x03c9); break;

								case 'thetasym': ch = String.fromCharCode(0x03d1); break;

								case 'upsih': ch = String.fromCharCode(0x03d2); break;

								case 'piv': ch = String.fromCharCode(0x03d6); break;

								case 'ensp': ch = String.fromCharCode(0x2002); break;

								case 'emsp': ch = String.fromCharCode(0x2003); break;

								case 'thinsp': ch = String.fromCharCode(0x2009); break;

								case 'zwnj': ch = String.fromCharCode(0x200c); break;

								case 'zwj': ch = String.fromCharCode(0x200d); break;

								case 'lrm': ch = String.fromCharCode(0x200e); break;

								case 'rlm': ch = String.fromCharCode(0x200f); break;

								case 'ndash': ch = String.fromCharCode(0x2013); break;

								case 'mdash': ch = String.fromCharCode(0x2014); break;

								case 'lsquo': ch = String.fromCharCode(0x2018); break;

								case 'rsquo': ch = String.fromCharCode(0x2019); break;

								case 'sbquo': ch = String.fromCharCode(0x201a); break;

								case 'ldquo': ch = String.fromCharCode(0x201c); break;

								case 'rdquo': ch = String.fromCharCode(0x201d); break;

								case 'bdquo': ch = String.fromCharCode(0x201e); break;

								case 'dagger': ch = String.fromCharCode(0x2020); break;

								case 'Dagger': ch = String.fromCharCode(0x2021); break;

								case 'bull': ch = String.fromCharCode(0x2022); break;

								case 'hellip': ch = String.fromCharCode(0x2026); break;

								case 'permil': ch = String.fromCharCode(0x2030); break;

								case 'prime': ch = String.fromCharCode(0x2032); break;

								case 'Prime': ch = String.fromCharCode(0x2033); break;

								case 'lsaquo': ch = String.fromCharCode(0x2039); break;

								case 'rsaquo': ch = String.fromCharCode(0x203a); break;

								case 'oline': ch = String.fromCharCode(0x203e); break;

								case 'frasl': ch = String.fromCharCode(0x2044); break;

								case 'euro': ch = String.fromCharCode(0x20ac); break;

								case 'image': ch = String.fromCharCode(0x2111); break;

								case 'weierp': ch = String.fromCharCode(0x2118); break;

								case 'real': ch = String.fromCharCode(0x211c); break;

								case 'trade': ch = String.fromCharCode(0x2122); break;

								case 'alefsym': ch = String.fromCharCode(0x2135); break;

								case 'larr': ch = String.fromCharCode(0x2190); break;

								case 'uarr': ch = String.fromCharCode(0x2191); break;

								case 'rarr': ch = String.fromCharCode(0x2192); break;

								case 'darr': ch = String.fromCharCode(0x2193); break;

								case 'harr': ch = String.fromCharCode(0x2194); break;

								case 'crarr': ch = String.fromCharCode(0x21b5); break;

								case 'lArr': ch = String.fromCharCode(0x21d0); break;

								case 'uArr': ch = String.fromCharCode(0x21d1); break;

								case 'rArr': ch = String.fromCharCode(0x21d2); break;

								case 'dArr': ch = String.fromCharCode(0x21d3); break;

								case 'hArr': ch = String.fromCharCode(0x21d4); break;

								case 'forall': ch = String.fromCharCode(0x2200); break;

								case 'part': ch = String.fromCharCode(0x2202); break;

								case 'exist': ch = String.fromCharCode(0x2203); break;

								case 'empty': ch = String.fromCharCode(0x2205); break;

								case 'nabla': ch = String.fromCharCode(0x2207); break;

								case 'isin': ch = String.fromCharCode(0x2208); break;

								case 'notin': ch = String.fromCharCode(0x2209); break;

								case 'ni': ch = String.fromCharCode(0x220b); break;

								case 'prod': ch = String.fromCharCode(0x220f); break;

								case 'sum': ch = String.fromCharCode(0x2211); break;

								case 'minus': ch = String.fromCharCode(0x2212); break;

								case 'lowast': ch = String.fromCharCode(0x2217); break;

								case 'radic': ch = String.fromCharCode(0x221a); break;

								case 'prop': ch = String.fromCharCode(0x221d); break;

								case 'infin': ch = String.fromCharCode(0x221e); break;

								case 'ang': ch = String.fromCharCode(0x2220); break;

								case 'and': ch = String.fromCharCode(0x2227); break;

								case 'or': ch = String.fromCharCode(0x2228); break;

								case 'cap': ch = String.fromCharCode(0x2229); break;

								case 'cup': ch = String.fromCharCode(0x222a); break;

								case 'int': ch = String.fromCharCode(0x222b); break;

								case 'there4': ch = String.fromCharCode(0x2234); break;

								case 'sim': ch = String.fromCharCode(0x223c); break;

								case 'cong': ch = String.fromCharCode(0x2245); break;

								case 'asymp': ch = String.fromCharCode(0x2248); break;

								case 'ne': ch = String.fromCharCode(0x2260); break;

								case 'equiv': ch = String.fromCharCode(0x2261); break;

								case 'le': ch = String.fromCharCode(0x2264); break;

								case 'ge': ch = String.fromCharCode(0x2265); break;

								case 'sub': ch = String.fromCharCode(0x2282); break;

								case 'sup': ch = String.fromCharCode(0x2283); break;

								case 'nsub': ch = String.fromCharCode(0x2284); break;

								case 'sube': ch = String.fromCharCode(0x2286); break;

								case 'supe': ch = String.fromCharCode(0x2287); break;

								case 'oplus': ch = String.fromCharCode(0x2295); break;

								case 'otimes': ch = String.fromCharCode(0x2297); break;

								case 'perp': ch = String.fromCharCode(0x22a5); break;

								case 'sdot': ch = String.fromCharCode(0x22c5); break;

								case 'lceil': ch = String.fromCharCode(0x2308); break;

								case 'rceil': ch = String.fromCharCode(0x2309); break;

								case 'lfloor': ch = String.fromCharCode(0x230a); break;

								case 'rfloor': ch = String.fromCharCode(0x230b); break;

								case 'lang': ch = String.fromCharCode(0x2329); break;

								case 'rang': ch = String.fromCharCode(0x232a); break;

								case 'loz': ch = String.fromCharCode(0x25ca); break;

								case 'spades': ch = String.fromCharCode(0x2660); break;

								case 'clubs': ch = String.fromCharCode(0x2663); break;

								case 'hearts': ch = String.fromCharCode(0x2665); break;

								case 'diams': ch = String.fromCharCode(0x2666); break;

								default: ch = ''; break;

						  }

					}
					i = semicolonIndex;
			  }
		}
		out += ch;
  }
  return out;
}
function encodeUTF8(s) {
  return unescape(encodeURIComponent(s));
}
function decodeUTF8(s) {
	try {
		return decodeURIComponent(escape(s));
	} catch (err) {
		return s;
	}
}
function brief (str, l) {
var temp = '';

	if (str.length > l) {
		temp = str.slice(0,l-3) + '...';
	} else {
		temp = str.slice(0,l);
	}

	return temp;
}
function openWindow(url) {
	var screenwidth = window.screen.availWidth-10;
	var screenheight = window.screen.availHeight-50;
	var screenleft=(screen.width/2)-75;
	var screentop=(screen.height/2)-150;
	var params = 'left=' + screenleft + ',top=' + screentop + ',width=640,height=480,toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resize=yes,resizable=yes';
	var wind=window.open(url,'generalwindow',params);
}	
function copyToClipboard(str) {
	g('holdtext').innerText = str;
	Copied = g('holdtext').createTextRange();
	Copied.execCommand("Copy");
}
function centerDiv (dWidth) {
	var c = getClientSize();
	var l = (c.width / 2) - (dWidth / 2);					
	return l;
}	
function showFInfo(str) {
	if (str.length > 0 ) {
		var posx =(parseInt(xMousePos) + 50);		
		if ((posx+tr.references.get('finfo').offsetWidth) >= xMousePosMax) {
			posx = (xMousePosMax - tr.references.get('finfo').offsetWidth);				
		}	
		tr.references.get('finfo').style.top = (parseInt(yMousePos) + 10) + 'px';
		tr.references.get('finfo').style.left = posx + 'px';
		tr.references.get('finfo').innerHTML = str;
		tr.references.get('finfo').style.display = 'block';
	} else {
		tr.references.get('finfo').style.display = 'none';
	}
}
function hideFInfo () {
	tr.references.get('finfo').style.display = 'none';
}	
function showInfo(str) {
	if (str.length > 0 ) {
		tr.references.get('hinfo').innerHTML = str;
		tr.references.get('hinfo').style.top = (parseInt(yMousePos) + 25) + 'px';
		tr.references.get('hinfo').style.left = (parseInt(xMousePos) - 50) + 'px';
		tr.references.get('hinfo').style.display = 'block';		
	} else {
		tr.references.get('hinfo').style.display = 'none';
	}
}
function hideInfo () {
	tr.references.get('hinfo').style.display = 'none';
}	
function removeRow(id) {
  var tr = g(id);
	if (tr) {
		if (tr.nodeName == 'TR') {
			var tbl = tr; // Look up the hierarchy for TABLE
			while (tbl != document && tbl.nodeName != 'TABLE') {
				tbl = tbl.parentNode;
			}
			if (tbl && tbl.nodeName == 'TABLE') {
				while (tr.hasChildNodes()) {
					tr.removeChild( tr.lastChild );
				}
				tr.parentNode.removeChild( tr );
			}
		} else {
			alert( 'Specified document element is not a TR. id=' + id );
		}
	} else {
		alert( 'Specified document element is not found. id=' + id );
	}
}		
function resizeClient () {
	var c = getClientSize();
	
	switch (tr.browseMode) {
		case 'content':
			switch (browser) {
				case 'ff':
				case 'sa':
				case 'op':		
				case 'ie':
					tr.references.get('contentdiv').style.height = (c.height - 73) + 'px';	
					tr.references.get('content').style.height = (c.height - 73) + 'px';	
					tr.references.get('contentdiv').style.width = (c.width) + 'px';	
					tr.references.get('content').style.width = (c.width) + 'px';	
			}
			tr.tabgroup.ensureVisible(tr.tabgroup.curTab);
			
			break;
	
		default:
			switch (browser) {
				case 'ff':
				case 'sa':
				case 'op':
				case 'ie':
					var h = c.height - 282;
					if (h < 0) {h=1};
					tr.references.get('playlists').style.height = h + 'px';

					if (tr.references.get('nlin') != null) {			
						var gridHeight = c.height - 360;
						if (gridHeight < 0) {gridHeight = 1};
						var discGridHeight = gridHeight + 17 + 'px';
						gridHeight += 'px';
						
					} else {					
						var gridHeight = c.height - 343;
						if (gridHeight < 0) {gridHeight = 1};
						var discGridHeight = gridHeight + 17 + 'px';
						gridHeight += 'px';
					}				

					tr.references.get('playgriddiv').style.height = gridHeight;
					tr.references.get('youtubediv').style.height = gridHeight;
					tr.references.get('discdiv').style.height = discGridHeight;				
					tr.references.get('publicdiv').style.height = gridHeight;

					break;
			}		
			
			//IF THE TABWAIT DIV IS SHOWING (DATA IS LOADING) THEN RESIZE IT
			if (tr.references.get('tabwait').style.display=='block') {
				tr.references.get('tabwait').style.width=tr.references.get('trackinfo').offsetWidth + 'px';
				tr.references.get('tabwait').style.height=tr.references.get('trackinfo').offsetHeight + 'px';	
			}
				
				
			switch (tr.mode) {
				case "playlist":
					//RESIZE THE COLUMN HEADERS TO THE COLUMN SIZES		
					switch (browser) {
						case 'ff':
						case 'sa':
						case 'op':
						case 'ie':
							
							var ttl = tr.references.get('playgriddiv').offsetWidth - 18 - 65 - 4;

							var col1 = Math.round((ttl / 100) * 40);
							var col2 = Math.round((ttl / 100) * 30);
							var col3 = Math.round((ttl / 100) * 30);

							tr.references.get('col1').style.width = col1 + 'px';
							tr.references.get('col2').style.width = col2 + 'px';
							tr.references.get('col3').style.width = col3 + 'px';
							tr.references.get('col4').style.width = '65px';

							g('tcol2').style.width = (col1 - 21) + 'px';
							g('tcol3').style.width = col2 + 'px';
							g('tcol4').style.width = col3 + 'px';

							break;
					}
							
					break;
				
				case "youtube":
					if (tr.youtuberesults.count > 0) {
				
						//RESIZE THE COLUMN HEADERS TO THE COLUMN SIZES
						switch (browser) {
							case 'ff':
							case 'sa':
							case 'op':
								tr.references.get('ycol2').style.width = tr.references.get('ytc2').offsetWidth + 'px';
								tr.references.get('ycol3').style.width = tr.references.get('ytc3').offsetWidth + 'px';
								
								break;
						}			
					}
					
					break;
					
				case "publicsearch":			
					if (tr.references.get('pubc2') != null) {
						//RESIZE THE COLUMN HEADERS TO THE COLUMN SIZES
						switch (browser) {
							case 'ff':
							case 'sa':
							case 'op':
								tr.references.get('pubcol2').style.width = tr.references.get('pubc2').offsetWidth + 'px';
								tr.references.get('pubcol3').style.width = tr.references.get('pubc3').offsetWidth + 'px';
								tr.references.get('pubcol4').style.width = tr.references.get('pubc4').offsetWidth + 'px';
								tr.references.get('pubcol5').style.width = tr.references.get('pubc5').offsetWidth + 'px';
								
								break;
						}			

					}
					break;
					
				case "publicplaylist":
					//RESIZE THE COLUMN HEADERS TO THE COLUMN SIZES		
					switch (browser) {
						case 'ff':
						case 'sa':
						case 'op':
						case 'ie':
							
							var ttl = tr.references.get('playgriddiv').offsetWidth - 18 - 48 - 4;

							var col1 = Math.round((ttl / 100) * 40);
							var col2 = Math.round((ttl / 100) * 30);
							var col3 = Math.round((ttl / 100) * 30);

							tr.references.get('col1').style.width = col1 + 'px';
							tr.references.get('col2').style.width = col2 + 'px';
							tr.references.get('col3').style.width = col3 + 'px';
							tr.references.get('col4').style.width = '65px';
							
							var ttl = tr.references.get('playgriddiv').offsetWidth - 18 - 48 - 4 - 16;
							
							var col1 = Math.round((ttl / 100) * 40);
							var col2 = Math.round((ttl / 100) * 30);
							var col3 = Math.round((ttl / 100) * 30);						
							
							g('pubtcol2').style.width = col1 + 'px';
							g('pubtcol3').style.width = col2 + 'px';
							g('pubtcol4').style.width = col3 + 'px';
							break;
					}
					break;			

			}		
		break;
	}
	
	


}
function doAddToPlaylist (vars) {
	//CALLED BY FLASH AFTER RESOLVING THE ARTIST AND ALBUM INFO
	var vars = vars.split("|!|")
	var str = 'func.asp?c=addtopl&pl=' + vars[6] + '&t='+escape(vars[0])+'&url='+escape(vars[1])+'&v='+escape(vars[2])+'&d='+escape(vars[3])+'&img='+escape(vars[4])+'&dur='+vars[5]
	str += '&si=' + escape(vars[7]) + '&ar=' + escape(vars[8]) + '&al=' + escape(vars[9]) + '&ai=' + escape(vars[10]);
	if (tr.findReplacement != 0) {str += '&tid=' + tr.findReplacement};

	//var str = 'func.asp?c=addtopl&pl=' + v6 + '&t='+escape(v0)+'&url='+escape(v1)+'&v='+escape(v2)+'&d='+escape(v3)+'&img='+escape(v4)+'&dur='+v5
	//str += '&si=' + escape(v7) + '&ar=' + escape(v8) + '&al=' + escape(v9) + '&ai=' + escape(v10);

	com(str, parseXML);

}
function updateAddAlbumStatus (s, desc, prog) {
	g('aastatus').innerHTML = s;
	g('aastatusdesc').innerHTML = desc;
	g('aaprogress').style.width = (274 / 100) * prog + 'px';
}
function encodeAWSCall (str, k) {
	var s = getRequestSignature(str, k)
	return s.signedquery
}
function postFAlbumXML (plid, ttlSongs, ttlNotFound, str) {
	if (ajaxStatus != 'busy') {	
		ajaxStatus = 'busy';
		document.body.style.cursor='wait';
		// POSTS DATA AND RETURNS DATA
		var refresh = Math.random();
		strURL = "func.asp?c=addalbum&pl=" + plid + "&ttl=" + ttlSongs + "&notfound=" + ttlNotFound
		
		if (strURL.lastIndexOf('?') != -1) {temp = "&"} else {temp = "?"};
		req.open('POST',strURL+temp+'r='+refresh);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send(str);	
		req.onreadystatechange = parseXML;
	} else {
		//ADD THE REQUEST TO THE QUEUE
		ajaxQ.push("postFAlbumXML(" + plid + "," + ttlSongs + "," + ttlNotFound + "," + str + ")");
	}
	return false;
}
function fAlert (str) {
	alert(str);
}
function convDurToSecs (dur) {
var temp = dur;	

	var arr = dur.split(":");
	
	temp = parseInt(arr[0]) * 60;
	temp += parseInt(arr[1]);
	
	return temp;
}

///////////  AJAX FUNCTIONS /////////////////////////////
var req = false;
var ajaxQ = Array(); // THE AJAX QUEUE
var ajaxStatus = 'ready'; // THE STATUS OF THE AJAX CALLER
var targetDiv = '';
function initCom () {
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
}
function updateAddAlbumStatus (s, desc, prog) {
	g('aastatus').innerHTML = s;
	g('aastatusdesc').innerHTML = desc;
	g('aaprogress').style.width = (274 / 100) * prog + 'px';
}
function com (strURL, callback, frm, tDiv, s) {
	if (ajaxStatus != 'busy') {		
		ajaxStatus = 'busy';
		document.body.style.cursor='wait';

		var refresh = Math.random();
		var str = "";
		
		if (strURL.lastIndexOf('?') != -1) {
			temp = "&";
		} else {
			temp = "?";
		}
		
		if (tDiv != undefined) {targetDiv = tDiv};
			
		if (frm != undefined || s != undefined) {
			if (s != undefined) {
				str = s;
			} else {
				str = getForm(frm);
			}
			req.open('POST',strURL+temp+'r='+refresh);
		} else {
			req.open('GET',strURL + temp + 'r=' + refresh);
		}		
				
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		if (callback != undefined) {req.onreadystatechange = callback};
		req.send(str);	
		
	} else {	
		str = "com('" + strURL + "'";
		if (callback != undefined) {str += "," + callback};
		if (frm != undefined) {str += ",g('" + frm.name + "')"} else {str += ",undefined"};
		if (tDiv != undefined) {str += ",'" + tDiv + "'"} else {str += ",undefined"};
		if (s != undefined) {str += ",'" + s + "'"} else {str += ",undefined"};
		str += ")";
		ajaxQ.push(str);
	
	}
	return false;
}
function comProcessNext () {
	ajaxStatus = 'ready';
	if (ajaxQ.length > 0) {
		eval(ajaxQ[0]);
		ajaxQ.splice(0,1);
	}
}
function parseDoc (response) {
var doc;
	try {//Internet Explorer
		doc=new ActiveXObject("Microsoft.XMLDOM");
		doc.async="false";
		doc.loadXML(response);
	} catch(e) {
		var parser=new DOMParser();
		doc=parser.parseFromString(response,"text/xml");
	}	
	return doc;
}
function getFirstNode (doc) {
	switch (browser) {
		case 'ie':
			var f = doc.firstChild.nextSibling;
			break;
		case 'ff':
		case 'sa':
		case 'op':		
			var f = doc.firstChild;
			break;
	}
	return f;
}
function parseXML () {
	document.body.style.cursor='default';
	
	if (req.readyState == 4) {		
		if (req.status == 200) {
			var response = req.responseText;
			comProcessNext();
			var doc = parseDoc(response);				
			var fnode = getFirstNode(doc);
			switch (fnode.nodeName) {
				case "pls":
					//PLAYLISTS			
					pls = doc.getElementsByTagName("p");											
					for (i=0;i<pls.length;i++) {					
						var node = pls[i];
						var res = new Playlist;
						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1");
						res.name = node.getAttribute("c2");
						res.shared = node.getAttribute("c3");
						res.rating = node.getAttribute("c4");	
						res.ttlvids = node.getAttribute("c5");	
						res.username = node.getAttribute("c6");							
						res.userrating = node.getAttribute("c7");	

						if (startPl != 0 && res.id == startPl) {
							tr.curPl = res;
							tr.pl = res.id;
							com ("func.asp?c=loadpl&pl=" + tr.pl, parseXML);
							tr.setSearchMode('disc');						
						} else {
						
							if (tr.curPl == undefined && i == 0 && startPl == 0) {
								tr.curPl = res;
								tr.pl = res.id;
								com ("func.asp?c=loadpl&pl=" + tr.pl, parseXML);
								tr.setSearchMode('disc');
							}	
						
						}
							
						tr.playlists.add(res);
					}
					tr.playlists.display();
					break;
					
				case 'pl':
					//TUNES
					tr.references.get('sloader').style.display = 'none';					
					//HIDE THE LOADING ICON
					if (g('plload' + tr.pl) != null) {g('plload' + tr.pl).style.display = "none"};
					//CLEAR DOWN THE CURRENT PL
					tr.curPl.clear();
					tu = doc.getElementsByTagName("t");
					var toggle = 0;
					
					for (i=0;i<tu.length;i++) {						
						var node = tu[i];
						var res = new Video;
						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1");
						res.videoid = node.getAttribute("c2");
						res.name = unescape(decodeUTF8(node.getAttribute("c3")));
						res.artist = unescape(decodeUTF8(node.getAttribute("c4")));
						res.album = unescape(decodeUTF8(node.getAttribute("c5")));
						res.duration = node.getAttribute("c6");			
						res.played = node.getAttribute("c7");
						res.seq = i;
						res.disabled = node.getAttribute("c8");
						tr.curPl.add(res);
					}				
					tr.curPl.cached = true;
					
					if (tr.mode == 'playlistsearch') {
						tr.lastSearchPl =  new CloneObject(tr.curPl);
					}
					
					tr.curPl.sort(tr.so);
					tr.curPl.display();
					
					if (startMode == 'disc') {
						tr.references.get('search').value = startSearch;
						tr.search('disc', startSearch);	
						tr.references.get("appwait").style.display = 'none';
						startMode = '';
					} else {
						if (tr.references.get("appwait").style.display != 'none' && g('nlin') == undefined) {tr.references.get("appwait").style.display = 'none'};					
						
						if (readCookie('shownfdragdrop') == null && g('nlin') == undefined && shownfdragdrop == false) {
							tr.references.get('appwait').style.display = 'block';
							tr.showTip('tip_dragdrop.asp', true);
							shownfdragdrop = true;
						}
					}

					break;	

				case 'pubpl':				
					//TUNES
					tr.references.get('sloader').style.display = 'none';
					//CLEAR DOWN THE CURRENT PL
					tr.curPubPl.clear();
					tu = doc.getElementsByTagName("t");
					var toggle = 0;

					for (i=0;i<tu.length;i++) {						
						var node = tu[i];
						var res = new Video;
						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1");
						res.videoid = node.getAttribute("c2");
						res.name = unescape(node.getAttribute("c3"));
						res.artist = unescape(node.getAttribute("c4"));
						res.album = unescape(node.getAttribute("c5"));
						res.duration = node.getAttribute("c6");			
						res.played = node.getAttribute("c7");
						res.seq = i;
						res.disabled = node.getAttribute("c8");
						
						tr.curPubPl.add(res);
					}
					tr.curPubPl.cached = true;
					tr.curPubPl.publicpl = true;
					tr.curPl.sort(tr.so);
					tr.curPubPl.display();	
					break;

				case 'pladd':
					//NEW TRACK ADDED TO PLAYLIST
					var tu = doc.getElementsByTagName("t");
										
					var toggle = 0
					var str = tr.templates.get('plrowtemplate');
					
					var node = tu[0];
					
					//THERE'S ONLY 1 RESULT TO LOOP THROUGH
					if (fnode.getAttribute("m") == 'fr') {
						var res = tr.curPl.get(node.getAttribute("c1"));
					
						res.videoid = node.getAttribute("c2")
						res.name = node.getAttribute("c3")
						res.artist = node.getAttribute("c4")
						res.album = node.getAttribute("c5")
						res.duration = node.getAttribute("c6")						
						res.played = node.getAttribute("c7")	

						//RESET THE STATE AFTER ADDING THE REPLACEMENT
						tr.findReplacement = 0;
						g('appwait').style.display='none';
						tr.setMode('playlist');
						tr.youtuberesults.forceRedisplay = false;
						tr.references.get('youtubediv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(images/alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('ytrowformat') + '</table>';
						
					} else {
									
						var res = new Video;

						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1")	
						res.videoid = node.getAttribute("c2")
						res.name = node.getAttribute("c3")
						res.artist = node.getAttribute("c4")
						res.album = node.getAttribute("c5")
						res.duration = node.getAttribute("c6")						
						res.played = node.getAttribute("c7")
						
						var seq = 0;
						if (tr.curPl.count > 0) {
							seq = tr.curPl.count
						}
						res.seq = seq;
						
						tr.curPl.add(res);
					
					}		
					
					//REDISPLAY THE PLAYLIST					
					tr.curPl.display();					
					
					break;
				case 'npls':				
					//NEW PLAYLIST
					pls = doc.getElementsByTagName("p");						
					
					for (i=0;i<pls.length;i++) {						
						var node = pls[i];
						var res = new Playlist;
						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1");
						res.name = node.getAttribute("c2");
						res.shared = node.getAttribute("c3");
						res.rating = node.getAttribute("c4");	
						res.ttlvids = node.getAttribute("c5");	
						res.username = node.getAttribute("c6");							
						res.userrating = node.getAttribute("c7");	

						tr.playlists.add(res);
					}
										
					tr.playlists.display();
					
					if (fnode.getAttribute("m") == 'adddisc') {
						tr.doAddDiscs(res.id);
					}					
					break;
				case 'plsaddalbum':
					var desc = '';
					if (fnode.getAttribute("notfound") == 0) {
						desc = 'All songs were found!';
					} else {
						desc = fnode.getAttribute("notfound") + ' songs were not found';
					}
					updateAddAlbumStatus ((parseInt(fnode.getAttribute("ttl")) - parseInt(fnode.getAttribute("notfound"))) + " songs have been added to your playlist", desc, 100);
					g('aaclose').style.display = 'block';
					g('aacancel').style.display = 'none';
					tr.playlists.get(fnode.getAttribute("pl")).cached = false;
					tr.playlists.load(parseInt(fnode.getAttribute("pl")));
					break;	
				case 'pub':
					//PUBLIC PLAYLISTS
					tr.references.get('sloader').style.display = 'none';
					
					var pub = doc.getElementsByTagName("p");
					var toggle = 0									
					var str = tr.templates.get('pubrowtemplate');
					var outArr = new Array();
					
					for (i=0;i<pub.length;i++) {	
						var node = pub[i];
						var res = new Playlist;
						//READ INT0 THE ARRAY
						res.id = node.getAttribute("c1");
						res.name = node.getAttribute("c2");
						res.shared = node.getAttribute("c3");						
						res.rating = node.getAttribute("c4");	
						res.ttlvids = node.getAttribute("c5");	
						res.username = node.getAttribute("c6");	
						res.uid = node.getAttribute("c8");	
						tr.publicplaylists.add(res);
						
						toggle += 1;
						if (toggle == 2) {
							tclass = 'tuneentry2'
							trclass = 'tunerow2'
							txtclass = 'tuneentryi'
							timg = 'white'
							tcolor = 'ffffff'
							toggle = 0
						} else {
							tclass = 'tuneentry1'
							trclass = 'tunerow1'
							txtclass = 'tuneentryi'
							timg = 'ltblue'
							tcolor = 'eff4fa'
						}																
						if (tr.playlists.inPlaylists(res.id)) {icolor = 'btn_unsubscribe'} else {icolor='btn_subscribe'};
						
						var rstr = '';
						for (var j=1;j<=5;j++) {
							if (j <= res.rating) {
								rstr += '<img src="' + imagePath + 'icon_star_over.gif" border=0>';
							} else {
								rstr += '<img src="' + imagePath + 'icon_star.gif" border=0>';
							}
						}
						var t = str;
						t = t.replace(/-i-/g, i);
						t = t.replace(/-id-/g, res.id);
						t = t.replace(/-name-/g, res.name);
						t = t.replace(/-ttlvids-/g, res.ttlvids);
						t = t.replace(/-rating-/g, rstr);
						t = t.replace(/-user-/g, res.username);
						t = t.replace(/-uid-/g, res.uid);
						t = t.replace(/-icolor-/g, icolor);
						t = t.replace(/<tbody>/g, '');
						t = t.replace(/<\/tbody>/g, '');

						outArr.push(t);						
					}

					tr.references.get('publicdiv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + outArr.join('') + tr.templates.get('pubrowformat') + '</table>';	
					resizeClient();
										
					//SET THE NEXT AND PREV BUTTONS
					var ttl = fnode.getAttribute("ttl")
					
					if (ttl > (tr.pubStartIndex + tr.pubMaxResults)) {
						if (tr.references.get('optpubnext').src.indexOf('_over') != -1) {
							tr.references.get('optpubnext').src = imagePath + 'opt_next_over.png';
						} else {
							tr.references.get('optpubnext').src = imagePath + 'opt_next.png';
						}
					} else {
						tr.references.get('optpubnext').src = imagePath +'opt_next_grey.png';
					}
					
					if (tr.pubStartIndex > 1) {
						if (tr.references.get('optpubprev').src.indexOf('_over') != -1) {
							tr.references.get('optpubprev').src = imagePath + 'opt_prev_over.png';
						} else {
							tr.references.get('optpubprev').src = imagePath + 'opt_prev.png';
						}
					} else {
						tr.references.get('optpubprev').src = imagePath + 'opt_prev_grey.png';	
					}
					break;
					
				case 'info': 				
					//INFO TAB
					it = doc.getElementsByTagName("i");
					var infoReceived = false;
					
					switch (fnode.getAttribute("tab")) {
						case "0": //RELEASES
							tab = 0;
							if (it.length == 0) {
								vol.getArtistReleaseInfo(escape(fnode.getAttribute("a")));
								return false;
							} else {
								var res = new Releases();
								res.artist = fnode.getAttribute("a");
								
								for (var i=0;i<it.length;i++) {
									var rel = new Release();
									var node = it[i];
									rel.name = node.getAttribute("c1");
									rel.mbid = node.getAttribute("c2");
									rel.img = node.getAttribute("c3");
									res.add(rel);
								}
								tr.infotabs.tabs[tab].addCacheData (res);
								tr.infotabs.display(tab, res);
								infoReceived = true;
							}
							break;
							
						case "1": //LYRICS
							tab = 1;
							if (it.length == 0) {							
								vol.getLyricInfo(escape(fnode.getAttribute("a")), escape(fnode.getAttribute("t")));
								return false;
							} else {
								var res = new Lyrics();
								res.artist = fnode.getAttribute("a");
								res.track = fnode.getAttribute("t");
								res.lyrics = unescape(it[0].getAttribute("c1"));
								res.checksum = it[0].getAttribute("c2");
								res.songid = it[0].getAttribute("c3");
								
								tr.infotabs.tabs[tab].addCacheData (res);
								tr.infotabs.display(tab, res);
								infoReceived = true;
							}
							break;					
					
						case "2": //BIO
							tab = 2;
							if (it.length == 0) {
								vol.getBioInfo(escape(fnode.getAttribute("a")));
								return false;
							} else {
								var res = new Bio();
								res.artist = fnode.getAttribute("a");
								res.bio = unescape(it[0].getAttribute("c1"));
								tr.infotabs.tabs[tab].addCacheData (res);
								tr.infotabs.display(tab, res);
								infoReceived = true;
							}
							break;
					
					
						case "3": //SIMILAR
							tab = 3;
							if (it.length == 0) {
								vol.getSimilarInfo(escape(fnode.getAttribute("a")));
								return false;
							} else {
								var res = new Similar();
								res.artist = fnode.getAttribute("a");
								
								for (var i=0;i<it.length;i++) {
									var rel = new Artist();
									var node = it[i];
									rel.name = node.getAttribute("c1");
									rel.img = node.getAttribute("c2");
									res.add(rel);
								}
								tr.infotabs.tabs[tab].addCacheData (res);
								tr.infotabs.display(tab, res);
								infoReceived = true;
							}
					
							break;	
					}
					
					if (infoReceived == false) {
						switch (tab) {
							case 0:
								tr.references.get('releases').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >No releases found</td></tr></table>';					
								break;
							case 1:
								tr.references.get('lyrics').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >No lyrics found</td></tr></table>';			
								break;
							case 2:
								tr.references.get('bio').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >No bio found</td></tr></table>';				
								break;
							case 3:
								tr.references.get('similar').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >No similar artists found</td></tr></table>';					
								break;
						}
								
						tr.references.get('tabwait').style.display = 'none';
					}					

			}
			
			//CHECK FOR ALERTS
			if (false) {
				als = doc.getElementsByTagName("alerts");
				if (als.length > 0) {
					for (i=0;i<als.length;i++) {			
						var node = als[i];
						switch (node.getAttribute("t")) {
							case "unread":
								
						
						
						}
					
					}
				}
			}

		} else {
			comProcessNext();
		}

	} 

}
function parseFXML (response) {
	document.body.style.cursor='default';
	var doc = parseDoc(response);				
	var fnode = getFirstNode(doc);		
	
	//alert(response)
	//alert(fnode.nodeName);
	
	var outArr = new Array();

	switch (fnode.nodeName) {
		case 'yt':
			tr.references.get('sloader').style.display = 'none';
			y = doc.getElementsByTagName("y");							

			for (var i=0;i<y.length;i++) {				
				var node = y[i];
				var res = new YouTubeResult;
				res.id = i;
				res.title = unescape(decodeURIComponent(node.getAttribute("c1")));
				res.swf = unescape(node.getAttribute("c2"));
				res.desc = unescape(decodeURIComponent(node.getAttribute("c3")));
				res.videoid = unescape(node.getAttribute("c4"));
				res.thumbimg = unescape(node.getAttribute("c5"));
				res.duration = unescape(node.getAttribute("c6"));					
				res.seconds = unescape(node.getAttribute("c7"));	
				tr.youtuberesults.add(res);
				
			}
			tr.youtuberesults.totalYtResults = fnode.getAttribute("ttl");			
			tr.youtuberesults.display();
			break;
			
		case 'ta':
			//TAB DATA
			//CHECK FOR TAB DATA
			var outArr = new Array();
			var tab;
			var infoReceived = false;

			//alert(response);
			
			//RELEASES
			r = doc.getElementsByTagName('r');
			var node = r[0];
			var outArr = new Array();

			if (node != undefined) {			
				tab = 0;
				infoReceived = true;
				var res = new Releases();
				res.artist = unescape(node.getAttribute("c1"));
				
				outArr.push('<?xml version="1.0" encoding="utf-8"?>');
				outArr.push('<info>');				
				for (var i=0;i<r.length;i++) {
					var node = r[i];
					var rel = new Release();
					rel.name = unescape(node.getAttribute("c2"));
					rel.mbid = unescape(node.getAttribute("c3"));
					rel.img = unescape(node.getAttribute("c4"));
					res.add(rel);
					
					str = '<i';
					str += ' c1="' + node.getAttribute("c2") + '"';
					str += ' c2="' + node.getAttribute("c3") + '"';
					str += ' c3="' + node.getAttribute("c4") + '"';
					str += '/>';
					outArr.push(str);
					
				}
				outArr.push('</info>');
				//POST THE DATA BACK TO THE SERVER
				com('func.asp?c=storeinfo&tab=' + tab + '&a=' + escape(res.artist), noCallback, undefined, undefined, outArr.join(''));
				
				tr.infotabs.tabs[tab].addCacheData (res);
				tr.infotabs.display(tab, res);
			}
			
			//LYRICS
			l = doc.getElementsByTagName('l');
			var node = l[0];			

			if (node != undefined) {
				tab = 1;
				infoReceived = true;
				var res = new Lyrics();
				res.lyrics = unescape(node.getAttribute("c1"));
				res.artist = unescape(node.getAttribute("c2"));
				res.track = unescape(node.getAttribute("c3"));	
				res.checksum = unescape(node.getAttribute("c4"));
				res.songid = unescape(node.getAttribute("c5"));
				
				outArr.push('<?xml version="1.0" encoding="utf-8"?>');
				outArr.push('<info>');	
				str = '<i';
				str += ' c1="' + node.getAttribute("c1") + '"';
				str += '/>';
				outArr.push(str);
				outArr.push('</info>');					
				//POST THE DATA BACK TO THE SERVER
				com('func.asp?c=storeinfo&tab=' + tab + '&a=' + escape(res.artist) + '&t=' + escape(res.track) + '&cs=' + escape(res.checksum) + '&sid=' + escape(res.songid), noCallback, undefined, undefined, outArr.join(''));
				
				tr.infotabs.tabs[tab].addCacheData (res);
				tr.infotabs.display(tab, res);
			}			
			
			//BIO
			b = doc.getElementsByTagName('b');
			var node = b[0];
			
			if (node != undefined) {
				tab = 2;
				infoReceived = true;
				var res = new Bio();
				res.bio = unescape(node.getAttribute("c1"));		
				res.artist = unescape(node.getAttribute("c2"));
				
				outArr.push('<?xml version="1.0" encoding="utf-8"?>');
				outArr.push('<info>');
				str = '<i';
				str += ' c1="' + node.getAttribute("c1") + '"';
				str += '/>';
				outArr.push(str);
				outArr.push('</info>');					
				//POST THE DATA BACK TO THE SERVER
				com('func.asp?c=storeinfo&tab=' + tab + '&a=' + escape(res.artist), noCallback, undefined, undefined, outArr.join(''));

				tr.infotabs.tabs[tab].addCacheData (res);
				tr.infotabs.display(tab, res);	
			}
			
			//SIMILAR
			s = doc.getElementsByTagName('s');
			var node = s[0];
			
			if (node != undefined) {			
				tab = 3;
				infoReceived = true;
				var res = new Similar();
				res.artist = unescape(fnode.getAttribute("a"));
				
				//alert(response);
				
				outArr.push('<?xml version="1.0" encoding="utf-8"?>');
				outArr.push('<info>');				
				for (var i=0;i<s.length;i++) {
					var node = s[i];
					var rel = new Artist();
					rel.name = unescape(node.getAttribute("c1"));
					rel.img = unescape(node.getAttribute("c2"));
					res.add(rel);
					
					str = '<i';
					str += ' c1="' + node.getAttribute("c1") + '"';
					str += ' c2="' + node.getAttribute("c2") + '"';
					str += '/>';
					outArr.push(str);
					
				}
				outArr.push('</info>');
				//POST THE DATA BACK TO THE SERVER
				com('func.asp?c=storeinfo&tab=' + tab + '&a=' + escape(res.artist), noCallback, undefined, undefined, outArr.join(''));
				
				tr.infotabs.tabs[tab].addCacheData (res);
				tr.infotabs.display(tab, res);
			}
			
			if (infoReceived == false) {
			
				if (tab == undefined) {tab = tr.curTabNo}
			
				switch (tab) {
					case 0:
						tr.references.get('releases').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >No releases found</td></tr></table>';					
						break;
					case 1:
						tr.references.get('lyrics').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >No lyrics found</td></tr></table>';			
						break;
					case 2:
						tr.references.get('bio').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >No bio found</td></tr></table>';				
						break;
					case 3:
						tr.references.get('similar').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >No similar artists found</td></tr></table>';					
						break;
				}
						
				tr.references.get('tabwait').style.display = 'none';
			}
			
			break;			

		case 'ti':
			//AMAZON INFO
			amaz = doc.getElementsByTagName('a');
			var node = amaz[0];
			var str = tr.templates.get('albuminfotemplate');				
			var t = str; 
			
			if (node != undefined) {
				//AMAZON INFO WAS AVAILABLE
				if (tr.amazonRedirect) {
					window.open(unescape(node.getAttribute("c2")))
					tr.amazonRedirect = false;
				} else {
					
					t = t.replace(/-url-/g, unescape(node.getAttribute("c2")));
					t = t.replace(/-img-/g, unescape(node.getAttribute("c3")));
					t = t.replace(/-dalbumname-/g, unescape(node.getAttribute("c1")));
					t = t.replace(/-dartistname-/g, tr.curVid.artist);
					
					tr.references.get('albuminfo').innerHTML = t;
				}

			} else {
				//AMAZON INFO WAS NOT AVAILABLE
				if (tr.amazonRedirect) {
					alert('This album could not be found on Amazon');
					tr.amazonRedirect = false;
				} else {
					t = t.replace(/-url-/g, 'javascript:return false');
					t = t.replace(/-img-/g, imagePath + 'no_albumart.png');
					t = t.replace(/-price-/g, '');
					
					tr.references.get('albuminfo').innerHTML = t;
				}
			}			

			break;
			
		case 'di':
			//DISCOGRAPHY
			tr.references.get('sloader').style.display = 'none';
			
			tr.discs.clear();
			var disc = doc.getElementsByTagName('r');
			var str = tr.templates.get('disctemplate');
			
			if (disc[0] != undefined) {
				for (var i=0;i<disc.length;i++) {	
					var node = disc[i];

					var res = new Disc;
					//READ INT0 THE ARRAY
					res.mbid = unescape(node.getAttribute("c1"));
					res.name = unescape(node.getAttribute("c2"));
					res.img = unescape(node.getAttribute("c3"));				
					
					tr.discs.add(res);

					var t = str;

					t = t.replace(/-id-/g, i);
					t = t.replace(/-name-/g, brief(HtmlDecode(res.name), 25));
					t = t.replace(/-fullname-/g, HtmlDecode(res.name).replace(/'/g, '\''));
					
					if (res.img.indexOf('default_album_medium') != -1) {
						t = t.replace(/-img-/g, imagePath + 'no_albumart2.png');
					} else {
						t = t.replace(/-img-/g, res.img);
					}

					outArr.push(t)
					
				}

				tr.references.get('discdiv').innerHTML = '<table style="background-color:262626" cellpadding=0 cellspacing=0 border=0 width="100%" height="100%" ><tr><td valign="top">' + outArr.join('') + '</td></tr></table>';
				if (readCookie('showdisctip') == null) {tr.showTip('tip_disc.asp')};	
			
			} else {
				//NO DISC RESULTS FOUND, SEARCH THE MB DATABASE
				tr.references.get('discdiv').innerHTML = '<table style="background-color:262626" cellpadding=20 cellspacing=0 border=0 width="100%" height="100%" ><tr><td valign="top" class="profiletext12white" style="height:17px" ><b>No results were found for the artist "' + tr.lastSearch + '". <br><br><a class="dischintlink" style="font-size:16px" onclick="tr.search(\'youtube\',\'' + tr.lastSearch.replace(/'/g, '\'') + '\')">Click here to search YouTube for ' + tr.lastSearch + '</a></b><br><br><div id="dischint"></div></td></tr></table>';			
				com('dischint.asp?s=' + tr.references.get('search').value.replace(/\'/g,'\''), handleResponse, undefined, 'dischint');
			}

	}

}
function handleResponse () {
	document.body.style.cursor='default';
	if (req.readyState == 4) {		
		if (req.status == 200) {
			var response = req.responseText;
			parseScript(response);	
			g(targetDiv).innerHTML = response;
			//RUN ANY CODE IN SCRIPT TAGS
			comProcessNext();			
		}		
	}
}	
function getForm(fObj) {
	var str = "";
	var ft = "";
	var fv = "";
	var fn = "";
	var els = "";
	for (var i=0;i<fObj.elements.length;i++) {
		els = fObj.elements[i];
		ft = els.title;
		fv = els.value;
		fn = els.name;			
		
		switch (els.type) {
			case "text":
			case "hidden":
			case "password":
			case "textarea":
				str += fn + "=" + encode(fv) + "&";
				break;
			
			case "checkbox":
			case "radio":
				if (els.checked) {str += fn + "=" + encode(fv) + "&"};
				break;
				
			case "select-one":
				str += fn + "=" + els.options[els.selectedIndex].value + "&";
				break;
		
		}		
	}
	str = str.substr(0,(str.length - 1));
	return str;
}
function encode(string) {
	return escape(string);
}	
function parseScript(_source) {
	//RUNS JAVASCRIPT IN AJAX PAGE AFTER IT'S LOADED 
	var source = _source;
	var scripts = new Array();
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);		
		// Add to scripts array
		scripts.push(source.substring(s_e+1, e));
		// Strip from source
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	// Loop through every script collected and eval it
	for(var i=0; i<scripts.length; i++) {
		try {			
			eval(scripts[i]);
		}
		catch(ex) {
			// do what you want here when a script fails
		}
	}
	// Return the cleaned source
	return source;
}
function noCallback () {
	document.body.style.cursor='default';
	if (req.readyState == 4) {		
		if (req.status == 200) {
			var response = req.responseText;
			comProcessNext();
		}
	}
}
function parseTemplates () {
	document.body.style.cursor='default';
	
	if (req.readyState == 4) {		
		if (req.status == 200) {
			var response = req.responseText;
			var arr = response.split("|");
			for (var i=0;i<arr.length;i++) {
				tr.templates.add(arr[i], arr[i+=1]);		
	
			}	
			tr.displayTG();
			
			//GOOGLE
			if (p == 'chart') {
				tr.loadContent('tgchart','chart.asp');
			} else {

				if (g('nlin') != undefined && startMode.length == 0) {
					tr.references.get('appwait').style.display = 'block';
					tr.showDialog('welcome');
				} 
				
			}

			comProcessNext();	
		}

	}			
}
///////////  COOKIE FUNCTIONS /////////////////////////////
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}	
///////////  VOLUME CONTROL FUNCTIONS /////////////////////////////
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function volume_DoFSCommand(command, args) {
	var volumeObj = isInternetExplorer ? document.all.volume : document.volume;
	switch (command) {
		case "volume":
			swf.setVolume(args);
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub volume_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call volume_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
function setSwfVolume (v) {
	swf.setVolume(v);
	if (v == 0) {
		tr.setMute(true);
	} else {
		tr.setMute(false);
	}
}
function getSwfVolume () {
	var v = swf.getVolume();

	if (swf.isMuted == false) {
		if (v == 0) {
			tr.setMute(true);
		} else {
			tr.setMute(false);
		}	
	}	
	return v;
}
//############## VIDEO PLAYER FUNCTIONS ######################
function onVolumeReady() {
	vol = g('volume');
}
function onYouTubePlayerReady(playerId) {
	swf = g('swf');
	swf.addEventListener("onStateChange", "onSwfStateChange");
	swf.addEventListener("onError", "onSwfError");
}
function onSwfError (errNum) {
	switch (errNum) {
		case 100: //VIDEO NOT FOUND / REMOVED OR MARKED AS PRIVATE
		case 101: // VIDEO DOES NOT ALLOW PLAYBACK IN EMBEDDED PLAYERS
		case 150: //SAME AS 101
			swf.clearVideo();
			var thisvid = this.curVid.id;
			tr.playNext();
			tr.playlists.get(thisvid).disable;
			break;
	}
}
function onSwfStateChange(newState) {  
	switch (newState) {
		case 0: // END
			//CLEAR THE CURRENT VID
			swf.clearVideo();
			// PLAY THE NEXT VID
			tr.playNext();
			break;
		case 5: //VIDEO CUED
			break;
		case 3: // BUFFERING
		case -1: // UNSTARTED (OCCURS WHEN THE VID FIRST LOADS)
		case 1: // PLAYING,
			tr.changePlayerState('playing');
			if (tr.mute) {swf.mute()};			
			break;
		case 2: // PAUSED
			tr.changePlayerState('paused');
			break;
	}
}
function mup () {
	tr.dragMode = '';
	tr.dragId = 0;	
	if (tr.fireHideMenus) {tr.hideMenus()};
}
/////////// INIT FUNCTIONS  /////////////////////////////
function init () {
	initCom();
	
	tr = new TubeRadio();
	tr.maxResults = maxYtResults;
	
	window.onresize = resizeClient;	
	document.onmouseup = mup;
	document.onkeydown = function (e) {
		var keycode = '';
		var src = '';
		if (window.event) {
			if (window.event.shiftKey) {keycode = 'shift'};
			if (window.event.ctrlKey || window.event.metaKey) {keycode = 'ctrl'};
			if (window.event.keyCode == 46) {keycode = 'del'}
			
			if (browser == 'ie') {
				src = window.event.srcElement.nodeName;
				if (src.toLowerCase() != 'input') { src = ''};
			} else {
				src = window.event.srcElement.id;
			};
		} else if (e) {
			if (e.which == 16) {keycode = 'shift'};
			if (e.which == 17 || e.metaKey) {keycode = 'ctrl'};
			if (e.which == 46 || e.which == 63272) {keycode = 'del'};
			src = (e.target.id);
		}
		
		if (keycode == 'del' && src.length == 0 && tr.browseMode == 'player') {
			if (tr.curPl.selCount > 0) {
				if (confirm('Are you sure you wish to delete the selected videos?')) {
					tr.curPl.delSelVids();
				}
			}
		}
		tr.curKey = keycode;
	}
	document.onkeyup = function (e) {
		tr.curKey = '';
	}
	resizeClient();
}

var tr;
var targetDiv;
var vol;
var swf;
var browser = getBrowser();
var imagePath = '';
var shownfdragdrop = false;
window.onload = init;
