//Ajax
var navigatorname;
if (navigator.userAgent.indexOf("Opera")>=0)
{
navigatorname="Opera"
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
navigatorname="IE"
}
if (navigator.userAgent.indexOf("Firefox")>=0)
{ 
navigatorname="Firefox"
}

//AJAX 对象
var XmlHTTP_obj=function(){
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    return new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
    return new ActiveXObject("Microsoft.XMLHTTP");
}
}

//用于获取相应地址返回的XML档
function GetXMLContent(urlstr){
	var http_request;
	urlstr.indexOf("?")==-1?urlstr=urlstr+"?"+Math.random():urlstr=urlstr+"&"+Math.random()
  if (window.XMLHttpRequest){ // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    http_request.open("GET",urlstr,false);
    http_request.send(null);
    return http_request.responseXML;
	}

//使FIREFOX支持selectNodes()、selectSingleNode()
//代码出处：http://km0ti0n.blunted.co.uk/mozXPath.xap
// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; } 
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}

// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
  return this.ownerDocument.selectNodes(cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; } 
var xItems = this.selectNodes(cXPathString, xNode);
if( xItems.length > 0 )
{
return xItems[0];
}
else
{
return null;
}
}

// prototying the Element
Element.prototype.selectSingleNode = function(cXPathString)
{ 
if(this.ownerDocument.selectSingleNode)
{
return this.ownerDocument.selectSingleNode(cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

function createXMLHttp() {
	var xmlHttp = null;
		var ex;
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		}
		catch (ex)
		{
			try
			{
				xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch (ex)
			{
				try
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (ex)
				{
	                
	                try
	                {
	                 xmlHttp = new XMLHttpRequest();
				    }
				    catch(ex)
				    {
				      throw new Error("XMLHttp object could be created.");
				    }
				}
			}
		}
	return xmlHttp;
}

function loginCheck()
{
if(loginForm.username.value.length == 0)
	{
		alert("用户名不能为空！");
		loginForm.username.focus();
		return false;
	}
	
if(loginForm.password.value.length == 0)
	{
		alert("密码不能为空！");
		loginForm.password.focus();
		return false;
	}
	
    return true;
}


function openSkin(inid){
		SkinForm.idlist.value = inid;
		SkinForm.submit();
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ShowLogin(){
	var objlogin = document.getElementById("loginpanel");
	var objtype = document.getElementById("type");
	var objbutton = document.getElementById("userlogin");
	if(objlogin.style.display == "none"||objlogin.style.display == ""){
		objlogin.style.display = "block";
		objtype.style.visibility="hidden";
		objbutton.innerHTML="<font color=ff0000>关闭</font>";
	}else{
		objlogin.style.display = "none";
		objtype.style.visibility="";
		objbutton.innerHTML="<font color=ff0000>登录</font>";
	}
}

function copyText(id) {
	try{
		var targetText = document.getElementById(id);
		targetText.focus();
		targetText.select();
		var clipeText = targetText.createTextRange();
		clipeText.execCommand("Copy");
	}catch(e){}
}

//获取ID
function $id(id,obj){
	if(obj==null){return document.getElementById(id)}
	else{return obj.getElementById(id)}
	}

//顶一下
function Hit(srcid,UserID){
	var iddiv_obj=$id("Src_ID"+srcid);
	var hitdiv_obj=$id("Src_HitNum"+srcid);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=hit&src_id="+srcid+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  alert(RetDes);
  	  break;
  	}
	}
	
function Hit2(srcid,UserID){
	var iddiv_obj=$id("Src_ID"+srcid);
	var hitdiv_obj=$id("Src_HitNum"+srcid);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=hit2&src_id="+srcid+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  alert(RetDes);
  	  break;
  	}
	}