var CurrentOpenDiv="";
var backdiv;
var popUpDiv;
var noScroll=false;
var scrollPosX=null;
var scrollPosY=null;

function openSection(OpenDiv)
{

	
	
	if(backdiv==null)
	{
		
		backdiv=document.createElement("div");
		backdiv.id="backdiv";
		backdiv.style.width="100%";
		backdiv.style.height="100%";
		backdiv.style.position="absolute";
		backdiv.style.zIndex="100";
		//alert(scrollPosY);
		
		//alert(backdiv.style.top);
		
		backdiv.style.backgroundColor="transparent";
		backdiv.style.overflow="hidden";
		document.body.appendChild(backdiv);
	}	
	
	
	if(CurrentOpenDiv!="")
	{
		
		thisObject=document.getElementById(CurrentOpenDiv);
		thisObject.style.visibility="hidden";
		thisObject.style.display="none";
		backdiv.style.visibility="hidden";
		backdiv.style.display="none";	
		window.onscroll=null;
		window.scrollTo(scrollPosX,scrollPosY);
		noscroll=false;
		
			
	}
	
	if(OpenDiv!=CurrentOpenDiv)
	{	
		
		getScrollPosition();
		//window.scrollTo(0,0);
		noScroll=true;
		
		window.onscroll = scrollStop;
//		window.setEvent("onscroll",scrollStop);
		
		thisObject=document.getElementById(OpenDiv);
		positionContent(thisObject);
		thisObject.style.visibility="";
		thisObject.style.display="";
		CurrentOpenDiv=OpenDiv;
		backdiv.style.visibility="";
		backdiv.style.display="";
		backdiv.onclick = function(){openSection(OpenDiv);};
		
		backdiv.style.top= (scrollPosY-1)+"px";
		backdiv.style.left="-1px";
		
	}
	else
	{
		CurrentOpenDiv="";
	}
}



function LoadIframeDiv(SourceID,DestID)
{
	
	var SourceDiv = document.getElementById(SourceID);
	
	var DestDiv = parent.document.getElementById(DestID);
	
	DestDiv.innerHTML = SourceDiv.innerHTML;
}

function hideElement(thisElementId)
{
	
	var thisElement = document.getElementById(thisElementId);
	
	thisElement.style.visibility="hidden";
	thisElement.style.display="none";
}

function showDivCLink(divElementID,linkElementID,LinkText)
{
	

	var divElement = document.getElementById(divElementID);
	
	divElement.style.visibility="";
	divElement.style.display="";
	
	var linkElement= document.getElementById(linkElementID);
	
	
	

	linkElement.href = "javascript:hideDivCLink(\"" + divElementID + "\",\"" + linkElementID + "\",\"" + linkElement.innerText + "\");"
	linkElement.innerText=LinkText;

}

function hideDivCLink(divElementID,linkElementID,LinkText)
{

	var divElement = document.getElementById(divElementID);
	
	divElement.style.visibility="hidden";
	divElement.style.display="none";
	
	var linkElement= document.getElementById(linkElementID);
	linkElement.href = "javascript:showDivCLink(\"" + divElementID + "\",\"" + linkElementID + "\",\"" + linkElement.innerText + "\");"
	linkElement.innerText=LinkText;
}


function returnURLvariable(varName)
{
	
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	var returnVal = "";
	for(var i = 0; i < hashes.length; i++)
	{
		var tempVar = hashes[i].split('=');
		if(tempVar[0].toLowerCase() == varName.toLowerCase())
		{
			returnVal=tempVar[1];
		}
	}	    
	
	return returnVal;

}

function returnWindowWidth()
{
	var theWidth;
	if (window.innerWidth)
	 	theWidth=window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		 theWidth=document.documentElement.clientWidth;
	else if (document.body)
	 	theWidth=document.body.clientWidth;
	return theWidth;
}

function returnWindowHeight()
{
	var theHeight;
	if (window.innerHeight)
	 	theHeight=window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		 theHeight=document.documentElement.clientHeight;
	else if (document.body)
		 theHeight=document.body.clientHeight;
	return theHeight;
}



function setIframeLocation(IFrameObj,newSRC) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = 'server.html';
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
    var tempIFrame=document.createElement('iframe');
    tempIFrame.setAttribute('id','RSIFrame');
    tempIFrame.setAttribute('name','RSIFrame');
    tempIFrame.style.border='0px';
    tempIFrame.style.width='0px';
    tempIFrame.style.height='0px';
    //tempIFrame.style.visibility='hidden';
    //tempIFrame.style.display='none';

    IFrameObj = document.body.appendChild(tempIFrame);
  
    if (document.frames) {
      // this is for IE5 Mac, because it will only
      // allow access to the document object
      // of the IFrame if we access it through
      // the document.frames array
      IFrameObj = document.frames['RSIFrame'];
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 
    && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('function(){setIframeLocation(IFrameObj,newSRC);}',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(newSRC);
  return false;
}

function ShowPopup(IframeUrl, IframeID, WrapperID)
{
	
	openSection(WrapperID);
	setIframeLocation(document.getElementById(IframeID),IframeUrl);
	//var showThis = ;
	//showThis.style.visibility

}

function onnavLink(thisDiv,thisID)
{
	
	var thisTitle = document.getElementById("navlinkItemTitle" +thisID);
	thisTitle.style.textDecoration = "underline";

}

function offnavLink(thisDiv,thisID)
{	
	var thisTitle = document.getElementById("navlinkItemTitle" +thisID);
	thisTitle.style.textDecoration = "none";
}

function scrollStop()
{
if(noScroll)
	{
		window.scrollTo(scrollPosX,scrollPosY);	
	}
	
	if(CurrentOpenDiv=="")
	{
		noScroll=false;
	}
	
}

function getScrollPosition()
{
	scrollPosY = f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
	


	scrollPosX = f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
	
	//return thisX + "," + thisY;
}



function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function positionContent(thisframe)
{
	//var viewNewsBox = document.getElementById("ViewNews_" + thisUID);
	thisframe.style.top = scrollPosY+(parseInt(returnWindowHeight())/2);
	thisframe.style.left = scrollPosX+(parseInt(returnWindowWidth())/2);
}


