/* Generella funktioner för alla sidor
John Eklund 2008
*/

function getRefToDiv(divID,oDoc) {
	if( !oDoc ) { oDoc = document; }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; }
		else {	//repeatedly run through all child layers
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				//on success, return that layer, else return nothing
				y = getRefToDiv(divID,oDoc.layers[x].document);
			}
			return y;
		}
	}
	return false;
}

function show(id, win) {
	ref = getRefToDiv(id, win);
	if( !ref ) { return; }
	if( ref.style )	//DOM & proprietary DOM
		ref.style.visibility = 'visible';
	else		//layers syntax
		ref.visibility = 'show';
}

function hide(id, win) {
	ref = getRefToDiv(id, win);
	if( !ref ) { return; }
	if( ref.style )	//DOM & proprietary DOM
		ref.style.visibility = 'hidden';
	else		//layers syntax
		ref.visibility = 'hide';
}

/*
if (document.all)			//Explorer 4,5
else if (document.layers)		//Netscape 4
else if (document.getElementById)	//Netscape 6 */
//isIE4 = (document.all) ? 1:0;
//isNN4 = (document.layers) ? 1:0;
// if (isNN4) { eval('document.'+mydoc+'.visibility = "show"'); }
// else if (isIE4) { eval('document.all.'+mydoc+'.style.visibility = "visible"');


NS4 = document.layers;
if (NS4) {
	origWidth = innerWidth;
	origHeight = innerHeight;
}


function changeclass_contents(theClass,element,value) {
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var ssheet = 0; ssheet < parent.contents.document.styleSheets.length; ssheet++){
	  for (var rule = 0; rule < parent.contents.document.styleSheets[ssheet][cssRules].length; rule++) {
	   if (parent.contents.document.styleSheets[ssheet][cssRules][rule].selectorText == theClass) {
	    parent.contents.document.styleSheets[ssheet][cssRules][rule].style[element] = value;
	   }
	  }
	}
}

function changeclass(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var ssheet = 0; ssheet < document.styleSheets.length; ssheet++){
	  for (var rule = 0; rule < document.styleSheets[ssheet][cssRules].length; rule++) {
	   if (document.styleSheets[ssheet][cssRules][rule].selectorText == theClass) {
	    document.styleSheets[ssheet][cssRules][rule].style[element] = value;
	   }
	  }
	}
}

function refresh() {
	if (NS4) {
		if (innerWidth != origWidth || innerHeight != origHeight) 
			location.reload();
	}
	else top.location.reload();
}

function emitfixedlayer(id, left, top) {
	/* Netscape 4, IE 4.x-5.0/Win ... */
	document.write('<style type="text/css">#'+id+' { position: absolute; left: '+left+'px; top: '+top+'px; }');

	/* Opera 5+, Netscape6+/Mozilla, Konqueror, Safari, OmniWeb 4.5+, iCab, ICEbrowser */
	document.write('body > div#'+id+' { position: fixed; }</style>');

	/* IE5.5+/Win - this is more specific than the IE 5.0 version */
	/* document.write('<!--[if gte IE 5.5]> <![if lt IE 7]> \ <-- removed because IE7 needs strict mode to support position:fixed and I dare not change modes... */
	document.write('<!--[if gte IE 5.5]> \
<style type="text/css"> div#'+id+' { \
left: expression( ( '+left+' + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + \'px\' ); \
top: expression( ( '+top+' + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + \'px\' ); } </style> \
<![endif]-->');
/* <![endif]> <-- removed before above line */
}

/*
function getobj(id){
	if (document.getElementById)
		return document.getElementById(id).style
	else if (document.all)
		return eval('document.all.' + id + '.style');
}
*/

function emitfixedlayer_bottom(id, left, bottom) {
	/* Netscape 4, IE 4.x-5.0/Win ... */
	document.write('<style type="text/css">#'+id+' { position: absolute; left: '+left+'px; bottom: '+bottom+'px; }');

	/* Opera 5+, Netscape6+/Mozilla, Konqueror, Safari, OmniWeb 4.5+, iCab, ICEbrowser */
	document.write('body > div#'+id+' { position: fixed; }</style>');

	/* IE5.5+/Win - this is more specific than the IE 5.0 version */
	/* document.write('<!--[if gte IE 5.5]> <![if lt IE 7]> \ <-- removed because IE7 needs strict mode to support position:fixed and I dare not change modes... */
	document.write('<!--[if gte IE 5.5]> \
<style type="text/css"> div#'+id+' { \
left: expression( ( '+left+' + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + \'px\' ); \
top: expression( ( -'+bottom+' - ' +id+ '.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + \'px\' ); } </style> \
<![endif]-->');
/* <![endif]> <-- removed before above line */
}

