//============================================
// Check Browser just in case
//============================================

navName=navigator.appName.toUpperCase();
appVer=navigator.appVersion.toUpperCase();
userAgent=navigator.userAgent.toUpperCase();

if ((navName.indexOf('OPERA') != -1) || (appVer.indexOf('OPERA') != -1) || (userAgent.indexOf('OPERA') != -1))
{ 	
	top.location.href="http://www.opera.com";	
}


//============================================
// Load the lowsrc image
//============================================

picloading=new Image();
picloading.src="imagepool/misc/picloading.gif";

//============================================
// Functions
//============================================

// Euro converter & Price writer
function localConv(sterling,mode) {

	// We only use the javascript if we are in local mode (i.e. running a demo)
	if (document.URL.indexOf("http://") == -1) 
	{

	// Everything below this line does not run when user is connect to the internet.
	// The host euro converter is used instead.
	// The following code is for demonstration purposes only.

	var rate=1.48;
	eurosUnrounded=sterling*rate;
	euros=Math.round(eurosUnrounded*100)/100;
	euroString=euros.toString().replace(".",",");
	sterlingString=sterling.toString();

	dotPos=sterlingString.indexOf(".");
	if (dotPos >= 0) {
		strlen=sterlingString.length;	
		decimaldigits=sterlingString.substr(dotPos+1,strlen-dotPos).length;
		if (decimaldigits == 1) {
			sterlingString=sterlingString+"0";
		}
	}

	commaPos=euroString.indexOf(",");
	if (commaPos >= 0) {
		strlen=euroString.length;	
		decimaldigits=euroString.substr(commaPos+1,strlen-commaPos).length;
		if (decimaldigits == 1) {
			euroString=euroString+"0";
		}
	}

	uc_mode=mode.toUpperCase();

	switch (uc_mode) {

	case "BR":
		css_sterling_class="sterling_price";
		css_euro_class="euro_price";
		price_break="<BR>";
		euro_delimiter_left="";
		euro_delimiter_right="";
		break;

	case "SL":
		css_sterling_class="sterling_price";
		css_euro_class="euro_price";
		price_break="&nbsp;&nbsp;";
		euro_delimiter_left="";
		euro_delimiter_right="";
		break;

	case "I1BR":
		css_sterling_class="sterling_inline1";
		css_euro_class="euro_inline1";
		price_break="<BR>";
		euro_delimiter_left="(";
		euro_delimiter_right=")&nbsp;";
		break;

	case "I1SL":
		css_sterling_class="sterling_inline1";
		css_euro_class="euro_inline1";
		price_break="&nbsp;&nbsp;";
		euro_delimiter_left="(";
		euro_delimiter_right=")&nbsp;";
		break;

	case "IN-SL":
		css_sterling_class="sterling_inline2";
		css_euro_class="euro_inline2";
		price_break="&nbsp;&nbsp;";
		euro_delimiter_left="(";
		euro_delimiter_right=")&nbsp;";
		break;

	case "DN-SL":
		css_sterling_class="sterling_price";
		css_euro_class="euro_price";
		price_break="&nbsp;&nbsp;";
		euro_delimiter_left="(";
		euro_delimiter_right=")&nbsp;";
		break;

	default:
		css_sterling_class="sterling_price";
		css_euro_class="euro_price";
		price_break="<BR>";
		euro_delimiter_left="";
		euro_delimiter_right="";
	}

	document.write("<font class=" + css_sterling_class + ">" + "&#163;&nbsp;" + sterlingString + "</font>");
	document.write(price_break);
	document.write("<font class=" + css_euro_class +">" + euro_delimiter_left + "Euro&nbsp;" + euroString + euro_delimiter_right + "</font>");

	}
	// end of local demonstration code
	return true;
}

function writePrice(sterling,mode) {
	
	return localConv(sterling,mode);
}

function writeprice(sterling,mode) {

	return writePrice(sterling,mode);
}

// Hide status bar messages

function hideStatus()
	{	window.status=' ';	return true; }

// Open New Window
function openWin(URL) {

	newWin=window.open(URL,"extraWin","toolbar=no,\
		width=850,height=450,status=no,scrollbars=yes,\
		copyhistory=no,resizable=yes,menubar=no,location=no");
	newWin.focus();
}

// Open New Map Window
function openMap(URL) {

	newWin=window.open(URL,"mapWin","toolbar=no,\
		width=780,height=600,status=no,scrollbars=yes,\
		copyhistory=no,resizable=yes,menubar=no,location=no");
	newWin.focus();
}

// Open Order Form
function openOrderForm(URL) {

	alert("The ORDER FORM can take up to 16s to download. Your patience is appreciated. Thank you.");
	newWin=window.open(URL,"orderForm","toolbar=no,\
		width=700,height=600,top=0,status=no,scrollbars=yes,\
		copyhistory=no,resizable=yes,menubar=no,location=no");
	newWin.focus();
}

// Open Small Info Window
function openSmallInfoWindow(URL) {

	newWin=window.open(URL,"mapWin","toolbar=no,\
		width=500,height=670,top=10,status=no,scrollbars=yes,\
		copyhistory=no,resizable=yes,menubar=no,location=no");
	newWin.focus();
}

// Open Conditions of Sale Window
function openConditions(URL) {

	newWin=window.open(URL,"condWin","toolbar=no,\
		width=600,height=600,top=0,status=no,scrollbars=yes,\
		copyhistory=no,resizable=yes,menubar=no,location=no");
	newWin.focus();
}

// Open New Links Window
function openLink(URL) {

	newWin=window.open(URL,"linkWin","top=0,left=0,alwaysRaised=yes,toolbar=yes,\
		status=yes,scrollbars=yes,height=500,\
		copyhistory=no,resizable=yes,menubar=yes,location=yes");
	newWin.focus();
}

// Find current window height

function findWindowHeight() {
	if (window.innerHeight != null) {		
		return window.innerHeight;
	}

	if (document.body.clientHeight != null) {
		return document.body.clientHeight;
	}

	return (height);
}



function findScrollTop() {


	if (window.pageYOffset != null)
		return window.pageYOffset;


	if (document.body.scrollWidth != null)
		return document.body.scrollTop;


	return null;


}


function findScrollLeft() {


	if (window.pageXOffset != null)
		return window.pageXOffset;


	if (document.body.scrollHeight != null)
		return document.body.scrollLeft;


	return null;


}



function findTopOfObject(objId) {


	var domStyle=findDOM(objId,1);
	var dom=findDOM(objId,0);


	if (domStyle.top)
		return domStyle.top;

	if (domStyle.offsetTop)
		return domStyle.offsetTop;

	if (domStyle.pixelTop)
		return domstyle.pixelTop;

	if (dom.offsetTop)
		return dom.offsetTop;

	return (null);


}


function findLeftOfObject(objId) {


	var domStyle=findDOM(objId,1);
	var dom=findDOM(objId,0);


	if (domStyle.left)
		return domStyle.left;


	if (domStyle.pixelLeft)
		return domstyle.pixelLeft;


	if (dom.offsetLeft)
		return dom.offsetLeft;


	return (null);
}






function findTop(object) {


	return findTopOfObject(object);
}






function findLeft(object) {


	return findLeftOfObject(object);
}


function findHeight(object) {


	var dom=findDOM(object,0);
	var domStyle=findDOM(object,1);	

	if (dom.offsetHeight) {
		return dom.offsetHeight;
	}

	return (null);


}


function findBottom (object) {
	return (findTop(object) + findHeight(object));
}


function startAnimate(obj,x,y) {

	cX = findLeft(obj);
	cY = findTop(obj);
	domStyle=findDOM(obj,1);
	animateDelay=0;
	animateObject(cX,cY);
}


function animateMenu(obj) {

	domStyle=findDOM(obj,1);
	dom=findDOM(obj,0);
	cY=findTop(obj);

	animateDelay=10;
	menubottom=findBottom(obj);	
	menuheight=findHeight(obj);	

	// We only run for Non Opera due to some weird problem with it
	
	navName=navigator.appName.toUpperCase();
	
	// Note that we send a slightly greater menu height to make absolutely
	// sure that the whole menu is visible and no pixels missing from the bottom
	// which has been observed in test.
	if (navName.indexOf('OPERA') == -1) { 
		scrollMenu(cY,menuheight+2); 
	}		
}


function scrollMenu (cY,mh) {


	wh=findWindowHeight();	
	sizediff=wh-mh;		

	dY=findScrollTop();	
	
	posdiff=0;

	if (cY != dY) {
		
		posdiff=1;

		if (cY > dY) {
			
			testit=1;
			if ((testit == 1) && (cY > dY +200)) { cY -=40; testit = 0;}
			if ((testit == 1) && (cY > dY +100)) { cY -=15; testit = 0;}
			if ((testit == 1) && (cY > dY +12))	{ cY -=5; testit = 0;}
			if ((testit == 1) && (cY > dY +6))	{ cY -=4; testit = 0;}
			if ((testit == 1) && (cY > dY +3))	{ cY -=3; testit = 0;}
			if ((testit == 1) && (cY > dY +2))	{ cY -=2; testit =0;}		
			if ((testit == 1) && (cY > dY +1))	{ cY -=1; testit =0;}		
			if ((testit == 1) && (cY > dY))	{ cY -=1; testit =0;}		
		
		
		}
		else 
			{
			testit=1;
			if ((testit == 1) && (cY < dY -200)) { cY +=40; testit = 0;}
			if ((testit == 1) && (cY < dY -100)) { cY +=15; testit = 0;}
			if ((testit == 1) && (cY < dY -12))	{ cY +=5; testit = 0;}
			if ((testit == 1) && (cY < dY -6))	{ cY +=4; testit = 0;}
			if ((testit == 1) && (cY < dY -3))	{ cY +=3; testit = 0;}
			if ((testit == 1) && (cY < dY -2))	{ cY +=2; testit =0;}		
			if ((testit == 1) && (cY < dY -1))	{ cY +=1; testit =0;}		
			if ((testit == 1) && (cY < dY))	{ cY +=1; testit =0;}		
		
			}


	}


	if (cY != dY) {
		if (domStyle.pixelTop) {
			if (sizediff > 0)
				domStyle.pixelTop=cY;
			else
				domStyle.pixelTop=0;
		}
		else {
				if (sizediff > 0)
					domStyle.top=cY;
				else
					domStyle.top=0;
		}
	}	


	setTimeout ('scrollMenu(' + cY + ',' + mh + ')',animateDelay);
}


function animateObject (cX,cY) {


	dX=findScrollLeft();
	dY=findScrollTop();


	if (cX != dX) {


		if (cX > dX) { cX -=2; }
		else { cX +=3; }
	}


	if (cY != dY) {
		if (cY > dY) { cY -=2; }				
		else { cY +=3; }
	}



	if ((cX != dX) || (cY != dY)) {
		if (domStyle.pixelLeft) {
			domStyle.pixelLeft=cX;
			domStyle.pixelTop=cY;
		}
		else {
				domStyle.left=cX;
				domStyle.top=cY;
		}
	}	


	setTimeout ('animateObject(' + cX + ',' + cY + ')',animateDelay);
}
