﻿//for ajax
var response;
var z;
var ds;
function calltesti()
{
    response=Index.fetchtest();
    z=0;
    if(!response.error)
    {
       ds=response.value;
       var img=document.getElementById("imgage");
       var content=document.getElementById("spntesti");
       var name=document.getElementById("spnname");
       if(ds!= null)
       {
        content.innerHTML=ds.Tables[0].Rows[0].testi;
        name.innerHTML=ds.Tables[0].Rows[0].Title;
        img.src='Images/'+ds.Tables[0].Rows[0].Image;
       }
       calltime();
    }
    else
    {
     //alert("Error");
    }
}
function calltime()
{
    window.setTimeout('delaysetting()',2000);
}
function delaysetting()
    {
    var img=document.getElementById("imgage");
    var content=document.getElementById("spntesti");
    var name=document.getElementById("spnname");
      if(z == ds.Tables[0].Rows.length)
      {
        z=0;
      }
      //alert(z);
      if(ds!= null)
      {
        content.innerHTML=ds.Tables[0].Rows[z].testi;
        name.innerHTML=ds.Tables[0].Rows[z].Title;
        img.src='Images/'+ds.Tables[0].Rows[z].Image;
      }
      z=(z+1);
      window.setTimeout('calltime()',2000);
    }
//XML file loading
    var xmlDoc;
    var i;
    var total;
    var txt=new Array();
    var id=new Array();
    var sn=new Array();
    var ut=new Array();
    var spnid=new Array();
    var hrefid=new Array();
    function BindData()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/tutorial.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        //alert(total);
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("TID")[i].childNodes[0].nodeValue;
            ut[i]=xmlDoc.getElementsByTagName("UT")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+1);
            hrefid[i]='href'+(i+1);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
        //document.getElementById("tblforum").style.visibility="hidden";//to hide the forum heading links
        for(i=0;i<total;i++)
        {
          //document.getElementById(hrefid[i]).setAttribute("onclick","Tutorial.aspx?TID="+id[i]);
          //alert("checkAccess("+ut[i]+","+id[i]+")")
          document.getElementById(hrefid[i]).setAttribute("href","javascript:checkAccess("+ut[i]+","+id[i]+")");
          document.getElementById(spnid[i]).innerHTML=txt[i];
        }
        document.getElementById("idmore").setAttribute("href","Subject.aspx?SubID=1");
        changetutorialback();
        return false;
    }
    
    //fuction for binding articles
    function BindDataArticle()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/atricle.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("AID")[i].childNodes[0].nodeValue;
            ut[i]=xmlDoc.getElementsByTagName("UT")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+1);
            hrefid[i]='href'+(i+1);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
        //document.getElementById("tblforum").style.visibility="hidden";//to hide the forum heading links
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","javascript:checkAccess1("+ut[i]+","+id[i]+")");
          document.getElementById(spnid[i]).innerHTML=txt[i];
        }
        document.getElementById("idmore").setAttribute("href","Article.aspx?aid=0");
        changeviewsback();
        return false;
    }
    //for news
    function BindNewsData()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/News.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("NID")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<total;i++)
        {
            spnid[i]='span'+(i+1);
            hrefid[i]='href'+(i+1);
            //sn[i]='SN'+(i+1);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
          //document.getElementById(sn[i]).innerHTML="";
        }
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","News.aspx?NID="+id[i]);
          document.getElementById(spnid[i]).innerHTML=txt[i];
          //document.getElementById(sn[i]).innerHTML=(i+1)+'.';
        }
        document.getElementById("idmore").setAttribute("href","News.aspx?NID=0");
        changetutorialback();
        return false;
    }
    //Binding data for forum
    function bindforum()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/Viewed.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("TID")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+10);
            hrefid[i]='href'+(i+10);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","Forum/ViewPosts.aspx?TID="+id[i]);
          document.getElementById(spnid[i]).innerHTML=txt[i];
        }
//        document.getElementById("tblforum").style.visibility="visible";
//        document.getElementById("mostview").style.backgroundColor="white";
//        document.getElementById("newlyadd").style.backgroundColor="SkyBlue";
//        document.getElementById("topview").style.backgroundColor="SkyBlue";
        changenemostviewback();
        return false;
    }
    //Binding forum for newly created
    function bindforum1()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/Newly.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("TID")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+10);
            hrefid[i]='href'+(i+10);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","Forum/ViewPosts.aspx?TID="+id[i]);
          document.getElementById(spnid[i]).innerHTML=txt[i];
        }
        //document.getElementById("tblforum").style.visibility="visible";
//        document.getElementById("mostview").style.backgroundColor="SkyBlue";
//        document.getElementById("newlyadd").style.backgroundColor="white";
//        document.getElementById("topview").style.backgroundColor="SkyBlue";
        changenewlyaddback();
        return false;
    }
    //Binding forum for top rated
    function bindforum2()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        //xmlDoc.load("XML/top.xml");
        xmlDoc.load("XML/Viewed.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("TID")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+10);
            hrefid[i]='href'+(i+10);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","Forum/ViewPosts.aspx?TID="+id[i]);
          document.getElementById(spnid[i]).innerHTML=txt[i];
        }
        //document.getElementById("tblforum").style.visibility="visible";
//        document.getElementById("mostview").style.backgroundColor="SkyBlue";
//        document.getElementById("newlyadd").style.backgroundColor="SkyBlue";
//        document.getElementById("topview").style.backgroundColor="white";
        changetopratedback();
        return false;
    }
    //Binding notice board data
    function BindNoticeData()
    {
        i=0;
        if (window.ActiveXObject)
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        }
        else if (document.implementation && document.implementation.createDocument)
        {
            xmlDoc=document.implementation.createDocument("ns","root",null);
        }    
        xmlDoc.async=false;
        xmlDoc.load("XML/Notice.xml");
        total=xmlDoc.getElementsByTagName("Table").length;
        for(i=0;i<total;i++)
        {
            txt[i]=xmlDoc.getElementsByTagName("Title")[i].childNodes[0].nodeValue;
            id[i]=xmlDoc.getElementsByTagName("NID")[i].childNodes[0].nodeValue;
        }
        for(i=0;i<5;i++)
        {
            spnid[i]='news'+(i+1);
            hrefid[i]='nwsref'+(i+1);
            //sn[i]='SN'+(i+1);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
          //document.getElementById(sn[i]).innerHTML="";
        }
        for(i=0;i<total;i++)
        {
          document.getElementById(hrefid[i]).setAttribute("href","Notice.aspx?NID="+id[i]);
          document.getElementById(spnid[i]).innerHTML=txt[i];
          //document.getElementById(sn[i]).innerHTML=(i+1)+'.';
        }
        document.getElementById("newsmore").setAttribute("href","Notice.aspx?NID=0");
        return false;
    }
    //To bind weekly Questions
    function bindweeklyque()
    {
        for(i=0;i<5;i++)
        {
            spnid[i]='span'+(i+1);
            //hrefid[i]='href'+(i+10);
        }
        for(i=0;i<5;i++)
        {
          document.getElementById(spnid[i]).innerHTML="";
        }
          document.getElementById("href1").setAttribute("href","weeklyQuestion.aspx");
          document.getElementById("span1").innerHTML="In a bag there are exactly 6 one rupee coin and ...";
          changeweekquesback();
          document.getElementById("idmore").setAttribute("href","weeklyQuestion.aspx");
        return false;
    }
     //1=Guest, 2=registered, 3=paid
    function checkAccess(UT,TID)
    {
        //var utype=document.getElementById("hdntype").value;
       //alert(utype);
//        if(UT =="1" ||utype=="2")
//        {
            window.location="Tutorial.aspx?TID="+TID;
//        }
//       else if(utype == UT)
//       {
//            window.location="Tutorial.aspx?TID="+TID;
//       }
//       else
//       {
//            document.getElementById("alertdiv").style.visibility="visible";
//       }
    }
    
    //checking for Articles
    function checkAccess1(UT,AID)
    {
        //var utype=document.getElementById("hdntype").value;
//        alert(utype);
//        if(UT =="1"||utype=="2")
//        {
            window.location="Article.aspx?AID="+AID;
//        }
//       else //if(utype == UT)
//       {
//            window.location="Article.aspx?AID="+AID;
//       }
//       else
//       {
//            document.getElementById("alertdiv").style.visibility="visible";
//       }
    }
    function foucuslogin()
    {
        var utype=document.getElementById("hdntype").value;
        document.getElementById("alertdiv").style.visibility="hidden";
        if(utype == "0")
        {
            document.getElementById("txtloging").focus();
        }
    }
    
    //To check empty login id and password
    function checkempty()
    {
        var login=document.getElementById("Header1_txtloging");
        var pass=document.getElementById("Header1_txtpasswd");
        if(login.value=="" && pass.value=="")
        {
            alert("Enter your login Id and password");
            login.focus();
            return false;
        }
        else if(login.value!="" && pass.value=="")
        {
            alert("Enter your Password");
            pass.focus();
            return false;
        }
        else if(login.value=="" && pass.value!="")
        {
            alert("Enter your login Id");
            login.focus();
            return false;
        }
        else
        {
            return true;
//             test9(login.value,pass.value);
        }
    }
    //
    //To check empty login id and password
    function checkempty1()
    {
        var login=document.getElementById("txtloging");
        var pass=document.getElementById("txtpasswd");
        if(login.value=="" && pass.value=="")
        {
            alert("Enter your login Id and password");
            login.focus();
            return false;
        }
        else if(login.value!="" && pass.value=="")
        {
            alert("Enter your Password");
            pass.focus();
            return false;
        }
        else if(login.value=="" && pass.value!="")
        {
            alert("Enter your login Id");
            login.focus();
            return false;
        }
        else
        {
            return true;
//             test9(login.value,pass.value);
        }
    }
//    function changecolor()
//    {
//        document.getElementById("mostview").style.backgroundColor="white";
//        document.getElementById("newlyadd").style.backgroundColor="SkyBlue";
//        document.getElementById("topview").style.backgroundColor="SkyBlue";
//    }
//    function changecolor1()
//    {
//        document.getElementById("mostview").style.backgroundColor="SkyBlue";
//        document.getElementById("newlyadd").style.backgroundColor="white";
//        document.getElementById("topview").style.backgroundColor="SkyBlue";
//    }
//    function changecolor2()
//    {
//        document.getElementById("mostview").style.backgroundColor="SkyBlue";
//        document.getElementById("newlyadd").style.backgroundColor="SkyBlue";
//        document.getElementById("topview").style.backgroundColor="white";
//    }
    //for mouse move
//    function changein(ojb)
//    {
//        document.getElementById(ojb).style.backgroundColor="#ccffff"
//    }
//    function changeout(ojb)
//    {
//        document.getElementById(ojb).style.backgroundColor="White"
//    }
//    function changeout1(ojb)
//    {
//        document.getElementById(ojb).style.backgroundColor="#5E99AB"
//    }
 //Functions for calling Ajax methods
function callback_test9(res)
{
    if(res.value != null)
    {
     showloggediv();
     //alert(res.value.Tables[0].Rows[0].LName);
     document.getElementById("utype").value=res.value.Tables[0].Rows[0].UType;
     document.getElementById("uname").innerHTML=res.value.Tables[0].Rows[0].Fname;
     document.getElementById("lname").innerHTML=res.value.Tables[0].Rows[0].LName;
     document.getElementById("lastlog").innerHTML=res.value.Tables[0].Rows[0].LoginTime;
//   document.getElementById("dys").innerHTML=res.value.Tables[0].Rows[0].days;
    }
    else
    {
        alert("Invalid Use id or password");
    }
}
function test9(id,pass)
{
    Index.validateuser(id,pass,callback_test9);
}

//function div show
function showloggediv()
{
  document.getElementById("loggedDiv").style.visibility="visible";
  document.getElementById("loingDiv").style.visibility="hidden";
}
function showlogindiv()
{
//  document.getElementById("loggedDiv").style.visibility="hidden";
//  document.getElementById("loingDiv").style.visibility="visible";
}
//To change anchor background color
function changetutorialback()
{
    document.getElementById("tdtutor").style.backgroundColor="white";
    document.getElementById("atutor").style.color="#036ec0";
    document.getElementById("tdviews").style.backgroundColor="#036ec0";
    document.getElementById("aviews").style.color="white";
    document.getElementById("tdweekque").style.backgroundColor="#036ec0";
    document.getElementById("aweekque").style.color="white";
    document.getElementById("tdblank").style.backgroundColor="white";
}
//To change views background color and font color
function changeviewsback()
{
    document.getElementById("tdviews").style.backgroundColor="white";
    document.getElementById("aviews").style.color="#036ec0";
    document.getElementById("tdtutor").style.backgroundColor="#036ec0";
    document.getElementById("atutor").style.color="white";
    document.getElementById("tdweekque").style.backgroundColor="#036ec0";
    document.getElementById("aweekque").style.color="white"; 
    document.getElementById("tdblank").style.backgroundColor="#036ec0";  
}
//to change weekly ques. bachgournt

function changeweekquesback()
{
    document.getElementById("tdweekque").style.backgroundColor="white";
    document.getElementById("tdblank").style.backgroundColor="#036ec0";
    document.getElementById("aweekque").style.color="#036ec0";
    document.getElementById("tdviews").style.backgroundColor="#036ec0";
    document.getElementById("aviews").style.color="white";
    document.getElementById("tdtutor").style.backgroundColor="#036ec0";
    document.getElementById("atutor").style.color="white";
    return false
}
function changenewlyaddback()
{
    document.getElementById("tdnewlyadd").style.backgroundColor="white";
    document.getElementById("anewlyadd").style.color="#036ec0";
    document.getElementById("tdnew").style.backgroundColor="white";
    document.getElementById("tdmostview").style.backgroundColor="#036ec0";
    document.getElementById("amostview").style.color="white";
    document.getElementById("tdtoprated").style.backgroundColor="#036ec0";
    document.getElementById("atoprated").style.color="white";
}
function changenemostviewback()
{
    document.getElementById("tdmostview").style.backgroundColor="white";
    document.getElementById("amostview").style.color="#036ec0";
    document.getElementById("tdnewlyadd").style.backgroundColor="#036ec0";
    document.getElementById("anewlyadd").style.color="white";
    document.getElementById("tdtoprated").style.backgroundColor="#036ec0";
    document.getElementById("tdnew").style.backgroundColor="#036ec0";
    document.getElementById("atoprated").style.color="white";
}
function changetopratedback()
{
    document.getElementById("tdtoprated").style.backgroundColor="white";
    document.getElementById("atoprated").style.color="#036ec0";
    document.getElementById("tdnewlyadd").style.backgroundColor="#036ec0";
    document.getElementById("anewlyadd").style.color="white";
    document.getElementById("tdmostview").style.backgroundColor="#036ec0";
    document.getElementById("amostview").style.color="white";
    document.getElementById("tdnew").style.backgroundColor="#036ec0";
}
//Functions for BYJU's Cat Classes block
function bindfaculty()
{
    document.getElementById("byjucat").innerHTML="No faculty details available(dummy text).";
    changefacultyback()
    return false;0
}
function bindcourses()
{
    document.getElementById("byjucat").innerHTML="Coming soon(dummy text).";
    changecourseback();
    return false;
}
function bindpresenses()
{
    document.getElementById("byjucat").innerHTML="Details will be added very soon(dummy text).";
    changepresensback();
    return false;
}
//for faculty
function changefacultyback()
{
    document.getElementById("tdfaculty").style.backgroundColor="white";
    document.getElementById("faculty").style.color="#681780";
    document.getElementById("tdcouseh").style.backgroundColor="#681780";
    document.getElementById("courseh").style.color="white";
    document.getElementById("tdpresenses").style.backgroundColor="#681780";
    document.getElementById("presenses").style.color="white";
}
//for Courses highligh
function changecourseback()
{
    document.getElementById("tdcouseh").style.backgroundColor="white";
    document.getElementById("courseh").style.color="#681780";
    document.getElementById("tdfaculty").style.backgroundColor="#681780";
    document.getElementById("faculty").style.color="white";
    document.getElementById("tdpresenses").style.backgroundColor="#681780";
    document.getElementById("presenses").style.color="white";
 }
//for presenses
function changepresensback()
{
    document.getElementById("tdpresenses").style.backgroundColor="white";
    document.getElementById("presenses").style.color="#681780";
    document.getElementById("tdfaculty").style.backgroundColor="#681780";
    document.getElementById("faculty").style.color="white";
    document.getElementById("tdcouseh").style.backgroundColor="#681780";
    document.getElementById("courseh").style.color="white";
}
//Functions for Online Cat Preparation
//function bindteam()
//{
//    document.getElementById("spanonline").innerHTML="No details available(dummy text).";
//    changeteamback();
//    return false;
//}

//function dindcousehigh2()
//{
//    document.getElementById("spanonline").innerHTML="Coming soom(dummy text).";
//    changehighback();
//    return false;
//}

//function bindusp()
//{
//    document.getElementById("spanonline").innerHTML="This part will be added very soon(dummy text).";
//    changeuspback();
//    return false;
//}

//for team
function changeteamback()
{
    document.getElementById("tdteam").style.backgroundColor="white";
    document.getElementById("team").style.color="#681780";
    document.getElementById("tdch").style.backgroundColor="#681780";
    document.getElementById("ch").style.color="white";
    document.getElementById("tdusp").style.backgroundColor="#681780";
    document.getElementById("USP").style.color="white";
}
//for Courses highligh2
function changehighback()
{
    document.getElementById("tdch").style.backgroundColor="white";
    document.getElementById("ch").style.color="#681780";
    document.getElementById("tdteam").style.backgroundColor="#681780";
    document.getElementById("team").style.color="white";
    document.getElementById("tdusp").style.backgroundColor="#681780";
    document.getElementById("USP").style.color="white";
 }
//for presenses
function changeuspback()
{
    document.getElementById("tdusp").style.backgroundColor="white";
    document.getElementById("USP").style.color="#681780";
    document.getElementById("tdteam").style.backgroundColor="#681780";
    document.getElementById("team").style.color="white";
    document.getElementById("tdch").style.backgroundColor="#681780";
    document.getElementById("ch").style.color="white";
}