﻿// Electromotion JavaScript Library

function enquire()
{
	window.location = 'contact.aspx?action=enquire&origin=' + encode(window.location);
}

function encode(text) 
{
	var sEncoded = '';
	
	sEncoded = escape(text);
	sEncoded = sEncoded.replace(/\//g,"%2F");
	sEncoded = sEncoded.replace(/\?/g,"%3F");
	sEncoded = sEncoded.replace(/=/g,"%3D");
	sEncoded = sEncoded.replace(/&/g,"%26");
	sEncoded = sEncoded.replace(/@/g,"%40");
	return sEncoded;
} 

var dayName = new Array("", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
var monName = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;

function initImgID() {di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}

function findElement(n,ly) {
	d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (d.layers) {img = findElement(changeImages.arguments[i],0);}
			else {img = d.images[changeImages.arguments[i]];}
			if (img) {img.src = changeImages.arguments[i+1];}
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		over_navhelp2 = newImage(/*URL*/'media/navhelp_on.gif');
		over_navhome2 = newImage(/*URL*/'media/navhome_on.gif');
		over_navprint2 = newImage(/*URL*/'media/navprint_on.gif');
		over_navcontact2 = newImage(/*URL*/'media/navcontact_on.gif');
		over_navlocn2 = newImage('media/navlocns_on.gif');
		over_navabout2 = newImage('media/navabout_on.gif');
		over_navwoodworking = newImage(/*URL*/'media/navwoodworking_on.gif');
		over_navmachinetools = newImage(/*URL*/'media/navmachinetools_on.gif');
		over_navsheetmetal = newImage(/*URL*/'media/navsheetmetal_on.gif');
		preloadFlag = true;
	}
}

var	isNS = navigator.appName == "Netscape";
var	isIE = navigator.appName == "Microsoft Internet Explorer";
var	isOpera = navigator.userAgent.indexOf("Opera") > -1;

function setUp()
{

   window.onresize = refreshValues;

   refreshValues();
}

function refreshValues() 
{

   if (isOpera) {
	document.all.opspacer.style.height = 10;
	if (document.body.scrollHeight < document.body.clientHeight)
	{
		document.all.opspacer.style.height = document.body.clientHeight - 261;
	}
	else
	{
		document.all.opspacer.style.height = document.body.scrollHeight - 261;
	}
   }
}

function catchSearch(e)
{
	if (!e) e = window.event;
	var code = e.keyCode; 
	if (code == 13) doSearch();
}

function catchMailList(e)
{
	if (!e) e = window.event;
	var code = e.keyCode; 
	if (code == 13) doMailList();
}


function doSearch()
{
	window.location = 'search.aspx?searchtext=' + document.getElementById('searchtext').value;
}

function doMailList()
{
	window.location = 'maillist.aspx?email=' + encode(document.getElementById('txtMail').value) + '&origin=' + encode(window.location);
}

function addToFavorites(theTitle)
{	
	var title = '';
	if (theTitle == '')
	{
	    title = getObjValue('REF') + ' - ' + getObjValue('MANUF') + ' ' + getObjValue('MODEL');
	}
	else
	{
	    title = theTitle;
	}
	var url = window.location.href; 
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");	
	} else if( window.external ) { // IE Favorite
	    try {
            window.external.AddFavorite( url, title);
        } 
        catch (error) {
            alert('Please add this page to your favourites by using the Add to favourites option in your browser!');
        }		
	} else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}


function mailPage(theTitle)
{
	self.location = 'mailpage.aspx?url=' + 
				    encode(self.location) + 
				    '&title=' + encode(theTitle);
}


function menuItemClick(menuId, itemId) 
{
    var menu = igmenu_getMenuById(menuId);
    var item = igmenu_getItemById(itemId);
    if (item != null) {
        var itemTag = item.getTag();        
        var tagType = itemTag.substring(0,1);
        var id = itemTag.substring(1);
        switch(tagType)
            {                           
                case 'c':
                    var childItems = item.getItems();                    
                    if (childItems.length == 0)
                        {
                        self.location = 'search.aspx?cat=' + id;
                        }
                    break;
                case 's':    
                    self.location = 'search.aspx?subcat=' + id;           
                    break;
            }
    }
}


// Finds a server control on the client side by id
function findObjWithClientId(Id) 
{ 
    var ctrls = document.getElementsByTagName("body")[0].getElementsByTagName("*");
    for(var count = 0; count < ctrls.length ; count ++) 
    { 
        var index = ctrls[count].id.indexOf(Id); 
        if(index != -1) 
        { 
            if((ctrls[count].id.length - index) == Id.length) 
            { 
                return ctrls[count]; 
            } 
        } 
    } 
    return null; 
}