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 Valid Length For The "+type_str+"!!!");
		return false;
	}
	number_found = false;
	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 Atleast One Numeric Value For The "+type_str+"!!!");
		return false;
	}	
	if(char_found==false)
	{
		error_focus(frm_name, element_name, "Please Have Atleast 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;			
		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)
{
	re = /^(http:\/\/|)(www\.|)\w+\.(com|org|gov|cc|mil|edu)$/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)
{
	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!!!");
		return false;		
	}
	return true;
}

function is_number(frm_name, element_name, otherValid, err_txt)
{
	num = document[frm_name][element_name].value;
	if(is_empty(frm_name, element_name, err_txt))
	{
		return false;
	}
	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)
{	
	str_txt = document[frm_name][element_name].value;	
	if(is_empty(frm_name, element_name, txt))
	{
		return false;
	}
	invalidChars = "1234567890/:,;@#!~`$%^&*()-+=_{}[]\\/?.<>\"'|";	
	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)
{
	zip_str = document[frm_name][element_name].value;
	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)
{
	if(is_empty(frm_name, element_name, "Please Enter A Valid Email Address!!!"))
	{
		return false;
	}	
	email_str = document[frm_name][element_name].value;
	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)
{	
	ext_str = ext_str.toUpperCase();	
	ext_check = document[frm_name][element_name].value;	
	ext_len = ext_check.length;
	ext_check = ext_check.substr(ext_len-3, ext_len);
	ext_check = ext_check.toUpperCase();	
	if(ext_check != ext_str)
	{
		error_focus(frm_name, element_name, "Must Select A "+ext_str+" File!!!");
		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)
{
	if(document[frm_name][element_name+(next_num-1)].value.length==length_val)
	{
		document[frm_name][element_name+next_num].focus();
	}
}

function is_first_option(frm_name, select_element, err_txt)
{	
	if(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();
	}
}