/* ------------------------------------------------------------
 * Common javascript routines and functions for Inreda.com 2008
 * ------------------------------------------------------------ */

/* ------------------------------------------------------------
 * GET DAY OF WEEK, MONTH, DAY, YEAR
 * ------------------------------------------------------------ */

var d         = new Date();
var weekday   = new Array("Söndag","Måndag","Tisdag","Onsdag","Torsdag","Fredag","Lördag");
var monthname = new Array("Januari","Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December");
var daynum    = new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");

/* ------------------------------------------------------------
 * GET TIME
 * ------------------------------------------------------------ */

var time      = new Date();
var hours     = time.getHours();
var minutes   = time.getMinutes();
var seconds   = time.getSeconds();

timeDay       = (hours   <  12 ? "AM" : "PM");
hours         = (hours   <= 12 ? hours : hours - 12);
hours         = (hours   <  10 ? "0" : "") + hours;
hours         = (hours   == 00 ? "12" : hours);
minutes       = (minutes <  10 ? "0" : "") + minutes;
seconds       = (seconds <  10 ? "0" : "") + seconds;

var clock     = hours + ":" + minutes + " " + timeDay;
	
/* ------------------------------------------------------------
 * DISPLAY DAY, DATE, AND TIME (MASTHEAD)
 * ------------------------------------------------------------ */

function displayDayDateTime() {
	document.write(weekday[d.getDay()] + " ");
	document.write(daynum[d.getDate()-1] + " ");
	document.write(monthname[d.getMonth()] + " ");
	document.write(clock);
	}
	
/* ------------------------------------------------------------
 * DISPLAY SCREEN ID
 * ------------------------------------------------------------ */

function fileName() { // extracts the current filename and returns it as a string
	
	var fileName = location.href.substring(location.href.lastIndexOf("/") + 1);
	
	if(fileName.indexOf("?") != -1)
		fileName = fileName.substring(0,fileName.indexOf("?"));
	if(fileName.indexOf("#") != -1)
		fileName = fileName.substring(0,fileName.indexOf("#"));
	
	return(fileName);
	}

/* ------------------------------------------------------------
 * INLINE JAVASCRIPT LINK SCRIPT
 * ------------------------------------------------------------ */

var NUM_CHECKED_BOX = 0;

function goToURL(theTarget,theURL,theState) {
	if (theState != "DYNAMIC")
	  eval(theTarget + ".location='" + theURL + "'");
	else if (theState == "DYNAMIC" && NUM_CHECKED_BOX == 1)
	  eval(theTarget + ".location='" + theURL + "'");
	else
	  alert("Please select one, and only one, course for which to view details.");
	}
	
/* ------------------------------------------------------------
 * POPUP WINDOW: GLOBAL VARIABLE(S)
 * ------------------------------------------------------------ */

var POPWIN  = null;

/* ------------------------------------------------------------
 * POPUP WINDOW: CLOSE EXISTING POPUP WINDOW
 * ------------------------------------------------------------ */

function closePopWin(theWin) {
  if ((theWin != null) && (theWin.closed != true))
  	theWin.close();
	}

/* ------------------------------------------------------------
 * POPUP WINDOW: DISPLAY POPUP WINDOW
 * ------------------------------------------------------------ */

function popWindow(loc,w,h) {

  closePopWin(POPWIN);	// closes an existing popup window if user opens 
                				// new window before closing existing window
	
	if (!(w)) var winW = screen.width - 100; 
	else      var winW = w + 20;
	if (!(h)) var winH = screen.height - 150; 
	else      var winH = h + 20;
		
	var params  = "width=" + winW + ",height=" + winH + ",status=yes,toolbar=no,directories=no,scrollbars=yes,resizable=yes,menubar=no,location=no,top=50,left=50,screeny=50,screenx=50";

	POPWIN = window.open(loc,"FHSC",params);
	POPWIN.focus;
	}

/* ------------------------------------------------------------
 * HOLD THE ID OF THE SELECTED PAGE ELEMENT
 * ------------------------------------------------------------ */

var storedEl = null;
	
function storeIt(theID) {
	storedEl = theID;
	}

/* ------------------------------------------------------------
 * PUT THE SELECTION IN THE INPUT FIELD OF THE OPENER
 * ------------------------------------------------------------ */

function populateIt(theCode) {
	theStoredEl = opener.storedEl;
	opener.document.getElementById(theStoredEl).value = theCode;
	}
	
function switchMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
	parent.main.focus();
}

function gotoUrl(url) {
	if (url == "")
	return;
	location.href = url;
}		

function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
	newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function showLayer(Id){
	if (document.all) {
		document.all[Id].style.visibility = "visible";
	} else if (document.layers){
		document.layers[Id].visibility = "show";
	} else if (document.getElementById){
		document.getElementById(Id).style.visibility = "visible";
	}
}
function hideLayer(Id){
	if (document.all) {
		document.all[Id].style.visibility = "hidden";
	} else if (document.layers){
		document.layers[Id].visibility = "hide";
	} else if (document.getElementById){
		document.getElementById(Id).style.visibility = "hidden";
	}
}

function waitPreloadPage() { 
	if (document.getElementById){
		document.getElementById('infobox').style.visibility='hidden';
	}else{
		if (document.layers){ 
		document.infobox.visibility = 'hidden';
	}
	else {
		document.all.infobox.style.visibility = 'hidden';
		}
	}
	document.getElementById("infobox").innerHTML="";
	return;
}


function fn_changeBtn(objekt,text) {
	objekt.value = text;
	return true;
}
//var message="";function clickIE() {if (document.all) {(message);return false;}}function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) {if (e.which==2||e.which==3) {(message);return false;}}}
//if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}document.oncontextmenu=new Function("return false")
