/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
 function doClick (buttonID, e)
 {

    var iKey = 0;
    
    if (window.event)
    {
        iKey = window.event.keyCode;
    }
    else
    {
        iKey = e.which;
    }
    
    if (iKey == 13)
    {
    
        var oButton = document.getElementById(buttonID);
        
        if (oButton != null)
        {
            
            oButton.click();
            event.keyCode = 0;
            
        }
        
    }
    
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

/* Clear the content of a field */
function clearField(fId, iniTxt)
{
	if(fId.value==iniTxt) { fId.value = ""; }
}


/* Switch the tabs for the more detail section of the site */
function showElement(element) {
	element.style.display = 'block';
	element.style.visibility = 'visible';
}

function hideElement(element) {
	element.style.display = 'none';
	element.style.visibility = 'hidden';
}

/* hide show list elements */
function toggleLayer(whichLayer) {
	
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	//else if (document.layers) {
		// this is the way nn4 works
		//var style2 = document.layers[whichLayer].style;
		//style2.display = style2.display? "":"block";
	//}	alert(elem.getAttribute);
}
/* end of show list elements -- JJ 25/11/2007 for FAQ pages */

function getClassName(elem) {
	
	if (!elem || elem.getAttribute == 'undefined') {
		return null;
	}
	var class_name= elem.getAttribute('class');
	
	if (class_name == null || class_name == '') {
		class_name= elem.getAttribute('className');
	}
	return class_name;
}

function SwitchTabs(_1, sElementType){
    if(_1){
        this.exists=true;
        this.tabs_div=_1;
        this.tab_buttons=this._createTabButtonArray(sElementType);
        this.tab_divs=this._createTabArray();
    }else{
        this.exists=false;
    }
}

SwitchTabs.prototype._createTabButtonArray=function(sElementType){
    var _2=this.tabs_div.getElementsByTagName(sElementType);
    var _3=Array();
    if(_2&&_2.length>0){
        for(var i=0;i<_2.length;i++){        
            var _5=getClassName(_2[i]);
            if(_5&&_5.substring(0,6)=="button"){
            _3.push(_2[i]);
            }
        }
    }
    return _3;
};

SwitchTabs.prototype._createTabArray=function(){
    var _6=Array();
    var _7=this.tabs_div.getElementsByTagName("div");
    if(_7&&_7.length>0){
        for(var i=0;i<_7.length;i++){
            if(_7[i].id.substring(0,3)=="tab"){
            _6.push(_7[i]);
            }
        }
    }
    return _6;
};

SwitchTabs.prototype.addEventHandlers=function(){
    if(!this.exists){
        return;
    }
    for(var i=0;i<this.tab_buttons.length;i++){
        var _a=this;
        this.tab_buttons[i].onclick=function(){
            var _b=getClassName(this);
            var _Num = _b.substring(7);
            var _c="tab_"+_Num;
            
            if (window.ChangeTab) //check function exists
            {
                ChangeTab(parseInt(_Num) + 1);
            }
            var _d=document.getElementById(_c);
            _a.setActiveTab(_d);
            };
    }
};

SwitchTabs.prototype.setActiveTab=function(_e){
    if(!this.exists){
        return;
    }
    for(var i=0;i<this.tab_divs.length;i++){
        hideElement(this.tab_divs[i]);
    }
    if(parseInt(_e)==_e){
        _e=this.tab_divs[_e];
    }
    showElement(_e);
};

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		document.getElementById(countfield).innerHTML = maxlimit - field.value.length;
}


function textCounterCheckout(field,  maxlimit, message) {
	if (field.value.length > maxlimit) { // if too long...trim it!
	    confirm(message);
	    field.value = field.value.substring(0, maxlimit);
	}
	

	// otherwise, update 'characters left' counter
	//else 
	//	document.getElementById(countfield).innerHTML = maxlimit - field.value.length;
	
//	if (field.value.length == maxlimit) 
//{	confirm("Address lines should be no more than 30 characters\nPlease enter further details below") }
	
}


/* basket and product detail quantity changer */
function qty_plus(whichLayer) {
	var qty = document.getElementById(whichLayer);
	if (parseInt(qty.value)) {
	if (qty.value < 999) {
	qty.value = parseInt(qty.value) + 1;
	}
	}
}
function qty_minus(whichLayer) {
	var qty = document.getElementById(whichLayer);
		if (parseInt(qty.value)) {
	if (qty.value > 0) {
		qty.value = parseInt(qty.value) - 1;
	}
	}
}

/***********************************************
* Bookmark site script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmark(title, url) {
	
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all) { // ie
		window.external.AddFavorite(url, title);
	}
}
/* END Bookmark this page */

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(){
	if (document.getElementById) {
		return document.getElementById("trailimageid").style
	}
	else if (document.all) {
		return document.all.trailimagid.style
	}
}

function gettrailobjnostyle(){
	if (document.getElementById) {
		return document.getElementById("trailimageid")
	}
	else if (document.all) {
		return document.all.trailimagid
	}
}

function truebody() {
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(title,description,currentimageheight) {
	document.onmousemove=followmouse;

	newHTML = '<div class="info_box">';
	newHTML = newHTML + '<h2>' + title + '</h2>';
	newHTML = newHTML + description + '<br/>';

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}


function hidetrail() {
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"
}

function followmouse(e) {
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - 15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){ // firefix
		xcoord = e.pageX - xcoord - 117; // Move to the left side of the cursor
		ycoord += e.pageY - 10;
	} else if (typeof window.event != "undefined"){ // ie
		xcoord = event.clientX + truebody().scrollLeft - xcoord - 117; // Move to the left side of the cursor
		ycoord += truebody().scrollTop + event.clientY - 10;
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
/* END Simple Image Trail */