var _dk = {};
_dk.client = (function(){	
	var t = {};
	var b = navigator.userAgent.toLowerCase();
	t.isOpera = (b.indexOf('opera') > -1);
	t.isIE = (!t.isOpera && b.indexOf('msie') > -1);
	t.isFF = (!t.isOpera &&!t.isIE&&b.indexOf('firefox') > -1);
	return t;
})();
_dk.util = (function(){
	var t = {};
	t.addEvent = function(o,c,h){
		if(_dk.client.isIE){
			o.attachEvent('on'+c,h);
		}else{
			o.addEventListener(c,h,false);
		}
		return true;
	};
	t.delEvent = function(o,c,h){
		if(_dk.client.isIE){
			o.detachEvent('on'+c,h);
		}else{
			o.removeEventListener(c,h,false);
		}
		return true;
	};
	return t;
})();

function $i(s){return document.getElementById(s)}
dk_hide = function(conf){
	this.conf = conf;
	var obj = ""
	obj = this.conf[0];
	var tar = this.conf[1];
	this._ax = parseInt(this.conf[2]);
	this._ay = parseInt(this.conf[3]);
	var _x,_y;
	if(!this._ax){_x = $i(obj).offsetLeft;}else{_x = $i(obj).offsetLeft+this._ax;}
	if(!this._ay){_y = $i(obj).offsetTop;}else{_y = $i(obj).offsetTop+this._ay;}
	$i(tar).onmouseover = $i(obj).onmouseover = function(){$i(tar).style.display = "block";$i(tar).style.left = _x+"px";$i(tar).style.top = _y+"px";}
	$i(tar).onmouseout = $i(obj).onmouseout = function(){$i(tar).style.display = "none";}
}
_dk.util.addEvent(window, 'load', function() {
	if($i('opt')){
		new dk_hide(["opt","searchoption","-6","-44"]);
	}	
	if($i('opencity')){
		new dk_hide(["opencity","citynav","0","15"]);
	}
});
function changeclass(obj,tar,i){
	if($i(obj) && $i(tar)){
		if(i==0){
			$i(obj).firstChild.className= "mouseover";
			$i(tar).style.display="block";
		}else if(i==1){
			$i(obj).firstChild.className= "";
			$i(tar).style.display="none";
		}
		$i(tar).onmouseover = function(){
			$i(obj).firstChild.className= "mouseover";
			$i(tar).style.display="block";
		}
		$i(tar).onmouseout = function(){
			$i(obj).firstChild.className= "";
			$i(tar).style.display="none";
		}
	}
}






 var xmlDoc;
 function getID(ajaxReqUrl){
    if(window.ActiveXObject){
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async="false"   
        xmlDoc.load(ajaxReqUrl); 
        getvalue(); 
    }
    else{
        alert("对不起，您的浏览器不支持“搜用户”功能，将打开搜索主页");
    }
 }
 
 function getvalue(){
    var nodes=xmlDoc.documentElement.childNodes;
    var value=nodes.item(0).childNodes.item(0).text ;
    window.document.getElementById('uid').value=value;
 }
 
 function searchUser(){
    var username = document.getElementById("search_keywords").value;
    var searchUrl = "http://search.19lou.com/search/uid/a0-u";
    var ajaxReqUrl = "http://health.19lou.com/member/ajax/info.xml?username=" + escape(username);
    getID(ajaxReqUrl);
    var uid = document.getElementById("uid").value;
    searchUrl = searchUrl + uid + ".html";
    open(searchUrl);
 }

 function searchIndex(n){
    var search_keywords = document.getElementById("search_keywords").value;
    if (search_keywords=="请输入搜索关键词..."){search_keywords =" ";}
    var utf8Keyword = encodeURIByUtf8(search_keywords);
    if (n==1){var searchUrl = "http://search.19lou.com/search/" + utf8Keyword ;}
        else if (n==2){var searchUrl = "http://search.19lou.com/search/" + utf8Keyword +"/a0-b2.html";}
        else if (n==3){var searchUrl = "http://search.19lou.com/search/" + utf8Keyword +"/a0-b0.html";}
        else if (n==4){var searchUrl = "http://search.19lou.com/search/" + utf8Keyword +"/a5.html";}
        else if (n==6){var searchUrl = "http://search.19lou.com/search/" + utf8Keyword +"/a3-b0.html";}
    open(searchUrl);
 }
 var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
 
 function utf8(wide) {
    var c, s;
    var enc = "";
    var i = 0;
    while(i<wide.length) {
        c= wide.charCodeAt(i++);
        // handle UTF-16 surrogates
        if (c>=0xDC00 && c<0xE000) continue;
        if (c>=0xD800 && c<0xDC00) {
            if (i>=wide.length) continue;
            s= wide.charCodeAt(i++);
            if (s<0xDC00 || c>=0xDE00) continue;
            c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
        }
        // output value
        if (c<0x80) enc += String.fromCharCode(c);
        else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
        else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
        else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    }
    return enc;
}

 var hexchars = "0123456789ABCDEF";

 function toHex(n) {
    return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
 }

 var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

 function encodeURIByUtf8(s) {
    var s = utf8(s);
    var c;
    var enc = "";
    for (var i= 0; i<s.length; i++) {
        if (okURIchars.indexOf(s.charAt(i))==-1)
        enc += "%"+toHex(s.charCodeAt(i));
        else
        enc += s.charAt(i);
    }
    return enc;
 } 
 
 
//复制URL地址
function setCopy(_sTxt){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}

//加入收藏
function addBookmark(site, url){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.external.addFavorite(url,site)
	} else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		return;
	} else {
		return;
	}
}
 
 //设为首页
function sethomepage(obj,url){
	if(_dk.client.isIE){
		obj.style.behavior = "url(#default#homepage)";
		obj.setHomePage(url);
	} else {
		return false;
	}
}
 
 
 
 
 
 var duk = {};
duk.showLoginStatus = function() {
    jQuery.getScript('http://www.19lou.com/loginstatus.php', function(){
        var loginStatusWrapper = jQuery('#loginstatus');
        if(data.isLogin){
			html = duk._getLoginStatusHtml(data.username,data.coin,data.prestige,data.grouptitle,data.avatarurl,data.welcome);
			loginStatusWrapper.html(html);
        }else{
			html = duk._getNotLoginStatusHtml();
			loginStatusWrapper.html(html);
        }
    });
}

duk._getLoginStatusHtml = function(username,coin,prestige,grouptitle,avatarurl,welcome) {
	var html = '';
	html +=  '<div class="portrait"><a href="http://www.19lou.com/member_avatar.php" target="_blank"><img src="'+avatarurl+'" /></a></div>';
	html += '<div class="data"><strong>'+username+'，'+welcome+'！</strong><br />';
	html += '金币:<b>'+coin+'</b>&nbsp;&nbsp;威望:<b>'+prestige+'</b>&nbsp;&nbsp;级别:<b>'+grouptitle+'</b><br />';
	html += '<a href="http://www.19lou.com/pm.php?folder=inbox" target="_blank">短信</a> | ';
	html += '<a href="http://www.19lou.com/my.php?item=threads" target="_blank">话题</a> | ';
	html += '<a href="http://www.19lou.com/invite.php" target="_blank">邀请</a> | ';
	html += '<a href="http://www.19lou.com/memcp.php" target="_blank">个人中心</a> | ';
	html += '<a href="http://www.19lou.com/passportlogin.php?action=logout&forward=http://www.19lou.com/" target="_blank">退出</a>';
	html += '</div>';
	return html;
}

duk._getNotLoginStatusHtml = function(){
	var html = '';
	html += '<div class="loggingin">';
	html += '<form id="form1" name="form1" method="post" action="">';
	html += '<a>用户名:</a><input type="text" name="textfield" id="textfield" class="input_b1"onclick="this.value=\'\';" onmouseover="this.className=\'input_b2\'" onmouseout="this.className=\'input_b1\'" onKeyDown="ctlent(event);" value="用户名" />';
	html += '<label><input type="checkbox" name="checkbox" id="checkbox" />记住状态</label>';
	html += '<a href="http://www.19lou.com/register.php">申请入住</a><br />';
	html += '<a>密&nbsp;&nbsp;&nbsp;&nbsp;码:</a><input type="password" name="textfield2" id="textfield2" class="input_b1" onmouseover="this.className=\'input_b2\'" onmouseout="this.className=\'input_b1\'" onKeyDown="ctlent(event);" />';
	html += '<input type="submit" name="button" id="button" value="立即登录" class="putin_b1"onclick="this.value=\'\';" onmouseover="this.className=\'putin_b2\'" onmouseout="this.className=\'putin_b1\'" onKeyDown="ctlent(event);" />';
	html += '<a href="http://www.19lou.com/member.php?action=lostpasswd">找回密码</a>';
	html += '</form>';
	html += '</div>';
	return html;
}

duk.showFooter = function() {
    
}