//      COPYRIGHT NOTICE LexisNexis  *****************
//   This JS file is protected by copyright law. 
//   Any use or reproduction in any form without the permission of LexisNexis 
//   is strictly prohibited. Distribution or use for commercial purposes is prohibited. 
//   http://www.lexisnexis.com/lncc/about/copyrt.html  Copyright
//   http://www.lexisnexis.com/lncc/about/terms.html  General conditions and terms for use
//   send mail to Owner:  Custom.Solutions@lexisnexis.com

function appendDate(btnDate, objTxtFrom, objTxtTo, strQuery, extOperator, strSegName) //replaces buildDate()
{
  var befStr = "";
  var aftStr = "";
  var from, to;
    if ((typeof extOperator == "undefined") || (extOperator == ""))    
      extOperator = "and";
	if (typeof strSegName == "undefined")    
      strSegName = "Date";
	if (typeof strQuery == "undefined")
		strQuery = "";	 	
	if (!btnDate[1].checked)
      return strQuery;
     if (isFormObj(objTxtFrom))
		from = objTxtFrom.value;
	 else
		from = objTxtFrom;
	 if (isFormObj(objTxtTo))
		to = objTxtTo.value;
	 else
		to = objTxtTo;
    if (to != "")
      befStr = "leq " + to;
    if (from != "")
      aftStr = " geq " + from;             
    if (befStr != "" || aftStr != "")
    {
	  if (strQuery != "")
		strQuery += " " + extOperator + " ";		        
      strQuery += strSegName + "(";
      if (befStr != "")
        strQuery += befStr;
      if (aftStr)
      {
        if (befStr)
          strQuery += " and ";
        strQuery += aftStr;
      }
      strQuery += ")";
    }
  return strQuery;
}

function appendSegment(objTxtElement, strSegName, strQuery, extOperator)
{
		
var text = "";
	if (isFormObj(objTxtElement))
		text = objTxtElement.value;
	 else
		text = objTxtElement;
	if (typeof strQuery == "undefined")
		strQuery = "";
	if ((typeof extOperator == "undefined") || (extOperator == ""))    
      extOperator = "and";
	
    if (text != "")
        {
        if (strQuery != "")
			strQuery += " " + extOperator + " ";
                strQuery += strSegName + "(" + text + ")";
        }
		return strQuery;
}

function buildFooter(targetName,showSuppID)
{
	var tempDate = new Date();
	var copyYear = tempDate.getFullYear();	
	if ((typeof targetName == "") || (typeof targetName == "undefined") || (targetName == ""))
		targetName = "_self";
	var aboutLink = "<a href='http:\/\/www.lexisnexis.com' target=" + targetName + " class='footerLink'><font face='verdana,arial,helvetica' size='1'>About LexisNexis<\/font><\/a>";
	var termsLink = "<a href='http:\/\/www.lexisnexis.com\/terms\/general' target=" + targetName + " class='footerLink'><font face='verdana,arial,helvetica' size='1'>Terms and Conditions<\/font><\/a>";
	var privacyLink ="<a href='http:\/\/www.lexisnexis.com\/terms\/privacy' target=" + targetName + " class='footerLink'><font face='verdana,arial,helvetica' size='1'>Privacy Policy<\/font><\/a>";
	var copyLink = "<a href='http:\/\/www.lexisnexis.com\/terms\/copyright.shtml' target=" + targetName + " class='footerLink'><font face='verdana,arial,helvetica' size='1'>Copyright &copy;<\/font><\/a>&nbsp;";
	var sep = "<font face='verdana,arial,helvetica' size='1'>&nbsp;&nbsp;|&nbsp;&nbsp;<\/font>";
	var reLine="<font face='verdana,arial,helvetica' size='1'>LexisNexis, a division of Reed Elsevier Inc. All rights reserved.</font>";
	var footerCopy = "<center>" + aboutLink + sep + termsLink + sep + privacyLink
	footerCopy += "<br>" + copyLink + "<font face='verdana,arial, helvetica' size='1'>&nbsp;" + copyYear + "<\/font>&nbsp;" + reLine +  "</center>";
	document.write(footerCopy);
}

function isFormObj(objectName)
{
if (typeof objectName.form == "undefined")
	return false;
if (typeof objectName.value == "undefined")
	return false;
return true;
}
function isDev()
{
	var currentURL = location.href;
	if((currentURL.indexOf("csdev") != -1) || (currentURL.indexOf("localhost") != -1))
		return true;
	else
		return false;
}

function isDev8080()
{
	var currentURL = location.href;
	if(currentURL.indexOf("csdev") != -1 && currentURL.indexOf(":8080") != -1)
		return true;
	else
		return false;
}

if (typeof window.parent.displaySearchValues == "undefined")
	window.parent.displaySearchValues = "new";
function showSearchValues(thisForm) {
	if (isDev() == true) {
		if (showSearchValues.arguments.length == 0) {
			alert("Invalid argument: Form Name\nThe search form name must be the first argument to showSearchValues().");
			return false;
		} // end if
		if (typeof thisForm.name == "undefined") {
			if (typeof thisForm != "string" && typeof thisForm.length == "number" && thisForm.length > 1) {
				alert("Which form's values do you want to display in showSearchValues()?\nForm: " + thisForm[0].name + " is an array of forms.");
				return false;
			} // end if
			else {
				alert("Invalid search form in showSearchValues().\nThe search form srgument must be an Object.");
				return false;
			} // end else
		} // end if
		
		var returnString = false;
		var sourceString = "";
		var termsString = "";
		var extraObjects = new Array();
		var extraObjectsIndex = 0;
		
		// Add additional arguments that were passed into the function as either string element names or element objects to the extraObjects array.
		for (var i = 1; i < showSearchValues.arguments.length; i++) {
			if (typeof showSearchValues.arguments[i] != "object")
				extraObjects[extraObjectsIndex] = (eval("thisForm." + showSearchValues.arguments[i]) != "undefined") ? eval("thisForm." + showSearchValues.arguments[i]) : showSearchValues.arguments[i];
			else
				extraObjects[extraObjectsIndex] = showSearchValues.arguments[i];
			extraObjectsIndex++;
		} // end for

		// Add extra development and testing elements.
		var extraElements = new Array("searchtype","after","relativedate","ORIGINATION_CODE","keydesc","client","clientid");
		for (var devIndex = 0; devIndex < extraElements.length; devIndex++)
			if (typeof eval("thisForm." + extraElements[devIndex]) != "undefined")
				extraObjects[extraObjectsIndex++] = eval("thisForm." + extraElements[devIndex]);

		// Test for source fields
		if (typeof thisForm.src == "object") { // for nexis.com source field.
			if (thisForm.src.type == "select-one")
				sourceString = "\nSource: " + thisForm.src.options[thisForm.src.selectedIndex].value;
			else if (thisForm.src.type == "select-multiple") {
				var sourceNumber = 0;
				var sourceStringMultiple = "";
				var sourceStringSingle = "";
				for (var s = 0; s < thisForm.src.length; s++) {
					if (thisForm.src.options[s].selected == true) {
						sourceStringMultiple += "\nSource " + (++sourceNumber) + ": " + thisForm.src.options[s].value;
						sourceStringSingle += "\nSource: " + thisForm.src.options[s].value;
					} // end if
				} // end for
				sourceString = (sourceNumber > 1) ? sourceStringMultiple : sourceStringSingle;
			} // end else if
			else
				sourceString = "\nSource: " + thisForm.src.value;
		} // end if
		else if (typeof thisForm.source == "object") { // for lexis.com or LNE (professional) source field.
			if (thisForm.source.type == "select-one")
				sourceString = "\nSource: " + thisForm.source.options[thisForm.source.selectedIndex].value;
			else if (thisForm.source.type == "select-multiple") {
				var sourceNumber = 0;
				var sourceStringMultiple = "";
				var sourceStringSingle = "";
				for (var s = 0; s < thisForm.source.length; s++) {
					if (thisForm.source.options[s].selected == true) {
						sourceStringMultiple += "\nSource " + (++sourceNumber) + ": " + thisForm.source.options[s].value;
						sourceStringSingle += "\nSource: " + thisForm.source.options[s].value;
					} // end if
				} // end for
				sourceString = (sourceNumber > 1) ? sourceStringMultiple : sourceStringSingle;
			} // end else if
			else
				sourceString = "\nSource: " + thisForm.source.value;
		} // end else if
		else
			sourceString = "\n\"SRC\" or \"SOURCE\" form elements for the source were not found.";

		// Test for query string fields
		if (typeof thisForm.query == "object") { // for nexis.com query string field.
			if (thisForm.query.type == "select-one")
				termsString = "\nSearch terms: " + thisForm.query.options[thisForm.query.selectedIndex].value;
			else if (thisForm.query.type == "select-multiple") {
				var termNumber = 0;
				var termsStringMultiple = "";
				var termsStringSingle = "";
				for (var s = 0; s < thisForm.query.length; s++) {
					if (thisForm.query.options[s].selected == true) {
						termsStringMultiple += "\nSearch term " + (++termNumber) + ": " + thisForm.query.options[s].value;
						termsStringSingle += "\nSearch terms: " + thisForm.query.options[s].value;
					} // end if
				} // end for
				termsString = (termNumber > 1) ? termsStringMultiple : termsStringSingle;
			} // end else if
			else
				termsString = "\nSearch terms: " + thisForm.query.value;
		} // end if
		else if (typeof thisForm.search == "object") { // for lexis.com query string field.
			if (thisForm.search.type == "select-one")
				termsString = "\nSearch terms: " + thisForm.search.options[thisForm.search.selectedIndex].value;
			else if (thisForm.search.type == "select-multiple") {
				var termNumber = 0;
				var termsStringMultiple = "";
				var termsStringSingle = "";
				for (var s = 0; s < thisForm.search.length; s++) {
					if (thisForm.search.options[s].selected == true) {
						termsStringMultiple += "\nSearch term " + (++termNumber) + ": " + thisForm.search.options[s].value;
						termsStringSingle += "\nSearch terms: " + thisForm.search.options[s].value;
					} // end if
				} // end for
				termsString = (termNumber > 1) ? termsStringMultiple : termsStringSingle;
			} // end else if
			else
				termsString = "\nSearch terms: " + thisForm.search.value;
		} // end else if
		else if (typeof thisForm.searchTerm == "object") { // for LNE (professional) query string field.
			if (thisForm.searchTerm.type == "select-one")
				termsString = "\nSearch terms: " + thisForm.searchTerm.options[thisForm.searchTerm.selectedIndex].value;
			else if (thisForm.searchTerm.type == "select-multiple") {
				var termNumber = 0;
				var termsStringMultiple = "";
				var termsStringSingle = "";
				for (var s = 0; s < thisForm.searchTerm.length; s++) {
					if (thisForm.searchTerm.options[s].selected == true) {
						termsStringMultiple += "\nSearch term " + (++termNumber) + ": " + thisForm.searchTerm.options[s].value;
						termsStringSingle += "\nSearch terms: " + thisForm.searchTerm.options[s].value;
					} // end if
				} // end for
				termsString = (termNumber > 1) ? termsStringMultiple : termsStringSingle;
			} // end else if
			else
				termsString = "\nSearch terms: " + thisForm.searchTerm.value;
		} // end else if
		else
			termsString = "\n\"QUERY\" or \"SEARCH\" form elements for the query string were not found.";
		
		var confirmString = "This development-only alert box will not display in production...\n" + sourceString + termsString;
		
		for (var extraIndex = 0; extraIndex < extraObjects.length; extraIndex++) {
			var extraString = "";
			if (typeof extraObjects[extraIndex] == "object") {
				if (extraObjects[extraIndex].type == "select-one")
					extraString = "\nSelected " + extraObjects[extraIndex].name + ": " + extraObjects[extraIndex].options[extraObjects[extraIndex].selectedIndex].value;
				else if (extraObjects[extraIndex].type == "select-multiple") {
					var extraNumber = 0;
					var extraStringMultiple = "";
					var extraStringSingle = "";
					for (var s = 0; s < extraObjects[extraIndex].length; s++) {
						if (extraObjects[extraIndex].options[s].selected == true) {
							extraStringMultiple += "\nSelected " + extraObjects[extraIndex].name + " " + (++extraNumber) + ": " + extraObjects[extraIndex].options[s].value;
							extraStringSingle += "\nSelected " + extraObjects[extraIndex].name + ": " + extraObjects[extraIndex].options[s].value;
						} // end if
					} // end for
					extraString = (extraNumber > 1) ? extraStringMultiple : extraStringSingle;
				} // end else if
				else
					extraString = "\n" + extraObjects[extraIndex].name + ": " + extraObjects[extraIndex].value;
			} // end if
			else
				extraString = "\n" + extraObjects[extraIndex] + ": Invalid form element passed to this function.";
			confirmString += extraString;
		} // end for
		
		confirmString += "\n\nClick OK to submit this search, or Cancel (alert will display for future submissions)."
		if (window.parent.displaySearchValues == true || window.parent.displaySearchValues == "new") {
			if (confirm(confirmString) == true) {
				if (window.parent.displaySearchValues == "new")
					window.parent.displaySearchValues = confirm("Display the development alert box for future searches?\n\n\"OK\" will display the alerts for future searches, \"Cancel\" will not.");
				returnString = true;
			} // end if
		} // end if
		else
			returnString = true;
	} // end if
	else
		returnString = true;
	return returnString;
} // end showSearchValues()

function getRadioValue(radioGroup)
{	
	var selectedValue = "";
	
	if(radioGroup.length == undefined)
		selectedValue = radioGroup.value;
	else
	{
		for(x=0; x<radioGroup.length; x++)
		{
			if(radioGroup[x].checked)
				selectedValue = radioGroup[x].value;			
		}
	}	
	return selectedValue;
}

function NavigateToDownloadURl(stringURL)
{
    if(window.opener)
    {
        window.opener.location=stringURL;
        self.close();
    }else
    {
        window.location=stringURL;        
    }
return false;

}
