// Browser detect check 4445566

var ie4 = (document.all && !document.getElementById) ? true:false;
var ns4 = (document.layers) ? true:false;
var dom2 = (document.getElementById) ? true:false;

var loc = new String(document.location);


// Random number generator: 0 to (max - 1)

function pickRandom(max) {
	return Math.floor(Math.random() * max);
}


// Home banner

function buildhomebanner() {
	var ran = pickRandom(2) + 1;

	var homebannerstring = '<td valign="top"><img src="images/homebanner' + ran + '.jpg" width=626 height=271 border=0></td>'
//	homebannerstring += '<td width="100%"><table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td background="images/home/homebanner' + ran + '_bg.jpg"><img src="/images/common/spacer.gif" alt="" width="5" height="219" border="0"></td></tr><tr><td><img src="/images/common/spacer.gif" alt="" width="5" height="17" border="0"></td></tr></table></td></tr></table>';
	
	document.write(homebannerstring);
}


// Rollover functions

var offstate = new Array();
var onstate = new Array();


function preloadmodelimages(imagedir,whichimg) {
	offstate['blast'] = new Image();
	offstate['blast'].src = imagedir + whichimg + 'blast_off.gif';
	offstate['lightning']= new Image();
	offstate['lightning'].src = imagedir + whichimg + 'lightning_off.gif';
	offstate['firebolt'] = new Image();
	offstate['firebolt'].src = imagedir + whichimg + 'firebolt_off.gif';
	onstate['blast'] = new Image();
	onstate['blast'].src = imagedir + whichimg + 'blast_on.gif';
	onstate['lightning'] = new Image();
	onstate['lightning'].src = imagedir + whichimg + 'lightning_on.gif';
	onstate['firebolt'] = new Image();
	onstate['firebolt'].src = imagedir + whichimg + 'firebolt_on.gif';
}

function modelrollon(whichmodel) {
	document.images[whichmodel].src = onstate[whichmodel].src;
}

function modelrolloff(whichmodel) {
	document.images[whichmodel].src = offstate[whichmodel].src;
}


// Photo gallery

function buildgallerythumbnails() {
	var gallerystring = '<span style="font-size: 6px">';
	for (i = 0; i < numphotos; i++) {
		gallerystring += '<a href="javascript:gallerypopup(' + (i + 1) + ')"><img src="' + photodir + photoname + (i + 1) + '_thumb.jpg" alt="" border="0" vspace="2"></a> ';
	}
	gallerystring += '</span>';
	document.write(gallerystring);
}

function gallerypopup(whichphoto) {
	var windowprops = 'width=' + popupwidth + ',height=' + popupheight + ',location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no';
	var whichdoc = popuppage + '?photo=' + whichphoto;
	var newwin = window.open(whichdoc, photoname, windowprops);
}


// Color selector 

function switchcolor(whichcolor) {
	document.images['modelcolor'].src = colordir + 'color_' + whichcolor + '.jpg';
}


// Pop up functions

function popwin(loc,winname,w,h,scroll,resize) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=' + ((screen.height - h) / 2) + ',left=' + ((screen.width - w) / 2) + ',location=no,scrollbars=' + scroll + ',menubar=no,toolbar=no,resizable=' + resize + '")');
}

function popwinLoc(loc,winname,w,h,scroll,resize,L,T) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=' + T + ',left=' + L + ',location=no,scrollbars=' + scroll + ',menubar=no,toolbar=no,resizable=' + resize + '")');
}

function popwinmenu(loc,winname,w,h,scroll,resize) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=' + ((screen.height - h) / 2) + ',left=' + ((screen.width - w) / 2) + ',location=no,scrollbars=' + scroll + ',menubar=yes,toolbar=yes,resizable=' + resize + '")');
}
function popwinmenutop(loc,winname,w,h,scroll,resize) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=' + 0 + ',left=' + ((screen.width - w) / 2) + ',location=no,scrollbars=' + scroll + ',menubar=yes,toolbar=yes,resizable=' + resize + '")');
}

function openinmain(whichpage) {
	window.opener.location = whichpage;
}

function printpage() {
	if (window.print){
  		window.print();
	} else {
		alert("Printing Instructions:\n\n - If you are using a Macintosh, please select \"Print\" from the \"File\" menu.\n - If you are using Windows, right click the page and select \"Print\" from the pop-up menu.");
	}
}

function riderlocator() {
	if (loc.indexOf('/en_us/') != -1) {
		popwin('/locator/ridersedge_us.asp','dealer',610,590,'yes','yes');
	} else {
		dealerlocator();
	}
}

function openinmain(whichpage) {
	window.opener.location = whichpage;
}

// Universal image rollover functions


function imghighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_off\.','g'),'_on\.');
	whichimg.src = imgsrc;
}

function imgnohighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_on\.','g'),'_off\.');
	whichimg.src = imgsrc;
}


// Navigation rollover functions

function sidenavon(whichnav) {
	document.images['sidenav' + whichnav].src = '/images/common/yellowbullet.gif';
}

function sidenavoff(whichnav) {
	document.images['sidenav' + whichnav].src = '/images/common/ltgraybullet.gif';
}

function switchbullet(name,number,color) {
	document.images[name + number].src = '/images/common/' + color + 'bullet.gif';
}

function menurollon(whichdoc,whichimg) {
	if (ns4 && whichdoc != '') {
		eval('document.layers["' + whichdoc + '"].document.images["' + whichimg + '"].src = "' + linkbase + 'images/nav/' + whichimg + '_on.gif"');
	} else {
		eval('document.images["' + whichimg + '"].src = "' + linkbase + 'images/nav/' + whichimg + '_on.gif"');
	}
}

function menurolloff(whichdoc,whichimg) {
	if (ns4 && whichdoc != '') {
		if (whichdoc != '') {
			eval('document.layers["' + whichdoc + '"].document.images["' + whichimg + '"].src = "' + linkbase + 'images/nav/' + whichimg + '_off.gif"');
		}
	} else {
		eval('document.images["' + whichimg + '"].src = "' + linkbase + 'images/nav/' + whichimg + '_off.gif"');
	}
}

function uppercaser(text) {
	text = text.toUpperCase();
	text = text.replace(new RegExp('&AMP;','g'),'&amp;');
	text = text.replace(new RegExp('UML;','g'),'uml;');
	text = text.replace(new RegExp('ACUTE;','g'),'acute;');
	text = text.replace(new RegExp('GRAVE;','g'),'grave;');
	text = text.replace(new RegExp('CEDIL;','g'),'cedil;');
	text = text.replace(new RegExp('CIRC;','g'),'circ;');
	text = text.replace(new RegExp('TILDE;','g'),'tilde;');
	text = text.replace(new RegExp('RING;','g'),'ring;');
	text = text.replace(new RegExp('LIG;','g'),'lig;');
	return text;
}

