function popup(id,time) {
	if (time == null) {
		time = 250;
	}
	show('popupframebg',time,75);
	setTimeout("show(\""+id+"\","+time+")",time);
}
function popdown(id,time) {
	if (time == null) {
		time = 250;
	}
	hide(id,time);
	setTimeout("hide(\"popupframebg\","+time+",75)",time);
}
function logout() {
	document.logoutForm.submit();
}
function login() {
	popup('login_form');
	document.getElementById('user_login').select();
	document.getElementById('user_login').focus();
}
function show(id,time,opacity) {
	if (opacity == null) {
		opacity = 100;
	}
	e=document.getElementById(id);
	if (e.style.left != "auto") {
		if (time != false) {
			if (time == null) {
				time = 250;
			}
			p=1000/20;
			t=0;
			s= opacity/(time/p);
			o=0;
			changeOpac(o,id);
			e.style.left= "auto";
			while (o<=opacity) {
				setTimeout("changeOpac("+Math.round(o)+",'"+id+"')",t);
				o=o+s;
				t = t+p;
			}
		}
		else {
			e.style.display = "block";
		}
	}
}

function hide(id,time,opacity) {
	if (opacity == null) {
		opacity = 100;
	}
	e=document.getElementById(id);
	if (e) {
		if (e.style.left != "-999em") {
			if (time != false) {
				if (time == null) {
					time = 250;
				}
				p=1000/20;
				t=0;
				s= opacity/(time/p);
				o=0;
				o=opacity;
				changeOpac(o,id);
				while (o>=0) {
					setTimeout("changeOpac("+Math.round(o)+",'"+id+"')",t);
					o=o-s;
					t = t+p;
				}
				setTimeout('document.getElementById("'+id+'").style.left = "-999em";',t+p);
			}
			else {
				e.style.display = "none"
			}
		}
	}
}
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}


function applyst() {
    load();
    if( window.XTRonload ) { window.XTRonload(); }
}
function savest() {
    GUnload();
    if( window.XTRonunload ) { window.XTRonunload(); }
}

var bubble =  "	<div id='map_bubble'> \
					<h3>JGEL</h3> \
					Unit 21 Moss Lane Industrial Estate<br/> \
					Royton<br/> \
					Oldham<br/> \
					OL2 6HR<br /> \
					ENGLAND<br /> \
					<br /> \
					<form onSubmit=\"getDirections(); return false;\" action=\"getDirections(); return false;\"> \
					<div id=\"get_directions\">Get directions: <a href=\"javascript:directionsToHere();\">To here</a> - <a href=\"javascript:directionsFromHere();\">From here</a>&nbsp;</div> \
					<div id=\"directions\"  style=\"display:none;\"> \
						<div id=\"d_text\">Start address:</div> \
						<input type=\"text\" id=\"address\" size=\"18\" /> \
						<input type=\"button\" value=\"Go\" onClick=\"getDirections();\" /> <br />\
						<a href=\"javascript:directionsBack();\">&laquo; Back</a> \
					</div> \
					<div id=\"directions_placeholder\"><br /><br /><br /><br /><br /></div> \
					</form> \
				</div>";	
    //<![CDATA[

    function load() {
      if (GBrowserIsCompatible()) {
      	var center = new GLatLng(53.56072,-2.10120);
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(center, 7);
        marker = new GMarker(center)
        GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(bubble);
		});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(bubble);
        
      }
    }

    //]]>

var directionsTo = true;

function convert(input) {
					var output = "";
					for (var i = 0; i < input.length; ++i) 
					{
						var temp = input.charAt(i); if (temp == " ") temp = "+";
						output += temp;
					}
					return output;
				}

function getDirections() {
	if (document.getElementById('address').value != "") {
		var address = convert(document.getElementById('address').value);
		if (directionsTo == true) {
			window.open('http://maps.google.co.uk/maps?f=d&source=s_d&saddr='+address+'&daddr=Unit+21+Moss+Lane+Industrial+Estate+Royton+Oldham+OL2+6HR+(JGEL)&hl=en&geocode=&mra=ls&sll=53.56072,-2.10120&sspn=0.011419,0.027595&g=Unit+21+Moss+Lane+Industrial+Estate+Royton+Oldham+OL2+6HR&ie=UTF8&z=8');
		}
		else {
			window.open('http://maps.google.co.uk/maps?f=d&source=s_d&saddr=Unit+21+Moss+Lane+Industrial+Estate+Royton+Oldham+OL2+6HR+(JGEL)&daddr='+address+'&geocode=&hl=en&mra=ls&sll=53.56072,-2.10120&sspn=1.480327,3.532104&ie=UTF8&ll=53.018088,-2.208252&spn=1.48044,3.532104&z=8');
		}
	}
}

function directionsToHere() {
	document.getElementById('get_directions').innerHTML = "<b>Get directions</b>: To here - <a href=\"javascript:directionsFromHere();\">From here</a>";
	document.getElementById('d_text').innerHTML = "Start address:";
	document.getElementById('directions_placeholder').style.display = "none";
	document.getElementById('directions').style.display = "inline";
	directionsTo = true;
}
function directionsFromHere() {
	document.getElementById('get_directions').innerHTML = "<b>Get directions</b>: <a href=\"javascript:directionsToHere();\">To here</a> - From here";
	document.getElementById('d_text').innerHTML = "End address:";
	document.getElementById('directions_placeholder').style.display = "none";
	document.getElementById('directions').style.display = "inline";
	directionsTo = false;
}
function directionsBack() {
	document.getElementById('get_directions').innerHTML = "Get directions: <a href=\"javascript:directionsToHere();\">To here</a> - <a href=\"javascript:directionsFromHere();\">From here</a>";
	document.getElementById('directions').style.display = "none";
}


function pageload() {
	if (typeof(logged_in)!='undefined') {
		if (typeof(login_onload)!='undefined') {
			if (logged_in==false && login_onload==true) {
				login();
			}
		}
		if (typeof(logout_page)!='undefined' && typeof(home_url)!='undefined') {
			if (logged_in==true && logout_page==true) {
				document.location = home_url;
			}
		}
	}
	if (typeof(load_map)!='undefined') {
		if (load_map==true) {
			applyst();
		}
	}
}
function pageunload() {
	if (typeof(load_map)!='undefined') {
		if (load_map==true) {
			savest();
		}
	}
}

if( window.addEventListener ) {
    window.addEventListener( 'load', pageload, false );
    window.addEventListener( 'unload', pageunload, false );
} else if( document.addEventListener ) {
    document.addEventListener('load' , pageload, false );
    document.addEventListener( 'unload', pageunload, false );
} else if( window.attachEvent ) {
    window.attachEvent( 'onload', pageload );
    window.attachEvent( 'onunload', pageunload );
} else {
    if( window.onload ) { window.XTRonload = window.onload; }
    if( window.onunload ) { window.XTRonunload = window.onunload; }
    window.onload = pageload;
    window.onunload = pageunload;
}