﻿/***************************** 
*    Yidea.net 艺想软件
*    公用函数 
******************************/
var responseType = 1;

/***************************** 
*    生成XML对象 
******************************/

var EXDoc=Class.create();
EXDoc.prototype={
	initialize:function(str){
		this.root=Xparse(str);
		this.root=this.root.contents[0];
	},
	gnn:function(node,name){
		
		for(var i=0;i<node.contents.length;i++){
			
			if(node.contents[i].name==name){
				return node.contents[i];
			}
			if(node.contents[i].contents.length>0)return this.gnn(node.contents[i],name);
		}
		return null;
	},
	findNodeByValue:function(node,name,_value){
		for(var i=0;i<node.contents.length;i++){
			if(node.contents[i].name==name && node.contents[i].value==_value){
				return node.contents[i];
			}
			if(node.contents[i].contents.length>0)return this.findNodeByValue(node.contents[i],name);
		}
		return null;	
	},
	findNodeByAttibute:function(node,name,_value){
		for(var i=0;i<node.contents.length;i++){
			if(node.contents[i].attributes[name]==_value)
			   return node.contents[i];

		}
		return null;	
	}
	
}

/***************************** 
*    实现VBSCRIPT的TRIM函数 
******************************/
String.prototype.trim= function()  
{  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

String.prototype.sub_str=function(len,place)
{
   var str=this;
   if(str.replace(/[^\x00-\xff]/gi,'xx').length<=len) return str; 
   
   if(place=='left')
   {
      var temp_len=len;  
      str=str.substr(0,len);
      while(str.replace(/[^\x00-\xff]/gi,'xx').length>len)
      {
         str=str.substr(0,--temp_len);
      }
   }
   if(place=='right')
   {
      var temp_startn=0;
      str=str.substr(str.length-len,len);
      while(str.replace(/[^\x00-\xff]/gi,'xx').length>len)
      {      
         str=str.substr(1,len);
      }     
   }
   return str;
}
/***************************** 
*    基础 
******************************/
var hideCount=0;
function HideAfter3Seconds(name)
{
	if(tipusing==false)return;
	hideCount++;
	if(hideCount==4){
		Element.hide($(name));
		hideCount=0;
	}
	else
	    setTimeout("HideAfter3Seconds('"+name+"')",1000);
}

function ShowTip(str,CommentTip)
{
	tipusing=true;
	$(CommentTip).innerHTML=str;
	Element.show($(CommentTip));
}

function HideTip(CommentTip)
{
	tipusing=false;
	$(CommentTip).innerHTML="";
	Element.hide($(CommentTip));
}


function RaiseOnload(func,type)
{
    if(type==null||type=='undefined')
        if (document.all)
            window.attachEvent('onload',function(){eval(func);});
        else 
            window.addEventListener('load', function(){eval(func);}, false);

    else
    {eval(func);}
}

_element.prototype.getValue=function(){
	if(!arguments){
		if(this.contents[0])return this.contents[0].value;
		else return "";
	}
	for(var i=0;i<this.contents.length;i++){
		if(this.contents[i].name==arguments[0]){
			if(this.contents[i].contents[0])return this.contents[i].contents[0].value;
			return "";
		}
	}
}
//将对象居中显示
function MoveCenter(obj)
{
   obj.style.display='block';
   obj.style.zindex=100;
   obj.style.position='absolute';
   obj.style.left=(document.body.clientWidth/2-obj.clientWidth/2)+"px";
   obj.style.top=(document.body.scrollTop+document.body.clientHeight/2-obj.clientHeight/2)+"px";
}
function RefleshChkNum()
{
	$("ImgChkNum").src="ChkNum.aspx?r="+Math.random();
}

/*************************
*
*  获取真实路径
*
**************************/
function GetBase()
{
  var oTagBase=document.all.tags("BASE");

  return (oTagBase&&oTagBase.length)?oTagBase[0].href:null;
}

function GetPath(str)
{
   return GetBase()+str;
}


function GotoUrl()
{
    switch (responseType)
    {
        case 2:
            window.open("ShowArticle.aspx");
            break;
        case 3:
            window.open("ShowPhoto.aspx");
            break;
        case 4:
            window.open("ShowArticle.aspx");
            break;
        
    }
}