﻿// JScript File

function AutoLogin(uname,pwd)
{   
    LoginName = uname;
    LoginPassword = pwd;    
    URL = "Log="+uname+"&Pass="+pwd+"&.rnd="+Math.random();    
    var myConn = new XHConn();
    myConn.connect( "AJAX/LoginDetails.aspx", "GET" , URL, processLogin2 );
    //return false;
}

function processLogin2 ( oXML )  
{
    ResponseText = oXML.responseText;    
    //alert(ResponseText);
    
    if(ResponseText == 0)
    {
        document.getElementById("LoginError").innerHTML = "<img src='images/SmallLoader.gif'>";
        document.getElementById("LoginError").innerHTML =  "Invalid login details."; 
        document.getElementById("txtLoginName").value = "";
        document.getElementById("txtPassword").value = "";
    }
    else
    {
        document.getElementById("ctl00_dvLoginSection").innerHTML = "<img src='images/SmallLoader.gif'>";
        document.getElementById("LoginError").innerHTML =  ""; 
        document.getElementById("ctl00_dvLoginSection").style.display = 'none';
        //document.getElementById("ctl00_dvLoggedSection").innerHTML =  ResponseText; 
        
        var col_array=ResponseText.split("$");
        
        //Set Login details
        document.getElementById("ctl00_dvLoggedSection").innerHTML = col_array[0];
        //alert("col_array[0]="+col_array[0]);
        
        //Set LoginName to hidden html field for rest of the operation in the site.
        document.getElementById("ctl00_hiddenLogName").value = col_array[1];
        //alert(col_array[1]);
        
        //Set LoginId to hidden html field for rest of the operation in the site.
        document.getElementById("ctl00_hiddenLogId").value = col_array[2];
//        if( col_array[3]=="16")
//        {
//            location.href="MOBContest.aspx?CID=9&&PID=1";
//        }
//        else
//        {               
//            document.getElementById("LoginError1").innerHTML =  "You are not user from malaysia.";                           
//        } 
        //alert(col_array[2]);
    }
}

function MOBLogin(formName)
{    
   
    if( isEmpty(formName.txtLoginName1) )
    {
        alert( 'LOGIN ID IS REQUIRED FILED.');
        return false;
    }
    else if( isEmpty(formName.txtPassword1) )
    {
        alert( 'PASSWORD IS REQUIRED FILED.' );
        return false;
    }
    LoginName = document.getElementById("txtLoginName1").value;
    LoginPassword = document.getElementById("txtPassword1").value;
    
    
    URL = "Log="+LoginName+"&Pass="+LoginPassword+"&.rnd="+Math.random();
    var myConn = new XHConn();
    myConn.connect( "AJAX/LoginDetails.aspx", "GET" , URL, processLogin1 );
    //return false;       
}


function processLogin1 ( oXML )  
{
    ResponseText = oXML.responseText;    
    if(ResponseText == 0)
    {
        document.getElementById("LoginError1").style.display='block';
        document.getElementById("LoginError1").innerHTML = "<img src='images/SmallLoader.gif'>";
        document.getElementById("LoginError1").innerHTML =  "Invalid login details."; 
        
        document.getElementById("txtLoginName1").value = "";
        document.getElementById("txtPassword1").value = "";        
    }
    else
    {          
        var col_array=ResponseText.split("$");               
        //code for MOB contest...   
         
        if(col_array[3]=="16")
        {      
           location.href="MOBContest.aspx?CID=9";
        }
        else
        {               
            document.getElementById("LoginError1").innerHTML =  "You are not user from malaysia.";     
            document.getElementById("txtLoginName1").value = "";
            document.getElementById("txtPassword1").value = "";                              
        }                    
    }  
    document.getElementById("LoginError").style.display='none';    
}

function ResetMOBRegistration()
{   
    document.getElementById("ctl00_ContentPlaceHolder1_Div_LoginName").style.display='none';     
    document.aspnetForm.reset();
}

