//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext) {
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) { 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


/* ---------------------- Site Routines ---------------------------*/
var dom = (document.getElementById)? true:false;

/*----------- Display Control & Cosmetics Functions ----------*/
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {obj["e"+type+fn]( window.event  ); 
		}
		obj.attachEvent("on"+type, obj[type+fn]);
	} 
}


function fnFocus(obj) {
	obj.style.backgroundColor = '#f2faf9';
	obj.style.borderColor = '#75a7a3';
	obj.style.color = '#ff0000';
}

function fnBlur(obj) {
	obj.style.backgroundColor = '#ffffff';
	obj.style.borderColor = '#75a7a3';
	obj.style.color = '#000000';
}

function stripe() {
	var ids = document.getElementsByTagName("table");
	for(k = 0;k < ids.length; k++){
		var id = ids[k].id;		
		if(id){	
			var table = document.getElementById(id);
			var rows = table.getElementsByTagName("tr");	
			for(i = 0; i < rows.length; i++){
				if(rows[i].className == "" ) {
					sRc = (i % 2 == 0) ? "even":"odd";
					rows[i].className = sRc;
				}
				
				if(rows[i].parentNode.nodeName=='TBODY') {
					rows[i].onmouseover = function() {this.className='ruled';return false}
					if (i % 2 == 0) {
						rows[i].onmouseout = function() {this.className= "even"; return false}
					} else {
						rows[i].onmouseout = function() {this.className= "odd"; return false}
					}
				}
			}
		}
	}
}


//----------------Start RssAjaxHagnar.js ------------------------------
//OBJECTS
var MaxItem
MaxItem = 5;
//objects inside the RSS2Item object
function RSS2Enclosure(encElement)
{
	if (encElement == null)
	{
		this.url = null;
		this.length = null;
		this.type = null;
	}
	else
	{
		this.url = encElement.getAttribute("url");
		this.length = encElement.getAttribute("length");
		this.type = encElement.getAttribute("type");
	}
}

function RSS2Guid(guidElement)
{
	if (guidElement == null)
	{
		this.isPermaLink = null;
		this.value = null;
	}
	else
	{
		this.isPermaLink = guidElement.getAttribute("isPermaLink");
		this.value = guidElement.childNodes[0].nodeValue;
	}
}

function RSS2Source(souElement)
{
	if (souElement == null)
	{
		this.url = null;
		this.value = null;
	}
	else
	{
		this.url = souElement.getAttribute("url");
		this.value = souElement.childNodes[0].nodeValue;
	}
}

//object containing the RSS 2.0 item
function RSS2Item(itemxml)
{
	//required
	this.title;
	this.link;
	this.description;

	//optional vars
	this.author;
	this.comments;
	this.pubDate;

	//optional objects
	this.category;
	this.enclosure;
	this.guid;
	this.source;

	var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
	var tmpElement = null;
	for (var i=0; i<properties.length; i++)
	{
		tmpElement = itemxml.getElementsByTagName(properties[i])[0];
		if (tmpElement != null)
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}

	this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
	this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
	this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
	this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}

//objects inside the RSS2Channel object
function RSS2Category(catElement)
{
	if (catElement == null)
	{
		this.domain = null;
		this.value = null;
	}
	else
	{
		this.domain = catElement.getAttribute("domain");
		this.value = catElement.childNodes[0].nodeValue;
	}
}

//object containing RSS image tag info
function RSS2Image(imgElement)
{
	if (imgElement == null)
	{
	this.url = null;
	this.link = null;
	this.width = null;
	this.height = null;
	this.description = null;
	}
	else
	{
		imgAttribs = new Array("url","title","link","width","height","description");
		for (var i=0; i<imgAttribs.length; i++)
			if (imgElement.getAttribute(imgAttribs[i]) != null)
				eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
	}
}

//object containing the parsed RSS 2.0 channel
function RSS2Channel(rssxml)
{
	//required
	this.title;
	this.link;
	this.description;

	//array of RSS2Item objects
	this.items = new Array();

	//optional vars
	this.language;
	this.copyright;
	this.managingEditor;
	this.webMaster;
	this.pubDate;
	this.lastBuildDate;
	this.generator;
	this.docs;
	this.ttl;
	this.rating;

	//optional objects
	this.category;
	this.image;

	var chanElement = rssxml.getElementsByTagName("channel")[0];
	var itemElements = rssxml.getElementsByTagName("item");

	for (var i=0; i<itemElements.length; i++)
	{
		Item = new RSS2Item(itemElements[i]);
		this.items.push(Item);
		//chanElement.removeChild(itemElements[i]);
	}

	var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
	var tmpElement = null;
	for (var i=0; i<properties.length; i++)
	{
		tmpElement = chanElement.getElementsByTagName(properties[i])[0];

		if (tmpElement!= null) {			
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
		}
	}

	this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
	this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
}

//PROCESSES

function fnCreateXml()
{
//	var URL = "newsdataDe.asp";
	
	var URL = "inc/ajax_xml.asp";
	var poststr = " ";
	httpXml.open("POST",URL,true);
	httpXml.onreadystatechange = handleXml;
	httpXml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpXml.setRequestHeader("Content-length", poststr.length);
	httpXml.setRequestHeader("Connection", "close");
	httpXml.send(poststr);
}

function handleXml()
{
	if(httpXml.readyState == 1){					
	}else if(httpXml.readyState == 4)
	{
		//alert(httpXml.responseText)
		if (httpXml.status == 200) {
			document.getElementById("chan_items").innerHTML =httpXml.responseText;
			//getRSS(); 
		}
	}
}

//uses xmlhttpreq to get the raw rss xml
function getRSS()
{
	//call the right constructor for the browser being used
	if (window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else
		alert("not supported");
	//prepare the xmlhttprequest object

	xhr.open("GET","inc/hegnar.xml?" +new Date().getTime(),true);
	xhr.setRequestHeader("Cache-Control", "no-cache");
	xhr.setRequestHeader("Pragma", "no-cache");
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				if (xhr.responseText != null) {
					processRSS(xhr.responseXML);
				} else {
					alert("Failed to receive RSS file from the server - file not found.");
					return false;
				}
			} else {
				alert("Error code " + xhr.status + " received: " + xhr.statusText);
			}
		}
	}

	//send the request
	xhr.send(null);
}

//processes the received rss xml
function processRSS(rssxml)
{
	RSS = new RSS2Channel(rssxml);
	showRSS(RSS);
}

//shows the RSS content in the browser
function showRSS(RSS)
{
	//default values for html tags used
	var imageTag = "<img id='chan_image'";
	var startItemTag = "<div id='item'>";
	var startTitle = "<div id='item_title'>";
	var startLink = "<li id='item_link'>";
	var startDescription = "<div id='item_description'>";
	var endTag = "</div>";
	var endLink = "</li>";

	//populate channel data
	/*var properties = new Array("title","link","description","pubDate","copyright");
	for (var i=0; i<properties.length; i++)
	{
		eval("document.getElementById('chan_"+properties[i]+"').innerHTML = ''");
		curProp = eval("RSS."+properties[i]);
		if (curProp != null)		
			eval("document.getElementById('chan_"+properties[i]+"').innerHTML = curProp");
	}*/

	//show the image
//	document.getElementById("chan_image_link").innerHTML = "";
/*	if (RSS.image.src != null)
	{
		document.getElementById("chan_image_link").href = RSS.image.link;
		document.getElementById("chan_image_link").innerHTML = imageTag
			+" alt='"+RSS.image.description
			+"' width='"+RSS.image.width
			+"' height='"+RSS.image.height
			+"' src='"+RSS.image.url
			+"' "+"/>";
	}*/

	//populate the items
	document.getElementById("chan_items").innerHTML = "";

	if (RSS.items.length <5 )
	{
		MaxItem = RSS.items.length;
	}
	for (var i=0; i<MaxItem; i++)
	{
		item_html = startItemTag;
		item_html += (RSS.items[i].link == null) ? "" : startLink + '<a href="' + RSS.items[i].link + '" target="_new">';//endTag;
		item_html += (RSS.items[i].title == null) ? "" :  RSS.items[i].title + '</a>' + endLink;
		item_html += endTag;
		document.getElementById("chan_items").innerHTML += item_html;
	}

	//we're done
	//document.getElementById("chan").style.visibility = "visible";
	return true;
}

var xhr;

//----------------End RssAjaxHagnar.js ------------------------------





//------------------- Start rssAjaxDe-------------------------------------------

var unorderedArray = new Array;						// Stores records in Assending order.
var unorderedArray1 = new Array;					// Stores records in Descending order
var arCls = new Array;
var frmNm = document.frmPost;
var dom = (document.getElementById)? true:false
if (dom) {
	doc = "document.getElementById(\"";
	sty = "\").style";
	wrp = "\")";
	htm = "\").innerHTML";
}

var http = getHttpObject();
var httpXml = getHttpObject();

function getHttpObject()
{
	var XMLHttp;
	try
	{
		XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");				
	}
	catch(e)
	{
		try
		{
			XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			XMLHttp = new XMLHttpRequest();
			//XMLHttp = false;
			
		}
	}
	return XMLHttp;
}


function fnPostdata()
{
	//var URL = "http://www.estatemedia.no/newsdataDe.asp";
	var URL = "inc/ajax_bridge.asp";
	var poststr = " ";
	http.open("POST",URL,true);	
	http.onreadystatechange = handleHttpResponse;
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);	
}

function handleHttpResponse()
{
	if(http.readyState == 1){					
		//document.getElementById("NameList").style.display = 'block';
		//document.getElementById("NameList").innerHTML="In Process...Wait...";
	}else if(http.readyState == 4)
	{
		//alert("Manoj" + http.responseText)
		sData = http.responseText;
		
		if (sData=="Error") {
			//alert(fnMsg(8));
		}
		else{
			fnMakeJSArray();
			popArray(unorderedArray);
			inner3();
		}
	}
}

function fnMakeJSArray(){
	var arrMainRec;// = new Array();
	var arrSubRec;// = new Array();
	
	arrMainRec = sData.split("#|");
	
	var vb2jsi,vb2jsj;
	
	if(typeof (aRc) =='object' ){
		aRc.length = arrMainRec.length;
		unorderedArray.length = arrMainRec.length;
		unorderedArray1.length = arrMainRec.length;		
	}else{		
	}	

	aRc = new Array(2);
	for (vb2jsi=0; vb2jsi < 2; vb2jsi++) {
		aRc[vb2jsi] = new Array(arrMainRec.length)
		for (vb2jsj=0; vb2jsj < arrMainRec.length; vb2jsj++) aRc[vb2jsi][vb2jsj] = " "
	}
	
	var i; 
	i = 0;
	for(i = 0;i < arrMainRec.length; i++)
	{
		dr = arrMainRec[i];			
		arrSubRec = dr.split("#~");
		var j;
		j =0;
		for(j=0; j < arrSubRec.length; j++)
		{			
			aRc[j][i]= arrSubRec[j];				
		}
	}
}
	
function popArray(theArray) {
	for (var j=0;j<aRc[0].length;j++) {
		theArray[j] = [aRc[0][j],aRc[1][j]];		
	}		
}

function inner3() { //Used to create table of record 
	var string = new Array();
	string.push(' ');
	for (var i=0;i<unorderedArray.length;i++)
	{

	
	if (i==0) {			
			continue;		
   } else {
		//for (var j=0;j<unorderedArray[0].length;j++)  {
		var strVal = unescape(unorderedArray[i][1]);
		string.push('<li><a href="http://www.estatemedia.no/DE/FullArticle.aspx?aid='+ unorderedArray[i][0] +'" target="_new">'+strVal+'</a></li>');
		//string.push('<li><a href="http://www.estatemedia.no/Nyheter/FullArticle.aspx?aid='+ unorderedArray[i][0] +'" target="_new">'+strVal+'</a></li>');
		
		//}   
   }

}

	var writestring = string.join('');
	document.getElementById('writeroot').innerHTML = "";
	//alert("writestring = " + writestring);
	document.getElementById('writeroot').innerHTML = writestring;
}
//------------------- End rssAjaxDe-------------------------------------------

addEvent(window,"load", stripe);
