//Function: ValidateFromToDate
//Description/Purpose: To validate the From/To date selection 
//Arguments: 1. string - From date textbox ID  2. string - To date textbox ID  3. string - Date range dropdown ID  4. string - From date label ID  5. string - To date label ID
//Return values: bool - true/false  
function ValidateFromToDate(fromDateControlId,toDateControlId,dateRangeControlId,fromDateLabelId,toDateLabelId)
{
     var dayDifferenceToCompare = 4018; //(365  * 11 years) + (2 days for leap year)
     var dayDifferenceText = "11 Years";
     fromDateControl = document.getElementById(fromDateControlId);
	 toDateControl = document.getElementById(toDateControlId);
	 dateRangeControl = document.getElementById(dateRangeControlId);
	 fromDateLabel = document.getElementById(fromDateLabelId);
	 toDateLabel = document.getElementById(toDateLabelId);
	 
	 if((fromDateControl!=null) && (toDateControl!=null) && (dateRangeControl!=null))
	 {
			lstrDate=dateRangeControl.value;
			lstrDateFrom=fromDateControl.value;
			lstrDateTo=toDateControl.value;
			 
			if(lstrDate=="-1" && lstrDateFrom=="" && lstrDateTo=="")
			{
				alert("Please select either Date range or enter Date From/To values");
				try{ fromDateControl.focus(); }
				catch(e) { }					
				return false;
			}		 
		
			if(lstrDate=="-1" && lstrDateFrom!="" && lstrDateTo=="")
			{
				var now = GetBostonDate();
				lstrDateTo = ""+LZ(now.getMonth()+1)+ "/" + LZ(now.getDate())+ "/" + now.getFullYear();
				toDateControl.value = lstrDateTo;
			}
			 
			if((lstrDate!="-1" ) && ((lstrDateFrom!="") || (lstrDateTo != "")))
			{
				alert("The From and To values cannot be combined with the Date Range selections");
				try{ fromDateControl.focus(); }
				catch(e) { }				
				return false;
			}
			 
			if(lstrDateFrom!="")
			{
				if(ValidateDate(lstrDateFrom)!=true)
				{
					alert("Invalid From Date entered. Please correct the errors and resubmit the form.");
					try{ fromDateControl.focus(); }
					catch(e) { }	
					fromDateLabel.style.color = 'red';
					return false;
				}
				
				var fromdate=Date.parse(lstrDateFrom);
				var todaysDate=Date.parse(getTodaysDate());
				datediff=((todaysDate-fromdate)/(24*60*60*1000));

				if(datediff>dayDifferenceToCompare)
				{
					alert("Please select a date range within the last " + dayDifferenceText + ", your date is currently outside this range.");
					try{ fromDateControl.focus(); }
					catch(e) { }	
					fromDateLabel.style.color = 'red';
					return false;
				}
			}
			
			if(lstrDateTo!="")
			{
				if(ValidateDate(lstrDateTo)!=true)
				{
					alert("Invalid To Date entered. Please correct the errors and resubmit the form.");
					try{ toDateControl.focus(); }
					catch(e) { }	
					toDateLabel.style.color = 'red';
					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.");
					try{ toDateControl.focus(); }
					catch(e) { }	
					toDateLabel.style.color = 'red';
					return false;
				}
				
				if(datediff>dayDifferenceToCompare)
				{
					alert("Please select a date range within the last " + dayDifferenceText + ", your date is currently outside this range.");
					try{ toDateControl.focus(); }
					catch(e) { }	
					toDateLabel.style.color = 'red';
					return false;
				}
			}
			
			if((lstrDateFrom!="") && (lstrDateTo!=""))
			{
				if(ValidateDateRange(lstrDateFrom,lstrDateTo)!=true)
				{
					alert("From field value should not be greater than To field.");
					try{ toDateControl.focus(); }
					catch(e) { }	
					toDateLabel.style.color = 'red';
					return false;
				}
			}
	 }
	 return true; 
}
//Function: ValidateLocationSection
//Description/Purpose: To validate the Location section (ZIP code and Distance) 
//Arguments: 1. string - ZIP code textbox ID  2. string - ZIP code label ID  3. string - Distance textbox ID  4. string - Distance label ID  
//Return values: bool true/false   
function ValidateLocationSection(zipControlId,zipLabelId,distanceControlId,distanceLabelId)
{
	 zipControl=document.getElementById(zipControlId);
	 zipLabel=document.getElementById(zipLabelId);
	 distanceControl=document.getElementById(distanceControlId);
	 distanceLabel=document.getElementById(distanceLabelId);
	 	 
	 if(zipControl != null)
	    lstrZip = zipControl.value;
	    
	 if(distanceControl!=null)   
	    lstrDistance = distanceControl.value;
	  
	 if(lstrZip!="")
		{
			if(lstrZip.indexOf(",")=="-1")
			{
				if(ValidateZipCode(lstrZip)!=true)
				{
					alert("Invalid ZIP Code entered. Please correct the errors and resubmit the form.");
					try{ zipControl.focus(); }
					catch(e) { }	
					zipLabel.style.color = 'red';
					return false;
				}
			}
			else
			{
				var lZipArray =lstrZip.split(",");
				for(i=0;i<lZipArray.length;i++)
				{
					if(ValidateZipCode(lZipArray[i]) != true)
					{
						alert("One or more invalid ZIP Code(s) entered.");
						try{ zipControl.focus(); }
						catch(e) { }	
						zipLabel.style.color = 'red';
						return false;
					}
				}
			}	
		}
		
		if((lstrDistance!="") && (lstrZip.indexOf(",")!="-1"))
		{
			alert("If more than one ZIP code is entered, distance can NOT be entered.");
			try{ distanceControl.focus(); }
			catch(e) { }	
			distanceLabel.style.color = 'red';
			return false;
		}
		
		if((lstrDistance!="") && (lstrZip==""))
		{
			alert("If distance is entered, a ZIP code must be entered.");
			try{ zipControl.focus(); }
			catch(e) { }	
			zipLabel.style.color = 'red';
			return false;
		}
		
		if(lstrDistance!="")
		{
			if(ValidateDistance(lstrDistance)!=true)
			{
				alert("Invalid distance entered. Please correct the errors and resubmit the form.");
				try{ distanceControl.focus(); }
				catch(e) { }	
				distanceLabel.style.color='red';
				return false;
			}
		}
		
		if((lstrZip!="") && (lstrDistance!=""))
		{
		 	if(lstrZip.indexOf("*")!="-1")
			{
				alert("Can not enter Distance value with given ZIP entry.");
				try{ distanceControl.focus(); }
				catch(e) { }	
				distanceLabel.style.color='red';
				return false;
			}
		}
	 return true; 
}
//Function: ValidateRevenueRange
//Description/Purpose: To validate the Revenue range selection  
//Arguments: 1. string - Revenue listbox ID  2. Revenue label ID  3. string - Revenue From textbox ID  4. string - Revenue From label ID  5. string - Revenue To textbox ID  6. string - Revenue To label ID    
//Return values: bool - true/false  
function ValidateRevenueRange(revenueControlId,revenueLabelId,revenuefromControlId,revenuefromLabelId,revenueToControlId,revenueToLabelId)
{
	 revenue=document.getElementById(revenueControlId);
	 revenueLabel=document.getElementById(revenueLabelId);
	 revenuefrom=document.getElementById(revenuefromControlId);
	 revenuefromLabel=document.getElementById(revenuefromLabelId);
	 revenueTo=document.getElementById(revenueToControlId);
	 revenueToLabel=document.getElementById(revenueToLabelId);
	 
	 if(revenue != null) lstrRevenue=revenue.value;
	 if(revenuefrom != null) lstrRevenuefrom=revenuefrom.value;
	 if(revenueTo != null) lstrRevenueTo=revenueTo.value;
	  
	 if(lstrRevenue != "")
		{
			if((lstrRevenue != "xx" ) && ((lstrRevenuefrom != "") || (lstrRevenueTo != "")))
			{
				alert("The From and To values cannot be combined with the Revenue selections.");
				try{ revenuefrom.focus(); }
				catch(e) { }	
				revenuefromLabel.style.color='red';
				return false;
			}
		}	
		if(lstrRevenuefrom!="")
		{
			if(ValidateRevenue(lstrRevenuefrom)!=true)
			{
				alert("Invalid From Revenue entered. Please correct the errors and resubmit the form.");
				try{ revenuefrom.focus(); }
				catch(e) { }	
				revenuefromLabel.style.color='red';
				return false;
			}
			
			if(Number(RemoveSpecialCharacters(lstrRevenuefrom))<10000)
			{
				alert("Revenue can not be lesser than $10,000 ");
				try{ revenuefrom.focus(); }
				catch(e) { }	
				revenuefromLabel.style.color = 'red';
				return false;
			}
		}
		
		if(lstrRevenueTo!="")
		{
			if(Number(lstrRevenueTo) == 0)
			{
				alert("Invalid To Revenue entered. Please correct the errors and resubmit the form.");
				try{ revenueTo.focus(); }
				catch(e) { }	
				revenueToLabel.style.color='red';
				return false;
			}
		
			if(ValidateRevenue(lstrRevenueTo) != true)
			{
				alert("Invalid To Revenue entered. Please correct the errors and resubmit the form.");
				try{ revenueTo.focus(); }
				catch(e) { }	
				revenueToLabel.style.color='red';
				return false;
			}
			
			if(Number(RemoveSpecialCharacters(lstrRevenueTo)) < 10000 )
			{
				alert("Revenue can not be lesser than $10,000");
				try{ revenueTo.focus(); }
				catch(e) { }	
				revenueToLabel.style.color='red';
				return false;
			}
			
			
		}
		
		if((lstrRevenuefrom!="") && (lstrRevenueTo!=""))
		{
			if((Number(RemoveSpecialCharacters(lstrRevenueTo)) - Number(RemoveSpecialCharacters(lstrRevenuefrom))) < 0 )
			{
				alert("From field value should not be greater than To field.");
				try{ revenuefrom.focus(); }
				catch(e) { }	
				revenuefromLabel.style.color='red';
				return false;
			}
		}	
	 
	 return true; 
}
//Function: ValidateEmployeeNumberRange
//Description/Purpose: To validate the Employee range selection  
//Arguments: 1. string - Employee listbox ID  2. string - Employee label ID  3. string - Employee From textbox ID  4. string - Employee From label ID  5. string - Employee To textbox ID  6. string - Employee To label ID  
//Return values: bool - true/false  
function ValidateEmployeeNumberRange(empControlId,empLabelId,empfromControlId,empfromLabelId,empToControlId,empToLabelId)
{
	 emp=document.getElementById(empControlId);
	 empLabel=document.getElementById(empLabelId);
	 empfrom=document.getElementById(empfromControlId);
	 empfromLabel=document.getElementById(empfromLabelId);
	 empTo=document.getElementById(empToControlId);
	 empToLabel=document.getElementById(empToLabelId);
	  
	 if(emp != null) lstrEmployee=emp.value;
	 if(empfrom != null) lstrEmployeeFrm=empfrom.value;
	 if(empTo != null) lstrEmployeeTo=empTo.value;
	  
	 if(lstrEmployee!="")
		{
			if((lstrEmployee!="" ) && ((lstrEmployeeFrm!="") || (lstrEmployeeTo!="")))
			{
				alert("The From and To values cannot be combined with the Employee Number selections.");
				try
				{ empfrom.focus(); }
				catch(e) { }
				empfromLabel.style.color='red';
				return false;
			}
		}	
		
		
		if(lstrEmployeeFrm!="")
		{
			if(Number(lstrEmployeeFrm)==0)
			{
				alert("Invalid From Employee number entered. Please correct the errors and resubmit the form.");
				try
				{  empfrom.focus(); }
				catch(e) { }
				empfromLabel.style.color='red';
				return false;
			}
			
			if(ValidateNumberOfEmployee(lstrEmployeeFrm)!=true)
			{
				alert("Invalid From Employee number entered. Please correct the errors and resubmit the form.");
				try
				{ empfrom.focus(); }
				catch(e) { }
				empfromLabel.style.color='red';
				return false;
			}
		}
		
		if(lstrEmployeeTo!="")
		{
			if(Number(lstrEmployeeTo)==0)
			{
				alert("Invalid To Employee number entered. Please correct the errors and resubmit the form.");
				try
				{  empTo.focus(); }
				catch(e) { }
				empToLabel.style.color='red';
				return false;
			}
			
			if(ValidateNumberOfEmployee(lstrEmployeeTo)!=true)
			{
				alert("Invalid To Employee number entered. Please correct the errors and resubmit the form.");
				try
				{  empTo.focus(); }
				catch(e) { }
				empToLabel.style.color='red';
				return false;
			}
		}
		
		if((lstrEmployeeFrm!="") && (lstrEmployeeTo!=""))
		{
			if((Number(RemoveSpecialCharacters(lstrEmployeeTo)) - Number(RemoveSpecialCharacters(lstrEmployeeFrm))) < 0 )
			{
				alert("From field value should not be greater than To field.");
				try
				{  empfrom.focus(); }
				catch(e) { }
				empfromLabel.style.color='red';
				return false;
			}
		}	
	 
	 return true; 
}
//Function: ValidateLocation
//Description/Purpose: To validate the Location Section controls  
//Arguments: 1. string - ZIP code textbox ID  2. string - Distance textbox ID  3. string - City textbox ID  4. string - State listbox ID  5. string - Country dropdown ID  6. string - Area code textbox ID 
//Return values: None
function ValidateLocation(zipControlId,distanceControlId,cityControlId,stateControlId,countryControlId,areaControlId)
{
	 zipControl=document.getElementById(zipControlId);
	 distanceControl=document.getElementById(distanceControlId);
	 cityControl=document.getElementById(cityControlId);
	 countryControl=document.getElementById(countryControlId);
	 areaControl=document.getElementById(areaControlId);
	 stateControl=document.getElementById(stateControlId);
	
	if((zipControl.value != "" || distanceControl.value != "" || areaControl.value != "") &&(cityControl.value != "" || countryControl.value != "0" || (stateControl.value != "" && stateControl.value != "0")))
	{
		alert('Selecting multiple location attributes may result in invalid or no results found.  For example avoid searching State and ZIP code together');
	}
}