// Javascript document for www.trct.co.uk (c) 2006 Tony Collings

// Switches the message's pre-populated in the form fields on and off.

function checkClearValue(field, label){  
  if(field.value == label)
  {
	field.style.color = "#000";
    field.value = "";
  }
}

function checkFillValue(field, label){
  if(field.value.length == 0)
  {
	field.style.color = "#ccc";
    field.value = label;
  }
  if(field.value == label)
  {
	field.style.color = "#ccc";  
  }
}
// Hides various elements 
function openMap(objOne,objTwo) 
{
		
	var One=document.getElementById(objOne);
	var Two=document.getElementById(objTwo);
	// var Two=document.getElementById(objTwo);
	// var img=document.images['image'];
	if (One.style.display == "none") // ON 
	{
		One.style.display = "";
		Two.style.display = "";
		
	}
		
	else // OFF
	{
		One.style.display = "none";
		Two.style.display = "none";
	}
}
function closeMap(objOne,objTwo) 
{
	var One=document.getElementById(objOne);
	var Two=document.getElementById(objTwo);
	// var Two=document.getElementById(objTwo);
	// var img=document.images['image'];
	if (One.style.display == "none") // ON 
	{
		One.style.display = "";
		Two.style.display = "";
	}
		
	else // OFF
	{
		One.style.display = "none";
		Two.style.display = "none";
	}
}
// Hide the form
function hideForm(objOne,objTwo)
{
		One.style.display = "none";
		Two.style.display = "none";
}
  

// Used to adjust width of Google Map 
function detectBrowserSize(){
	
	var obj=document.getElementById('google_map');
	
	switch (screen.width) 
	{
		case 800: obj.style.height = "320px"; break;
		case 1024: obj.style.height = "520px"; break;
		case 1200: obj.style.height = "800px"; break;
		default: obj.style.height = "520px"; break;
	}
	
}

// Blur effect, MSIE only. 
function blurObject(myObj)
{
	//alert("Hello World");
	var obj=document.getElementById(myObj);
	obj.style.filter = "progid:DXImageTransform.Microsoft.Blur(PixelRadius='10', MakeShadow='false', ShadowOpacity='0.25')";
}

// Cross-Browser Add To Favourites
function AddToFavourites (url,title)
{ 

var agt = navigator.userAgent.toLowerCase(); 
var app = navigator.appName.toLowerCase(); 
var ieAgent = agt.indexOf('msie'); 
var nsAgent = app.indexOf('netscape'); 
var opAgent = app.indexOf('opera'); 

	if (nsAgent!= -1) 
		{ // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title,url,"");	
		} 
	else if(ieAgent!= -1) 
		{ // IE Favorite		
		window.external.AddFavorite(url,title); 

		}	
	else if(opAgent!= -1)
			
			// Other methods of detecting Opera
			
			// window.opera && window.print 
			// opAgent!= -1
			// agt.substr(agt.indexOf('opera')+6,1) < 9
		{
				alert("You are using a browser that does not support adding Favorites by script, please add it manually");	
		}

}  


// Opens new windows
var newwindow;
function openWindow(url,name,height,width) {
// newwindow=window.open(url,name,'width='+width+',height='+height+', resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no');
newwindow=window.open(url,name,'width=850,height=650, resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no');
	if (window.focus) {newwindow.focus()}
}


// Closes windows
function closeWindow() {
  window.close();
}


// Provides a static element on a page when scrolling
// use window.onscroll = window_onscroll;
function window_onscroll(){
  var panel1 = document.getElementById('postcomment');
  var panel2 = document.getElementById('test');
  if(typeof(document.media)=='string')
  {// only do this for ie
    var s;
    // scrolling offset calculation via www.quirksmode.org 
    if (self.pageYOffset){s = self.pageYOffset;}
    else if (document.documentElement && 
      document.documentElement.scrollTop) {	
        s = document.documentElement.scrollTop; }
    else if (document.body) {	s = document.body.scrollTop; }
    panel1.style.top = s + 40;
	panel2.style.top = s + 40;
	
  }
  if(typeof(window.print)=='function')
  {// only do if not ie
    var x;
    // scrolling offset calculation via www.quirksmode.org
    if (self.pageXOffset){ x = self.pageXOffset;}
    else if (document.documentElement &&
      document.documentElement.scrollTop){ 
        x = document.documentElement.scrollLeft; }
    else if (document.body) { x = document.body.scrollLeft;}
    panel1.style.left = ( x - 0 ) + "px";
	panel2.style.left = ( x - 0 ) + "px";
  }
}


/*	MOOTOOLS
	Requires the mootools JS library. www.mootools.net
	------------------------------------------------------------------------ */
function borderFX(elArray,onFocusColor,onBlurColor){
	elArray.each(function(el) {
		
		el.addEvents({
			'focus' : function() {el.setStyles({border:'2px solid '+onFocusColor});}, 
			'blur' : function() {el.setStyles({border:'2px solid '+onBlurColor});}
		}); 
	});
	
}







