﻿//------main------------------
var base = "http://localhost:1354/NovNotify/novn/";
var href = window.document.location.href;
base = "http://" + my_getbetween(href,"http://","/novn") + "/novn/";

//------main end -------------

//----lib -------------------
var xmlHttp;
function sendget(url)
{
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    
    xmlHttp.open("GET", url);
    xmlHttp.onreadystatechange = callback;
    xmlHttp.send(null);
}

function callback()
{
    //alert(xmlHttp.readyState);
    if(xmlHttp.readyState == 4)
    {    
        if(xmlHttp.status == 200)
        {
            //alert(xmlHttp.responseText);
            
                var dd = document.getElementById("main_data");
		        var data = xmlHttp.responseText;
		        if(data == null)
		        {
		            //dd = document.getElementById("loading_pic");
		            //dd.innerHTML = "load error ";
		            alert("访问网络失败");
		        }else{ 
		            data = my_getbetween(data,"<div>","</div>");
		            if(data.indexOf("没登录") >0)
		            {
		                alert("aa");
		                window.location = "login.aspx";
		            }
                    //dd.innerHTML = data;
                    alert(data);
                    if(data.indexOf("reload")>0)
                    {
                        window.location= window.location.href;
                    }
                }
            
        }else{
            //alert("error");
            var dd = document.getElementById("loading_pic");
		    dd.innerHTML = "";
            
        }
    }
}



function my_getbetween(str,from,to)
{
    var s = str.indexOf(from);
    if(s <0) return null;
    var e = str.indexOf(to,from.length + s);
    if(e <0)return null;
    
    return str.substring(from.length+s,e);
}

function addfav(uid,bookid,sig)
{
    sendget(base+"function.aspx?type=addfav&bookid="+bookid + "&uid="+uid + "&sig=" + sig);
}
function delfav(uid,bookid,sig)
{
    sendget(base + "function.aspx?type=delfav&bookid="+bookid + "&uid="+uid +"&sig=" + sig);
}
function reload_me()
{
    window.location = window.location.href; 
}
