var localForm; 
function initForm(theForm)   { localForm = frmMeetings; }
//function closeCalendar(io)   {}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

function LTrim(str)
{  var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
	   var j=0, i = s.length;
	   while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			  j++;
	   s = s.substring(j, i);
   }
return s;
}

function RTrim(str)
{  var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	   var i = s.length - 1;       
	   while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			  i--;
	   s = s.substring(0, i+1);
   }
return s;
}

function Trim(str)  { return RTrim(LTrim(str)); }

var TodayDate=new Date();
var TodayMonth=TodayDate.getMonth()+1;
var TodayYear=TodayDate.getYear();
var TodayDay=TodayDate.getDate();
//alert(TodayDay);
function Trim(str)  { return RTrim(LTrim(str)); }
function strip(number) {
		var sOut = '';
		mask = '1234567890';
		for(count = 0; count <= number.length; count++) {
			if(mask.indexOf(number.substring(count, count+1),0) != -1 ) sOut += number.substring(count,count+1);
		}
		return sOut;
	}

function NetE_Validate_Zip(objval)
{
	if (objval.length == 0)
		return true;
	if (objval.length != 5 && objval.length != 10)
		return false;
	if (objval.charAt(0) == "-" || objval.charAt(0) == "+")
		return false;
	if (! NetE_Validate_Integer (objval.substring(0,5)))
		return false;
	if (objval.length == 5)
		return true;
	if (objval.charAt(5) != "-" && objval.charAt(5) != " ")
		return false;
	if (objval.charAt(6) == "-" || objval.charAt(6) == "+")
		return false;
	return ( NetE_Validate_Integer (objval.substring(6,10)));
}


function NetE_Validate_Phone(objval)
{
	if (objval.length == 0)
		return true;
	if (objval.length != 12)
		return false;
	if (! NetE_Validate_Number (objval.substring(0,3)))
		return false;
	else
		if (! NetE_Validate_NumberRange ((eval(objval.substring(0,3))), 100, 1000))
			return false;
	if (objval.charAt(3) != "-" && objval.charAt(3) != " " )
		return false;
	if (! NetE_Validate_Number (objval.substring(4,7)))
		return false;
	else
		if (! NetE_Validate_NumberRange ((eval(objval.substring(4,7))), 100, 1000))
			return false;
	if (objval.charAt(7) != "-" && objval.charAt(7) != " ")
		return false;

	if (objval.charAt(8) == "-" || objval.charAt(8) == "+")
		return false;
	else
	{
		return ( NetE_Validate_Integer (objval.substring(8,12)));
	}

	return true;
}

function  NetE_Validate_NumberRange (objval, min_value, max_value)
{
	if (min_value != null)
	{
		if (objval < min_value)
			return false;
	}
	if (max_value != null)
	{
		if (objval > max_value)
			return false;
	}

	return true;
}

function NetE_Validate_Integer (objval)
{
	 if (objval.length == 0)
		return true;
	var check_char=-1;
	for(var j=0 ; j < objval.length; j++)
	{
		if( objval.charAt(j) == "." )
		{
			check_char = j;
			break;
		}
	}

	if (check_char < 0)
		return NetE_Validate_Number(objval);
	else
		return false;
}

function  NetE_Validate_Number (objval)
{
	if (objval.length == 0) return true;

	var start_format = " 0123456789$.";
	var number_format = " .0123456789";
	var check_char=-1;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	for(var j=1 ; j < start_format.length; j++)
		if( objval.charAt(0) == start_format.charAt(j) )
		{
			check_char = j;
			break;
		}

	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;

	for (var i = 1; i < objval.length; i++)
	{
		check_char =-1;
		for( j=1 ; j <number_format.length; j++)
			if( objval.charAt(i) == number_format.charAt(j) ){
				check_char = j;
				break;
			}

		if (check_char < 0)
			return false;
		else if (check_char == 1)
			{
				if (decimal)
					return false;
				else
					decimal = true;
			}
			else if (check_char == 0)
			{
				if (decimal || digits)
					trailing_blank = true;
			}
			else if (trailing_blank)
				return false;
			else
				digits = true;
	}

	return true
}

function isValidDate(dateStr)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
			
	var matchArray = dateStr.match(datePat); 
	
	if (matchArray == null) 
	{
	alert("Date is not in a valid format dd/mm/yyyy.")
	return false;
	}
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { 
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31.");
	return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn't have 31 days!")
	return false
	}
	if (month == 2) { 
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
	   }
	}
	return true;
}


function validate(theForm) 
{
	 if (Trim(theForm.txtFirstName.value) == "") 
	 {
		alert("Please enter your first name.");
		theForm.txtFirstName.focus();
		return (false);
	 }
	 if (Trim(theForm.txtLastName.value) == "") 
	 {
		alert("Please enter your last name.");
		theForm.txtLastName.focus();
		return (false);
	 } 
 
   if (Trim(theForm.txtEmail.value) == "")
  {
	alert("Please enter email address.");
	theForm.txtEmail.focus();
	return (false);
  }
	var checkStr = theForm.txtEmail.value;
	var ch = checkStr.indexOf('@');
	if (ch==0 || ch==-1) {
		alert("Please enter a valid Email address.");
		theForm.txtEmail.focus();
		return (false);
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzfSOZsozYÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-@.-_'";
	var checkStr = theForm.txtEmail.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
				if (j == checkOK.length) {
					allValid = false;
					break;
				}
	}
	if(!allValid) {
		alert("Please enter only letter, digit and \"@.-_'\" characters in the \"Email\" field.");
		theForm.txtEmail.focus();
		return (false);
	}
	if(!(NetE_Validate_Phone(theForm.txtPhone.value)))
	{
		alert("Please enter a valid phone number 999-999-9999.");
		theForm.txtPhone.focus();
		return false;
	}	
	
	if ((theForm.HowDidYouHear[0].checked==true) && (theForm.txtNewspaper.value == ""))
	{
		alert("Please enter a Newspaper name.");
		theForm.txtNewspaper.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[0].checked==false) && (theForm.txtNewspaper.value != ""))
	{
		alert("Please check Newspaper.");
		theForm.HowDidYouHear[0].focus();
		return false;	
	}	
	
	if ((theForm.HowDidYouHear[1].checked==true) && (theForm.txtRadio.value == ""))
	{
		alert("Please enter a Radio Station name.");
		theForm.txtRadio.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[1].checked==false) && (theForm.txtRadio.value != ""))
	{
		alert("Please check Radio.");
		theForm.HowDidYouHear[1].focus();
		return false;	
	}		
	if ((theForm.HowDidYouHear[2].checked==true) && (theForm.txtBillboard.value == ""))
	{
		alert("Please enter where you saw the Billboard.");
		theForm.txtBillboard.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[2].checked==false) && (theForm.txtBillboard.value != ""))
	{
		alert("Please check Billboard.");
		theForm.HowDidYouHear[2].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[3].checked==true) && (theForm.txtMagazine.value == ""))
	{
		alert("Please enter Magazine name.");
		theForm.txtMagazine.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[3].checked==false) && (theForm.txtMagazine.value != ""))
	{
		alert("Please check Magazine.");
		theForm.HowDidYouHear[3].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[4].checked==true) && (theForm.txtWebsite.value == ""))
	{
		alert("Please enter Website.");
		theForm.txtWebsite.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[4].checked==false) && (theForm.txtWebsite.value != ""))
	{
		alert("Please check Website.");
		theForm.HowDidYouHear[4].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[5].checked==true) && (theForm.txtOnlineSearch.value == ""))
	{
		alert("Please enter Online Search terms.");
		theForm.txtOnlineSearch.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[5].checked==false) && (theForm.txtOnlineSearch.value != ""))
	{
		alert("Please check Online Search.");
		theForm.HowDidYouHear[5].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[6].checked==true) && (theForm.txtRefferByFriend.value == ""))
	{
		alert("Please enter the name of Friend who refered you.");
		theForm.txtRefferByFriend.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[6].checked==false) && (theForm.txtRefferByFriend.value != ""))
	{
		alert("Please check Refered by a Friend.");
		theForm.HowDidYouHear[6].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[7].checked==true) && (theForm.txtPastGuest.value == ""))
	{
		alert("Please enter the name of the guest who recommened us.");
		theForm.txtPastGuest.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[7].checked==false) && (theForm.txtPastGuest.value != ""))
	{
		alert("Please check Recommended by a past guest.");
		theForm.HowDidYouHear[7].focus();
		return false;	
	}
	if ((theForm.HowDidYouHear[8].checked==true) && (theForm.txtOther.value == ""))
	{
		alert("Please enter other type of referals.");
		theForm.txtOther.focus();
		return false;	
	}
	
	if ((theForm.HowDidYouHear[8].checked==false) && (theForm.txtOther.value != ""))
	{
		alert("Please check Other.");
		theForm.HowDidYouHear[8].focus();
		return false;	
	}	

return (true);
}