var currentLoc = null;
window.onload = function()
{

	highlightGlobalNav('header');
	highlightGlobalNav('topnav'); 
	/*openSubNav();*/
	highlightLocalNav('sidenav');
	
	var thispath = window.location.toString().split('#')[0].split('?')[0];
	thispath = thispath.replace(/^http:\/\/.+?\/(.*)$/, "/$1");
	
	/**** commented out Google Map data - if it is decided to bring back the US and UK page location maps, uncomment this area
	if (thispath == '/contact/uslocations.asp') {
		showCDGMap(0);
	}else if (thispath == '/contact/uklocations.asp'){
		showCDGMap(6);
	}
	***** end Google Maps comments */

}
//digitalDirectory and technicalDirectory array hold the names of the directories in each section, used to tell what drop down should be open/closed onLoad
var digitalDirectoryArray = ['dcms','development','imaging','professionalservices'];
var technicalDirectoryArray = ['techwriting','partsdatamanagement','s1000d','interactivemanuals','technicaldataconversion','cms'];


function highlightGlobalNav(navdiv)
{
	var thissection = window.location.toString().split('/')[3];
	if(thissection=="" || thissection==null){
		thissection="index.asp";	
	}
	var navul = document.getElementById(navdiv);
	if (navul) {
		var navanchors = navul.getElementsByTagName('a');
		if (navanchors) {
			for(var i = 0; i <= navanchors.length-1; i++) {
				if (navanchors[i].href.toString().split('/')[3] == thissection) {
					navanchors[i].className = 'here';
					break;
				} else {
					navanchors[i].className = 'nothere';
				}
			}
		}
	}
}


function highlightLocalNav(navdiv)
{
	var thispath = window.location.toString().split('#')[0].split('?')[0];
	var navwrap = document.getElementById(navdiv);
	if (navwrap) {
		var navanchors = navwrap.getElementsByTagName('a');
		if (navanchors) {
			for(var i = 0; i <= navanchors.length-1; i++) {
				if (navanchors[i].href == thispath) {
					navanchors[i].className = 'here';
					break;
				} else {
					navanchors[i].className = 'nothere';
				}
			}
		}
	}
}


function clearfield(element) 
{
	if (element.defaultValue == element.value) element.value = "";
}

function dropDown(whichID)
{
	var myDoc = document.getElementById(whichID);
	var arrowName = whichID+"arrow";
	if(myDoc.style.display=="block"){
		//take the element passed to us and move it over
		myDoc.style.display = "none";
		//switch our arrow to an open state
		document.images[arrowName].src = "/images/arrow_right.gif";
	}else{
		//take the element passed to us and move it over
		myDoc.style.display = "block";
		//switch our arrow to an open state
		document.images[arrowName].src = "/images/arrow_down.gif";
	}
	
	
}
function openSubNav()
{
	var thissection = window.location.toString().split('/')[3];
	//only perform our check if we're in the services section
	if(thissection=='services'){
		var thissubsection = window.location.toString().split('/')[4];
		for(var i=0;i<digitalDirectoryArray.length;i++){
			if(thissubsection==digitalDirectoryArray[i]){
				dropDown('digitalnav');
				break;
			}
		}
		for(var i=0;i<technicalDirectoryArray.length;i++){
			if(thissubsection==technicalDirectoryArray[i]){
				dropDown('technicalnav');
				break;
			}	
		}
	}
	
}

function jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function randomImage()
{
	//hold an array of links to our pdfs
	var pdfArray = new Array();
	var pdfLinkArray = new Array();
	//pdfArray = ['case_study_CTSv2.pdf','case_study_AVFSCv3.pdf','case_study_LASC_CaseStudy_final2004NF.pdf', 'case_study_Inglewood-CaseStudy-1005.pdf'];
	pdfArray = ['Advanced Strategies for Configuration Management: Lessons Learned from the Aviation Industry white paper','Configuration Management: Shared Challenges Within the Nuclear Energy and Aviation Industries white paper','Lean Basics: An Introduction to the Value of Lean white paper','What You Should Know About S1000D(TM) white paper','S1000D(TM) - An Overview white paper']
	var randomNum = Math.ceil(Math.random()*5);
	//var pdfLink = "/pdf/"+pdfArray[(randomNum-1)];
	var pdfLink = "/whitepaperrequest/"
	var pdfLinkArray = ['configmgmt-aviation/','configmgmt/','Lean/', 'S1000D/', 'S1000DOverview/'];
	var imgDisplay = "<img src=\"/images/casestudy-"+randomNum+".jpg\" alt=\""+pdfArray[(randomNum-1)]+"\" title=\""+pdfArray[(randomNum-1)]+"\" usemap=\"#casestudymap\" /><map name=\"casestudymap\" id=\"casestudymap\"><area shape=\"rect\" coords=\"308,5,500,139\" href=\""+pdfLink+pdfLinkArray[(randomNum-1)]+"\" target=\"_blank\" /></map>";
	return imgDisplay;
}



function switchMap(dropdown)
{
	var ix = dropdown.options[dropdown.selectedIndex].value;
	dropdown.selectedIndex = 0;
	showCDGMap(ix);
}


function showCDGMap(ix)
{
	if (GBrowserIsCompatible()) {
		var location = getLocation(ix);
		currentLoc = ix;
		var m = document.getElementById("map");
		m.style.height = "225px";
		m.style.width = "860px";
		
		var map = new GMap(m);
		map.addControl (new GSmallMapControl());
		
		//if we're less than 5, we're a US map, (only 1 point showing)
		if(ix<6){
			var point = new GPoint(location.latitude, location.longitude);
			map.centerAndZoom (point, 9);
			marker = new GMarker(point);
		
			var html = ''
			html += '<div style="white-space:nowrap;">'
			html += '<strong>' + location.name + '</strong>' 
			html += '<br />' + location.address1 
			html += '<br />' + location.address2 
			html += '</div>';
			GEvent.addListener(marker, 'click', function(){ marker.openInfoWindowHtml(html); });
			map.addOverlay(marker);
		}else{
			
			//we're a UK map, we'll need to show both positions on the same screen; this could be a loop if more points are needed to be added on the UK screen
			var location = getLocation(6);
			//we're a UK map, we need to show 2 points at once
			var point = new GPoint(location.latitude,location.longitude);
			map.centerAndZoom (point, 12);
			marker = new GMarker(point);
			var html = ''
			html += '<div style="white-space:nowrap;">'
			html += '<strong>' + location.name + '</strong>' 
			html += '<br />' + location.address1 
			html += '<br />' + location.address2 
			html += '</div>';
			GEvent.addListener(marker, 'click', function(){ marker.openInfoWindowHtml(html); });
			map.addOverlay(marker);
			
			
			var location = getLocation(7);
			//we're a UK map, we need to show 2 points at once
			var point2 = new GPoint(location.latitude,location.longitude);
			marker2 = new GMarker(point2);
			var html2 = ''
			html2 += '<div style="white-space:nowrap;">'
			html2 += '<strong>' + location.name + '</strong>' 
			html2 += '<br />' + location.address1 
			html2 += '<br />' + location.address2 
			html2 += '</div>';
			GEvent.addListener(marker2, 'click', function(){ marker2.openInfoWindowHtml(html2); });
			map.addOverlay(marker2);

			
		}
		//marker.openInfoWindowHtml(html);
	}

}





function toTarget () 
{
	var addr = document.directions.fromaddress.value;
	addr = addr.replace(/\+/g, '%2B');
	addr = addr.replace(/ /g, '+');
	
	//what address are we shooting for?
	var location = getLocation(currentLoc);
	var googleAddress = location.address1+',';
	googleAddress += location.address2;
	var txt = 'http://maps.google.com/?q=from:'+addr+'+to:+';
	txt += googleAddress;
	return txt;
	
}



function getLocation(ix)
{
	var locations = new Array();
	locations[0] = { 
		name:      'CDG Corporate Headquarters', 
		address1:  '222 North Sepulveda Blvd.',
		address2:  'El Segundo, CA 90245',
		latitude:  -118.395870,
		longitude: 33.913992
	};
	locations[1] = { 
		name:      'CDG Sales Offices', 
		address1:  '6141 Katella Avenue',
		address2:  'Cypress, CA 90630-5202',
		latitude:  -118.025951,
		longitude: 33.80315
	};
	locations[2] = { 
		name:      'San Diego, California', 
		address1:  '6910 Carroll Road',
		address2:  'San Diego, CA 92121',
		latitude:  -117.170734,
		longitude: 32.885281
	};
	locations[3] = { 
		name:      'Bellevue, Washington', 
		address1:  '15400 SE 30th Place',
		address2:  'Bellevue, WA 98007',
		latitude:  -122.134795,
		longitude: 47.582518
	};
	locations[4] = { 
		name:      'Rancho Cucamonga, California', 
		address1:  '9500 Cleveland Avenue',
		address2:  'Rancho Cucamonga, CA 91730',
		latitude:  -117.567272,
		longitude: 34.084405
	};
	locations[5] = { 
		name:      'St. Louis, Missouri<br />Lindbergh & McDonnell Bldg. 34', 
		address1:  'Hazelwood, MO 63042',
		address2:  '',
		latitude:  -90.34255,
		longitude: 38.753682
	};
	locations[6] = { 
		name:      'Gate House, Fretherne Road', 
		address1:  'Welwyn Garden City<br />Hertfordshire',
		address2:  'AL8 6NS, United Kingdom',
		latitude:  -1.446612,
		longitude: 54.003343
	};
	locations[7] = { 
		name:      'Monkswell Hoese, Manse Lane', 
		address1:  'Knaresborough<br />North Yorkshire',
		address2:  'HG5 8NQ, United Kingdom',
		latitude:  -0.205430,
		longitude: 51.800770
	};
	return locations[ix];
}

