// JavaScript Document
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;
}


function handleServerResponse(dText) 
{
	whatDivCont = document.getElementById(dText);
	whatDivCont.innerHTML = "<img border='0' src='fileadmin/template/main/images/ajax-loader.gif' class='ajaxGalleryLoader' />";			
		
  if (xmlHttp.readyState == 4) 
  {
	if (xmlHttp.status == 200) 
    {
		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;
		
		var titleArray1 = xmlRoot.getElementsByTagName("obj1");
		var helloMessage1=titleArray1.item(0).firstChild.data;
		
		var titleArray2 = xmlRoot.getElementsByTagName("obj2");
		var helloMessage2=titleArray2.item(0).firstChild.data;
		
			
		whatDivCont.innerHTML = helloMessage1 + helloMessage2;
		
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function goToContentAjax(maxListItem, targetpage, whatUID, objContainer, whatObj){
	
	for(var i=1; i<=maxListItem; i++){
		document.getElementById("nList" + i).className="nList";
	}	
	whatObj.className="curListItem";
	prodidTemp = whatObj.id.substr(5);
	
	
	var params = "&id=" + whatUID + "&type=" + 1000001;
	
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{			
		var date = new Date();
		var timestamp = date.getTime();		

		xmlHttp.open("POST", "index.php", true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse(objContainer);
		}
		
		// make the server request
		xmlHttp.send(params);
	 }		
}

function goToAnsatteAjax(maxListItem, targetpage, whatUID, objContainer, whatObj){
	
	for(var i=1; i<=maxListItem; i++){
		document.getElementById("nList" + i).className="nList";
	}	
	whatObj.className="curListItem";
	prodidTemp = whatObj.id.substr(5);
	
	
	var params = "&id=" + targetpage + "&tx_employer[tx_uddmedarbejder_employers]=" + whatUID + "&type=" + 1000001;
	
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{			
		var date = new Date();
		var timestamp = date.getTime();		

		xmlHttp.open("POST", "index.php", true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse(objContainer);
		}
		
		// make the server request
		xmlHttp.send(params);
	 }		
}


function goToCalendarAjax(maxListItem, targetpage, whatUID, objContainer, whatObj){
	
	for(var i=1; i<=maxListItem; i++){
		document.getElementById("nList" + i).className="block_b_news";
	}	
	whatObj.className="block_b_news";
	prodidTemp = whatObj.id.substr(5);
	
	
	var params = "&id=" + targetpage + "&tx_ttnews[tt_news]=" + whatUID + "&type=" + 1000001;
	
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{			
		var date = new Date();
		var timestamp = date.getTime();		

		xmlHttp.open("POST", "index.php", true);
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse(objContainer);
		}
		
		// make the server request
		xmlHttp.send(params);
	 }		
}


function handleServerResponse2(whatUID, whatObj) 
{
  if (xmlHttp.readyState == 4) 
  {
	if (xmlHttp.status == 200) 
    {
		if(xmlHttp.responseText=="No")
		{
			document.getElementById("theDiv1").innerHTML="Ingen galleri";
			return false;
		}
		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;
		
		var titleArray1 = xmlRoot.getElementsByTagName("obj1");
		var helloMessage1=titleArray1.item(0).firstChild.data;	
				
		var titleArray2 = xmlRoot.getElementsByTagName("obj2");
		var helloMessage2=titleArray2.item(0).firstChild.data;	
		
		var titleArray3 = xmlRoot.getElementsByTagName("obj3");
		var helloMessage3=titleArray3.item(0).firstChild.data;
		
		var titleArray4 = xmlRoot.getElementsByTagName("obj4");
		var helloMessage4=titleArray4.item(0).firstChild.data;
		
		var titleArray5 = xmlRoot.getElementsByTagName("obj5");
		var helloMessage5=titleArray5.item(0).firstChild.data;
		
		/*
		if(xmlRoot.getElementsByTagName("obj6"))
		{
			var titleArray6 = xmlRoot.getElementsByTagName("obj6");
			var helloMessage6=titleArray6.item(0).firstChild.data;
			
			var whatlinkAndSub=helloMessage6.split(",");
			if(parseInt(whatlinkAndSub[1])!=0)
			{
				document.getElementById("subNList" + whatlinkAndSub[0]).className="subNListA";
			}
		}
		*/
		window.location.hash = helloMessage4 + "|" + whatUID + "|" + whatObj.id;
		
		document.getElementById("theDiv1").innerHTML=helloMessage3;
		
		document.getElementById("slideshowTitle").innerHTML=helloMessage4;
		
		document.getElementById("blockG_text").innerHTML=helloMessage5;
		
		var ip = null;
		var aImg=new Array();
		aImg=helloMessage1.split(",");
		
		function onPreload(aImages, nImages)
		{	
			
		  var oDiv = document.getElementById("theDiv1");
		   if (nImages == aImages.length )
		   {
			
				completeObj="";
			for(var i=0; i<1; i++)
			{
					completeObj +="<div class='block_m1_6bigimg' id='blockGImg' style='background-image: url(" + aImages[i].src + ")'><div id='blendimage' style='background-image: url(" + aImages[i].src + ")'>&nbsp;</div></div>";
			}
			oDiv.innerHTML = completeObj;
			document.getElementById('startSlideShow').onmouseup=function()
			{
				nextImageSS(aImg, aImg.length, 'blockGImg', 'blendimage', 'stopSlideShow', 'startSlideShow', 'imgCount');
			} 
			document.getElementById("arrowslide").onmouseup=function()
			{
				onmouseup=nextImage(aImg, aImg.length, 'prev', 'blockGImg', 'blendimage', 'stopSlideShow', 'startSlideShow', 'imgCount');
			}
			document.getElementById("arrowslide1").onmouseup=function()
			{
				onmouseup=nextImage(aImg, aImg.length, 'next', 'blockGImg', 'blendimage', 'stopSlideShow', 'startSlideShow', 'imgCount');
			}
			document.getElementById("imgCount").innerHTML="1 / " + aImg.length;
		   }
		}
		prodid=0;
		prodidShow=0;
		//nextImageSS(aImg, aImg.length, 'blockGImg', 'blendimage', 'stopSlideShow', 'startSlideShow', 'imgCount');
		if(typeof(interval1)!='undefined')
		{
			clearInterval(interval1);		
		}
		ip = new ImagePreloader(aImg, onPreload);			
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}


function handleServerResponse3(whatUID) 
{
	var dImg=document.getElementById("theDiv2");
  if (xmlHttp.readyState == 4) 
  {
	if (xmlHttp.status == 200) 
    {
		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;
		
		var titleArray1 = xmlRoot.getElementsByTagName("obj1");
		var helloMessage1=titleArray1.item(0).firstChild.data;	
		dImg.innerHTML=helloMessage1;
		
		
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}



function goToFilmAjax(targetpage, whatUID, maxListItem, whatObj)
{
	var folderpath="fileadmin/template/main/php/";
	
	for(var i=0; i<maxListItem; i++)
	{
		document.getElementById("nList" + i).className="nList";
	}	
	whatObj.className="curListItem";
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{			
		var date = new Date();
		var timestamp = date.getTime();

		xmlHttp.open("GET", folderpath + "filmAjax_xml.php?id=" + whatUID + "&targetpage=" + targetpage + "&time=" + timestamp, true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse3(whatUID);
		}
		
		// make the server request
		xmlHttp.send(null);
	 }		
}


function goToGalleryAjax(targetpage, whatUID, maxListItem, whatObj, whatSub)
{
	var folderpath="fileadmin/template/main/php/";
	
	
	
	for(var i=0; i<maxListItem; i++)
	{
		document.getElementById("nList" + i).className="nList";
		if(document.getElementById("subNList" + i))
		{
			if((whatObj.parentNode.id.substr(0,8)!="subNList"))
			{ 
				document.getElementById("subNList" + i).className="subNList";
			}
		}		
	}
	if(!document.getElementById("subNList" + whatSub))
	{
		whatObj.className="curListItem";
	}
		if(document.getElementById("subNList" + whatSub))
		{
			document.getElementById("subNList" + whatSub).className="subNListA";
			document.getElementById("nList" + (parseInt(whatSub)+1)).className="curListItem";
		}
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{			
		var date = new Date();
		var timestamp = date.getTime();

		xmlHttp.open("GET", folderpath + "galleryAjax_xml.php?id=" + whatUID + "&targetpage=" + targetpage + "&time=" + timestamp, true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange =function()
		{
			handleServerResponse2(whatUID, whatObj);
		}
		
		// make the server request
		xmlHttp.send(null);
	 }		
}


function goToContentAjax1(maxP, arrIDString, targetpage, way, divID)
{
	maxP=parseInt(maxP);
	
	var arrID=new Array;
	arrID=arrIDString.split(",");
		
	if(typeof(prodidTemp)=="undefined")
	{
		prodidTemp=1;
	}
	prodid=(prodidTemp-1);
		
		
	
	if(way=='next')
	{
		prodid++;
	}
	if(way=='prev')
	{
		prodid--;
	}
	
	if(prodid==maxP)
	{
		prodid=0;
	}
	if(prodid==-1)
	{
		prodid=maxP-1;
	}	
	goToContentAjax(maxP, targetpage, arrID[prodid], divID, document.getElementById("nList" + (prodid+1)));
}


function goToAnsatteAjax1(maxP, arrIDString, targetpage, way, divID, whatObj)
{
	maxP=parseInt(maxP);
	
	var arrID=new Array;
	arrID=arrIDString.split(",");
		
	if(typeof(prodidTemp)=="undefined")
	{
		prodidTemp=1;
	}
	prodid=(prodidTemp-1);
		
		
	
	if(way=='next')
	{
		prodid++;
	}
	if(way=='prev')
	{
		prodid--;
	}
	
	if(prodid==maxP)
	{
		prodid=0;
	}
	if(prodid==-1)
	{
		prodid=maxP-1;
	}	
	goToAnsatteAjax(maxP, targetpage, arrID[prodid], divID, document.getElementById("nList" + (prodid+1)));
}


function goToCalendarAjax1(maxP, arrIDString, targetpage, way, divID, whatObj)
{
	maxP=parseInt(maxP);
	
	var arrID=new Array;
	arrID=arrIDString.split(",");
		
	if(typeof(prodidTemp)=="undefined")
	{
		prodidTemp=1;
	}
	prodid=(prodidTemp-1);
		
		
	
	if(way=='next')
	{
		prodid++;
	}
	if(way=='prev')
	{
		prodid--;
	}
	
	if(prodid==maxP)
	{
		prodid=0;
	}
	if(prodid==-1)
	{
		prodid=maxP-1;
	}	
	goToCalendarAjax(maxP, targetpage, arrID[prodid], divID, document.getElementById("nList" + (prodid+1)));
}


function overText(obj, colorize){
	obj.style.color = colorize;	
}

function outText(obj, colorize){
	obj.style.color = colorize;	
}

function overList(objS, bClassCur, bClass)
{
	if(objS.className==bClassCur)
	{
		objS.className=bClassCur;
	}
	else
	{
		objS.className=bClass;
	}
}

function outList(objS, bClassCur, bClass)
{
	if(objS.className==bClassCur)
	{
		objS.className=bClassCur;
	}
	else
	{
		objS.className=bClass;
	}
}