function hasAttribute(attribute) 
{
	var has=this.getAttribute(attribute);
    return (has==null) ? false : true;
}


function validateGetValueOf(o) {

	var value="";

	if(typeof(o)=="object") {

		switch(o.type) {

			case "select":

		            var i=o.options.SelectedIndex;
		            value=(i!=-1) ? o.options[i].value : "";
            break;

			case "checkbox":
			case "radio":
            case "input":
            case "textarea":
            case "file":

            default:
		            return o.value;
					break;
		}
	}

	return value;
}


function Validate(objectname, fieldname, MM)
{
	if(!objectname.hasAttribute) objectname.hasAttribute=hasAttribute;
	if(objectname.hasAttribute('pattern')) {
            				
		var pattern = new RegExp(objectname.getAttribute('pattern'));
        var value	= validateGetValueOf(objectname);
							
		if (pattern != '/null/') {
								
				var offendingChar = value.match(pattern);
				
				if(offendingChar == null) {

                		if (MM=="") {
							
							objectname.hasAttribute('errorMsg') ? ValidateError(objectname,objectname.getAttribute('errorMsg')):ValidateError(objectname,"Parse error in form ! --"+fieldname+"\n");							
						
						} else {
							
							return(false);
						}
						 
				} else {
					
					objectname.style.borderColor = "#cccccc";
					
				}							
		}
							
	}
	
	
	return(true);	
}


function ValidateError(objectname, text)
{
	var text = text
	
	objectname.style.borderColor = "red";
	objectname.style.color = "red";
	
	alert('* '+text);
}
