var nType = 0;
var nSecond = 0;
var issend = 0;

$(document).ready(function() {
    GetLoginInfor();
    setListValue(); 
});

this.setListValue = function()
{
    var url = window.location.toString();
    url = url.toLowerCase();
    url = url.replace("#","");
    var paras = url.split("?");
    if(paras.length == 2)
    {
        var params = paras[1].split('&');
        for(i=0; i< params.length;i++)
        {
            if(params[i].indexOf("t=") >= 0)
            {
                nType = params[i].replace("t=","");
            }
            if(params[i].indexOf("s=") >= 0)
            {
                nSecond = params[i].replace("s=","");
            }
            if(params[i].indexOf("url=") >= 0)
            {
               $("#im1").attr("src",unescape(params[i].replace("url=","")));
            }
        }
    }
    
    $("#list"+nType+"").attr("class","FaqList1")
    $("#list"+nType+"").attr("background","/service/images/sartservice_14.jpg")
    
    $("#imgsecond"+nSecond+"").attr("src","/usercenter/images/bottomlittle_03.jpg");
}

this.GetLoginInfor = function()
{
    Request.sendPOST("../AjaxLogin.aspx", "d="+new Date+"&n=4",
    this.bind(this, this.ReturnInfor), null, null); 
}

this.ReturnInfor = function(req)//载入页面输出登录信息
{
    if(req.responseText == "")
    {
        $("#loginin").show();
        return;
    }
    $("#LoginArea").show();
    $("#LoginArea").html(req.responseText);
}


this.UserLogin = function()
{
    
    if($("#txbUserName").val() == "")
    {
        $("#mes").html('请填写用户名');
        return;
    }
    if($("#txbPwd").val() == "")
    {
        $("#mes").html('请填写密码');
        return;
    }
    if(issend == 1)
    {
        $("#mes").html('登录中…请稍候…');
        return;
    }
    issend=1;
    Request.sendPOST("../AjaxLogin.aspx", "d="+new Date+"&n=3&un="+escape($("#txbUserName").val())+"&pw="+escape($("#txbPwd").val()),
    this.bind(this, this.ReturnSend), null, null); 
}

//解决回调函数中，this引用无效的问题
this.bind = function(instance, method)
{
    return function()
    {
	    method.apply(instance, arguments);
    }
}

this.ReturnSend = function(req)//回调函数
{
    issend = 0;
    if(req.responseText == "")
    {
        $("#mes").html('用户名密码有误');
        return;
    }
    $("#loginin").hide();
    $("#LoginArea").show();
    $("#LoginArea").html(req.responseText);
}


jQuery.fn.setIframeHeight = function() {
    var $_self = this; 
    $_self[0].onload = function(){
        //下面2种获取高度的方式都可
        //var height1 = $( window.frames[$_self[0].name].document.body ).height();
        var height = $_self.contents().find("body").height();
        if( height < 600){
	        $_self.height(600);
        }else{
	        $_self.height( height+30 );
        }
    }
    return this;
}

$(function(){
    $("#im1").setIframeHeight();
});


this.setLoginOut = function()
{
    Request.sendPOST("/LoginOut.aspx", "d="+new Date+"",
    this.bind(this, this.ReturnOut), null, null); 
}

this.ReturnOut = function(req)//退出
{
   $("#loginin").show();
   $("#LoginArea").hide();
   $("#LoginArea").html('');
   $("input").val('');
}

this.GoUrl = function(url,nType,nSecond)
{
    $("#im1").attr("src",url);
    $("#im1").setIframeHeight();
    $("td[class='FaqList1']").map(function(){
        $(this).attr("class","FaqList");
        $(this).attr("background","/service/images/sartservice_16.jpg");
    })
    $("td[background='/service/images/sartservice_14.jpg']").map(function(){
        $(this).attr("background","/service/images/sartservice_16.jpg");
    })
    $("#list"+nType+"").attr("background","/service/images/sartservice_14.jpg")
    $("#list"+nType+"").attr("class","FaqList1")
    if(nSecond > 0)
    {
        $("img[src='/usercenter/images/bottomlittle_03.jpg']").map(function(){
        $(this).attr("src","/usercenter/images/bottomlittle_06.jpg");
        })
        $("#imgsecond"+nSecond+"").attr("src","/usercenter/images/bottomlittle_03.jpg");
    }
    
}