function checkAnchor() {
	var frm = document.forms["multichoice"];
         if (frm.anchorIt.value == 'true')
         	document.location.hash='addchoice';
}

function validatemultichoice(todaysdate, thisyear)
{
                var frm = document.forms["multichoice"];

                if (frm.name.value.length < 2)
                {
                        alert('Please enter a valid name!');
                        frm.name.focus();
                        return false;
                }
                if (frm.email.value.length < 2)
                {
                        alert('Please enter a valid e-mail address!');
                        frm.email.focus();
                        return false;
                }
                if (frm.title.value.length < 2)
                {
                        alert('You must enter an event title!');
                        frm.title.focus();
                        return false;
                }

                if (frm.desc.value.length > 1024)
                {
                        alert('Your event description is too long!');
                        frm.desc.focus();
                        return false;
                }
                else if (frm.desc.value.length < 2)
                {
                        alert('Your event description is too short!');
                        frm.desc.focus();
                        return false;
                }
                if (frm.invitees.value.length < 4)
                {
                        alert('You must enter at least 1 e-mail address!');
                        frm.invitees.focus();
                        return false;
                }
                if (frm.address.value.length > 2 && frm.citystate.value.length < 2)
                {
                        alert('If you enter an address you must enter a valid City, State');
                        frm.invitees.focus();
                        return false;
                }
}










function validate_alphanum(str,fieldname,required)
{
	str1 = str.value
//	reg = /\d/
	reg = /^([a-zA-Z0-9 ])+$/

	if ((required==1) || (str1!=""))
	{
		if (str1.length<1)
		{
			alert("Please enter a valid value for "+fieldname);
			str.focus();
			return 0;
		}

		if (!reg.test(str1))
		{
			alert(fieldname+" can have only alpha numeric characters");
			str.focus();
			return 0;
		}

	}
}

//	Checks if there is any alphabets if no then error

function validate_alphanumsp(str,fieldname,required)
{
	str1 = str.value
//	reg = /\d/
	reg = /[a-z0-9]/i

	if ((required==1) || (str1!=""))
	{
		if (str1.length<1)
		{
			alert("Please enter a valid value for "+fieldname);
			str.focus();
			return 0;
		}

		if (!reg.test(str1))
		{
			alert(fieldname+" must have atleast a single alphabet or number");
			str.focus();
			return 0;
		}

	}
}

function validate_word(field,alert_text,required)
{
	str	= field.value;

	reg_exp	= /\W/i;

	if ((str != '') || (required == 1))
	{

		if (str.length < 1)
		{
			alert(alert_text+' is mandatory');
			field.focus();
			return 0;
		}

		if (reg_exp.test(str))
		{
			alert(alert_text+' can have only alpha numerics and underscore (_)');
			field.focus();
			return 0;
		}
	}
}

function validate_date(in_date,fieldname,required)
{
	date_arr = in_date.split("/");

	if (date_arr.length > 0)
	{
		mon = date_arr[0];
		day = date_arr[1];
		yea = date_arr[2];
	}
	else
	{
		if (required == 0)
		{
			return 1;
		}
	}

	if ((mon == 0) && (day == 0) && (yea == 0) && (required == 0))
	{
		return 1;
	}

	month_days = [31,28,31,30,31,30,31,31,30,31,30,31];

	reg=/\D/;

	if ((required==1) || (((date_arr[0]!="") || (date_arr[1]!="") || (date_arr[2]!="")) && (date!="")))
	{
		if ((mon==2) && ((yea%4)==0))
			month_days[1] = 29;

		if ((reg.test(mon)) || (reg.test(day)) || (reg.test(yea)))
		{
			alert("Please enter a valid date (mm/dd/yyyy) for "+fieldname);
			return 0;
		}
		if ( ((mon<1) || (mon>12)) || ((day<1) || (day>month_days[mon-1])) || (yea.length!=4))
		{
			alert("Please enter a valid date (mm/dd/yyyy) for "+fieldname);
			return 0;
		}
		return 1;
	}
}



function checkemail(field,fieldname,required)
{	// valid email check

	str	= field.value;

	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	var reg3 = /[a-zA-Z]/i;//--- should have atleast a single alphabet

	if ((required==1) || (str.length>0))
	{
		if ((!reg1.test(str)) && reg2.test(str) && (reg3.test(str))) // if syntax is valid
		{
		   return 1;//return true;
		}
		else
		{
			alert("Please enter Valid Email Account for " + fieldname );
			field.focus();
			return 0;
		}
	}

}


function validate_number(num,fieldname,required)
{
	num1 = num.value;
//	reg_exp = /[0-9.]/g
	reg_exp = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (num1=="")
		{
			alert(fieldname+" is mandatory");
			num.focus();
			return 0;
		}

		if (!reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		num1 = parseInt(num1)
		if (isNaN(num1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
	}


}

function validate_ndigit(num,fieldname,digits,required)
{
	num1 = num.value;
	reg_exp = /[^0-9.]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		if (isNaN(num1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
		if (num1.length!=digits)
		{
			alert("Please enter a "+digits+" digit number for "+fieldname);
			num.focus();
			return 0;
		}
	}
}

function validate_range(num,fieldname,low_val,high_val,required)
{



	num1 = num.value;
	reg_exp = /[^0-9.]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		if (isNaN(num1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
		if ((num1<low_val) || (num1>high_val))
		{
			alert("Range for "+fieldname+" is invalid.");
			num.focus();
			return 0;
		}
	}
}

function validate_integer(num,fieldname,required)
{
	num1 = num.value;
	reg_exp = /[^0-9]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		if ((isNaN(num1)) || (num1.length<1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
	}
}


function validate_string(str,fieldname,required)
{
	str1 = str.value
	reg = /\d/

	sp_reg	= /\S/

	if ((required==1) || (str1.length>0))
	{
		if (reg.test(str1))
		{
			alert("Can not have numbers in "+fieldname);
			str.focus();
			return 0;
		}
		if (str1.length<1)
		{
			alert(fieldname+" is mandatory");
			str.focus();
			return 0;
		}

		if (!sp_reg.test(str1))
		{
			alert('Please enter a valid entry for '+fieldname);
			str.focus();
			return 0;
		}
	}
}



function validate_url(field,display,required)
{
	if ((field.value!="") || (required==1))
	{
		web=field.value;
  		s1=web.substring(0,3);
		dot=web.substring(3,4);
	  	s2=s1.toLowerCase();

		if(s2!="www" || dot!=".")
		{
			alert(display+" URL is invalid\n Usage: www.yourURLsitename.com ");
			field.focus();
			return 0;
		}
	}
 }


function validate_datetime(date_time,fieldname,required)
{
	if ((required == 1) || (date_time.value != ''))
	{
		if ((date_time.value == '') && (required == 1))
		{
			alert(fieldname+' is mandatory');
			return 0;
		}


		vdate_time = date_time.value.split(" ");

		if (vdate_time.length != 2)
		{
			alert('Invalid date time format for '+fieldname+' \nValid Format : mm/dd/yyyy hh:mm:ss');
			date_time.focus();
			return 0;
		}


		vdt	=  vdate_time[0];

		flag	= validate_date(vdt,fieldname,1);

		if (flag == 0)
		{
			date_time.focus();
			return false;
		}

		if (vdate_time[1] != '')
		{
			vtime	= vdate_time[1];
			vtime	= vtime.split(":");

			if (vtime.length == 3)
			{
				vhours	= vtime[0] * 1;
				vmin	= vtime[1] * 1;
				vsec	= vtime[2] * 1;

				if ((vhours > 23) || (vhours < 0) || (isNaN(vhours)) )
				{
					alert('Invalid Hour.Please Enter Hour Between Zero and 23');
					date_time.focus();
					return 0;
				}

				if ((vmin > 59) || (vmin < 0) || (isNaN(vmin)) )
				{
					alert('Invalid Minutes.Please Enter Minutes Between Zero and 59');
					date_time.focus();
					return 0;
				}

				if ((vsec > 59) || (vsec < 0) || (isNaN(vsec)) )
				{
	 				alert('Invalid Seconds.Please Enter Seconds Between Zero and 59');
					date_time.focus();
					return 0;
				}
			}
			else
			{
				alert('Please Enter Proper Time Format For '+fieldname +'  \n\t\tFormat hh:mm:ss');
				date_time.focus();
				return 0;
			}
		}
		else
		{
			alert('Please Enter Time For '+fieldname +'  \n\tFormat hh:mm:ss');			date_time.focus();
			return 0;
		}

	}
}

function pull_datechk(tmp_month,tmp_day,tmp_year,disp_val,required)
{

	if (((tmp_month.value!='') || (tmp_day.value!='') || (tmp_year.value!='')) || (required == 1))
	{

		if (tmp_month.value == '')
		{
			alert('Please select the month for '+disp_val);
			tmp_month.focus();
			return false;
		}

		if (tmp_day.value == '')
		{
			alert('Please select the day for '+disp_val);
			tmp_day.focus();
			return false;
		}

		if (tmp_year.value == '')
		{
			alert('Please select the year for '+disp_val);
			tmp_year.focus();
			return false;
		}

		dt=new Date(tmp_year.value,tmp_month.value-1,tmp_day.value);

		temp_day=dt.getDate();

		if (temp_day!=(tmp_day.value))
		{
			alert("Please select valid date for "+disp_val);
			tmp_month.focus();
			return 0;
		}
	}

}

function validate_password(str,fieldname,required)
{
	str1 = str.value

	reg	= /\s/

	if ((required==1) || (str1.length>0))
	{
		if (reg.test(str1))
		{
			alert("Can not have spaces in "+fieldname);
			str.focus();
			return 0;
		}
		if (str1.length<1)
		{
			alert(fieldname+" is mandatory");
			str.focus();
			return 0;
		}
	}

}





function validate_zip(zip1,zip2,display,required)
{
	reg_zip1 = /^[a-zA-Z0-9]+$/
	reg_zip2 = /^[a-zA-Z0-9]+$/ 		// both zip1 and zip2 contains alphanumeric values

	zip1val = zip1.value;
	zip2val = zip2.value;

	if ((required==1) || ((zip1val!="") || (zip2val!="")))
	{
		if (zip1.value=="")
		{
			alert("Please enter value for "+display+" Zip1");
			zip1.focus();
			return 0;
		}

/*
		if (zip2.value=="")
		{
			alert("Please enter value for "+display+" Zip2");
			zip2.focus();
			return 0;
		}
*/

		if (zip1val.length>5)
		{
			alert(display+" Zip1 length is invalid");
			zip1.focus();
			return 0;
		}

		if (zip2val.length>4)
		{
			alert(display+" Zip2 length is invalid");
			zip2.focus();
			return 0;
		}

		if (!(reg_zip1.test(zip1val)))
		{
			alert("Invalid characters in "+display+" Zip1");
			zip1.focus();
			return 0;
		}

		if ( zip2.value!="" &&  !(reg_zip2.test(zip2val)))
		{
			alert("Invalid characters in "+display+" Zip2");
			zip2.focus();
			return 0;
		}
	}
}


//	Right trim

function rtrim_field(str)
{
	var spc_reg	= /\s*$/;

	mat	= str.match(spc_reg);
	str	= str.replace(mat,'');

	return str;
}

//	Left trim

function ltrim_field(str)
{
	var spc_reg	= /^\s*/;

	mat	= str.match(spc_reg);
	str	= str.replace(mat,'');

	return str;
}

//	Trim

function trim_field(str)
{
	str	= rtrim_field(str);

	str	= ltrim_field(str);

	return str;
}


// credit card expiration month validation

function credit_exp_validation(temp_month,temp_year,req)
{

	today_date		= new Date();

	today_month		= today_date.getMonth();

	today_year		= today_date.getYear();

	today_month		= (today_month * 1) + 1;

	if((temp_month.value == '') && (req == '1'))
	{
		alert('Please select the credit card expiration month');
		temp_month.focus();
		return false;
	}

	if((temp_year.value == '') && (req == '1'))
	{
		alert('Please select the credit card expiration year');
		temp_year.focus();
		return false;
	}

	if ((temp_month.value < today_month) && (temp_month.value != ''))
	{
		if((temp_year.value <= today_year) && (temp_year.value != ''))
		{
			alert('Please select valid credit card expiration month');
			temp_month.focus();
			return false;
		}
	}

	if((temp_year.value < today_year) && (temp_year.value != ''))
	{
		alert('Please select valid credit card expiration year');
		temp_year.focus();
		return false;
	}


}

function validate_time(fname,dname,req)
{

	fval	= fname.value;

	reg_exp	= /[^0-9:]/;

	if (reg_exp.test(fval))
	{
		alert('Invalid time format for "'+dname+'".\nValid format hh:mm:ss');
		fname.focus();
		return false;
	}

	pecs	= fval.split(':');

	if (pecs.length != 3)
	{
		alert('Invalid time format for "'+dname+'".\nValid format hh:mm:ss (24 hour format)');
		fname.focus();
		return false;
	}

	if ((pecs[0].value>23) || (pecs[1].value > 60) || (pecs[2].value > 60))
	{
		alert('Please enter time in 24 hour format for "'+dname+'".\nValid format hh:mm:ss');
		fname.focus();
		return false;
	}


}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}

function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
}
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
}