String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


function is_required (aform)
{

	aform.form_err_msg.style.height="1";
	form_required_message="";	
	element_count = aform.elements.length;
	
	aform.form_err_msg.value = form_required_message;
	aform.form_err_msg.style.visibility = "hidden";	
	
	radio_count=0;
		
	for (i=0; i<element_count; i++)
	{
		var element = aform.elements[i]; 

		element_name = element.name;
		element_type = element.type;
		element_required = element.getAttribute('required');
		element_err_msg = element.getAttribute('err_msg');
		element_span_id = element.getAttribute('span_id');
		
		//alert(element_type);
		
		if (element_required>0)
		{
			if (element_type=="text")
			{
				element.value = element.value.trim();
				if (element.value.trim()=="")
				{
					form_required_message += element_err_msg+"\n";
					element.style.border = "1px solid #800000";
					element.style.backgroundColor = "#FFC4C4";
				}
				else
				{
					element.style.border = "1px solid #006600";
					element.style.backgroundColor = "#FFFFFF";
				}
			}
			
			
			if (element_type=="radio")
			{
				isfound=false;
				for (a=0; a<element_count; a++)
				{
					var temp_element = aform.elements[a];
					temp_element_name = temp_element.name;
					temp_element_type = temp_element.type;

					if ((element_type=="radio") && (temp_element_name==element_name))
					{
						//alert(temp_element.name+":"+temp_element.checked)
						if (temp_element.checked==true)
						{
							isfound=true;
						}
					}
									
				}
				if (!isfound)
				{
					form_required_message += element_err_msg+"\n";
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.backgroundColor = "#FFC4C4";
					}
				}
				else
				{
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.backgroundColor = "#FFFFFF";
					}				
				}
			}
			
			if (element_type=="checkbox")
			{
				isfound=false;
				for (a=0; a<element_count; a++)
				{
					var temp_element = aform.elements[a];
					temp_element_name = temp_element.name;
					temp_element_type = temp_element.type;

					if ((element_type=="checkbox") && (temp_element_name==element_name))
					{
						if (temp_element.checked==true)
						{
							isfound=true;
						}
					}
									
				}
				if (!isfound)
				{
					form_required_message += element_err_msg+"\n";
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.backgroundColor = "#FFC4C4";
					}
				}
				else
				{
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.backgroundColor = "#FFFFFF";
					}				
				}
			}
			
			if (element_type=="select-one")
			{
				temp = element.selectedIndex;
				var tempselectedvalue = element.options[temp].value;
				if (element.value.trim()=="")
				{
					form_required_message += element_err_msg+"\n";
					element.options[temp].style.backgroundColor = "#FFC4C4";
					element.options[temp].style.background = "#FFC4C4";
					
					
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.border = "1px solid #800000";
					}
				}
				else
				{
					element.style.border = "1px solid #006600";
					element.options[temp].style.backgroundColor = "#FFFFFF";
					element.options[temp].style.background = "#FFFFFF";
					if( element_span_id !="null")
					{
						document.getElementById(element_span_id).style.border = "2px solid #FFFFFF";
					}
				}			
			}	
			
			
			if (element_type=="select-multiple")
			{		
				isfound=false;
			
				for(var a=0; a<element.options.length; a++)
				{
					if(element.options[a].selected)
					{
						isfound=true;
					}
	
				}
				if (!isfound)
				{
					form_required_message += element_err_msg+"\n";
					element.style.backgroundColor = "#FFC4C4";
				}
				else
				{
					element.style.backgroundColor = "#FFFFFF";			
				}
			}			
			
			
			
			
		}
			

	}
	
	
	if (form_required_message!="")
	{
		
		aform.form_err_msg.value = form_required_message;
		aform.form_err_msg.style.visibility = "visible";
		aform.form_err_msg.style.height="60";
		return false;
	}	
	
	
	return true;
}


function confirm_delete()
{
      return confirm("Warning:\n\nYou are about to permanently delete a record.\n\nPress [OK] to proceed or [Cancel]");
     //  onsubmit="return confirm_save();"
}