// $Header:   //USBHPVCS2/DNBPROJECTS/FabSrv/EBIR/archives/Scripts/sir/sir.js_v   1.4   Apr 28 2003 09:13:34   grahamg  $

var isNav, isIE, isIE4, isNav6;
var lastDisplayedDivId = "overview";
var showWord = "visible";
var hideWord = "hidden";

var surveyURL = '/product/new_features/betabir.htm?param1=' + requestSubscriber;
var introURL = '/sir/help/bir_popup.html';
var paymentDetailDate = '';
var rowCount = 0;
var blueTableBackground = '#ccffff';
var numberFormatter = new NumberFormat();
var judgmentCount = 0;
var suitCount = 0;
var lienCount = 0;
var uccCount = 0;

if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
		showWord = "show";
		hideWord = "hide";
	} else if (navigator.appName.indexOf("Microsoft") != -1) {
		isIE = true;
        var msie = navigator.appVersion.indexOf("MSIE ");

        var msieVersion = parseInt(navigator.appVersion.substring(msie+5, navigator.appVersion.indexOf(".", msie)));
        if (msieVersion == 4) {
            isIE4 = true;
        }
	}
}	
if (parseInt(navigator.appVersion) >= 5 && navigator.appName == "Netscape")
{
	isNav6 = true;
	isNav = false;
	showWord = "visible";
	hideWord = "hidden";
}	
function positionIt(id,x,y)
{
	if (isNav) {
		document.layers[id].left = x;
		document.layers[id].top = y;
	} else	if (isIE) {
		document.all[id].style.pixelLeft = x;
		document.all[id].style.pixelTop = y;
	} else	if (isNav6) {
		document.getElementById(id).style.left = x;
		document.getElementById(id).style.top = y;
	}
}

function setVisibility(id, visState) {
	if (isNav) {
		document.layers[id].visibility = visState;
		if (visState == 'hide') {
			document.layers[id].display='none';
		} else {
			document.layers[id].display='';
		}
	} else if (isIE) {
		document.all[id].style.visibility = visState;
        if (!isIE4) {
			if (visState == 'hidden') {
				document.all[id].style.display='none';
			} else {
				document.all[id].style.display='';
            }
		}
	} else if (isNav6) {
		document.getElementById(id).style.visibility = visState; 
		if (visState == 'hidden') {
			document.getElementById(id).style.display='none';
		} else {
			document.getElementById(id).style.display='';
		}
	}
}

function fullyLoaded() {
	if (!allSectionsLoaded) {
		if (retries >= 2) {
			retries = 0;
			location.reload();
		} else {
			alert("This report has not finished loading.\nPlease wait a moment,\nthen press 'OK'");
			retries++;
		}
	}
	return allSectionsLoaded;
}

function displayIt(id) {
	// hide previously displayed div, then show selected div
	if (isNav) {
		if (lastDisplayedDivId != "") {
			document.layers[lastDisplayedDivId].visibility = hideWord;
			document.layers[lastDisplayedDivId].display = 'none';
			document.layers[lastDisplayedDivId + "on"].visibility = hideWord;
			document.layers[lastDisplayedDivId + "on"].display = 'none';
		}
		document.layers[id].visibility = showWord;	
		document.layers[id].display = '';	
		document.layers[id + "on"].visibility = showWord;	
		document.layers[id + "on"].display = '';	
		var sidebarDiv = document.layers[id].document.layers[id + 'Sidebar'];
		var contentDiv = document.layers[id].document.layers[id + 'Content'];
		var footerDiv = document.layers[id].document.layers[id + 'Footer'];
		var sideDiv = document.layers[id].document.layers[id + 'Side'];
		var maxHeight = contentDiv.clip.height > sidebarDiv.clip.height ? contentDiv.clip.height : sidebarDiv.clip.height;
		document.layers[id].clip.height=maxHeight + footerDiv.clip.height;
		contentDiv.top = 0;
		contentDiv.visibility = 'inherit';
		sidebarDiv.clip.height = maxHeight;
		sidebarDiv.background.src = imagePath + 'navbkgnd.gif';
		footerDiv.top = maxHeight;
		footerDiv.visibility = 'inherit';
		sideDiv.clip.height = maxHeight;
		sideDiv.clip.width = 15;
		sideDiv.visibility = 'inherit';
	} else if (isIE) {
		if (lastDisplayedDivId != "") {
			document.all[lastDisplayedDivId].style.visibility = hideWord;
            if (!isIE4)
	    		document.all[lastDisplayedDivId].style.display = 'none';
			document.all[lastDisplayedDivId + "on"].style.visibility = hideWord;
            if (!isIE4)
    			document.all[lastDisplayedDivId + "on"].style.display = 'none';
		}
		document.all[id].style.visibility = showWord;
		document.all[id].style.display = '';
		document.all[id + "on"].style.visibility = showWord;
		document.all[id + "on"].style.display = '';
		var sidebarDiv = document.all[id + 'Sidebar'];
		var contentDiv = document.all[id + 'Content'];
		var footerDiv = document.all[id + 'Footer'];
		var sideDiv = document.all[id + 'Side'];
		var maxHeight = contentDiv.offsetHeight > sidebarDiv.offsetHeight ? contentDiv.offsetHeight : sidebarDiv.offsetHeight
	    contentDiv.style.top=0;
        contentDiv.style.left=150;
        contentDiv.style.borderLeft="11px solid white";
        contentDiv.style.borderRight="10px solid white";
        contentDiv.style.visibility='inherit';
		sidebarDiv.style.height=maxHeight;
		sidebarDiv.style.backgroundImage='url(' + imagePath + 'navbkgnd.gif)'
		footerDiv.style.top=maxHeight;
		footerDiv.style.visibility='inherit';
		sideDiv.style.height=maxHeight;
		sideDiv.style.visibility='inherit';
	} else if (isNav6) {
		if (lastDisplayedDivId != "") {
			document.getElementById(lastDisplayedDivId).style.visibility = hideWord; 
			document.getElementById(lastDisplayedDivId).style.display = 'none'; 
			document.getElementById(lastDisplayedDivId + "on").style.visibility = hideWord; 
			document.getElementById(lastDisplayedDivId + "on").style.display = 'none'; 
		}
		document.getElementById(id).style.visibility = showWord; 
		document.getElementById(id).style.display = ''; 
		document.getElementById(id + "on").style.visibility = showWord; 
		document.getElementById(id + "on").style.display = ''; 
		var sidebarDiv = document.getElementById(id + 'Sidebar');
		var contentDiv = document.getElementById(id + 'Content');
		var footerDiv = document.getElementById(id + 'Footer');
		var sideDiv = document.getElementById(id + 'Side');
		var maxHeight = contentDiv.offsetHeight > sidebarDiv.offsetHeight ? contentDiv.offsetHeight : sidebarDiv.offsetHeight
	    contentDiv.style.top=0;
        contentDiv.style.left=150;
        contentDiv.style.borderLeft="11px solid white";
        contentDiv.style.borderRight="10px solid white";
        contentDiv.style.visibility='inherit';
		sidebarDiv.style.height=maxHeight;
		sidebarDiv.style.backgroundImage='url(' + imagePath + 'navbkgnd.gif)'
		footerDiv.style.top=maxHeight;
		footerDiv.style.visibility='inherit';
		sideDiv.style.height=maxHeight;
		sideDiv.style.visibility='inherit';
	}
	lastDisplayedDivId = id;
}

function displayMenu(id)	
{
	if (isNav)
	{
		document.layers[id].visibility = showWord;
	}
	else 
	if (isIE)
	{
		document.all[id].style.visibility = showWord;
	}
	else 
	if (isNav6)
	{
		document.getElementById(id).style.visibility = showWord;
	}
}

function handleResize() {
	if (isNav) {
		location.reload();
	}
}

function showtab(targetname) {
	if (fullyLoaded()) {
		displayIt(targetname);
		return true;
	}
	return false;
}

// END TAB IMAGE ARRAY DEFINITION AND ROLLOVER FUNCTIONS

function openMap() {
	var mapSite = "http://sbs.dnb.com/Products/eBir/Map.asp";
	var query = "?compName=" + escape(companyName) + "&compAddLine1=" + escape(companyAddress) + "&compAddLine2=" + escape(companyCity + " " + companyState);
	var mapUrl = mapSite + query;
	window.open(mapUrl,'map','width=640,height=480,resizable=yes,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes')
}
function openTicker() {
	var tickerSite = "http://dnb.edgarexplorer.com/profile.asp";
	var query = "?ticker=" + escape(stockTicker);
	var tickerUrl = tickerSite + query;
	window.open(tickerUrl,'ticker','width=770,height=600,resizable=yes,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes')
}
function openFilings() {
	var tickerSite = "http://dnb.edgarexplorer.com/searchrouter.asp";
	var query = "?ticker=" + escape(stockTicker);
	var tickerUrl = tickerSite + query;
	window.open(tickerUrl,'ticker','width=770,height=600,resizable=yes,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes')
}

function openHelp(doc)
{
	var helpWin = window.open(doc,'help','width=770,height=500,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes');
	helpWin.focus();
}

function openWebsite(doc, urlType)
{
	var targetURL = helpPath + "bizURL.html?targetURL=" + escape(doc) + "&urlType=" + urlType + "&dunsCase=" + dunsCase;
	bizWin = window.open(targetURL,'biz','width=770,height=500,resizable=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes');
	bizWin.focus();
}

function infobotURL(parameters)
{
   	return ( "/scripts/ProductRetriever.asp?" + parameters + "&SESSIONID=" + sessionid );
}

function callInfobot(parameters, msg)
{
	if (msg == null || confirm(msg))
	{
		location = infobotURL(parameters);
	}
}

function exportOne(sectionName) {
	var requestURL = "/scripts/ProductRetriever.asp?REQUESTTYPE=CsvExport&SESSIONID=" + sessionid +"&dunsCase=" + dunsCase + "&CsvSectionName=" + sectionName;
	openHelp(requestURL);
}

function exportChoose() {
	var requestURL=helpPath+"exportForm.html?sessionid=" + sessionid + "&dunsCase=" + dunsCase + "&primName=" + companyName + "&primAddr=" + companyAddress + ", " + companyCity + ", " + companyState + "  " + companyZip;
	if (showPaymentSummary) {
		requestURL += "&showPmtSum=1";
	}
	if (showPaymentDetails) {
		requestURL += "&showPmtDet=1";
	}
	if (showUpdateExport) {
		requestURL += "&showUpdate=1";
	}
	if (showStatementUpdate) {
		requestURL += "&showFinUpd=1";
	}
	if (showComparative) {
		requestURL += "&showFinComp=1";
	}
	if (showFinance) {
		requestURL += "&showFinStmt=1";
	}
	if (showJudgments) {
		requestURL += "&showJudg=1";
	}
	if (showSuits) {
		requestURL += "&showSuit=1";
	}
	if (showLiens) {
		requestURL += "&showLien=1";
	}
	if (showUCCs) {
		requestURL += "&showUCC=1";
	}
	openHelp(requestURL);
}

function dbiaNewSearch()
{
  if (isInfobot == "true")
	callInfobot('REQUESTTYPE=CONTRACTNEWSEARCH&PROCESSFLOW=CORPT');
  else
    location = searchURL;
}

function dbiaHome()
{
	callInfobot('REQUESTTYPE=CONTRACTMENU');
}

function dbiaReportArchive()
{
  if (isInfobot == "true")
    callInfobot('REQUESTTYPE=unreadarchive&PROCESSFLOW=CORPT');
  else
    location = archiveURL;
}

function dbiaMonitoring(cmid)
{
	var f = document.MonitoringForm;
	if (f)
	{
		f.SESSIONID.value = sessionid;
		f.DUNSNUMBER.value = dunsCase;
		f.COMPANYNAME.value = companyName;
        if (cmid != null && cmid != '') {
            f.CMID.value = cmid;
        }
		if (companyName.length > 30) {
			f.ABBREVCOMPANYNAME.value = companyName.substring(0,30);
		} else {
			f.ABBREVCOMPANYNAME.value = companyName;
		}
		f.submit();
	}
//	callInfobot('REQUESTTYPE=SENDCONTINUOUSMONITORINGPAGE&PROCESSFLOW=CORPT&PRODUCTNAME=Business+Information+Report&DUNSNUMBER=' +
//		dunsCase + '&CMRETURNDUNS=None&COMPANYNAME=' + escape(companyName) + '&ABBREVCOMPANYNAME=' + escape(companyName));
}

function dbiaEmailReport()
{
  if (isInfobot == "true")
    callInfobot('REQUESTTYPE=emailreportsconfirm&emailFilePath=' + escape(emailFilePath));
  else
    location = emailURL;
}

function dbiaInvestigation()
{
	var f = document.InvestigationForm;
	if (f)
	{
		var investWebfab = 'Y';
		var phoneNum = phoneNumber(companyPhone);
		f.SESSIONID.value = sessionid;
		f.COMPANYNAME.value = companyName;
		f.COMPANYADDRESS.value = companyAddress;
		f.COMPANYCITY.value = companyCity;
		f.COMPANYSTATE.value = companyState;
		f.COMPANYPHONE.value = phoneNum;
		f.INVESTDUNSNUMBER.value = dunsCase;
		f.INVESTCOMPANYNAME.value = companyName;
		f.INVESTCOMPANYADDRESS.value = companyAddress;
		f.INVESTCOMPANYCITY.value = companyCity;
		f.INVESTCOMPANYSTATE.value = companyState;
		f.INVESTCOMPANYPHONE.value = phoneNum;
		f.OIWebfab.value = investWebfab;
		f.submit();
	}
//	callInfobot('REQUESTTYPE=INVESTIGATESTATIC&PROCESSFLOW=CORPT&COMPANYNAME=' + escape(companyName) +
//		'&COMPANYADDRESS=' + escape(companyAddress) + 
//		'&COMPANYCITY=' + escape(companyCity) +
//		'&COMPANYSTATE=' + companyState + 
//		'&COMPANYPHONE=' + escape(companyPhone) +
//		'&INVESTDUNSNUMBER=' + dunsCase +
//		'&CMRETURNDUNS=None&INVESTCOMPANYNAME=' + escape(companyName) +
//		'&INVESTCOMPANYADDRESS=' + escape(companyAddress) +
//		'&INVESTCOMPANYCITY=' + escape(companyCity) + 
//		'&INVESTCOMPANYSTATE=' + companyState +
//		'&INVESTCOMPANYPHONE=' + escape(companyPhone));
}

function dbiaCompanyReports()
{
	callInfobot('REQUESTTYPE=contractnewsearch&PROCESSFLOW=CORPT');
}

function dbiaCompanyLookup()
{
	callInfobot('REQUESTTYPE=contractWBColkup&PROCESSFLOW=WBCL');
}

function dbiaPublicRecordsSearch()
{
	callInfobot('REQUESTTYPE=prnewsearch&PROCESSFLOW=PR');
}

function dbiaCountryRisk()
{
	callInfobot('REQUESTTYPE=countryrisk&PROCESSFLOW=CRSR');
}

function dbiaUSMarketingLists()
{
	callInfobot('REQUESTTYPE=usmlhome&PROCESSFLOW=USML');
}

function dbiaGlobalFamilyLinkage(cmid)
{
	callInfobot('REQUESTTYPE=contractWBFamLnkge&PROCESSFLOW=WBFL&SIRDUNS=' + dunsCase + (cmid != null && cmid != '' ? "&CMID=" + cmid : ""));
}

function dbiaGlobalMarketingLists()
{
	callInfobot('REQUESTTYPE=contractWBCrtList&PROCESSFLOW=WBML');
}

var tid;
var popupTarget;
function setSurveyTimer(popupFile) {
	popupTarget = popupFile;
	tid = window.setTimeout("surveyPopup(popupTarget)", 45000);
}

function surveyPopup (popupFile) {
    var apop = window.open(popupFile, "popupwindow", "menubar=no,width=380,height=280");
}

function displaySurvey()
{
	window.clearTimeout(tid);
	openHelp(surveyURL);
}
var introTid;
var introPopupTarget;
function setIntroTimer(popupFile) {
	if (!repeatCustomer.load() || !repeatCustomer.repeatVisit) {
		introPopupTarget = popupFile;
		introTid = window.setTimeout("introPopup(introPopupTarget)", 500);
		repeatCustomer.repeatVisit = 'true';
		repeatCustomer.store();
	}
}

function introPopup (popupFile) {
    var apop = window.open(popupFile, "popupwindow", "menubar=no,width=600,height=400");
}

function displayInto()
{
	window.clearTimeout(tid);
	openHelp(introURL);
}

function printerFriendly(showPrompt)
{
	var targetURL = printFriendlyURL;
	if (showPrompt) {
		targetURL += '?printPrompt';
	}
	window.open(targetURL,'pf','width=770,height=500,resizable=yes,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes');
}

function doPrint() {
	if (!isIE4) {
		window.print();
	} else {
		alert("To print from this browser, you must select \"File/Print\" from the Main Menu.");
	}
}

function buyParentBIR()
{
	if(reportWarning('parent Business Information')) {
		callInfobot('REQUESTTYPE=checkPastPurchaseAndOrder&productselected=Business+Information+Report&productsselected=Business+Information+Report&COMPANYNAME_=&hqtradeup=on&dunsnumber=' + parentDunsCase);
	}
}

function buyComprehensiveReport()
{
  if(reportWarning('Comprehensive')) {
    if (isInfobot == true)
      callInfobot('REQUESTTYPE=checkPastPurchaseAndOrder&productselected=Comprehensive+Report&productsselected=Comprehensive+Report&dunsnumber=' + dunsCase);
    else
      location = compUpsellURL;
  }
}

function saveReportAsText()
{
  window.open(textOnlyURL,'pf','width=770,height=500,resizable=yes,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes');
}

function buyPaymentAnalysisReport()
{
  if(reportWarning('Payment Analysis')) {
    if (isInfobot == "true")
      callInfobot('REQUESTTYPE=checkPastPurchaseAndOrder&productselected=Payment+Analysis+Report&productsselected=Payment+Analysis+Report&dunsnumber=' + dunsCase);
    else
      location = parUpsellURL;
  }
}

function buyHigherRiskScoreReport()
{
  if(reportWarning('Higher Risk Score')) {
    if (isInfobot == "true")
      callInfobot('REQUESTTYPE=checkPastPurchaseAndOrder&productselected=Higher+Risk+Score+Report&productsselected=Higher+Risk+Score+Report&dunsnumber=' + dunsCase);
    else
      location = highriskUpsellURL;
  }
}

function buyIndustryNormsReport()
{
  if(reportWarning('Industry Norms')) {
    if (isInfobot == "true")
      callInfobot('REQUESTTYPE=checkPastPurchaseAndOrder&productselected=Industry+Norms&productsselected=Industry+Norms&dunsnumber=' + dunsCase + '&GRP4ADDRESSEE=' + requestAttention);
    else
      location = industryNormsUpsellURL;
  }
}

function reportWarning(repname)
{
  return(confirm("Confirmation - Order the " + repname + " Report?"));
}

function phoneNumber(phoneString) {
	var phoneNum = '';
	for (var i = 0; i < phoneString.length; i++) {
		var phoneChar = phoneString.charAt(i);
		if (phoneChar >= '0' && phoneChar <= '9') {
			phoneNum += phoneChar;
		}
	}
	return phoneNum;
}

function formatCompanyName(cname) {
   var maxThreshold = 33;
   var smallCompanyStyleThreshold = 28;

   var length = cname.length;
   var score = 0;
   var characters = 0;
   var x;
   for (var i = 0; i < cname.length && score < maxThreshold; i++) {
     if (cname.charAt(i) == '&') {
       x = cname.substring(i).indexOf(';');
       if (x > 0) {
         i += x;
         continue;
       }
     }
     if ((cname.charAt(i) >= 'a' && cname.charAt(i) <= 'z') && (cname.charAt(i) != 'w')) {
       score += .75;
     }
     else if (cname.charAt(i) == 'W') {
       score += 1.2;
     }
     else if (cname.charAt(i) == 'w') {
       score += .8;
     }
     else {
       score += 1;
     }
     characters++;
   }

   if (score < smallCompanyStyleThreshold) {
     document.write('<span class="companyTitle">' + cname + '</span>');
   }
   else if (score < maxThreshold) {
     document.write('<span class="smallCompanyTitle">' + cname + '</span>');
   }
   else {
     document.write('<span class="smallCompanyTitle">' + cname.substr(0, characters-4) + '...' + '</span>');
   }

}
function Cookie(document, name, days, path, domain, secure) {
	this.$document=document;
	this.$name=name;
	if (days) {
		this.$expiration = new Date((new Date()).getTime() + days*24*60*60*1000);
	} else {
		this.$expiration = null;
	}
	if (path) {
		this.$path = path;
	} else {
		this.$path = null;
	}
	if (domain) {
		this.$domain= domain;
	} else {
		this.$domain= null;
	}
	if (secure) {
		this.$secure= secure;
	} else {
		this.$secure= null;
	}
}
function _Cookie_store() {
	var cookieVal = "";
	for (var prop in this) {
		if ((prop.charAt[0] == '$') || ((typeof this[prop]) == 'function')) {
			continue;
		}
		if (cookieVal != "") {
			cookieVal += '&';
		}
		cookieVal += prop + ':' + escape(this[prop]);
	}
	var cookie = this.$name + '=' + cookieVal;
	if (this.$expiration) {
		cookie += '; expires=' + this.$expiration.toGMTString();
	}
	if (this.$path) {
		cookie += '; path=' + this.$path;
	}
	if (this.$domain) {
		cookie += '; domain=' + this.$domain;
	}
	if (this.$secure) {
		cookie += '; secure=' + this.$secure;
	}
	this.$document.cookie = cookie;
}

function _Cookie_load() {
	var allCookies = this.$document.cookie;
	if (allCookies == null || allCookies == "") {
		return false;
	}
	var start = allCookies.indexOf(this.$name + '=');
	if (start == -1) {
		return false;
	}
	start += this.$name.length + 1;
	var end = allCookies.indexOf(';', start);
	if (end == -1) end = allCookies.length;
	var cookieVal = allCookies.substring(start, end);
	var a = cookieVal.split('&');
	for (var i = 0; i < a.length; i++) {
		a[i] = a[i].split(':');
	}
	for (var i = 0; i < a.length; i++) {
		if (a[i][0] == "$expiration") {
			this[a[i][0]] = new Date(unescape(a[i][1]));
		} else {
			this[a[i][0]] = unescape(a[i][1]);
		}
	}
	return true;
}

function _Cookie_remove() {
	var cookie;
	cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	this.$document.cookie = cookie;
}

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;

var repeatCustomer = new Cookie(document, "beenHereDoneThat", 90);