<!--

//################################################################################
//#	This include file calls function(s) from the following other include file(s)
//#			whitespace.js
//#
//################################################################################	

function validateForm(frm, strUrl, strValidateSearchName){
	var blnValid = true;
	if(strUrl.toLowerCase() == "fullsearch.aspx"){
		if(!validateCIKAndNameAndTicker(frm)){
			return false;
		}
		if(!validateNameLength(frm)){
			return false;
		}
		if(!validateFormGroupAndType(frm)){
			return false;
		}
		if(!validateDateFields(frm)){
			return false;
		}
		if(countShrtFrmCommonFieldsWithData(frm) == 0){
			blnValid = false;
		}		
	}
	
	else if(strUrl.toLowerCase() == "ftsearch.aspx"){
		if(!validateCIKAndNameAndTicker(frm)){
			return false;
		}
		if(!validateNameLength(frm)){
			return false;
		}
		if(!validateFormGroupAndType(frm)){
			return false;
		}
		if(!validateIndustryAndSector(frm)){
			return false;
		}
		if(!validateDateFields(frm)){
			return false;
		}
		if(countCommonFieldsWithData(frm) == 0){
			blnValid = false;
		}
	}

	if(!blnValid){
		alert('Please enter at least 1 search parameter.'); 
		if(frm.Name != null){
			frm.Name.focus(); 
		}
		return false; 
	}
	
	return true;
}


function validateCIKAndNameAndTicker(frm){
	var intFieldCount = 0;
	var strFields = "";
	
	if(frm.Name != null){
		if(!isAllSpaces(frm.Name.value)){ 
			intFieldCount++; 
			if(strFields == ""){ strFields = "a company name"; }
		}
		if(!isAllSpaces(frm.Ticker.value)){ 
			intFieldCount++; 
			if(strFields == ""){ strFields = "a symbol"; }
			else{ strFields += " and a symbol"; }
		}
		if(!isAllSpaces(frm.CIK.value)){ 
			intFieldCount++; 
			if(strFields == ""){ strFields = "a CIK"; }
			else{ strFields += " and a CIK"; }
		}
	}
	
	if(intFieldCount > 1){
		alert('You cannot enter ' + strFields + '.\nThe fields are mutually exclusive.');
		return false;
	}
	
	return true;
}


function validateNameAndTicker(frm){
	var intFieldCount = 0;
	
	if(frm.Name != null){
		if(!isAllSpaces(frm.Name.value)){ intFieldCount++; }
		if(!isAllSpaces(frm.Ticker.value)){ intFieldCount++; }
	}
	
	if(intFieldCount > 1){
		alert('You cannot enter both a company name and a symbol.\nThe fields are mutually exclusive.');
		return false;
	}
	
	return true;
}


function validateNameLength(frm){
	var MIN_CHARS = 3;
	var intNameLength = -1;

	if(frm.Name != null){
		if(!isAllSpaces(frm.Name.value)){ 
			frm.Name.value = trim(frm.Name.value);
			intNameLength = frm.Name.value.length;
		}
	}
	
	if(intNameLength != -1 && intNameLength < MIN_CHARS){
		alert('You must enter at least ' + MIN_CHARS + ' characters when searching by company name.\nIf less than ' + MIN_CHARS + ' characters are entered, the search will be too broad.');
		frm.Name.focus();
		return false;
	}
	
	return true;
}

function validateFormGroupAndType(frm){

	if(frm.FormGroupID[0].selectedIndex > 0 && frm.FormTypeID.selectedIndex > 0){
		alert('You cannot select both an act group and a form type.\nThe fields are mutually exclusive.');
		return false;
	}
	
	if(frm.FormGroupID[1].selectedIndex > 0 && frm.FormTypeID.selectedIndex > 0){
		alert('You cannot select both a form group and a form type.\nThe fields are mutually exclusive.');
		return false;
	}
	
	return true;
}


function validateIndustryAndSector(frm){
	if(frm.IndustryID.selectedIndex > 0 && frm.SectorID.selectedIndex > 0){
		alert('You cannot select both an industry and a sector.\nThe fields are mutually exclusive.');
		return false;
	}
	
	return true;
}


function validateDateFields(frm){
	var blnHasStartDate = (!isAllSpaces(frm.v_drs.value));
	var blnHasEndDate = (!isAllSpaces(frm.v_dre.value));
	var blnHasSpecificDate = (!isAllSpaces(frm.v_dss.value));
	var blnHasPredefinedDate = (!isAllSpaces(frm.v_drp.value));
	
	if(blnHasPredefinedDate && blnHasSpecificDate){
		alert('You cannot select a time frame and enter a specific date at the same time.\nThe fields are mutually exclusive.');
		return false;
	}
	
	if(blnHasPredefinedDate && (blnHasEndDate || blnHasStartDate)){
		alert('You cannot select a time frame and enter a date range at the same time.\nThe fields are mutually exclusive.');
		return false;
	}
	
	if(blnHasSpecificDate && (blnHasEndDate || blnHasStartDate)){
		alert('You cannot enter a specific date and a date range at the same time.\nThe fields are mutually exclusive.');
		return false;
	}
	
	return true;
}

// date validation for short version of the search form:
function validateShrtFrmDateFields(frm)
{
	// check to see if v_drp (drop down) is all spaces.
	if(isAllSpaces(frm.v_drp.value))
	{
		alert('You must choose a Time Frame. If no Time Frame is desired, then choose Time Frame option: No Limit');
		return false;
	}
	
	// if nothing failed, then return true:
	return true;
}


function countCommonFieldsWithData(frm){
	var intFieldCount = 0;

	if(frm.Name != null){
		if(!isAllSpaces(frm.Name.value)){ intFieldCount++; }
	}
	if(frm.Ticker != null){
		if(!isAllSpaces(frm.Ticker.value)){ intFieldCount++; }
	}
	if(frm.SECFileNo != null){
		if(!isAllSpaces(frm.SECFileNo.value)){ intFieldCount++; }
	}
	if(!isAllSpaces(frm.Text.value)){ intFieldCount++; }
	if(frm.FormGroupID[0].selectedIndex > 0 || frm.FormGroupID[1].selectedIndex > 0){ intFieldCount++; }
	if(frm.FormTypeID.selectedIndex > 0){ intFieldCount++; }
	if(!isAllSpaces(frm.v_drp.value)){ intFieldCount++; }
	if(!isAllSpaces(frm.v_dss.value)){ intFieldCount++; }
	if(!isAllSpaces(frm.v_drs.value)){ intFieldCount++; }
	if(!isAllSpaces(frm.v_dre.value)){ intFieldCount++; }
	
	return intFieldCount;
}

//function used for short search form:
function countShrtFrmCommonFieldsWithData(frm)
{
	var intFieldCount = 0;

	if(frm.Name != null)
	{
		if(!isAllSpaces(frm.Name.value)){ intFieldCount++; }
	}
	if(frm.Ticker != null)
	{
		if(!isAllSpaces(frm.Ticker.value)){ intFieldCount++; }
	}
	if(frm.SECFileNo != null)
	{
		if(!isAllSpaces(frm.SECFileNo.value)){ intFieldCount++; }
	}
	if(frm.FormGroupID[0].selectedIndex > 0 || frm.FormGroupID[1].selectedIndex > 0){ intFieldCount++; }
	if(frm.FormTypeID.selectedIndex > 0){ intFieldCount++; }
	if(!isAllSpaces(frm.v_drp.value)){ intFieldCount++; }
	
	return intFieldCount;
}

	
function countProFieldsWithData(frm){
	var intFieldCount = 0;

	if(frm.CIK != null){
		if(!isAllSpaces(frm.CIK.value)){ intFieldCount++; }
	}
	if(frm.IndustryID.selectedIndex > 0){ intFieldCount++; }
	if(frm.SectorID.selectedIndex > 0){ intFieldCount++; }
	if(!isAllSpaces(frm.City.value)){ intFieldCount++; }
	if(frm.StateID.selectedIndex > 0){ intFieldCount++; }
	if(frm.ExchangeID.selectedIndex > 0){ intFieldCount++; }
		
	return intFieldCount;
}
		

function isValidDate(strValue){
	var arrDate;
	var blnHasWhiteSpace = hasSpaces(strValue);
	var blnIsTooShort = false;
	var intMinLength = 6;
	var strDay;
	var strMonth;
	var strNumericTest = "0123456789";
	var strYear;		

	blnIsTooShort = (strValue.length < intMinLength);
	
	if(!blnHasWhiteSpace && !blnIsTooShort){
		arrDate = strValue.split("/");
		if(arrDate.length < 3){
			alert("Date array must have 3 elements!");
			return false;
		}
		
		strMonth = parseInt(arrDate[0]);
		strDay = parseInt(arrDate[1]);
		strYear = parseInt(arrDate[2]);
			
		if(isNaN(strMonth) || isNaN(strDay) || isNaN(strYear)){
			alert("IsNaN returned true!");
			return false;
		}
			
		if(strMonth < 1 || strMonth > 12){
			alert("Invalid month!");
			return false;
		}
			
		if(strDay < 1 || strDay > 31){
			alert("Invalid day!");
			return false;
		}
			
		if( !(strYear.length == 2 || strYear.length == 4)){
			alert("Invalid year!");
			return false;
		}
			
		return true;
	}
	else{
		alert("Date contained whitespace or was too short!");
		return false;
	}
}
		
// -->