
	re_emal = /^[\w-\.]+\@[\w\.-]+\.[\w\.-]+$/;
	re_name = '';
	
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 5;
	
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars)
return (isInteger(s) && s.length > minDigitsInIPhoneNumber)
}
	
	function validate() {
	//	o_form.elements['Submit'].disabled = true;
		o_form = document.forms['add'];

		clear_errors ();
		a_errors = [];
	
		// check if name is entered
		o_txtname = o_form.elements['txtName'];
		// check if comment is entered
		o_txtphone = o_form.elements['txtPhone'];
		// check if comment is entered
		o_txtcomments = o_form.elements['txtComments'];
		
		if (!o_txtname.value)
			a_errors[a_errors.length] = {'t': 'Your Name is required.', 'f': 'add_name'};
		
		// check if e-mail address is entered
		o_txtemail = o_form.elements['txtEmail'];
		if (!o_txtemail.value)
			a_errors[a_errors.length] = {'t': 'Your E-mail is required.', 'f': 'add_email'};
	
		if (!o_txtphone.value)
			a_errors[a_errors.length] = {'t': 'Your Phone Number is required.', 'f': 'add_phone'};
		else if ((checkInternationalPhone(o_txtphone.value)==false))
			a_errors[a_errors.length] = {'t': 'Invalid Phone Number format.', 'f': 'add_phone'};
			
		if (o_txtemail.value && !re_emal.exec(o_txtemail.value))
			a_errors[a_errors.length] = {'t': 'Invalid E-mail format.', 'f': 'add_email'};
		
		if (!o_txtcomments.value)
			a_errors[a_errors.length] = {'t': 'Your Comments are required', 'f': 'add_comments'};
			
		if (a_errors.length) {
			error(a_errors, 'add');
			return false;
		}
		report('Sending...', 'add');
		o_form.submit();
	}
	
	function clear_errors() {
		a_areas = ['add_error', 'error_box'];
		a_captions = ['add_name', 'add_email', 'add_comments','add_phone'];
		
		for (var n_i = 0; n_i < a_areas.length; n_i++) {
			e_errbox = document.getElementById(a_areas[n_i]);
			if (e_errbox && e_errbox.innerHTML) {
				e_errbox.style.display = 'none';
				e_errbox.innerHTML = '';
			}
		}
		for (var n_i = 0; n_i < a_captions.length; n_i++) {
			e_caption = document.getElementById(a_captions[n_i]);
			e_caption.style.color = '#000';
			e_caption.style.fontWeight = 'normal';
		}
	}
	
	function error (a_errors, s_area) {
		e_errbox = document.getElementById((s_area + '_error'));
		s_message = '';
		
		if (a_errors.length == 1) {
			s_message = '<table cellpadding="4" cellspacing="0" border="0" width="100%"><tr><td valign="top" width="30"><b><font color="red">Error:</font></b></td><td>' + a_errors[0]['t'] + '</td></tr></table>';
		}
		else {
			s_message = '<table cellpadding="4" cellspacing="0" border="0" width="100%"><tr><td valign="top" width="30"><b><font color="red">Errors:</font></b></td><td nowrap><ul style="margin-top:0px;margin-bottom:3px;margin-left:15px; margin-left: 20; text-align:left; text-indent:0; margin-right:0; padding-left:0">';
			for (n_i = 0; n_i < a_errors.length; n_i++) {
				s_message += '<li>' + a_errors[n_i]['t'] + '</li>';
			}
			s_message += '</ul></td></tr></table>';
		}
		
		if (e_errbox && e_errbox.innerHTML != null) {
			e_errbox.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td bordercolor="#000" bordercolorlight="#000" bordercolordark="#000">  <table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse: collapse" bordercolor="#111111"><tr> <td style="border:1px solid #fff; color: #008000;">' + s_message + '</td></tr></table></td></tr></table><br>';
			e_errbox.style.display = 'block';
		}
		for (n_i = 0; n_i < a_errors.length; n_i++)
			if (a_errors[n_i]['f']) {
				e_caption = document.getElementById(a_errors[n_i]['f']);
				e_caption.style.color = '#FF0000';
				e_caption.style.fontWeight = 'bold';
			}
		//o_form.elements['Submit'].disabled = false;
	}
	
	function report (s_message, s_area) {
		e_msgbox = document.getElementById(s_area + '_error');
		if (e_msgbox && e_msgbox.innerHTML != null) {
			e_msgbox.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td> <table cellpadding="5" cellspacing="0" border="1" width="100%" style="border-collapse: collapse" bordercolor="#FFFFFF"><tr>  <td style="border:1px solid #fff; color: #008000"><b>Accepted: </b>' + s_message + '</td></tr></table></td></tr></table><br>';
			e_msgbox.style.display = 'block';
		}
	}
