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);
}

var sele=0;

function sel(val,id)
{
	sele=val;
	//window.location = "index.php?id=" + id + "&gall=" + val;
}

function change(id)
{
	window.location = "index.php?id=" + id + "&gall=" + document.getElementById("s"+sele).value;
}

function openMenu(ID,DU)
{
	document.getElementById(ID).style.background='gray';
	document.getElementById(DU).style.visibility='visible';
//	document.getElementById(DU).style.border='1px solid #660000';
}

function closeMenu(ID,DU)
{
	document.getElementById(ID).style.background='black';
	document.getElementById(DU).style.visibility='hidden';
//	document.getElementById(DU).style.border='0px none #660000';
}

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 popup_inneutelista(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 = "inneutelista.php?id=" + id;
}

function popup_ordermeny()
{
	win=window.open("","","width=700,height=600,left=50,top=50,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
	win.location = "menynprint.php";
}

function popup_vimmel(id,gall)
{
	win=window.open("","","width=550,height=450,left=50,top=50,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
	win.location = "popvimmel.php?id=" + id + "&gall=" + gall;
}

function popup_akut(id,gall)
{
	win=window.open("","","width=550,height=450,left=50,top=50,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
	win.location = "popakut.php?id=" + id + "&gall=" + gall;
}

function popup(image,topic)
{
	if(!topic)topic="";
	win=window.open("","","width=550,height=450,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>\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+="<"+"br/"+">"+"<"+"br/"+">"+"<"+"br/"+">";
	_CODE+="<" + "div style=\"margin:auto;width:500px;\""+ ">";
	_CODE+="<"+"img src=\""+image+"\" style=\"padding:20px;border:1px solid #333;background:#cebea9;\">"+"<"+"br/"+">"+"<"+"a href=\"popvimmel.php?id=2\""+">"+"Föregående"+"<"+"/a"+">"+" "+"<"+"a href=\"\""+">"+"Nästa"+"<"+"/a"+">"+"<"+"/div"+">"+"\n";
	_CODE+="<"+"/body>\n";
	_CODE+="<"+"/html>\n";
	win.document.write(_CODE);
	win.document.close();
	win.focus();
}



function popup2(url,top){
MyWin = window.open("","","scrollbars=no,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,width=100,height=100");
with(MyWin.document){
open();
write("<html>\\n<head><scr"+"ipt>");
write("window.onresize=function(){if(document.getElementById){\\ndocument.getElementById(\'myimg\').style.width=(document.all)?document.body.clientWidth:window.innerWidth;\\ndocument.getElementById(\'myimg\').style.height=(document.all)?document.body.clientHeight:window.innerHeight;\\n}}\n");
write("awidth=(document.layers)?0:8;awidth+=(document.all)?4:0;aheight=(document.layers)?0:29;\\n");
write("window.onload=function(){ window.resizeTo(document.images[0].width+awidth,document.images[0].height+aheight); window.moveTo(parseInt(screen.width/2-document.images[0].width/2),parseInt(screen.height/2-document.images[0].height/2));\n");
write("if(document.all) document.all[\'wait\'].style.visibility=\'hidden\';\n");
write("if(document.layers) document.layers[\'wait\'].visibility=\'hide\';\n");
write("if(document.getElementById) document.getElementById(\'wait\').style.visibility=\'hidden\';\n");
write("}\\n</scr"+"ipt>\\n");
write("<title>"+top+"</title>\\n</head>\\n<body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0 rightmargin=0 style=\"overflow:hidden;\">\\n");
/*write("<div id=\'wait\' style=\'position:absolute;top:0px;left:0px;width:100px;height:100px;background-color:rgb(0,0,200);color:white;font:bold 12px Arial;\'><p> </p><p>Vänta...<br>Bilden laddas</p></div>\\n");*/
write("<img id=\"myimg\" ' src=\""+url+"\" \">\n");
write("</body>\\n</html>\\n");
close();
}
} 

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();
}
