// Urls.js - sets URLs in static content

var Servlets = "/webapp/wcs/stores/servlet/";
var contextRoot = "JDHT";
var StaticContents = "/" + contextRoot;
var eShop = "Heritage"; // Heritage store name
var eShopStoreId = "10001";
var eShopCatalogId = "10001";

var eParts = "Parts";   // Parts store name
var ePartsStoreId = "10051";
var ePartsCatalogId = "10151";

var menu_item1 = '" target="_self" class="categoryLinks" onMouseOver="MM_showHideLayers(\'museum\',\'\',\'show\')" onMouseOut="MM_showHideLayers(\'museum\',\'\',\'hide\')"';
var item1 = '" class="categoryLinks"';

var menu_item2 = '" target="_self" class="menubar" onMouseOver="MM_showHideLayers(\'museum\',\'\',\'show\')" onMouseOut="MM_showHideLayers(\'museum\',\'\',\'hide\')"';
var item2 = '" class="menubar"';

var displayTimer = null;
var subMenuTimer = null;
var currentMenu = null;



function writeTraceCertsView(face, text)
{
    var URL = '<a href=\"#\" onclick="submitPRTServiceForm();" class="' + face + '">' + text + '</a>';
    document.write(URL);
}

function writeCarHireMailView(face, text)
{
    var URL = '<a href=\"#\" onclick="submitCarHireForm();" class="' + face + '">' + text + '</a>';
    document.write(URL);
}

function submitCarHireForm() {
    document.location = "../../CarHireMail.html";
}

function submitPRTServiceForm() {
    document.location = "../../TraceService.html";
}
function backToJaguarCollection() {
    document.location = "../html/Trust/jdht_collection/collection.html";
}
function writeWeddingHireMailView(face, text)
{
    var URL = '<a href="' + makeServletURL("WeddingHireMailView", eShopStoreId, eShopCatalogId) + '" class="' + face + '">' + text + '</a>';
    document.write(URL);
}



// Menu functions 
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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function buildTrustMenu() {

	var menuDiv = document.getElementById('trustMenuHolder');
	menuDiv.style.width = "780px";
	menuDiv.style.position = "absolute";

	if (menuDiv == null) {
		return;
	}

	var menuHTML = "";
	menuHTML = menuHTML + "<table id=\"trst_tbl\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	menuHTML = menuHTML + "  <tr valign=\"top\">";
	menuHTML = menuHTML + "     <td width=\"20%\" id=\"trst_td\" class=\"categoryLinks\"><div id=\"trst_lnk\" align=\"center\" class=\"menuDiv\" style=\"width:99%\" onmouseover=\"setMenuColor('trst',1,0,true)\" onmouseout=\"setMenuColor('trst',1,2)\" onclick=\"menuClick('" + StaticContents + "/html/Trust/index_intro.html','_top')\">The Trust</div></td>";
	menuHTML = menuHTML + "		<td width=\"20%\" id=\"shop_td\" class=\"categoryLinks\"><div id=\"shop_lnk\" align=\"center\" class=\"menuDiv\" style=\"width:99%\" onmouseover=\"setMenuColor('shop',1,0,false)\" onmouseout=\"setMenuColor('shop',1,1)\" onclick=\"menuClick('http://www.jdht.com/JDHT/html/TrustFrames.html','mainFrame')\">eShop</div></td>";
	menuHTML = menuHTML + " 	<td width=\"20%\" id=\"part_td\" class=\"categoryLinks\"><div id=\"part_lnk\" align=\"center\" class=\"menuDiv\" style=\"width:99%\" onmouseover=\"setMenuColor('part',1,0,false)\" onmouseout=\"setMenuColor('part',1,1)\" onclick=\"menuClick('http://www.jaguarclassicparts.com/JDHT/html/JCPHomePage.html','mainFrame')\">Classic Parts</div></td>";
	menuHTML = menuHTML + "		<td width=\"20%\" id=\"jagr_td\" class=\"categoryLinks\"><div id=\"jagr_lnk\" align=\"center\" class=\"menuDiv\" style=\"width:99%\" onmouseover=\"setMenuColor('jagr',1,0,false)\" onmouseout=\"setMenuColor('jagr',1,1)\" onclick=\"menuClick('" + StaticContents + "/html/Trust/my_jaguar/myJag.html','mainFrame')\">My Jaguar/Daimler</div></td>";
	menuHTML = menuHTML + "		<td width=\"20%\" id=\"blnk_td\"></div></td>";
	menuHTML = menuHTML + " </tr>";
	menuHTML = menuHTML + "</table>";

	menuDiv.innerHTML = menuHTML;

}


function setMenuColor(divName,frameIndex,reset,subMenu) {

	var thisDiv = document.getElementById(divName+"_lnk");
	
	if ((reset == 0) || (reset == 4)) {	

		thisDiv.style.backgroundColor = "#990000";
		thisDiv.style.color = "#FFFFFF";
		
		if ((subMenu != null) && (subMenu == true)) {
			displayTimer = setTimeout(displaySubMenu,500);
			currentMenu = divName;
		}		
		
		if (subMenuTimer != null) {
			clearTimeout(subMenuTimer);
		}
				
	}
	else if (reset == 1) {
		thisDiv.style.backgroundColor = "#fffce9";
		thisDiv.style.color = "#000000";
		if (displayTimer != null) {
			clearTimeout(displayTimer);
			displayTimer = null;
			currentMenu = null;
		}
		if (document.getElementById("subMenuDiv") != null) {
			document.body.removeChild(document.getElementById("subMenuDiv"));
		}			
	}
	else if (reset == 2) {
		thisDiv.style.backgroundColor = "#fffce9";
		thisDiv.style.color = "#000000";
		subMenuTimer = setTimeout(clearSubMenu,500);
	}
	
}


function menuClick(clickURL, clickTarget) {
	if ((clickTarget != null) && (clickTarget.length > 0)) {
		document.location.href = clickURL;
	}
}

function clearSubMenu() {

	if (document.getElementById("subMenuDiv") != null) {
		document.body.removeChild(document.getElementById("subMenuDiv"));
	}
	subMenuTimer = null;
}

function displaySubMenu() {


	displayTimer = null;
    var subMenuDiv = null;	
    
	if (document.getElementById("subMenuDiv") != null) {
		document.body.removeChild(document.getElementById("subMenuDiv"));
	}

	var menuDiv = document.getElementById('trustMenuHolder');

	subMenuDiv = document.createElement("DIV");
	subMenuDiv.style.position = "absolute";
	subMenuDiv.style.left = menuDiv.offsetLeft+"px";
	subMenuDiv.style.top = (menuDiv.offsetTop + menuDiv.offsetHeight) + "px";
	subMenuDiv.style.color = "white";
	subMenuDiv.style.visibility = "visible";
	subMenuDiv.id = "subMenuDiv";
		
	var menuText = "<table border=0 cellpadding=0 cellspacing=0>";

	var currentSubMenu = getSubMenu();

	var menuIndex = 0;
	for (var i = 0; i < currentSubMenu.length; i++) {	
		menuText = menuText + "<tr><td width='100%' id='subCol"+menuIndex+"'><div class='dropMenuDiv' id='sub"+menuIndex+"_lnk' style='width:100%'";
		menuText = menuText + " onmouseover=\"setMenuColor('sub"+menuIndex+"',2,0)\" onmouseout=\"setMenuColor('sub"+menuIndex+"',2,2)\"";				
		menuText = menuText + "onclick=\"menuClick('" + StaticContents + currentSubMenu[i][1] + "','mainFrame')\" >";
		menuText = menuText + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + currentSubMenu[i][0] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td></tr>";
		menuIndex++;
	}
	menuText = menuText + "</table>"

	subMenuDiv.innerHTML = menuText;	
	document.body.appendChild(subMenuDiv);

	var menuIndex = 0;
	var maxWidth = 152;
	for (var i = 0; i < currentSubMenu.length; i++) {
		document.getElementById("sub"+menuIndex+"_lnk").style.width = maxWidth+"px";
		menuIndex++;
	}

}

function getSubMenu() {

	var childMenu = [];
	
	childMenu[0] = ['About JDHT','/html/Trust/about/about.html'];
	childMenu[1] = ['Services','/html/Trust/services/services.html'];
	childMenu[2] = ['News &amp; Events','/html/JDHTNewsAndEvents.html'];
	childMenu[3] = ['History of Jaguar','/html/Trust/jag_story/js_intro.html'];
	childMenu[4] = ['JDHT Collection','/html/Trust/jdht_collection/collection.html'];
	childMenu[5] = ['Friends of JDHT','/html/Trust/friends/friends.html'];
	childMenu[6] = ['Hire Cars','/html/Trust/hire_car/hire_home.html'];
	childMenu[7] = ['Trace Certificates','/html/Trust/certs/trace_certs.html'];
	childMenu[8] = ['Contact Us','/html/Trust/contact/contact.html'];
	
	return childMenu;
	
}
