// JavaScript Document


// Show/hide css elements.
/*function ShowElement(id,display){
  var elementstyle = document.getElementById(id).style;
  if(display == "inverse"){
    if(elementstyle.display == "block"){elementstyle.display = "none";}
	else{elementstyle.display = "block"}
  }
  else{
    if(display == true){
      elementstyle.display = "block";
    }
    else{
  	  elementstyle.display = "none";
    }
  }
}*/

function ShowElement(id,display,display_style){
  var elementstyle = document.getElementById(id).style;
  if(display == "inverse"){
    if (elementstyle.display == display_style){elementstyle.display = "none";}
	else{elementstyle.display = display_style}
  }
  else{
    if(display == true){
      elementstyle.display = display_style;
    }
    else{
  	  elementstyle.display = "none";
    }
  }
}

function EnterPressed(e) {

  var characterCode
  if(e && e.which){           // NN4 specific code
    e = e
    characterCode = e.which
  }
  else {
    e = event
    characterCode = e.keyCode // IE specific code
  }
  if (characterCode == 13) return true   // Enter key is 13
  else return false
}


/* Returns the weekday in text format. eg. 1 = måndag, 7 = söndag
   If "short" is "true" the month name is shortend to three letters. eg. sep*/
function ConvertWeekday(day_num,short){	
  
  // Convert the month to text
  switch(day_num){
    case "1" : day = "måndag"; break;
	case "2" : day = "tisdag"; break;
	case "3" : day = "onsdag"; break;
	case "4" : day = "torsdag"; break;
	case "5" : day = "fredag"; break;
	case "6" : day = "lördag"; break;
	case "0" : day = "söndag"; break;
  }
  
  if(short==true){
	day = day.substring(0,3);  
  }
  
  //day = day.replace("å","&aring;");
  
  return (day);
}

/* Returns the month in text format. eg. 09 > september
   If "short" is "true" the month name is shortend to three letters. eg. sep*/
function ConvertMonth(month_num,short){	
  
  // Convert the month to text
  switch(month_num){
    case "01" : month = "januari"; break;
	case "02" : month = "februari"; break;
	case "03" : month = "mars"; break;
	case "04" : month = "april"; break;
	case "05" : month = "maj"; break;
	case "06" : month = "juni"; break;
	case "07" : month = "juli"; break;
	case "08" : month = "augusti"; break;
	case "09" : month = "september"; break;
	case "10" : month = "oktober"; break;
	case "11" : month = "november"; break;
	case "12" : month = "december"; break;
  }
  
  if(short==true){
	month = month.substring(0,3);  
  }
  
  return (month);
}


/* Returns the date in text format. eg. 2009-02-08 > 8 februari 2009
   If "short" is "true" the month name is shortend to three letters. eg. 8 feb 2009
   
   !!! NEEDS ConvertMonth TO WORK !!!
   */
function ConvertDate(date,short){	
  // Split the date into three variables.
  var date_array = date.split("-",3);
  var year = date_array[0];
  var month = date_array[1];
  var day = date_array[2];
  
  // Remove leading zero when the day number is lower than 10.
  if(day<10) day = day.replace(/0/,"");
  
  // Convert the month to text
  month = ConvertMonth(month,short)
  
  return (day+" "+month+" "+year);
}