﻿

        function register_keyDown()
        {

            var isEnter=false;

            if (window.event) 
            {
              if (event.keyCode == 13) isEnter= true;
            }
            else if(e.which == 13) isEnter= true;
           
            if( isEnter )
            {
                BTN_REGISTER_onclick();
                return false;
            }
            else return true;
        }


        function registerFocused()
        {
            if( $("#TXT_REGISTER").val()=="Email address" ) $("#TXT_REGISTER").val("").focus();
        }
        

        function registerBlur()
        {
            if( $("#TXT_REGISTER").val()=="" ) $("#TXT_REGISTER").val("Email address");
        }
        
        

        function captchaFocused()
        {
            if( $("#TXT_CAPTCHA").val()=="Enter the numbers above" ) $("#TXT_CAPTCHA").val("").focus();
        }
        

        
          
        function captchaBlur()
        {
            if( $("#TXT_CAPTCHA").val()=="" ) $("#TXT_CAPTCHA").val("Enter the numbers above");
        }
        
        
        
        
        function reloadCaptchaImage(setFocus) {
            $(".captchaJpg").attr("src", "../Captcha.ashx?update=" + (new Date()).valueOf() );
            $("#TXT_CAPTCHA").val("");
            
            if( setFocus ) {
                $("#TXT_CAPTCHA").focus();
            }
        }
  
        function BTN_REGISTER_onclick() 
        {        
            var emailAddress = $("#TXT_REGISTER").val();
            var captcha = $("#TXT_CAPTCHA").val();
            if( captcha=="" || captcha == "Enter the numbers above" )
            {
                $("#TXT_CAPTCHA").animate({ backgroundColor: "#ff0000" }, 500);
                $("#TXT_CAPTCHA").delay(500, function()
                    { 
                        $("#TXT_CAPTCHA").animate({ backgroundColor: "#ffffff" }, 500); 
                    });
                
            } else if( (emailAddress=="Email address")||(emailAddress=="")||(!echeck(emailAddress)) )
            {
                alert( emailAddress );
                $("#TXT_REGISTER").animate({ backgroundColor: "#ff0000" }, 500);
                $("#TXT_REGISTER").delay(500, function()
                    { 
                        $("#TXT_REGISTER").animate({ backgroundColor: "#ffffff" }, 500); 
                    });
            }
            else
            {
                $("#BTN_REGISTER").hide();
                $(".unregisterLink").hide();
                $(".loading").show();
                
                $("#jQearyAjax").load("../Services.aspx", { jaction: "Register", emailaddress: emailAddress, "CAPTCHA": captcha }, BTN_REGISTER_onclick_Return); 
            }
        }
        
        function BTN_UNREGISTER_onclick()
        {
            var emailAddress = $("#TXT_REGISTER").val();
            var captcha = $("#TXT_CAPTCHA").val();
            if( (emailAddress=="Email address")||(emailAddress=="")||(!echeck(emailAddress)) )
            { 
                $("#TXT_REGISTER").animate({ backgroundColor: "#ff0000" }, 500);
                $("#TXT_REGISTER").delay(500, function()
                    { 
                        $("#TXT_REGISTER").animate({ backgroundColor: "#ffffff" }, 500); 
                    });
            }
            else
            {
                $("#BTN_UNREGISTER").hide();
                $(".unregisterLink").hide();
                $(".loading").show();
            
                $("#jQearyAjax").load("../Services.aspx", { jaction: "Unregister", emailaddress: emailAddress, "CAPTCHA": captcha }, BTN_UNREGISTER_onclick_Return); 
            }  
        
        }
        
        var useDiv;
        
        function BTN_UNREGISTER_onclick_Return( response )
        {        
           
        
            if( response=="OK" )    {
                useDiv=".unregisterThankYou";
                reloadCaptchaImage(false);
            }
            else
            {
                useDiv=".registerFail";
                reloadCaptchaImage(true);
            }
           
            var target = $(".registerDiv");
            var position = target.position();
            
            
            $(useDiv).show().css("top",position.top+"px")
                                    .css("left",position.left+"px")
                                    .width(target.width())
                                    .height(target.height());
                               
            $(useDiv).hide();
                                
            $(useDiv).fadeIn(500).delay(4000, function()
                     {
                        $(".loading").hide();
                        $("#BTN_UNREGISTER").show();
                        $(".unregisterLink").show();
                        $(useDiv).fadeOut(2000); 
                     });
        }
        
        
        function BTN_REGISTER_onclick_Return( response )
        {
           
        
            if( response=="OK" ) {
                useDiv=".registerThankYou";
                reloadCaptchaImage(false);
            }
            else {
                useDiv=".registerFail";
                reloadCaptchaImage(true);
            }
           
            var target = $(".registerDiv");
            var position = target.position();
            
            
            $(useDiv).show().css("top",position.top+"px")
                                    .css("left",position.left+"px")
                                    .width(target.width())
                                    .height(target.height());
                               
            $(useDiv).hide();
                                
            $(useDiv).fadeIn(500).delay(4000, function()
                     {
                        $(".loading").hide();
                        $("#BTN_REGISTER").show();
                        $(".unregisterLink").show();
                        $(useDiv).fadeOut(2000); 
                     });
        }
        
    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){
		   
		    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					
	}