function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function imgFit (img, maxImgWidth) 
{ 
   if (typeof img.naturalWidth == 'undefined') { 
      img.naturalHeight = img.height; 
      img.naturalWidth = img.width; 
   } 
   if (img.width > maxImgWidth) { 
      img.height = Math.round(((maxImgWidth)/img.width)*img.height); 
      img.width = maxImgWidth; 
      img.title = 'Click here to enlarge image'; 
      img.style.cursor = 'move'; 
   } else if (img.width == maxImgWidth && img.width < img.naturalWidth) { 
      img.height = img.naturalHeight; 
      img.width = img.naturalWidth; 
      img.title = 'Click here to resize image'; 
   } 
}

var tid = 0, x = 0, y = 0;
var obj;

document.onmousemove=track;

function track(e)
{
    x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
    y = (document.all) ? window.event.y + document.body.scrollTop : e.pageY;
}

function show(id)
{
    obj = document.getElementById("popup" +id);
    obj.style.left = x + 5;
    obj.style.top = y - 75;
    obj.style.display = "block";
    tid = window.setTimeout("show("+id+")",1);
}

function hide(id)
{
    obj = document.getElementById("popup" +id);
    window.clearTimeout(tid);
    obj.style.display = "none";
}
function msg(id, msg, saved)
{
	var klappText = document.getElementById('k' + id);

	if (klappText.style.display == 'none') {
  		klappText.style.display = 'block';
  		if(msg != 1){
  		ajax('readpm', id, msg, 0);
  		}
  		
	}
	else {
  		klappText.style.display = 'none';
	}
}

var checkflag = "false";

function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Avmarkera alla"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Markera alla"; }
}

function ajax(type, id, msg, saved) {
	var url = 'ajaxhandler.php?type=' + escape(type) + "&id=" + escape(id) + "&saved=" + escape(saved)+ "&msg=" + escape(msg);
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
				try {
					request = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e2) {
						request = false;
								}
				}

if (!request && typeof XMLHttpRequest != 'undefined') {
request = new XMLHttpRequest();
}
	request.open("GET", url, true);
	global_content = id;
	request.onreadystatechange = go;
	request.send(null);
}

function go() {
  if (request.readyState == 4) {
	  if (request.status == 200) {
		var response = request.responseText;
		if(response!= '1337')
		document.getElementById("mess" + global_content).innerHTML = response;
	  }
  }
}

var lastsok = '';

function songsearch() {

  var ord = document.getElementById("ssearch").value;
  ord = ord.replace(/^\s+|\s+$/g, '');
  if(ord != lastsok && ord.length > 1)
  {
      
    document.getElementById("innansida").innerHTML = '<h2>Searching&nbsp;&nbsp;</h2>';
    document.getElementById("searchloader").innerHTML = '<img src="pic/loading1.gif" width="16" height="16">';
    lastsok = ord;
    window.location.href = '#song=' + escape(ord);
    try{
      sokrequest.abort();
    }
      catch(e){
    }

    var url = 'ajax_songsearch.php?q=' + escape(ord);
    if(window.XMLHttpRequest)
    {
      sokrequest = new XMLHttpRequest();
    }
    else
    {
      sokrequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    sokrequest.open("GET", url, true);
    sokrequest.onreadystatechange = songgo;
    sokrequest.send(null);
    
  }

}

function songgo() {
  if (sokrequest.readyState == 4) {
	  if (sokrequest.status == 200) {
		
      var ord = document.getElementById("ssearch").value;
      var respons = sokrequest.responseText;
      document.getElementById("sida").innerHTML = respons;
      document.getElementById("innansida").innerHTML = '<h2>Search results on "' + ord + '"</h2>';
      document.getElementById("searchloader").innerHTML = '';
	  }
  }
}

var lastsok2 = '';

var ord = '';
var soktid = 0;
var soklengd = 10; // med 50 i speed
var totaltid = 40;

function torrsearch() {

  ord = document.getElementById("tsearch").value;
  ord = ord.replace(/^\s+|\s+$/g, '');
  if(ord != lastsok2 && ord.length > 1)
  {
    var sord = ord.replace(' ','_');
    document.getElementById("innansida").innerHTML = '<h2>Searching&nbsp;&nbsp;</h2>';
    document.getElementById("searchloader").innerHTML = '<img src="pic/loading1.gif" width="16" height="16">';
    window.location.href = '#search=' + sord;
    
    lastsok2 = ord;
    BorjaSok();   
    
  }

}

function tgo() {
  if (sokrequest2.readyState == 4) {
	  if (sokrequest2.status == 200) {
	  
      //ord = document.getElementById("tsearch").value;
      var respons = sokrequest2.responseText;
      document.getElementById("sida").innerHTML = respons;
      document.getElementById("innansida").innerHTML = '<h2>Search results on "' + ord + '"</h2>';
      document.getElementById("searchloader").innerHTML = '';
	  }
  }
}


function BorjaSok()
{
  if(soktid <= 0)
  {
    setTimeout("KanskeSoka()", 50);
  }
  soktid = totaltid;
}

function KanskeSoka()
{
  soktid -= soklengd;
  if(soktid <= 0)
  {
    
    try{
      sokrequest2.abort();
    }
      catch(e){
    }

    var url = 'ajax_tsearch.php?q=' + escape(ord);
    if(window.XMLHttpRequest)
    {
      sokrequest2 = new XMLHttpRequest();
    }
    else
    {
      sokrequest2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    sokrequest2.open("GET", url, true);
    sokrequest2.onreadystatechange = tgo;
    sokrequest2.send(null);


    soktid = 0;
  }
  else
  {
    setTimeout("KanskeSoka()", 50);
  }

}
