var cm=null;
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  //self.blur();
}

function expandCollapseClick (DOMEvent)
{
	var customGetByID;
	var parentID;
	var child;
	if (document.all)
	{
		document.getElementById = document.all;
		parentID = window.event.srcElement.id;
		child = document.getElementById ("m" + parentID);
	}
	else
	{
		parentID = DOMEvent.target.id;
		child = document.getElementById ("m" + parentID);
	}
	if (child != null)
	{
		var parentImage = document.getElementById (parentID);
		if (child.style.display == "none")
		{
			child.style.display = "block";
			parentImage.src = "/discussion/minus.gif";
			parentImage.alt = "- Collapse this area";
		}
		else
		{
			child.style.display = "none";
			parentImage.src = "/discussion/plus.gif";
			parentImage.alt = "+ Expand this area";
		}
	}
	return true;
}

function expandCollapse (parentID)
{
	var child;
	child = document.getElementById ("m" + parentID);

	if (child != null)
	{
	child.style.display = "block";
	}
	return true;
}

function LCexpandCollapseClick (DOMEvent)
{
	var customGetByID;
	var parentID;
	var child;
	if (document.all)
	{
		document.getElementById = document.all;
		parentID = window.event.srcElement.id;
		child = document.getElementById ("m" + parentID);
	}
	else
	{
		parentID = DOMEvent.target.id;
		child = document.getElementById ("m" + parentID);
	}
	if (child != null)
	{
		var parentImage = document.getElementById (parentID);
		if (child.style.display == "none")
		{
			child.style.display = "block";
			parentImage.src = "/images/lc_test.gif";
			parentImage.alt = "- Collapse this area";
		}
		else
		{
			child.style.display = "none";
			parentImage.src = "/images/lc_test.gif";
			parentImage.alt = "+ Expand this area";
		}
	}
	return true;
}

function RTKL_showHideContent(id,bOn)
{
	var bMO = false;
	var oContent = document.all.item(id);
	if (!oContent) return;

	if (event.srcElement)
	{
		bOn = (oContent.style.display.toLowerCase() == "none");
	}

	if (bOn == false)
	{
		oContent.style.display = "none";
	}
	else
	{
		oContent.style.display = "";
		if (id = "browseWindow")
		{
		oContent.style.overflow = "scroll";
		}
	}

}


function RTKL_toggleText(id,bOn)
{
	var bMO = false;
	var oContent = document.all.item(id);
	if (!oContent) return;

	if (event.srcElement)
	{
		bOn = (oContent.innerHTML == "Open Browse Window");
	}

	if (bOn == false)
	{
		oContent.innerHTML = "Open Browse Window";
	}
	else
	{
		oContent.innerHTML = "Close Browse Window";
	}

}


function showDiv (parentID)
{
	var child;
	child = document.getElementById (parentID);

	if (child != null)
	{
	child.style.display = "";
	}
	return true;
}

function hideDiv (parentID)
{
	var child;
	child = document.getElementById (parentID);

	if (child != null)
	{
	child.style.display = "none";
	}
	return true;
}

function CheckList(elCheckBox, elSelectList)
{
	var elBox = FindElement(elCheckBox);
	var elList = FindElement(elSelectList);

	for (var i = 0; i < elList.length; i++)
	{
		elList.options[i].selected = elBox.checked;
	}
}

function FindElement(elementName)			// uses partial name
{
	if (document.getElementById) {
		var e1 = document.getElementById(elementName);
		if (e1 != null) return e1;
	}
	
	var frm = document.forms[0];
	var el = frm.elementName;
	if (el != null) return el;
	for (var i = 0; i < frm.elements.length; i++)   {
		if (frm.elements[i].name.indexOf(elementName) != -1) {
			return frm.elements[i];
		}
	}
	return null;
}

function SelectAll(elName) {
	for (var i=0;i<document.forms[0].elements.length;i++){
		var e=document.forms[0].elements[i];
		if (e.name==elName &! e.disabled) {
		e.checked=!e.checked;
		}
	}
}

function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;

}

function show(el,m) {
	if (m) {
		m.style.display='';
		m.style.Left = getPos(el,"Left");
		m.style.Top = getPos(el,"Top");
		m.style.Width = getPos(el,"Width");
		m.style.Height = getPos(el,"Height");
		//secs = 10
    //StartTheTimer()

	}
	if ((m!=cm) && (cm)) {
		cm.style.display='none';
		//StopTheClock()
	}
	cm=m;
}

function hide(el,m) {
	if (m) {
		m.style.display='none';
		//secs = 10
    //StartTheTimer()

	}
	if ((m!=cm) && (cm)) {
		cm.style.display='none';
		//StopTheClock()
	}
	cm=m;
}

function StopTheClock()
{
    if(timerRunning)
    	clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        show(null)
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
	
	/* RTKL - BASIC JAVASCRIPT (basic.js) - 
	   this file contains basic JavaScript for rollovers, popups, etc
	   and is included on all pages. It also contains the DHTML scripting for
	   the pop-up navigation menu scheme. */
	   
	var lastMenuOne = null;
	var lastMenuTwo = null;
	var lastHighSub = null;
	
	// below used for login link scripting
	var KeyID = 0;
	var retURL = null;
	document.onkeydown = checkKeyDown;
	document.onkeyup = restoreKeyUp;
	
	function openmail(raddr) {
		var wURL, wAttrs;
	
		wURL = 'ma' + 'il' + 'to:' + raddr + '@' + 'rt' + 'kl' + '.' + 'co' + 'm';
		//wAttrs = "height=464,width=620,resizable=no,scrollbars=no,status=no,toolbar=no,location=no";
		window.open(wURL, "", "");
		window.focus;		
	}
	
	function openmap(office) {
		var mapUrl, wAttrs;
		// 901 South Bond Street Baltimore MD 21231 USA
		// Serrano, 28 28001 Madrid, Spain
		// 5-17-6 Roppongi, Minato-ku Tokyo 106-0032, Japan
		switch (office) {
			case "Chicago":
				mapUrl = "http://maps.yahoo.com/broadband#mvt=m&q1=200%20South%20Michigan%20Avenue,%20Chicago,%20IL%2060604&trf=0&lon=-87.624593&lat=41.879467&mag=3";
				break;
			case "Dallas":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=1717+Pacific+Avenue+75201&sll=41.880028,-87.629397&sspn=0.011327,0.01899&ie=UTF8&z=17&iwloc=addr&om=1";
				break;
			case "LA":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=333+South+Hope+Street+90071&sll=32.782588,-96.79749&sspn=0.006395,0.009495&ie=UTF8&z=17&iwloc=addr&om=1";
				break;
			case "Miami":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=1500+San+Remo+Avenue+33146&sll=34.053315,-118.252725&sspn=0.006302,0.009495&ie=UTF8&z=17&iwloc=addr&om=1";
				break;
			case "DC":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=1250+Connecticut+Avenue,+NW+20036&sll=25.70604,-80.28235&sspn=0.006854,0.009495&ie=UTF8&z=16&iwloc=addr&om=1";
				break;
			case "London":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=22+Torrington+Place+London+WC1E&sll=51.52083,-0.133724&sspn=0.004733,0.009495&ie=UTF8&z=16&iwloc=addr&om=1";
				break;
			case "Madrid":
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=Serrano,+28+28001+Madrid,+Spain&sll=51.521647,-0.134167&sspn=0.009466,0.01899&ie=UTF8&z=16&iwloc=addr&om=1";
				break;
			case "Shanghai":
				mapUrl = "";
				break;
			case "Tokyo":
				mapUrl = "";
				break;
			default:
				mapUrl = "http://maps.google.com/maps?f=l&hl=en&geocode=&q=rtkl&near=baltimore+md&ie=UTF8&ei=ooHLRrK6DonKrAKRpbyODg&cd=1&cid=39285530,-76595350,3316050363494166030&li=lmd&z=14&iwloc=A&om=1";
				break;
		}
		
		if (mapUrl.length > 0) {
			wAttrs = "height=600,width=800,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes";
			window.open(mapUrl, "", wAttrs);
			window.focus;				
		}
	}
	
	function openJobApp(jid) {
		var wAttrs, wURL;
		
		if (jid.length > 0) {
			wAttrs = "width=800,height=600,menubar=no,toolbar=yes,resizable=yes,scrollbars=yes,status=yes";
			wURL = "http://www.rtkl.com/apply_online.aspx?jobID=" + jid;
			window.open(wURL, "RTKLApp", wAttrs);
			window.focus;				
		}	
	}
	
	function openJobPrint(jid) {
		var wAttrs, wURL;
		
		if (jid.length > 0) {
			wAttrs = "";
			wURL = "careers_print.aspx?id=" + jid;
			window.open(wURL, "RTKLApp", wAttrs);
			window.focus;				
		}	
	}
	
	function openPressPrint(id) {
		var wAttrs, wURL;
		
		if (id.length > 0) {
			wAttrs = "";
			wURL = "press_print.aspx?id=" + id;
			window.open(wURL, "RTKLPress", wAttrs);
			window.focus;				
		}	
	}
	
	function toggleDivBorder(obj, idx, stat) {
		// roll off and on red border (in this case, default gray border blends into bkgd to avoid 1px image move)
		// this global page variable [currThumbIdx] must be defined on the calling page
		var bstr;
		var doit = 0;
		if (stat == 1) {
			bstr = "1px solid #FF0000";
			doit = 1;
		} else if (stat == 0 && idx != currThumbIdx) {
			bstr = "1px solid #E1E1E1";
			//bstr = "none";
			doit = 1;
		}
		
		if (doit) {
			if (document.getElementsByTagName && document.getElementById) {
				//Netscape 6+ model (also works in IE 6)
				document.getElementById(obj).style.border = bstr;
			} else {
				if (document.all) {
					//IE model (at least, versions prior to 6)
					document.all(obj).style.border = bstr;	
				}	
			}	
		}
	}	
	
	function selectLeader(lidx) {
		// swap out highlighted leader photo and leader quote and make sure this thumbnail stays highlighted
		var obj, imgFileName, imgOld, thName;
		var imgName = "leaderHeadPhoto";
		if (currThumbIdx > 0) {
			// turn off previous highlight
			holdIdx = currThumbIdx;
			obj = "leadth_" + holdIdx;
			currThumbIdx = 0;
			toggleDivBorder(obj, holdIdx, 0);
		}
		// reset global flag to new highlight
		currThumbIdx = lidx;
		// swap leader highlighted graphic at top of box
		imgOld = document.images[imgName].src;
		//imgFileName = imgOld.substring(0, imgOld.lastIndexOf('/'));
		//imgFileName = imgFileName + "/" + "temp01_head.jpg";
		thName = "leadth_" + lidx;
		imgFileName = document.images[thName].src.replace("/leaders", "/leadersFull");
		document.images[imgName].src = imgFileName;
			
		// swap in title/name text for this leader id from hidden div placed on page
		obj = "leaderNameText_" + lidx;
		setElementText("leaderName", getElementText(obj));
		// swap in title/name text for this leader id from hidden div placed on page
		obj = "leaderQuoteText_" + lidx;
		setElementText("leaderQuote", getElementText(obj));		
	}
	
	function checkKeyDown(e) {
		// store globally last key press
		retURL = self.location;
		KeyID = (window.event) ? event.keyCode : e.keyCode;
	}
	
	function restoreKeyUp(e) {
		// on key up restore last key press to 0
		retURL = null;
		KeyID = 0;
	}
	
	function clickLogin() {
		// if "a" key is pressed (for "admin"), go to admin login page
		// otherwise, go to FTP 
		var goadm = 0;
		var goURL;
		
		if (KeyID == 65) {
			KeyID = 0;
			//alert("go admin login");
			goURL = "../login/login.cfm";
			if (retURL != null) 
				goURL = goURL + "?jump=" + escape(retURL);
			self.location = goURL;
		} else {
			//alert("go FTP");
			self.location = "ftp://ftp.rtkl.com";
			/* wURL = "ftp://ftp.rtkl.com";
			window.open(wURL, "", "");
			window.focus; */	
		}
	}
	
	
	
	function goToFAQtopic() {
		id = document.golink.catid.selectedIndex;
		if (id >= 0) {
			cid = document.golink.catid.options[id].value;
			location.href = "#faqcat" + cid;
		}
	}
	
	function findDealerOnEnter(e){ 
		// (e is event object passed from function call)		
		var keyCode 
	
		if (e && e.which) { 
			// key code is contained in mozilla's (netscape/firefox) which property
			e = e;
			keyCode = e.which;
		} else {
			// key code is contained in IE's keyCode property
			e = event;
			keyCode = e.keyCode; 
		}
	
		// if character code is ascii 13 (enter key), submit form
		if (keyCode == 13) { 
			// document.forms[0].submit();
			findDealer();
			return false; 
		} else {
			return true;
		}		
	}
	
	function setElementVisibility (obj, mode) {
		// update visibility of element requested
		if (mode == "h")
			var setstyl = "hidden";
		else
			var setstyl = "visible";
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = setstyl;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = setstyl;
			}	
		}		
	}	
	
	function setElementText (obj, str) {
		// update HTML of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).innerHTML = str;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).innerHTML = str;	
			}	
		}		
	}	
	
	function getElementText (obj) {
		// get HTML of element requested
		var str;
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			str = document.getElementById(obj).innerHTML;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				str = document.all(obj).innerHTML;	
			}	
		}	
		return str;
	}	
	
	function setElementBkgdColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.backgroundColor = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.backgroundColor = clr;	
			}	
		}		
	}	
	
	function setElementColor (obj, clr) {
		// update background-color of element requested
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.color = clr;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.color = clr;	
			}	
		}		
	}
	
	function showWinH() {
		var winh;
		//winh = window.innerHeight;
		winh = document.body.clientHeight;
		alert(winh);
	}
 
	function RollOnBasic(imgName) {
		if (document.images){
			imgFileName = "";
			imgOld = document.images[imgName].src;
			dotPos = imgOld.lastIndexOf('.');
			imgExt = imgOld.substring(dotPos+1, dotPos+4); 
			imgFileName = imgOld.substring(0, imgOld.lastIndexOf('_'));
			imgFileName = imgFileName + "_2." + imgExt;
			document.images[imgName].src = imgFileName;
		}
	}
	
	function RollOffBasic(imgName) {
		if (document.images){
			imgFileName = "";
			imgOld = document.images[imgName].src;
			dotPos = imgOld.lastIndexOf('.');
			imgExt = imgOld.substring(dotPos+1, dotPos+4); 
			imgFileName = imgOld.substring(0, imgOld.lastIndexOf('_'));
			imgFileName = imgFileName + "_1." + imgExt;
			document.images[imgName].src = imgFileName;
		}
	}

	
	function hideOrShowItem (obj, stat) {
		var vis;
		if (stat == 1) {
			vis = "visible";
			lastVisDiv = obj;
		} else {
			vis = "hidden";
			lastVisDiv = "";
		}
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = vis;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = vis;	
			}	
		}
	}
	
	function toggleFldMode(obj, basenm) {
		var stat = null;
		var setstyl = null;
		var fldid;
		
		fldid = obj + '_id';
		//toggle mode from whatever it is now, so need to check current status
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			stat = document.getElementById(obj).style.visibility;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				stat = document.all(obj).style.visibility;	
			}	
		}
				
		//set to opposite of current status
		if (stat == 'visible')
			setstyl = 'hidden';
		else
			setstyl = 'visible';
					
		//now set mode of object	
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			document.getElementById(obj).style.visibility = setstyl;
			//disable the field if hidden, so only one field passed
			if (setstyl == 'hidden')
				document.getElementById(fldid).disabled = true;
			else
				document.getElementById(fldid).disabled = false;
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				document.all(obj).style.visibility = setstyl;
				//disable the field if hidden, so only one field passed
				if (setstyl == 'hidden')
					document.all(fldid).disabled = true;
				else
					document.all(fldid).disabled = false;	
			}
		}
		return setstyl;	
	}	
	
	function updateText(obj, str) {
		// update text of element requested - this is for debugging popup script above
		var str;
		str = str + "<br>" + getElementText(obj);
		setElementText (obj, str);
	}
	
	
	
	// *** DMS 5-12-06: pasted in Sarah's IE active content kluge:
	// this function lets javascript output the necessary Flash object and embed tags
	// to workaround IE 6's new 'active content' security warnings 
	// *** DMS 5-13-06: added width & height params so can use for Help or other Flash content as well
	function RunFlash(flashfile, flashW, flashH) {
	   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,0,0" width="' + flashW + '" height="' + flashH + '">\n');
	    document.write(' <param name=movie value="' + flashfile + '" />\n');
		document.write(' <param name=quality value=high />\n');
		document.write(' <embed src="' + flashfile + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + flashW + '" height="' + flashH + '">\n');
		document.write('</embed>\n');
	    document.write('</object>\n');
	}	
		
function printpage() {
  window.print();
  }

