//-----------------------------------------------------------------
// Name: declareMenuItems()
// Description: Setup the barleyfields menu
//-----------------------------------------------------------------

function declareMenuItems(useFrameset)
{
    	var txt;
    	var fset;
    
    	if (useFrameset) <!-- this is the index content and links for the inside framset used-->
    	{
	    	fset = " target='mainFrame' ";
	        fpos = "../../";
	    	txt =  "<a href='" + fpos + "page/about_barleyfields.htm' class='links'" + fset + ">Welcome to Barleyfields</a><br>";
	    	txt += "<a href='" + fpos + "page/news.htm' class='links'" + fset + ">News</a><br>";
			txt += "<a href='" + fpos + "page/events.htm' class='links'" + fset + ">Competitions</a><br>";
			txt += "<a href='" + fpos + "page/onlineentries.htm' class='links'" + fset + ">How to Enter Events Online</a><br>";
			txt += "<a href='" + fpos + "page/demos.htm' class='demos'" + fset + ">Demonstrations</a><br>";
			txt += "<a href='" + fpos + "page/entryforms.htm' class='links'" + fset + ">Entry Forms</a><br>";
			txt += "<a href='" + fpos + "page/results.htm' class='links'" + fset + ">Results</a><br>";
			txt += "<a href='" + fpos + "page/ridingschool.htm' class='links'" + fset + ">Schl Hols/ Training Courses</a><br>";
			txt += "<a href='" + fpos + "page/bhs.htm' class='links'" + fset + ">BHS Exams & Training</a><br>";
			txt += "<a href='" + fpos + "page/bbq.htm' class='links'" + fset + ">Dog Show & BBQ</a><br>";
			<!--txt += "<a href='" + fpos + "page/henparty.htm' class='links'" + fset + ">Hen Parties</a><br>";-->
			txt += "<a href='" + fpos + "page/ridingclub.htm' class='links'" + fset + ">Riding Club</a><br>";
			txt += "<a href='" + fpos + "page/gallery.htm' class='links'" + fset + ">Photo Gallery</a><br>";
			txt += "<a href='" + fpos + "page/facilities.htm' class='links'" + fset + ">Facilities</a><br>";
			txt += "<a href='" + fpos + "page/saddlery.htm' class='links'" + fset + ">Saddlery</a><br>";
	    	txt += "<a href='" + fpos + "page/prices.htm' class='links'" + fset + ">Our Prices</a><br>";
	    	txt += "<a href='" + fpos + "page/contactus.htm' class='links'" + fset + ">Contact Us</a><br>";
	    	txt += "<a href='" + fpos + "page/links.htm' class='links'" + fset + ">Links</a><br>";
			
	}
	else
	{
	    	fset = " target='_self' "; <!-- these are the links from the front page with no framsets and just one image, these links go through to the internal pages that use framsets-->
	        fpos = "";
	    	txt =  "<a href='" + fpos + "page_navigation/index.htm?TITLE=Leading Eventing Centre&PAGE=../page/about_barleyfields.htm' class='links'" + fset + "></a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Latest News &amb; Events&PAGE=../page/clinics.htm' class='links'" + fset + "></a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Events &amb; Events&PAGE=../page/directions.htm' class='links'" + fset + "></a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=TrainingClinics &amb; Events&PAGE=../page/events.htm' class='links'" + fset + "></a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Results&PAGE=../page/facilities.htm' class='links'" + fset + "> </a><br>";
			txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Competition Times&PAGE=../page/hire_charges.htm' class='links'" + fset + "></a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Dressage&PAGE=../page/livery.htm' class='links'" + fset + "> </a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Show Jumping&PAGE=../page/results.htm' class='links'" + fset + "> </a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Cross Country Course&PAGE=../page/times.htm' class='links'" + fset + "></a><br>";
	    	txt += "<a href='" + fpos + "page_navigation/index.htm?TITLE=Entry Forms&PAGE=../page/entryform.htm' class='links'" + fset + "></a><br>";

	}	    
    	return (txt);
}

//-----------------------------------------------------------------
// Name: showTopMenu()
// Description: Format the menu for the main barleyfields 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 barleyfields 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='lefthorse.jpg' width='96' height='180'>"
		txt += "</p>";
    	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 setMainPageFrameSrc(titleOfPage, pageReference)
{
	
	var fset;
		
	fset = "";
	if (titleOfPage != null && pageReference != null)
	{
		fset += "<TITLE>" + titleOfPage + "</TITLE>";
		fset += "</HEAD>";
		fset += "<FRAMESET ROWS='100,*' COLS='*' FRAMEBORDER='NO' BORDER='0' FRAMESPACING='0'>";
		fset += "<FRAME NAME='topFrame' SCROLLING='NO' noresize SRC='page_navigation/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='page_navigation/left_nav/left_nav.htm' MARGINWIDTH='0' MARGINHEIGHT='0' FRAMEBORDER='NO'>";
		fset += "<FRAME NAME='mainFrame' SRC='" + pageReference + "' 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: setFrameSrc()
// Description: Set the frame src attribute on the default frameset.
//-----------------------------------------------------------------

function popupWindow(windowname){

	var winOptions = 'directories=no,location=no,menubar=no,titlebar=yes,alwaysRaised=yes,dependent=yes,';
	winOptions += 'scrollbars=yes,width=400,height=400, top=150, left=150'
	window.open("" + windowname + "", "ViewMap", winOptions)
}

//-----------------------------------------------------------------
// 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;"
}