function popup(url,type)
{
	var str = "";
	var name = ""
    if (url)
    {
        var newWin = window.open(url,name,str);
        newWin.focus();                                    
    }

}

function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

function validateContactForm() 
{
	var error = "";
	var form = document.forms['contact_us'];
	if(trim(form.realname.value) == "")
	{
		error = error + "The name field is empty, please enter your name.\n";
	}
	if(trim(form.email.value) == "")
	{
		error = error + "The email field is empty, please enter your email.\n";
	}
	else
	{
		if(echeck(form.email.value)==false)
		{
			error = error + "The email field is not a valid email address.\n";
		}
	}
	if(trim(form.subject.value) == "")
	{
		error = error + "The subject field is empty, please enter the subject of your message.\n";
	}
	if(trim(form.msg.value) == "")
	{
		error = error + "The message field is empty, please enter your message.\n";
	}

	if(error != "")
	{
		error = "Errors have been found in the submitted data.  Please correct these errors before continuing:\n\n" + error;
		alert(error);
		return false;
	}

	return true;

}
