/**
 *  File for general element-handling in searchResult.jsp, like adding items to lists, changing
 *  styles etc.
 */


//----  general element-handlers --------
function trimString (str) {
  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}


function setColor(i){
  if(i<9){
  var color="#f"+i+""+i;
  document.getElementById('infoContainer').style.backgroundColor=color;
  i++;
  setTimeout('setColor('+i+')', 40);
  }
  else{
    document.getElementById('infoContainer').style.backgroundColor="#f0f0f0";
    return;
  }
}

function goSweLang(){
  var lang="locale=sv_SE";
  var url=window.location+"";

  if(url.charAt(url.length-1)=="#"){
    url=url.substring(0,url.length-1);
  }

  if(url.indexOf("locale=en_US")!=-1){
    url = url.replace("locale=en_US","locale=sv_SE");
    document.location.href=url;
  }
  else{
    if(url.substring(url.length-4,url.length)=="html"){
       url=url+"?"+lang;
       document.location.href=url;
    }
    else{
      if(url.indexOf("locale=sv_SE")==-1){
        url=url+"&"+lang;
        document.location.href=url;
      }
    }
  }
}

function goEngLang(){
  var lang="locale=en_US";
  var url=window.location+"";

  if(url.charAt(url.length-1)=="#"){
    url=url.substring(0,url.length-1);
  }

  if(url.indexOf("locale=sv_SE")!=-1){
    url = url.replace("locale=sv_SE","locale=en_US");
    document.location.href=url;
  }
  else{
    if(url.substring(url.length-4,url.length)=="html"){
       url=url+"?"+lang;
       document.location.href=url;
    }
    else{
      if(url.indexOf("locale=en_US")==-1){
        url=url+"&"+lang;
        document.location.href=url;
      }
    }
  }
}


function showHide(id){
           var target=document.getElementById(id);
                if (target.className=="descriptionHidden")
    		{
                  target.className='descriptionVisible';
                }
                else
                {
                  target.className='descriptionHidden';
    		}
}

function createInfoRow(propertyStr){
  var tr = document.createElement("tr");
  var td = document.createElement("td");
  if(document.getElementById("user").value=="member"){
    td.setAttribute("colSpan", "4");
  }
  else{
    td.setAttribute("colSpan", "3");
  }
  td.appendChild(document.createTextNode(propertyStr));
  tr.appendChild(td);
  return tr;
}
//----  //general element-handlers --------

