/* Global Javascripts */

/* Error trap 
window.onerror=errorTrap;
function errorTrap(sMsg,sUrl,sLine){
	var err="!!! A Javascript error was thrown and caught !!!\n\n";
	err += "Error: " + sMsg + "\n";
	err += "Line: " + sLine + "\n";
	err += "URL: " + sUrl;
	alert(err);
	return false;
} */

/* Generic popup function */
function PopWin(url,name,width,height,menubar,location,toolbar,scrollbars,resizable,directories) {
	window.open(url, name, 'resizable='+resizable+',menubar='+menubar+',scrollbars='+scrollbars+',location='+location+',toolbar='+toolbar+',width='+width+',height='+height +',directories='+directories+'');
}

function showComments() {
  document.getElementById('showComments').style.display='none';
  document.getElementById('pageComments').style.display='block';
}
function hideComments() {
  document.getElementById('showComments').style.display='block';
  document.getElementById('pageComments').style.display='none';
}
function abuse() {
  window.open('/comment-abuse.xml?__xsl=/templates/comment-abuse-layout.xsl&amp;page=&page.path;&amp;id=&_.id;&amp;comment=&_.comment;&amp;user=&_.user_name;','abuse','scrollbars=yes,width=260,height=370')
}
function tipFriend() {
	window.open('/tip-friend.xml?__xsl=/templates/tip-friend-layout.xsl&amp;url=&page.path;','tipsa','toolbar=no,menubar=no,width=260,height=270')
}

function rowOver(rowItem) { document.getElementById(rowItem).style.backgroundColor = '#eae7dc'; }
function rowOut(rowItem) { document.getElementById(rowItem).style.backgroundColor = ''; }

function FixTime(tm){
	if(tm<10)
		return "0" + tm;
	else
		return tm;
}

function time(ms) {
	//get days
	var days = Math.floor(ms/86400000);
	ms = ms % 86400000;
	
	//hours
	var hours = FixTime(Math.floor(ms/3600000));
	
	ms = ms % 3600000;
	
	//minutes
	var minutes = FixTime(Math.floor(ms/60000));
	ms = ms % 60000;
	
	//seconds
	var seconds = FixTime(Math.floor(ms/1000));
	ms = ms % 1000;
	
	return days + ":" + hours + ":" + minutes + ":" + seconds;	
}

// Open myPaper
function openMyPaper(pid,pnr){
	if(pnr){
		var win = window.open('http://www.mypaper.se/show/resume/show.asp?pid='+pid+'&initPage='+pnr,'mypaper'+pid,'width=1020,height=745,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
	} else {
		var win = window.open('http://www.mypaper.se/show/resume/show.asp?pid='+pid,'mypaper'+pid,'width=1020,height=745,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
	}
}