// swap images
function swap(img, over)
{
	if(over)
	{
		i = "images/" + img.name + "_1.gif";
	}
	else
	{
		i = "images/" + img.name + "_0.gif";
	}
	img.src = i;
}

function swap_it(img_id, img_src)
{
	document.all(img_id).src = img_src;
}

function show_hide(img_str, div_str)
{
	if(document.all(div_str).style.display == "none")
	{
		swap_it(img_str, 'images/arrow_down.gif');
		document.all(div_str).style.display = "block";
	}
	else
	{
		swap_it(img_str, 'images/arrow_right.gif');
		document.all(div_str).style.display = "none";		
	}
}

function show_hide2(div_str)
{
	if(document.all(div_str).style.display == "none")
	{
		document.all(div_str).style.display = "block";
	}
	else
	{
		document.all(div_str).style.display = "none";		
	}
}

function show_hide3(div_str)
{
	if(document.all(div_str).style.display == "none")
	{
		document.all(div_str).style.display = "block";
	}
	else
	{
		document.all(div_str).style.display = "none";		
	}
}

function set_parent_img(file_loc, file_id)
{
	opener.document.forms[0].upload.value=file_loc;
	opener.document.forms[0].fID.value=file_id;
	window.close();
}

function popup_image(img)
{
	newWin = window.open("popup_image.asp?img=" + img, "myWin", "width=300,height=250, top=100, left=100, pageY=10, pageX=10, toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,statusbar=no");
	newWin.focus();
}

high_month = "|1|3|5|7|9|10|12|";
thirty_day_month = "|4|6|8|11|";
feb_days = "2";
function is_good_date(month_num, day_num, required)
{
	if(required)
	{
		if(((month_num == 0)||(month_num.length == 0))||((day_num == 0)||(day_num.length == 0)))
		{
			alert("Sorry, Please Select A Valid Date");
			return false;
		}
		if(((thirty_day_month.indexOf("|"+month_num+"|") >= 0)&&(day_num > 30))||((month_num == 2)&&(day_num > 28)))
		{
			alert("Sorry, There Are Not That Many Days For That Month");
			return false;
		}
	}
	return true;
}

function is_good_length(form_name, element_name, err_txt, required, min_num, max_num)
{
	if(required)
	{
		tmp_str = document[form_name][element_name].value;
		if((tmp_str.length < min_num)||(tmp_str.length > max_num))
		{
			error_focus(form_name, element_name, err_txt);
			return false;
		}
	}		
	return true;
}

function is_sql(frm_name, element_name, txt)
{	
	str_txt = document[frm_name][element_name].value;	
	if(is_empty(frm_name, element_name, txt))
	{
		return false;
	}
	invalidChars = "/:,;!`*()-+={}[]\\/?.<>\"'|";	
	for(i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if(str_txt.indexOf(badChar, 0)>-1)
		{//found a bad character
			error_focus(frm_name, element_name, txt);
			return true;
		}
	}	
	return false;
}

function is_empty(frm_name, element_name, txt)
{
	str_txt = document[frm_name][element_name].value;
	if(str_txt.length==0)
	{
		error_focus(frm_name, element_name, txt);		
		return true;
	}
	else
	{
		return false;
	}
}

function user_pwd_match(frm_name, pwd_val, user_val)
{
	pwd_str = document[frm_name][pwd_val].value;
	user_str = document[frm_name][user_val].value;
	if(pwd_str==user_str)
	{
		error_focus(frm_name, user_val, "Username and Password Cannot Match");
		return true;
	}
	return false;
}

function is_good_login(frm_name, element_name, type_str, pwd_length)
{
	login = document[frm_name][element_name].value;
	if(is_empty(frm_name, element_name, "Please Enter A Valid "+type_str+"."))
	{
		return false;
	}
	if((login.length < pwd_length)||(login.length > 15))
	{ 
		error_focus(frm_name, element_name, "Please enter at least " + pwd_length + " characters for the "+type_str+".");
		return false;
	}
	number_found = true;
	char_found = false;
	for(i=0; i<login.length; i++)
	{
		/*if(found_char(login.charAt(i), "num"))
		{
			number_found = true;
		}*/
		if(found_char(login.charAt(i), "char"))
		{
			char_found = true;
		}
	}
	/*if(number_found==false)
	{
		error_focus(frm_name, element_name, "Please Have At least One Numeric Value For The "+type_str+".");
		return false;
	}	*/
	if(char_found==false)
	{
		error_focus(frm_name, element_name, "Please Have At least One Alphabet Letter For The "+type_str+".");
		return false;
	}
	return true;	
}

function found_char(char_val, type_str)
{
	if(type_str=="char")
	{
		validChars = "abcdefghijklmnopqrstuvwxyz";
	}
	else if(type_str=="num")
	{
		validChars = "1234567890";
	}
	if(validChars.indexOf(char_val.toLowerCase(), 0)<=-1)
	{
		return false;
	}
	return true;	
}

function image_popup(img_str)
{
	the_img = new Image;
	the_img.src = img_str;
	leftPos = (screen.width/2)-(the_img.width/2);	
	topPos = (screen.height/2)-(the_img.height/2);
	setTimeout("", 50);
	window.open(img_str, "EnlargedImage", "height="+(the_img.height+20)+",width="+(the_img.width+20)+",left="+leftPos+",top="+topPos);	
}

function change_next_select(array_str, form_str, element_str, element_str2, length_num)
{	
	document[form_str][element_str2].options.length=length_num;
	
	var j = 0;
	
	for(i=0; i < array_str.length; i = i + 2)
	{
		sIndex = document[form_str][element_str].selectedIndex;
		get_select = document[form_str][element_str].options[sIndex].value;
		//alert(array_str[i]+" = "+get_select);
		if(array_str[i] == get_select)
		{
			Opt = document.createElement("OPTION");
			Opt.value = array_str[i+1][0];
			Opt.text = array_str[i+1][1];
			if(navigator.appName.indexOf("Microsoft") != -1)
			{
				document[form_str][element_str2].add(Opt);			
			}
			else
			{
				document[form_str][element_str2].appendChild(Opt);
			}
		}
	}
}

function is_good_url(frm_name, element_name, required)
{
	str_txt = document[frm_name][element_name].value;
	if((str_txt.length == 0)&&(required == false))
		return true;
		
	re = /^(http:\/\/|)(www\.|)|\w+\.(com|org|gov|cc|mil|edu|net)$/i;
	url = document[frm_name][element_name].value;
	if(!re.test(url))
	{
		error_focus(frm_name, element_name, "Please Enter A Valid URL!!!");
		return false;
	}
	return true;
}

function is_good_phone(frm_name, element_name, required)
{
	str_txt = document[frm_name][element_name].value;
	if((str_txt.length == 0)&&(required == false))
		return true;
		
	re = /^(\([1-9]?\d{2}\)|\d{3}[-])\d{3}[-]\d{4}$/;
	phone_str = document[frm_name][element_name].value;
	if(!re.test(phone_str))
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Phone Number.\n(555)123-4567\n555-123-4567");
		return false;		
	}
	return true;
}

function is_number(frm_name, element_name, otherValid, err_txt, required)
{
	num = document[frm_name][element_name].value;
	str_txt = document[frm_name][element_name].value;
	if((required == true)&&(is_empty(frm_name, element_name, err_txt)))
		return false;
	else if(str_txt.length == 0)
		return true;
		
	validChars = "1234567890" + otherValid;
	for(i=0; i<num.length; i++)
	{
		goodChar = num.charAt(i);
		if(validChars.indexOf(goodChar, 0)<=-1)
		{
			error_focus(frm_name, element_name, err_txt);
			return false;
		}
	}
	return true;
}

function is_string(frm_name, element_name, txt, required)
{	
	str_txt = document[frm_name][element_name].value;
	if((required == true)&&(is_empty(frm_name, element_name, txt)))
		return false;
	else if(str_txt.length == 0)
		return true;
		
	invalidChars = "/:,;~`%^&*()-+=_{}[]\\/.<>\"|0123456789";	
	for(i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if(str_txt.indexOf(badChar, 0)>-1)
		{//found a bad character
			error_focus(frm_name, element_name, txt);
			return false;
		}
	}	
	return true;
}

function is_good_zip(frm_name, element_name, required)
{	
	zip_str = document[frm_name][element_name].value;
	if((zip_str.length == 0)&&(required == false))
		return true;
		
	if(isNaN(zip_str))
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Zip Code.");
		return false;
	}
	if(zip_str.length != 5)
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Zip Code.");
		return false;	
	}
	return true;
}

function is_good_email(frm_name, element_name, required)
{
	email_str = document[frm_name][element_name].value;
	if((required == true)&&(is_empty(frm_name, element_name, "Please Enter A Valid Email Address.")))
		return false;
	else if(email_str.length == 0)
		return true;
	
	invalidChars = " /:,;";	
	for(i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i)
		if(email_str.indexOf(badChar, 0)>-1)
		{//found a bad character
			error_focus(frm_name, element_name, "Please Enter A Valid Email Address.");
			return false;
		}
	}	
	//check for @ sign
	atPos = email_str.indexOf("@", 1);
	if(atPos == -1)
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Email Address.");
		return false;
	}
	if(email_str.indexOf("@", atPos+1) > -1)
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Email Address.");
		return false;		
	}
	//check for period
	periodPos = email_str.indexOf(".", atPos);
	if(periodPos == -1)
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Email Address.");
		return false;	
	}
	if(periodPos+3 > email_str.length)
	{
		error_focus(frm_name, element_name, "Please Enter A Valid Email Address.");
		return false;	
	}
	return true;
}

function is_good_extension(frm_name, element_name, ext_str, required)
{	
	ext_str = ext_str.toUpperCase();	
	ext_array = ext_str.split("|");
	ext_check = document[frm_name][element_name].value;	
	ext_len = ext_check.length;
	if((required)||(ext_len > 0))
	{
		ext_check = ext_check.substr(ext_len-3, ext_len);
		ext_check = ext_check.toUpperCase();
		for(var i = 0; i < ext_array.length; i++)
		{
			if(ext_check == ext_array[i])
			{
				return true;		
			}
		}
		error_focus(frm_name, element_name, "Must Select A "+ext_str.replace("|", " or ")+" File(s).");	
		return false;
	}
	return true;
}

function check_length(frm_name, element_name, prev_num, length_val)
{
	if(document[frm_name][element_name+prev_num].value.length < length_val)
	{
		document[frm_name][element_name+prev_num].focus();
	}
}

function Move_Next(frm_name, element_name, next_num, length_val)
{
	var tmp_val = document[frm_name][element_name+(next_num-1)].value;
	if(tmp_val.length == length_val)
	{
		document[frm_name][element_name+next_num].focus();
	}
}

function is_first_option(frm_name, select_element, err_txt, required)
{	
	if((required == true)&&(document[frm_name][select_element].selectedIndex == 0))
	{
		error_focus(frm_name, select_element, err_txt);
		return true;
	}
	return false;
}

function error_focus(frm_name, element_name, err_str)
{
	alert(err_str);
	document[frm_name][element_name].focus();
	if(document[frm_name][element_name].type!="select-one")
	{
		document[frm_name][element_name].select();
	}
}