
//Javascript 

/*******************************************************************
FUNCTION: 	val_zip
ARGS: 		in_zip
PURPOSE: 	tests if zip is valid (five digits long)
RETURNS: 	true or false
********************************************************************/
function val_zip(in_zip) {	
	var tmp_chr;
	var num_cnt = 0;
	var bad_chr_cnt = 0;
	zip_len = in_zip.length;

	//alert("IN ZIP: " + in_zip + ".");
	if (zip_len == 0)
		return false;
	else {
		for (i=0;i<zip_len;i++) {
	    	tmp_chr = in_zip.substring(i,i+1);		
			isnum_val = isnum(tmp_chr);
			if (isnum_val == "yes")
				num_cnt = num_cnt + 1;
			else
				bad_chr_cnt = bad_chr_cnt + 1;
		}
		if ((num_cnt != 5) || (bad_chr_cnt > 0))
			return false;
		else
			if (bad_chr_cnt > 0)
				return false;
	}
	return true;
}

/*******************************************************************
FUNCTION: 	val_date
ARGS: 		in_date
PURPOSE: 	tests if date is valid (in mm/dd/yy format)
RETURNS: 	0 or non-zero
********************************************************************/
function val_date(in_date) {
	var isnum_val, tmp_chr, slash_cnt, mo, da, yr;
	tmp_chr = "";
	slash_cnt = 0;
	mo = "";
	da = "";
	yr = "";
	isnum_val = "";
		
	//alert(in_date);
	for (i=0;i<in_date.length;i++) {
	    tmp_chr = in_date.substring(i,i+1);
		if (tmp_chr == '/') {
			//alert("Found divider");
		    slash_cnt++;
			if (slash_cnt > 2)
			    return(1);
		}
		else {
			isnum_val = isnum(tmp_chr);
			if (isnum_val == "yes") {
				if (slash_cnt == 0)
					mo = mo + tmp_chr;
				else if (slash_cnt == 1)
					da = da + tmp_chr;
				else if (slash_cnt == 2)
					yr = yr + tmp_chr;
			}
			else
			    return(2);
		}
	}

	if ((mo.length > 0 && mo.length <= 2) &&
		(da.length > 0 && da.length <= 2) &&
	    (yr.length == 2 || yr.length == 4))
		return(0);
	else
		return(3);
}

function alphanumeric(alphanum)
{
	var numaric = alphanum;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}


/******************************************************
FUNCTION: 	test_email
ARGS: 		in_email
PURPOSE: 	tests if email is valid (contains at least 
			three characters , one dot and one @ symbol)
RETURNS: 	0 if valid, non-zero if invalid
******************************************************/
function test_email(in_email) {
	var tmp_chr, ret_code;
	at_cnt = 0;
	dot_cnt = 0;
	char_cnt = 0;
	email_len = in_email.length;
	ret_code = 0;
	
	if (email_len == 0)
		ret_code = 99;
	else {
		for (i=0;i<email_len;i++) {
	    	tmp_chr = in_email.substring(i,i+1);
			if (tmp_chr == "@")
				at_cnt = at_cnt + 1;
			else
				if (tmp_chr == '.')
					dot_cnt = dot_cnt + 1;
				else
					char_cnt = char_cnt + 1;
		}
		if (at_cnt != 1) 
			ret_code = 1;
		else if (dot_cnt == 0)
			ret_code = 2;
		else if (char_cnt == 3)
			ret_code = 3;
	}
	return(ret_code);
}

/*********************************************
FUNCTION: isnum
ARGS: in_str
PURPOSE: tests if passes string is all numeric
RETURNS: "yes" or "no"
*********************************************/
function isnum(in_str) {
	var ret_code, i, tmp_chr;
	ret_code = "no";
	
	for (i=0;i<in_str.length;i++) {
	    tmp_chr = in_str.substring(i,i+1);
		if (tmp_chr == '0' || tmp_chr == '1' || tmp_chr == '2' || tmp_chr == '3' || tmp_chr == '4' || tmp_chr == '5' || tmp_chr == '6' || tmp_chr == '7' || tmp_chr == '8' || tmp_chr == '9')
			ret_code = "yes";
		else {
			ret_code = "no";
			break;
		}
	}
	return(ret_code);
}


/******************************************************
FUNCTION: 	test_tel
ARGS: 		in_tel
PURPOSE: 	tests if tel is valid (contains at least 
			seven numbers)
RETURNS: 	0 if valid, non-zero if invalid
******************************************************/
function test_tel(in_tel) {
	var tmp_chr, ret_code;
	var num_cnt = 0;
	var bad_chr_cnt = 0;
	var ret_code;
	ret_code = 0;
	
	tel_len = in_tel.length;

	if (tel_len == 0)
		ret_code = 99;
	else {
		for (i=0;i<tel_len;i++) {
	    	tmp_chr = in_tel.substring(i,i+1);		
			isnum_val = isnum(tmp_chr);
			if (isnum_val == "yes")
				num_cnt = num_cnt + 1;
			else
				if (tmp_chr != '(' && tmp_chr != ')' && tmp_chr != '-')
					bad_chr_cnt = bad_chr_cnt + 1;
		}
		if (num_cnt < 7) 
			ret_code = 1;
		else 
			if (bad_chr_cnt > 0)
				ret_code = 2;
	}
	return(ret_code);
}

//Gets the Value of the Radio Button
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//Checks the state of the check boxes and returns True of False
function checkbox_checker(checkObj) {
	if ((checkObj).checked)
		return true;
	else
		return false;
}

function set_nav_button_down(button) {
	but_name_down_fname = "images/" + button + "_f3.gif";
	MM_swapImage(button,'',but_name_down_fname,1);
}

function open_site(the_link) {
	//alert("blorp open_site");
	var the_site;
	if (the_link != "") {
		the_site = "http://www." + the_link;
		window.open(the_site)
		window.reload;
	}
}

function cat_search_submit(cat) {
	//alert(cat);
	var oOption = document.getElementById("catId");
	oOption.options[oOption.selectedIndex].value = cat;
	var strText = oOption.options[oOption.selectedIndex].value;
	//alert(strText);
	this.search_form.action = "search.aspx";
	this.search_form.submit();
}
