﻿    function openPopup(url, sName, height, width) {
        var leftSubtrahend = 5;
        var topSubtrahend = 15;
        var left = (window.screen.width - width) / 2 - leftSubtrahend;
        var top = (window.screen.height - height) / 2 - topSubtrahend;
        window.open(url, sName, "height=" + height + ", left=" + left +
                ", top=" + top + ", width=" + width);
    }
function winOpen(){
    var win = window.open("http://www.buyit.se/bokahogakusten/lista.asp?subKategori=39","Bokning","width=600,height=510,toolbar=0,resizable=0,status=0,location=0,scrollbars=1");
    win.focus();
}    
function saveDoc(){
var pnlMn = document.getElementById('pnlMain');

//Fixar viewmode till rätt format innan sparandet av doc
if(viewMode == 2){
    pnlMn.innerHTML = pnlMn.innerText; 
} 
document.getElementById("txtMain").innerText = document.getElementById("pnlMain").innerHTML;
form1.submit();
}
function selOn(ctrl){ 
ctrl.className = 'selOn';
}
function selOff(ctrl){ 
ctrl.className = 'selOff';
}
function doBold(){ 
pnlMain.document.execCommand('bold', false, null); 
}
function doItalic(){ 
pnlMain.document.execCommand('italic', false, null); 
}
function doUnderline(){ 
pnlMain.document.execCommand('underline', false, null); 
}
function InsertHorizontalRule(){ 
pnlMain.document.execCommand('InsertHorizontalRule');
}
function doStrikeThrough(){ 
pnlMain.document.execCommand('strikethrough', false, null); 
}
function RemoveFormat(){ 
pnlMain.document.execCommand('RemoveFormat'); 
}
function InsertUnorderedList(){ 
pnlMain.document.execCommand('InsertUnorderedList'); 
}
function InsertOrderedList(){ 
pnlMain.document.execCommand('InsertOrderedList'); 
}
function doUndo(){ 
pnlMain.document.execCommand('undo'); 
}
function doRedo(){ 
pnlMain.document.execCommand('redo'); 
}
/*
function InsertMarquee(){ 
pnlMain.document.execCommand('InsertMarquee'); 
}*/
function pasteFromClipboard(frm){
  if (document.execCommand){
    document.getElementById('pnlMain').focus();
    document.execCommand("paste");
  }
}
function copy(){
if (document.execCommand){
document.execCommand("copy");
}
}
function indent(){
if (document.execCommand){
document.execCommand("indent");
}
}
function outdent(){
if (document.execCommand){
document.execCommand("outdent");
}
}
function justifyright(){
if (document.execCommand){
document.execCommand("justifyright");
}
}
function justifycenter(){
if (document.execCommand){
document.execCommand("justifycenter");
}
}
function justifyfull(){
if (document.execCommand){
document.execCommand("justifyfull");
}
}
function subscript(){
if (document.execCommand){
document.execCommand("subscript");
}
}
function superscript(){
if (document.execCommand){
document.execCommand("superscript");
}
}
function doBackcolor(colr){
if (document.execCommand){
document.execCommand("backcolor","false",colr);
visa();
}
}
function doForecolor(colr){
if (document.execCommand){
document.execCommand("forecolor","false",colr);
visa2();
}
}
function doFont(fName) 
{ 
if(fName != '') 
document.execCommand('fontname', false, fName); 
} 
function doFontSize(fSize) 
{ 
if(fSize != '') 
document.execCommand('fontsize', false, fSize); 
} 
var viewMode = 1;

function doToggleView(){ 
var pnlMn = document.getElementById('pnlMain');

if(viewMode == 1){
    pnlMn.innerText = pnlMn.innerHTML; 
    viewMode = 2;    
}else{
    pnlMn.innerHTML = pnlMn.innerText; 
    viewMode = 1;
} 
}

function addToSelection(before,after){
	if(document.selection.createRange().text){
		document.selection.createRange().pasteHTML(before+document.selection.createRange().text+after);
	}
}

function clearCode(code)
{
	code = code.replace(/[”“]/gi,'"');
	code = code.replace(/[‘’]/gi,"'");
	code = code.replace(/<([\w]+) class=([^ |>]*)([^>]*)/gi, "<$1$3");
	code = code.replace(/<([\w]+) style="([^"]*)"([^>]*)/gi, "<$1$3");
	code = code.replace(/<\\?\??xml[^>]>/gi, "");
	code = code.replace(/<\/?\w+:[^>]*>/gi, "");
	code = code.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi,"");
	code = code.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi,"");
	code = code.replace(/<b([^>])*>(&nbsp;)*\s*<\/b>/gi,"");	
	code = code.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	code = code.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
	code = code.replace(/<\\?\?xml[^>]*>/gi, "") ;
	code =  code.replace( /\s*style="\s*"/gi, '' ) ;
	code = code.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
	code = code.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;

	code = code.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	code = code.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	code = code.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	
	return code;
}

function insertTable (parent, rows, cols) {
    var table = document.createElement ("TABLE");
    var tbody = document.createElement ("TBODY");
    var tr = [], td = [];

    for (var i = 0; i < rows; i++) {
        tr[i] = document.createElement ("TR");
        td[i] = [];

        for (var j = 0; j < cols; j++) {
            td[i][j] = document.createElement ("TD");
            //td[i][j].innerHTML = i + ":" + j;
            tr[i].appendChild (td[i][j]);
        }

        tbody.appendChild (tr[i]);
    }

    table.appendChild (tbody);
    parent.appendChild (table);
}


function InjectTab(objTextArea)
{
    if (document.selection && document.selection.createRange){
	var r = document.selection.createRange();
	r.text = "        ";
    } else if (objTextArea.selectionStart && objTextArea.selectionEnd){
	objTextArea.value = objTextArea.value.substring(0, objTextArea.selectionStart)
		+ "        "
		+ objTextArea.value.substring(objTextArea.selectionEnd);
    }
}


function showmenuie5(e){
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? document.body.scrollLeft+event.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX

//same concept with the vertical position
if (bottomedge<menuobj.offsetHeight)
menuobj.style.top=ie5? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
else
menuobj.style.top=ie5? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY

menuobj.style.visibility="visible"
return false
}

function hidemenuie5(e){
menuobj.style.visibility="hidden"
}

function highlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor="highlight"
firingobj.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}

function lowlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor=""
firingobj.style.color="black"
window.status=''
}
}

function jumptoie5(url,target,width,height){
window.open(url,target,'width='+width+',height='+height)
}
function jumptoie6(url,target,width,height){
window.open(url,target,'width='+width+',height='+height+',scrollbars=1')
}

function jumpto(id,lang){
if(confirm('Vill du verkligen radera denna sida?')==true){
document.location.href='delpage.aspx?id='+id.substring(4)+'&lang='+lang;
}else{
return false;
}
}

function visa(){ 
var layer = document.getElementById('palette1');
	if(layer.style.display=='none'){
		layer.style.display='block';
	} else {
		layer.style.display='none';
	}
} 
function visa2(){ 
var layer = document.getElementById('palette2');
	if(layer.style.display=='none'){
		layer.style.display='block';
	} else {
		layer.style.display='none';
	}
} 
function FontMenu(){ 
var layer = document.getElementById('FontMenu');
	if(layer.style.display=='none'){
		layer.style.display='block';
	} else {
		layer.style.display='none';
	}
} 
function FontSize(){ 
var layer = document.getElementById('FontSize');
	if(layer.style.display=='none'){
		layer.style.display='block';
	} else {
		layer.style.display='none';
	}
} 
function clears(){
if(confirm("Vill du verkligen rensa bort all HTML-kod?")){
        var pnlMain = document.getElementById('pnlMain');
        pnlMain.innerHTML = clearCode(pnlMain.innerText);
}
}







/*------------------------------TEST---------------------------------------------
	Function    : tables_action
	Description : perform an action on selected table
	Usage       :
	Arguments   : table_action - objectname + action to execute td - startpoint cell
	inserted by lvn : table operations
 ---------------------------------------------------------------------- */
	function tables_action(table_action,td) { // operations only valid on table cells
	if (td.tagName == 'TD' || td.tagName == 'TH' ) {
		var TableParts = table_action.split("_");
		var objname    = table_action.replace(/^_(.*)_[^_]*$/, '$1');
		var cmdID      = TableParts[ TableParts.length-1 ];
		var editor_obj = document.all["_" +objname + "_editor"];
		var config     = document.all[objname].config;
		var tr,td,tbody,table,newtr;
		// get the table object model
		tr = td.parentNode;
		while(tr != null && tr.tagName != 'TR'){tr = tr.parentNode;}
		if (tr != null) {
		var tbody = tr.parentNode;
		while(tbody != null && tbody.tagName != 'TBODY' && tbody.tagName != 'THEAD' && tbody.tagName != 'TFOOT'){tbody = tbody.parentNode;}
		if (tbody != null) {
		table = tbody.parentNode;
		while(table!= null && table.tagName != 'TABLE'){table = table.parentNode;}
		}
		}
	// only execute commands if table object model is complete
	if (table != null) {
	// local functions to insert rowdetails and columns
	
	function insertRowDetails(tr,newtr) {
		for (var i=0;i < tr.cells.length;i++) {newtr.insertCell(-1);}
		}

	function insertColumn(tbody,where) {
		for (var i=0;i < tbody.rows.length;i++) {
		tr = tbody.rows(i);
		if (where > tr.cells.length){tr.insertCell();} 
		else {tr.insertCell(where);}
		}
		}
	function deleteColumn(tbody,where) {
		for (var i=0;i <  tbody.rows.length;i++) {
		var tr = tbody.rows(i);
		if (tr.cells.length - 1 < where){tr.deleteCell(tr.cells.length - 1);} 
		else {tr.deleteCell(where);}
		tr = tbody.rows(i);
		if (tr.cells.length == 0){tbody.deleteRow(i);}
		}  
		}
        
	function splitCell(tbody,currTr,currTd){
	// rowspan > 1 just insert cell and decrease colspan
		if (currTd.colSpan > 1) {
		currTd.colSpan = currTd.colSpan - 1;
		currTr.insertCell(currTd.cellIndex + 1);
		} 
		else { 
	// rowspan = 1 increase colspan for all other rows and insert cell in current row
		for (var i=0;i <  tbody.rows.length;i++) {
		var tr = tbody.rows(i);
		var td = tr.cells(currTd.cellIndex);
		if (i == currTr.rowIndex) {tr.insertCell(currTd.cellIndex + 1);} 
		else {td.colSpan = td.colSpan + 1;}
		}
		}
		} 

	function mergeCells(tbody,currTr,currTd){ 
	//first check if there are cells to the right 
		if (currTd.cellIndex < currTr.cells.length-1) { 
	//get current colspan and cell to be merged's colspan add the two together to get the new one, move the content and delete the right one 
		var currColSpan = currTd.colSpan ; 
		var mergeCellColSpan = currTr.cells(currTd.cellIndex+1).colSpan; 
		var mergeCell = currTr.cells(currTd.cellIndex+1); 
		currTd.innerHTML = currTd.innerHTML + mergeCell.innerHTML; 
		currTr.deleteCell(currTd.cellIndex + 1); 
		currTd.colSpan = currColSpan+mergeCellColSpan ; 
		} 
		else {alert('Select the leftmost cell of the split to merge.');} 
		} 
		
	function splitRow(tbody,currTr,currTd){
	// check rowspan on other cells
		if (currTd.rowSpan > 1){
		currTd.rowSpan = currTd.rowSpan - 1;
		var tr = tbody.rows(currTr.rowIndex + 1);
		var where = 0;
		for (var i=0;i <  currTr.cells.length;i++) {
		if (i < currTd.cellIndex){
		if (currTr.cells(i).rowSpan < 2){where++;}
		}
		}   
		tr.insertCell(where);
		} 
		else {
		for (var i=0;i <  currTr.cells.length;i++) {
		var td = currTr.cells(i);
		if (i == currTd.cellIndex) {
		tr = tbody.insertRow(currTr.rowIndex + 1);
		tr.insertCell(0);
		} 
		else {td.rowSpan = td.rowSpan + 1;}
		}
		}
		}
	function mergeRows(tbody,currTr,currTd){
	// check if topmost of cells to merge
		var top = false;
		if (currTd.rowSpan < 2){
		for (var i=0;i <  currTr.cells.length;i++) {
		if (i !== currTd.cellIndex) {
		if (currTr.cells(i).rowSpan > 1){top = true; break;}
		}
		}
		}
		if (top){return;} 
		else {alert('Select the topmost row of the split to merge.');}
		}
	
	// execute the operation depending on the given command
	switch(cmdID.toLowerCase()) {
		case 'createcaption'      : table.createCaption();break;
		case 'deletecaption'      : table.deleteCaption();break;
		case 'createthead'        : table.createTHead();break;
		case 'deletethead'        : table.deleteTHead();break;
		case 'createtfoot'        : table.createTFoot();break;
		case 'deletetfoot'        : table.deleteTFoot();break;
		case 'insertrowtop'       : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
		case 'insertrowbottom'    : newtr = tbody.insertRow(-1);insertRowDetails(tr,newtr);break;
		case 'insertrowbefore'    : newtr = tbody.insertRow(tr.rowIndex);insertRowDetails(tr,newtr);break;
		case 'insertrowafter'     : newtr = tbody.insertRow(tr.rowIndex+1);insertRowDetails(tr,newtr);break;
		case 'insertrowstart'     : newtr = tbody.insertRow(0);insertRowDetails(tr,newtr);break;
		case 'deleterow'          : tbody.deleteRow(tr.rowIndex);break;
		case 'insertcolumnleft'   : insertColumn(tbody,0);break;
		case 'insertcolumnright'  : insertColumn(tbody,-1);break;
		case 'insertcolumnbefore' : insertColumn(tbody,td.cellIndex);break;
		case 'insertcolumnafter'  : insertColumn(tbody,td.cellIndex+1);break;
		case 'deletecolumn'       : deleteColumn(tbody,td.cellIndex);break;
		case 'insertcellleft'     : tr.insertCell(0);break;
		case 'insertcellright'    : tr.insertCell(-1);break;
		case 'insertcellbefore'   : tr.insertCell(td.cellIndex);break;
		case 'insertcellafter'    : tr.insertCell(td.cellIndex+1);break;
		case 'insertcellstart'    : tr.insertCell(0);break;
		case 'deletecell'         : tr.deleteCell(td.cellIndex);break;
		case 'splitcell'          : splitCell(tbody,tr,td);break;
		case 'mergecells'         : mergeCells(tbody,tr,td);break;
		case 'splitrow'           : splitRow(tbody,tr,td);break;
		case 'mergerows'          : mergeRows(tbody,tr,td);break;
// inserted by lvn : property pallettes
        case 'tableproperties'    : nullBorders(editor_obj.contentWindow.document,'hide'); 
                                       setGlobalVar('_editor_field',objname);
                                       setGlobalVar('_editor_table',table);
                                       showModalDialog(_editor_url + "popups/tableprop.html?"+objname,
                                                       window,
                                                       "resizable: yes; help: no; status: no; scroll: no; ");
                                       td.focus();
                                       break;
           case 'rowproperties'      : setGlobalVar('_editor_field',objname);
                                       setGlobalVar('_editor_row',tr);
                                       showModalDialog(_editor_url + "popups/rowprop.html?"+objname,
                                                       window,
                                                       "resizable: yes; help: no; status: no; scroll: no; ");
                                       td.focus();
                                       break;
           case 'cellproperties'     : setGlobalVar('_editor_field',objname);
                                       setGlobalVar('_editor_cell',td);
                                       showModalDialog(_editor_url + "popups/cellprop.html?"+objname,
                                                       window,
                                                       "resizable: yes; help: no; status: no; scroll: no; ");
                                       td.focus();
                                       break;
// end insert lvn property pallettes
           default                   : break;
        }
// if 0 table borders and the switch to show them is on: show them 
	// toggle is on : show null borders
	if (config.showborders){nullBorders(editor_obj.contentWindow.document,'show');}
		}
		} 
		return;
		}
// end insert by lvn 

/* ---------------------------------------------------------------------- */
//Fonthandling
  var Fonts = new Array();
  Fonts[0] = "Arial";
  Fonts[1] = "Sans Serif";
  Fonts[2] = "Tahoma";
	Fonts[3] = "Verdana";
	Fonts[4] = "Courier New";
	Fonts[5] = "Georgia";
	Fonts[6] = "Times New Roman";
	Fonts[7] = "Impact";
  Fonts[8] = "Comic Sans MS";

var FontSizes = new Array();
  FontSizes[0]  = "1";
  FontSizes[1]  = "2";
  FontSizes[2]  = "3";
	FontSizes[3]  = "4";
	FontSizes[4]  = "5";
	FontSizes[5]  = "6";
	FontSizes[6]  = "7";


var ToolbarList = {"selectfont": ['SelectFont', 'SelectFont', 'images/tools/fontSelector.gif', 'images/tools/fontSelector.gif'],
									 "selectsize": ['SelectSize', 'SelectSize', 'images/tools/fontSize.gif', 'images/tools/fontSize.gif']};

function generate_wysiwyg(textareaID) {
 
  var n = "textarea1";
  var toolbar;
  var toolbar2='';
	var iframe = '';  
		  
  toolbar =  '<table cellpadding="0" cellspacing="0" border="0" style="width:150px;">'
  toolbar += '<tr>';
  toolbar += '<td style="width: 106px;"><span id="FontSelecttextarea1"></span></td>';
	toolbar += '<td style="width: 44px;"><span id="FontSizestextarea1"></span></td>';
  toolbar += '<td>&nbsp;</td></tr></table>';  

  document.getElementById('textarea1').insertAdjacentHTML("afterEnd", toolbar);
	
	outputFontSelect('textarea1');
	outputFontSizes('textarea1'); 
	
  hideFonts('textarea1');
	hideFontSizes('textarea1');
	
};

function outputFontSelect(n) {

  var FontSelectObj        = ToolbarList['selectfont'];
  var FontSelect           = FontSelectObj[2];
  var FontSelectOn         = FontSelectObj[3];
  
	Fonts.sort();
	var FontSelectDropDown = new Array;
	FontSelectDropDown['textarea1']  = '<table border="0" cellpadding="0" cellspacing="0"><tr><td style=\'cursor:pointer\'><img src="' + FontSelect + '" id="selectFonttextarea1" width="106" height="16" onClick="showFonts(\'' + 'textarea1' + '\');" unselectable="on"><br>';
	FontSelectDropDown['textarea1'] += '<span id="Fontstextarea1" class="dropdownFont" style="width: 145px;">';

	for (var i = 0; i <= Fonts.length;) {
	  if (Fonts[i]) {
      FontSelectDropDown['textarea1'] += '<button type="button" onClick="formatText(\'FontName\',\'' + 'textarea1' + '\',\'' + Fonts[i] + '\')\; hideFonts(\'' + 'textarea1' + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 120px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family:' + Fonts[i] + '; font-size: 12px;">' + Fonts[i] + '</td></tr></table></button><br>';	
    }	  
	  i++;
  }
	FontSelectDropDown['textarea1'] += '</span></td></tr></table>';
	document.getElementById('FontSelecttextarea1').insertAdjacentHTML("afterBegin", FontSelectDropDown[n]);
};

function outputFontSizes(n) {

  var FontSizeObj        = ToolbarList['selectsize'];
  var FontSize           = FontSizeObj[2];
  var FontSizeOn         = FontSizeObj[3];

	FontSizes.sort();
	var FontSizesDropDown = new Array;
	FontSizesDropDown['textarea1'] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td style=\'cursor:pointer\'><img src="' + FontSize + '" id="selectSizetextarea1" width="44" height="16" onClick="showFontSizes(\'' + 'textarea1' + '\');" unselectable="on"><br>';
  FontSizesDropDown['textarea1'] += '<span id="Sizestextarea1" class="dropdownFont" style="width: 170px;">';

	for (var i = 0; i <= FontSizes.length;) {
	  if (FontSizes[i]) {
      FontSizesDropDown['textarea1'] += '<button type="button" onClick="formatText(\'FontSize\',\'' + 'textarea1' + '\',\'' + FontSizes[i] + '\')\;hideFontSizes(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 145px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family: arial, verdana, helvetica;"><font size="' + FontSizes[i] + '">size ' + FontSizes[i] + '</font></td></tr></table></button><br>';	
    }	  
	  i++;
  }
	FontSizesDropDown['textarea1'] += '</span></td></tr></table>';
	document.getElementById('FontSizestextarea1').insertAdjacentHTML("afterBegin", FontSizesDropDown['textarea1']);
};


function hideFonts(n) {
  document.getElementById('Fontstextarea1').style.display = 'none'; 
};

function hideFontSizes(n) {
  document.getElementById('Sizestextarea1').style.display = 'none'; 
};

function showFonts(n) { 
  if (document.getElementById('Fontstextarea1').style.display == 'block') {
    document.getElementById('Fontstextarea1').style.display = 'none';
	}
  else {
    document.getElementById('Fontstextarea1').style.display = 'block'; 
    document.getElementById('Fontstextarea1').style.position = 'absolute';		
  }
};


function showFontSizes(n) { 
  if (document.getElementById('Sizestextarea1').style.display == 'block') {
    document.getElementById('Sizestextarea1').style.display = 'none';
	}
  else {
    document.getElementById('Sizestextarea1').style.display = 'block'; 
    document.getElementById('Sizestextarea1').style.position = 'absolute';		
  }
};
	
	
function formatText(val,ara,siz){
	if(siz.length > 1){
	doFont(siz);
	}else{
	doFontSize(siz);
	}
	}
	