/**cookie*/
function getcookie(name){
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : decodeURIComponent(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
//收藏，支持Fox
function addfavorite(url,name){
   if (document.all){
      window.external.addFavorite(url,name);
   }
   else if (window.sidebar){
      window.sidebar.addPanel(name,url,"");
   }
}
/*弹出窗口*/
function block(id,msg,twidth,theight,border_string,padding_string){
	if(!twidth)twidth="250";
	if(!theight)theight = "150";
	if(!border_string)border_string = '2px solid #268F00';
	if(!padding_string)padding_string = '10px'
	//var tmargin_left =parseInt(twidth/2);
	//var margin_str = '-'+parseInt(theight/2)+'px 0 0 -'+tmargin_left+'px';
	var margin_str = '0 auto';
	if(document.getElementById(id)!=null){
		$('#'+id).block(msg, { border:border_string ,padding:padding_string,cursor:'default',width:twidth,margin:margin_str});
	}else{
		$.blockUI(msg, { border: border_string,padding:padding_string,cursor:'default',width:twidth,margin:margin_str});
	}
}
function unblock(id){
	if(document.getElementById(id)!=null){
		$('#'+id).unblock();
	}else{
		$.unblockUI();
	}
}
function askMiniMsg(_id,_msg,_width,_height){
	$.blockUI.defaults.overlayCSS.opacity = '0';
	if(!_width)_width = 200;
	if(!_height)_height = 50;
	block(_id,_msg,_width,_height);
}

function askMiniMsgWithTime(_id,_msg,_time,_width,_height){
	askMiniMsg(_id,_msg,_width,_height);
	setTimeout(function(){unblock(_id)},_time*1000);
}

function askConfirm(msg,id,functionV,functionV2,butv1,butv2)
{
	if(!id)id='';
	if(!butv1)butv1='确定';
	if(!butv2)butv2='取消';
	var html = '<div class="content">'+msg+'</div>';
	html += '<div class="buttons"><input type="button" id="myblog_confirm_cancel" value="'+butv2+'"/><input type="button" id="myblog_confirm_button" value="'+butv1+'"/></div>';
	askMiniMsg(id,html,500,100)
	$('#myblog_confirm_button').click(function(){
		unblock(id)
		if(functionV){$(functionV)}
	})
	$('#myblog_confirm_cancel').click(function(){
		unblock(id)
		if(functionV2){$(functionV2)}
	})	
}

function askImageCode(root_url,id,encode_input_name,refresh_text)
{
	if(!id) id = "img_code";
	var str = '<span id="' + id + '" style="cursor:pointer"></span>';
	if(refresh_text)
	{
		str += '<a href="javascript:void(0)" id="href_' + id + '">' + refresh_text + '</a>';
	}
	var url = root_url + '/imgcode.php?';
	if(encode_input_name) url = url + 'name=' + encode_input_name + '&';
	document.write(str);
	$('#'+id).load(url + Math.random());
	$('#'+id).click(function(){
		$('#'+id).load(url + Math.random());
	})
	$('#href_'+id).click(function(){
		$('#'+id).load(url + Math.random());
	})
}

function favQuestion(qid,div)
{
	if(!div)var div='_div_title_msg';
	$.ajax({
		type:'post',
		url:'/index.php?q/ajax/fav',
		data:'qid='+qid,
		success:function(msg){
    		askMiniMsgWithTime(div,msg,3)
		}
	})
}
function copyToClipBoard(_content,div) {
	if($.browser.msie){
		window.clipboardData.setData("Text",_content);
		askMiniMsgWithTime(div,"复制成功，请粘贴到你的QQ/MSN上推荐给你的好友",3,270)
	}else{
		askMiniMsgWithTime(div,"您的浏览器不支持该操作！请手动复制！",3,270)
	}
}
function answer_question()
{
	$('#search_form').submit();	
}
function answer_search()
{
	var _keyword = $('#keyword').val();
	if(_keyword=='' || _keyword=='输入关键字搜索答案 或 输入问题直接提问')
	{
		askMiniMsgWithTime('search_msg','请输入内容!',1,120)
		$('#keyword').focus();
	}
	else
	{
		window.open('/index.php?search_' + encodeURIComponent(_keyword) + '.html');
	}
}
var showmenu = function() { 
    if (document.all&&document.getElementById) { 
        navRoot = document.getElementById("nav"); 
		if(navRoot)
        for (i=0; i<navRoot.childNodes.length; i++) { 
            node = navRoot.childNodes[i]; 
            if (node.nodeName=="LI"){
                node.onmouseover=function(){ 
                this.className+=" over"; 
                }
                node.onmouseout=function() { 
                this.className=this.className.replace(" over", ""); 
                } 
            }
        }
		navRoot2 = document.getElementById("nav2"); 
		if(navRoot2)
        for (i=0; i<navRoot2.childNodes.length; i++) { 
            node2 = navRoot2.childNodes[i]; 
            if (node2.nodeName=="LI"){
                node2.onmouseover=function(){ 
                this.className+=" over"; 
                }
                node2.onmouseout=function() { 
                this.className=this.className.replace(" over", ""); 
                } 
            }
        }
		navRoot3 = document.getElementById("nav3"); 
		if(navRoot3)
        for (i=0; i<navRoot3.childNodes.length; i++) { 
            node3 = navRoot3.childNodes[i]; 
            if (node3.nodeName=="LI"){
                node3.onmouseover=function(){ 
                this.className+=" over"; 
                }
                node3.onmouseout=function() { 
                this.className=this.className.replace(" over", ""); 
                } 
            }
        }
		navRoot4 = document.getElementById("nav4"); 
		if(navRoot4)
        for (i=0; i<navRoot4.childNodes.length; i++) { 
            node4 = navRoot4.childNodes[i]; 
            if (node4.nodeName=="LI"){
                node4.onmouseover=function(){ 
                this.className+=" over"; 
                }
                node4.onmouseout=function() { 
                this.className=this.className.replace(" over", ""); 
                } 
            }
        }
    }
}
window.onload = showmenu;
function observer(functionV)
{
	this.update = functionV;
}
function LoginSubject()
{
	this.observers = [];//观察者
	this.loginUserId = 0;//登陆用户ID
	this.loginUserName = '';//登陆用户名称
	this.loginIntegral = 0; //积分
}
LoginSubject.prototype.add = function(obj,_runNow)
{
	this.observers.push(obj);
}
LoginSubject.prototype.notify = function()
{
	var _tmp = this.observers.pop();
	while(_tmp!=null)
	{
		_tmp.update();
		_tmp = this.observers.pop();
	}
}

var quickaskfirstshow=true;
function quickask(){
if(quickaskfirstshow==true){
  var temp_float=new String;
  var Dh=parseInt(document.documentElement.scrollHeight);
  var Dw=parseInt(document.documentElement.scrollWidth);
  temp_float="<div id=\"quickaskfloatBoxBg\" style=\"height:"+Dh+"px;width:"+Dw+";filter:alpha(opacity=0);opacity:0;\"></div>";
  temp_float+="<div id=\"quickaskfloatBox\" class=\"kslogin\"><p id=\"kslogin_top\"><span>[<a href=\"javascript:;\">关闭</a>]</span>亲爱的用户，您还没有登陆！</p>";
  temp_float+="<div class=\"lgzc\">";
  temp_float+="<div class=\"loginku\">";
  temp_float+="<ul><li><tt>帐号名称：</tt><input type=\"text\" id=\"_username\" /></li><li><tt>密　　码：</tt><input type=\"password\" id=\"_passwd\" /></li></ul>";
  temp_float+="<dl><dt><a href=\"javascript:;\" onclick=\"asklogin()\">登 陆</a></dt><dd><a href=\"javascript:;\" target=\"_blank\">忘记密码?</a></dd></dl></div>";
  temp_float+="<div class=\"zc\"><p>您还没有申请优一网免费帐号？</p><a href=\"http://my.u91.com/?register/1\">立即注册</a></div></div>";
  temp_float+="<div class=\"ksbut\"><p><a href=\"javascript:;\" id=\"directask\"></a></p></div></div>";
  $("body").append(temp_float);
  quickaskfirstshow=false;
}
$("#kslogin_top span").click(function(){
  $("#quickaskfloatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
  window.onscroll='';
  window.onresize='';
  $("#quickaskfloatBox").hide(); 
});
$("#directask").click(function(){
  $("#quickaskfloatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
  window.onscroll='';
  window.onresize='';
  $("#quickaskfloatBox").hide(); 
});
$("#quickaskfloatBoxBg").show();
$("#quickaskfloatBoxBg").animate({opacity:"0.5"},"normal");
scollask();
window.onscroll=scollask;
window.onresize=scollask;
}
function scollask()
{
var Dh=parseInt(document.documentElement.clientHeight);
var Dw=parseInt(document.documentElement.clientWidth);
var height = '230';
var width = '400';
$("#quickaskfloatBox").css({display:"block",left:(Dw/2-200)+"px",top:(Dh-300)/2+parseInt(document.documentElement.scrollTop)+"px",width:width,height:height});
}
function asklogin()
{
	var username = $('#_username').val();
	var passwd = $('#_passwd').val();
	if(!username || !passwd)
	{
		alert('请填写完整资料再提交！');
		return false;
	}
	$.ajax({
		   url:'/index.php?asklogin',
		   type:'POST',
		   data:'username='+username+'&passwd='+passwd,
		   success: function (msg)
		   {
			   if(msg=='success'){
			   window.location.reload();
			   }else{
				   alert(msg);
			   }
		   }
	})
}
