﻿function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function checkemail(emailstr)
{
	var emailFilter = /^(([a-zA-Z0-9_\-]+)|(([a-zA-Z0-9_\-]+)([\.]{1,1}[a-zA-Z0-9_\-]+)+)+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	//emailFilter=/^(([a-zA-Z0-9_\-]+)|(([a-zA-Z0-9_\-]+)([\.]{1,1}[a-zA-Z0-9_\-]{1,}))+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	//emailFilter=/^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$/;

	if (!(emailFilter.test(emailstr))) 
		return false;
	return true;
}


jQuery(document).ready(function(){
    jQuery("#btnSubmit").click(function() {
//        if (jQuery("#captchacode").val() != '') 
//        {
//            jQuery.getJSON("/CaptchaImage.aspx?validateCaptchaCode=" +  jQuery("#captchacode").val() + "&format=json&jsoncallback=?", function(data){
//	
//		        if (data.status == "1")
//		        {
//		        
    	           	if (jQuery("#strName").val() == '')
    	           	{
    	           	    alert('Please enter your name.');
    	           	    return false;
    	           	} 
		            if (!checkemail(jQuery("#strEmail").val()))
		            {
    			        alert('Please enter a valid email address.');
    			        return false;
                    }
    	           	if (jQuery("#strMessage").val() == '')
    	           	{
    	           	    alert('Please enter a message.');
    	           	    return false;
    	           	}
    	           	jQuery("#contactForm").submit();
//		        }
//			    else
//			    {
//				    if (data.session == "0")
//					    RefreshImage("imgCaptcha");
//    				
//				    alert("Please key in the security key correctly.");
//				    jQuery("#captchacode").focus();
//    		
//				    result = false;
//			    }
//		    });
//        }
//        else
//            alert('Please key in the security key correctly.');
    });
//    jQuery("#btnSubmit").css({
//        "display" : "block"
//    });

    jQuery('.emailButton').click(function (){
        if (!checkemail(jQuery("#EmailAddress").val()))
        {
            alert('Please enter a valid email address.');
            return false;
        }
    });
});