//////////////////////////////////////////////////////
// Javascripts for viewing and editing page content //
//////////////////////////////////////////////////////

	function newWindow(url, specs) {
		window.open(url, "_blank", specs);
	}

	function uploadImageWindow() {
		url = "php/uploadImage.php";
		specs = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=no, copyhistory=no, width=300, height=100";
		newWindow(url, specs);
	}
	function selectImageWindow() {
		url = "php/selectImage.php";
		specs = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=300, height=600";
		newWindow(url, specs);
	}
	function viewInfo(nr) {
		url = "php/produkt.php?pnr=" + nr;
		specs = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=no, copyhistory=no, width=800, height=600";
		newWindow(url, specs);
	}

	function hideMessage() {
		hide("transparentBox");
		hide("transparentBoxText");
	}
	function createLink() {
		if (document.selection){
			range = document.selection.createRange();
			range.execCommand("CreateLink");
			href = range.parentElement().getAttribute("href");
			if(href.substr(0,27)!='http://www.bageribaronen.se') {
				range.parentElement().setAttribute("target", "_blank");
			}
		}
	}
	function insertImage(image,alignment) {
		imageStr = image;
		if(alignment!='center') {
			imageStr = imageStr + '"' + ' style="float:' + alignment + '; margin: 5px;"';
		}alert(imageStr);
		window.opener.document.execCommand('InsertImage', false, imageStr );
		if(alignment=='center') {		
			window.opener.document.execCommand('JustifyCenter');
		}
		window.close()
	}
	function pagemenuSelect(section,selected) {
		document.getElementById( "selected_" + section ).value = selected;
		document.getElementById( "select_" + section ).submit();
	}
	function pagemenuSave(section) {
		menuObj = document.getElementById('dragdrop_menyval');

		// Varje rad
		for( i = 0; i < menuObj.childNodes.length; i++ ) {
			// Firefox puts in lots of #text nodes...skip these
			if( menuObj.childNodes[i].nodeName=='#text' ) continue;

			rowObj = menuObj.childNodes[i];	
			
			// Varje menyruta
			for( j = 0; j < rowObj.childNodes.length; j++ ) {
				// Firefox puts in lots of #text nodes...skip these
				if( rowObj.childNodes[j].nodeName=='#text' ) continue;

				colObj = rowObj.childNodes[j].childNodes[2];	
				
				// Varje menyval (Item)
				for( k = 0; k < colObj.childNodes.length; k++ ) {
					if( colObj.childNodes[k].nodeName=='INPUT' ) {
						endObj = colObj.childNodes[k];
						if( k > 0 ) {
							oldName = endObj.getAttribute('name');
							endObj.setAttribute('name', "sub" + oldName );
						}
					}
				}
			}
		}
		document.getElementById( "save_" + section ).submit();
	}
	function edit(section) {
		hide( "view_" + section );
		show( "edit_" + section );
	}
	function view(section) {
		hide( "edit_" + section );
		show( "view_" + section );
	}
	function disableControls(section) {
		hide( "controls_" + section );
	}
	function enableControls(section) {
		show( "controls_" + section );
	}
	function save(section) {
		var content = document.getElementById( "editable_" + section ).innerHTML;
		content = content.replace( /<BR>/g, "<br />" );
		content = content.replace( /P>/g, "p>" );
		content = content.replace( /<P/g, "<p" );
		content = content.replace( /STRONG>/g, "b>" );
		content = content.replace( /EM>/g, "i>" );
		content = content.replace( /A>/g, "a>" );
		content = content.replace( /<A/g, "<a" );
		content = content.replace( /UL>/g, "ul>" );
		content = content.replace( /OL>/g, "ol>" );
		content = content.replace( /LI>/g, "li>" );
		content = content.replace( /IMG>/g, "img>" );
		content = content.replace( /<IMG/g, "<img" );

		document.getElementById( "edited_" + section ).value = content;
		document.getElementById( "save_" + section ).submit();
	}

///END////////////////////////////////////////////////
// Javascripts for viewing and editing page content //
//////////////////////////////////////////////////////
