var eSrc; 
function ieBlur() { 
	eSrc = event.srcElement 
	while ("A" != eSrc.tagName.toUpperCase() && "BODY" != eSrc.tagName.toUpperCase())
		eSrc = eSrc.parentElement; 
	if("A" == eSrc.tagName.toUpperCase())
		eSrc.blur();
} 

if(document.all) document.onmouseup = ieBlur; 

// ------------------------------- //

var bm_normal = new Image;
var bm_hover = new Image;
var bm_pinned = new Image;
var n_normal = new Image;
var n_alle = new Image;
var n_blank = new Image;
var n_pinned = new Image;
var n_hover = new Image;

var id = 0;

bm_normal.src = "http://" + document.domain + "/Skins/" + book_id + "/text/bm_normal.gif";
bm_hover.src = "http://" + document.domain + "/Skins/" + book_id + "/text/bm_hover.gif";
bm_pinned.src = "http://" + document.domain + "/Skins/" + book_id + "/text/bm_pinned.gif ";
n_normal.src = "http://" + document.domain + "/Skins/" + book_id + "/text/n_normal.gif";
n_alle.src = "http://" + document.domain + "/Skins/" + book_id + "/text/nt_pinned.gif";
n_blank.src = "http://" + document.domain + "/Skins/" + book_id + "/text/nt_normal.gif";
n_pinned.src = "http://" + document.domain + "/Skins/" + book_id + "/text/n_pinned.gif ";
n_hover.src = "http://" + document.domain + "/Skins/" + book_id + "/text/n_hover.gif ";

// ------------------------------- //
//    bookmarks                    //
// ------------------------------- //

function act(imgName) {
  if (document.images)
//  		alert(document.domain)
//		alert(document[imgName].src)  
//		alert(eval("bm_pinned.src"))
    if (document[imgName].src != eval("bm_pinned.src")) {
      document[imgName].src = eval("bm_hover.src")
		window.status = "Trykk for å sette bokmerke"
	}
	else
		window.status = "Trykk for å fjerne bokmerke"		
}

function inact(imgName) {
	if (document.images)
//		alert(document[imgName].src)
		if (document[imgName].src != eval("bm_pinned.src")) {
			document[imgName].src = eval("bm_normal.src")
	}	
}

function setBookmark(id, imgName) {
  if (document.images)
    if (document[imgName].src == eval("bm_pinned.src")) {
      document[imgName].src = eval("bm_hover.src")
	    delBookmarkDB(id)
		window.status = "Bokmerke fjernet"
	}
	else {
      document[imgName].src = eval("bm_pinned.src") 
	    setBookmarkDB(id)
		window.status = "Bokmerke satt"
	}
}

// ------------------------------- //
//    notater                      //
// ------------------------------- //

function n_act(imgName) {
  if (document.images)
    if (document[imgName].src != eval("n_pinned.src")) {
      document[imgName].src = eval("n_hover.src")
		window.status = "Trykk for å sette notat"
	}
	else
		window.status = "Trykk for å fjerne notat"		
}

function n_inact(imgName) {
	if (document.images)
		if (document[imgName].src != eval("n_pinned.src")) {
			document[imgName].src = eval("n_normal.src")
	}	
}

function setNote(id, imgName) {
  if (document.images)
    if (document[imgName].src == eval("n_pinned.src")) {
//      document[imgName].src = eval("n_hover.src")
//        document[imgName].src = eval("n_normal.src")
	    setNotatDB(id)
		window.status = "Notat fjernet"
	}
	else {
//      document[imgName].src = eval("n_pinned.src") 
	    setNotatDB(id)
		window.status = "Notat satt"
	}
}

//------------------

function setNotatDB(id) {
  window.open('/Note/setNote?block_id=' + id + '&b=' + book_id + '&pub=0', 'right')
}

//------------------

function setBookmarkDB(id) {
  window.open('/Bookmark/setBookmark?block_id=' + id + '&b=' + book_id , 'right')
}

function delBookmarkDB(id) {
//	alert('delBookmark('+id+')')
  window.open('/Bookmark/delBookmark?block_id=' + id + '&b=' + book_id, 'right')
}

//-------------------

function viewPublicNote(id) {
  window.open('/Note/setNote?block_id=' + id + '&b=' + book_id + '&pub=1', 'right')
}

//-------------------

// sett merke hvor bokmerkene skal st&aring;!
function parseBookmarks(img) {
	for (i = 0; i < img.length; i++) {
    	if (img[i].name != '') {
			re = new RegExp(img[i].name) 
			if (re.test(bms))
				img[i].src = bm_pinned.src
			if (re.test(ns))
				img[i].src = n_pinned.src
			if (re.test(as))
				img[i].src = n_alle.src
		}
	}
}

function test() {
  alert('test')
}

parseBookmarks(document.images);
