/////////////////////////////////////////////////////////
// 		Filename: HM_Loader.js
//		Date: 	  08.14.01
//		Purpose:
//		This file detects browser and launches
//		appropriate DHMTL menu script
// =====================================================
//		Modified: 09.10.01
//		Added HM_FilePath variable to accomodate new
//		portal (which needs absolute path, not relative)
//
//		Any changes to the structure of the global nav that would 
//		add or reduce the number of menus must be coordinated	
//		with the Real Estate Technology Group (Scott Hamby, Manager)
//		as the drop downs on their directory page act as the 8th menu item.
//
/////////////////////////////////////////////////////////

   HM_DOM = (document.getElementById) ? true : false;
   HM_NS4 = (document.layers) ? true : false;
    HM_IE = (document.all) ? true : false;
   HM_IE4 = HM_IE && !HM_DOM;
   HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
  HM_IE4M = HM_IE4 && HM_Mac;
HM_IsMenu = (HM_DOM || HM_NS4 || (HM_IE4 && !HM_IE4M));

HM_BrowserString = HM_NS4 ? "NS4" : HM_DOM ? "DOM" : "IE4";

if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;

//HM_FilePath = "js/";
HM_FilePath = "http://ppld.corp.sprint.com/univincludes/globalnav/js/";

if (window.HM_FilePath + "" == "undefined")
	HM_FilePath = "";


HM_GL_MenuWidth          = 120;
HM_GL_FontFamily         = "Verdana,sans-serif";
HM_GL_FontSize           = 8;
HM_GL_FontBold           = false;
HM_GL_FontItalic         = false;
HM_GL_FontColor          = "#000000";
HM_GL_FontColorOver      = "#ffffff";
HM_GL_BGColor            = "#ffffff";
HM_GL_BGColorOver        = "#cc0000";
HM_GL_ItemPadding        = 2;

HM_GL_BorderWidth        = 1;
HM_GL_BorderColor        = "#000000";
HM_GL_BorderStyle        = "solid";
HM_GL_SeparatorSize      = 1;
HM_GL_SeparatorColor     = "#000000";

HM_GL_ImageSrc = "http://globalnav.corp.sprint.com/univincludes/globalnav/images/HM_more.gif";
HM_GL_ImageSrcLeft = "http://globalnav.corp.sprint.com/univincludes/globalnav/images/HM_more.gif";

HM_GL_ImageSrcOver = "http://globalnav.corp.sprint.com/univincludes/globalnav/images/HM_more_over.gif";
HM_GL_ImageSrcLeftOver = "http://globalnav.corp.sprint.com/univincludes/globalnav/images/HM_more_over.gif";

HM_GL_ImageSize          = 10;
HM_GL_ImageHorizSpace    = 0;
HM_GL_ImageVertSpace     = 0;

HM_GL_KeepHilite         = false;
HM_GL_ClickStart         = false;
HM_GL_ClickKill          = 0;
HM_GL_ChildOverlap       = 0; // was 25 -- javascript function for menu id?
HM_GL_ChildOffset        = -1; // same as above?
HM_GL_ChildPerCentOver   = null;
HM_GL_TopSecondsVisible  = .5; //1.5
HM_GL_ChildSecondsVisible = 0; //.5
HM_GL_StatusDisplayBuild = 0;  //1
HM_GL_StatusDisplayLink  = 1;
HM_GL_UponDisplay        = null;
HM_GL_UponHide           = null;

//HM_GL_RightToLeft      = true;
//HM_GL_CreateTopOnly      = HM_NS4 ? true : false;
HM_GL_CreateTopOnly      = true;
HM_GL_ShowLinkCursor     = true;

// the following function is included to illustrate the improved JS expression handling of
// the left_position and top_position parameters
// you may delete if you have no use for it

function HM_f_CenterMenu(topmenuid) {
	var MinimumPixelLeft = 0;
	var TheMenu = HM_DOM ? document.getElementById(topmenuid) : HM_IE4 ? document.all(topmenuid) : eval("window." + topmenuid);
	var TheMenuWidth = HM_DOM ? parseInt(TheMenu.style.width) : HM_IE4 ? TheMenu.style.pixelWidth : TheMenu.clip.width;
	var TheWindowWidth = HM_IE ? document.body.clientWidth : window.innerWidth;
	return Math.max(parseInt((TheWindowWidth-TheMenuWidth) / 2),MinimumPixelLeft);
}

function HM_f_MenuAdjust(menuid,isTop,topVal) {
	var tempVal = 0;
	if (isTop) {
		tempVal = document.style.marginheight;

	}
	else {
		var marginLeft = 0;

	}
}


// from include.js
// begin DHTML menu code
if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;

// dummy onShow and onHide page specific functions:
function __pageOnShow(menuID) {};
function __pageOnHide(menuID) {};

// check to see if there are page-defined onShow and onHide functions - save these
if (window.HM_onShow + "" != "undefined") {
	//alert("onShow = defined locally");
	__pageOnShow = window.HM_onShow;
}

if (window.HM_onHide + "" != "undefined") {
	//alert("onShow = defined locally");
	__pageOnHide = window.HM_onHide;
}

function __onShow(menuID)
{ // hide forms underneath menus - function for global nav

	if (HM_NS4) {
		if ((menuID == 3) || (menuID == 4) || (menuID == 5) || (menuID == 6) || (menuID == 7) ) //
			document.layers['navSearchD'].visibility = 'hidden';
	}
	if (HM_IE4) {
		if ((menuID == 3) || (menuID == 4) || (menuID == 5) || (menuID == 6) || (menuID == 7) ) //
			document.all['navSearchD'].style.visibility = 'hidden';
	}
	if (HM_DOM){
		if ((menuID == 3) || (menuID == 4) || (menuID == 5) || (menuID == 6) || (menuID == 7) ) //
		document.getElementById('navSearchD').style.visibility = 'hidden';
	}

	__pageOnShow(menuID); // call locally defined onShow

} // end __onShow

function __onHide(menuID)
{ // show all forms - function for global nav
	if (HM_NS4)
		document.layers['navSearchD'].visibility = 'visible';
	if (HM_IE4)
		document.all['navSearchD'].style.visibility = 'visible';
	if (HM_DOM)
		document.getElementById('navSearchD').style.visibility = 'visible';

	__pageOnHide(menuID); // call locally defined onHide
} // end __ onHide


/* set HM_onShow and HM_onHide to globally defined functions */
window.HM_onShow = __onShow;
window.HM_onHide = __onHide;


// added to preload 'go' submit button
go_button = new Image();
go_button.src = "/vcc/univincludes/globalnav/images/go.gif";

go_button_on = new Image();
go_button_on.src = "/vcc/univincludes/globalnav/images/go_on.gif";



// added for rollover on submit
var formObj;
if (document.layers)
	formObj = document.layers['navSearchD'].document.navSearch;
else
	formObj = document.navSearch;


function doSearch() {
// added formObj - if using layers, reference form within layer (NN 4+)
// if not using layers, reference form object within document.
var formObj;
if (document.layers)
	formObj = document.layers['navSearchD'].document.navSearch;
else
	formObj = document.navSearch;


//alert("selected index = " + formObj.searchType.selectedIndex);
if ( formObj.searchType[formObj.searchType.selectedIndex].value != "divider" ) { // make sure divider isnt chosen

	if ( formObj.searchType[formObj.searchType.selectedIndex].value == "phone" ) {
		//alert("phone directory");

		if(formObj.query_string.value == "") {
        	//alert("http://sprintdirectory.corp.sprint.com/");
			location.href = "http://sprintdirectory.corp.sprint.com/";
	      	return false;
    	}
		else {

			var querytext = formObj.query_string.value
	        if(querytext.indexOf(" ") == -1 && querytext.indexOf(",") == -1) {
            	var word1 = "" + querytext
				//alert("http://sprintdirectory.corp.sprint.com/servlet/Directory?lastname=" + word1);
            	//location.href =  "http://sprintdirectory.corp.sprint.com/servlet/Directory?lastname=" + word1;
				location.href =  "http://ppld.corp.sprint.com/webapps/fon/Directory?lastname=" + word1;
            	return false;
		  	}
        	else {
            	var newstr1 = "";
            	var newstr2 = "";
				var reverseNames = true;
            	for (var i=0; i < querytext.length; i++) {/**/
                	if (querytext.charAt(i) != " " && querytext.charAt(i) != ",")
                    	newstr1 += querytext.charAt(i);

					else {
						if (querytext.charAt(i) == ","){
							reverseNames = false;
							//alert("comma!");
						}

                    	for (var testme = i+1; testme < querytext.length; testme++) {
                  		//check for space after comma
                  			if (querytext.charAt(testme) != " ")
                           		newstr2 += querytext.charAt(testme);
                      	}
                      	break;
					} // end else there is a space or comma
                 } // end for length of text
				 /*if (reverseNames == true) {
				 	//alert("reversing");
				 	var temp = newstr1;
					newstr1 = newstr2;
					newstr2 = temp;
				}*/
			} // end if no spaces or commas
        }// end if there is a value in the search field for phone directory
			//alert("http://sprintdirectory.corp.sprint.com/servlet/Directory?lastname=" + newstr1 + "&firstname=" + newstr2);
            //location.href =  "http://sprintdirectory.corp.sprint.com/servlet/Directory?lastname=" + newstr1 + "&firstname=" + newstr2;
			location.href =  "http://ppld.corp.sprint.com/webapps/fon/Directory?lastname=" + newstr1 + "&firstname=" + newstr2;
            return false;
		/**/
	}// end if search phone directory


	else if ( formObj.searchType[formObj.searchType.selectedIndex].value == "forms" ) {
		//alert("forms");

    	if(formObj.query_string.value == "") {
			//alert("http://forms.corp.sprint.com");
        	location.href="http://forms.corp.sprint.com";
      		return false;
      	}
		else {
			//alert("http://ppld.corp.sprint.com/webapps/forms/main?request=formsearch&form_name=" + addPlus(formObj.query_string.value));
        	location.href = "http://ppld.corp.sprint.com/webapps/forms/main?request=formsearch&form_name=" + addPlus(formObj.query_string.value);
	        //location.href = "http://ppld.corp.sprint.com/servlet/com.sprint.imc.forms.Servlet?request=formsearch&form_name=" + addPlus(formObj.query_string.value);
        	return false;
      	} // end if value for forms search
	/**/
	}// end search forms


	else if ( formObj.searchType[formObj.searchType.selectedIndex].value == "C1" ){
		//alert("pinpoint sites");/**/

		if(formObj.query_string.value == "") {
			//alert("http://webdir.corp.sprint.com");
			location.href="http://webdir.corp.sprint.com";
	    	return false
		} // end if no value
		else {
	        var keyword = formObj.query_string.value;
    		var newKeyword = "";
		    if (keyword.indexOf(" ") > -1) {  //it contains a space, so sub in %20
        		for (var i=0; i < keyword.length; i++) {
                	 if (keyword.charAt(i) != " " )
		        	    newKeyword += keyword.charAt(i);
        		     else
                		newKeyword += "%20";
		         } // end for
        		 keyword = newKeyword;
      		}// end if contains a space
			if (keyword.indexOf("&") > -1) {  //it contains a &, so sub in %
        		for (var i=0; i < keyword.length; i++) {
                	 if (keyword.charAt(i) != "&" )
		        	    newKeyword += keyword.charAt(i);
        		     else
                		newKeyword += "%";
		         } // end for
        		 keyword = newKeyword;
      		}// end if contains a space			
	  		//alert("http://ppld.corp.sprint.com/webapps/webdir/main?request=keywordsearch&keyword=" + keyword);
      		location.href = "http://ppld.corp.sprint.com/webapps/webdir/main?request=keywordsearch&keyword=" + keyword;
      		// old one ... location.href = "http://ppld.corp.sprint.com/servlet/com.sprint.imc.servlet.webdirectory.Servlet?request=keywordsearch&keyword=" + keyword;-->
      		return false
		} // end else there is a value
	} // end pinpoint sites search ("Find a Site")


	else { // one of the collections search
		//alert("verity search");
		if(formObj.query_string.value == "") {
			//alert("http://ppld.corp.sprint.com/search.htm");
         	//location.href = "http://ppld.corp.sprint.com/search.htm";
	      if (formObj.searchType[formObj.searchType.selectedIndex].text == "CRC")
		  	location.href="http://ppld.corp.sprint.com/search/searchcrc.shtml";
		else if (formObj.searchType[formObj.searchType.selectedIndex].text == "HR")
			location.href="http://ppld.corp.sprint.com/search/searchhr.shtml";
		  return false
    	 } // end if no value entered
		 else {
			ChkText;/**/
			var myUrl =	"http://search.corp.sprint.com/s97is.vts?resulttemplate=gnrslttmp.hts"; 		
	//"http://ppsearch.corp.sprint.com/search97cgi/s97_cgi?serverkey=primary&resulttemplate=rslttmp.hts&resultstyle=normal";
			/*if  ( formObj.searchType[formObj.searchType.selectedIndex].value == "crc" ) //check if they chose CRC
					myUrl+="&collection=site_crcbrg" +
						 "&collection=site_crcdataq" +
						 "&collection=site_crcforr" +
						 "&collection=site_crcfs" +
						 "&collection=site_crcggv3" +
						 "&collection=site_crcgiga" +
						 "&collection=site_crcidc" +
						 "&collection=site_crcint" +
						 "&collection=site_crcir" +
						 "&collection=site_crcmeta" +
						 "&collection=site_crcpel" +
						 "&collection=site_crcphil" +
						 "&collection=site_crcpro" +
						 "&collection=site_crcrdsl" +
						 "&collection=site_crcyoln";
			else // every other collection search is straightforward
			*/
				myUrl+="&collection=" + formObj.searchType[formObj.searchType.selectedIndex].value;

			formObj.QueryText.value = formObj.query_string.value

			var start = 0;
			var end = 0;
			var tmpQueryText = "";
			while(true) {
				//alert("1start: " + start + "  end: " + end);
				end = formObj.QueryText.value.indexOf(" ", start);
				if (end == -1) {
					end = formObj.QueryText.value.length;
					//alert("2start: " + start + "  end: " + end);
					tmpQueryText += formObj.QueryText.value.substring(start, end);
					//alert("tmpQueryText: " + tmpQueryText);
					break;
				}// end if at end
				else {
					//alert("3start: " + start + "  end: " + end);
					tmpQueryText += formObj.QueryText.value.substring(start, end);
					tmpQueryText += "+";
					//alert("tmpQueryText: " + tmpQueryText);
					start = end + 1;
				} // end else not at end
			} // end while

        	myUrl+="&QueryText=" + tmpQueryText;

			//}// end if value entered

			//alert("myUrl: " + myUrl);
			window.open(myUrl,'_parent');
			return false;
		} // end else value was entered

	} // end collection search
} // end if not divider

} // end doSearch

function addPlus(InString) {
	var OutString = "";
	for (Count=0; Count < InString.length; Count++)  {
		if (InString.charAt(Count)==" ") {
			OutString = OutString + "+" ;
    	}
		else {
      		OutString = OutString + InString.charAt(Count);
   	 	}
  	}
  	return OutString;
} // end addPlus

function ChkText() {
	var bErrFlg = true;
    if (formObj.query_string.value == "")
    	return confirm("No Text was entered!  This could take some time.");
} // ChkText

// end DHTML menu code
// end from include.js


if(HM_IsMenu) {

	// write array file tag
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='" + HM_FilePath + "HM_Arrays.js' TYPE='text/javascript'><\/SCR" + "IPT>");

	// check to see if other array files...
	if ((window.HM_OtherMenuPage + "" == "undefined")||(window.HM_OtherMenuPage == "")||(window.HM_OtherMenuPage == null)) {
		//alert("no other menus");
	}
	else
		document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='" + HM_OtherMenuPage + "' TYPE='text/javascript'><\/SCR" + "IPT>");
	
	// write script file tag
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='" + HM_FilePath + "HM_Script"+ HM_BrowserString +".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}


//end
