function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if(lstr == 0){
			return false
		}
		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){
		    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					
	}
/*Img rollover function*/
function rollover(name,source){
    document.images[name].src=source;
}
function popup(theURL) {

    var centerX = 10;
    var centerY = 10;

        windowprops = "top=" + centerY + ",left=" + centerX + ",resizable=no" + ",width=500,height=500";

        window.open(theURL, "Details", windowprops);
}

function popup(w,h,theURL) {

    var centerX = 10;
    var centerY = 10;

        windowprops = "top=" + centerY + ",left=" + centerX + ",scrollbars=yes,resizable=no" + ",width="+w+",height="+h;

        window.open(theURL, "Details", windowprops);
}




function validateContactForm(form, optional){
	if(optional == ""){
		optional = [];
	}
	requiredPass = true;
	$(form).find(":input[type!=hidden]").each(function(){
		//is this field required? (or not found in the optional array)
		if(optional.toString().indexOf($(this).attr("id")) === -1){
			var id = $(this).attr('id');
			//$('#messages').hide().addClass('error').append('<p>Checking Field ('+id+')</p>').fadeIn();
			if($(this).attr("value") == ""){
				$('#messages').hide().addClass('error').append('<p>'+id+' is a required field!</p>').fadeIn();
				$(this).css('border',"1px solid red");
				requiredPass = false;
			}
		}
	});
	if(!requiredPass){
		$('#messages').hide().addClass('error').append('<p>Please fill out all required fields before submitting the form.<br/><b>They have been marked in red outline</b></p>').fadeIn();
		return false;
	}


	//check email
	validEmail = echeck($(form).find('#email').attr("value"));
	if(!validEmail){
		$('#messages').hide().addClass('error').append('<p>Invalid Email Address!</p>').fadeIn();
		$(form).find('#email').trigger('focus');
		return false;
	}


	chal = $(form).find('#recaptcha_challenge_field').val();
	resp = $(form).find('#recaptcha_response_field').val();
	recapResult = true;
	$.ajax({
		async: false,
		url: 'ajax_recaptcha.php',
		data: 'recaptcha_challenge_field='+chal+'&recaptcha_response_field='+resp,
		type: 'POST',
		success: function(html){
			if(html == "false"){
				$('#messages').hide().addClass('error').html("<p>The Recaptcha Failed to Match! Please try again.</p>").fadeIn();
				recapResult = false;
			}else if(html == "true"){
				$('#messages').hide().addClass('success').html("<p>The Recaptcha matched!</p>").fadeIn();
			}
				
		}
	});
	if(!recapResult){
		return false;
	}

	return true;
}
