//use: $('mainContent')
function $() {	// from prototype
	var elements = new Array();
	
	for (var i = 0; i < arguments.length; ++i) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}

function openDiv(id){
	$(id).style.display='block';
}

function closeDiv(id){
	$(id).style.display='none';
}

function writeToDiv(id, text){
	$(id).innerHTML = text;
}

function toggle( targetId ){
  if (document.getElementById){
        target = document.getElementById( targetId );
           if (target.style.display == "none"){
              target.style.display = "block";
           } else {
              target.style.display = "none";
           }
     }
} 

function goto(url){
	window.location.href=url;
}

function popup(url, name, height, width, toolbar, menubar, location, scrollbar, resizable){
	window.open(url, name, "height=" + height + ",width=" + width + ",toolbar=" + toolbar + ",menubar=" + menubar + ",location=" + location + ",scrollbars=" + scrollbar + ",resizable=" + resizable);
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}



function checkGuestbookInput(name, text){
	if(name==''){
		writeToDiv('statusMsg','Du m&aring;ste fylla i ditt namn');
		return false;
	}
	if(text==''){
		writeToDiv('statusMsg','Du m&aring;ste skriva något i meddelanderutan');
		return false;
	}
	return true;	
}


//popup window to display larger picture when clicking on image
//var popupWindow = "";
//function popupWindow(url, width, height) {
	// Is the same popup already open? If so, change only the url
	//if(!popupWindow.closed && popupWindow.location){
		//popupWindow.focus();
	//}else{
		//popupWindow = window.open(url,"","width=" + width + ",height=" + height + ",scrollbars=auto,status=no,toolbar=no,resizable=yes,location=no,menubar=no,directories=no")
	//}
//}


/* X: used in a few places*/
function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

function xDisplay(e,s)
{
  if(!(e=xGetElementById(e))) return null;
  if(e.style && xDef(e.style.display)) {
    if (xStr(s)) e.style.display = s;
    return e.style.display;
  }
  return null;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

function xVisibility(e, bShow)
{
  if(!(e=xGetElementById(e))) return null;
  if(e.style && xDef(e.style.visibility)) {
    if (xDef(bShow)) e.style.visibility = bShow ? 'visible' : 'hidden';
    return e.style.visibility;
  }
  return null;
}

