// JavaScript Document
// JavaScript Document
// stores the reference to the XMLHttpRequest object


var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 

function process(folderpath, targetpage, newsid)
{
	
	 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	 {
		retFieldDate=document.getElementById('ndateLK');
		retFieldTitle=document.getElementById('ntitleLK');
		retFieldBody=document.getElementById('dynPage_nyheder0');
		retFieldImg=document.getElementById('block_m2_shownews_img');
		retFieldTilmeld=document.getElementById('ndateTDG');
				 
		 
			xmlHttp.open("GET", folderpath + "showNews_lang_xml.php?targetpage=" + targetpage + "&newsid=" + newsid, true);
			// define the method to handle server responses
			xmlHttp.onreadystatechange = handleServerResponse;
			
			// make the server request
			xmlHttp.send(null);
			
			
	 }	
}

// executed automatically when a message is received from the server
function handleServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
	 // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		
	   // extract the XML retrieved from the server
      var xmlResponse = xmlHttp.responseXML;
	  
	  if(!xmlResponse || !xmlResponse.documentElement)
	  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);  
	  }
	  
	  var rootNodeName=xmlResponse.documentElement.nodeName;
	  
	  if(rootNodeName == "parserror")
	  {
		  throw("Invalid XML structure");
	  }
	  
	  xmlRoot=xmlResponse.documentElement;
	  
	 
	 
      // obtain the document element (the root element) of the XML structure
     
	 	  
	  // get the text message, which is in the first child of
      // the the document element
	 	  
	    titleArray = xmlRoot.getElementsByTagName("obj1");
		helloMessage=titleArray.item(0).firstChild.data;
		retFieldDate.innerHTML = helloMessage;
		
		titleArray = xmlRoot.getElementsByTagName("obj2");
		helloMessage=titleArray.item(0).firstChild.data;
		retFieldTitle.innerHTML = helloMessage;
		
		document.title = "Lange kurser - " + helloMessage + " - Askov Højskole";
		
		titleArray = xmlRoot.getElementsByTagName("obj3");
		helloMessage=titleArray.item(0).firstChild.data;
		retFieldBody.innerHTML = helloMessage;
		
		titleArray = xmlRoot.getElementsByTagName("obj4");
		helloMessage=titleArray.item(0).firstChild.data;
		retFieldImg.innerHTML = helloMessage;
		
		titleArray = xmlRoot.getElementsByTagName("obj5");
		helloMessage=titleArray.item(0).firstChild.data;
		retFieldTilmeld.innerHTML = helloMessage;	
		
		initPageSlideFade('blockS_lk', 'dynPage_nyheder');
		
		block1 = document.getElementById('blockS_lk');
		block2 = document.getElementById('dynPage_nyheder0');
		block3 = document.getElementById('arrows');
		block4 = document.getElementById('arrows1');		
		
		g=block1.offsetHeight;
		h=block2.offsetHeight;
		
		if(h>g)
		{
			block3.style.display='block';
			block4.style.display='block';
		}
		else
		{
			block3.style.display='none';
			block4.style.display='none';
		}		
		
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}


function initPageSlideFade(obj, obj1){
	scroller1 = new scrollerobj(obj);
	
	t1_pages = new Array();
	for (var i=0; i<numScrollPages; i++){
		t1_pages[i] = new scrollerobj(obj1+i, obj);
		t1_pages[i].moveTo(0,0);
	}
}
//if the browser is ok, the script is started onload..
//if(bw.bw && !pageslidefadeLoaded) onload = initPageSlideFade;