//Service & Body Shop

var imgOnAppointment = new Image(253,48);
imgOnAppointment.src = '/images/image.php?file=buttons/'+ISOCODE+'/appointment2.gif';
var imgOffAppointment = new Image(253,48);
imgOffAppointment.src = '/images/image.php?file=buttons/'+ISOCODE+'/appointment1.gif';

// MORE INFO BUTTON
var imgOnInfo = new Image(253,48);
imgOnInfo.src = '/images/image.php?file=buttons/'+ISOCODE+'/more_info2.gif';
var imgOffInfo = new Image(253,48);
imgOffInfo.src = '/images/image.php?file=buttons/'+ISOCODE+'/more_info1.gif';

//Parts
var imgOnPartsRequest = new Image(253,48);
imgOnPartsRequest.src = '/images/image.php?file=buttons/'+ISOCODE+'/parts_request2.gif';
var imgOffPartsRequest = new Image(253,48);
imgOffPartsRequest.src = '/images/image.php?file=buttons/'+ISOCODE+'/parts_request1.gif';

//Finance
var imgOnCreditApp = new Image(253,48);
imgOnCreditApp.src = '/images/image.php?file=buttons/'+ISOCODE+'/credit_app2.gif';
var imgOffCreditApp = new Image(253,48);
imgOffCreditApp.src = '/images/image.php?file=buttons/'+ISOCODE+'/credit_app1.gif';

function changeImg(imgName,imgPre) {
	if(document.images){
		document.images[imgName].src = eval(imgPre + '.src');
	}
}

var aTabs = new Array( "searchNew", "searchPreowned", "searchDemos", "searchPromotions" );
function SwitchActiveTab( sActive, NewClassName )
{
	for( var i = 0; i < aTabs.length; i++ )
	{
		var el = document.getElementById( aTabs[ i ] );
		var sectionContent = document.getElementById( el.id + "_content" );
		if( el.id == sActive.id )
			{
				el.className = NewClassName;
				sectionContent.style.display = "block";
			}
		else 
			{
				el.className = "";
				sectionContent.style.display = "none";
			}
		el = null;
		sectionContent = null;
	}
	return false;
}

function SwitchSiteLanguage(IsoCode)
{
  var Cookie    = '';
  var dExpires  = new Date();

  dExpires.setTime(dExpires.getTime() + 60 * 60 * 24 * 30 * 1000);

  Cookie += 'site_language=' + IsoCode + '; ';
  Cookie += 'expires=' + dExpires.toGMTString() + '; ';
  Cookie += 'path=/; ';

  document.cookie = Cookie;

  return true;
}

sfHover = function() {
	var timeout = 500;
	var cssClass = "sfhover";

	var queue = [];
	var reCSS = new RegExp("\\b" + cssClass + "\\b");
	var sfEls = document.getElementById("topMenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {

		// mouseover and mouseout handlers for regular mouse based interface.
		sfEls[i].onmouseover = function() {
			queueFlush();
			this.className += " " + cssClass;
		}
		sfEls[i].onmouseout = function() {
			queue.push([setTimeout(queueTimeout, timeout), this]);
		}

		// focus and blur handlers for keyboard based navigation.
		sfEls[i].onfocus = function() {
			queueFlush();
			this.className += " " + cssClass;
		}
		sfEls[i].onblur = function() {
			queue.push([setTimeout(queueTimeout, timeout), this]);
		}

		// click event handler needed for tablet type interfaces (e.g. Apple iPhone).
		sfEls[i].onclick = function(e) {
			if (this.className.search(reCSS) == -1) {
				// CSS not set, so clear all sibling (and decendants) menus, and then set CSS on this menu...
				var elems = this.parentNode.getElementsByTagName("li");
				for (var i=0; i<elems.length; i++) {
					elems[i].className = elems[i].className.replace(reCSS, "");
				}
				this.className += " " + cssClass;
			} else {
				// CSS already set, so clear all decendant menus and then this menu...
				var elems = this.getElementsByTagName("li");
				for (var i=0; i<elems.length; i++) {
					elems[i].className = elems[i].className.replace(reCSS, "");
				}
				this.className = this.className.replace(reCSS, "");
			}
			if (e && e.stopPropagation)
				e.stopPropagation();
			else
				window.event.cancelBubble = true;
		}
	}

	queueFlush = function () {
		while (queue.length) {
			clearTimeout(queue[0][0]);
			queueTimeout();
		}
	}

	queueTimeout = function() {
		if (queue.length) {
			var el = queue.shift()[1];
			el.className = el.className.replace(reCSS, "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

function init() {//function call required as part of body onload event when google map used on a page
		sfHover();
		loadGoogleMap();
	}
addLoadEvent(sfHover);
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function changeStyle(obj, new_style) {
    obj.className = new_style;
}

function openWindow(url,width,height){
	newWin = window.open(url, 'viewWin', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,left='+(screen.width-width)/2+',top='+(screen.height-height)/2+',width=' + width + ',height=' + height + '');

}

function loadRelp() {
	openWindow('http://www.realelivepeople.com/guest.php?requestedHost='+RELPCODE+'&clientLanguage='+LOWERISO,600,550);	
}

/*$(document).ready(function() {
  	$("#footerLinks li.nvFirst a").addClass("first");
		$("#footerLinks li a").unwrap();
		
		$('a.leadButton').removeAttr('onclick');
		$('a.newLead, a.leadButton').click(function(){
			window.open(this.href, 'viewWin', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,left='+(screen.width-600)/2+',top='+(screen.height-550)/2+',width=600,height=550, ');
			return false;
		});
 	});*/

function switchSearchTab (searchType) {	
	$('#searchContainerHeader a').removeClass('current');
	$('#searchContainerBody div').css('display', 'none');
	
	var searchFor = '#'+searchType;
	//alert(searchFor);
	$(searchFor).addClass('current');
	
	switch (searchType)
	{
		case 'searchNew':
			$('#searchNew_content').css('display', 'block');
			$('#searchNew_content .searchBoxGrey').css('display', 'block');
			break;
		case 'searchUsed':
			$('#searchUsed_content').css('display', 'block');
			$('#searchUsed_content .searchBoxGrey').css('display', 'block');
			break;
		case 'searchDemos':
			$('#searchDemos_content').css('display', 'block');
			$('#searchDemos_content .searchBoxGrey').css('display', 'block');
			break;
	}
}