
//Function: Window On Load event handler
//Description/Purpose: Writes/Appends client side javascript file to head tag of document
//Description/Purpose: pointing to /CommonLib/Functions.js                         
//Arguments: none
//Return values: none
window.onload 
{ 
	with (document.getElementsByTagName("head")[0].appendChild(document.createElement("script"))) 
	{ 
		setAttribute("id", "FunctionsScript", 0); 
		setAttribute("type", "text/javascript", 0); 
		setAttribute("src", "/CommonLib/Functions.js", 0); 
	} 
} 

//Function: SetCoAssociationControl
//Description/Purpose: Sets visible the Company Association drop down  and message
//Description/Purpose: if  SmartNews is selected as SalesTrigger otherwise invisible                          
//Arguments: none
//Return values: none
function SetCoAssociationControl()
{
	var lstrEvent;
	var lstrResult;
	
	if(document.getElementById('FindEventsControl_lstEventType') == null)
	   return;
	   
	if(document.getElementById('FindEventsControl_cboCoAssociation') != null)
	{
	    lstrResult = document.getElementById('FindEventsControl_cboCoAssociation').value;
	}   
	   
	lstrEvent = document.getElementById('FindEventsControl_lstEventType').value;
	if(lstrEvent == "1139")
	{
		if(document.getElementById('FindEventsControl_cboCoAssociation') != null)
		{	
		    if(lstrResult == 0)
		    {	    
				document.getElementById('FindEventsControl_lblCoAssociation').style.visibility = 'visible';
				document.getElementById('FindEventsControl_cboCoAssociation').style.visibility = 'visible';
				document.getElementById('FindEventsControl_lblComAssMsg').style.visibility = 'visible';
			}
			else if(lstrResult == 1 || lstrResult == 2)
			{
				document.getElementById('FindEventsControl_lblCoAssociation').style.visibility = 'visible';
				document.getElementById('FindEventsControl_cboCoAssociation').style.visibility = 'visible';
				document.getElementById('FindEventsControl_lblComAssMsg').style.visibility = 'hidden';			   
			}
		}
	}
	else
	{
	   if(document.getElementById('FindEventsControl_lblCoAssociation') != null)
			document.getElementById('FindEventsControl_lblCoAssociation').style.visibility = 'hidden';
	   if(document.getElementById('FindEventsControl_cboCoAssociation') != null)		
			document.getElementById('FindEventsControl_cboCoAssociation').style.visibility = 'hidden';
	   if(document.getElementById('FindEventsControl_lblComAssMsg') != null)	
			document.getElementById('FindEventsControl_lblComAssMsg').style.visibility = 'hidden';
	}
	//if(document.getElementById('FindEventsControl_cboCoAssociation') != null)
		//document.getElementById('FindEventsControl_cboCoAssociation').selectedIndex = 0 ;
	
}

///submit click-validation for trueleadprofile
//Function: SubmitClick
//Description/Purpose: The function is Click event handler of Search button on search pages
//Description/Purpose: It validates date range, location, industry details and returns false if some
//Description/Purpose: Invalid input is there otherwise true                         
//Arguments: none
//Return values: boolean(true/false)
function SubmitClick()
{
		TrimAllTextBox();
		ResetAllLabelColor(LabelsIdsToReset);
		
		var lstrEvent;
		lstrEvent = document.getElementById('FindEventsControl_lstEventType').value;
		
		var lstrIndustry;
		var lstrSIC;
		var	lstrCoAsso;
				
		lstrIndustry = document.getElementById('FindEventsControl_lstIndustry').value ;
		lstrSIC = document.getElementById('FindEventsControl_txtSIC').value ;
		if(document.getElementById('FindEventsControl_cboDateRange') != null)
		{
			if(!ValidateFromToDate('FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo','FindEventsControl_cboDateRange','FindEventsControl_lblDateFrom','FindEventsControl_lblDateTo'))
			{   return false;  }
		}
		
		if(document.getElementById('cboDate') != null)
		{
			if(!ValidateFromToDate('txtDateFrom','txtDateTo','cboDate','lblFrom','lblTo'))
			{   return false;  }
		}
		
		if(document.getElementById('FindEventsControl_txtDistance').disabled != true)
		{  
			if(!ValidateLocationSection('FindEventsControl_txtZip','FindEventsControl_lblZip','FindEventsControl_txtDistance','FindEventsControl_lblDistance'))
			{	return false;  }
		
			if(!ValidateRevenueRange('FindEventsControl_lstRevenue','FindEventsControl_lblRevenue','FindEventsControl_txtRevenuefrom','FindEventsControl_lblRevfrm','FindEventsControl_txtRevenueTo','FindEventsControl_lblRevto'))
			{	return false;  }
			
			if(!ValidateEmployeeNumberRange('FindEventsControl_lstEmployee','FindEventsControl_lblEmployee','FindEventsControl_txtEmployeeFrm','FindEventsControl_lblEmpfrm','FindEventsControl_txtEmployeeTo','FindEventsControl_lblEmpto'))
			{	return false;  }	
		
		}
		
	return true;
}


//Function: ShowWarningMsg
//Description/Purpose: show warning Msg for Smart Triggers not associated with a company
//Description/Purpose: When event type is "All" (SI + RFP + News) and the user had entered in one of the  
//Description/Purpose: search criteria (Industry, SIC, Revenue, Employees, Employees From, Employees To,                          
//Description/Purpose: Revenue, Revenue from, Revenue To) give a warning message  
//Arguments: none
//Return values: none
function ShowWarningMsg()
{
	    var lstrIndustry;
		var lstrSIC;
		var lstrRevenue;
		var lstrRevenuefrom;
		var lstrRevenueTo;
		var lstrEmployeeTo;
		var lstrEmployeeFrm;
		var lstrEmployee;
		var lstrEvent;
			 			
		lstrIndustry = document.getElementById('FindEventsControl_lstIndustry').value ;
		lstrSIC = document.getElementById('FindEventsControl_txtSIC').value ;
		lstrRevenue = document.getElementById('FindEventsControl_lstRevenue').value ;
		lstrRevenuefrom = document.getElementById('FindEventsControl_txtRevenuefrom').value ;
		lstrRevenueTo = document.getElementById('FindEventsControl_txtRevenueTo').value ;
		lstrEmployeeFrm = document.getElementById('FindEventsControl_txtEmployeeFrm').value ;
		lstrEmployeeTo = document.getElementById('FindEventsControl_txtEmployeeTo').value ;
		lstrEmployee = document.getElementById('FindEventsControl_lstEmployee').value ;		
		lstrEvent = document.getElementById('FindEventsControl_lstEventType').value;
		
		
		if(lstrEmployee == "0")
		{
			lstrEmployee='';
		}
		if(lstrRevenue == "0")
		{
			lstrRevenue='';
		}
		if(lstrIndustry == "0")
		{
			lstrIndustry='';
		}
		
		
		
		var selboxEvent;
		var lItemCount;
		lItemCount= 0;
		
		selboxEvent = document.getElementById('FindEventsControl_lstEventType');
		for(var i = 0; i < selboxEvent.options.length; i++)
		{
			if(selboxEvent.options[i].selected)
				lItemCount++;

			if(lItemCount > 1)
				break;
		}	
		 
		if(lstrEvent == "ALL" || lItemCount > 1)
		{	
				if(lstrIndustry != '' || lstrSIC != '' || lstrRevenue != '' || lstrRevenuefrom != '' || lstrRevenueTo != ''
						|| lstrEmployeeFrm != '' || lstrEmployeeTo != '' || lstrEmployee != '')
				{
					//alert("Warning: Smart Triggers not associated with a company will not be returned when searching by company attributes.");
					alert(document.getElementById('hdnCompAssoAlertMsg').value);
				}
		}		
}

//Function: getTodaysDate
//Description/Purpose: returns value of today's date hidden control
//Arguments: none
//Return values: value of hidden control todays date  
function getTodaysDate()
{
	 return document.getElementById('hdnTodaysDate').value;
}

//Function: hideControl
//Description/Purpose: hides company association drop down and related message 
//Arguments: none
//Return values: none
function hideControl()
{    
	if(document.getElementById('FindEventsControl_cboCoAssociation') != null)
	{
		document.getElementById('FindEventsControl_lblCoAssociation').style.visibility = 'hidden';
		document.getElementById('FindEventsControl_cboCoAssociation').style.visibility = 'hidden';
		document.getElementById('FindEventsControl_lblComAssMsg').style.visibility = 'hidden';
	}
 	   
}
   
//Function: ResetFilterCriteria
//Description/Purpose: Resets the search criteria selected by users on Lead Search pages
//Description/Purpose: and sets the control values to default                         
//Arguments: none
//Return values:  none
function ResetFilterCriteria()
{

		ResetAllLabelColor(LabelsIdsToReset);
		
	 	document.getElementById('FindEventsControl_lstEventType').selectedIndex = 0;
	 
		document.getElementById('FindEventsControl_cboCategory').disabled = true;
		
	
		document.getElementById('FindEventsControl_cboCountry').selectedIndex = 0;
		
		//Call AJAX function for fill state.
		var lstrCountry = document.getElementById('FindEventsControl_cboCountry').value;
		FindEventsCriteria.AjaxGetStates(lstrCountry ,FillStates_CallBack);
		
		document.getElementById('FindEventsControl_lstStateProv').selectedIndex = 0;
		document.getElementById('FindEventsControl_cboDateRange').selectedIndex = 3;
		document.getElementById('FindEventsControl_lstEmployee').selectedIndex = -1;
		document.getElementById('FindEventsControl_lstRevenue').selectedIndex = -1;
		document.getElementById('FindEventsControl_lstIndustry').selectedIndex = -1;
		
		document.getElementById('FindEventsControl_lstSubCategory').options.length = 0;
		document.getElementById('FindEventsControl_cboCategory').options.length = 0
		
		if(document.getElementById('FindEventsControl_cboTerritory') != null)
		{
			document.getElementById('FindEventsControl_cboTerritory').selectedIndex = 0;
			if(document.getElementById('FindEventsControl_lstCompany') != null)
			{
			   document.getElementById('FindEventsControl_lstCompany').selectedIndex = 0;
			}
			  
			HideDetailsPanel();
		}	
		
		document.getElementById('FindEventsControl_txtKeyword').value = '';
		
		OnDateRangeChanged('FindEventsControl_cboDateRange','FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo','FindEventsControl_lblDateFrom','FindEventsControl_lblDateTo','FindEventsControl_anchor2','FindEventsControl_anchor3');
			
		document.getElementById('FindEventsControl_txtCity').value = '';
		document.getElementById('FindEventsControl_txtZip').value = '';
		document.getElementById('FindEventsControl_txtAreaCode').value = '';
		document.getElementById('FindEventsControl_txtDistance').value = '';
		document.getElementById('FindEventsControl_txtSIC').value = '';
		document.getElementById('FindEventsControl_txtRevenuefrom').value = '';
		document.getElementById('FindEventsControl_txtRevenueTo').value = '';
		document.getElementById('FindEventsControl_txtEmployeeFrm').value = '';
		document.getElementById('FindEventsControl_txtEmployeeTo').value = '';
		
		
		document.getElementById('FindEventsControl_selectedCountryValue').value = '';
		document.getElementById('FindEventsControl_hidState').value = '';
		document.getElementById('FindEventsControl_hidEventtype').value = '';
		document.getElementById('FindEventsControl_hidCategory').value = '';
		document.getElementById('FindEventsControl_hidSubCategory').value = '';
		document.getElementById('FindEventsControl_selectedIndustryValue').value='';
		document.getElementById('FindEventsControl_selectedEmpValue').value='';
		document.getElementById('FindEventsControl_selectedRevValue').value='';
		
		document.getElementById('FindEventsControl_radNoTerritoryComp').click();
		
		//Add for #4179
		if(document.getElementById('FindEventsControl_radCompanyTracker') != null)
			document.getElementById('FindEventsControl_radCompanyTracker').disabled = false;
		if(document.getElementById('FindEventsControl_radTerritory') != null)
			document.getElementById('FindEventsControl_radTerritory').disabled = false;

		
		
		hideControl();
		ControlsEnable();
	
		//TA 4.2.5 *CommentedOut*
	        ShowSmartNewsOldMsg('FindEventsControl_cboDateRange','FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo', 'FindEventsControl_lstEventType', 'FindEventsControl_lblSmartNewsOldMsg');
}

//Function: ControlsEnable
//Description/Purpose: Enables Company Attribute controls
//Arguments: none
//Return values: none
function ControlsEnable()
{
	document.getElementById('FindEventsControl_lstIndustry').disabled = false;
	document.getElementById('FindEventsControl_txtSIC').disabled = false;
	document.getElementById('FindEventsControl_lstRevenue').disabled = false;
	document.getElementById('FindEventsControl_txtRevenuefrom').disabled = false;
	document.getElementById('FindEventsControl_txtRevenueTo').disabled = false;
	document.getElementById('FindEventsControl_txtEmployeeFrm').disabled = false;
	document.getElementById('FindEventsControl_txtEmployeeTo').disabled = false;
	document.getElementById('FindEventsControl_lstEmployee').disabled = false;
	document.getElementById('FindEventsControl_txtZip').disabled = false;
	document.getElementById('FindEventsControl_txtCity').disabled = false;
	document.getElementById('FindEventsControl_cboCountry').disabled = false;
	document.getElementById('FindEventsControl_lstStateProv').disabled = false;
	document.getElementById('FindEventsControl_txtDistance').disabled = false;
	 
	if(document.getElementById('navSIC') != null)
	{
		document.getElementById('navSIC').style.visibility = 'visible';
	}
	else
	{
		if(document.getElementById('FindEventsControl_navSIC') != null)
		{
			document.getElementById('FindEventsControl_navSIC').style.visibility = 'visible';
		}
	}	
}

//Function: FillStates_CallBack
//Description/Purpose: Call Back Function for FindEventsCriteria.AjaxGetStates
//Description/Purpose: takes response object(array of states) and fill the state list drop down with it                          
//Arguments: Response object(states array) of FindEventsCriteria.AjaxGetStates
//Return values: none
function FillStates_CallBack(objResponse)
{
	if(objResponse.value != null)
	{
		var selbox=document.getElementById('FindEventsControl_lstStateProv');
		selbox.options.length = 0;
		for(var i = 0; i < objResponse.value.length; i++)
		{
			selbox.options[selbox.options.length] = new Option(objResponse.value[i].Val,objResponse.value[i].ID);						
		}
		selbox.selectedIndex = 0 ;
	}
}

//Function: MarkImpLead
//Description/Purpose: takes details of the lead which is to be marked important and calls
//Description/Purpose: ajax function. If operation is successfull then returns true otherwise false                         
//Arguments: image object, RFP id, News ID, event profile ID, date of publishing of the lead 
//Return values: boolean(true/false)
function MarkImpLead(Object,lRfpID,lNewID,lEventProfileID,lDatePublish)
{	
	if(lNewID == '')
		lNewID = 0;
	
	var lStatus = '';	
	var important= '/images/important.gif';
	var notimportant= '/images/notimportant.gif';
	Object.src.match(important)  ? lStatus = false : lStatus = true ;
	
	objResponse = TrueLeadProfiles.AjaxMakeLeadImportant(lRfpID,lNewID,lEventProfileID,lDatePublish,lStatus);
	
	if(objResponse.value == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}		

//Function: MarkReadLead
//Description/Purpose: takes details of the lead which is to be marked as read and calls
//Description/Purpose: ajax function. If operation is successfull then returns true otherwise false                           
//Arguments: image object, RFP id, News ID, event profile ID, date of publishing of the lead
//Return values: none
function MarkReadLead(Object,lRfpID,lNewID,lEventProfileID,lDatePublish)
{	
	var lStatus = '';
	
	if(lNewID == '')
		lNewID = 0;
	
	var ElementID = document.getElementById(Object);

	var read= '/images/read.gif';
	var unread= '/images/unread.gif';
	ElementID.src.match(read)  ? lStatus = false : lStatus = true ;

	objResponse = TrueLeadProfiles.AjaxMakeLeadRead(lRfpID,lNewID,lEventProfileID,lDatePublish,lStatus);
	if(objResponse.value == true)
	{
		//var object = document.getElementById(Object);
		flagRead(ElementID) ;				
	}
	
}

///either check imp lead or read it
//Function: MarkOnlyReadLead
//Description/Purpose: takes details of the lead which is to be marked as read and calls
//Description/Purpose: ajax function. do not returns anything.                          
//Arguments: image object, RFP id, News ID, event profile ID, date of publishing of the lead
//Return values: none
function MarkOnlyReadLead(Object,lRfpID,lNewID,lEventProfileID,lDatePublish)
{			
	var ElementID = document.getElementById(Object);
	var read= '/images/read.gif';
	var unread= '/images/unread.gif';
	ElementID.src.match(read)  ? lStatus = false : lStatus = true ;
	
	if(lStatus == false)
	{
	}
	else
		MarkReadLead(Object,lRfpID,lNewID,lEventProfileID,lDatePublish)
			
}

//Function: OnDateRangeChanged
//Description/Purpose: Common function taking IDs of date related controls on search page
//Description/Purpose: if the date range option "Custom" is selected then it will show from/to controls
//Description/Purpose: otherwise will make invisible                         
//Arguments: Control IDs of Date Range drop down, From textbox, To textbox, From label, To label, From calendar control, To calendar control
//Return values: none
function OnDateRangeChanged(pDateRangeID , pTxtFromID , pTxtToID , pLblFromID , pLblToID , pFromCalID , pToCalID)
{
	var lDateRangeControl = document.getElementById(pDateRangeID);
	var lFromDateControl = document.getElementById(pTxtFromID);
	var lToDateControl = document.getElementById(pTxtToID);
	
	var lLblFromControl = document.getElementById(pLblFromID);
	var lLblToControl = document.getElementById(pLblToID);
	var lFromCalControl = document.getElementById(pFromCalID);
	var lToCalControl = document.getElementById(pToCalID);
	
	var lFromToDateRow = document.getElementById('FindEventsControl_tblFromToDateRow');
	
	if(lDateRangeControl!=null)
	{
		if(lDateRangeControl.selectedIndex != 5)
		{
			lFromDateControl.value = "";
			lToDateControl.value = "";
		}
	
		if(lDateRangeControl.selectedIndex != 5) 
		{
			if(lFromToDateRow!=null)
			{
				lFromToDateRow.style.display = 'none';
			}
			
			lFromDateControl.style.visibility = 'hidden';
			lToDateControl.style.visibility = 'hidden';
			lLblFromControl.style.visibility = 'hidden';
			lLblToControl.style.visibility = 'hidden';
			lFromCalControl.style.visibility = 'hidden';
			lToCalControl.style.visibility = 'hidden';
			
		}
		else
		{
			if(lFromToDateRow!=null)
			{
				lFromToDateRow.style.display = 'inline';
			}
			
			lFromDateControl.style.visibility = 'visible';
			lToDateControl.style.visibility = 'visible';
			lLblFromControl.style.visibility = 'visible';
			lLblToControl.style.visibility = 'visible';
			lFromCalControl.style.visibility = 'visible';
			lToCalControl.style.visibility = 'visible';
			
		}
	}
	
}

//Function: ColumnHide
//Description/Purpose: hides given column(s) from given gird control on page
//Arguments: Grid control ID, string containing column names to hide
//Return values: none
function ColumnHide(pGridName,pStrColumns)
{
	if(document.getElementById('tdSummary') == null) 
		return;
		
	if(document.getElementById(pGridName) == null  )
	{
		document.getElementById('tdSummary').style.display = "none";
		return;
	}

	var lArrColumns;
	var lShowHide;
	if(document.getElementById('LblNoResults') != null)
	{
		document.getElementById('tdSummary').style.display = "none";
		return;
	}
	lShowHide = document.getElementById('hdnSummaryDetailsStatus').value;
	lArrColumns = pStrColumns.split(",");
	
	document.getElementById('tdSummary').style.display = "block";
	if(lShowHide == "" || lShowHide == "Details" )
	{
		
		for(var i=0; i<document.getElementById(pGridName).rows.length; i++)
		{
			
			for(var j = 0 ; j < lArrColumns.length ;j++)
			{
				document.getElementById(pGridName).rows[i].cells[lArrColumns[j]].style.display = "none"	
			}
		}
		document.getElementById('hpLinkShowDet').innerHTML = "Show Detailed Results";
		document.getElementById('hdnSummaryDetailsStatus').value = "Summary";
	
	}
	else
	{
		for(var i=0; i<document.getElementById(pGridName).rows.length; i++)
		{

			for(var j = 0 ; j < lArrColumns.length  ;j++)
			{
				document.getElementById(pGridName).rows[i].cells[lArrColumns[j]].style.display = "block"	
			}
		}
		document.getElementById('hpLinkShowDet').innerHTML = "Show Summary Results";
		document.getElementById('hdnSummaryDetailsStatus').value = "Details";
		
	}
	
}


//Function: ColumnHideAjax
//Description/Purpose: hides given column(s) from given gird control on page and sets session value
//Description/Purpose: for the status of the columns                         
//Arguments: Grid control ID, sting containing column names to hide
//Return values: none
function ColumnHideAjax(pGridName,pStrColumns)
{
	ColumnHide(pGridName,pStrColumns)
	SetSummarySessionValue(document.getElementById('hdnSummaryDetailsStatus').value);
	window.location = '#__datagrid_bkmark';
}


//Function: OpenTaxonomy
//Description/Purpose: opens the given document in a new pop-up window
//Description/Purpose: mostly used for Taxonomy diagram                         
//Arguments: URL as string
//Return values: none
function OpenTaxonomy(theURL) 
{ 
	window.open(theURL,'Taxonomy','resizable=yes,width=920,height=600, Left=52, Top=84');
}

//Function: ShowSmartNewsOldMsg
//Description/Purpose: Added for TA 4.2.5. If SalesTrigger is selected as "SmartNews" and some date range
//Description/Purpose: is entered then shows message that "News will be shown for last 6 months"                        
//Arguments: IDs of daterange drop down, From date textbox, To date textbox, Trigger type control, Message label
//Return values: none
function ShowSmartNewsOldMsg(dateRangeID, fromDateID, toDateID, lstEventTypeID, lblSmartOldMsgID)
{
	  
	  if ((dateRangeID != null) && (fromDateID != null) && (toDateID != null) && (lstEventTypeID != null) && (lblSmartOldMsgID != null))
	   {    		
						
			var dateRangeControl = document.getElementById(dateRangeID);
			var lstrDateFromControl = document.getElementById(fromDateID);
			var lstrDateToControl = document.getElementById(toDateID);
			var lstEventTypeControl = document.getElementById(lstEventTypeID);
			var lblSmartOldMsgIDControl = document.getElementById(lblSmartOldMsgID);
			
			if((dateRangeControl != null) && (lstrDateFromControl != null) && (lstrDateToControl != null) && (lstEventTypeControl != null) && (lblSmartOldMsgIDControl != null))
			{
				var lstrDateFrom = lstrDateFromControl.value;
				var lstrDateTo = lstrDateToControl.value;		
				
				if((dateRangeControl.selectedIndex == 0) && CheckSelection(lstEventTypeID))
				{	
					document.getElementById(lblSmartOldMsgID).style.visibility = 'visible';				   			   
				}			
				else if(CheckDateRange(lstrDateFrom, lstrDateTo) && CheckSelection(lstEventTypeID))
					{
						if(lstrDateFrom != "")
						{
							var fromdate = Date.parse(lstrDateFrom);
							var todaysDate = Date.parse(getTodaysDate());
							var daysdiff = ((todaysDate - fromdate)/(24*60*60*1000));
				            
							if ((daysdiff > 182)) //182 days equivalent to 26 weeks which is 6 months
							{
							document.getElementById(lblSmartOldMsgID).style.visibility = 'visible';		            
							}
							else
							{
							document.getElementById(lblSmartOldMsgID).style.visibility = 'hidden';			        
							}
						}	
						else if(lstrDateFrom == "")		      
						{
							document.getElementById(lblSmartOldMsgID).style.visibility = 'visible';
						}
						else
						{
							document.getElementById(lblSmartOldMsgID).style.visibility = 'hidden';
						}
				}
				else
				{
				document.getElementById(lblSmartOldMsgID).style.visibility = 'hidden';			   
				}	
			}		
			
	   } 
}

//Function: CheckSelection
//Description/Purpose: Takes TriggerType control ID and checks if SmartNews is selected. 
//Description/Purpose: Returns true if SmartNews is selected otherwise false                         
//Arguments: Trigger type control ID
//Return values: Boolean(true/false)
function CheckSelection(lstEventTypeID)
{
    var lstEventTypeControl = document.getElementById(lstEventTypeID);		   
	
	for(var i = 0; i < lstEventTypeControl.options.length; i++)
	{
		if(lstEventTypeControl.options[i].selected)
		{
		    if(lstEventTypeControl.options[i].value == "ALL")
		    {
		       for(var j = 0; j < lstEventTypeControl.options.length; j++)
	              {
	                 if(lstEventTypeControl.options[j].value == "1139")	  
	                  {	                    
	                     return true;
	                  }
	                  else if(j == lstEventTypeControl.options.length -1)
	                  {
	                    return false;
	                  }                      	                
	              }	
	            return false;   	       	       		       
		     }
		    else if(lstEventTypeControl.options[i].value == "1139")
		         {
		            return true;
		         }
		  			  
		}	    
	}	
   return false;
   
}

//Function: CheckDateRange
//Description/Purpose: Validates if selected/entered date range is valid or not
//Description/Purpose: returns true if date range is valid otherwise false                         
//Arguments: string containing from date, string containing to date
//Return values: Boolean(true/false)
function CheckDateRange(lstrDateFrom, lstrDateTo)
{   
  if((lstrDateFrom == "") && (lstrDateTo == ""))
  {
     return false;
  }
  
  if((lstrDateFrom != "") && (lstrDateTo == ""))
  {
      var todate = Date.parse(lstrDateFrom);
	  var todaysDate = Date.parse(getTodaysDate());
	  datediff = ((todaysDate-todate)/(24*60*60*1000));

	  if(datediff < 0)
	   {
		  alert("From field value should not be in the future.");		
		  return false;
	    }
        
  }
  
  if((lstrDateFrom != "") && (lstrDateTo != ""))
	{
		if(ValidateDateRange(lstrDateFrom,lstrDateTo) != true)
		{
			alert("From field value should not be greater than To field.");					
			return false;
		}
	}
			
	var todate = Date.parse(lstrDateTo);
	var todaysDate = Date.parse(getTodaysDate());
	datediff = ((todaysDate-todate)/(24*60*60*1000));

	if(datediff < 0)
	{
		alert("To field value should not be in the future.");		
		return false;
	}
	
	if((lstrDateFrom == "") && (lstrDateTo != ""))
    {     		
		return true;       
    }
	
	
	return true;
}

//Function: CallFunctionForSmartNewsOld
//Description/Purpose: Checks the instance of search page that means TLP or STP and calls
//Description/Purpose: function to show SmartNews message passing respective control IDs                         
//Arguments: none
//Return values: none
function CallFunctionForSmartNewsOld()
{
   var myUrl = new String(window.location);  
   
   if(myUrl.toUpperCase().indexOf("TRUELEADPROFILES.ASPX", 0) > -1)
   {      
      ShowSmartNewsOldMsg('cboDate', 'txtDateFrom', 'txtDateTo', 'FindEventsControl_lstEventType', 'lblSmartNewsOldMsg');     
   }
   else if((myUrl.toUpperCase().indexOf("TRUELEADPROSPECTING.ASPX", 0)) > -1)
   {     
     ShowSmartNewsOldMsg('FindEventsControl_cboDateRange','FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo', 'FindEventsControl_lstEventType', 'FindEventsControl_lblSmartNewsOldMsg');
   }
}