/* opens a new window with width and height */
function newWindow(url, hoyde, bredde) {
	var name = "window";
	var features ="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=1,resizable=1,width="+bredde+",height="+hoyde
	vindu = window.open(url, name, features);
}

/* opens a new window */
function winOpen(url, width, height) {
	time = new Date();
	theName = Math.ceil(time);
	var options='';
	if (width != null) {
		options += 'width='+width;
	}
	if (height != null) {
		options += ',height='+height;
	}
	options += ',resizable=yes, scrollbars=false';
	w = window.open (url, theName, options);
}


/* Shows the specified poll */
function showPoll(pollId, width, height) {
	// dim the background
	if (!objectplanet.Dimmer) {
		alert("The objectplanet.Dimmer.js module not found");
	}
	var poll = document.getElementById(pollId);
	objectplanet.Dimmer.dim(poll);
	
	// calculate the relative left position	
	width = width ? width : 320;
	height = height ? height : 320;
	var leftPos = Math.round(document.body.clientWidth * 0.5 - width * 0.5);

	// place and show the poll
	poll.style.position = 'fixed';
	poll.style.width = width + "px";
	poll.style.height = height + "px";
	poll.style.left = leftPos + "px";
	poll.style.top = '10%';
	poll.style.visibility = 'visible';
}


/* Shows the specified external url */
function showSurvey(id, url, width, height) {
	if (navigator.appName.indexOf('icrosoft') >= 0) {
		window.open(url,'',"width=" + width + ",height=" + height + ",directories=no,location=0,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no");
	}
	else {
		var form = document.getElementById(id);
		objectplanet.Dimmer.dim(form);
		var centerX = document.body.clientWidth * 0.5;
		form.style.left = (centerX - (width * 0.5)) + 'px';
		form.style.visibility = 'visible';
	}
}

/* Hides the specified floating element */
function hideFloat(id) {
	var form = document.getElementById(id);
	if (form) {
		form.style.visibility = 'hidden';
		objectplanet.Dimmer.hide();
	}
}

/* highlights the box */
function addBoxHighlight(box, headerId, contentId) {
	var header = document.getElementById(headerId);
	var content = document.getElementById(contentId);
	box.onmouseover = function() {
		content.style.borderLeft = "1px solid #accc80";
		content.style.borderRight = "1px solid #accc80";
		content.style.borderBottom = "1px solid #accc80";
	};
	box.onmouseout = function() {
		content.style.borderLeft = "1px solid #f7f7f7";
		content.style.borderRight = "1px solid #f7f7f7";
		content.style.borderBottom = "1px solid #f7f7f7";
	};
	box.onmousedown = box.onmouseout;
}

/* Sets the link of the top menu home item */
function setHomeLink() {
	var homeMenu = document.getElementById("topMenuHome");
	var homeMenuLink = document.getElementById("topMenuHomeLink");
	if (homeMenu && homeMenuLink) {
		if (document.location && (document.location + "").indexOf("opinio") > 0) {
			homeMenuLink.href = "/opinio/";
			homeMenu.onclick = function() {
				document.location = "/opinio/";
			}
		}
		else if (document.location && (document.location + "").indexOf("probe") > 0) {
			homeMenuLink.href = "/probe/";
			homeMenu.onclick = function() {
				document.location = "/probe/";
			}
		}
		else if (document.location && (document.location + "").indexOf("easycharts") > 0) {
			homeMenuLink.href = "/easycharts/";
			homeMenu.onclick = function() {
				document.location = "/easycharts/";
			}
		}
		else {
			homeMenuLink.href = "/";
			homeMenu.onclick = function() {
				document.location = "/";
			}
		}
	}
}

this.tooltip = function(){	
	xOffset = 10;
	yOffset = 20;		
	$(".tooltip").hover(function(e){											  
			this.t = this.title;
			this.title = "";									  
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");		
	    },
		function(){
			this.title = this.t;		
			$("#tooltip").remove();
	    }
	);	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
}
