﻿// JScript File

/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dhtmlgoodies_slideSpeed = 20;	// Higher value = faster (set lower down)
var dhtmlgoodies_timer = 5;	// Lower value = faster
var oneAtATime = true;

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(answerDiv!=null){
	    if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		    if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId && oneAtATime){		
			    objectIdToSlideDown = numericId;
			    slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		    }else{
    			
			    answerDiv.style.display='block';
			    answerDiv.style.visibility = 'visible';
    			
			    slideContent(numericId,dhtmlgoodies_slideSpeed);
		    }
	    }else{
		    slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		    dhtmlgoodies_activeId = false;
	    }	
	}
	//x=x+1;
}

function slideContent(inputId,direction)
{
	switchClass(inputId,direction);
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
    //show tab here.
	dhtmlgoodies_slideSpeed = 1000;
	showHideContent('','dhtmlgoodies_q2');
	dhtmlgoodies_slideSpeed = 20;
}

window.onload = initShowHideDivs;

function switchClass(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_q' + inputId);
	if (direction>0){obj.className = "dhtmlgoodies_question_active";}
  else
  {obj.className = "dhtmlgoodies_question";}

}

//fire click
function fnTrapKD(e, btn){

var keynum
//   alert('hello' + btn);

//if (document.all){

if(window.event) // IE
    {
    keynum = e.keyCode
    }
else if(e.which) // Netscape/Firefox/Opera
    {
    keynum = e.which
    }
 if (keynum == 13)
   { 
     e.returnValue=false;
     //e.cancel = true;
     //document.getElementById(btn).click();
     //alert('hello' + btn);
     __doPostBack(btn,'');
     //btn.click();
     return false;
   }
// } 
}



//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/
/*
navHover = function() {
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);*/


function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        //obj.style.visibility = iState ? "visible" : "hidden";
        obj.style.display = iState ? "inline" : "none";
    }
    else if(document.all)	// IE 4
    {
        //document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        document.all[szDivID].style.display = iState ? "inline" : "none";
    }
}

function toggle_visibility(id) {
var e = document.getElementById(id);

if (e != null)
{
if(e.style.display == 'none')
    e.style.display = '';
else 
    e.style.display = 'none';}
}

function toggle_image(id) {
    var e = document.getElementById(id);
    if (e != null) {
        if (e.innerHTML == '<IMG style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none" alt="More Data" src="Images/Plus.gif">')
            e.innerHTML = '<IMG style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none" alt="More Data" src="Images/Minus.gif">';
        else
            e.innerHTML = '<IMG style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none" alt="More Data" src="Images/Plus.gif">';
    }
}

function set_display(id,value) {
    var e = document.getElementById(id);
    if( e != null) e.style.display = value;
}

function displayMsg(msg, id) {
//var e = document.getElementById("info");
var e = document.getElementById(id);
e.innerHTML=msg;
e.style.visibility="visible";
//setTimeout("document.getElementById('" + id + "').style.visibility='hidden';", 3000)
setTimeout("document.getElementById('" + id + "').style.visibility = 'hidden';", 3000)
}



function setFocus(msg) {
        document.getElementById(msg).focus();
        //WebForm_AutoFocus(msg);
}

function setCtrlFocus(c)

{

setTimeout("setCtrlFocus2('" + c + "')",500);

return true;

}

 

function setCtrlFocus2(c)

{
var t = document.getElementById(c);

try {

if( t != null) t.focus();//document.getElementById(c).focus();

}

catch (e){}

return true;

}

//PBY New For Menu
//function HideContent(d) {
//    if (d.length < 1) { return; }
//    document.getElementById(d).style.visibility = "hidden";
//}
//function ShowContent(d) {
//    if (d.length < 1) { return; }
//    document.getElementById(d).style.visibility = "visible";
//}
//PBY New For Menu


//PBY New For Showing And Hiding Divs
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }
function UpdateCursorPositionDocAll(e) { cX = event.clientX; cY = event.clientY; }
if (document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    d.style.left = (cX + 10) + "px";
    d.style.top = (cY + 10) + "px";
}
function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}
function ReverseContentDisplay(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    if (dd.style.display == "none") { dd.style.display = "block"; }
    else { dd.style.display = "none"; }
}
//PBY New For Showing And Hiding Divs

//PBY New for switching classes
function changeClass(idElement, newClass) {
    document.getElementById(idElement).setAttribute('class', newClass);
}
//PBY New for switching classes


//PBY New to sniff the browser
function warnAboutBrowser() {
    engine = null;
    ie8Browser = '';
    if (window.navigator.appName == "Microsoft Internet Explorer") {
        // This is an IE browser. What mode is the engine in?
        if (document.documentMode) // IE8
        {
            engine = document.documentMode;
            ie8Browser = 'Yes';
        }
        else // IE 5-7
        {
            engine = 5; // Assume quirks mode unless proven otherwise
            if (document.compatMode) {
                if (document.compatMode == "CSS1Compat")
                    engine = 7; // standards mode
            }
        }
        // the engine variable now contains the document compatibility mode.
        if (engine < 8) {
                        if (ie8Browser == 'Yes') { //alert("ie8Browser = : " + ie8Browser);
                alert('If the site is not displaying correctly\r\nplease click on Page in the top left of\r\nclick on Compatability view to remove\r\nthe tick.');
            }
            else
            {
                doIt = confirm('This website is best viewed in Internet Explorer 8.0.\r\nIf you are experiencing problems or the page is not\r\nbeing displayed correctly go to the Microsoft site to\r\ndownload the latest version?');
                if (doIt) {//alert("Engine = " + engine); //DO SOMETHING                    
                    window.open('http://www.microsoft.com/windows/internet-explorer/default.aspx');
                }
            }       
        }       
    }
}

function ResetScrollPosition() {
    setTimeout("window.scrollTo(0,0)", 0);
}


function bookmarksite(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);
}


function RedirectGoogleSearch(id, site) {
    var e = document.getElementById(id);
    if (e != null) {
        var str1 = 'http://www.google.co.uk/search?hl=en&lr=&as_qdr=all&q='
        var str2 = e.value.replace(' ', '+') + '+'; //car+parts+
        var str3 = 'site%3Ahttp%3A%2F%2F' //www.livingstonautoparts.co.uk'
        var str4 = site
        var str5 = str1 + str2 + str3 + str4;
        window.location = str5;
    }
}

function showMessage(id, text) {
    var e = document.getElementById(id);
    e.style.display = 'block';
    e.style.backgroundColor = "#00FFFF";
    e.innerHTML = text;
    window.setTimeout(function () {
        e.style.display = 'none';
    }, 5000);
}
