// JavaScript -- Common Routines 
//
// 	Determine Browser Version //
//  We'll assume everyone is using a browser of Version 4 or above but we will not cater for Netscape 4
//
//	This Netscape 4 stuff is a hangover 'cos, based on statistics, I don't cater for it any longer
//
var brName
var brVer
var br
br="IE";
brName = navigator.appName;									// get browser name
brVer = parseInt(navigator.appVersion);						// and version
	if (brName=="Netscape" && brVer == 4) {					// If Netscape 4
		parent.mainframe.location.href="http://www.dgs-photography.co.uk/sorry.html"			// put in some dummy frames
		parent.bannerframe.location.href="http://www.dgs-photography.co.uk/blank.html"
		parent.menuframe.location.href="http://www.dgs-photography.co.uk/blank.html"	
	  br="n4";												
	} 					

//
// Link to relevant stylesheet //	
//
var stDom;
if (document.domain=="localhost") {					// first check if we're on the local IIS
		stDom="localhost/dgs-photography";}					// yes
else {
		stDom="www.dgs-photography.co.uk";}					// no
		
//
//	If user tries to load a sub-document directly then make sure it gets 'framed'
//
var sthost1 = "www.cyclingphotos.org.uk"			// get cycling site domain names
var sthost2 = "www.cyclingpictures.co.uk"

var stHref;
stHref = window.location.href;
if ((window.name != 'Popup') && (stHref.indexOf('paypal')==-1)) {	// unless it is a pop up..or a Paypal return page
	if (parent.frames.length == 0) {
		if ((window.location.host == sthost1) || (window.location.host == sthost2)) {
			window.location = "http://"+sthost1+"/index.asp?Mainpage=" +stHref;
			}
			else {
			window.location = "http://"+stDom+"/index1.asp?reqdoc=" +stHref;
			}
}
}

//
//	If document has been retrieved from folder 'sportsphotos' or 'cyclingphotos' then insert a Base statement
//

if ((stHref.indexOf("sportsphotos")!=-1) || (stHref.indexOf("cyclingphotos")!=-1)) {
document.writeln('<base href="http://'+stDom+'/">');
}
//
//
//
document.writeln('<link rel="stylesheet" type="text/css" href="http://'+ stDom +'/dgsstyle.css">');
//
// This function caters for Netscape window resize bug
//
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// Routine to switch a menu item and main page

function switchPages(menuURL,mainURL) {
parent.menuframe.location.href="http://"+stDom+"/"+ menuURL;
parent.mainframe.location.href="http://"+stDom+"/"+ mainURL;
}

// Open a new window

function openWin(URL) {
var aWindow = window.open(URL,'Popup','height=500,width=500,scrollbars,top=100,left=100, titlebar=yes');
}

// Routine to display a message window

function messageWindow(title, msg)
{
  var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title><link href="dgsstyle.css" rel="stylesheet" type="text/css"></head>';
  var body = '<body><center><p class="notimplemented">'+msg+'<br></p><p><form><input type="button" value="   Done   " onClick="self.close()"></form></body>';
  msgWindow.document.write(head + body);
}
//
//	Minimalist event handler..only interested in the right mousedown event...
//		-- of course Netscape and IE use different values for the buttons!!
//
function eventHandle(e)
{
var mess= 'A POLITE MESSAGE\n\r\nHave you read the copyright notices?\n\r\nI cannot prevent you downloading or copying images but\n\rplease be aware that those on this site are really\n\ronly good enough for display on screen.\n\r\nIf you would like a printed copy or high resolution digital\n\rimage then please contact me.\n\n\rI do not have any problem with you using my images on\n\ryour own website but I would appreciate some recognition.\n\rIt would also be nice to be asked in advance.\n\n\rThank You.'
if (brName == "Netscape") {
	var butt = e.which;
	var elmname = e.target.tagName;
	}
else {
	var butt = event.button;
	var elmname = event.srcElement.tagName;
	}
if ((brName == "Netscape" && butt == 3) || (brName != "Netscape" && butt == 2)) {		// if it's the right mouse button and clicked over an image
	//if ((elmname == "IMG") || (elmname == "AREA")) {
	parent.mainframe.location.href="http://"+stDom+"/blank.html";		
	//}
	}
//if (window.location.host == "www.cyclingphotos.org.uk") {									// need this to cut out js errors until we implememnt paypal across all sites
//	parent.menuframe.document.getElementById('buyitem').style.visibility='hidden';			// hide the 'buy item' button
//	parent.menuframe.document.getElementById('nobuyitem').style.visibility='visible';		// and show the main menu
//}
window.status = "";
return true;	
}
document.onmousedown=eventHandle;
//
//  The following event handler was introduced in conjunction with the Paypal shopping cart
//		-- I didn't want to amend over 20000 documents to cater for a 'buy now' button so this function
//			detects the loading of a document from a 'slides' folder (all major images have a 'slides' level
//			in the directory structure and the 'slides' level contains nothing but images or, in the case of the
//			clubs database 'slides' somewhere in the URL) and shows a 'buy button'.
//	Only done for 'www.cyclingphotos.org.uk' for the moment -- Aug 2005
//
//function eventload() {
//if (parent.menuframe.document.getElementById('buyitem')) {
//if ((window.location.host == "localhost")|| (window.location.href.indexOf("cycling")!=-1) ) {
//	if (parent.mainframe.location.href.indexOf("slides")!=-1) {				// are we loading a 'slide'?
//	parent.menuframe.document.getElementById('buyitem').style.visibility='visible';
//	parent.menuframe.document.getElementById('nobuyitem').style.visibility='hidden';
//	}
//	else {
//	parent.menuframe.document.getElementById('buyitem').style.visibility='hidden';
//	parent.menuframe.document.getElementById('nobuyitem').style.visibility='visible';
//	}
//}
//}
//}
//window.onload=eventload;

function eventmouseover() {
window.status = "";
window.defaultStatus = "";
return true;
}

window.onmouseover=eventmouseover;
//
//	The following functions determine the clients window width and height
//

function clientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function clientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function 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;
}
