var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1));
var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera')!=-1) {
    var is_opera = true;
    var is_opera_preseven = (window.opera && !document.childNodes);
    var is_opera_seven = (window.opera && document.childNodes);
}


function openMenu(ID,DU)
{
 document.getElementById(ID).style.background='url(bilder/obutton.gif)';
 document.getElementById(DU).style.visibility='visible';
// document.getElementById(DU).style.border='1px solid #660000';
}

function closeMenu(ID,DU)
{
 document.getElementById(ID).style.background='url(bilder/button.gif)';
 document.getElementById(DU).style.visibility='hidden';
// document.getElementById(DU).style.border='0px none #660000';
}


function popup(image,topic)
{
 if(!topic)topic="";
 win=window.open("","","width=100,height=100,left=50,top=50,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
 _CODE="";
 _CODE+="<"+"html>\n";
 _CODE+="<"+"title>";
 _CODE+=topic;
 _CODE+="<"+"/title>\n";
 _CODE+="<"+"link rel=\"stylesheet\" href=\"style/popup.css\" />";
 _CODE+="<"+"script>\n";
 _CODE+="function resize()\n";
 _CODE+="{\n";
 _CODE+="window.resizeTo(document.images[0].width,document.images[0].height);\n";
 _CODE+="}\n";
 _CODE+="<"+"/script>\n";
 _CODE+="<"+"body onload=\"resize();\">\n";
 _CODE+="<"+"table style=\"position:absolute;\">\n";
 _CODE+="<"+"tr>";
 _CODE+="<"+"td class=\"popknapp\">\n";
 _CODE+="<"+"a href=\"#\" onclick=\"javascript:window.print()\">";
 _CODE+="skriv ut bild<"+"/a>\n";
 _CODE+="<"+"/td>";
 _CODE+="<"+"td class=\"popknapp\">\n";
 _CODE+="<"+"a href=\"#\" onclick=\"javascript:window.close()\">";
 _CODE+="st&auml;ng f&ouml;nster<"+"/a>\n";
 _CODE+="<"+"/td>";
 _CODE+="<"+"/tr>\n";
 _CODE+="<"+"/table>\n";
 _CODE+="<"+"img src=\""+image+"\">\n";
 _CODE+="<"+"/body>\n";
 _CODE+="<"+"/html>\n";
 win.document.write(_CODE);
 win.document.close();
 win.focus();
}

var rot13map;

function rot13init()
{
  var map = new Array();
  var s   = "abcdefghijklmnopqrstuvwxyz";
  
  for (i=0; i<s.length; i++)
    map[s.charAt(i)]			= s.charAt((i+13)%26);
  for (i=0; i<s.length; i++)
    map[s.charAt(i).toUpperCase()]	= s.charAt((i+13)%26).toUpperCase();
  return map;
}

function decode(a)
{
  if (!rot13map)
    rot13map=rot13init();
  s = "";
  for (i=0; i<a.length; i++)
    {
      var b = a.charAt(i);

      s	+= (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
    }
  return s;
}

function mejl(adress) {
	/*window.location = "mailto" + unescape("%3A") + adress + unescape("%40") + dom;*/
	window.location = "mailto" + unescape("%3A") + decode(adress);
}

function overMenu()
{
}

function popup_info(id)
{
	win=window.open("","","width=320,height=240,left=50,top=50,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
	win.location = "personinfo.php?id=" + id;
}


function insertTags(tagOpen, tagClose, sampleText, ID) {

	var txtarea = document.getElementsByName(ID)[0];
	
	//txtarea.value += 'dd';
	
	// IE
	if(document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if(!theSelection) { theSelection=sampleText;}
		txtarea.focus();
		if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var scrollTop=txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if(!myText) { myText=sampleText;}
		if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
		  txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();

		var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
		txtarea.scrollTop=scrollTop;

	// All others
	} else {
		var copy_alertText=alertText;
		var re1=new RegExp("\\$1","g");
		var re2=new RegExp("\\$2","g");
		copy_alertText=copy_alertText.replace(re1,sampleText);
		copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
		var text;
		if (sampleText) {
			text=prompt(copy_alertText);
		} else {
			text="";
		}
		if(!text) { text=sampleText;}
		text=tagOpen+text+tagClose;
		document.infoform.infobox.value=text;
		// in Safari this causes scrolling
		if(!is_safari) {
			txtarea.focus();
		}
		noOverwrite=true;
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}
