

var heightControl 
var ArrayFrameName = new Array();
var ArrayFrameHeight = new Array();


function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function getViewportHeight() {
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
    if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 	
	if (document.body) return document.body.clientWidth; 
	
	return 500;	
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}
function RefreshFromSiteEdit()
{
	var sLocation;
	
	sLocation = document.location.toString();
    sLocation = sLocation.toLowerCase();

	if ((sLocation.indexOf('?refresh=true') != -1) || (sLocation.indexOf('&refresh=true') != -1))
	{
		document.location = document.location;
	}
	else
	{
		if (sLocation.indexOf('?') != -1)
		{
			document.location = document.location + '&Refresh=True';
		}
		else
		{
			document.location = document.location + '?Refresh=True';
		}
	}
}

function RefreshParent()
{
	var sLocation;
	var sOpener = window.opener
	if (sOpener && sOpener != window)  {
		try {
			sLocation = sOpener.document.location.toString();
			sLocation = sLocation.toLowerCase();

			if ((sLocation.indexOf('?refresh=true') != -1) || (sLocation.indexOf('&refresh=true') != -1)) {
				window.opener.document.location = window.opener.document.location;
			}
			else {
				if (sLocation.indexOf('?') != -1) {
					window.opener.document.location = window.opener.document.location + '&Refresh=True';
				}
				else {
					window.opener.document.location = window.opener.document.location + '?Refresh=True';
				}
			}
		} catch (e) { }
	}
}

function ClosePopupRefreshParent()
{
	var sLocation;
	
	sLocation = window.opener.document.location.toString();
	sLocation = sLocation.toLowerCase();
	
	if ((sLocation.indexOf('?refresh=true') != -1) || (sLocation.indexOf('&refresh=true') != -1))
	{
		window.opener.document.location = window.opener.document.location;
	}
	else
	{
		if (sLocation.indexOf('?') != -1)
		{
			window.opener.document.location = window.opener.document.location + '&Refresh=True';
		}
		else
		{
			window.opener.document.location = window.opener.document.location + '?Refresh=True';
		}
	}
	
	window.close(false);
}
function CloseModalRefreshParent()
{
	var sLocation;
	
	sLocation = parent.document.location.toString();
	sLocation = sLocation.toLowerCase();
	
	parent.hidePopWin(false);
	
	if ((sLocation.indexOf('?refresh=true') != -1) || (sLocation.indexOf('&refresh=true') != -1))
	{
		parent.document.location = parent.document.location;
	}
	else
	{
		if (sLocation.indexOf('?') != -1)
		{
			parent.document.location = parent.document.location + '&Refresh=True';
		}
		else
		{
			parent.document.location = parent.document.location + '?Refresh=True';
		}
	}
}

// Add refresh=true and template=true if not already there
function CloseTemplateRefreshParent()
{
	var sLocation, sLocationOriginal;
	
	sLocationOriginal = parent.document.location.toString();
	sLocation = parent.document.location.toString().toLowerCase();

	if ((sLocation.indexOf('?refresh=true') == -1) && (sLocation.indexOf('&refresh=true') == -1))   // No refresh=true? Add it
	{
	    if (sLocation.indexOf('?') == -1)
		    sLocationOriginal = sLocationOriginal + '?refresh=true';
		else
		    sLocationOriginal = sLocationOriginal + '&refresh=true';
	}
		
	if ((sLocation.indexOf('?template=t') == -1) && (sLocation.indexOf('&template=t') == -1))       // No template=true? Add it
	{
	    if (sLocation.indexOf('?') == -1)
		    sLocationOriginal = sLocationOriginal + '?Template=T';
		else
		    sLocationOriginal = sLocationOriginal + '&Template=T';
	}
	
	parent.document.location = sLocationOriginal;
}



function HideContentIFrames()
{
	var oContent;
	var aoIFrames;
	var sSource;
	var x;
	
	oContent = parent.document.getElementById("content");
	
	if (oContent != null)
	{
		aoIFrames = oContent.getElementsByTagName('iframe');
		
		if (aoIFrames != null)
		{
			for (x=0;x<aoIFrames.length;x++)
			{
				sSource = aoIFrames[x].src;
				sSource = sSource.toLowerCase();
				
				if ((sSource.indexOf('.pdf') != -1) || (sSource.indexOf('getdocument.asp') != -1))
				{
					aoIFrames[x].style.display = 'none';
				}
			}
		}
	}
}
function Popup(theURL, Name, popW, popH, scroll, resize) 
{
	//alert(theURL);
	Name = Name.replace(/[^a-zA-Z]+/g,'');
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resize;
	Win = window.open(theURL, Name, winProp);
	if (Win)
		Win.window.focus();
	return false;
}
function QueryString_Parse(sQuery)
{
	var pairs = sQuery.substring(1).split("&");

	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;
		}
	}
}
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
} 
function SwapAdminMode(sImage, sStatus, sFrame, sPage, lIndex, sApprove, sGuest,nMode)
{	

	var oAdminImage  = document.getElementById(sImage);
	var oAdminStatus = document.getElementById(sStatus);
	var bToAdmin;
	//News/viewnews.asp
	bToAdmin = (oAdminImage.src.indexOf('admin.gif') >= 0);
	if (bToAdmin)
	{
		oAdminImage.src = 'images/user.gif';
		oAdminStatus.style.display = '';
		if(sPage == 'News/viewnews.asp')
		{
			window.frames[sFrame].document.location = sPage + '?ContentIndex=' + lIndex + '&Nmode=' + nMode + '&Mode=' + sApprove + '&Status=0';
		}
		else
		{
			window.frames[sFrame].document.location = sPage + '?ContentIndex=' + lIndex + '&Mode=' + sApprove + '&Status=0';
		}
		
	}
	else
	{
		oAdminImage.src = 'images/admin.gif';
		oAdminStatus.style.display = 'none';
		if(sPage == 'News/viewnews.asp')
		{
			window.frames[sFrame].document.location = sPage + '?ContentIndex=' + lIndex + '&Nmode=' + nMode + '&Mode=' + sGuest + '&Status=0';
		}
		else
		{
			window.frames[sFrame].document.location = sPage + '?ContentIndex=' + lIndex + '&Mode=' + sGuest + '&Status=0';
		}
		
	}
}
function SwapAdminMode1(sImage, sStatus, sFrame, sPage, lIndex, nPageID, sApprove, sGuest,nMode,sAnchor,sUAnchor)
{	
	
	var oAdminImage  = document.getElementById(sAnchor);
    var oUserImage  = document.getElementById(sUAnchor);
	var oAdminStatus = document.getElementById(sStatus);
	if (sImage == 'Admin')
	{
		oAdminImage.style.display = 'none';
		oUserImage.style.display = '';
		if(sPage == 'News/viewnews.asp' || sPage == 'PhotoGallery/ShowPhotos.asp' || sPage == 'DocumentStore/ShowDocument.asp' || sPage == 'Sponsor/ViewSponsors.asp')
		{
			window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&Nmode=' + nMode + '&Mode=' + sApprove + '&Status=0&Visible=Admin';
		}
		else if(sPage == 'Directory/events.asp')
		{
			window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&mode=edit';				
		}
		else if(sPage == 'eCommerce/Catalog.aspx')
		{
            window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&PageID=' + nPageID + '&Mode=' + nMode + '&Status=0&Visible=Admin';		
        }
		else
		{
			window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&Mode=' + sApprove + '&Status=0';
		}
		
	}
	else
	{

        oAdminImage.style.display = '';
		oUserImage.style.display = 'none';
		if(sPage == 'News/viewnews.asp' || sPage == 'PhotoGallery/ShowPhotos.asp' || sPage == 'DocumentStore/ShowDocument.asp' ||  sPage == 'Sponsor/ViewSponsors.asp' )
		{
			window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&Nmode=' + nMode + '&Mode=' + sGuest + '&Status=0&Visible=User';
		}
		else if(sPage == 'eCommerce/Catalog.aspx')
		{
            window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&PageID=' + nPageID + '&Mode=' + nMode + '&Status=0&Visible=User';		
        }
		else
		{
			window.frames[sFrame].document.location = sPage + '?UniqueHTMLID='+ sFrame +'&ContentIndex=' + lIndex + '&Mode=' + sGuest + '&Status=0';
		}
		
	}	
	setTall() ;
}

function setTall() 
{
	if (document.getElementById) {

		var divs = new Array(
			document.getElementById('pageContent'), 
			document.getElementById('left'),
			document.getElementById('right')
			);

		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			
			if (divs[i] && divs[i].offsetHeight > maxHeight) 
			{
 				maxHeight = divs[i].offsetHeight;
				
			}
		}
		
		if(maxHeight < 600)
		{
			maxHeight = 600;
		}
		
		
		for (var i = 0; i < divs.length; i++) {
			if (divs[i]) {
				divs[i].style.height = maxHeight + 'px';

				if (divs[i].offsetHeight > maxHeight) {
					maxHeight = divs[i].offsetHeight + 10;	  //Chrome and Safari resize the offset on the fly (without padding!)
				}
			}
		}
	}
	
	
	heightControl = maxHeight;
	
	
/* Commentet Temporarily . Will be removed later  	
	if (getQuerystring('Template')=="T")
	{
    	 showPopWinRight('/ContentEditor/Templateselector.asp', 330, 500, null);
	}
*/	
}
var timeOutSession;

function setSessionTimeOut(nTimeOut)
{
	clearTimeout(timeOutSession);
	timeOutSession = self.setTimeout('showTimeOutPopUp()', nTimeOut)
}

function setSessionTimeOutDefault() {
	setSessionTimeOut(1200000);
}

function showTimeOutPopUp()
{
   showPopWin('../ContentEditor/Timeout.asp', 300, 120, null,false);
}


function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}


function setTallFrames( frameHeight, frameId ) {
	var  htDifference = 0;		
	if (!document.getElementById) 
		return;
		
	var divs = new Array(
		document.getElementById('pageContent'), 
		document.getElementById('left'),
		document.getElementById('right')
		);

	// Find the max height of the three content panels
	var maxHeight = 0;
	for (var i = 0; i < divs.length; i++)
	{
		if ((divs[i]!=null) && (divs[i].offsetHeight > maxHeight) )
		{
			maxHeight = divs[i].offsetHeight + 10;
		}
	}	
		
	if (ArrayitemExists(frameId, ArrayFrameName) == false)
	{		  
		var maxlength = parseInt(ArrayFrameName.length);		   
		ArrayFrameName[maxlength] = frameId;
		ArrayFrameHeight[maxlength] = frameHeight;		   	   		   		   
	}
  
	if(heightControl > 0)
	{
		for(var i = 0; i < ArrayFrameName.length; i++)
		{		   
			if(ArrayFrameName[i] == frameId)
			{		      
				htDifference = parseInt(frameHeight) - parseInt(ArrayFrameHeight[i]);		     
				if(parseInt(htDifference) < 0)
					htDifference = 0 - parseInt(htDifference);
	   //ArrayFrameHeight[i]=htDifference;
	   
				htDifference = heightControl + htDifference;  
			}
		}

		for (var i = 0; i < divs.length; i++) 
		{            			     
            //if(maxHeight<htDifference)
            divs[i].style.height= htDifference + "px";
            //else
            //  divdd[i].style.height= maxHeight + "px";
        }
	}		
	 ////*****************************************************///	
}

function ArrayitemExists(frameid,arrayName)
{
  var status=false; //Ites does not exists in the array 
  for(var i=0;i<arrayName.length;i++)
  {  
   if(arrayName[i]==frameid)
    {      
      status=true;
      break;
    }
  } 
  return status;
}


function autoResize(id)
{
    var newheight;

    if(document.getElementById){
    newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
    }

    document.getElementById(id).height= (newheight) + "px";
}


function SetStatusImageBorder(frameId,StatusImageame)
{
	//alert(frameId);
	alert(StatusImageame);
	
	}

