// JavaScript Document

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
	
function updatelink(){
			var temp= document.getElementById('refid').innerHTML
//			alert(temp)
			document.getElementById('mailto').href += "REF:"+ temp
}

		
function clearInput(obj, text)
    {
        if(obj.value == text)
        {
            obj.value = "";
        }
    }

function hideVideo(){
			document.getElementById("imgs").style.display ="";
			document.getElementById("flashmenu").style.display ="none";
			document.getElementById("flashmenu").innerHTML="";
	}
function playVideo(f){
			if(document.getElementById("flashmenu").innerHTML==""){	
		
				document.getElementById("flashmenu").style.position="absolute";
				document.getElementById("flashmenu").style.margin="-110px 0 0 -325px";
				document.getElementById("flashmenu").style.display ="";
			
				var so = new SWFObject("/flash/m3diesel_lrg.swf", "spromo", "550", "400", "9", "#000");
				so.addVariable("testvar", f);		
				so.addParam("wmode", "transparent")
				so.write("flashmenu");
//		document.getElementById("imgs").style.display ="none";
			}else{
			document.getElementById("flashmenu").style.position="absolute";
				document.getElementById("flashmenu").style.margin="-110px 0 0 -325px";
				document.getElementById("flashmenu").style.display ="";
			
				var so = new SWFObject("/flash/m3diesel_lrg.swf", "spromo", "550", "400", "9", "#000");
				so.addVariable("testvar", f);		
				so.addParam("wmode", "transparent")
				so.write("flashmenu");
			}			
	}

function handleWindowScroll () {
    pane = document.getElementById("windowPane");
	filter = document.getElementById("transfilter");
    if (pane != null && filter != null) {
	    pane.style.left = document.documentElement.scrollLeft + "px";
	    pane.style.top = document.documentElement.scrollTop + "px";
		
		filter.style.left = document.documentElement.scrollLeft + "px";
	    filter.style.top = document.documentElement.scrollTop + "px";
    }	
}

window.onscroll = handleWindowScroll;

function textAreaLimiter(obj, maxlength, evt)
{
	var charCode = (evt.which)?evt.which : event.keycode;
	var max = maxlength;
	var text = obj.value;
	if(text.length > max)
	{
		var ignoreKeys = [8,46,37,38,39,40,35,36];
		for(i=0;i<ignoreKeys.length;i++)
		{
			if(charCode==ignoreKeys[i])
			{
				return true;	
			}
		}
		return false;
	}
	else
	{
		return true;	
	}
}


function pointer(element)
{
	element.style.cursor = "pointer";	
}

function clearhighlight(container, itemname, itemnameselected, tagName)
{
	var fs = document.getElementById(container);
	var tags = fs.getElementsByTagName(tagName);	
	for(i=0; i< tags.length; i++)
	{		
		if(tags[i].className == itemnameselected)
		{
			tags[i].className = itemname;	
		}		
	}
}

function loadFlash(name, i, t, h, element)
{	
	var so = new SWFObject("/flash/feature.swf", "feature", "823", "260", "8", "#000000");
	so.addVariable("i", i);
	var text = "<b>" + name + "</b><br />" + t;
	so.addVariable("t", encodeURIComponent(text));
	so.addVariable("h", h);
	so.addParam("wmode", "opaque")
	so.write("flashcontent");
	clearhighlight("featureSelector", "featureitem", "featureitemselected", "TD");
	element.className = "featureitemselected";
}

function featureFlashHoverOn(element)
{
    if(element.className != "featureitemselected")
    {
        element.className = "featureitemhover";
    }  
}

function featureFlashHoverOff(element)
{
    if(element.className == "featureitemhover")
    {
        element.className = "featureitem";
    }  
}

function loadAccFlash(name, i, t, h, element)
{
	var so = new SWFObject("/flash/accessories.swf", "feature", "823", "260", "8", "#000000");
	so.addVariable("i", i);
	var text = "<b>" + name + "</b><br />" + t;
	so.addVariable("t", encodeURIComponent(text));
	so.addVariable("h", h);
	so.addParam("wmode", "opaque")
	so.write("flashcontent");
	clearhighlight("accessoriesGridContainer", "featureitem", "featureitemselected", "DIV");
	element.className = "featureitemselected";
}

function accHoverOn(element)
{
    if(element.className != "featureitemselected")
    {
        element.className = "featureitemhover";
    }    
}

function accHoverOff(element)
{
   if(element.className == "featureitemhover")
    {
        element.className = "featureitem";
    }    
}

function clearAccFlash(src, alt)
{	
	document.getElementById("flashcontent").innerHTML = "<img src=\"" + src + "\" border=\"0\" alt=\"" + alt + "\" />";
}

function HighLightTabs(element, parentid)
{
	var parent = document.getElementById(parentid);
	var tags = parent.getElementsByTagName('TD');
	
	for(i=0; i< tags.length; i++)
	{		
		if(tags[i].className == "singletabnavselected")
		{
			tags[i].className = "singletabnav"
		}else if(tags[i].className == "tabnavfisrtselected")
		{
			tags[i].className = "tabnavfisrt"
		}else if(tags[i].className == "tabnavselected"){
			tags[i].className = ""
		}
	}	
	
	if(element.parentNode.className == "singletabnav")
	{
		element.parentNode.className = "singletabnavselected";
		
	}else if(element.parentNode.className == "tabnavfisrt")
	{
		element.parentNode.className = "tabnavfisrtselected";
		
	}else{
		element.parentNode.className = "tabnavselected";
		
	}
	 	
}
function highlightCMON(element)
{
	element.className = "cModelDivOn";
}
function highlightCMOFF(element)
{
	element.className = "cModelDiv";
}
function SetSearchTab()
{
	document.getElementById("searchTab").className = "searchresultsselected";	
}

function clearTextBox(textBox, originalText)
{
	if(originalText == textBox.value)
		textBox.value = "";	
}

function PrintPage()
{
	if (window && window.print) { window.print(); }
}

function popup(id, title, contents)
{
	var popup =  document.getElementById(id);
	
	if(popup==null)
	{		
		document.getElementById("popupPlaceholder").innerHTML += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"" + id + "\"class=\"popup\" style=\"\"><tr valign=\"top\"><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr valign=\"top\" class=\"popupHeaderRow\"><td><div class=\"popupTitle\">" + title +"</div></td><td valign=\"middle\" align=\"right\" class=\"popupClose\"><img onclick=\"closePopup('" + id + "'); return false;\" onmouseover=\"pointer(this);\" src=\"/images/popupclose.gif\" width=\"15\" height=\"15\" alt=\"\" /></td></tr></table><div class=\"popupContent\">" + contents + "</div></td></tr></table>";
	}
	else
	{
		popup.style.display = "block";
		popup.style.visibility = "visible";
	}
	
	document.getElementById("windowPane").style.left = document.documentElement.scrollLeft + "px";
	document.getElementById("windowPane").style.top = document.documentElement.scrollTop + "px";	
	
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		document.getElementById("windowPane").style.display = "block";
	}else{
		document.getElementById("windowPane").style.display = "table";
	}
	
	//show the background filter;
	document.getElementById("transfilter").style.display = "block";
	
	return false;
}


function popupflash(id, title, filename, width, height)
{
	var popup =  document.getElementById(id);
	
	if(popup==null)
	{		
			document.getElementById("popupPlaceholder").innerHTML += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"" + id + "\"class=\"popup\" style=\"\"><tr valign=\"top\"><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr valign=\"top\" class=\"popupHeaderRow\"><td><div class=\"popupTitle\">" + title +"</div></td><td valign=\"middle\" align=\"right\" class=\"popupClose\"><img onclick=\"closePopup('" + id + "'); return false;\" onmouseover=\"pointer(this);\" src=\"/images/popupclose.gif\" width=\"15\" height=\"15\" alt=\"\" /></td></tr></table><div class=\"popupFlashContent\" id=\"flashVideoPopup\"></div></td></tr></table>";
			
			var so = new SWFObject("/flash/vid.swf", "spromo", "640", "520", "9", "#000");
			so.addVariable("filename", filename);
			so.addVariable("vidWidth", width);
			so.addVariable("vidHeight", height);
			so.addParam("wmode", "transparent")
			so.write("flashVideoPopup");
	}
	else
	{
		popup.style.display = "block";
		popup.style.visibility = "visible";
	}
	
	document.getElementById("windowPane").style.left = document.documentElement.scrollLeft + "px";
	document.getElementById("windowPane").style.top = document.documentElement.scrollTop + "px";	
	
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		document.getElementById("windowPane").style.display = "block";
	}else{
		document.getElementById("windowPane").style.display = "table";
	}
	
	//show the background filter;
	document.getElementById("transfilter").style.display = "block";
}

function closePopup(id)
{	
	document.getElementById("popupPlaceholder").innerHTML = "";	
	document.getElementById("windowPane").style.display = "none";	
	document.getElementById("transfilter").style.display = "none";
}

function initGMap()
{
 if (GBrowserIsCompatible()) { 

      // A function to create the marker and set up the event window
      // Dont try to unroll this function. It has to be here for the function closure
      // Each instance of the function preserves the contends of a different instance
      // of the "marker" and "html" variables which will be needed later when the event triggers.    
      function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }

      // Display the map, with some controls and set the initial location 
	  
      var map = new GMap2(document.getElementById("map"), {size:new GSize(740,350)});
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(43.907787,-79.359741),8);
    
      // Set up three markers with info windows 
    
      var point = new GLatLng(43.65654,-79.90138);
      var marker = createMarker(point,'<div style="width:240px">Some stuff to display in the First Info Window. With a <a href="http://www.econym.demon.co.uk">Link</a> to my home page</div>')
      map.addOverlay(marker);

      var point = new GLatLng(43.91892,-78.89231);
      var marker = createMarker(point,'Some stuff to display in the<br>Second Info Window')
      map.addOverlay(marker);

      var point = new GLatLng(43.82589,-79.10040);
      var marker = createMarker(point,'Some stuff to display in the<br>Third Info Window')
      map.addOverlay(marker);

    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm	
}
