var __debug = '';
var iRequestObjId = 0;
var xmlhttp = new Array();
var ajaxUrlsToLoad = new Array();
var _windowIsLoaded = false;


/*
	Shorthand for document.getElementById
*/
function $id(id) {return document.getElementById(id)}

/* To test if a string is an email */
var _rEmailRegExp = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
function _isEmail (sTxt) {    
    return _rEmailRegExp.test(sTxt);
}

/* Trim functions */
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
};
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
};

function setCEnd(obj) 
{
    if (document.selection) 
	{ 
       obj.focus ();
       var oSel = document.selection.createRange ();  
       oSel.moveStart ('character', -obj.value.length);
       oSel.moveStart ('character', obj.value.length);
       oSel.moveEnd ('character', 0);
       oSel.select ();
    }
    else if (obj.selectionStart || obj.selectionStart == '0') 
    {
       obj.selectionStart = obj.value.length;
       obj.selectionEnd = obj.value.length;
       obj.focus ();
    }   
}


/* instead of target="_blank" */
function eLnk(obj)
{
    if (obj && obj.href)
    {
        window.open(obj.href);
    }
    return false;
}

/* instead of target="popup" */
function pop(obj)
{
    window.open(obj.href,'','status=1,width=360,height=420,scrollbars=yes');
    return false;
}

var _domain;
function mailLink(beforeAt)
{
    beforeAt = escape(beforeAt);
    _domain = escape('@'+'npinvestor'+'.'+'dk');
    document.write('<a href="mailto:'+unescape(beforeAt+_domain)+'" style="margin:0;padding:0;">'+unescape(beforeAt+_domain)+'</a>');
}

var _txtSpArr;
var _txtSaArr;
var _txtSTagNames = ['p','a','li'];
function txtS(obj)
{
    if ($id('articleText') && obj)
    {
        var s = 0;        
        if (obj.className && obj.className.length > 0)
        {           
            s = parseInt(obj.className.charAt(obj.className.length-1));
        }
        
        var _children = obj.parentNode.childNodes;
        for(var k=0;k<_children.length;k++)
        {
            if(_children[k] && _children[k].tagName == "A")
            {
                _children[k].style.color = '';
            }
        }        
        _children = null;
        delete _children;
        obj.style.color = '#414549';        
        for (var j=0; j<_txtSTagNames.length; j++)
        {
            _txtSpArr = $id('articleText').getElementsByTagName(_txtSTagNames[j]);   
            for (var i=0; i<_txtSpArr.length; i++)
            {
                _txtSpArr[i].style.fontSize = (13+s)+'px';
            } 
        }
        
        $id('articleText').style.fontSize = (13+s)+'px';
    }
    
    return false;
}

function _loadTab(obj,container)
{
    _tabChange(obj);
    _load(obj.href,container);
    return false;
}

var _tabChildren;
function _tabChange(obj)
{    
    _tabChildren = obj.parentNode.childNodes;
    for (var i=0; i<_tabChildren.length;i++)
    {        
        if(_tabChildren[i] && _tabChildren[i].tagName == "A")
        {
            if (obj == _tabChildren[i] && i == 0)
            {
                _tabChildren[i].className = "s f";
            }
            else if (obj == _tabChildren[i])
            {
                _tabChildren[i].className = "s";
            }
            else if (i==0)
            {
                _tabChildren[i].className = "f";
            }
            else
            {
                _tabChildren[i].className = "";
            }  
        }      
    }    
}

var _hvr_elm;
function hvr(obj)
{    
    if (!_hvr_elm)
    {
        _hvr_elm = document.createElement('div');
        _hvr_elm.className = 'hvr_elm_box';
        document.body.appendChild(_hvr_elm);
    }
    _hvr_elm.style.display = 'block';
    _hvr_elm.innerHTML = (obj.tagName=="IMG" && obj.alt.length > 0) ? obj.alt : obj.title;
    obj.title = '';            
}
function hvro(obj)
{
    if (_hvr_elm)
    {
        if (obj.tagName=="IMG")
        {
            obj.alt = _hvr_elm.innerHTML;
        }
        else
        {
            obj.title = _hvr_elm.innerHTML;
        }
       _hvr_elm.innerHTML = '';
       _hvr_elm.style.display = 'none';
    }
}
var _hvrWidth = 220;
var _hvrx;
var _hvry;
function _hvr_move(evt)
{
    if (_hvr_elm)
    {        
        _hvrx=0;
        _hvry=0;	
        if (document.all)
        {		
            _hvrx = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;		
            _hvry = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;    		
            _hvrx += window.event.clientX;		
            _hvry += window.event.clientY;		
	    } 
        else 
        {    		
            _hvrx = evt.pageX;		
            _hvry = evt.pageY;	
        }
        
        if (_hvr_elm.offsetX && _hvr_elm.offsetY)
        {
            _hvrx += _hvr_elm.offsetX;
            _hvry += _hvr_elm.offsetY;
        }                
        
        _hvrx += 22;
        _hvry += 4;
        
        if ((_hvrx+_hvrWidth) > document.body.offsetWidth)
        {
            _hvrx -= ((22*2) + _hvrWidth);            
        }
        
        if ((_hvry+_hvr_elm.offsetHeight) > document.body.offsetHeight)
        {
            _hvry -= ((4*2)+_hvr_elm.offsetHeight);
        }        
                
        _hvr_elm.style.left = _hvrx + "px";	        
        _hvr_elm.style.top = _hvry + "px";
    }
}

/*
	Returns an XMLHttpRequest Object
*/
function _getRequestObject () {
	var xmlhttp = null;
	if(!xmlhttp)
	{
	    if (window.XMLHttpRequest)
	    {
	        xmlhttp = new XMLHttpRequest(); 
	    }                
		else if( typeof ActiveXObject != "undefined")
		{	
 			if(!xmlhttp)
 			{
 			    try { xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); }
 			    catch(e) { xmlhttp=null; }
 			}
 			if(!xmlhttp)
 			{
 			    try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
 			    catch(e) { xmlhttp=null; }
 			}
		}			
	}
	return xmlhttp;
}

/*
	Inserts the contents of the supplied URL in the element with the supplied id.
*/
function _load(url, id, priority) 
{
    if (!_windowIsLoaded)
    {        
        priority = (priority != undefined ? priority : ajaxUrlsToLoad.length+10);
        ajaxUrlsToLoad.push(        
                {
                    Url:url,
                    ClientID:id,
                    Priority:priority
                }
            );
    }
    else
    {
        _loadAjaxObject(url,id);
    }
}

var _autoRefresh = new Array();
function _aref(id)
{
    _autoRefresh.push(
        {
            ClientID:id,
            Obj:null
        }
    );
}

function _loadAjaxObject(url,id)
{
	if ($id(id)) 
	{	    
        if ($id(id+"_load"))
        {
            var iHeight = $id(id).scrollHeight;
    	    
	        if (iHeight < 1)
	        {
	            iHeight = 250;
	        }
        
            $id(id+"_load").style.height = iHeight + "px";
            $id(id+"_load").style.minHeight = iHeight + "px";
            $id(id+"_load").style.marginTop = "-" + iHeight + "px";
            $id(id+"_load").style.lineHeight = iHeight + "px";
            $id(id+"_load").style.display = "block";
        }

		iRequestObjId++;
		xmlhttp[iRequestObjId] = _getRequestObject();
		var fCallback = _createLoadCallback(id,iRequestObjId);
		xmlhttp[iRequestObjId].onreadystatechange = fCallback;
		if (url.indexOf('?') < 1)
		{
		    url += "?rl="+new Date().getTime();
		}
		else
		{
		    url += "&rl="+new Date().getTime();
		}
        
		xmlhttp[iRequestObjId].open("get", url, true); 		
		xmlhttp[iRequestObjId].send(null);		
		
		for(var i=_autoRefresh.length-1; i >= 0; i--)
		{
		    if (_autoRefresh[i].ClientID == id)
		    {
		        if (_autoRefresh[i].Obj != null)
		        {
		            window.clearTimeout(_autoRefresh[i].Obj);
		        }
		        
		        _autoRefresh[i].Obj = window.setTimeout('_loadAjaxObject(\''+url+'\',\''+id+'\')',60000);
		    }
		}
    }
}

/*
	Creates a callback function using the supplied id as $id(id).innerHTML target.
*/
function _createLoadCallback (id,objId) {
	var sId = id;
	var sObj = xmlhttp[objId];
	return function _loadCallback () 
	    {	 
		    if (sObj.readyState==4) 
		    {		
		        if ($id(sId))
		        {        
  		            if (sObj.status==200) 
  		            {
			            $id(sId).innerHTML = sObj.responseText;
		            } 
		            else 
		            {
			            $id(sId).innerHTML = "HTTP Code: " + sObj.status;
    	            }
    	        }
    	        
    	        if ($id(sId+"_load"))
    	        {
    	            $id(sId+"_load").style.display = "none";
    	        }
	        }
        };
}

function _loadAjaxObjects()
{
    if (ajaxUrlsToLoad)    
    {   
        ajaxUrlsToLoad.sort(function(a,b) { return a.Priority - b.Priority; });
        for(var i=0;i<ajaxUrlsToLoad.length;i++)
        {
            _loadAjaxObject(ajaxUrlsToLoad[i].Url,ajaxUrlsToLoad[i].ClientID);
        }        

        //We don't want to store the objects, so we reset the array
        ajaxUrlsToLoad = new Array();
    }
}

function cmntRep(cmntID)
{
    var cmntHttp = _getRequestObject();
	cmntHttp.onreadystatechange = function() 
	    {	 
		    if (cmntHttp.readyState==4) 
		    {		        
  		        if (cmntHttp.status==200) 
  		        {  		            
			        window.alert(cmntHttp.responseText);
		        } 
	        }
        };
	cmntHttp.open('get', '/ajax_pages/comment_report.aspx?comment='+cmntID+'&rl='+new Date().getTime(), true); 		
	cmntHttp.send(null);
}

var _defaultSearchFieldText_Quotes;
var _defaultSearchFieldText_News;
var _defaultSearchFieldText_News_Inner;
function _setSearchEvents()
{
    var searchfield_quotes = $id("searchfield_quotes");    
    var searchfield_news = $id("searchfield_news");    
    var searchfield_news_inner = $id("searchfield_news_inner");    
    
    if (searchfield_quotes)
    {
        _defaultSearchFieldText_Quotes = searchfield_quotes.value;
    
        searchfield_quotes.onfocus = function()
            {
                if ($id("searchfield_quotes").value == _defaultSearchFieldText_Quotes)
                {
                    $id("searchfield_quotes").value = '';
                }
            };
            
        searchfield_quotes.onkeypress = function(evt)
            {                
                var e = window.event ? window.event : evt;
                var key = e.which ? e.which : e.keyCode;
                if (key == 13 && $id("stocksearch"))
                {
                    $id("stocksearch").click();
                    return false;
                }                                
            };
        
        searchfield_quotes.onblur = function()
            {
                if ($id("searchfield_quotes").value == '')
                {
                    $id("searchfield_quotes").value = _defaultSearchFieldText_Quotes;
                }
            };
        
    }
    
    if (searchfield_news)
    {
        _defaultSearchFieldText_News = searchfield_news.value;
    
        searchfield_news.onfocus = function()
            {
                if ($id("searchfield_news").value == _defaultSearchFieldText_News)
                {
                    $id("searchfield_news").value = '';
                }
            };
        
        searchfield_news.onblur = function()
            {
                if ($id("searchfield_news").value == '')
                {
                    $id("searchfield_news").value = _defaultSearchFieldText_News;
                }
            };
        
    }
    
    if (searchfield_news_inner)
    {
        _defaultSearchFieldText_News_Inner = searchfield_news_inner.value;
    
        searchfield_news_inner.onfocus = function()
            {
                if ($id("searchfield_news_inner").value == _defaultSearchFieldText_News_Inner)
                {
                    $id("searchfield_news_inner").value = '';
                }
            };
        
        searchfield_news_inner.onblur = function()
            {
                if ($id("searchfield_news_inner").value == '')
                {
                    $id("searchfield_news_inner").value = _defaultSearchFieldText_News_Inner;
                }
            };
        
    }
}

var _ntHeight = 150;
var _ntWidth = 310;
var _nTickRO = null;
var _nTickID = 0;
var _nTickIDtmp = "";
var _nTickW;
var _nTickInObj;
function _newsTick()
{
    _nTickRO = _getRequestObject();
    _nTickRO.onreadystatechange = function _loadCallback ()
	    {
		    if (_nTickRO.readyState==4)
		    {
  		        if (_nTickRO.status==200)
  		        {
			        _nTickIDtmp = _nTickRO.responseText;
			        if (_nTickIDtmp && _nTickIDtmp.length > 0)
			        {
			            _nTickID = parseInt(_nTickIDtmp);
			            __doTick(_nTickID,_nTickPop,true);		            
			        }
		        }     	            	        
	        }
        };
	
	if (!isNaN(_nTickID) && _nTickID > 0)
	{
	    _nTickRO.open("get", "/ajax_pages/latest_news_check.aspx?rl="+new Date().getTime()+"&newsID="+_nTickID, true);
	    _nTickRO.send(null);	
	}
}

function __doTick(newsID,tryPop,tryIn)
{
    if (!isNaN(newsID) && newsID > 0)
    {
        if (tryPop)
        {			            
            _nTickW = window.open("/ticker.aspx?newsID="+newsID,"NPinvestorNewsTicker","height="+_ntHeight+",width="+_ntWidth+",status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0");
        }
        else
        {
            _nTickW = null;
            delete _nTickW;
        }
        
        if (_nTickW && _nTickW != null)
        {
            _nTickW.moveTo(document.body.scrollWidth-_ntWidth,document.body.scrollHeight-_ntHeight);
        }
        else if (tryIn)
        {
            if (!_nTickInObj)
            {
                _nTickInObj = document.createElement("span");
                document.body.appendChild(_nTickInObj);
            }
            
            _nTickInObj.innerHTML = '<iframe id="nTickIfr" style="width:'+_ntWidth+'px;height:'+_ntHeight+'px;" scrolling="no" frameborder="0" src="/ticker.aspx?newsID='+newsID+'" class="tickFr"></iframe>';
            window.setTimeout('_nTickInObj.innerHTML = "";',_nTickTO);
        }
    }
}

var _tickExistTitle;
function tickerTitle(title)
{
    _tickExistTitle = document.title;
    _setDocumentTitleRec(title);
}

function _setDocumentTitleRec(title)
{
    document.title = title + ' - NPinvestor.dk';
    if (title.length > 0)
    {
        window.setTimeout('_setDocumentTitleRec("'+title.substr(1)+'")',230);
    }
    else
    {
        document.title = _tickExistTitle;
    }
}

function makearray(n)
{
  this.length = n;
  for(var i = 1; i <= n; i++)
  this[i] = 0;
  return this;
}

var hexa = new makearray(16);
for(var i = 0; i < 10; i++) 
{ 
    hexa[i] = i;
}
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

function hex(i)
{
    if (i < 0)
    {
        return "00";
    }
    else if (i >255)
    {
        return "ff";
    }
    else 
    {
        return "" + hexa[Math.floor(i/16)] + hexa[i%16];
    }
}

function _setObjBGColor(r, g, b, oid)
{
    var hr = hex(r); var hg = hex(g); var hb = hex(b);
    $id(oid).style.backgroundColor = "#"+hr+hg+hb;
}

/* Usage:
 *   fade(inr,ing,inb, outr,outg,outb, step);
 * example.
 *   fade(0,0,0, 255,255,255, 255);
 * fade from black to white with very slow speed.
 *   fade(255,0,0, 0,0,255, 50);
 *   fade(0xff,0x00,0x00, 0x00,0x00,0xff, 50); // same as above
 * step 2 is very fast and step 255 is very slow.
*/
var _fsr,_fsg,_fsb,_fer,_feg,_feb,_foid;
var _fint;
var step = 50;
function fade(sr, sg, sb, er, eg, eb, oid)
{
    var i = 0; 
    _fsr = sr;
    _fsg = sg;
    _fsb = sb;
    _fer = er;
    _feg = eg;
    _feb = eb;
    _foid = oid;
    _fint = window.setInterval('if (i<step) {_setObjBGColor(Math.floor(_fsr * ((step-i)/step) + _fer * (i/step)),Math.floor(_fsg * ((step-i)/step) + _feg * (i/step)),Math.floor(_fsb * ((step-i)/step) + _feb * (i/step)),_foid);i++;}else{window.clearInterval(_fint);_fint=null;}',step);
}

function fadeBlink(sr, sg, sb, er, eg, eb, oid)
{
    fade(sr,sg,sb,er,eg,eb,oid);
    fade(er,eg,eb,sr,sg,sb,oid);
}

function fixedDisPos(obj,p)
{   
    if (navigator.appVersion && navigator.appVersion.indexOf('MSIE 6') > 0)
    {        
        var margin = p == 'l' ? (490*-1)-160 : 490;
        obj.outerHTML = '<div style="position:absolute;margin-left:'+margin+'px;display:block;">'+obj.innerHTML+'</div>';
    }
    else
    {
        var margin = p == 'l' ? ((document.body.scrollWidth/2)-(960/2)-160-10) : (document.body.scrollWidth-((document.body.scrollWidth-960)/2)+10);
        var styleText = 'position:fixed;display:block;margin-left:'+margin+'px;';
        if( obj.style.setAttribute ) 
        {                 
            obj.style.setAttribute("cssText", styleText ); 
        } 
        else 
        { 
            obj.setAttribute("style", styleText ); 
        }
        styleText = null;
        delete styleText;
    }
}

function init()
{    
    //CALL EVENTS HERE
    document.onmousemove = _hvr_move;    
    _loadAjaxObjects();
    _setSearchEvents();    
    _windowIsLoaded = true;

    var tab;    
    for(var i=0; i < _autoRefresh.length; i++)
	{
	    tab = _autoRefresh[i].ClientID;
	    tab = tab.substring(0,tab.lastIndexOf('_')+1);
	    tab = tab + "menu";	    
	    tab = $id(tab);	    
	    if (tab && tab.getElementsByTagName('a').length > 0)
	    {
	        var url = tab.getElementsByTagName('a')[0].href;	        
	        if (_autoRefresh[i].Obj != null)
	        {
	            window.clearTimeout(_autoRefresh[i].Obj);
	        }
	        _autoRefresh[i].Obj = window.setTimeout('_loadAjaxObject(\''+url+'\',\''+_autoRefresh[i].ClientID+'\')',60000);
	    } 
	}
	url = null;
	delete url;
	tab = null;
	delete tab;

    if (document.body.scrollWidth > 1300 && $id('aspnetForm') && $id('skyscrape'))
    {   
        var skyscrape = $id('skyscrape');        
        //IF NO CAMPAIGN, DON'T BOTHER ALL THE POSITIONING STUFF
        if (skyscrape.innerHTML != undefined && skyscrape.innerHTML.indexOf('No matching campaign') < 0)
        {
            fixedDisPos(skyscrape,'r');
        }        
        skyscrape = null;
    }
    
    if (document.body.scrollWidth > 1500 && $id('aspnetForm') && $id('skyscrape2'))
    {   
        var skyscrape2 = $id('skyscrape2');                
        if (skyscrape2.innerHTML != undefined && skyscrape2.innerHTML.indexOf('No matching campaign') < 0)        
        {            
            fixedDisPos(skyscrape2,'l');
        }        
        skyscrape2 = null;
    }
    
    if ($id('bgbnr') && $id('aspnetForm'))
    {
        var bgbnr = $id('bgbnr');
        if (bgbnr.innerHTML != undefined && bgbnr.innerHTML.match(/<img/gi))
        {
            var rex = new RegExp(/<img.*?src=\"?([^\s\"]*)\"?[^\/>]*\/?>/gi);
            var m = rex.exec(bgbnr.innerHTML);
            if (m && m[1])
            {               
                var img = new Image();
                img.src = m[1];
                if (img.height > 400 && img.width < 21)
                {
                    var s = 'white url('+m[1]+') repeat-x scroll left top';
                    document.body.style.background = s;
                    if ($id('top_banner_box'))
                    {
                        $id('top_banner_box').style.background = s;
                    }
                    s = null;
                }
                else
                {
                    document.body.style.background = 'url('+m[1]+')';
                    $id('outer_box').style.borderLeft = $id('footer').style.borderLeft = $id('outer_box').style.borderRight = $id('footer').style.borderRight = 'solid 1px #3d769f';
                }                
                img = null;                
            }
            m = null;            
            rex = null;
        }
        bgbnr = null;
    }
    
    window.setInterval('_newsTick()',50000);    
    
    if (addthis_config && pageTracker)
    {
        addthis_config.data_ga_tracker = pageTracker;
    }
    
    if (typeof theForm != 'undefined' && typeof Sys != 'undefined' && Sys.WebForms && Sys.WebForms.PageRequestManager && Sys.WebForms.PageRequestManager.getInstance())
    {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest
            (
                function(sender,args)
                {
                    if (args.get_error() != undefined)
                   {
                       var errorMessage = args.get_error().message;
                       errorMessage = 'Der er sket en fejl:\r\n' + errorMessage;
                       args.set_errorHandled(true);
                       alert(errorMessage);
                       errorMessage = null;
                   }
                }
            );
    }
}
var addthis_config = {services_exclude: 'more,email,print',services_compact:'favorites,facebook,twitter,linkedin,plaxo,wordpress,google,live,gmail,yahoomail',ui_click: true,ui_header_color: '#343639', data_use_flash:false, data_use_cookies:false};

if ( typeof window.addEventListener != 'undefined' )
{
    window.addEventListener( 'load', init, false );
}
else if ( typeof window.attachEvent != 'undefined' ) 
{
    window.attachEvent( 'onload', init );
}
else 
{
    if ( window.onload != null ) 
    {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[init]();
      };
    }
    else
    {
      window.onload = init;
    }    
}