﻿// JScript File

function Span_OnMouseOver(val){
    document.getElementById("tdLink" + val).className="navLinkHover";
}

function Span_OnMouseOut(val){
    document.getElementById("tdLink" + val).className="navLink";
}

function On_MouseEvent(el,cls){
    if(el==null || el.className== cls)
        return;
    el.className=cls;
    
}
function Home(){
    if(isRegisterForm() || isManagerForm())
        HomeEx();
    else
        WS4Kid.DocsHome2HTML(callback_DoSearchEx);
}

function isRegisterForm(){
    var pathName=self.location.pathname;
    if(isNotNull(pathName)){
        var n=pathName.lastIndexOf("/");
        if(n>-1){
            if(pathName.toLowerCase().indexOf("/register.aspx")>-1){
                return true;
            }
        }
    }
    return false;
}

function isManagerForm(){
    var pathName=self.location.pathname;
    if(isNotNull(pathName)){
        var n=pathName.lastIndexOf("/");
        if(n>-1){
            if(pathName.toLowerCase().indexOf("/manager.aspx")>-1){
                return true;
            }
        }
    }
    return false;
}

function HomeEx(status){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0){
        if(status ==null || status == ""){
            self.location=curHref.substring(0,nlast+1,curHref) + "Default.aspx";
        }else{
            self.location=curHref.substring(0,nlast+1,curHref) + "Default.aspx" + status;    
        }
    }
}

function BannerAction(searchBy,val){
    if(isNull(searchBy))
        searchBy=0;
    if(isRegisterForm() || isManagerForm()){
        HomeEx("?status=" + searchBy);
    }else{
        DoAction(searchBy,val);
    }
}

function RegisterForm(){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location=curHref.substring(0,nlast+1,curHref) + "Register.aspx";
}

function SignIn(defURL){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0){
        if(defURL == null || defURL == "")
            defURL="Default.aspx&status=101";
        self.location=curHref.substring(0,nlast+1,curHref) + "SignIn.aspx?ReturnUrl=" + defURL;    
    }
}

function SignOut(){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location=curHref.substring(0,nlast+1,curHref) + "SignOut.aspx";
}

function AccountInfo(){
    document.getElementById('tdViewContent').innerHTML="<iframe id=ifrViewContent src=\"AccountInfo.aspx\" style=\"width:615px; height:400px;\" scrolling=\"auto\" frameborder=\"no\" ></iframe>";
    /*
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location=curHref.substring(0,nlast+1,curHref) + "Default.aspx?status=101";
    */
}

function UpdateDateTimeChanged(){
    var day=document.getElementById("selDay").value;
    var month=document.getElementById("selMonth").value;
    var year=document.getElementById("selYear").value;
    document.getElementById("UDateTime1_hiDate").value=day + "/" + month + "/" + year;
}

function UpdateAccount(){
    var bInvalid=false;
    var fullName= document.getElementById("tdFullName").innerText;
    var userName=document.getElementById("tdUserName").innerText;
    if(isNull(userName))
        bInvalid=true;
    var address=document.getElementById("iAddress").value;
    if(isNotNull(address)){
        if(!isAddress(address)){
            bInvalid=true;
            document.getElementById("lblInvalidAddress").style.display="";
        }else{
            document.getElementById("lblInvalidAddress").style.display="none";
        }
    }
    
    var emailAddress=document.getElementById("iEmailAddress").value;
    if(!isEmail(emailAddress)){
        bInvalid=true;
        document.getElementById("lblInvalidEmailAddress").style.display="";
    }else{
        document.getElementById("lblInvalidEmailAddress").style.display="none";
    }
     
    var phoneNumber=document.getElementById("iPhoneNumber").value;
    if(isNotNull(phoneNumber)){
        if(!isPhoneNumber(phoneNumber)){
            bInvalid=true;
            document.getElementById("lblInvalidPhoneNumber").style.display="";
        }else{
            document.getElementById("lblInvalidPhoneNumber").style.display="none";
        }
    }
     var DOB=document.getElementById("udtDOB_hiDate").value;
     var stateProvince=document.getElementById("selStateProvince").value;
     var gender=document.getElementById("selGender").value;
     
     if(bInvalid)
        return;
     WS4Kid.UpdateAccount(userName, fullName, address, stateProvince, emailAddress, phoneNumber,DOB,gender,callback_UpdateAccount);
}

function Register(){
    var bInvalid=false;
    var fullName=document.getElementById("iFullName").value;
    if(!isName(fullName)){
        //WS4Kid.GetResourceString("Register","vi-VN","pls_enter_a_valid_full_name",MsgBox);
        bInvalid=true;
        document.getElementById("lblInvalidFullName").style.display="";
    }else{
        document.getElementById("lblInvalidFullName").style.display="none";
    }

    var userName=document.getElementById("iUserName").value;
    if(!isUserName(userName)){
        bInvalid=true;
        document.getElementById("lblInvalidUserName").style.display="";
    }else{
        document.getElementById("lblInvalidUserName").style.display="none";
    }
    
    var password=document.getElementById("iPassword").value;
    var passwordConfirm=document.getElementById("iPasswordConfirm").value;
    if(isNull(password) || isNull(passwordConfirm) || password.length<6){
        bInvalid=true;
        document.getElementById("lblInvalidPassword").style.display="";
    }else{
        document.getElementById("lblInvalidPassword").style.display="none";
    }
    
    if(password != passwordConfirm){
        bInvalid=true;
        document.getElementById("lblInvalidMatchingPassword").style.display="";
    }else{
        document.getElementById("lblInvalidMatchingPassword").style.display="none";
    }
    
    var dayOfBirth=document.getElementById("UDateTime1_hiDate").value
    if(dayOfBirth==""){
        dayOfBirth=document.getElementById("selDay").value + "/" + document.getElementById("selMonth").value + "/" + document.getElementById("selYear").value; 
    }
    var gender=document.getElementById("selGender").value;    
    var phoneNumber=document.getElementById("iPhoneNumber").value;
    if(isNotNull(phoneNumber)){
        if(!isPhoneNumber(phoneNumber)){
            bInvalid=true;
            document.getElementById("lblInvalidPhoneNumber").style.display="";
        }else{
            document.getElementById("lblInvalidPhoneNumber").style.display="none";
        }
    }
    
    var customerCode=document.getElementById("iCustomerCode").value;
    
    if(!WS4Kid.isCustomerCode(customerCode)){
        bInvalid=true;
        document.getElementById("lblCustomerCode").style.display="";
    }
    
    var emailAddress=document.getElementById("iEmailAddress").value;
    if(!isEmail(emailAddress)){
        bInvalid=true;
        document.getElementById("lblInvalidEmailAddress").style.display="";
    }else{
        document.getElementById("lblInvalidEmailAddress").style.display="none";
    }
    var address=document.getElementById("iAddress").value;
    if(isNotNull(address)){
        if(!isAddress(address)){
            bInvalid=true;
            document.getElementById("lblInvalidAddress").style.display="";
        }else{
            document.getElementById("lblInvalidAddress").style.display="none";
        }
    }
        
    var stateProvince=document.getElementById("selStateProvince").value;
    var pinCode=document.getElementById("iPINCode").value;
    var language=document.getElementById("hiLanguage").value;

    if(bInvalid)
        return;
    
    var args = new Array();
    args[0]=fullName;
    args[1]=userName;
    args[2]=emailAddress;
    args[3]=pinCode;
    args[4]=customerCode;
    args[5]="0";
    args[6]="";
    args[7]=password;
    args[8]=dayOfBirth;
    args[9]=gender;
    args[10]=phoneNumber;
    args[11]=address;
    args[12]=stateProvince;
    args[13]="1";
    args[14]=language;
    WS4Kid.Register(args,callback_Register);
}

function Subjects(){
    WS4Kid.Subjects(callback_Subjects);
}

function Subjects2Sel(){
   WS4Kid.Subjects2Sel(callback_Subjects2Sel);
}

function DoChangePassword(){
    document.getElementById('trChangePassword').style.display="";
}

function DoSaveChangePassword(){
    var bInvalid=false;
    var oldPass=document.getElementById('iOldPassword').value;
    var newPass=document.getElementById('inewPassword').value;
    var confirmPass=document.getElementById('iConfirmPassword').value;
    if(isNull(newPass) || isNull(confirmPass) || newPass.length<6){
        bInvalid=true;
        document.getElementById("trInvalidPassword").style.display="";
    }else{
        document.getElementById("trInvalidPassword").style.display="none";
    }
    document.getElementById("trInvalidMatchingPassword").style.display="none";    
    if(newPass != confirmPass){
        if(!bInvalid)
            document.getElementById("trInvalidPassword").style.display="none";
        document.getElementById("trInvalidMatchingPassword").style.display="";
        bInvalid=true;
    }

    if(bInvalid)
        return;
    WS4Kid.UpdatePassword(oldPass,newPass,callback_UpdatePassword);
}

function DoSearch(){
    var keyWord=document.getElementById('iKeyWord').value;
    if(isNotNull(keyWord))
        WS4Kid.Search(keyWord,callback_DoSearch);
}

function Forum(){
    //alert("Coming soon!");
    return;
}

function Help(){
    //alert("Coming soon!");
    return;
}

function DoViewPageAt(el,page){
    var itemsView=document.getElementById('selItemsView').value;
    var postStart=((page-1) * itemsView) + 1;
    var searchBy=document.getElementById('hiSearchBy').value;
    var keyWord=document.getElementById('hiKeyWord').value;
    WS4Kid.Search2HTML(searchBy,keyWord,postStart,itemsView,callback_DoViewPageAt);
    document.getElementById('hiItemsView').value=itemsView;
    document.getElementById('hiCurPage').value=page;
    //SetItemsView(itemsView);
}

function DoItemsViewChanged(el){
    DoViewPageAt(el,1);
}

function DoViewPaymentDetail(usr){
    var fromDate=document.getElementById('udtFrom_hiDate').value;
    var toDate=document.getElementById('udtTo_hiDate').value;
    WS4Kid.PaymentDetailItems(usr,fromDate,toDate,callback_DoViewPaymentDetail);
}

function DoActiveUser(val){
}

function DoDeActiveUser(val){
}

function DoDeleteUser(val){
}
/* 
function PaymentDetail(){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location=curHref.substring(0,nlast+1,curHref) + "Default.aspx?status=4";    
}

function AddMoneyDetail(){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location=curHref.substring(0,nlast+1,curHref) + "Default.aspx?status=3";    
}

function AddMoney(){
    var curHref=self.location.href;
    var nlast=curHref.lastIndexOf("/");
    if(nlast>0)
        self.location.href=curHref.substring(0,nlast+1,curHref) + "Default.aspx?status=2";
}

*/
