var MAX_BUILDING_NUMBER = 32 //max building number, and imply that one building, one unit
var MAX_PRODUCE_NUMBER = 4 //max produce sequences for one unit, refer to VIP
var MAX_GOODS_TYPE = 30 //max number of goods' types
function start(){
    fi(1)
    wi(1)
    ci(1)
    mi(1)
    pi(1)
    setInterval(show_st,1000)
    //show_st()
    //g1i(1) because changed unit produce way, now it's no use. consider later.
}

function fi(t){
    //food increase
    //alert('here')
    myElement = document.getElementById('f')
    //alert(myElement)
    if(myElement != null) {
        if (myElement.title>0) {
            {
            d = myElement.innerHTML.split("/");
            food = parseInt(d[0]); //food amount
            limit = parseInt(d[1]); //food limit
            inc = myElement.title/3600;
            if(food != limit)
                {
                setTimeout("fi(0)", 1/inc*1000);
                if(t == 0){myElement.innerHTML=food + 1 + "/" + limit;}
                }
            }
        }
    }
}

function wi(t){
    //wood increase
    myElement = document.getElementById('w');
    if(myElement != null)
    {
    if (myElement.title>0) {
    d = myElement.innerHTML.split("/");
    wood = parseInt(d[0]); //wood amount
    limit = parseInt(d[1]); //wood limit
    inc = myElement.title/3600;
    if(wood != limit)
    {
    setTimeout("wi(0)", 1/inc*1000);
    if(t == 0){myElement.innerHTML=wood + 1 + "/" + limit;}
    }
    }
    }
}

function ci(t){
    //clay increase
    myElement = document.getElementById('c');
    if(myElement != null)
    {
    if (myElement.title>0) {
    d = myElement.innerHTML.split("/");
    clay = parseInt(d[0]); //clay amount
    limit = parseInt(d[1]); //clay limit
    inc = myElement.title/3600;
    if(clay != limit)
    {
    setTimeout("ci(0)", 1/inc*1000);
    if(t == 0){myElement.innerHTML=clay + 1 + "/" + limit;}
    }
    }
    }
}

function mi(t){
    //mine increase
    myElement = document.getElementById('m');
    if(myElement != null)
    {
    if (myElement.title>0) {
    d = myElement.innerHTML.split("/");
    mine = parseInt(d[0]); //mine amount
    limit = parseInt(d[1]); //mine limit
    inc = myElement.title/3600;
    if(mine != limit)
    {
    setTimeout("mi(0)", 1/inc*1000);
    if(t == 0){myElement.innerHTML=mine + 1 + "/" + limit;}
    }
    }
    }
}

function pi(t){
    //pop increase
    myElement = document.getElementById('p');
    //alert(myElement.title)
    if(myElement != null)
    {
    d = myElement.innerHTML.split("/");
    pop = parseInt(d[0]); //population
    limit = parseInt(d[1]); //pop limit
    inc = myElement.title/3600;
    if(pop != limit)
    {
    setTimeout("pi(0)", 1/inc*1000);
    if(t == 0){myElement.innerHTML=pop + 1 + "/" + limit;}
    }
    }
}

function valid(num)
{
//alert("here");
if(isNaN(num) == true) {num = 0;}
document.form1.num1.value=num
//return num;
}

function g1i(t){
    //function to deal with goods' increase, according to the unit's produce sequences.
    //for all unit, check if there's produce seq. exists or not...
    for ( var i = 1; i < MAX_BUILDING_NUMBER; i++ ) { //because unit_type is bounded to building.
        up = document.getElementById('up'+i+'_'+1) 
        //unit produce, from the first produce seq. of the unit, so it's "1"
        
        if (up!=null) {
            //parse the up data, now it's like: 
            //<li id=up21_1 style="display:none">3.333/1/11053/3/2007,04,08,17,57,12</li>
            //they are: produce_speed/unit_seq/goods_quantity/goods.id/last_goods_finish_time
            u = up.innerHTML.split("/"); 
            var temp = u[2] - Math.floor(u[2]);
            var time_now = new Date()

            uu = u[4].split(",");
            //u[4] is like 2007,04,08,02,46,12
            
            var time_lgf = new Date()
            time_lgf.setYear(uu[0])
            time_lgf.setMonth(uu[1]-1)
            time_lgf.setDate(uu[2])
            time_lgf.setHours(uu[3],uu[4],uu[5])
            
            timed = time_now.getTime() - Date.parse(time_lgf)  
            
            setTimeout("good_inc('" + parseInt(u[3]) + "','" + i + "','" + 1 + "','" + 1 +"')", 3600000/u[0]-timed)            
            //alert(3600000/u[0]-timed)
            //setTimeout("good_inc('" + parseInt(u[3]) + "','" + i + "','" + 1 + "','" + 0 +"')", 3600000*temp/u[0])
        }
    }
}

//no use now.
function good_inc(gid,uid,seq,t) {
    //sub-function to deal with goods' increase, according to the unit's produce sequences.
    //alert(gid)
    goods=document.getElementById('g'+gid);
    up = document.getElementById('up'+uid+'_'+seq);
    if (up!=null) {
        u = up.innerHTML.split("/");

        //else {
            if (parseInt(u[2])==0) { //this produce seq. completed, start to deal with next one. note:still same unit.
                var next_seq = parseInt(seq)+1
                //alert(next_seq)
                up = document.getElementById('up'+uid+'_'+next_seq);
                if (up != null) {
                    //alert("here")
                    //setTimeout("good_inc('" + gid + "','" + uid + "','" + next_seq + "','" + 1 +"')", 3600000/u[0])
                    setTimeout("good_inc('" + gid + "','" + uid + "','" + next_seq + "','" + 1 +"')", 0)
                }
            }
            else { //still the same produce sequence.
                goods.innerHTML = parseInt(goods.innerHTML) + 1
                //alert("here")
                up.innerHTML = u[0]+"/"+ u[1]+"/"+ (parseInt(u[2])-1) +"/"+gid;
                setTimeout("good_inc('" + gid + "','" + uid + "','"+ seq + "','" + 1 +"')", 3600000/u[0])
            }
        //}
    }
}

function minus_res(wood,clay,mine,food,silver,pop) {
    //minus resources. mainly be used when in ajax function.
    vs = vs - silver
    vf = vf - food
    vw = vw - wood
    vc = vc - clay
    vm = vm - mine
    vp = vp - pop
    document.getElementById('s').innerHTML = vs + "/" + vsl
    document.getElementById('f').innerHTML = vf + "/" + vfl
    document.getElementById('w').innerHTML = vw + "/" + vrl
    document.getElementById('c').innerHTML = vc + "/" + vrl
    document.getElementById('m').innerHTML = vm + "/" + vrl
    document.getElementById('p').innerHTML = vp + "/" + vpl
    document.getElementById('t').innerHTML = parseInt(document.getElementById('t').innerHTML) - parseInt(pop / 50)
}

function event_timer(time_remain,counter) {
    rt = parseInt(time_remain) + 4 //compensation for server dealing time...try
    eventid=document.getElementById('event_time_remain'+counter);
    if (rt == 0) 
    {
       window.location.reload();
    }
    else 
    {  
       eventid.innerHTML = time_format(rt);
       time_remain = time_remain - 1
       setTimeout("event_timer('" + time_remain + "','" + counter + "')",1000) 
    }
}

function event_timer_wonder(time_remain,counter) { //for wonder event, no reload page after it arrives!
    rt = parseInt(time_remain) + 2 //compensation for server dealing time...try
    eventid=document.getElementById('event_time_remain'+counter);
    if (rt > 0)
    {  
       eventid.innerHTML = time_format(rt);
       time_remain = time_remain - 1
       setTimeout("event_timer_wonder('" + time_remain + "','" + counter + "')",1000) 
    }
    else {
        eventid.innerHTML = "0:00:0x";
    }
}

function time_format(s) {
//from seconds to hh:mm:ss format. if more than 1 day, show xx天.
var t;
if(s > -1){
    hour = Math.floor(s/3600);
    min = Math.floor(s/60) % 60;
    sec = s % 60;
    day = parseInt(hour / 24);
    if (day > 0) {
        hour = hour - 24 * day;
        t = day + "天," + hour + ":";
        }
    else t = hour + ":";
    
    if(min < 10){t += "0";}
        t += min + ":";
    if(sec < 10){t += "0";}
        t += sec;}
else
    {t = "0:00:0x";}
return t;
}

function CurentTime(){  
    var mm = now.getMinutes();  
    var ss = now.getTime() % 60000;ss = (ss - (ss % 1000)) / 1000;  
    var clock = now.getHours() +':';  
    if (mm < 10) clock += '0'; 
    clock += mm+':';  
    if (ss < 10) clock += '0';  
    return(clock + ss); 
}  

function show_st(){ 
    document.getElementById('server_time_id').innerHTML = CurentTime();now.setSeconds(now.getSeconds()+1); 
    //setTimeout("show_st()", 1000); 
} 

function live_combat_timer(time_remain) {
    //timer for live combat, now in testing!
    //note:because js count month from 0 to 11, so in template, use format as: |date:"Y,m-1,d,H,i,s"
    var rt = parseInt(time_remain) + 5 //compensation for server dealing time...try
    
    eventid=document.getElementById('next_round_time_remain'); 
    if (rt == 0) 
    {
       window.location.reload();
    }
    else 
    {  
       eventid.innerHTML = time_format(rt);
       time_remain = time_remain - 1
       setTimeout("live_combat_timer('" + time_remain + "')",1000) 
    }
}

function add_train(gid,n){document.getElementById('soldier_number'+gid).value=document.getElementById('m'+gid).innerHTML;}

//trade transfer
function add_res(rid,rname,number) {
    var c;
    if (document.transform.caravan_left.value==0) {
        if (rname != 'silver') {return 0}
        }
    
    switch (rname)
         {
            case 'wood_number':
                c = document.transform.wood_number.value;
                document.getElementById("caravan_left2").innerHTML = document.getElementById("caravan_left2").innerHTML - 1;
                document.getElementById("caravan_left3").innerHTML = document.getElementById("caravan_left3").innerHTML - 1;
                document.getElementById("caravan_left4").innerHTML = document.getElementById("caravan_left4").innerHTML - 1
            break;
            case 'clay_number':
                c = document.transform.clay_number.value;
                document.getElementById("caravan_left1").innerHTML = document.getElementById("caravan_left1").innerHTML - 1;
                document.getElementById("caravan_left3").innerHTML = document.getElementById("caravan_left3").innerHTML - 1;
                document.getElementById("caravan_left4").innerHTML = document.getElementById("caravan_left4").innerHTML - 1
            break;
            case 'mine_number':
                c = document.transform.mine_number.value;
                document.getElementById("caravan_left1").innerHTML = document.getElementById("caravan_left1").innerHTML - 1;
                document.getElementById("caravan_left2").innerHTML = document.getElementById("caravan_left2").innerHTML - 1;
                document.getElementById("caravan_left4").innerHTML = document.getElementById("caravan_left4").innerHTML - 1
            break;
            case 'food_number':
                c = document.transform.food_number.value;
                document.getElementById("caravan_left1").innerHTML = document.getElementById("caravan_left1").innerHTML - 1;
                document.getElementById("caravan_left2").innerHTML = document.getElementById("caravan_left2").innerHTML - 1;
                document.getElementById("caravan_left3").innerHTML = document.getElementById("caravan_left3").innerHTML - 1
            break;
            case 'silver':
                c = document.transform.silver.value;
            break;
         } 

    if (c=='') {
        a = 0
    }
    else {
        if (isNaN(parseInt(c))){
            a= 0
        }
        else {
            a = parseInt(c)
        }
    }
    a = a + number
    rid.value = a
    
    document.transform.caravan_left.value = document.transform.caravan_left.value - 1
    //alert(document.transform.caravan_left.value);
    
}

function multi_res(rid) {
    var ta = 0 //judge if reset all x to 0
    if (document.transform.caravan_left.value==0) {
        return 0;
    }
    if (rid==1) {
        if (document.transform.wood_number.value !='') {
            ta=1;document.transform.wood_number.value = parseInt(document.transform.wood_number.value) * document.getElementById("caravan_left1").innerHTML
        }
    }
    if (rid==2) {
        if (document.transform.clay_number.value !='') {
            ta=1;document.transform.clay_number.value = parseInt(document.transform.clay_number.value) * document.getElementById("caravan_left2").innerHTML
        }
    }
    if (rid==3) {
        if (document.transform.mine_number.value !='') {
            ta=1;document.transform.mine_number.value = parseInt(document.transform.mine_number.value) * document.getElementById("caravan_left3").innerHTML
        }
    }
    if (rid==4) {
        if (document.transform.food_number.value !='') {
            ta=1;document.transform.food_number.value = parseInt(document.transform.food_number.value) * document.getElementById("caravan_left4").innerHTML
        }
    }
    if (ta==1) {
        document.getElementById("caravan_left1").innerHTML = 0;
        document.getElementById("caravan_left2").innerHTML = 0;
        document.getElementById("caravan_left3").innerHTML = 0;
        document.getElementById("caravan_left4").innerHTML = 0;
        document.transform.caravan_left.value = 0;
    }
    
}

function multi_silver(n) {
    if (document.transform.silver.value !='') {
        document.transform.silver.value = parseInt(document.transform.silver.value) * n
    }
}

function checkAll(name)
//check all the checkbox...
{
    var el = document.getElementsByTagName('input');
    var len = el.length;
    for(var i=0; i<len; i++)
    {
        if((el[i].type=="checkbox") && (el[i].name==name))
        {
            el[i].checked = true;
        }
    }
}
function clearAll(name) 
{
    var el = document.getElementsByTagName('input');
    var len = el.length;
    for(var i=0; i<len; i++)
    {
        if((el[i].type=="checkbox") && (el[i].name==name))
        {
            el[i].checked = false;
        }
    }
}

function SetCookie(name,value)
{
var Days = 30; //30 days
var exp = new Date(); // or .... new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}

function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}


function updateMsg() {
    var time_now = new Date();
    $.getJSON("/chat/?t="+time_now.getTime()+"&m="+ $("#max_message_number").val(),
      function(data){
        if (data.messege != '') {
            //alert(data.messege);
            $("#chatwindow").append(String(data.messege));
            //data.messege.appendTo("#chatwindow");
            $.each(data.messege, function(i,messege){
              //$("<img/>").attr("src", item.media.m).appendTo("#images");
              //messege.appendTo("#chatwindow");
              if ( i == 3 ) return false;
            });
            document.chatform.max_message_number.value = data.user_max_mes;
            scroll_to_bottom();
        }
        //else {alert('no data')}
      });

 setTimeout('updateMsg()', 5000);
};

function scroll_to_bottom() {
    var objDiv = document.getElementById("chatwindow");
    objDiv.scrollTop = objDiv.scrollHeight;
}

function updateMsg2() {
    var time_now = new Date();
    $.getJSON("/chat2/?t="+time_now.getTime()+"&m="+ $("#max_message_number2").val(),
      function(data){
        if (data.messege != '') {
            $("#chatwindow2").append(String(data.messege));
            $.each(data.messege, function(i,messege){
              if ( i == 3 ) return false;
            });
            document.getElementById("max_message_number2").value = data.user_max_mes;
            scroll_to_bottom2();
        }
      });

 setTimeout('updateMsg2()', 10000);
};

function scroll_to_bottom2() {
    var objDiv = document.getElementById("chatwindow2");
    objDiv.scrollTop = objDiv.scrollHeight;
}

jQuery.sub_sim = function(sub_type) { //battle simulator
    //alert(sub_type);
    $.post("/military/simulator/",{
                attacker_type:  $("select[name='attacker_type']").val(),
                defender_type:  $("select[name='defender_type']").val(),
                attacker_force:  $("input[name='attacker_force']").val(),
                defender_force:  $("input[name='defender_force']").val(),
                attacker_number:  $("input[name='attacker_number']").val(),
                defender_number:  $("input[name='defender_number']").val(),
                a_level:  $("select[name='a_level']").val(),
                d_level:  $("select[name='d_level']").val(),
                a_starve:  $("input[name='a_starve']").attr("checked"),
                d_starve:  $("input[name='d_starve']").attr("checked"),
                a_ladder_number:  $("input[name='a_ladder_number']").val(),
                d_wall_level:  $("select[name='d_wall_level']").val(),
                sub_type:sub_type,
                method: 'POST'
            }, function(data) {
                $("#result").html('');
                $("#anum_error").html('');
                $("#dnum_error").html('');
                $("#aforce_error").html('');
                $("#dforce_error").html('');
                $("#a_ladder_error").html('');
                if (data.attacker_number) {
                  document.getElementById("anum_error").innerHTML=data.attacker_number
                }
                if (data.defender_number) {
                  document.getElementById("dnum_error").innerHTML=data.defender_number
                }
                if (data.attacker_force) {
                  document.getElementById("aforce_error").innerHTML=data.attacker_force
                }
                if (data.defender_force) {
                  document.getElementById("dforce_error").innerHTML=data.defender_force
                }
                
                if (data.a_ladder_number) {
                  document.getElementById("a_ladder_error").innerHTML=data.a_ladder_number
                }
                if (data.sub_type==3) {
                      $("#result").append(data.death_result);
                }
                else {
                    if (data.result1) {
                      $("#result").append(data.result1);
                    }
                    if (data.result2) {
                      $("#result").append(data.result2);
                    }
                }
                if (data.total_result) {
                    $("#result").append('***************<br>');
                    $("#result").append(data.total_result);
                }
                if (data.sub_type!=1) {
                  if (data.attacker_casulty) {
                      $("input[name='attacker_number']").attr("value", $("input[name='attacker_number']").val()-data.attacker_casulty)
                  }
                  if (data.defend_casulty) {
                      $("input[name='defender_number']").attr("value", $("input[name='defender_number']").val()-data.defend_casulty)
                  }
                }
        },'json');
        return false;
};

function soldier_train(general_id) {
    $.post("/military/train/",{
                train_number: document.getElementById('soldier_number'+general_id).value,
                general_id: general_id,
                method: 'POST'
            }, function(data) {
                if (data.body[0][0] == "error") {
                    document.getElementById('train_error'+data.body[1][1]).innerHTML = data.body[0][1];
                }
                else {
                    document.getElementById('rb'+data.body[0][1]).disabled=false;
                    minus_res(data.body[1][1],data.body[2][1],data.body[3][1],data.body[4][1],data.body[5][1],data.body[6][1]);
                    document.getElementById('in_traing'+data.body[0][1]).innerHTML = data.body[7][1];
                    document.getElementById('train_error'+data.body[0][1]).innerHTML = "";
                    document.getElementById('soldier_number'+data.body[0][1]).value="";
                    
                }
        },'json');
        return false;
};

jQuery.swordsman_add_skill = function(sid,skillid) {
    $.post("/military/swordsman_as/",{
                sid: sid,
                skillid: skillid,
                method: 'POST'
            }, function(data) {
                if (data.body[0][0] == "success") {
                    a = document.getElementById(data.body[2][1]+'_' + data.body[1][1])
                    b = parseInt(a.innerHTML)
                    aa = document.getElementById(data.body[2][1]+'_un')
                    var sp_left = parseInt(aa.innerHTML)-1
                    if (sp_left >= 0 ){ /*must, or will have display error */
                        a.innerHTML = b + 1
                        aa.innerHTML = sp_left
                    }
                    if (sp_left == 0) {
                        document.getElementById(data.body[2][1]+'_1_plus').innerHTML = "(<b>+</b>)"
                        document.getElementById(data.body[2][1]+'_2_plus').innerHTML = "(<b>+</b>)"
                        document.getElementById(data.body[2][1]+'_3_plus').innerHTML = "(<b>+</b>)"
                    }
                    }
                else {
                    window.location.reload()
                    }
                
        },'json');
        return false;
};

jQuery.general_add_property = function(gid,pid) {
    $.post("/military/general_add_property/",{
                gid: gid,
                pid: pid,
                method: 'POST'
            }, function(data) {
                if (data.body[0][0] == "success") {
                    a = document.getElementById(data.body[2][1]+'_' + data.body[1][1])
                    b = parseInt(a.innerHTML)
                    aa = document.getElementById(data.body[2][1]+'_un')
                    var pp_left = parseInt(aa.innerHTML)-1
                    if (pp_left >= 0 ){ /*must, or will have display error */
                        a.innerHTML = b + 1
                        aa.innerHTML = pp_left
                        if (data.body[1][1]==1) { //added dominion, change max. soldier number
                            document.getElementById('max_sn'+data.body[2][1]).innerHTML = parseInt(document.getElementById('max_sn'+data.body[2][1]).innerHTML)+50
                        }
                    }
                    if (pp_left == 0) {
                        document.getElementById(data.body[2][1]+'_1_plus').innerHTML = "(<b>+</b>)"
                        document.getElementById(data.body[2][1]+'_2_plus').innerHTML = "(<b>+</b>)"
                        document.getElementById(data.body[2][1]+'_3_plus').innerHTML = "(<b>+</b>)"
                    }
                    }
                else {
                    window.location.reload()
                    }
                
        },'json');
        return false;
};



//in city.
function change_color(position_id,background_id,title) {
var myi = document.getElementById("myimg");
var mya = document.getElementById("myimga");
myi.style.display='';
myi.title = title;
myi.src="/site_media/img/red_bg_" + background_id +".gif";
myi.className="bld" + position_id;
mya.href="/building/" + position_id +"/";
//mya.onMouseOut="alert('a')";
}

function no_color() {//now no use...
var myi = document.getElementById("myimg");
myi.style.display='none';
}

//for emotin in online chat.
function ins_emo(eid){
    var o = document.getElementById("chatmsg");
    o.focus();
    var v = "\\" + eid;
    if(document.selection) {document.selection.createRange().text = v;}
    else {o.value = o.value.substr(0, o.selectionStart) + v + o.value.substr(o.selectionEnd);}
}

//popup window
(function($){
$.openWindow = function(options){
	var defaults = {
		title:"",                           //标题
		content:"Content",                       //显示内容
		loadUrl:"",                              //调用url
		bColor:"#777",                           //背景色
		bWidth:document.body.clientWidth+"px",   //背景宽度
		bHeight:document.body.clientHeight+"px", //背景高度
		oColor:"#eee",                           //弹出窗口颜色
		oWidth:500,                              //弹出窗口宽度
		oHeight:200                              //弹出窗口高度
	};
	$.extend(defaults,options);
	//绑定div到body
	var pop_title = "<div id='pop_title'><img src='/site_media/img/del.gif'/>"+defaults.title+"</div>";
	//var pop_frame = "<div id='pop_frame'>"+pop_title+"<div id='pop_content'>loading...</div></div>";
    var pop_frame = "<div id='pop_frame'>"+pop_title+"<div id='pop_content'><img style='float:center' src='/site_media/img/loading.gif' /></div></div>";
	if(!($("#pop_frame").length))$("body").append(pop_frame);
    
    defaults.loadUrl ? $("#pop_content").load(defaults.loadUrl) : $("#pop_content").html(defaults.content);
	 
	$("#pop_title>img").css({"cursor":"pointer","float":"right"}).click(function(){$("#pop_background").remove();$("#pop_frame").remove();});
    
    //$("#pop_title>img").css({"cursor":"pointer","float":"right"}).click(function(){$("#pop_background").remove();$("#pop_frame").hide(2000,function(){$("#pop_frame").remove()});});
    	
	
	//$("#pop_title").css({"font-size":"12px","background":"#ccc","color":"#777","margin":"5px","padding":"5px"});
	//$("#content").css({"text-algin":"left","font-size":"14px","padding":"10px 10px 10px 10px","overflow-x":"hidden","overflow-y":"auto","width":defaults.oWidth+"px","height":defaults.oHeight+"px"});
	$("#pop_frame").css({"width":defaults.oWidth+"px","top":((document.documentElement.clientHeight-defaults.oHeight)/2+document.documentElement.scrollTop-50)+"px","left":(document.body.clientWidth-defaults.oWidth)/2+"px"});
    
    //for background...
    var pop_background = "<div id='pop_background'></div>";
    if(!($("#pop_background").length))$("body").append(pop_background);
	$("#pop_background").css({"background":defaults.bColor,"width":defaults.bWidth,"height":defaults.bHeight,"z-index":"9998","position":"absolute","filter":"alpha(opacity:40)","-moz-opacity":"0.4","left":0,"top":0});
};
})(jQuery);

$(document).ready(function(){
    $("form#noteform").submit(function(){
      $.post("/vip/note_pad/",{
            note_content: $("#note_content").val(),
            method: 'POST'
          }, function() {
                var s=document.getElementById('note_hid');s.style.display='none';
                document.getElementById('note_text').innerHTML=$("#note_content").val();
            });
      return false;
    });
    
    $('.pop_a').click(function(){
     $.openWindow({"loadUrl":this.href});return false;
    });
    
    $(".ajax_us").click(function(){ //for unit(general, swordsman) update and revive...
        time_now = new Date();
        var a = $(this);
        $.get($(this).attr('href') + '&t=' + time_now.getTime(),
                function(data){
                   //$("#pop_background").remove(); //only none-pop window use this!!!!
                   //$("#pop_frame").remove();
                   a.after('<div class="event_class">'+data+'</div>');
                   a.remove();
                });
        return false;
    });
});

//pop general skill description
function pop_skills(skill_id){
    if(skill_id != 0) {
        $.openWindow({"loadUrl":"/ingame_help/general_skill/" + skill_id + "/","title":"武将技能"});
    }
}

