var hD="0123456789ABCDEF";
var timerID = 0;

function UpdateTimer() {


   
   if (timerID) {
      clearTimeout(timerID);
   }
	
   var  tDate = new Date();
   var 	ct = tDate.getTime();

   if (document.images) { 
			//document["sb"].src = '/sb.php?cb=' + ct ;
   }

   timerID = setTimeout("UpdateTimer()", 900000);
}

function randomBG() {
	f1=d2h(Math.round(Math.random()*15));
	f3=d2h(Math.round(Math.random()*15));
	f2=d2h(Math.round(Math.random()*15));
	
	return("#"+f1+f1+f2+f2+f3+f3);
}

function d2h(d) {
	var h = hD.substr(d&15,1);
	while(d>15) {d>>=4;h=hD.substr(d&15,1)+h;}
	return h;
}

function h2d(h) {
	return parseInt(h,16);
} 

function winPop(doc,name,scroll,status,width,height,resizable){
		
	newWin = open(doc,name,"scrollbars=" + scroll + ",resizable="+resizable+",status=" + status + ",width=" + width + ",height=" + height);

	if (!newWin.opener)
		newWin.opener = self; 
	
	if (newWin)
		newWin.focus();

}

function email(address,domain,ext,style,nm) {
	var first = 'ma';
	var second = 'il';
	var third = 'to:';

	document.write('<a href="');
	document.write(first+second+third);
	document.write(address);
	document.write('@');
	document.write(domain);
	document.write('.');
	document.write(ext); 
	document.write('"');  
	if (style!='')
		document.write(' class="'+ style+'" ');  
	document.write('>'); 

	if (nm=='') {
		document.write(address);
		document.write('@');
		document.write(domain);
		document.write('.');
		document.write(ext);  
	} else {
		document.write(nm);  
	}
	document.write('</a>');
}



function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


	
function printRange() {
	var range = document.body.createTextRange();
	if (range!=null) {
    	alert(range.htmlText);
	}
}

function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject


// F. Permadi 2005.
// (C) F. Permadi
// Print DOM tree
////////////////////////////////////////////
// This function traverses the DOM tree of an element and prints the tree.  
// This function called recursively until the DOM tree is fully traversed.
// 
// Parameters:
// - targetDocument is where the tree will be printed into
// - currentElement is the element that we want to print
// - depth is the depth of the current element 
//   (it should be 1 for the initial element)
////////////////////////////////////////////
function traverseDOMTree(targetDocument, currentElement, depth)
{
  if (currentElement)
  {
    var j;
    var tagName=currentElement.tagName;
    // Prints the node tagName, such as <A>, <IMG>, etc
    if (tagName)
      targetDocument.writeln("&lt;"+currentElement.tagName+"&gt;");
    else
      targetDocument.writeln("[unknown tag]");

    // Traverse the tree
    var i=0;
    var currentElementChild=currentElement.childNodes[i];
    while (currentElementChild)
    {
      // Formatting code (indent the tree so it looks nice on the screen)
      targetDocument.write("<BR>\n");
      for (j=0; j<depth; j++)
      {
        // &#166 is just a vertical line
        targetDocument.write("&nbsp;&nbsp;&#166");
      }								
      targetDocument.writeln("<BR>");
      for (j=0; j<depth; j++)
      {
        targetDocument.write("&nbsp;&nbsp;&#166");
      }					
      if (tagName)
        targetDocument.write("--");

      // Recursively traverse the tree structure of the child node
      traverseDOMTree(targetDocument, currentElementChild, depth+1);
      i++;
      currentElementChild=currentElement.childNodes[i];
    }
    // The remaining code is mostly for formatting the tree
    targetDocument.writeln("<BR>");
    for (j=0; j<depth-1; j++)
    {
      targetDocument.write("&nbsp;&nbsp;&#166");
    }			
    targetDocument.writeln("&nbsp;&nbsp;");
    if (tagName)
      targetDocument.writeln("&lt;/"+tagName+"&gt;");
  }
}
////////////////////////////////////////////
// This function accepts a DOM element as parameter and prints
// out the DOM tree structure of the element.
////////////////////////////////////////////
function printDOMTree(domElement, destinationWindow)
{
  // Use destination window to print the tree.  If destinationWIndow is
  //   not specified, create a new window and print the tree into that window
  var outputWindow=destinationWindow;
  if (!outputWindow)
    outputWindow=window.open();

  // make a valid html page
  outputWindow.document.open("text/html", "replace");
  outputWindow.document.write("<HTML><HEAD><TITLE>DOM</TITLE></HEAD><BODY>\n");
  outputWindow.document.write("<CODE>\n");
  traverseDOMTree(outputWindow.document, domElement, 1);
  outputWindow.document.write("</CODE>\n");
  outputWindow.document.write("</BODY></HTML>\n");
  
  // Here we must close the document object, otherwise Mozilla browsers 
  //   might keep showing "loading in progress" state.
  outputWindow.document.close();
}
//BRYON'S FUNCTIONS FOR THE MP3 PLAYER!!!
var popupWin = null;
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
function openPlayer() {

	if( !popupWin || popupWin.closed ) {
		popupWin = window.open("../popupwindow.php", "popupWin","width=430,height=227,status=no,scrollbars=no,resizable=no");
	} else popupWin.focus();
}
function controlPlayer(func,param) {
	if( popupWin && !popupWin.closed ) {
		// The popup is open so call it
		popupWin.controlPlayer(func,param);
		openPlayer();
	} else {
		// The popup is closed so open it
		thisMovie("mp3player").jsControl(func,param);
	}
}
function addtoPlaylist(entityID) {
	try {
 		var xmlhttp = new XMLHttpRequest();
	}
	catch (error)	{
 		try{
   			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		}
 		catch (error) {
		   return false;
 		}
	}
	xmlhttp.open('POST', '../userplaylist.php' , true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('entity_id=' + entityID);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			//controlPlayer('loadUserPlaylist','')
		}
	}
}
function ajaxrequest(fileurl, elementid, query) {
	try {
 		var xmlhttp = new XMLHttpRequest();
	}
	catch (error)	{
 		try{
   			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		}
 		catch (error) {
		   return false;
 		}
	}

	xmlhttp.open('POST', fileurl, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(query);

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			 document.getElementById(elementid).innerHTML=xmlhttp.responseText;
		}
	}
}
function ajaxFormSubmit(handlerURL, obj, target_id) {
  var getstr = "";
  for (i=0; i<obj.childNodes.length; i++) {
	 if (obj.childNodes[i].tagName == "INPUT") {
		if (obj.childNodes[i].type == "text") {
		   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "checkbox") {
		   if (obj.childNodes[i].checked) {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   } else {
			  getstr += obj.childNodes[i].name + "=&";
		   }
		}
		if (obj.childNodes[i].type == "hidden") {
			 getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "select") {
		  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "radio") {
		   if (obj.childNodes[i].checked) {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   }
		}
	 }   
	 if (obj.childNodes[i].tagName == "SELECT") {
		var sel = obj.childNodes[i];
		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	 }
	 
  }
   ajaxrequest(handlerURL, target_id, getstr);
}
function swapDiv(div, newdisplay) {
		  var style_sheet = getStyleObject(div);
		  if (style_sheet)
		  {
		    changeObjectVisibility(div, newdisplay);
		  }
}
function getStyleObject(objectId) 
		{
  		if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
   		}
   		else if (document.all && document.all(objectId)) {  
		return document.all(objectId).style;
   		} 
   		else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId];
   		} 
   		else {
		return false;
   		}
		}
		
function changeObjectVisibility(div, newdisplay) {
	    var styleObject = getStyleObject(div);
    	if (styleObject) {
		styleObject.display = newdisplay;
		return true;
    	} else {
		return false;
    	}
		}

function matchingDivs(){
	var mHeight = document.getElementById("brinkBody").offsetHeight;
	document.getElementById("outerRight").style.height=mHeight + 53 + "px";
	document.getElementById("outerLeft").style.height=mHeight + "px";
}

