var Bright = 'hlight';
var Default= '';



function hl(el, style){el.className = style;}


function notEmpty(elem, err) 
{
    var str = elem.value;

    if(str == null || str.length == 0) 
	{
		hl(elem, Bright);
		errorString+=err; 
		return false;
	}
	else 
	{
		hl(elem,Default);
		return true;
	}
}


function validEmail(elem, err)
{
    if(elem.value.length > 0)
	{
		var str = elem.value;
	    var splitted = str.match("^(.+)@(.+)$");

	    if(splitted !== null && splitted[1] !== null)
		{
	    	var regexp_user=/^\"?[\w-_\.]*\"?$/;
		    if(splitted[1].match(regexp_user) !== null && splitted[2] !== null)
			{
		    	var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if((splitted[2].match(regexp_domain) !== null) || (splitted[2].match(regexp_ip) !== null))
				{
					hl(elem,Default);
					return true;
				}
			}
		
		}
	}
	hl(elem, Bright);
	errorString+=err;
	return false;
}


function notSelected(elem, err, ind) 
{
    var str = elem.selectedIndex;

    if(str==ind) 
	{
		hl(elem, Bright);
		errorString+=err; 
		return false;
	}
	else 
	{
		hl(elem,Default);
		return true;
	}
}

function popwin(newURL, w, h) 
{
 	window.open(newURL, "newwin","toolbar=no, width="+w+",height="+h+",location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no");
}


function validateForm(formname)
{
	errorString = "Please fill in following fields:     \n-------------------------------\n";

	var Results = [
	notEmpty(formname.b_fname, 'Your name \n'),
	notEmpty(formname.org_name, 'Organisation name \n'),
	notEmpty(formname.b_phone, 'Phone\n'),
	validEmail(formname.b_email, 'Email (should be valid) \n'),
	];

	if (Results[0] && Results[1] && Results[2])
	{
		popwin('sendinfo.php',380,120);
		return true;
	}
	else
	{
		alert(errorString);
		return false;
	}
}


