﻿var TopMainMenuItems = [];
var page_id_arr = 0;

function getTopMenuItems() {
    var webMethod = '/WebServices/GetTopMenuItems.asmx/TopMenuItems';
    $.ajax({
        type: "POST",
        url: webMethod,
        //  data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var items = msg.d;
            TopMainMenuItems = new Array();
            TopMainMenuItems = items;
            Set_Top_Menu();
            //            if (items.length > 0) {
            //                $.each(items, function (idx, item) {
            //                    TopMainMenuItems.push(item);
            //                });
            //            }
            //            else {
            //                alert("No records found");
            //            }
        },
        error: function (e) {
            alert(e);
            $(divToBeWorkedOn).html("Unavailable");
        }
    });
}


///////////////////////////////////////////////////////////
//For Top Menu Design

function Set_Top_Menu() {
    
    if (Page_Info.Page_ID && page_id_arr > 0 && page_id_arr <=7) {
        Info_Cell = document.getElementById("Menu_Info_Div");
        cell = document.getElementById(Page_Info.Page_ID);
    }
    else {
        Info_Cell = document.getElementById("Menu_Info_Div");
        cell = document.getElementById("Menu_0");
    }
    if (cell != null) {
        if (cell.id == "Menu_1")
            cell.className = "Top_Main_Menu_Table_Cell_Page";
        else if (cell.id == "Menu_7")
            cell.className = "Top_Main_Menu_Table_Cell_Page3";
        else
            cell.className = "Top_Main_Menu_Table_Cell_Page2";
    }

    for (i = 0; i < TopMainMenuItems.length; i++) 
    {
        div = document.getElementById(TopMainMenuItems[i].Rsc_Title);
        div.innerHTML = "<a href=\"" + TopMainMenuItems[i].Rsc_Link + "\">" +
					  	TopMainMenuItems[i].Rsc_Description + "</a>";
    }

}


function Set_Top_Menu_Mouse_Over(This) {
    Info_Cell = document.getElementById("Menu_Info_Div");

    if (This.id != Page_Info.Page_ID) {
        if (This.id == "Menu_1") {
            This.className = "Top_Main_Menu_Table_Cell_Mouse_Over";
            //This.style["color"] = "blue";
        }
        else if (This.id == "Menu_7") {
            This.className = "Top_Main_Menu_Table_Cell_Mouse_Over3";
            //This.style["color"] = "blue";
        }
        else {
            This.className = "Top_Main_Menu_Table_Cell_Mouse_Over2";
            //This.style["color"] = "blue";
        }
    }
    try {
        for (i = 0; i < TopMainMenuItems.length; i++) {
            if (This.id == TopMainMenuItems[i].Rsc_Title) {
                Info_Cell.innerHTML = TopMainMenuItems[i].Rsc_Notes;
                Manu_Top_Last_Mouse_On = i;
            }
        }
    }
    catch (ex)
    { }
}

function Set_Top_Menu_Mouse_Out(This) {
    Info_Cell = document.getElementById("Menu_Info_Div");

    if (This.id == Page_Info.Page_ID)
        if (This.id == "Menu_1")
            This.className = "Top_Main_Menu_Table_Cell_Page";
        else if (This.id == "Menu_7")
            This.className = "Top_Main_Menu_Table_Cell_Page3";
        else
            This.className = "Top_Main_Menu_Table_Cell_Page2";
    else {
        This.className = "Top_Main_Menu_Table_Cell";
    }

    try {
        if (page_id_arr >= 0 && page_id_arr <= Pages_Info.length)
            Info_Cell.innerHTML = Pages_Info[page_id_arr].Page_Details;
        else
            Info_Cell.innerHTML = "";
    }
    catch (e) {
    }
}
function Set_Top_Menu_Out_Body() {

        Info_Cell = document.getElementById("Menu_Info_Div");
    try {
         Info_Cell.innerHTML = TopMainMenuItems[page_id_arr].Rsc_Notes;
    }
    catch(e){
        
    }
}

function Menu_Right_Title_Mouse_Over(This) {
    if (This.id == "Top_Menu_Right_Title_Table_Ques_id") {
        This.className = "Top_Menu_Right_Title_Table_Ques_Over";
    }
    else if (This.id == "Top_Menu_Right_Title_Table_Email_id") {
        This.className = "Top_Menu_Right_Title_Table_Email_Over";
    }
    else if (This.id == "Top_Menu_Right_Title_Table_Home_id") {
        This.className = "Top_Menu_Right_Title_Table_Home_Over";
    }
}

function Menu_Right_Title_Mouse_Out(This) {
    if (This.id == "Top_Menu_Right_Title_Table_Ques_id") {
        This.className = "Top_Menu_Right_Title_Table_Ques";
    }
    else if (This.id == "Top_Menu_Right_Title_Table_Email_id") {
        //background:url(index_img/Mail_PSD_buttom.png) no-repeat;
        This.className = "Top_Menu_Right_Title_Table_Email";
    }
    else if (This.id == "Top_Menu_Right_Title_Table_Home_id") {
        This.className = "Top_Menu_Right_Title_Table_Home";
    }
}

function showBooks() {

    var evalue = "";
    //var etype = 'ordered';
    var divToBeWorkedOn = '#newscontent';
    var webMethod = 'WebServices/CentralLibrary.asmx/Getbooks';
    //var parameters = "{'evalue':'" + evalue + "','etype':'" + etype + "'}";
    //var parameters = "{'newsType':'" + newsType + " '}";
    //alert('lkj');
    $.ajax({
        type: "POST",
        url: webMethod,
        //  data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            //alert(msg.d);
            //alert('truetrue');
            $(divToBeWorkedOn).html(msg.d);
        },
        error: function (e) {
            //alert(e);
            $(divToBeWorkedOn).html("Unavailable");

        }
    });

    $('#newscontent').animate({
        opacity: 0.8,
        left: '+=50',
        height: '400'
    }, 2000, function () {

        // Animation complete.

    });

}


function validate_Account(id, pass) {
    
    //err = "nochange";
    var webMethod = '/WebServices/MemberShip/Login.asmx/SignIn';
    var parameters = "{'id':'" + id + "','pass':'" + pass + "'}";
    $.ajax({
        type: "POST",
        url: webMethod,
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            userLogin = msg.d;
        },
        error: function (e) {
            userLogin = e;
        },
        complete: function () {
            if(userLogin=="true")
            window.location = '/news1.aspx';
        }

    });
//    alert(userLogin);
    

}


function login() {
    var id = $("#User_Name_Area_Text_id").val();
    var pass = $("#Password_Area_Text_id").val();
    validate_Account(id, pass);
    //alert(err);
    //alert("   id: " + id + "\n" + " pass: " + pass);
    //window.location = 'http://www.yahoo.com';
}



