﻿
// JScript File
    var oIntervalLoadPlaylist = null;
    var oBtnClick = null;
    var browser = navigator.appName;
    
    function funCheckClick(evt)
    {

        if (browser == "Microsoft Internet Explorer")
        {
            if (evt.keyCode == 13)
            {
                funClickLogin();
            }
        }
        else 
        {
            if (evt.charCode == 13)
            {
                funClickLogin();
            }
        }   
    }

    function funClickLogin()
    {
        parent.document.getElementById("tdIfrmWork").style.backgroundImage = "url(ImagesApp/MainBG.gif)";

      //  
        
        if (document.getElementById("ucLogin_txtUserName").value == "" || (document.getElementById("ucLogin_txtPassword").value == "" && document.getElementById("ucLogin_hdnPassword").value == ""))
        {
            //g_workFrame.src = "artistRegister.aspx";
        }
        else
        {
         
           oBtnClick = "login";
          
            checkLogin();
           //firefox
           if (!document.all)
           {
              parent.PageMethods.CheckLoggedUser(CheckLoggedUserLoginSucceedHandler,CheckLoggedUserLoginFailedHandler);
   
           }
      
          
        }  
    }
    function loginRegisterDiv()
    {
      //check validators
    ValidatorEnable(parent.RequiredFieldValidatorTextBoxEmailAddress, true);
    ValidatorEnable(parent.RegularExpressionValidator1, true);
    ValidatorEnable(parent.RequiredFieldValidatorPasswordDiv, true);
    if(parent.RequiredFieldValidatorTextBoxEmailAddress.isvalid && parent.RegularExpressionValidator1.isvalid && parent.RequiredFieldValidatorPasswordDiv.isvalid)
       
       { 
         userLogedIn=false;
         loginRegister($get('TextBoxEmail').value,$get('TextBoxPasswordLoginDiv').value);
         if (userLogedIn)
         {
          UploadButtonClick();
         
         }
        
      }
     
    }

    function loginRegister(username, password)
    {
        document.getElementById("ucLogin_txtUserName").value = username;
        document.getElementById("ucLogin_txtPassword").value = password;
        oBtnClick = "login";
        checkLogin();
    }

    function checkLogin()
    {
        doAjaxRequest(buildAjaxLoginCommand(),{method:"GET", onSuccess:ajaxLoginSuccess, onFailure:ajaxFailure});
    }

    function ajaxLoginSuccess(oReq)
    { 
        var ajaxReturnValue = oReq.responseText.split("*~~*")
    //    oReq = null;
        var ajaxReturnValue = ajaxReturnValue[0].split(";")
        if (ajaxReturnValue[0] != "false")
        {
         
            userLogedIn=true;
            document.getElementById("trErrorLogin").style.display = "none";
            document.getElementById("ucLogin_divLogout").style.display = "block";
            document.getElementById("ucLogin_divMain").style.display = "none";
            document.getElementById("ucLogin_lblName").innerText = ajaxReturnValue[2];
            document.getElementById("ucLogin_lblName").innerText = document.getElementById("ucLogin_lblName").innerText.replace("_"," ");
            document.getElementById("divSignInDiv").style.display="none";
            funClickHomePage(); 
           
        }
        else
        {   userLogedIn=false;
            document.getElementById("trErrorLogin").style.display = "block";
            document.getElementById("ucLogin_divLogout").style.display = "none";
            document.getElementById("ucLogin_divMain").style.display = "block";
            document.getElementById("ucLogin_txtPassword").value = "";
            
        }
    }

     

    function buildAjaxLoginCommand()
    {
        var strPassword="", strRememberMe="";
        if (document.getElementById("ucLogin_txtPassword").value == "")
        {
            strPassword = document.getElementById("ucLogin_hdnPassword").value;
        }
        else
        {
            strPassword = document.getElementById("ucLogin_txtPassword").value; 
        }
        
        strRememberMe = document.getElementById("ucLogin_chkRememberMe").checked;
        
        var ajaxCommand = "ajaxFunctionID=1&param=" + document.getElementById("ucLogin_txtUserName").value + "," + strPassword + "," + strRememberMe;
        return ajaxCommand;
    }

  

  

   
   

    function funClickLogout()
    {
       //close artist upload divs 
        userLogedIn=false;
        parent.document.getElementById('divUploadFiles').style.display = 'none'; 
        parent.document.getElementById('divAddAlbum').style.display = 'none'; 
        parent.document.getElementById("tdIfrmWork").style.backgroundImage = "url(http://www.jumbey.com/ImagesApp/MainBG.gif)";
        oBtnClick = "logout";
        logout();
        //firefox
           if (!document.all)
           {
              parent.PageMethods.CheckLoggedUser(CheckLoggedUserLogOutSucceedHandler,CheckLoggedUserLoginFailedHandler);
   
           }
       
        
    }

    function logout()
    {
        doAjaxRequest(buildAjaxLogoutCommand(),{method:"GET", onSuccess:ajaxLogoutSuccess, onFailure:ajaxFailure});
    }

    function buildAjaxLogoutCommand()
    {
        var ajaxCommand = "ajaxFunctionID=8&param=''";
        return ajaxCommand;
    }

    function ajaxLogoutSuccess(oReq)
    {
        var ajaxReturnValue = oReq.responseText.split("*~~*")
        if (ajaxReturnValue[0])
        {
            document.getElementById("ucLogin_divLogout").style.display = "none";
            document.getElementById("ucLogin_divMain").style.display = "block";
            document.getElementById("ucLogin_txtUserName").value = "";
            document.getElementById("ucLogin_txtPassword").value = "";
            g_workFrame.src = "MusicList.aspx?genreId=0";
        }
        else
        {
            document.getElementById("ucLogin_divLogout").style.display = "block";
            document.getElementById("ucLogin_divMain").style.display = "none";
        }
        
    }
    
    function funClickHomePage()
    {
        parent.doAjaxRequest(buildAjaxHomePage(),{method:"GET", onSuccess:ajaxHomePageSuccess, onFailure:parent.ajaxFailure});
         //firefox
           if (!document.all)
           {
              parent.PageMethods.CheckLoggedUserType(CheckLoggedUserTypeSucceedHandler,CheckLoggedUserTypeFailedHandler);
   
           }
        //g_workFrame.src = "MusicList.aspx?genderId=2";
    }
    
    function buildAjaxHomePage()
    {
        var ajaxCommand = "ajaxFunctionID=9&param=''";
        return ajaxCommand;
    }
    
    function ajaxHomePageSuccess(oReq)
    {
//        debugger;
     
        
        var ajaxReturnValue = oReq.responseText.split("*~~*")
          
        if (ajaxReturnValue[0] == "True")
        {
            g_workFrame.src = "http://www.jumbey.com/artistPage.aspx";   
        }
        else
        {
            g_workFrame.src = "http://www.jumbey.com/ListenerPage.aspx";
        }
    }
    
    function funLoadArtist()
    { 
        parent.document.getElementById("tdIfrmWork").style.backgroundImage = "url(http://www.jumbey.com/ImagesApp/MainBG.gif)";
        
        
        
        g_workFrame.src = "http://www.jumbey.com/artistRegister.aspx";
    }
    
    function funLoadListener()
    {
        parent.document.getElementById("tdIfrmWork").style.backgroundImage = "url(http://www.jumbey.com/ImagesApp/MainBG.gif)";
        
        
        
        g_workFrame.src = "http://www.jumbey.com/listenerRegister.aspx";
    }
    
    function funForgetPassword()
    {
        parent.document.getElementById("divForgetPassword").style.display = "block";
       
    }
    
 
    
    function funMainPage()
    {
        window.location.href = "http://www.jumbey.com/MusicList.aspx";
    }
    
    //set the password textbox on the div login form - when catching enter - the LoginDivClickButton implemented
  function SetDivLoginButton(e)
  {  
      if(window.event) // IE
          {
            if(e.keyCode==13)
          {
      parent.LogInDivClickButton();
   
         
      }
      }
     else if(e.which) // Netscape/Firefox/Opera
        {
          if(e.which==13)
          parent.LogInDivClickButton();
        }
         
  }
   
    function SetMainLoginButton(e,obj)
  {  
      if(window.event) // IE
          {
          if(e.keyCode==13)
          { 
           obj.blur();
           parent.funClickLogin(); 
           }
      }
     else if(e.which) // Netscape/Firefox/Opera
        {
          if(e.which==13)
          { 
           obj.blur();
           parent.funClickLogin(); 
          }
        }
  }
  
  
   
       
        //ajax PageMethods handlers 
  
  function CheckLoggedUserLoginSucceedHandler(result,context,methodName)
  { 
  if(result)
       {
       
            userLogedIn=true;
            document.getElementById("trErrorLogin").style.display = "none";
            document.getElementById("ucLogin_divLogout").style.display = "block";
            document.getElementById("ucLogin_divMain").style.display = "none";
            document.getElementById("divSignInDiv").style.display="none";  
            funClickHomePage(); 
           
        }
        else
        {
          userLogedIn=false;
            document.getElementById("trErrorLogin").style.display = "block";
            document.getElementById("ucLogin_divLogout").style.display = "none";
            document.getElementById("ucLogin_divMain").style.display = "block";
            document.getElementById("ucLogin_txtPassword").value = "";
            
        }
       
  }
  function CheckLoggedUserLogOutSucceedHandler(result,context,methodName)
  {
  if(!result)
   {
            document.getElementById("ucLogin_divLogout").style.display = "none";
            document.getElementById("ucLogin_divMain").style.display = "block";
            document.getElementById("ucLogin_txtUserName").value = "";
            document.getElementById("ucLogin_txtPassword").value = "";
            g_workFrame.src = "MusicList.aspx?genreId=0";
        }
        else
        {
            document.getElementById("ucLogin_divLogout").style.display = "block";
            document.getElementById("ucLogin_divMain").style.display = "none";
        }
     funClickHomePage(); 
  }
   function CheckLoggedUserLoginFailedHandler(result,context,methodName)
  {
  }
    function CheckLoggedUserTypeSucceedHandler(result,context,methodName)
  {
      if (result == "artist")
        {
            g_workFrame.src = "http://www.jumbey.com/artistPage.aspx";   
        }
        else if (result=="listener")
        {
            g_workFrame.src = "http://www.jumbey.com/ListenerPage.aspx";
        }
  
  }
  
   function CheckLoggedUserTypeFailedHandler(result,context,methodName)
  {
  }
  
