function func_submit(str_form,str_page,str_hidden,str_hidden_value)
{
	var obj_form=eval("document." + str_form);
	if (str_hidden != "")
	var obj_hid=eval("document." + str_form + "." + str_hidden);
	if (str_hidden_value != "" && !isNaN(str_hidden_value))
		obj_hid.value=str_hidden_value;
	obj_form.method="post";
	obj_form.action=str_page;
	obj_form.submit();
}
function func_trim(param_text)
{
	var str_text=new String(param_text);
	var str_return_text;
	str_return_text="";
	b_non_blank_started=false;
	b_non_blank_ended=false;
	str_intermediate_blank_chunk="";
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(str_text.charCodeAt(i_loop)!=32)
		{
			if(!b_non_blank_started)
			{
				b_non_blank_started=true;
			}
			if(b_non_blank_started && !b_non_blank_ended)
			{
				str_return_text+=str_text.charAt(i_loop);
			}
			if(b_non_blank_ended)
			{
				str_return_text+=(str_intermediate_blank_chunk+str_text.charAt(i_loop));
				b_non_blank_ended=false;
				str_intermediate_blank_chunk="";
			}
		}
		else
		{
			if(b_non_blank_started)
			{
				b_non_blank_ended=true;
				str_intermediate_blank_chunk+=" ";
			}
		}
	}
	return str_return_text;
}

function func_is_max_length(param_text,param_num)
{
	var i_length;
	var str_text=new String(func_trim(param_text));
	i_length=func_len(str_text);
	if (i_length>param_num)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function func_len(param_text)
{
	var str_text=new String(func_trim(param_text));
	return str_text.length;
}

function func_is_numeric(param_text)
{
	if(!isNaN(param_text))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function func_is_positive_integer(param_text)
{
	var b_is_positive_integer=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
		{
			b_is_positive_integer=false;
			break;
		}
	}
	if(b_is_positive_integer)
	{
		var i_integer=new Number(str_text);
		if(i_integer.valueOf()<=0)
		{
			b_is_positive_integer=false;
		}
	}
	return b_is_positive_integer;
}

function func_is_non_negative_integer(param_text)
{
	var i_length;
	var b_is_non_negative_integer=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
		{
			b_is_non_negative_integer=false;
			break;
		}
	}
	if(b_is_non_negative_integer)
	{
		var i_integer=new Number(param_text);
		if(i_integer.valueOf()<0)
		{
			b_is_non_negative_integer=false;
		}
	}
	return b_is_non_negative_integer;
}

function func_is_integer(param_text)
{
	var i_length;
	var b_is_integer=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!(str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9"))
		{
			b_is_integer=false;
			break;
		}
	}
	return b_is_integer;
}

function func_is_real_number(param_text)
{
	var i_length;
	var b_is_real_number=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
		{
			b_is_real_number=false;
			break;
		}
	}
	return b_is_real_number;
}

function func_is_positive_real_number(param_text)
{
	var i_length;
	var b_is_positive_real_number=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
		{
			b_is_positive_real_number=false;
			break;
		}
	}
	if(b_is_positive_real_number)
	{
		var i_real_number=new Number(str_text);
		if(i_real_number.valueOf()<=0.0)
		{
			b_is_positive_real_number=false;
		}
	}
	return b_is_positive_real_number;
}

function func_is_non_negative_real_number(param_text)
{
	var i_length;
	var b_is_non_negative_real_number=true;
	var str_text=new String(func_trim(param_text));
	var i_loop;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if(!((str_text.charAt(i_loop)>="0" && str_text.charAt(i_loop)<="9") || (str_text.charAt(i_loop)==".") || (str_text.charAt(i_loop)=="+") || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="e") || (str_text.charAt(i_loop)=="E")))
		{
			b_is_non_negative_real_number=false;
			break;
		}
	}
	if(b_is_non_negative_real_number)
	{
		var i_real_number=new Number(str_text);
		if(i_real_number.valueOf()<0.0)
		{
			b_is_non_negative_real_number=false;
		}
	}
	return b_is_non_negative_real_number;
}

function func_is_email(param_email)
{
	var str_current_character;
	var b_valid_email,b_period_present; 
	var i_last_position_of_period,b_correct_length_extension;
	var i_num_at_symbol=0;
	var i_pos_at_symbol;
	var i_length_of_server_name=1;
	var i_pos_consecutive_dots;
	var str_email=new String(func_trim(param_email));
	i_length=str_email.length;
	b_period_present=1;
	b_correct_length_extension=1;
	i_last_position_of_period=0;
	
	if(i_length==0)
	{
		return true;
	}
	
	for(i_loop=0; i_loop<i_length; i_loop++)
	{
		if(!((str_email.charCodeAt(i_loop)>=65 && str_email.charCodeAt(i_loop)<=90)
		  || (str_email.charCodeAt(i_loop)>=97 && str_email.charCodeAt(i_loop)<=122)
		  || (str_email.charCodeAt(i_loop)>=48 && str_email.charCodeAt(i_loop)<=57)
		  || (str_email.charAt(i_loop)=="@")
		  || (str_email.charAt(i_loop)=="_")
		  || (str_email.charAt(i_loop)=="-")
		  || (str_email.charAt(i_loop)==".")))
		{
			return false;
		}
	}
	
	i_pos_consecutive_dots=str_email.indexOf('..');
	if(i_pos_consecutive_dots!=-1)
	{
		return false;
	}
	
	var i_pos_space;
	i_pos_space = str_email.indexOf(' ');
	if(i_pos_space!=-1)
	{
		return false;
	}
	
	i_last_position_of_period = str_email.lastIndexOf('.');
	if(i_last_position_of_period<=0)
	{
		b_period_present=0;
	}
	
	if(((i_length-i_last_position_of_period)>4) || ((i_length-i_last_position_of_period)<3))
	{
		b_correct_length_extension=0;
	}
	
	for(i_loop=0;i_loop<=i_length;i_loop++)
	{
		str_current_character=str_email.charAt(i_loop);
		if (str_current_character=='@')
		{
			i_num_at_symbol=i_num_at_symbol + 1;
		}
	}
	
	if(i_num_at_symbol!=1)
	{
		return false;
	}
	
	i_pos_at_symbol = str_email.indexOf('@');
	if(str_email.charAt(i_pos_at_symbol+1) == '.')
	{
		i_length_of_server_name=0;
	}
	
	if((i_num_at_symbol==1) && (b_period_present==1) && (b_correct_length_extension==1) && (i_length_of_server_name==1))
	{
		b_valid_email=1;
	}
	else
	{
		 b_valid_email=0;
	}
	
	if(b_valid_email==0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function func_is_min_length(param_text,param_num)
{
	var i_length;
	var str_text=new String(param_text);
	i_length = func_len(str_text);
	if (i_length<param_num)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.() 
function func_is_telephone_number(param_text) 
{ 
	var b_is_telephone_number=true; 
	if(func_trim(param_text)!="") 
	{ 
		var str_text=new String(func_trim(param_text));
		var i_length=func_len(str_text);
		var i_loop; 
		for (i_loop=0;i_loop<i_length;i_loop++) 
		{ 
			if (!((str_text.charCodeAt(i_loop) >= 48 && str_text.charCodeAt(i_loop) <= 57) || (str_text.charAt(i_loop) == "-")|| (str_text.charAt(i_loop) == "(")|| (str_text.charAt(i_loop) == ")") || (str_text.charAt(i_loop) == "+") || (str_text.charCodeAt(i_loop) ==32) || (str_text.charAt(i_loop) == "."))) 
			{ 
				b_is_telephone_number=false; 
			} 
		} 
	} 
	return b_is_telephone_number; 
}

function func_is_fax_number(param_text) 
{ 
	var b_is_fax_number=true; 
	if(func_trim(param_text)!="") 
	{ 
		var str_text=new String(func_trim(param_text));
		var i_length=func_len(str_text);
		var i_loop; 
		for (i_loop=0; i_loop<i_length; i_loop++) 
		{ 
			if (!((str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57) || (str_text.charAt(i_loop)=="-") || (str_text.charAt(i_loop)=="(") || (str_text.charAt(i_loop)==")") || (str_text.charAt(i_loop)=="+") || (str_text.charCodeAt(i_loop)==32) || (str_text.charAt(i_loop)=="."))) 
			{ 
				b_is_fax_number=false; 
			} 
		} 
	} 
	return b_is_fax_number; 
}

function func_is_alpha_numeric(param_text)
{
	var str_text=new String(func_trim(param_text));
	var i_loop;
	var b_is_alpha_numeric=true;
	for (i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if (!((str_text.charCodeAt(i_loop)>=65 && str_text.charCodeAt(i_loop)<=90) || (str_text.charCodeAt(i_loop)>=97 && str_text.charCodeAt(i_loop)<=122) || (str_text.charCodeAt(i_loop)>=48 && str_text.charCodeAt(i_loop)<=57)))
		{
			b_is_alpha_numeric=false; 
		}
	 }
	return b_is_alpha_numeric;
}

function func_is_alphabet(param_text)
{
	var str_text=new String(func_trim(param_text));
	var i_loop;
	var b_is_alphabet=true;
	for(i_loop=0;i_loop<str_text.length;i_loop++)
	{
		if (!((str_text.charCodeAt(i_loop)>=65 && str_text.charCodeAt(i_loop)<=90) || (str_text.charCodeAt(i_loop)>=97 && str_text.charCodeAt(i_loop)<=122)))
		{
			b_is_alphabet=false;
		}
	}
	return b_is_alphabet;
}

function func_is_date(i_date,i_month,i_year)
{
	var b_correct_date;
	var dt_date=new Array(3);
	b_correct_date=4; 
	dt_date[0]=i_date;
	dt_date[1]=i_month;
	dt_date[2]=i_year;
	if(b_correct_date==4 && (dt_date[0]>31 || dt_date[0]<1))
	{
		b_correct_date=1;
		alert("Illegal value for date" );
	}
	 if(b_correct_date==4 && (dt_date[1]>12 || dt_date[1]<1))
	{
		b_correct_date=2;
		alert('Illegal value for month');
	}
	if(b_correct_date==4 && dt_date[2]<=0)
	{
		b_correct_date=3;
		alert('Illegal value for year');
	}
	if(b_correct_date==4 && ((dt_date[1]==1 || dt_date[1]==3 || dt_date[1]==5 || dt_date[1]==7 || dt_date[1]==8 || dt_date[1]==10 ||dt_date[1]==12) && (dt_date[0]>31 || dt_date[0]<1)))
	{
		b_correct_date=1;
		alert('Illegal value for date.MonthName and date mismatch');
	}
	if(b_correct_date==4 && ((dt_date[1]==4 || dt_date[1]==6 || dt_date[1]==9 || dt_date[1]==11) && (dt_date[0]>30 || dt_date[0]<1)))
	{
		 b_correct_date=1;
		alert('Illegal value for date.Monthname and date mismatch');
	}
	var i_year;
	i_year=dt_date[2];
	if((i_year % 400)>0)
	{
		if((i_year % 100)>0 && (i_year % 4)==0) //leap year 
		{
			if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>29)
			{
				b_correct_date=1;
				alert('Illegal value for date.In that year, February cannot have that day.');
			}
		}
		else
		{		
			if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>28) 
			{			
				b_correct_date=1;
				alert('Illegal value for date.In that year, February cannot have that day.');
			}
		}
	}
	else
	{
		if(b_correct_date==4 && dt_date[1]==2 && dt_date[0]>29) 
		{
			b_correct_date=1;
			alert('Illegal value for date.In that year, February cannot have that day.');
		}
	}
	return b_correct_date;
}

function func_is_url(param_url)
{
	var str_url=new String(func_trim(param_url));
	b_correct_length_extension=1;
	var i_length=str_url.length;
	var str_prefix=str_url.slice(7);
	b_period_present=1;
	b_correct_length_extension=1;
	var i_loop;
	if(str_prefix.toLowerCase()=="http://" && str_url.length==7)
	{
		return false;
	}
	
	for(i_loop=0; i_loop<i_length; i_loop++)
	{
		if(!((str_url.charCodeAt(i_loop)>=65 && str_url.charCodeAt(i_loop)<=90)
		  || (str_url.charCodeAt(i_loop)>=97 && str_url.charCodeAt(i_loop)<=122)
		  || (str_url.charCodeAt(i_loop)>=48 && str_url.charCodeAt(i_loop)<=57)
		  || (str_url.charAt(i_loop)=="/")
		  || (str_url.charAt(i_loop)==":")
		  || (str_url.charAt(i_loop)=="_")
		  || (str_url.charAt(i_loop)=="-")
		  || (str_url.charAt(i_loop)==".")))
		{
			return false;
		}
	}
	
	var i_pos_consecutive_dots=str_url.indexOf('..');
	if(i_pos_consecutive_dots!=-1)
	{
		return false;
	}
	
	var i_pos_space;
	i_pos_space = str_url.indexOf(' ');
	if(i_pos_space!=-1)
	{
		return false;
	}
	
	var i_last_position_of_period = str_url.lastIndexOf('.');
	if(i_last_position_of_period<=0)
	{
		b_period_present=0;
	}
	
	if(((i_length-i_last_position_of_period)>4) || ((i_length-i_last_position_of_period)<3))
	{
		b_correct_length_extension=0;
	}
	
	if((b_period_present==0) || (b_correct_length_extension==0))
	{
		return false;
	}
	
	return true;
}

function func_is_combo_selected(obj_combo)
{
	var i_loop;
	if(obj_combo.selectedIndex>0 && obj_combo.options[obj_combo.selectedIndex].value!="")
	{
		return true;
	}
	else
	{
		return false;
	}
}

function func_is_option_selected(obj_radio)
{
	var i_loop;
	for (i_loop=0; i_loop<obj_radio.length; i_loop++)
	{
		if ((obj_radio[i_loop].checked) && (obj_radio[i_loop].value != ""))
		{
			return true;
		}
	}
	return false;
}

function func_start()
{

}

//select All checkboxes starting with..
function func_select_all_checkboxes(str_form_name,str_search_chars,str_select_all)
{
	var obj_form=eval("document." + str_form_name);
	for(var i=0; i<obj_form.length; i++)
	{
		if(obj_form.elements[i].type == "checkbox")
		{
			var str_checkbox_name = new String(obj_form.elements[i].name);
			if(str_checkbox_name.indexOf(str_search_chars) != -1)
			{
				var obj_checkbox = eval("document." + str_form_name + "." + str_checkbox_name);
				if(eval("document." + str_form_name + "." + str_select_all + ".checked")==true)
					obj_checkbox.checked  = true;
				else
					obj_checkbox.checked = false;
			}
		}
	}
}

//unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
function func_unselect_checkbox(str_form_name,str_search_chars,str_select_all)
{
	var b_correct=true;
	var obj_form=eval("document." + str_form_name);
	for(var i=0; i<obj_form.length; i++)
	{
		if(obj_form.elements[i].type == "checkbox")
		{
			var str_checkbox_name = new String(obj_form.elements[i].name);
			if(str_checkbox_name.indexOf(str_search_chars) != -1)
			{
				var obj_checkbox = eval("document." + str_form_name + "." + str_checkbox_name);
				if(obj_checkbox.checked==false)
					b_correct=false;
			}
		}
	}
	var obj_checkbox_all=eval("document." + str_form_name + "." + str_select_all);
	if (obj_checkbox_all != null)
	{
		if(b_correct)
			obj_checkbox_all.checked=true;
		else
			obj_checkbox_all.checked=false;
	}
}

//selected checkbox values are stored in the hidden field with "," as delimiter
function func_store_selected_checkboxes(str_form_name,str_hidden_name,str_search_chars)
{
	var obj_form=eval("document." + str_form_name);
	var obj_hidden=eval("document." + str_form_name + "." + str_hidden_name);
	var i_length=str_search_chars.length;
	eval("document." + str_form_name + "." + str_hidden_name).value="";
	for(var iLoop=0;iLoop<obj_form.elements.length;iLoop++)
	{
		if(obj_form.elements[iLoop].type=="checkbox")
		{
			var str_checkbox_name=new String(obj_form.elements[iLoop].name);
			if(str_checkbox_name.slice(0,i_length)==str_search_chars)
			{
				if(obj_form.elements[iLoop].checked==true)
				{
					obj_hidden.value+=(obj_hidden.value=="") ? str_checkbox_name.slice(i_length) : ("," + str_checkbox_name.slice(i_length));
				}
			}
		}
	}		
	//alert(obj_hidden.value);
}	

function func_is_checkbox_selected(obj_form,str_checkbox_prefix)
{
	var b_correct=false;
	for(var i=0; i<obj_form.elements.length; i++)
	{
		var str_name=obj_form.elements[i].name;
		var str_type=obj_form.elements[i].type;
		if((str_type=="checkbox") && (str_name.indexOf(str_checkbox_prefix)!=-1))
		{
			var b_checked=obj_form.elements[i].checked;
			if(b_checked==true)
			{
				b_correct = true;
				break;
			}
		}
	}
	return b_correct;
}
	 

/*  Validation functions starts here..... */
function invalidemail(y)
{
	var len = y.length;
	if (len < 1)
	{
		return true;
	}
	var i = 0;
	for (i=0; i<len; i++)
	{
		if (!((y.charCodeAt(i) >= 65 && y.charCodeAt(i) <= 90)
		  || (y.charCodeAt(i) >= 97 && y.charCodeAt(i) <= 122)
		  || (y.charCodeAt(i) >= 48 && y.charCodeAt(i) <= 57)
		  || (y.charAt(i) == "@")
		  || (y.charAt(i) == "_")
		  || (y.charAt(i) == ".")))
		{
			return true;
		}
	}
	var at = y.indexOf("@");
	if (at < 0)
	{
		return true;
	}
	i = 0;
	var dot;
	dot = y.indexOf(".", at);
	if (!(dot > 1))
	{
		return true;
	}
	return false;
}

function isValidURL(strText)
{
	var bcorrect=true;
	if(bcorrect && isNull(strText))
	{
		return true;
	}
	if(bcorrect && strText.indexOf("/")!=-1)
	{
		strText=strText.substring(0,strText.indexOf("/"));
	}
	
	var len = strText.length;
	
	//validate the characters allowed
	if(bcorrect)
	{	
		var i = 0;
		for (i=0; i<len; i++)
		{
			if (!((strText.charCodeAt(i) >= 65 && strText.charCodeAt(i) <= 90)
			  || (strText.charCodeAt(i) >= 97 && strText.charCodeAt(i) <= 122)
			  || (strText.charCodeAt(i) >= 48 && strText.charCodeAt(i) <= 57)
			  || (strText.charAt(i) == "-")
			  || (strText.charAt(i) == "_")
			  || (strText.charAt(i) == ".")))
			{
				bcorrect=false;
			}
		}
	}
	
	if(bcorrect && strText.indexOf("..")!=-1)
		bcorrect=false;
	if(bcorrect && strText.indexOf("-")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf("_")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf(".")==0)
		bcorrect=false;
	if(bcorrect && strText.indexOf(".")==-1)
		bcorrect=false;
	
	//validate last index of '.' and number of chars next to that
	if(bcorrect)
	{
		var iLastPos=strText.lastIndexOf('.');
		var iMinChar=len - iLastPos;
		if(iMinChar<3 || iMinChar>5)
			bcorrect=false;
	}
	
	//validate extension
	if(bcorrect)
	{
		var strExtension=strText.substring(strText.lastIndexOf('.')+1);
		if(!isAlphaNumeric(strExtension))
			bcorrect=false;
	}
	return bcorrect;
}

function isNotNumeric(n)
{
	if (n == "")
	{
		return true;
	}
	var len = n.length;
	var i = 0;
	for (i=0; i<len; i++)
	{
		if (!((n.charCodeAt(i) >= 48) && (n.charCodeAt(i) <= 57)))
		{
			return true;
		}
	}
	return false;
}

function containsBlank(s)
{
	var len = s.length;
	for (i=0; i<len; i++)
	{
		if (s.charAt(i) == " ")
		{
			return true;
		}
	}
	return false;
}

function isBlank(StrText)
{
	if (StrText.length < 0)
	{
		return true;
	}
	for (var i=0; i<StrText.length; i++)
	{
		if (StrText.charAt(i) != " ")
		{
			return false;
		}
	}
	return true;
}

function getSelectedOption(OItem)
{
	var optionValue = "";
	for (var i=0; i<OItem.length; i++)
	{
		if (OItem.options[i].selected == true)
		{
			 optionValue = OItem.options[i].value;
			 return optionValue;
		}
	}
}

function optionSelected(OItem)
{
	for (var i=0; i<OItem.length; i++)
	{
		if ((OItem.options[i].selected == true) && (OItem.options[i].value != ""))
		{
			return true;
		}
	}
	return false;
}

function isValidDate(iYear, iMonth, iDay)
{ 
	if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
	{
	  return false;
	}
		var dtNewDate = new Date(iYear, (iMonth-1), iDay);
		if ((parseInt(dtNewDate.getFullYear()) == iYear)
			&& (parseInt(dtNewDate.getMonth()) == (iMonth-1))
			&& (parseInt(dtNewDate.getDate()) == iDay))
		{
			return true;
		}
	return false;
}

//Returns true if "text" is alphanumeric
function isAlphaNumeric(text)
{
	var str = new String(text);
	for (var i=0;i<str.length;i++)
	{
		if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
		{
			return false; 
		}
	 }
	return true;
}

// returns true if the given text is Null
function isNull(text)
{
	if((trim(text) == "") || (text == null))
	{
		//alert("Must not be Null Sring");
		return true;
	}
	else
	{
		return false;
	}
}

// returns true if length of the text is greater than given num.
function isMaxLength(text,num)
{
	var strlen;
	var text=new String(text);
	strlen = len(text);
	if (strlen > num)
	{
		//alert(" Must not be greater than maximum " + num + " characters ");
		return true;
	}
	else
	{
		return false;
	}
}

// returns true if length of the text is less than given value.
 function isMinLength(text,num)
{
	var strlen;
	var text=new String(text);
	strlen = len(text);
	if (strlen < num)
	{
		//alert(" Must not be Less than minimum " + num + " characters ");
		return true;
	}
	else
	{
		return false;
	}
}

// returns true if the text is Number and false if it is not a number.
function isNumber(text)
{
	var ilen;
	var bflagNum=true;
	var text=new String(text);
	if (isNaN(text))
	{
		return false;
	}
	else
	{
		if(func_is_positive_integer(text))
		return true;
		else
		return false;
	}
}

// returns true if valid Email.
function isEmail(emailval)
{
	var tempStr,icount;
	var blnmail,blnperiod; 
	var lastoccofperiod,maxthree;
	var ampicount=0;
	var amppos;
	var servername = 1;
	var dots;
	icount=emailval.length;
	blnperiod = 1;
	maxthree = 1;
	specialchar = 0
	lastoccofperiod = 0;
	if (icount==0)
	{
		return true;
	}
	for(i=0;i<icount;i++)
	{
		tempStr = emailval.charAt(i);
		if ((tempStr >='a')&&(tempStr <='z'))
		{
			specialchar=specialchar+1;
		}
		else
		{
			if ((tempStr >='A')&&(tempStr <='Z'))
			{
				specialchar=specialchar+1;
			}
			else
			{
				if ((tempStr >= 0)&&(tempStr<=9))
				{
					specialchar=specialchar+1;
				}
				else
				{
					if ((tempStr=='_')||(tempStr=='-')||(tempStr=='.')||(tempStr=='@'))
					{
						specialchar=specialchar+1;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}
	dots = emailval.indexOf('..');
	if (dots != -1)
	{
		return false;
	}
	espace = emailval.indexOf(' ');
	if (espace != -1)
	{
		return false;
	}
	lastoccofperiod = emailval.lastIndexOf('.');
	if (lastoccofperiod <= 0)
	{
		blnperiod = 0;
	}
	if (((icount - lastoccofperiod) > 5)||((icount - lastoccofperiod) < 3))
	{
		maxthree = 0;
	}
	 for(i=0;i<=icount;i++)
	{
		tempStr = emailval.charAt(i)
		if (tempStr=='@')
		ampicount=ampicount + 1;
	}
	amppos = emailval.indexOf('@');
	if (emailval.charAt(amppos+1) == '.')
	servername = 0;
	if(icount - emailval.charAt(amppos)< 5) 
	servername = 0;
	if ((ampicount==1)&&(blnperiod==1)&&(maxthree==1)&&(servername==1))
	{
		blnmail=1;
	}
	else
	{
		 blnmail=0;
	}
	 //return blnmail;
	if (blnmail==0)
	{
		//alert('Please enter a valid email address');
		return false;
	}
	else
	{
		return true;
	}
 }

//returns true if the text carries only alphabets.
function isAlphabetic(textval)
{
	var text=new String(textval);
	var ilen;
	var bflag=true;
	for(ilen=0;ilen<=text.length;ilen++)
	{
		if(text.charCodeAt(ilen) < 65 || text.charCodeAt(ilen) > 90 && text.charCodeAt(ilen) < 97 || text.charCodeAt(ilen) > 122)
		{
			bflag=false;
		}
	}
	return bflag;
}

function isCurrency(text)
{
	var bflag=true;
	if(text != "")
	{
		var k = len(text);
		var i;
		for (i=0; i<k; i++)
		{
			if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == ".")))
			{
				bflag=false;
			}
		}
	}
	return bflag;
}
//isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.()
function isTelephoneNumber(text)
{
	var bflag=true;
	if(text != "")
	{
		var k = len(text);
		var i;
		for (i=0; i<k; i++)
		{
			if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == "-")|| (text.charAt(i) == "(")|| (text.charAt(i) == ")") || (text.charAt(i) == "+") || (text.charAt(i) == ".")|| (text.charAt(i) == " ")))
			{
				bflag=false;
			}
		}
	}
	return bflag;
}

//returns true if it is valid date.
function isDate(date,month,year)
{ 
	var bflag=true;
	if (isNaN(year) || isNaN(month) || isNaN(date))
	{
		bflag=false;
	}
	if(bflag)
	{
		var dtnew = new Date(year,month-1,date);
		if ((parseInt(dtnew.getFullYear()) == year) && (parseInt(dtnew.getMonth()) == (month-1)) && (parseInt(dtnew.getDate()) == date))
		{
			bflag=true;
		}
		else
		{
			bflag=false;
		}
	}
	return bflag;
}

//returns string by removing whitespaces from both the ends.
function trim(text)
{
	var stext = new String(text);
	var sresult = "";
	//Remove leading spaces
	for (var i=0; i<stext.length; i++)
	{
		if (stext.charAt(i) != " ")
		{
			sresult = stext.substr(i, (stext.length - i));
			break;
		}
	}
	stext = sresult;
	//Remove trailing spaces
	for (var j=(stext.length - 1); j>=0; j--)
	{
		if (stext.charAt(j) != " ")
		{
			sresult = stext.substr(0, (j + 1));
			break;
		}
	}
	return sresult;
}

// returns length of the text
function len(text)
{
	var strText=new String(text);
	return strText.length;
}

// selecting & focusing on the element that holds incorrect value
function selectFocus(element)
{
	element.select();
	element.focus();
	return true;
}

//returns true if a radio button is checked
function IsRadioChecked(objForm,strName)
{
	var bcorrect;
	bcorrect=false;
	for(i=0; i<objForm.elements.length; i++)
	{
		var name=objForm.elements[i].name;
		var type=objForm.elements[i].type;
		if((type=="radio") && (name.indexOf(strName)!=-1))
		{
			var val=objForm.elements[i].checked;
			if(val==true)
			{
				bcorrect=true;
				break;
			}
		}
	}	
	return bcorrect;
}

//returns true if atleast one check box is selected
function IsCheckboxSelected(objForm,strName)
{
	var bcorrect=false;
	for(var i=0; i<objForm.elements.length; i++)
	{
		var name=objForm.elements[i].name;
		var type=objForm.elements[i].type;
		if((type=="checkbox") && (name.indexOf(strName)!=-1))
		{
			var val=objForm.elements[i].checked;
			if(val==true)
			{
				bcorrect = true;
				break;
			}
		}
	}
	return bcorrect;
}	

/*  Validation functions ends here. */



/*  HTML Element Validation functions starts here..... */

//HTML Element "Text box" validations (includes text area also.)
function ValidateTextBox(strName,obj,bZeroLength,iMaxChars,bAlphabet,bNumeric,bAlphanumeric,bEmail,bTelNumber,bURL,bFile,strFileType,bCurrency)
{
	var bCorrect=true;
	
	//Zerolength validation is optional, if bZeroLength is true then textbox value is checked for zerolength.
	if(bCorrect && bZeroLength)
	{
		if(isNull(obj.value))
		{
			bCorrect=false;
			alert("Please enter " + strName + ".");
			selectFocus(obj);
		}
	}
	
	//MaxLength is not optional
	if(bCorrect)
	{
		if(isMaxLength(obj.value,iMaxChars))
		{
			bCorrect=false;
			alert(strName + " is greater than " + iMaxChars + " characters.");
			selectFocus(obj);
		}
	}
	
	//Alphabet validation is optional, if bAlphabet is true then textbox value is checked for Alphabets.
	if(bCorrect && bAlphabet)
	{
		if(!isAlphabetic(obj.value))
		{
			bCorrect=false;
			alert(strName + " must have only alphabets.");
			selectFocus(obj);
		}
	}
	
	//Numeric validation is optional, if bNumeric is true then textbox value is checked for Numeric.
	if(bCorrect && bNumeric)
	{
		if(!isNumber(obj.value))
		{
			bCorrect=false;
			alert(strName + " must have only numbers.");
			selectFocus(obj);
		}
	}

	//Alphanumeric validation is optional, if bAlphanumeric is true then textbox value is checked for Alphanumeric.
	if(bCorrect && bAlphanumeric)
	{
		if(!isAlphaNumeric(obj.value))
		{
			bCorrect=false;
			alert(strName + " must have only alphanumeric characters.");
			selectFocus(obj);
		}
	}		

	//Email validation is optional, if bEmail is true then textbox value is checked for Email.
	if(bCorrect && bEmail)
	{
		if(!isEmail(obj.value))
		{
			bCorrect=false;
			alert(strName + " entered is not a valid email address.");
			selectFocus(obj);
		}
	}			

	//TelNumber validation is optional, if bTelNumber is true then textbox value is checked for TelNumber.
	if(bCorrect && bTelNumber)
	{
		if(!isTelephoneNumber(obj.value))
		{
			bCorrect=false;
			alert(strName + " is not a valid telephone/fax number.");
			selectFocus(obj);
		}
	}	
	
	//URL validation is optional, if bURL is true then textbox value is checked for URL.
	if(bCorrect && bURL)
	{
		if(!isValidURL(obj.value))
		{
			bCorrect=false;
			alert(strName + " is not a valid URL.");
			selectFocus(obj);			
		}
	}
	if(bCorrect && bFile)
	{
		if(!isFile(obj.value,strFileType))
		{
			bCorrect=false;
			alert(strName + " is not a valid File Type.");
			selectFocus(obj);
		}
	}
	if(bCorrect && bCurrency)
	{
		if(!isCurrency(obj.value))
		{
			bCorrect=false;
			alert(strName + " is not a valid number.");
			selectFocus(obj);
		}
	}
	return bCorrect;
}


//HTML Element "Drop-down list" validations
function ValidateDropdownList(strName,obj,bSelect,iMaxChars)
{
	var bCorrect=true;
	
	//Select validation is optional, if bSelect is true then textbox value is checked for Selection.
	if(bCorrect && bSelect)
	{
		if(getSelectedOption(obj)=="")
		{
			bCorrect=false;
			alert(strName + " is not selected.");
			obj.focus();
		}
	}

	//MaxLength is not optional
	if(bCorrect)
	{
		if(isMaxLength(getSelectedOption(obj),iMaxChars))
		{
			bCorrect=false;
			alert(strName + " is greater than " + iMaxChars + " characters.");
			obj.focus();
		}
	}
	
	return bCorrect;
}

//HTML Element "Radio button" validations
function ValidateRadioButton(strLabel,strRadioName,objForm,bChecked)
{
	var bCorrect=true;
	
	//Radio button validation is optional, if bChecked is true then it is checked for Selection.
	if(bCorrect && bChecked)
	{
		if(!IsRadioChecked(objForm,strRadioName))
		{
			bCorrect=false;
			alert(strLabel + " is not selected.");
		}
	}
	return bCorrect;
}

//HTML Element "Check box" validations
function ValidateCheckBox(strLabel,strCheckBoxName,objForm,bChecked)
{
	var bCorrect=true;
	
	//Check box validation is optional, if bChecked is true then it is checked for Selection.
	if(bCorrect && bChecked)
	{
		if(!IsCheckboxSelected(objForm,strCheckBoxName))
		{
			bCorrect=false;
			alert(strLabel + " is not selected.");
		}
	}
	return bCorrect;
}

// validate date box.
function ValidateDateBox(strLabel,obj,iDay,iMonth,iYear,bSelected,bFutureDate,bPastDate)
{
	var bcorrect=true;
	if(bSelected)
	{
		if(bcorrect && !isDate(iDay,iMonth,iYear))
		{
			bcorrect=false;
			alert("Please select a valid " + strLabel + ".");
			obj.focus();
		}
	}
	if(iDay!="" && iMonth!="" && iYear!="")
	{
		if(bcorrect && !isDate(iDay,iMonth,iYear))
		{
			bcorrect=false;
			alert("Please select a valid " + strLabel + ".");
			obj.focus();
		}
	}
	if (bFutureDate)
	{
		if(bcorrect)
		{
			var dtnew = new Date(iYear,iMonth-1,iDay);
			var dtnow = new Date();
			if(dtnew<dtnow)
			{
				bcorrect=false;
				alert("Please select a valid future date.");
				obj.focus();
			}
		}
	}
	if(bPastDate)
	{
		if(bcorrect)
		{
			var dtnew = new Date(iYear,iMonth-1,iDay);
			var dtnow = new Date();
			if(dtnew>dtnow)
			{
				bcorrect=false;
				alert("Please select a valid past date.");
				obj.focus();
			}
		}
	}
	return bcorrect;
}


//select All checkboxes starting with..
function SelectAllCheckBoxes(strFormName,strSearchChars,strSelectAll)
{
	var objForm=eval("document." + strFormName);
	for(var i=0; i<objForm.length; i++)
	{
		if(objForm.elements[i].type == "checkbox")
		{
			var strCheckBoxName = new String(objForm.elements[i].name);
			if(strCheckBoxName.indexOf(strSearchChars) != -1)
			{
				var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
				if(eval("document." + strFormName + "." + strSelectAll + ".checked")==true)
					objCheckBox.checked  = true;
				else
					objCheckBox.checked = false;
			}
		}
	}
}

//unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
function UnSelectCheckBox(strFormName,strSearchChars,strSelectAll)
{
	var bcheckbox=true;
	var objForm=eval("document." + strFormName);
	for(var i=0; i<objForm.length; i++)
	{
		if(objForm.elements[i].type == "checkbox")
		{
			var strCheckBoxName = new String(objForm.elements[i].name);
			if(strCheckBoxName.indexOf(strSearchChars) != -1)
			{
				var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
				if(objCheckBox.checked==false)
					bcheckbox=false;
			}
		}
	}
	var objCheckBoxAll=eval("document." + strFormName + "." + strSelectAll);
	if (objCheckBoxAll != null)
	{
		if(bcheckbox)
			objCheckBoxAll.checked=true;
		else
			objCheckBoxAll.checked=false;
	}
}

//selected checkbox values are stored in the hidden field with "," as delimiter
function StoreSelectedCheckBoxes(strFormName,strHiddenName,strSearchChars)
{
	var objForm=eval("document." + strFormName);
	var objHidden=eval("document." + strFormName + "." + strHiddenName);
	var iLen=strSearchChars.length;
	eval("document." + strFormName + "." + strHiddenName).value="";
	for(var iLoop=0;iLoop<objForm.elements.length;iLoop++)
	{
		if(objForm.elements[iLoop].type=="checkbox")
		{
			var strCheckBoxName=new String(objForm.elements[iLoop].name);
			if(strCheckBoxName.slice(0,iLen)==strSearchChars)
			{
				if(objForm.elements[iLoop].checked==true)
				{
					objHidden.value+=(objHidden.value=="") ? strCheckBoxName.slice(iLen) : ("," + strCheckBoxName.slice(iLen));
				}
			}
		}
	}		
	//alert(objHidden.value);
}	

//Checks whether file type is ends with specified extension or not

function isFile(strValue,strFileType)
{
	var bCorrect=false;
	strImage=new String(strValue);
	var bHtml=false;
	var bAll=false;
	var bImage=false;
	if(strValue.length==0)
	{
		return true;
	}
	if(strFileType.toLowerCase()=="htm" || strFileType.toLowerCase()=="html")
	{
		bHtml=true;
	}
	if(strFileType.toLowerCase()=="all")
	{
		bAll=true;
	}
	if(strFileType.toLowerCase()=="img")
	{
		bImage=true;
	}
	if(strImage.indexOf(".")!=-1)
	{
		iIndex=strImage.indexOf(".");
		if(bAll==true)
		{
			strFile=strImage.substring(iIndex+1);
			if(strFile.length>=2 && strFile.length<250)
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else	if(bImage==true)
		{
			if((strImage.substring(iIndex+1)).toLowerCase()=="gif" || (strImage.substring(iIndex+1)).toLowerCase()=="jpg" || (strImage.substring(iIndex+1)).toLowerCase()=="jpeg" || (strImage.substring(iIndex+1)).toLowerCase()=="bmp")
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else	if(bHtml==true)
		{
			if((strImage.substring(iIndex+1)).toLowerCase()=="htm" || (strImage.substring(iIndex+1)).toLowerCase()=="html")
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
		else
		{
			if((strImage.substring(iIndex+1)).toLowerCase()==strFileType.toLowerCase())
			{
				bCorrect=true;
				return bCorrect;
				
			}
			else
			{
				bCorrect=false;
				return bCorrect;
				
			}
		}
	}
	else
	{
		bCorrect=false;
		return bCorrect;
	}
}
/*  HTML Element Validation functions ends here. */