function verifyNotify(field1, field2, result_id, match_html, nomatch_html) 
{
	this.field1 = field1;
	this.field2 = field2;
	this.result_id = result_id;
	this.match_html = match_html;
	this.nomatch_html = nomatch_html;
	
	this.check = function() 
	{
		if (!this.result_id) { return false; }
		if (!document.getElementById){ return false; }
		r = document.getElementById(this.result_id);
		if (!r){ return false; }
	
		if (this.field1.value == "" || this.field2.value == "") 
		{
			return false;
		}
	
		else if (this.field1.value == this.field2.value) 
		{
	 		r.innerHTML = this.match_html;
	 		return true;
		} 
		else 
		{
	  		r.innerHTML = this.nomatch_html;
	  		return false;
		}
	}
}



function validateNotifyEmail(field, result_id, match_html, nomatch_html) 
{
	this.field = field;
	this.result_id = result_id;
	this.match_html = match_html;
	this.nomatch_html = nomatch_html;
	
	this.check = function() 
	{
	 
		if (!this.result_id) { return false; }
		if (!document.getElementById){ return false; }
		r = document.getElementById(this.result_id);
		if (!r){ return false; }
		
		if (this.field.value == "") 
		{
			return false;
		}
		else if (checkEmail(this.field.value)) 
		{
	   		r.innerHTML = this.match_html;
	   		return true;
		} 
		else 
		{
	   		r.innerHTML = this.nomatch_html;
	   		return false;
		}
	}
}

function checkEmail(emailAdress) 
{
	var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < emailAdress.length ;i++)
	{
		if	(ok.indexOf(emailAdress.charAt(i))<0)
		{ 
			return (false);
		}	
	} 
	
	if (document.images) 
	{
		var re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		var re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!emailAdress.match(re) && emailAdress.match(re_two)) 
		{
			return (-1);		
		}
	}
}
function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '') ;
}

function validateRequired(field, result_id, required_html)
{
	this.field = field;
	this.result_id = result_id;
	this.required_html = required_html;
	
	this.check = function() 
	{
		
		if (!document.getElementById){ return false; }
		if (this.result_id) 
			r = document.getElementById(this.result_id);
		
				
		with (this.field)
		{
			if (value==null || trim(value) == "")
			{
				if (this.result_id) 
					r.innerHTML = this.required_html;	
				else
				{
					alert(this.required_html);
					focus();
				}
				return false;
			}
			if (this.result_id) 
				r.innerHTML = "";
			return true;
		}
	}
}

function validateNumber(field, result_id, required_html) 
{
	this.field = field;
	this.result_id = result_id;
	this.required_html = required_html;
    
    this.check = function() 
	{
		if (!document.getElementById){ return false; }
			
		with (this.field)
		{
    	   	var pattern = new RegExp("[0-9]+");
       	
		   	if(value.match(pattern))
		     	return true;
 		   	
 		   	if (this.result_id) 
		   	{
		   		r = document.getElementById(this.result_id);
				r.innerHTML = this.required_html;						
		 	}
			else
			{
				alert(this.required_html);
				focus();
			}
			return false;
		}	
	}
}

function validateDate(field, result_id, required_html) 
{
	this.field = field;
	this.result_id = result_id;
	this.required_html = required_html;
    
    this.check = function() 
	{
		if (!document.getElementById){ return false; }
			
		with (this.field)
		{
    	   	// Regular expression used to check if date is in correct format
			var pattern = new RegExp("[0-3][0-9]\/0|1[0-9]\/19|20[0-9]{2}");
       	
		   	if(value.match(pattern))
		    {
		      	var date_array = value.split('/');
		      	var day = date_array[0];
		      	var month = date_array[1] - 1;	//  months in the range 0 - 11
		      	var year = date_array[2];
		
		      	source_date = new Date(year,month,day);
		
		      	if(year == source_date.getFullYear() && month == source_date.getMonth() && day == source_date.getDate())
		    	{
		        	return true;
		      	}
		   	}
 		   
 		   	if (this.result_id) 
		   	{
		   		r = document.getElementById(this.result_id);
				r.innerHTML = this.required_html;						
		 	}
			else
			{
				alert(this.required_html);
				focus();
			}
			return false;
		}	
	}
}
