/* GENERAL FUNCTIONS - START */

function showPic(image) { 	
	try {
		popUpWin.close();
	} catch(e){
	 // nothing
	}
	popUpWin = window.open("http://app.weblogg.no/simple/popup.bd?action=viewPopup&image=" + image,'image','width=100,height=100');	
	popUpWin.focus();
}

function parseQueryString (str) {
  str = str ? str : location.search;
  var query = str.charAt(0) == '?' ? str.substring(1) : str;
  var args = new Object();
  if (query) {
    var fields = query.split('&');
    for (var f = 0; f < fields.length; f++) {
      var field = fields[f].split('=');
      args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
    }
  }
  return args;
}

// Displays the blogsoft navbar1 in a blog
function showNavBar1() {
	var html = '';
	html += '<link href="http://localhost:8500/xblog/shared/css/header.css" rel="stylesheet" type="text/css" />';
	html += '<div id="navbar1">';
	html += '<form id="navbar1-form" action="http://app.weblogg.no/index.bd" method="post">';
	html += '<table border="0" cellpadding="0" cellspacing="0">';
	html += '<tr>';
	html += '<td>Søk i denne bloggen:</td>';
	html += '<td><input id="navbar1-field" name="criteria" type="text" class="formField" /></td>';
	html += '<td><input id="navbar1-btn-search" type="hidden" name="bl_id" value="4157" /><input type="hidden" name="fa" value="search.do" /><input name="Submit" type="submit" class="formButton" value="Søk" /></td>';
	html += '<td><a href=""><img id="navbar1-logo" src="pbblogsoftlogo1.gif" /></a></td>';
	html += '<td><div id="navbar1-btn-new" class="button"><a href="http://app.weblogg.no/index.bd?fa=login.newuser&lid=1">Få din egen blogg</a></div></td>';
	html += '</tr>';
	html += '</table>';
	html += '</form>';
	html += '</div>'
	document.write(html);
}

function myunescape(str) {
	str = "" + str;
	while (true) {
		var i = str . indexOf ('+');
		if (i < 0)
			break;
			str = str . substring (0, i) + '%20' + str . substring (i + 1, str . length);
	}
	return unescape (str);
}

/* GENERAL FUNCTIONS - END */

/* CALENDAR FUNCTIONS - START */

function checkIt(s) {
	place = detect.indexOf(s) + 1;
	thestring = s;
	return place;
}

function wrapIt(s) {
	re=/;/g
	return s.replace(re, "; ")
}

var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, thestring, place;

if (checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('k-meleon')) {
	browser = "K-Meleon";
	var rv = detect.match(/k-meleon ([\w.]+)/);

	if (rv) {
		rv = rv[0];
		version = rv.substr(3);
	}
}
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer";
else if (checkIt('moz')) browser = "Firefox";   //added 26.09.06
else if (!checkIt('compatible')) {
	browser = "Netscape Navigator"
	version = detect.charAt(8);

	if (typeof(navigator.product) != "undefined") {
		browser = "Mozilla";
		rv = navigator.userAgent.match(/([Mozilla ]?Fire\w+)\/([\w|\+.]+)/);
		
		if (rv) {
			browser = rv[1];
			version = rv[2];
		}
		else {
			rv = navigator.userAgent.match(/rv:([\w|\+.]+)/);

			if (rv) {
				rv = rv[0];
				version = rv.substr(3);
			}
		}
	}
}
else browser = "An unknown browser";

if (!version) {
	version = detect.charAt(place + thestring.length);
}

var browsername = "";

if (browser)
	browsername += browser;

if (version)
	browsername += " " + version;


// Default displaytype
var displayType = "block";

if (browser == "Internet Explorer")
	displayType = "block";
else if(browser == "Opera")
	displayType = "table-row";
else if(browser == "Firefox")		//added 26.09.06
	displayType = "table-row";		//added 26.09.06 - block doesn't work with firefox

function toggleDay(dayFieldId, entryBoxId) {
	if (document.getElementById) {

		// Day cell (td)
		dayField = document.getElementById(dayFieldId);
		
		// Assign span that hold the entries
		entryBox = document.getElementById(entryBoxId);
		
		if (entryBox.style.display == displayType) {
			// Hide content
			//var sURL = unescape(window.location.pathname); -	reload the page if nothing else works
			//window.location.replace( sURL );					-not an optimal solution
			entryBox.style.display = "none";
			dayField.className = "cssDayMouseOut";
		} 
		else {
			// Show content
			entryBox.style.display = displayType;
			dayField.className = "cssDayMouseOver";
		}
	}
}

function dayMouseOver(dayFieldId, entryBoxId, style) {
	if(document.getElementById) {

		dayField = document.getElementById(dayFieldId);
		entryBox = document.getElementById(entryBoxId);

		if(entryBox.style.display != displayType) {
			switchStyle(dayFieldId, style);
		}
	}
}

function dayMouseOut(dayFieldId, entryBoxId, style) {
	if(document.getElementById) {

		dayField = document.getElementById(dayFieldId);
		entryBox = document.getElementById(entryBoxId);

		if(entryBox.style.display != displayType) {
			switchStyle(dayFieldId, style);
		}
	}
}

function switchStyle(targetId, style) {
	if(document.getElementById) {
		target = document.getElementById(targetId);
		target.className = style;
	}
}

/* CALENDAR FUNCTIONS - END */

// Remove borders on images with class "image" or "thumbnail" - DISABLED
//window.onload = function () {
//	if(document.getElementsByTagName) {
//		obj = document.getElementsByTagName("img");
//		for (var i = 0; i < obj.length; i++) {
//	   	if(obj[i].className == "thumbnail" || obj[i].className == "image") {
//				obj[i].setAttribute("style","border:0");
//			}
//		} 
//	}
//}
			
