//---- Set this variable only! ----
var buildDir = "/_layouts/scripts/";

//---------------------------------

var ie4 = false, ie5_mac = false, ie55 = false;
var nn4 = false, dom = false, opera = false, safari = false;
var agent = navigator.userAgent.toLowerCase();

if (agent.indexOf("opera") != -1)
	opera = true;
else if (agent.indexOf("safari") != -1)
	safari = true;
else if (document.all)
{
	var version = parseFloat(agent.substr(agent.indexOf("msie")+5, 3));
	if (agent.indexOf("mac") != -1 && version >= 5)
		ie5_mac = true;
	else
	{
		if (version >= 5.5)
			ie55 = true;
		else if (version >= 4)
			ie4 = true;
	}
}
//else if (document.layers)
else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4 && 
	parseInt(navigator.appVersion) < 5)
	nn4 = true;
else if (document.getElementById)
	dom = true;

var blank = new Image();
blank.src = buildDir + "blank.gif";

if (ie4)
	document.write('<script type="text/javascript" src="' + buildDir + 'ie4-build.js"></script>');
else if (ie5_mac)
	document.write('<script type="text/javascript" src="' + buildDir + 'ie5m-build.js"></script>');
else if (ie55)
	document.write('<script type="text/javascript" src="' + buildDir + 'ie55-build.js"></script>');
else if (nn4)
	document.write('<script type="text/javascript" src="' + buildDir + 'ns4-build.js"></script>');
else if (dom)
	document.write('<script type="text/javascript" src="' + buildDir + 'dom-build.js"></script>');
else if (opera)
	document.write('<script type="text/javascript" src="' + buildDir + 'op7-build.js"></script>');
else if (safari)
	document.write('<script type="text/javascript" src="' + buildDir + 'saf-build.js"></script>');
else
{
	alert("Your browser doesn't support this script.");
	//location.href = buildDir + "upgrade.html"; NAVINT
	document.write('<script type="text/javascript" src="' + buildDir + 'no-build.js"></script>');
}

function drawFooterNav(boolIsCorp)
{
  var i;
  var strOutput = "";
  var strSep = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  
  if (boolIsCorp != true)
    strOutput += "<a href=\"http://www.hospira.com\" title=\"Hospira.com\" class=\"footer\" target=\"_new\">Hospira.com</a>" + strSep;
  
  for (i = 0; i < arrFooterLinks.length; i++)
  {
    strOutput += "<a href=\"" + arrFooterLinkHREFs[i] + "\" title=\"" + arrFooterLinks[i] + "\" class=\"footer\">" + arrFooterLinks[i] + "</a>";
    
    if (i != arrFooterLinks.length - 1)
      strOutput += strSep;
  }
  
  strOutput += "<br>" + strCopyrightNotice;
  
  document.write(strOutput);
}

function navigateFromSearch(strTitle, strListName, strURL)
{
  strTitle = unescape(strTitle);
  strListName = unescape(strListName);
  strURL = unescape(strURL);
  
  if (strTitle.substring(strTitle.length - 5, strTitle.length) == ".aspx")
    window.location.href = "/" + strTitle;
  else
    window.location.href = strURL;  
}

function warnOnLeave(strURL)
{
  var boolExitHospira = confirm(strWarnOnLeaveMsg);
  
  if (boolExitHospira)
  {
    window.open(strURL);
  }
  else
    return;
}

function showLines()
{
  if (!opera)
  {
    var i;
  
    for (i = 0; i < arrDivIDs.length; i ++)
    {
      document.getElementById(arrDivIDs[i]).style.zIndex = "1000000000";
      document.getElementById(arrDivIDs[i]).style.visibility = "visible";
    }
  }
}

function Querystring()
{
// get the query string, ignore the ? at the front.
	var querystring=location.search.substring(1,location.search.length);

// parse out name/value pairs separated via &
	var args = querystring.split('&');

// split out each name = value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');

		this[name]=value;
	}

	this.get=Querystring_get;
}


function Querystring_get(strKey,strDefault)
{
	var value=this[strKey];
	if (value==null)
	{
		value=strDefault;
	}

	return value;
}

function dynamiccontentNS6(elementid,content)
{
  if (document.getElementById)
  {
    rng = document.createRange();
    el = document.getElementById(elementid);
    rng.setStartBefore(el);
    htmlFrag = rng.createContextualFragment(content);

    while (el.hasChildNodes())
      el.removeChild(el.lastChild);

    el.appendChild(htmlFrag);
  }
}

function fillApplyButton()
{
  document.getElementById("btnApplyNow").value = strApplyNowButtonText;
}

function applyNow(strPath)
{
  var strJobTitle = document.getElementById("divJobTitle").value;
  var strURL = "/" + strPath + "/apply.aspx?pos=" + encodeURI(strJobTitle);
  location.href = strURL;
}

function loadJobDetail(strURL)
{  
  var qs = new Querystring()
  var strID = qs.get("ID", null);
  var strURL = strURL + "/jobopeningdetail.aspx?ID=" + strID;
  window.frames["iFrameTemp"].location = strURL;
}

function loadPRDetail(strURL)
{  
  var qs = new Querystring()
  var strID = qs.get("ID", null);
  var strURL = strURL + "/pressrelease.aspx?ID=" + strID;
  window.frames["iFrameTemp"].location = strURL;
}

function checkParent()
{
  if (parent.document.getElementById("divContentPlaceHolder") != null)
  {  
    var htmlData = document.getElementById("jobContent").innerHTML;
    parent.document.getElementById("divContentPlaceHolder").innerHTML = htmlData;
    parent.document.getElementById("divJobTitle").value = document.getElementById("cellJobTitle").innerHTML;
  }
}

function checkPRParent()
{
  if (parent.document.getElementById("divContentPlaceHolder") != null)
  {  
    var htmlData = document.getElementById("jobContent").innerHTML;
    parent.document.getElementById("divContentPlaceHolder").innerHTML = htmlData;
  }
}

function checkProductionJob(strNo)
{
  var strDisplay = "block";
  if (opera || dom)
    strDisplay = "table-row";

  document.getElementById("rowProductionPosition").style.display = "none";

  if (document.getElementById("cellProductionPosition").value == strNo)
    document.getElementById("rowTimeShift").style.display = "none";
  else
    document.getElementById("rowTimeShift").style.display = strDisplay;  
}

function resizeIFrame(strID)
{
  /*
  if (parent.frames[strID] != null)
  {
    parent.resizeIFrameParent(strID, document.body.scrollHeight + 5);
  }

  if (strID == "iframeMSDSSearch")
  {
    if (parent.frames('iframeProductCatalog'))
      parent.resizeIFrameParent('iframeProductCatalog', document.body.scrollHeight + 5);
  }
  */
}

function writeYear()
{
  var today = new Date();
  var year = today.getYear();
  
  if (year < 1000)
    year += 1900;
    
  return year;

}

var strPageSearchTerm = "";
function CacheSearchString()
{
    var frm = document.forms["frmSearch"];
    strPageSearchTerm = frm.elements["SearchString"].value;
}
function SubmitSiteSearch(rwNextListPage, rwNextDocPage, rwLastPage)
{
    var strCategory;
    var frm = document.forms["frmSearch"];
    var bRestoreSearchString = true;
    if (rwNextListPage > 0)
        strCategory = "Lists";
    else if (rwNextDocPage > 0)
        strCategory = "Documents";
    else
    {
        bRestoreSearchString = false;
        strCategory = "";
        frm["ListPagePosition"].value = "";
        frm["DocPagePosition"].value = "";
    }
    frm["Category"].value = strCategory;
    rwLastPage = (rwLastPage > 0) ? rwLastPage + 1 : 0;
    frm["PageFirstRow"].value = rwLastPage;
    if (bRestoreSearchString)
        frm["SearchString"].value = strPageSearchTerm;
    frm.submit();
}

function encodeHTML(strTextToEncode)
{
  strTextToEncode = strTextToEncode.replace(/</g, "&lt;");
  strTextToEncode = strTextToEncode.replace(/>/g, "&gt;");  
  return strTextToEncode;
}

function writeSearchLink(strLink, strURL)
{
  var strReturnOutput = "";
  strReturnOutput = "<a href=\"" + strURL + "\" title=\"" + strLink + "\">" + strLink + "</a><br />";
  document.write(strReturnOutput);
}

function fillSearchTerm()
{
  var strSearchText = document.forms[0].SearchString.value;
  
  strSearchText = encodeHTML(strSearchText);

  if (document.getElementById("searchQueryText"))
    document.getElementById("searchQueryText").innerHTML = strSearchResultsBegin + "<em>" + strSearchText + "</em>" + strSearchResultsEnd;
  
  if (document.getElementById("noResultsFound"))
    document.getElementById("noResultsFound").innerHTML = strSearchNoResults;
}

function checkEnter(iKeyCode, strStringToSearch)
{
  if (iKeyCode == 13)
    submitSearchFormFromTop(strStringToSearch);
}

function submitSearchFormFromTop(strStringToSearch)
{
  document.forms("frmSearch").SearchString.value = strStringToSearch;
  document.forms("frmSearch").submit();
}

function drawLanguageToggle(strPath1, strLang1, strPath2, strLang2)
{
  document.write("<div style=\"text-align: center; padding-top: 5px;\">");
  document.write("<a href=\"javascript:toggleLanguage('" + strPath1 + "');\">");
  document.write(strLang1 + "</a>&#160;|&#160;<a href=\"javascript:toggleLanguage('" + strPath2 + "');\">" + strLang2 + "</a></div>");
}

function toggleLanguage(strLanguage)
{
  var strBaseURL = top.location.href;
  var strRoot;
  var strFile;
  var iFirstIndexDouble = strBaseURL.indexOf("//");
  var strRootWorkVar = strBaseURL.substring(iFirstIndexDouble + 2, strBaseURL.length);
  var iFirstIndex = strRootWorkVar.indexOf("/");
  var iQSIndex;
  var arrExcludedFiles = new Array();
  var i;
  
  var iLastIndex;
  var index = strBaseURL.indexOf("/");

  arrExcludedFiles[0] = "search.aspx";
  arrExcludedFiles[1] = "jobopeningdetail.aspx";
  arrExcludedFiles[2] = "pressrelease.aspx";
  arrExcludedFiles[3] = "apply.aspx";
  
  while (index != -1)
  {
    index = strBaseURL.indexOf("/", index + 1);
    
    if (index != -1)
      iLastIndex = index;
  }
  
  strRoot = strBaseURL.substring(0, iFirstIndex + 7);
  strFile = strBaseURL.substring(iLastIndex + 1, strBaseURL.length);
  iQSIndex = strFile.indexOf("?");

  if (iQSIndex != -1)
     strFile = strFile.substring(0, iQSIndex);

  for (i = 0; i < arrExcludedFiles.length; i ++)
  {
    if (strFile == arrExcludedFiles[i])
    {
      strFile = "default.aspx";
      break;
    }
  }

  top.location.href = strRoot +"/" + strLanguage + "/" + strFile;
}

function preSelectForm()
{
  var qs = new Querystring()
  var strCType = qs.get("ctype", null);
  var strRType = qs.get("rtype", null);

  if (strCType == "121" && document.getElementById("subjectDropDownList"))
  {
    document.getElementById("subjectDropDownList").selectedIndex = 7;
    document.getElementById("subjectDropDownList").disabled = true;
  }

  if (strRType == "brochure" && document.getElementById("questionCommentTextBox"))
  {
    document.getElementById("questionCommentTextBox").value = "Request a brochure";
    document.getElementById("questionCommentTextBox").disabled = true;
  }
}