//layerScript.js last modified 25.06.2006 by Philip Sparke of sunny-properties.com
/*
Auto center window script- Craig Edmonds (http://www.123marbella.com)
Edited by Kevin Crosbie (http://www.propertysolutions.es)
Enhanced by Philip Sparke (http://www.sunny-prperties.com)
*/
//public variables
var speed=50; 
var loop, timer ;
var initialised; 
var win = null;

function resizeFix()
{
	//Resize and fix window
	errorDetailedMessage = "(jslf01): ";
	//Here we execute the code within a try statement
	try
	{
		if ((widthCheck != window.innerWidth) || (heightCheck != window.innerHeight))
		{
			document.location.href = document.location.href;
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function hideLayer()
{
	//Hide document layer
	errorDetailedMessage = "(jslf02): ";
	// document.all["divMsg"].style.visibility = "hidden";
	//Here we execute the code within a try statement
	try
	{
		if(document.layers)
			document.layers["divMsg"].visibility = 'hide';
		else if(document.getElementById) 
			document.getElementById("divMsg").style.visibility = 'hidden';
		else if(document.all)
			document.all["divMsg"].style.visibility = 'hidden';
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function verifyCompatibleBrowser()
{
	errorDetailedMessage = "(jslf03): ";
	//Here we execute the code within a try statement
	try
	{ 
    	this.ver=navigator.appVersion; 
   		this.dom=document.getElementById?1:0; 
   		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    	this.ie4=(document.all && !this.dom)?1:0; 
    	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    	this.ns4=(document.layers && !this.dom)?1:0; 
    	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5); 
    	return this;
	} 
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
} 

bw=new verifyCompatibleBrowser() 

function ConstructObject(obj,nest)
{
	errorDetailedMessage = "(jslf04): ";
	//Here we execute the code within a try statement
	try
	{  
   		nest=(!nest) ? '':'document.'+nest+'.' ;
    	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight;
    	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight; 
    	this.up=MoveAreaUp;this.down=MoveAreaDown; 
    	this.MoveArea=MoveArea; this.x; this.y; 
    	this.obj = obj + "Object";
    	eval(this.obj + "=this"); 
    	return this; 
	} 
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
} 

function MoveArea(x,y)
{ 
	errorDetailedMessage = "(jslf05): ";
	//Here we execute the code within a try statement
	try
	{  
   		this.x=x;this.y=y; 
    	this.css.left=this.x;
    	this.css.top=this.y; 
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
} 


function MoveAreaDown(move)
{
	errorDetailedMessage = "(jslf06): ";
	//Here we execute the code within a try statement
	try
	{  
		if(this.y>-this.scrollHeight+objContainer.clipHeight)
		{ 
   			this.MoveArea(0,this.y-move) 
    		if(loop)
			{
				setTimeout(this.obj+".down("+move+")",speed)
			} 
		} 
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function MoveAreaUp(move)
{
	errorDetailedMessage = "(jslf07): ";
	//Here we execute the code within a try statement
	try
	{  
		if(this.y<0)
		{ 
    		this.MoveArea(0,this.y-move); 
    		if(loop)
			{
				setTimeout(this.obj+".up("+move+")",speed)
			} 
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function PerformScroll(speed)
{
	errorDetailedMessage = "(jslf08): ";
	//Here we execute the code within a try statement
	try
	{  
		if(initialised)
		{ 
			loop=true; 
			if(speed>0)
			{
				objScroller.down(speed);
			} 
			else
			{
				objScroller.up(speed);
			} 
		}
	} 
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}
 
function CeaseScroll()
{
	errorDetailedMessage = "(jslf09): ";
	//Here we execute the code within a try statement
	try
	{  
    	loop=false;
    	if(timer)
		{
			clearTimeout(timer);
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 
}

function InitialiseScrollableArea()
{
	errorDetailedMessage = "(jslf10): ";
	//Here we execute the code within a try statement
	try
	{  
    	objContainer=new ConstructObject('divContainer'); 
    	objScroller=new ConstructObject('divContent','divContainer'); 
    	objScroller.MoveArea(0,0); 
    	document.getElementById('divContainer').style.height = getRelativeHeight() + "px";
    	objContainer.css.visibility='visible' ;
   		initialised=true; 
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 
} 

function displayStatusMsg(msgStr)
{
	errorDetailedMessage = "(jslf11): ";
	//Here we execute the code within a try statement
	try
	{  
  		status=msgStr;
  		document.returnValue = true;
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 
}

function preloadImages()
{
	var d, i, j;
	errorDetailedMessage = "(jslf12): ";
	//Here we execute the code within a try statement
	try
	{ 
  		d=document;
		if(d.images)
		{
			if(!d.p)
			{
				d.p=new Array();
			}
    		j=d.p.length;
			a=preloadImages.arguments;
			for(i=0; i<a.length; i++)
			{
    			if (a[i].indexOf("#")!=0)
				{
					d.p[j]=new Image; d.p[j++].src=a[i];
				}
			}
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 
}

function swapImgRestore()
{
	var i, x, a;
	errorDetailedMessage = "(jslf13): ";
	//Here we execute the code within a try statement
	try
	{  
  		a=document.sr;
		for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
		{
			x.src=x.oSrc;
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 	
}

function findObj(n, d)
{
	var p, i, x;
	errorDetailedMessage = "(jslf14): ";
	//Here we execute the code within a try statement
	try
	{   
  		if(!d)
		{
			d=document;
		}
		
		if((p=n.indexOf("?"))>0&&parent.frames.length)
		{
    		d=parent.frames[n.substring(p+1)].document;
			n=n.substring(0,p);
		}
		
  		if(!(x=d[n])&&d.all)
		{
			x=d.all[n];
		}
		
		for (i=0;!x&&i<d.forms.length;i++)
		{
			x=d.forms[i][n];
		}
		
  		for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		{
			x=findObj(n,d.layers[i].document);
		}
		return x;
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	} 
}

function swapImage()
{
	var i, j=0, x, a;
	errorDetailedMessage = "(jslf15): ";
	//Here we execute the code within a try statement
	try
	{    
  		a=swapImage.arguments;
		document.sr=new Array;
		for(i=0;i<(a.length-2);i+=3)
		{
   			if ((x=findObj(a[i]))!=null)
			{
				document.sr[j++]=x;
				if(!x.oSrc)
				{
					x.oSrc=x.src;
					x.src=a[i+2];
				}
			}
		}
   	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function reloadPage(init)
{
	errorDetailedMessage = "(jslf16): ";
	//Here we execute the code within a try statement
	try
	{
		//reloads the window if Nav4 resized
  		if (init==true) with (navigator)
		{
			if ((appName=="Netscape")&&(parseInt(appVersion)==4))
			{
    			document.pgW=innerWidth;
				document.pgH=innerHeight;
				onresize=reloadPage;
			}
		}
  		else if (innerWidth!=document.pgW || innerHeight!=document.pgH)
		{
			location.reload();
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

reloadPage(true);

function getRelativeHeight()
{
	var height = 0;
	errorDetailedMessage = "(jslf17): ";
	//Here we execute the code within a try statement
	try
	{
		//calculates the height for this browser window - the top bar of the website.
		//	var Wide = screen.width;
		//alert (document.body.offsetHeight);
		//	if (Wide <= 640){
		//		height = 310;
		//	}
		//	else if (Wide <= 800){
		//		height = 310;
		//	}
		//	else if (Wide <= 1024){
		//		height = 470;
		//	}
		//	else if (Wide <= 1280){
		//		height = 570;
		//	}
		//
		//	return height;
	 	if (bw.ns5)
		{
 			 height = window.innerHeight;
 		}
 		else
		{
 			height = document.body.offsetHeight;
 		}

		height = document.body.clientHeight;
  		// I've decided that I always want to display a certain amount, so I'm going to put in a minimum value of three quarters the screen height
		if (height < 400)
		{
			height = 400;
		}
		return height - 102;	// return the height minus the space at the top (subtracted an extra 40)
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function NewWindow(mypage,myname,w,h,resize,scroll,tool,loc,dir,st,menu,chist)
{
	var LeftPosition, TopPosition, settings;
	errorDetailedMessage = "(jslf18): ";
	//Here we execute the code within a try statement
	try
	{
		//window.open('jex5.htm','mywindow','width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes,left=0,top=100,screenX=0,screenY=100')
		//resizable=yes or no - Use this to control whether or not you want the user to be able to resize the window. 
		//scrollbars=yes or no - This lets you decide whether or not to have scrollbars on the window. 
		//toolbar=yes or no - Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.). 
		//location=yes or no - Whether or not you wish to show the location box with the current url (The place to type http://address). 
		//directories=yes or no - Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...). 
		//status=yes or no - Whether or not to show the window status bar at the bottom of the window. 
		//menubar=yes or non - Whether or not to show the menus at the top of the window (File, Edit, etc...). 
		//copyhistory=yes or no - Whether or not to copy the old browser window's history list to the new window.
		if (win)
		{
			win.close();
			win = null;
		}
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings = 'width='+w+',height='+h+',resizable='+resize+',scrollbars='+scroll+',toolbar='+tool+',location='+loc+',directories='+dir+',status='+st+',menubar='+menu+',copyhistory='+chist+',left='+LeftPosition+',top='+TopPosition;
		win = window.open(mypage,myname,settings);
		win.focus();
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function dblClickProtect(button)
{
	errorDetailedMessage = "(jslf18): ";
	//Here we execute the code within a try statement
	try
	{
		button.disabled = true;
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}
