
var DateSelectionPossible = true;
var ldoc = document.getElementById;
//Function: fromDateClicked
//Description/Purpose:To Hide combo/list box control if the calendar is overlapping these controls
//Arguments:None
//Return values:Bool 
function fromDateClicked()
{
    var  strControlsToHide = "";
    	if(DateSelectionPossible)
	{ 
		strControlsToHide = 'FindEventsControl_cboS8Fillings';
		if((ldoc('FindEventsControl_cboCoAssociation') != null) && (ldoc('FindEventsControl_cboCoAssociation').style.visibility == 'visible')) 
		{ 
			strControlsToHide = strControlsToHide + ',FindEventsControl_cboCoAssociation';
		}
		var maxItemLength = 0 ;
		var lItemLength = ldoc('FindEventsControl_lstSubCategory').options.length;
		for(i=0; i < lItemLength ; i++ )
		{
			maxItemLength = ldoc('FindEventsControl_lstSubCategory').options[i].text.length;
			
		    if(maxItemLength > 70)
		       break;
		}	
		calendar.select(ldoc('FindEventsControl_txtDateFrom'),'anchor2','MM/dd/yyyy',strControlsToHide,'fromDateChanged'); 		
	} 
	return false;
}
//Function: fromDateChanged
//Description/Purpose:To Show the news message if date is above 6 months old
//Arguments:None
//Return values:None 
function fromDateChanged()
{
	if(ldoc('FindEventsControl_txtDateFrom').value != "")
     		ldoc('FindEventsControl_cboDateRange').selectedIndex = 5 ;
     
     ShowSmartNewsOldMsg('FindEventsControl_cboDateRange','FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo', 'FindEventsControl_lstEventType', 'FindEventsControl_lblSmartNewsOldMsg');     
   
}
//Function: toDateChanged
//Description/Purpose:To Show the news message if date is above 6 months old
//Arguments:None
//Return values:None 
function toDateChanged()
{

     if(ldoc('FindEventsControl_txtDateTo').value != "")
     		ldoc('FindEventsControl_cboDateRange').selectedIndex = 5 ;
       
   //TA 4.2.5 *CommentedOut*
   	ShowSmartNewsOldMsg('FindEventsControl_cboDateRange','FindEventsControl_txtDateFrom','FindEventsControl_txtDateTo', 'FindEventsControl_lstEventType', 'FindEventsControl_lblSmartNewsOldMsg');     
}
//Function: Profiles_fromDateChanged
//Description/Purpose:To Show the news message if date is above 6 months old on profiles
//Arguments:None
//Return values:None 
function Profiles_fromDateChanged()
{
     if(ldoc('txtDateFrom').value != "")
     		ldoc('cboDate').selectedIndex = 5 ;
 
   ShowSmartNewsOldMsg('cboDate', 'txtDateFrom', 'txtDateTo', 'FindEventsControl_lstEventType', 'lblSmartNewsOldMsg');     
   
}
//Function: Profiles_toDateChanged
//Description/Purpose:To Show the news message if date is above 6 months old on profiles
//Arguments:None
//Return values:None 
function Profiles_toDateChanged()
{
    if(ldoc('txtDateTo').value != "")
     		ldoc('cboDate').selectedIndex = 5 ;
     
   ShowSmartNewsOldMsg('cboDate', 'txtDateFrom', 'txtDateTo', 'FindEventsControl_lstEventType', 'lblSmartNewsOldMsg');    
}

//Function: onDateRangeSelect
//Description/Purpose:To Show the from and to date when customs is selected
//Arguments:ComboBox,Anchor Link
//Return values:None 
function onDateRangeSelect(cbodateRange,anchorLnk)
{
	var txtDateRange = cbodateRange;
	var calAnchor1 = anchorLnk ;
	
	if((txtDateRange.value == "-1") || (txtDateRange.value == '0'))
		calAnchor1.style.cursor = "hand";
	else
		calAnchor1.style.cursor = "default";
}	


//Function: todateClicked
//Description/Purpose:To show the combo when date is selected and the calendar is hidden
//Arguments:ComboBox,None
//Return values:None 
function todateClicked()
{
	if(DateSelectionPossible)
		calendar.select(ldoc('FindEventsControl_txtDateTo'),'anchor3','MM/dd/yyyy','FindEventsControl_cboS8Fillings','toDateChanged');
		
	return false;
}

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); 
	} 
} 


//AJAX 
//===========================================================================================

//Function: FillStates
//Description/Purpose:To call Ajax Function to get all the states whithin the country selected
//Arguments:ComboBox,None
//Return values:None 
function FillStates()
{ 	
	var lstrCountry;
	lstrCountry = ldoc('FindEventsControl_cboCountry').value;
	ldoc('FindEventsControl_hidState').value = '';	
	if(lstrCountry != "")
		ldoc('FindEventsControl_selectedCountryValue').value = lstrCountry;
	else
		ldoc('FindEventsControl_selectedCountryValue').value = '';
	
	FindEventsCriteria.AjaxGetStates(lstrCountry ,FillStatesEvent_CallBack);
}
//Function: FillStatesEvent_CallBack
//Description/Purpose:To fill the states in the state combo depending upon the response
//Arguments:Ajax Response 
//Return values:None 
//Call Back Function for States
function FillStatesEvent_CallBack(objResponse)
{
	if(objResponse.value != null)
	{
		var selbox=ldoc('FindEventsControl_lstStateProv');
		selbox.options.length = 0;
		var lLength = objResponse.value.length;
		for(var i = 0; i < lLength; i++)
		{
			selbox.options[selbox.options.length] = new Option(objResponse.value[i].Val,objResponse.value[i].ID);						
		}
		selbox.selectedIndex = 0 ;
	}
}

//Function: sortItem
//Description/Purpose:script for sorting items in the list
//Arguments:target list control
//Return values:none 
function sortItem(box)
{
	var arrbox = new Array();
	var arrLookup = new Array();
	var i;
	var lLength = box.options.length;
	for (i = 0; i < lLength; i++) 
	{
		arrLookup[box.options[i].text] = box.options[i].value;
		arrbox[i] = box.options[i].text;
	}
 	arrbox.sort();
	box.length = 0;
	var lLengthArr = arrbox.length;
	var c;
	for(c = 0; c < lLengthArr; c++) 
	{
		var no = new Option();
		no.value = arrLookup[arrbox[c]];
		no.text = arrbox[c];
		box[c] = no;
   }
}

//Function: FillCategories
//Description/Purpose:To call Ajax Function to get all the categories whith in the Trigger Selected
//Arguments:None 
//Return values:None 

function FillCategories()
{
	var lstrEvent;
	var selboxEvent ;
	selboxEvent = ldoc('FindEventsControl_lstEventType');
	
	if(CheckAllSelected(selboxEvent , 'FindEventsControl_lstEventType'))
		return;
	ldoc('FindEventsControl_hdnCboAsc').value = "";
		

	var lStrEventType = "";
	
	var selbox1 = ldoc('FindEventsControl_lstEventType');
	lLength = selbox1.options.length;
	for(var i = 0; i < lLength; i++)
	{		
		if(selbox1.options[i].selected)
			lStrEventType = lStrEventType +  "," + selbox1.options[i].value ;			
	}
	
	if(lStrEventType != "")
	{
		ldoc('FindEventsControl_hidEventtype').value = lStrEventType.substring(1);
		
	}
	else
	{
		ldoc('FindEventsControl_hidEventtype').value = '';
	}
	///on change store the value in hidden field	
	 	
	lstrEvent = ldoc('FindEventsControl_lstEventType').value;
	var selbox=ldoc('FindEventsControl_lstSubCategory');
	ldoc('FindEventsControl_hidCategory').value = "";
	ldoc('FindEventsControl_hidSubCategory').value = "";
	selbox.options.length = 0;
	
	ControlsEnableEvent();
	if(ldoc('FindEventsControl_cboCoAssociation') != null)
	{
		ldoc('FindEventsControl_lblCoAssociation').style.visibility = 'hidden';
		ldoc('FindEventsControl_cboCoAssociation').style.visibility = 'hidden';
		ldoc('FindEventsControl_lblComAssMsg').style.visibility = 'hidden';
	}
	//Code to disable and clear category DropDown when more than one EventType is selected
	var lItemCount;
	lItemCount= 0;
	var lLengthSel = selboxEvent.options.length;
	for(var i = 0; i < lLengthSel; i++)
	{
			if(selboxEvent.options[i].selected)
				lItemCount++;
			
			if(lItemCount > 1)
			{
				MultipleSI();
				
				if(ldoc('hdnManualTerritory') != null)
				{
	  				if(ldoc('hdnManualTerritory').value == 'Y')
						DisableAllControl(true);
					   
				}
				//Fixed for bug#4179
				if(ldoc('FindEventsControl_radCompanyTracker') != null)
					ldoc('FindEventsControl_radCompanyTracker').disabled = false;
				if(ldoc('FindEventsControl_radTerritory') != null)
					ldoc('FindEventsControl_radTerritory').disabled = false;
				return;
			}
	}
	
	//=====================================
	
	if(lstrEvent == "1139")
	{
		ldoc('FindEventsControl_hdnCboAsc').value = "0";
		NewsEvent();
	}
	else if(lstrEvent == "SO")
	{		
		ControlsDisable();		
	}
	ldoc('FindEventsControl_hidCategory').value = "0";	
	FindEventsCriteria.AjaxGetCategories(lstrEvent ,FillCategories_CallBack);
	
	if(ldoc('hdnManualTerritory') != null)
	{
	  	if(ldoc('hdnManualTerritory').value == 'Y')
			DisableAllControl(true);
	}
	//Fixed for bug#4179
	if(ldoc('FindEventsControl_radCompanyTracker') != null)
		ldoc('FindEventsControl_radCompanyTracker').disabled = false;
	if(ldoc('FindEventsControl_radTerritory') != null)
		ldoc('FindEventsControl_radTerritory').disabled = false;
}

//Function: MultipleSI
//Description/Purpose:Set the cat,subcat default value and set the length
//Arguments:None 
//Return values:None 
function MultipleSI()
{
	ldoc('FindEventsControl_cboCategory').options.length = 0;
	ldoc('FindEventsControl_cboCategory').disabled = true;
	ldoc('FindEventsControl_lstSubCategory').options[0] = new Option("Not Applicable","Not Applicable");
	ldoc('FindEventsControl_cboCategory').style.width = "";
	ldoc('FindEventsControl_cboCategory').style.width = 150;
	ldoc('FindEventsControl_lstSubCategory').style.width = 150;
	ldoc('FindEventsControl_lstSubCategory').disabled = true;	
}

//Function: NewsEvent
//Description/Purpose:Set the visibility of the news related controls if news is selected as a trigger type
//Arguments:None 
//Return values:None 
function NewsEvent()
{
	if(ldoc('FindEventsControl_cboCoAssociation') != null)
	{
		ldoc('FindEventsControl_lblCoAssociation').style.visibility = 'visible';
		ldoc('FindEventsControl_cboCoAssociation').style.visibility = 'visible';
		ldoc('FindEventsControl_lblComAssMsg').style.visibility = 'visible';
		ldoc('FindEventsControl_cboCoAssociation').selectedIndex = 0 ;
	}
}
//Function: FillCategories_CallBack
//Description/Purpose:Call Back functions used to fill categories depending uopn the response
//Arguments:Ajax Response 
//Return values:None 
//Call Back Function for Categories
function FillCategories_CallBack(objResponse)
{
	var selbox=ldoc('FindEventsControl_cboCategory');
	selbox.options.length = 0;
	ldoc('FindEventsControl_lstSubCategory').style.width = 150;
	ldoc('FindEventsControl_lstSubCategory').disabled = true;
	ldoc('FindEventsControl_lstSubCategory').options.length = 0;
	ldoc('FindEventsControl_lstSubCategory').options[0] = new Option("Not Applicable","Not Applicable");
	
	if(objResponse.value != null)
	{
		if(objResponse.value.length > 1)
		{
			selbox.style.width ="";
			var lLength = objResponse.value.length;
			for(var i = 0; i < lLength; i++)
			{
				selbox.options[selbox.options.length] = new Option(objResponse.value[i].Val,objResponse.value[i].ID);						
			}
			selbox.selectedIndex = 0 ; 	
		}
		else
		{
			selbox.style.width = 150;
			
		}
		selbox.disabled = false;
	}
	else
	{	
		selbox.style.width = 150;
		selbox.disabled = true;	
	}
}

//Function: FillSubCategories
//Description/Purpose:Calls Ajax function to bring all the sub-cats. depending upon the cat. selected
//Arguments:none 
//Return values:None 
//Call Back Function for Categories
function FillSubCategories()
{
	var lstrEvent;
	var lstrCategory;
	lstrEvent = ldoc('FindEventsControl_lstEventType').value;
	lstrCategory = ldoc('FindEventsControl_cboCategory').value;
	ldoc('FindEventsControl_hidSubCategory').value = "";
	
	if(lstrCategory != "0")
		ldoc('FindEventsControl_hidCategory').value = lstrCategory;
	
	else
		ldoc('FindEventsControl_hidCategory').value = "0";
		
		lstrCategory = lstrEvent + "#" + lstrCategory;
		ldoc('FindEventsControl_hidSubCategory').value = "0";
		FindEventsCriteria.AjaxGetSubCategories(lstrCategory ,FillSubCategories_CallBack);
}
//Function: FillSubCategories_CallBack
//Description/Purpose:Ajax call back fn. used to fill sub-cat. list depending upon the response
//Arguments:Ajax response 
//Return values:None 

function FillSubCategories_CallBack(objResponse)
{
	var selbox=ldoc('FindEventsControl_lstSubCategory');
	selbox.options.length = 0;
		
	if(objResponse.value != null)
	{
		if(objResponse.value.length > 1)
		{
			selbox.style.width ="";
			var lLength = objResponse.value.length;
			for(var i = 0; i < lLength; i++)
			{
				selbox.options[selbox.options.length] = new Option(objResponse.value[i].Val,objResponse.value[i].ID);						
			}
			selbox.selectedIndex = 0 ;
			selbox.disabled = false;
		}
		else
		{
			selbox.options[0] = new Option("Not Applicable","Not Applicable");	
			selbox.style.width = 150;
			selbox.disabled = true;	
		}
	}
	else
	{
		selbox.options[0] = new Option("Not Applicable","Not Applicable");
		selbox.style.width = 150;
		selbox.disabled = true;	
	}
}

//AJAX=============================================================================================================
//Function: NewsControlsDisable
//Description/Purpose:TO Disable enable controls depending upon the news association selected
//Arguments:None 
//Return values:None 
function NewsControlsDisable()
{
	var lstrResult;
	if(ldoc('FindEventsControl_cboCoAssociation') != null)
	{
		lstrResult = ldoc('FindEventsControl_cboCoAssociation').value;
		ldoc('FindEventsControl_hdnCboAsc').value = lstrResult;
		ldoc('FindEventsControl_lblComAssMsg').style.visibility = 'hidden';
	}
	
	ControlsEnableEvent();	
	if(lstrResult == 0)
	{
		if(ldoc('FindEventsControl_cboCoAssociation') != null)
			ldoc('FindEventsControl_lblComAssMsg').style.visibility = 'visible';
	}
	else if(lstrResult == 2)
	{
		ControlsDisable();
		ldoc('FindEventsControl_txtZip').disabled = true;
		ldoc('FindEventsControl_txtCity').disabled = true;
		ldoc('FindEventsControl_cboCountry').disabled = true;
		ldoc('FindEventsControl_lstStateProv').disabled = true;
		ldoc('FindEventsControl_txtDistance').disabled = true;
		ldoc('FindEventsControl_txtAreaCode').disabled = true;
		ldoc('FindEventsControl_navSIC').style.visibility = 'hidden';	
	}
	
	if(lstrResult == 2)
	{
		ldoc('FindEventsControl_radCompanyTracker').disabled = true;
		ldoc('FindEventsControl_radTerritory').disabled = true;
		ldoc("FindEventsControl_radNoTerritoryComp").checked = true;
		OnClickNoCompTerritory();
	}
	else
	{
		ldoc('FindEventsControl_radCompanyTracker').disabled = false;
		ldoc('FindEventsControl_radTerritory').disabled = false;
	}
}
//Function: ControlsDisable
//Description/Purpose:To Disable controls
//Arguments:None 
//Return values:None 
function ControlsDisable()
{
	ldoc('FindEventsControl_lstIndustry').disabled = true;
	ldoc('FindEventsControl_txtSIC').disabled = true;
	ldoc('FindEventsControl_lstRevenue').disabled = true;
	ldoc('FindEventsControl_txtRevenuefrom').disabled = true;
	ldoc('FindEventsControl_txtRevenueTo').disabled = true;
	ldoc('FindEventsControl_txtEmployeeFrm').disabled = true;
	ldoc('FindEventsControl_txtEmployeeTo').disabled = true;
	ldoc('FindEventsControl_lstEmployee').disabled = true;
	ldoc('FindEventsControl_navSIC').style.visibility = 'hidden';
}
//Function: ControlsEnableEvent
//Description/Purpose:To Enable controls
//Arguments:None 
//Return values:None 
function ControlsEnableEvent()
{
	ldoc('FindEventsControl_lstIndustry').disabled = false;
	ldoc('FindEventsControl_txtSIC').disabled = false;
	ldoc('FindEventsControl_lstRevenue').disabled = false;
	ldoc('FindEventsControl_txtRevenuefrom').disabled = false;
	ldoc('FindEventsControl_txtRevenueTo').disabled = false;
	ldoc('FindEventsControl_txtEmployeeFrm').disabled = false;
	ldoc('FindEventsControl_txtEmployeeTo').disabled = false;
	ldoc('FindEventsControl_lstEmployee').disabled = false;
	ldoc('FindEventsControl_txtZip').disabled = false;
	ldoc('FindEventsControl_txtCity').disabled = false;
	if(ldoc('FindEventsControl_cboCountry').options.length > 0)
		ldoc('FindEventsControl_cboCountry').disabled = false;
	ldoc('FindEventsControl_lstStateProv').disabled = false;
	ldoc('FindEventsControl_txtDistance').disabled = false;
	ldoc('FindEventsControl_txtAreaCode').disabled = false;
	ldoc('FindEventsControl_navSIC').disabled = false;
	ldoc('FindEventsControl_navSIC').style.visibility = 'visible';
	///this function written for truelead profile .js
	DisableControlAccordingHidden();
}
//Function: DisableControlAccordingHidden
//Description/Purpose:///this function required where control are enable & disable according to event change
///the control are always disable if value is set from profile
//Arguments:None 
//Return values:None

function DisableControlAccordingHidden()
{	
	var IsAllTerritory = false;
	if(ldoc('FindEventsControl_hdnAllTerritory').value != "" && ldoc('FindEventsControl_hdnAllTerritory').value == "0")
		IsAllTerritory = true;	
		
	if(ldoc('FindEventsControl_hdnSicText').value != '')
		ldoc('FindEventsControl_lstIndustry').disabled  = true;
	if(ldoc('FindEventsControl_hdnRevFrom').value != '' || ldoc('FindEventsControl_hdnRevTo').value != '')
		ldoc('FindEventsControl_lstRevenue').disabled  = true;		
	if(ldoc('FindEventsControl_hdnEmpFrom').value != '' || ldoc('FindEventsControl_hdnEmpTo').value != '')
		ldoc('FindEventsControl_lstEmployee').disabled  = true;
	if(ldoc('FindEventsControl_hdnCity').value != '')
		ldoc('FindEventsControl_txtCity').disabled = true;
	if(ldoc('FindEventsControl_hdnDistance').value != '')
	{	
		ldoc('FindEventsControl_txtZip').disabled = true;
		ldoc('FindEventsControl_txtDistance').disabled = true;
	}
}

//Function: OnSubCatChanged
//Description/Purpose:Function is used to set the hidden filed value for sub-cats
//Arguments:None 
//Return values:None
function OnSubCatChanged()
{
	var lstrSubCat = "";
	var selbox = ldoc('FindEventsControl_lstSubCategory');
	
	if(CheckAllSelected(selbox , 'FindEventsControl_lstSubCategory'))
		return;
	
	var lLength = selbox.options.length;
	for(var i = 0; i < lLength; i++)
	{
		if(selbox.options[i].selected)
			lstrSubCat = lstrSubCat +  "," + selbox.options[i].value 
	}
	if(lstrSubCat != "")
		ldoc('FindEventsControl_hidSubCategory').value = lstrSubCat.substring(1);
	else
		ldoc('FindEventsControl_hidSubCategory').value = '';
}
//Function: OnStateChanged
//Description/Purpose:Function is used to set the hidden filed value for states
//Arguments:None 
//Return values:None
function OnStateChanged()
{
	var lstrState = "";
	var selbox = ldoc('FindEventsControl_lstStateProv');
	

	if(CheckAllSelected(selbox , 'FindEventsControl_lstStateProv'))
		return;
	
	var lLength = selbox.options.length;
	for(var i = 0; i < lLength; i++)
	{
		
		if(selbox.options[i].selected)
			lstrState = lstrState +  "," + selbox.options[i].value 
	}
	if(lstrState != "")
		ldoc('FindEventsControl_hidState').value = lstrState.substring(1);
	else
		ldoc('FindEventsControl_hidState').value = '';
}

//Function: OnIndustryChange
//Description/Purpose:Function is used to set the hidden filed value for Business(industry)
//Arguments:None 
//Return values:None
function OnIndustryChange()
{
	if(CheckAllSelected(ldoc('FindEventsControl_lstIndustry') , 'FindEventsControl_lstIndustry'))
		return;
		
	var lstrIndustry = "";
	var selbox = ldoc('FindEventsControl_lstIndustry');	
	var lLength = selbox.options.length;	
	for(var i = 0; i < lLength; i++)
	{
		if(selbox.options[i].selected)
			lstrIndustry = lstrIndustry +  "," + selbox.options[i].value 
	}
	if(lstrIndustry != "")
		ldoc('FindEventsControl_selectedIndustryValue').value = lstrIndustry.substring(1);
	else
		ldoc('FindEventsControl_selectedIndustryValue').value = '';
}

//Function: OnRevenueChange
//Description/Purpose:Function is used to set the hidden filed value for revenue range
//Arguments:None 
//Return values:None
function OnRevenueChange()
{
	if(CheckAllSelected(ldoc('FindEventsControl_lstRevenue') , 'FindEventsControl_lstRevenue'))
		return;
		
	var lstrRevenue = "";
	var selbox = ldoc('FindEventsControl_lstRevenue');
	var lLength = selbox.options.length;
	for(var i = 0; i < lLength; i++)
	{
		
		if(selbox.options[i].selected)
			lstrRevenue = lstrRevenue +  "," + selbox.options[i].value 
	}
	if(lstrRevenue != "")
		ldoc('FindEventsControl_selectedRevValue').value = lstrRevenue.substring(1);
	else
		ldoc('FindEventsControl_selectedRevValue').value = '';
}

//Function: OnEmployeeChange
//Description/Purpose:Function is used to set the hidden filed value for employee range
//Arguments:None 
//Return values:None
function OnEmployeeChange()
{
	if(CheckAllSelected(ldoc('FindEventsControl_lstEmployee') , 'FindEventsControl_lstEmployee'))
		return;
	
	var lstrEmployee = "";
	var selbox = ldoc('FindEventsControl_lstEmployee');	
	var lLength = selbox.options.length;
	for(var i = 0; i < lLength; i++)
	{
		
		if(selbox.options[i].selected)
			lstrEmployee = lstrEmployee +  "," + selbox.options[i].value 
	}
	if(lstrEmployee != "")
		ldoc('FindEventsControl_selectedEmpValue').value = lstrEmployee.substring(1);
	else
		ldoc('FindEventsControl_selectedEmpValue').value = '';
}
//Function: OnTrackingTypeChanged
//Description/Purpose:Function is used to disable the company list box if the tracking type is selected
//Arguments:None 
//Return values:None
function OnTrackingTypeChanged()
{
	var selbox = ldoc('FindEventsControl_cboTrackingType');
	if(selbox.value != 0)
		ldoc('FindEventsControl_lstCompany').disabled = true;
	else
		ldoc('FindEventsControl_lstCompany').disabled = false;
}
//Function: OnCoTrackerChanged
//Description/Purpose:Function is used to disable the company tracker list box if the Companies are selected
//Arguments:None 
//Return values:None
function OnCoTrackerChanged()
{   
  	RestoteDetailsPanelState();
 
	var selbox = ldoc('FindEventsControl_lstCompany');
	var trackingType = ldoc('FindEventsControl_cboTrackingType');
	var strControl = 'FindEventsControl_lstCompany';
	
	if(selbox.options.length < 1)
		return;
	
	if(selbox.options.length > 1)
	{
		if(selbox.options[0].selected && CheckItemSelected(strControl,0))
		{
			alert('You can not select all option with other option, please use ctrl key to de-select when "All" and some other option is selected.');
			ldoc(strControl).selectedIndex = 0;
			return true;
		}
	}
	
	if(selbox.options[0].selected)
		trackingType.disabled = false;
	else
	   trackingType.disabled = true;
	
	if(selbox.options[0] != null)
	{
		if(selbox.options[0].selected)
		{
			if(trackingType.options.length == 1)
				trackingType.disabled = true;
			else
				trackingType.disabled = false;
		}
		else
		{
			trackingType.disabled = true;
		}
	}
    return false;
}

//Function: OnCityChanged
//Description/Purpose:Function is used to disable Zip,Dist,Country,State if city is entered and vise-versa
//Arguments:None 
//Return values:None
function OnCityChanged()
{
	if(ldoc('FindEventsControl_txtCity').value == "")
	{
		ldoc('FindEventsControl_txtZip').disabled = false;
	    ldoc('FindEventsControl_txtDistance').disabled = false;
	    ldoc('FindEventsControl_cboCountry').disabled = false;
	    ldoc('FindEventsControl_lstStateProv').disabled = false;
	}
	else
	{
	    ldoc('FindEventsControl_txtZip').disabled = true;
	    ldoc('FindEventsControl_txtDistance').disabled = true;
	    ldoc('FindEventsControl_cboCountry').disabled = true;
	    ldoc('FindEventsControl_lstStateProv').disabled = true;
	}
}
//Function: OnZipChanged
//Description/Purpose:Function is used to disable City,Dist,Country if zip is entered and vise-versa
//Arguments:None 
//Return values:None
function OnZipChanged()
{
	if(ldoc('FindEventsControl_txtZip').value == "")
	{
		ldoc('FindEventsControl_txtCity').disabled = false;
	    ldoc('FindEventsControl_cboCountry').disabled = false;
	    ldoc('FindEventsControl_lstStateProv').disabled = false;
	}
	else
	{
	    ldoc('FindEventsControl_txtCity').disabled = true;
	    ldoc('FindEventsControl_cboCountry').disabled = true;
	    ldoc('FindEventsControl_lstStateProv').disabled = true;
	}
}

//Function: CheckItemSelected
//Description/Purpose:Function is used check whether a given item is selected form a control
//Arguments:list id , itemindex 
//Return values:bool
function CheckItemSelected(lst_Id,itemIndex)
{	
	var limit = 0;
	var selbox = ldoc(lst_Id);
	var lLength = selbox.options.length;
	for(var i = 0; i < lLength; i++) 
	{	
		if((selbox.options[i].selected) && (i != itemIndex))
			return true;
	}
	return false;
}
//Function: CheckAllSelected
//Description/Purpose:Function to validate that "ALL" and any other item cannot be selected
//Arguments:listbox and value selected
//Return values:bool
function CheckAllSelected(selbox, strControl)
{
	if(selbox.options[0].selected && checkselected(strControl))
	{
		alert('You can not select all option with other option, please use ctrl key to de-select when "All" and some other option is selected.');
		ldoc(strControl).selectedIndex = 0;
		return true;
	}
	return false;
}


//Function: OnKeyEmpFromValidate
//Description/Purpose:Validate Emp From 
//Arguments: None
//Return values:Bool	
function OnKeyEmpFromValidate()
{
	var returnValue = true;
	returnValue = (ValidateNumber(8,'FindEventsControl_txtEmployeeFrm',true));
	return returnValue;
}

//Function: OnChangeEmpFromValidate
//Description/Purpose:Validate Emp From 
//Arguments: None
//Return values:Bool			
function OnChangeEmpFromValidate()
{
	ValidateNumber(8,'FindEventsControl_txtEmployeeFrm',false);
	return;
}

//Function: OnKeyEmpToValidate
//Description/Purpose:Validate Emp To 
//Arguments: None
//Return values:Bool	 
function OnKeyEmpToValidate()
{
	var returnValue = true;
	returnValue = (ValidateNumber(8,'FindEventsControl_txtEmployeeTo',true));
	return returnValue;
}

//Function: OnChangeEmpToValidate
//Description/Purpose:Validate Emp To 
//Arguments: None
//Return values:Bool		
function OnChangeEmpToValidate()
{
	ValidateNumber(8,'FindEventsControl_txtEmployeeTo',false);
	return;
} 

//Function: OnKeyRevFromValidate
//Description/Purpose:Validate rev From 
//Arguments: None
//Return values:Bool		
function OnKeyRevFromValidate()
{
	var returnValue = true;
	returnValue = (ValidateNumber(16,'FindEventsControl_txtRevenuefrom',true));
	return returnValue;
}
				
//Function: OnChangeRevFromValidate
//Description/Purpose:Validate rev From 
//Arguments: None
//Return values:Bool		
function OnChangeRevFromValidate()
{
	ValidateNumber(16,'FindEventsControl_txtRevenuefrom',false);
	return;
}

//Function: OnKeyRevToValidate
//Description/Purpose:Validate rev To 
//Arguments: None
//Return values:Bool		
function OnKeyRevToValidate()
{
	var returnValue = true;
	returnValue = (ValidateNumber(16,'FindEventsControl_txtRevenueTo',true));
	return returnValue;
}
				
//Function: OnKeyRevToValidate
//Description/Purpose:Validate rev To 
//Arguments: None
//Return values:Bool		
function OnChangeRevToValidate()
{
	ValidateNumber(16,'FindEventsControl_txtRevenueTo',false);
	return;
}
//Function: onLinkFocus
//Description/Purpose:To Change the cursor style when gets focus 
//Arguments: None
//Return values:None
function onLinkFocus()
{
	var lnkAnchor = ldoc('FindEventsControl_anchor2');
	if(!DateSelectionPossible)
		lnkAnchor.style.cursor = "auto";
}
/******display the errormsg for zipcode & sic***********/
//Function: onZipFocus
//Description/Purpose:display the errormsg for zipcode if its there in the territory
//Arguments: None
//Return values:None
function onZipFocus()
{
	if(ldoc('FindEventsControl_hdnZip').value == '')
		return;
		
	ldoc('FindEventsControl_txtZip').style.background='#FFFF99'; 
	ldoc('FindEventsControl_zipMsg').style.display='block';
	ldoc('FindEventsControl_zipMsg').innerHTML = "Zip code values used in your territory are not displayed, validation will occur if zip codes are entered.";	
}	

//Function: OnBlurZip
//Description/Purpose:remove the errormsg for zipcode if its there in the territory
//Arguments: None
//Return values:None
function OnBlurZip()
{
	if(ldoc('FindEventsControl_hdnZip').value == '')
		return;
		
	ldoc('FindEventsControl_txtZip').style.background=''; 
	ldoc('FindEventsControl_zipMsg').style.display='none';
}

//Function: onZipFocus
//Description/Purpose:display the errormsg for SIC code if its there in the territory
//Arguments: None
//Return values:None
function onSicFocus()
{
	if(ldoc('FindEventsControl_hdnSicText').value == '')
		return;
				
	ldoc('FindEventsControl_txtSIC').style.background='#FFFF99'; 
	ldoc('FindEventsControl_sicMsg').style.display='block';
	ldoc('FindEventsControl_sicMsg').innerHTML = "SIC code values used in your territory are not displayed, validation will occur if SIC codes are entered.";
}	

//Function: OnBlurZip
//Description/Purpose:remove the errormsg for SIC code if its there in the territory
//Arguments: None
//Return values:None
function OnBlurSic()
{
	if(ldoc('FindEventsControl_hdnSicText').value == '')
		return;
		
	ldoc('FindEventsControl_txtSIC').style.background=''; 
	ldoc('FindEventsControl_sicMsg').style.display='none';
}

//Function: ResetKeywordPopupFlag
//Description/Purpose:set value of hidden field kwyword popup to blank
//Arguments: None
//Return values:None
function ResetKeywordPopupFlag()
{
   if(ldoc('hdnKeywordPopuop') != null)
      ldoc('hdnKeywordPopuop').value = '';
}

