﻿// JScript File

    var ajax_load = "<img src='images/load.gif' alt='' />";
	var loadUrl = "login.aspx";
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    var msg="";
    
$(document).ready(function(){
//on doc ready
	$("#result2").removeClass("errmsg").html('');
    $("#result").removeClass("errmsg").html('');
    Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
     skipSetup: true,
    // include the html player because we want to display some html content
     players: ["html","iframe"]
     });
     
//forget password
$("#forgotPWD").click(function(){
    var url=location.protocol+'//'+location.host+'/'+uri.path+'/forgot.aspx';
    var title='Forgot Password';
    var height=100;
    var width=350;
    OpenShadow(url,title,height,width);    
});

 function OpenShadow(url,title,height,width)
    {
        Shadowbox.open({
        content:    url,
        player:     "iframe",
        title:      title,
        height:     height,
        width:      width
        });
    }
                      

	
	//	$.post()submit profile
	$("#bntsubmit").click(function(){
		$("#result2").removeClass("errmsg").html(ajax_load+' Processing, please wait ...');
		var hasError = false;
		var strPassword = $("#txtpwd").val();
		var strPassword2 = $("#txtpwd2").val();
		var strEmail = $("#txtemail").val();
		var strEmail2 = $("#txtemail2").val();
		var strSurname = $("#txtsurname").val();
		var strFirstname = $("#txtfirstname").val();
		var strOthername = $("#txtmiddlename").val();
		var nickName = $("#txtnickname").val();
		msg="";
		if(strSurname==''){
		msg = msg + '* Surname is required<br>';
		hasError = true;
		}
		if(strFirstname==''){
		msg = msg + '* Firstname is required<br>';
		hasError = true;
		}
		
		if(!emailReg.test(strEmail) || strEmail=='' ){
		msg = msg + '* Invalid email<br>';
		hasError = true;
		}
		if(!emailReg.test(strEmail2) || strEmail2=='' ){
		msg = msg + '* Invalid confirmed email<br>';
		hasError = true;
		}
		if(emailReg.test(strEmail2) && emailReg.test(strEmail) && strEmail2!='' && strEmail!=''){
		    if (strEmail2!=strEmail){
		    msg = msg + '* Email and confirmed email must be the same<br>';
		    hasError = true;
		    }
		}
		if(strPassword==''){
		msg = msg + '* Password is required<br>';
		hasError = true;
		}
		if(strPassword2==''){
		msg = msg + '* Confirm password is required<br>';
		hasError = true;
		}
		if(strPassword!='' && strPassword2!=''){
		    if (strPassword!=strPassword2){
		    msg = msg + '* Password and confirmed password must be the same<br>';
		    hasError = true;
		    }
		}
		if (hasError==true){
		$("#result2").addClass("errmsg").html(msg);
		return false;
		}
		$.ajax({
            url: loadUrl,
            cache: false,
            dataType: "html",
            type: "POST",
            data: {Password: strPassword, Email: strEmail, a: 2, Surname: strSurname, Nickname:nickName, Firstname: strFirstname,  Othername: strOthername},
            error:    function (XMLHttpRequest, textStatus, errorThrown) {
            // typically only one of textStatus or errorThrown 
            // will have info
            //alert(XMLHttpRequest.responseText);
            $("#result").addClass("errmsg").html(XMLHttpRequest.responseText);
             this; // the options for this ajax request
          },
            success: function(responseText) {
				//$("#result").html(responseText);
				if(responseText==1){
				$("#txtpwd").val("");
		        $("#txtpwd2").val("");
		        $("#txtemail").val("");
		        $("#txtemail2").val("");
		        $("#txtsurname").val("");
		        $("#txtfirstname").val("");
		        $("#txtmiddlename").val("");
		        $("#txtnickname").val("");
				$("#result2").addClass("successmsg").html("Profile created successfuly. Notification has been sent to your mail.")
				}
				if(responseText==2)$("#result2").removeClass("successmsg").addClass("errmsg").html("unable to create profile, try again later.")
				if(responseText==3)$("#result2").removeClass("successmsg").addClass("errmsg").html("Email already exist, Notification has been resent to your email.")
            }//success
        })//ajax
	});//click

});//dom ready


