			
//<!--

/**************************************************************
*                                                             *
* Function to safly add onload events                         *
* written by simonwillison.net                                *
* ref: www.webreference.com/programming/javascript/onloads    *
*                                                             *
**************************************************************/

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

/**************************************************************
*                                                             *
* Two examples of use:                                        *
* addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);            *
* addLoadEvent(function() { more code to run on page load }); *
*                                                             *
**************************************************************/


var win=null;
function NewWindow(mypage,w,h,bScroll,bMenu,bResize, sWinName){
	var LeftPosition, TopPosition, settings
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=((screen.height)?(screen.height-h)/2:100)-100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+bScroll+',location='+bMenu+',directories='+bMenu+',status='+bMenu+',menubar='+bMenu+',toolbar='+bMenu+',resizable='+bResize;
	
	if(win)
	{
		win.close();
		win=window.open(mypage,sWinName,settings);
		win.focus();
	}
	else
	{
		win=window.open(mypage,sWinName,settings);
//		win.resizeTo(w,h); 
		win.focus();
	}				
}

function checkSubmit(e, jsCode)
{
	var charCode = (navigator.appName == "Netscape")? e.which : e.keyCode;
	if(charCode == 13)
	{
		e.keyCode = 9;
		eval(jsCode);
	}
}


function IfSubmit(e)
{
	var charCode = (navigator.appName == "Netscape")? e.which : e.keyCode;
	if(charCode == 13)
	{
		e.keyCode = 9;
		return true;
	}
	return false;
}


function TieButton(e, btn){
		if(((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)))
		{
			e.returnValue=false;
			e.cancel=true;
			btn.click();
		}
}


function doSearchFormKeyDown(e,document_id, textbox) {    
	var objTextbox = document.getElementById(textbox)
	//if (objTextbox==null) alert('Textbox is null');
	if (objTextbox==null) return true;
	
	if(((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)))
	{
		e.returnValue=false;
		e.cancel = true;
		document.location.href = "?did=" + document_id + "&" +  objTextbox.id + "=" + objTextbox.value;return false;				
	}
	return true;
}

function doSearchForm(document_id, textbox)
{
	var loc;
	
	loc = "?did=" + document_id + "&" +  textbox.id + "=" + textbox.value;
	
	// loc is the relative path your wish to redirect to
	var b = document.getElementsByTagName('base');
	if (b && b[0] && b[0].href) {
	if (b[0].href.substr(b[0].href.length-1) == '/' && loc.charAt(0) == '/')
		loc = loc.substr(1);
	    loc = b[0].href + loc;
	}
	location.href = loc;
}


function doSearchFormFromArchive(sitedirectory_id, textbox)
{
	document.location.href = "?aid=" + sitedirectory_id + "&" +  textbox.name + "=" + textbox.value;
}

function getElement(elName)
{	
	return document.all ? document.all(elName) : document.getElementById ? document.getElementById(elName) : document.layers ? document.layers[elName] : null;
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} 

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} 
function doVoteForm(document_id, radiobutton, bUseOwnWindow)
{
	var iObjectId = getSelectedRadioValue(radiobutton)
	if(iObjectId > -1)
	{
		if(bUseOwnWindow == false)
		{
			document.location.href = "?did=" + document_id + "&documentobjectid=" +  iObjectId + "&viewtype=vote";
		}
	}
}

var wndPopUp = null;
var sImageGalleryWindowProperties = 'toolbar=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=780,height=490';

function doWndImageGallery(sImageGalleryPath, sParam)
{
	if(wndPopUp!=null)
		wndPopUp.close();
	var strParam, nw;
	strParam = 'default.aspx?';
	if(sParam) 
		strParam += sParam;
	nw = open(sImageGalleryPath + strParam, 'Archive',sImageGalleryWindowProperties);
	wndPopUp = nw;
	nw.focus();
}

function addImage(file, element)
{
	var fileId = parseInt(file.Id, 10);
	var ext = file.Fileextension;

	document.getElementById(element).value=fileId + ext;

	var width = parseInt(file.Width, 10);
	var height = parseInt(file.Height, 10);
	
	if (parseInt(width, 10)<=69 && parseInt(height,10)<=68) // and )
	{
		previewImage(fileId, ext, element, parseInt(width, 10), parseInt(height,10), file);
		return;
	}
	else
	{
		if (parseInt(width, 10)<parseInt(height,10))
		{
			previewImage(fileId, ext, element, (parseInt(width, 10)/parseInt(height,10))*68, 68, file);
		}
		else
		{
			previewImage(fileId, ext, element, 69, (parseInt(height,10)/parseInt(width, 10))*69, file);
		}
	}
}

function previewImage(fileId, ext, element, width, height, file)
{
	document.getElementById(element + 'Preview').style.backgroundImage = "url(arch/_img/w" + width + "/" + fileId + ext + ")"
	
	var rootElement = element.substring(element, element.length-5);
	if (!file.Description=='')
	{ 
		if (confirm(globalTextConfirmOverwriteImageText)) document.getElementById(rootElement + '3_t').value = file.Description;
	}
	if(document.getElementById(rootElement + '4_w')!=null) document.getElementById(rootElement + '4_w').value = file.Width;
}

var winImage=null;

function ShowImage(src,bScroll,bMenu,bResize, sWinName){
	var LeftPosition, TopPosition, settings
	
	if (document.getElementById(src))
	{	
		if (document.getElementById(src).value=='') return;
		
		settings='scrollbars='+bScroll+',location='+bMenu+',directories='+bMenu+',status='+bMenu+',menubar='+bMenu+',toolbar='+bMenu+',resizable='+bResize;
		if(winImage)
		{
			winImage=window.open('arch/_img/' + document.getElementById(src).value,sWinName,settings);
			winImage.focus();
		}
		else
		{
			winImage=window.open('arch/_img/' + document.getElementById(src).value,sWinName,settings);
			winImage.focus();
		}
	}
}

function deleteImage(src)
{
	if (document.getElementById(src)) document.getElementById(src).value='';
	
	var obj = document.getElementById(src.replace('src', '') + 'Image'); 
	if (obj)
	{
		obj.src="im/trans.gif";
		obj.width=70;
		obj.height=50;
	}
}

function addHrefFromArchive(object, element)
{	
	switch(getObjectClass(object))
	{
		case 'file_data':
			eval(element + '.value = "arch/_img/' + object.Id + object.Fileextension + '"');
			break;
		case 'folder_data':
			eval(element + '.value = ' + object.Id);
			break;
		case 'document_data':
			eval(element + '.value = "?did=' + object.Id + '"');
			break;
		case 'sitedirectory_data':			
			eval(element + '.value = "?aid=' + object.Id + '"');
			break;
		default:
			alert('Unsupported objecttype: ' + getObjectClass(object) + '\n' + 'Must be "sitedirectory_data", "document_data" or "file_data"');
	}
	
}

function addIdFromArchive(object, element)
{	
	switch(getObjectClass(object))
	{
		case 'file_data':
			eval(element + '.value = "' + object.Id + '"');
			break;
		case 'folder_data':
			eval(element + '.value = ' + object.Id);
			break;
		case 'document_data':
			eval(element + '.value = "' + object.Id + '"');
			break;
		case 'sitedirectory_data':			
			eval(element + '.value = "' + object.Id + '"');
			break;
		default:
			alert('Unsupported objecttype: ' + getObjectClass(object) + '\n' + 'Must be "sitedirectory_data", "document_data" or "file_data"');
	}
	
}

function getObjectClass(obj)
{
	if (obj && obj.constructor && obj.constructor.toString)
	{
		var arr = obj.constructor.toString().match(/function\s*(\w+)/);
		return arr && arr.length == 2 ? arr[1] : undefined;
	}
	else
	{
		return undefined;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
//expires = expires * 1000 * 60 * 60 * 24;
expires = expires * 1000 * 60 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
		


function get_random(iMax)
{
    var ranNum= Math.round(Math.random()*parseInt(iMax,10));
    if(ranNum < 1)
      return get_random(iMax);
    return ranNum;
}

/* Andrew Urquhart : Client-Side Request Object for javascript : http://andrewu.co.uk/tools/request/
COPYRIGHT:You are free to use this script for any use you wish if this comment is left intact. Feel free to enhance the script and send me the updated version. Please don't redistribute. This script is provided as is,with no warranty of any kind. Use it at your own risk. Copyright Andrew R Urquhart; VERSION:#1.3 2005-05-11 17:52 UTC*/
function RObj(ea){var LS="";var QS=new Object();var un="undefined";var x=null;var f="function";var n="number";var r="string";var e1="ERROR:Index out of range in\r\nRequest.QueryString";var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";function Err(arg){if(ea){alert("Request Object:\r\n"+arg)}};function URID(t){var d="";if(t){for(var i=0;i<t.length;++i){var c=t.charAt(i);d+=(c=="+"?" ":c)}};return unescape(d)};function OL(o){var l=0;for(var i in o){if(typeof o[i]!=f){l++}};return l};function AK(key){var auk=true;for(var u in QS){if(typeof QS[u]!=f&&u.toString().toLowerCase()==key.toLowerCase()){auk=false;return u}}if(auk){QS[key]=new Object();QS[key].toString=function(){return TS(QS[key])};QS[key].Count=function(){return OL(QS[key])};QS[key].Count.toString=function(){return OL(QS[key]).toString()};QS[key].Item=function(e){if(typeof e==un){return QS[key]}else {if(typeof e==n){var a=QS[key][Math.ceil(e)];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a}else {Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")")}}};QS[key].Item.toString=function(e){if(typeof e==un){return QS[key].toString()}else {var a=QS[key][e];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a.toString()}};QS[key].Key=function(e){var t=typeof e;if(t==r){var a=QS[key][e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e3+"("+(e?e:"")+")")}};QS[key].Key.toString=function(){return x}};return key};function AVTK(key,val){if(key!=""){var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val}};function TS(o){var s="";for(var i in o){var ty=typeof o[i];if(ty=="object"){s+=TS(o[i])}else if(ty!=f){s+=o[i]+", "}};var l=s.length;if(l>1){return(s.substring(0,l-2))}return(s==""?x:s)};function KM(k,o){var k=k.toLowerCase();for(var u in o){if(typeof o[u]!=f&&u.toString().toLowerCase()==k){return u}}}if(window.location&&window.location.search){LS=window.location.search;var l=LS.length;if(l>0){LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for(var i=0;i<l;++i){var c=LS.charAt(i);if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")){skip=true}if(c=="="&&eqAt==-1&&!skip){eqAt=i}if(c=="&"&&ampAt==-1){if(eqAt!=-1){ampAt=i}if(skip){preAmpAt=i+1};skip=false}if(ampAt>eqAt){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k}}if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){if(preAmpAt!=l){if(eqAt!=-1){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)))}else if(preAmpAt!=l-1){AVTK(URID(LS.substring(preAmpAt,l)),"")}}if(l==1){AVTK(LS.substring(0,1),"")}}}};var TC=OL(QS);if(!TC){TC=0};QS.toString=function(){return LS.toString()};QS.Count=function(){return(TC?TC:0)};QS.Count.toString=function(){return(TC?TC.toString():"0")};QS.Item=function(e){if(typeof e==un){return LS}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+"().Item("+e+")")}else {return QS[KM(e,QS)]}};return x};QS.Item.toString=function(){return LS.toString()};QS.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+"().Key("+(e?e:"")+")")};Err(e1+"().Item("+e+")")};QS.Key.toString=function(){Err(e2+"().Key")};this.QueryString=function(k){if(typeof k==un){return QS}else {var k=KM(k,QS);if(typeof QS[k]==un){t=new Object();t.Count=function(){return 0};t.Count.toString=function(){return "0"};t.toString=function(){return x};t.Item=function(e){return x};t.Item.toString=function(){return x};t.Key=function(e){Err(e3+"("+(e?e:"")+")")};t.Key.toString=function(){return x};return t}if(typeof k==n){return QS.Item(k)}else {return QS[k]}}};this.QueryString.toString=function(){return LS.toString()};this.QueryString.Count=function(){return(TC?TC:0)};this.QueryString.Count.toString=function(){return(TC?TC.toString():"0")};this.QueryString.Item=function(e){if(typeof e==un){return LS.toString()}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+".Item("+e+")")}else {return QS[KM(e,QS)]}}if(typeof e==n){Err(e1+".Item("+e+")")};return x};this.QueryString.Item.toString=function(){return LS.toString()};this.QueryString.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]=="object"&&(++c==e)){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+".Key("+(e?e:"")+")")};Err(e1+".Item("+e+")")};this.QueryString.Key.toString=function(){Err(e2+".Key")};this.Version=1.3;this.Author="Andrew Urquhart (www.andrewu.co.uk)"};var Request=new RObj(false);

function HTMLEncode(t) {
    return t.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}




/**************************************************************
*                                                             *
*  Function that shortens text to fit within a div..          *
*                                                             *
**************************************************************/
// Function to recursively look for a classname in parentnodes. 
// Returns the noe if found. Returns NULL if it reaches the beforeClassname or body-tag.
function FindParentByClass(node, classname, beforeClassname) {
    // if you do not pass a beforeClassname we'll put an unlikly class name in that parameter for you.
    beforeClassname = beforeClassname == "" ? "quite unlikely name for a css class" : beforeClassname;
    var parent = node.parentNode;

    // debugging //if(!confirm(parent.tagName + ", " + parent.className +"\n\nContinue?")) return "TERMINATE";

    // loock for classname
    var re = new RegExp('\\b' + classname + '\\b');
    if (re.test(parent.className)) {
        return parent; // good boy!
    } else {
        if (parent.className == beforeClassname) return null;
        if (parent.tagName == "BODY") return null;
        // if not found, lets take a loock at grandpa..
        return FindParentByClass(parent, classname, beforeClassname);
    }
}


// The function that loops trough all tags with the fittext-text classname
function Fixall() {
    // Get all tags with the fittext-text classname
    var divsToFix = getElementsByClassName("fittext-text-node", document);

    // Fixing all the collected boxes, one by one.
    for (i = 0; i < divsToFix.length; i++) {

        // The div to fix
        var contentNode = divsToFix[i];

        // The tag whith the height-spesifications (cannot cotinue without it)
        var outerNode = FindParentByClass(contentNode, "fittext-outer-node")
        if (outerNode == null) break;

        // The tag to compare with grandpa, if not found it is the content-node it self
        var innerNode = FindParentByClass(contentNode, "fittext-inner-node", "fittext-outer-node")
        if (innerNode == null) innerNode = contentNode;

        // First we check if the content is at all lager then the sized parent - cuz else there's just no point, is there..
        if (innerNode.offsetHeight > outerNode.offsetHeight) {
            // Remove all leading and trailing whitespace from the content div, it might throw the math off.
            contentNode.innerHTML = contentNode.innerHTML.replace(/^\s+|\s+$/g, "");

            // We don't want to split the text inside tags! So we make a copy of the text one with no tags - easy peasy..
            var contentNoTags = contentNode.innerHTML.replace(/<[^>]*>/g, function(s) { return s.replace(/./g, "_") });

            // For better performance we do some crude cuts first before we start looking for the exact fit
            // Lets split the block in half until it is undersized.
            var lastOversizedContent; // We'll want one "undo-level"
            while (innerNode.offsetHeight > outerNode.offsetHeight) {
                lastOversizedContent = contentNode.innerHTML;
                contentNode.innerHTML = contentNode.innerHTML.substr(0, contentNode.innerHTML.length / 2);
            }

            // Now the block is too small goshdarnit! Let's take one step back and do the final trimming from there.
            contentNode.innerHTML = lastOversizedContent + "&nbsp;...";
            contentNoTags = contentNoTags.substring(0, lastOversizedContent.length);

            // Now here comes the final filleting.
            while (innerNode.offsetHeight > outerNode.offsetHeight) {
                // Slice off a word, and than slice up close to a word
                contentNoTags = String(contentNoTags.match(/.*[ ,.!?]/));
                contentNoTags = String(contentNoTags.match(/.*[^ ,.!?]/));

                // Lets not be stuck here if the box is simply to small and there is no good way to resolving the issue.
                if (contentNoTags == "null") {
                    contentNode.innerHTML = ""; // no room - no text!
                    break; // I QUIT!! (I'll be back for the next div though)
                }

                lastOversizedContent = lastOversizedContent.substr(0, contentNoTags.length);
                contentNode.innerHTML = lastOversizedContent + "&nbsp;...";

                // Safety feature; Give the user a chance to stop a loop of death at every 200 steps.. Mainly for debugging use.
                // if((this.step == undefined ? this.step = 1 : ++step) % 200 == 0 && confirm(step + " steps!\n\nBreak now?")) return;
                // if (!confirm("Continue?")) return; // Debug one step at a time
            }
        }
    }
}

// Function for getting elements by class name
function getElementsByClassName(classname, node) {
    if (!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
        if (re.test(els[i].className)) a.push(els[i]);
    return a;
}

// Add the Fixall-function to the pageload event
addLoadEvent(Fixall);
/**************************************************************
*                                                             *
*  / Function that shortens text to fit within a div..        *
*                                                             *
**************************************************************/

// -->