var siteRoot
siteRoot = "/cudc/"

function findObj(theObj, theDoc) {
	var p, i, foundObj;
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)   {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	return foundObj;
}

function autonav() {//opens and highlights the appropriate menu item for the page
	if (navopen != null && navopen > 0) {
		toggle(navopen, arrayMove[navopen-1]);
		var tcell = ('subnav' + navopen + navsub);
		tcell = document.getElementById(tcell);
		tcell.style.backgroundImage = "url(" + siteRoot + "images/sub_nav_high.gif)";
	}
}

function rollover(n, state) {//opens and highlights the appropriate menu item for the page
	var imgName
	if (state=='over') {
		imgName = siteRoot + "images/main_nav_btn_over.jpg";
	} else {
		imgName = siteRoot + "images/main_nav_btn.jpg";
	}
	var tcell = ('titletable' + n);
	tcell = document.getElementById(tcell);
	tcell.style.backgroundImage = 'url('+imgName+')';
}

function picopen(n) { //changes the nav arrow to a down arrow
	//alert('picopen');
	pic = ('navimg' + n);
	pic = document.getElementById(pic);
	pic.src = siteRoot + "images/mnav_open.gif";
}

function picclose(n) { //changes the nav arrow to a sideways arrow
	//alert('picclose');
	pic = ('navimg' + n);
	pic = document.getElementById(pic);
	pic.src = siteRoot + "images/mnav_closed.gif";
}

function lasttoggle(n,move) { //closes the last menu toggled
	if (n <= nom) {
		menu = ('sub' + n);
		submenu = document.getElementById(menu);
		submenu = submenu.style;
	//alert(submenu.visibility);
		if (submenu.visibility == visible) {
			submenu.visibility = hidden;
			picclose(n); // Remove this if you don't use pictures
			for (var i = (n+1); i <= nom; i++) {
				submenu = document.getElementById(ttls[i]);
				submenu.style.top = parseInt(submenu.style.top) - move;
			}
		}
	}
}

function toggle(n,move) { //toggles the selected menu item and closes any previously opened items
	menu = ('sub' + n);
	submenu = document.getElementById(menu);
	submenu = submenu.style;
//alert(submenu.visibility);
	if (submenu.visibility == visible) {
		submenu.visibility = hidden;
		picclose(n);
		for (var i = (n+1); i <= nom; i++) {
			submenu = document.getElementById(ttls[i]);
			submenu.style.top = parseInt(submenu.style.top) - move;
		}
	} else {
		submenu.visibility = visible;
		picopen(n);
		if (lastn != n && lastn != 0) {
			lasttoggle(lastn,lastmove);
		}
		for (var i = (n+1); i <= nom; i++) {
			submenu = document.getElementById(ttls[i]);
			submenu.style.top = parseInt(submenu.style.top) + move;
		}
	}
	lastn = n;
	lastmove = move;
}

//Dependencies: Requires dealerlist.asp page to be loaded
function switchCity(citySel) {
	citySel = document.getElementById(citySel)
	for (i=0; i <= cityList.length-1; i++) {
		submenu = document.getElementById(cityList[i]);
		submenu = submenu.style;
		if (citySel.value != cityList[i]) {
			submenu.visibility = hidden;
		} else {
			submenu.visibility = visible;
		}
	}
}

function WriteLayer(ID) { 
	var iTemp, sText, iHTML;
	ID = document.getElementById(ID);
	iTemp = ID.value;
	if (iTemp != '* All') {
		iArr = cityGroup[iTemp];
		sText = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>'
		sText = sText + '<table cellspacing=1 cellpadding=3 width=470 align=center border=0>';
		for (p=0; p <= iArr.length-1; p++) {
			sText = sText + '<tr class=Color_TableLightBlue><td>' + cityGroup[iTemp][p] + '</td><td>' + iTemp + '</td></tr>';
		}
		sText = sText + '</table></td></tr></table>';
	} else {
		sText = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>'
		sText = sText + '<table cellspacing=1 cellpadding=3 width=470 align=center border=0>';
		for (p=0; p <= disArr.length-1; p++) {
			sText = sText + '<tr class=Color_TableLightBlue><td>' + disArr[p] + '</td><td>' + cityArr[p] + '</td></tr>';
		}
		sText = sText + '</table></td></tr></table>';
	}
	ID = 'scrollList';
	iHTML = document.getElementById(ID);
	iHTML.innerHTML= sText;
}

var popUpWin=0;
function popUpWindow(winTitle, URLStr, left, top, width, height) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

