//======================================================
// *** Gulfstream Core Scripts
// *** Copyright 2006 Gulfstream Aerospace Corporation
// -----------------------------------------------------
// *** Created 2006-02-22
//======================================================

//======================================================
// *** init
// -----------------------------------------------------
// ***
//======================================================
function init(){
	
	//alert('init');
}


//======================================================
// *** openNewWindow
// -----------------------------------------------------
// *** opens new window with specified variables
//======================================================
function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}

//======================================================
// *** MM_jumpMenu
// -----------------------------------------------------
// *** creates jump menu
//======================================================
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



//======================================================
// *** generateBreadcrumb
// -----------------------------------------------------
// *** generates breadcrumb links for page
//======================================================
function generateBreadcrumb(){

	var thisURL = window.location;
	var thisTitle = document.title;
	
	// *** first build main part of breadcrumb
	var strURL = thisURL.toString();
	var arrURL = strURL.split("/");
	// *** pop out the first four items in the array - 
	// *** the root of the url string (http:, /, /, [domain]
	
	// *** remove the http://www.gulfstream.com/ string
	// *** from the array
	arrURL.reverse();
	for(var i=0; i<3; i++){
		arrURL.pop(i);
	}
	// *** reorder to correct order
	arrURL.reverse();
	// *** get rid of trailing slashes
	var lastItem = arrURL.length-1;
	arrURL.pop(lastItem);

	// *** create an array to contain the pieces of the breadcrumb string
	var arrURLDisplay = [];

	// *** now loop through the arrURL array and capitalize the first letter of 
	// *** each word in each array item
	for(var i=0; i<arrURL.length; i++){
		
		// *** create an array of characters from this phrase
		var arrPhrase = arrURL[i].split("");
		var newPhrase = "";
		// *** loop through characters in phrase array
		// *** and capitalize the first character, and
		// *** any characters that follow a space (" ")
		for(var j=0; j<arrPhrase.length; j++){
			
			// *** handle first char
			if(j==0){
				arrPhrase[j] = arrPhrase[j].toUpperCase();
			}
			
			// *** handle subsequent chars
			if(arrPhrase[j] == "_"){
				
				//arrPhrase[j] = " ";
				arrPhrase[j+1] = arrPhrase[j+1].toUpperCase();
			}

			newPhrase += arrPhrase[j];
		}

		arrURLDisplay[i] = newPhrase;
	}

	// *** now build end of breadcrumb - the title
	var strTitle = thisTitle.toString();
	var titleColonPosition = strTitle.lastIndexOf(":");

	if(titleColonPosition == null || titleColonPosition == -1){
		titleColonPosition = 0;
	} else {
		titleColonPosition++;
	}
	
	var strNewTitle = strTitle.substr(titleColonPosition, strTitle.length);
	strNewTitle = cleanString(strNewTitle);

	// *** now compose breadcrumb
	var breadcrumb = "<a href=\"/\" class=\"footerLinkWhite\">Home</a> / ";
	
	// *** loop through array
	for(var j=0; j<arrURL.length+1; j++){
		
		// *** if this is last item in array
		if(j==arrURL.length){
			
			var section = "<span style=\"font-weight:bold;\">"+strNewTitle+"</span>";
			
			
		} else {
			
			// *** get this section url
			var sectionURL = "";
			for(var m=0; m<=j; m++){
				//alert('arrURL['+m+'] = ' + arrURL[m]);
				sectionURL += "/"+arrURL[m]; 
				
			}
			var section = "<a href="+sectionURL+" class=\"footerLinkWhite\">"+arrURLDisplay[j]+"</a> / ";
			
		}
		
		breadcrumb += section;
		
	}
	
	// *** return the final string
	// *** example:  <a href="/" class="footerLinkWhite">Home</a> / <a href="/g150/">G150</a> / <span style="font-weight:bold;">G150 Overview</span>;
	return(breadcrumb);
}


function cleanString(str){
	
	var re = /[\/_*]/g;
	str = str.replace(re, " ");
	return(str);
	
}


function validateForm(which){

	var tf = which;
	for (i=0; i<tf.length; i++){
		var te = tf.elements[i];
		var ten = te.name;
		var tev = te.value;
		var teid = te.id;
		var tet = te.type;
		
		// *** get element name prefix
		var teprefix = ten.substr(0, 2);
		//alert('hey teprefix = ' + teprefix);
		
		if(teprefix=='RE'){
			
			
			if(tev == ''){
				alert('Please make sure the "'+teid+'" field is completed.');
				return(false);
			}
			
		}
		

	}
	
	return(true);
}


function displayFooterForm(){

	var te = document.getElementById("footerFormContainer");
	te.style.display = "inline";

}

function displayEmailPageForm(){

	var te = document.getElementById("emailPageFormContainer");
	te.style.display = "inline";

}

function printThisPage(){
	
	window.print();
	
	
}


function hidePageElement(elementID){
	
	document.getElementById(elementID).style.display='none';
}

function showPageElement(elementID){
	
	document.getElementById(elementID).style.display='block';
}


//======================================================
// *** Flash API
// -----------------------------------------------------
// *** functions to interact with embedded
// *** flash movies
//======================================================

function resizeObjectHeight(which, newHeight){
	
	//alert('hey resizeFlash which = ' + which + ' and nh = ' + newHeight);
	var tf = document.getElementById(which);
	tf.style.height = newHeight+"px";
}


