//-----------------------------------------------------------------
// Name: declareMenuItems()
// Description: Setup the MKEC menu
//-----------------------------------------------------------------

function declareMenuItems(useFrameset)
{
    	var txt;
    	var fset;
    
    	if (useFrameset)
    	{
	    	fset = " target='mainFrame' ";
	        fpos = "../../";
	    	txt =  "<a href='" + fpos + "page/about_mkec.htm' class='links'" + fset + ">about the centre</a><br>";
	    	txt += "<a href='" + fpos + "page/news_events.htm' class='links'" + fset + ">latest news</a><br>";
			txt += "<a href='" + fpos + "page/events.htm' class='links'" + fset + ">dates & schedules</a><br>";
			txt += "<a href='" + fpos + "page/trainingclinics.htm' class='links'" + fset + ">training clinics</a><br>";
	    	txt += "<a href='" + fpos + "page/results.htm' class='links'" + fset + ">results</a><br>";
			txt += "<a href='" + fpos + "page/times.htm' class='links'" + fset + ">competition times</a><br>";
	    	txt += "<a href='" + fpos + "page/dressage.htm' class='links'" + fset + ">dressage</a><br>";
	    	txt += "<a href='" + fpos + "page/showjumping.htm' class='links'" + fset + ">show jumping</a><br>";
	    	txt += "<a href='" + fpos + "page/xc_course.htm' class='links'" + fset + ">cross country</a><br>";
	    	txt += "<a href='" + fpos + "page/threedayevent.htm' class='links'" + fset + ">MK three day event</a><br>";
	    	txt += "<a href='" + fpos + "page/horsetrials.htm' class='links'" + fset + ">BE horse trials</a><br>";	
			txt += "<a href='" + fpos + "page/trailblazers.htm' class='links'" + fset + ">trailblazers</a><br>	";
	    	txt += "<a href='" + fpos + "page/livery.htm' class='links'" + fset + ">livery</a><br>";
	    	txt += "<a href='" + fpos + "page/hire_charges.htm' class='links'" + fset + ">hire charges</a><br>";
	    	txt += "<a href='" + fpos + "page/directions.htm' class='links'" + fset + ">directions</a><br>";
	    	txt += "<a href='" + fpos + "page/clinics.htm' class='links'" + fset + ">training</a><br>";
	    	txt += "<a href='" + fpos + "page/sponsors.htm' class='links'" + fset + ">our sponsors</a><br>";
	    	txt += "<a href='" + fpos + "page/volunteers.htm' class='links'" + fset + ">volunteers</a><br>";
	    	txt += "<a href='" + fpos + "page/bandb.htm' class='links'" + fset + ">b & b list</a><br>";
	    	txt += "<a href='" + fpos + "page/fionas_gossip.htm' class='links'" + fset + ">fiona's & ruggies gossip</a><br>";
	    	txt += "<a href='" + fpos + "page/usefullinks.htm' class='links'" + fset + ">useful links</a><br>";
	    	txt += "<a href='" + fpos + "page/contactus.htm' class='links'" + fset + ">contact us</a><br>";

	}
	else
	{
	    	fset = " target='_self' ";
	        fpos = "";
	    	txt =  "<a href='" + fpos + "page_navigation/index.htm?TITLE=Leading Eventing Centre&PAGE=../page/about_mkec.htm' class='links'" + fset + ">about the centre</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Latest News &amb; Events&PAGE=../page/news_events.htm' class='links'" + fset + ">latest news</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Events &amb; Events&PAGE=../page/events.htm' class='links'" + fset + ">dates & schedules</a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=TrainingClinics &amb; Events&PAGE=../page/trainingclinics.htm' class='links'" + fset + ">training clinics</a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Results&PAGE=../page/results.htm' class='links'" + fset + ">results</a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Competition Times&PAGE=../page/times.htm' class='links'" + fset + ">competition times</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Dressage&PAGE=../page/dressage.htm' class='links'" + fset + ">dressage</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Show Jumping&PAGE=../page/showjumping.htm' class='links'" + fset + ">show jumping</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Cross Country Course&PAGE=../page/xc_course.htm' class='links'" + fset + ">cross country</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Equine Affairs Unaffiliated Three Day Event&PAGE=../page/threedayevent.htm' class='links'" + fset + ">MK three day event</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=British Eventing Horse Trials&PAGE=../page/horsetrials.htm' class='links'" + fset + ">BE horse trials</a><br>";	
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Trailblazers&PAGE=../page/trailblazers.htm' class='links'" + fset + ">trailblazers</a><br>	";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Livery&PAGE=../page/livery.htm' class='links'" + fset + ">livery</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Hire Charges&PAGE=../page/hire_charges.htm' class='links'" + fset + ">hire charges</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Directions&PAGE=../page/directions.htm' class='links'" + fset + ">directions</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Training Clinics&PAGE=../page/clinics.htm' class='links'" + fset + ">training</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Training&PAGE=../page/sponsors.htm' class='links'" + fset + ">our sponsors</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Our Volunteers&PAGE=../page/volunteers.htm' class='links'" + fset + ">volunteers</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Local Bed &amb; Breakfast&PAGE=../page/bandb.htm' class='links'" + fset + ">b & b list</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Gossip&PAGE=../page/fionas_gossip.htm' class='links'" + fset + ">fiona's & ruggies gossip</a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Useful Links&PAGE=../page/usefullinks.htm' class='links'" + fset + ">useful links</a><br>";

	}	    
    	return (txt);
}

//-----------------------------------------------------------------
// Name: showTopMenu()
// Description: Format the menu for the main MKEC page
//-----------------------------------------------------------------

function showTopMenu(useFrameset)
{
    	var txt;
    
    	txt  = "<!-- Menu with Absolute Positioning -->";
    	txt += "<div id='dvMenu' style='position: absolute; top: 66px; left: 23px; width: 195px; height: 338px; padding: 0px; border:0;'>";
    	txt += "<p class='menu'>";
    	txt += declareMenuItems(useFrameset);
    	txt += "</p>";
    	txt += "</div>";
    
    	return (txt);
}


//-----------------------------------------------------------------
// Name: showTopMenu()
// Description: Format the menu for the main MKEC page
//-----------------------------------------------------------------

function showLeftMenu(useFrameset)
{
    	var txt;
    
    	txt  = "<!-- Menu with Absolute Positioning -->";
    	txt += "<div id='dvMenu' style='position: absolute; top: 10px; left: 23px; width: 195px; height: 338px; padding: 0px; border:0;'>";
    	txt += "<p class='menu'>";
    	txt += declareMenuItems(useFrameset);
    	txt += "</p>";
    	txt += "<img src='horsewoman.jpg' width='140' height='125'>"
    	txt += "</div>";
    
    	return (txt);
}

  
//-----------------------------------------------------------------
// Name: getKeys()
// Description: Read the querystring and parse contents into identified
// elements.
//-----------------------------------------------------------------

function getKeys() 
{ 
   	var keys = new Object(); 
   	var queryString = location.search.substring(1); 
   	var keyPairs = queryString.split("&"); 
    
   	for(var i = 0; i < keyPairs.length; i++) 
   	{ 
      		var position = keyPairs[i].indexOf('='); 
        	if (position == -1) continue; 
       
       		var keyname = keyPairs[i].substring(0, position ); 
       
      		var keyvalue = keyPairs[i].substring(position + 1); 
       		keys[keyname] = unescape(keyvalue); 
   	} 
   	return keys; 
  }
  
//-----------------------------------------------------------------
// Name: setFrameSrc()
// Description: Set the frame src attribute on the default frameset.
//-----------------------------------------------------------------

function setFrameSrc()
{
    	// Set the Frame SRC attribute to the required page.
   	keys = getKeys();
	
	var fset;
		
	fset = "";
	if (keys["TITLE"] != null && keys["PAGE"] != null)
	{
		fset += "<TITLE>" + keys["TITLE"] + "</TITLE>";
		fset += "</HEAD>";
		fset += "<FRAMESET ROWS='100,*' COLS='*' FRAMEBORDER='NO' BORDER='0' FRAMESPACING='0'>";
		fset += "<FRAME NAME='topFrame' SCROLLING='NO' noresize SRC='top_nav/top_nav.htm' MARGINWIDTH='0' MARGINHEIGHT='0' FRAMEBORDER='NO' >";
		fset += "<FRAMESET COLS='187,*' FRAMEBORDER='NO' BORDER='0' FRAMESPACING='0' ROWS='*'>";
		fset += "<FRAME NAME='leftFrame' noresize SCROLLING='NO' SRC='left_nav/left_nav.htm' MARGINWIDTH='0' MARGINHEIGHT='0' FRAMEBORDER='NO'>";
		fset += "<FRAME NAME='mainFrame' SRC='" + keys["PAGE"] + "' FRAMEBORDER='NO' SCROLLING='AUTO' MARGINWIDTH='20' MARGINHEIGHT='20'>";
		fset += "</FRAMESET>";
		fset += "</FRAMESET>";
		fset += "<NOFRAMES>";
		fset += "<BODY BGCOLOR='#FFFFFF' TEXT='#000000' LEFTMARGIN='0' TOPMARGIN='0' MARGINWIDTH='0' MARGINHEIGHT='0'>";
		fset += "</BODY></NOFRAMES>";

		document.write(fset);
  	}
}

//-----------------------------------------------------------------
// Name: funShowPage()
// Description: Show a page within an iframe.
// Note:- to change the style of the Print & Close window text add the style into the iPage table as below
//-----------------------------------------------------------------

function funShowPage(divId, frameid, page, id, width, height) 
{ 	
	var iPage = ""; 	
	var iStyle = ""; 	
	var iHeader = "";
	var objref = xbGetElementById(divId); 	
	var txtPos = "";
	
	if (objref) 	
	{ 	
	 	iStyle = "STYLE='position:relative;width:" + width + "px;height:" + height + "px;'";
		iPage = "<table class='links' width='" + (width - 20) + "'><tr><td width='5'>&nbsp;</td><td align='left'><a href='javascript:funPrintList(\"" + page + "\");'>Print List</a></td><td align='right'><a href='javascript:funClosePage();'>Close Window</a></td></tr></table>";
		iPage +="<IFRAME NAME='" + id + "' ID='" + id + "' " + iStyle + " SRC='" + page + "' FRAMEBORDER=0></IFRAME>"; 		
		objref.innerHTML = iPage; 	
		objref.style.visibility = 'visible';
		objref.style.display = 'block'; 	
	}
}

//-----------------------------------------------------------------
// Name: funClosePage(divId)
// Description: Close the Window
//-----------------------------------------------------------------

function funClosePage()
{
	var objref = xbGetElementById("dvEquineAffairs");
	if (objref)
	{
		objref.innerHTML = "";
		objref.style.visibility = 'hidden';
		objref.style.display = 'none';
	}	
}

//-----------------------------------------------------------------
// Name: funPrintList(pagetoload)
// Description: Prints List
//-----------------------------------------------------------------

function funPrintList(pagetoload)
{
	var winOptions ='directories=no,location=no,menubar=yes,titlebar=no,alwaysRaised=yes,dep endent=yes,scrollbars=yes,width=800,height=500, top=50,left=50';
	var w = window.open(pagetoload, 'PrintList', winOptions);
}

//-----------------------------------------------------------------
// Name: funGetWidthHeight(width, height, widthOfTable)
// Description: Retrieves the base position of the list depending
// on the type of browser and the screen resolution. The positioning
// is based on an 800 x 600 screen and we need to increase the positioning
// based on other screen resolutions.
//-----------------------------------------------------------------

function funGetWidthHeight(width,  height, widthOfTable)
{
	var theWidth = 0;
	var theHeight = 0;
	var posWidth = 0;
	var posHeight = 0;
	
	if (window.innerWidth)
	{
		theWidth = window.innerWidth;
		theHeight = window.innerHeight;
	}
	else if (document.documentElement &&
			 document.documentElement.clientWidth)
	{
		theWidth = document.documentElement.clientWidth;
		theHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		theWidth = document.body.clientWidth;
		theHeight = document.body.clientHeight;
	}
	
	if (theWidth == 0)
	{
		posWidth = width;
		posHeight = height; 
	}
	else
	{
		posWidth = width + (theWidth - 800);
		posHeight = height + (theHeight - 600);
	}
	
	alert("theWidth = " + theWidth);
	alert("theHeight = " + theHeight);
	alert("posWidth = " + posWidth);
	alert("posHeight = " + posHeight);
	
	return "top:" + posHeight + "px;left:" + posWidth + "px;"
}
