/*
 * for IE, indexOf is not self-defined...
 */
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

/*
 * remove the backslash before quotes
 * DZ 4/6/2010
 */
function removeQuoteSlash(str){
    var res = "";
    if (str == "") return res;
    res = str.replace('\\"', '"');

    return res.replace("\\'", "'");
}

function trim(s) {
	return rtrim(ltrim(s));
}

function ltrim(s) {
    var l = 0;
    while(l < s.length && s.charAt(l) == ' ') l++;
    return s.substring(l, s.length);
}

function rtrim(s) {
	var r = s.length-1;
	while(r > 0 && s.charAt(r) == ' ') r--;
	return s.substring(0, r+1);
}

function clearField(obj) {
	if (obj.id == "artistSearch" && obj.value == "Enter artist or title")
		obj.value = "";
}

function leaveField(obj) {
	if (obj.id == "artistSearch" && trim(obj.value) == "") {
		obj.value = "Enter artist or title";
    }
    else {
        obj.value = trim(obj.value);
        // showHint(obj.value);
    }
}


/*
 * Set the font color and background color of an object
 * DZ - 3/28/2010
 */
function setColorsSpan(objStr, objStr2, switchName) {
	var obj = document.getElementById(objStr);
	var obj2 = document.getElementById(objStr2);
	if (obj2.style.visibility == "visible") {
		obj.style.color = "black";
		obj.innerHTML = switchName + " On";
	}
	else {
		obj.style.color = "grey";
		obj.innerHTML = switchName + " Off";
	}	
}

function setColorsBtn(objStr, objStr2, switchName) {
	var obj = document.getElementById(objStr);
	var obj2 = document.getElementById(objStr2);
	if (obj2.style.visibility == "visible") {
		obj.style.color = "white";
		obj.value = switchName + " On";

	}
	else {
		obj.style.color = "grey";
		obj.value = switchName + " Off";
	}	
}

/*
 * Toggle a section to show/hide
 * DZ - 3/28/2010 
 */
function toggleSection(sectionId) {
	var obj = document.getElementById(sectionId); 
	if (obj.style.display == "none") {
		obj.style.display = "";
	}
	else {
		obj.style.display = "none";
	}

}

function toggleSection2(sectionId) {
	var obj = document.getElementById(sectionId); 
	if (obj.style.visibility == "hidden") {
		obj.style.visibility = "visible";
	}
	else {
		obj.style.visibility = "hidden";
		// if parameters' toggle, need to do more:
		if (sectionId == 'paras') {// stop parameters		
			obj.value = "";
		}			
	}
}

/*
 * Show/hide a section
 * DZ - 3/28/2010
 */
function showSection(sectionId, showOrHide) {
	var obj = document.getElementById(sectionId); 
	if (showOrHide == 0 && obj.style.visibility == "visible") 
		obj.style.visibility = "hidden";
	else if (showOrHide == 1 && obj.style.visibility == "hidden")
		obj.style.visibility = "visible";
}
