﻿
function validateFrm(FormtoValidate){
		var requiredFields = new Array("Name",  "Email", "CompanyName", "Phone", "Comments");
		var missingFields = new Array();
		var missingBudget = 0;
		var missingBudgetTxt="";
		var missingBids = 0;
		var missingBidsText = "";
		var missingCampaignStrategy = 0;
		var missingCampaignStrategyText = "";
		
		var alertOutPut = 'Some required fields have not been   \n'
						+ 'completed.  Please check you answers   \n'
						+ 'for the following fields:   \n\n';
							
		for (var i=0; i < requiredFields.length; i++)
		{
			if (FormtoValidate.elements[requiredFields[i]].value == "" || FormtoValidate.elements[requiredFields[i]].value == null || FormtoValidate.elements[requiredFields[i]].value == FormtoValidate.elements[requiredFields[i]].defaultValue )
			{
				missingFields[missingFields.length] = requiredFields[i]
			}
		}
		
		if (document.getElementById('MonthlyBudget').value == " -- Select One -- " || 
			document.getElementById('MonthlyBudget').value == undefined )
			{
				missingBudget = 1;
				missingBudgetTxt = "Monthly search budget";
			}
			
			if (document.getElementById('BidOptimization').value == " -- Select One -- " || 
			document.getElementById('BidOptimization').value == undefined )
			{
				missingBids = 1;
				missingBidsText = "Bid Optimization";
			}
			
			if (document.getElementById('SearchCampaignStrategy').value == " -- Select One -- " || 
			document.getElementById('SearchCampaignStrategy').value == undefined )
			{
				missingCampaignStrategy = 1;
				missingCampaignStrategyText = "Search Campaign Strategy";
			}
		
		if (missingFields.length > 0  || missingBudget == 1 || missingBids == 1 || missingCampaignStrategy == 1)
		{
		
			for (var i=0; i < missingFields.length; i++)
			{
				alertOutPut += missingFields[i] + '\n';
			}
				alertOutPut +=  missingBudgetTxt;
				alertOutPut += ( missingBids == 1 ) ? "\n" + missingBidsText : "";
				alertOutPut += ( missingCampaignStrategy == 1 ) ? "\n" + missingCampaignStrategyText : "";
					alert(alertOutPut);
					if(missingFields.length > 0){FormtoValidate.elements[missingFields[0]].focus()};
					return false;
		}	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(FormtoValidate.Email.value)))
			{
				var alertOutPut = 'You have entered an invalid email   \n'
								+ 'address.  Please check you entry   \n'
								+ 'and try again.   ';
				alert(alertOutPut);
				FormtoValidate.Email.focus();
				return false	
			}	
		
			else
				{
					return true;
				}
		}
