asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0

//判断浏览器
o_navigator = navigator.userAgent;
var isIE = (o_navigator.indexOf("MSIE") > -1) ? 1 : 0;
var isIE5 = (o_navigator.indexOf("MSIE 5") > -1) ? 1 : 0;
var isMac = (o_navigator.indexOf("Mac") > -1) ? 1 : 0;
var isOpera = (o_navigator.indexOf("Opera") > -1) ? 1 : 0;
var isIE50 = (o_navigator.indexOf("MSIE 5.0") > -1) ? 1 : 0;
var isIE55 = (o_navigator.indexOf("MSIE 5.5") > -1) ? 1 : 0;
var isIE6 = (o_navigator.indexOf("MSIE 6.0") > -1) ? 1 : 0;
var isNN6 = (o_navigator.indexOf("Netscape6") > -1) ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;
isIE = (isIE && !isOpera);

//添加Array的delArray方法
function delArray(arr,index){
 if(index>arr.length-1){
  return false;
 }
 for(var i=index;i<arr.length;i++){
  arr[i] = arr[i+1];
 }
 arr.length--;
 return true;
}

//添加Object的inObject方法
function inObject(obj,word){
 var bFound = false;
 for(a in obj){
  if(obj[a] == word){
   bFound = true;
   break;
  }
 }
 return bFound;
}

//添加String的RTrim方法
String.prototype.RTrim = function()
{
    var whitespace = new String(" \t\n\r");
    var s = new String(this);
 
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

//让substr无大小写区分
function stristr(haystack,needle){
 var strCompare = haystack.toLowerCase();
 var intIndex = strCompare.indexOf(needle.toLowerCase());
 if(intIndex!=-1){
  return haystack.substr(intIndex);
 }else{
  return false;
 }
}

//strstr
function strstr(haystack,needle){
 var intIndex = haystack.indexOf(needle);
 if(intIndex!=-1){
  return haystack.substr(intIndex);
 }else{
  return false;
 }
}

//stripslashes
function stripslashes(str){
 return str.replace(/\\/g,"");
}

//本函数将字符串中含有 . \\ + * ? [ ^ ] ( $ ) 等字符的前面加入反斜线 "\" 符号。
function quotemeta(str){
 return str.replace(/([\.\\\+\*\?\[\^\]\(\$\)])/g,"\\$1");
}

//
function arrReplace(arr1,arr2,str){
  var maxIndex = Math.min(arr1.length,arr2.length);
 for(var i=0; i< maxIndex; i++){
  str = str.replace(new RegExp(quotemeta(arr1[i]),"g"),arr2[i]);
 }
 return str;
}


/*******************************************************************************************
原型:   FormatNumber(srcStr,nAfterDot)
创建者:  Newskyline
创建时间: 14:15 2004-12-27
功能描述: 格式化小数
输入参数: srcStr:   待格式化的数字
      nAfterDot: 小数点后的位数
返回值:  无
*******************************************************************************************/
function FormatNumber(srcStr,nAfterDot){
 var srcStr,nAfterDot;
 var resultStr,nTen;
 srcStr = "" + srcStr + "";
 strLen = srcStr.length;
 dotPos = srcStr.indexOf(".",0);
 if (dotPos == -1){
   resultStr = srcStr+".";
   for (i=0;i<nAfterDot;i++){
     resultStr = resultStr+"0";
   }
   return resultStr;
 }
 else{
   if ((strLen - dotPos - 1) >= nAfterDot){
     nAfter = dotPos + nAfterDot + 1;
     nTen =1;
     for(j=0;j<nAfterDot;j++){
       nTen = nTen*10;
     }
     resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
     return resultStr;
   }
   else{
     resultStr = srcStr;
     for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
       resultStr = resultStr+"0";
     }
     return resultStr;
   }
 }
}

/*******************************************************************************************
原型:   HTMLEncode(fString)
创建者:  Newskyline
创建时间: 12:57 2005-2-19
功能描述: HTML过滤函数
输入参数: fString:  待格式化的字符串
返回值:  无
*******************************************************************************************/
function HTMLEncode(fString){
 fString = fString.replace(/&/g, "&amp;") ;
 fString = fString.replace(/\"/g, "&quot;") ;
 fString = fString.replace(/</g, "&lt;") ;
 fString = fString.replace(/>/g, "&gt;") ;
// fString = fString.replace(/'/g, "&#39;") ;
// fString = fString.replace(/\t/g, "&nbsp;&nbsp;") ;
// fString = fString.replace(/\r/g, "") ;
// fString = fString.replace(/\n/g, "<br />") ;
 fString = fString.replace(/' '/g, "&nbsp;") ;
 return fString;
}

// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  {
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}


function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 }
 else {
  window.onload = function() {
   oldonload();
   func();
  }
 }
}

SCROLL_TIME = 300;
var objDiv;
var Scroller = function(){
/* var startTime,startHeight,endHeight,dist,accel;
 var aniTimer;*/
 aDiv : null;
}

Scroller.show = function(){
 with(this.aDiv){
  this.startTime = (new Date()).getTime();
  this.startHeight = 0;
  this.endHeight = scrollHeight;
  this.dist = this.endHeight;
  this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
  if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
  this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
 }
}

Scroller.hide = function(){
 with(this.aDiv){
  this.startTime = (new Date()).getTime();
  this.startHeight = scrollHeight;
  this.endHeight = 0;
  this.dist = -this.startHeight;
  this.accel = this.dist / SCROLL_TIME / SCROLL_TIME;
  if (this.aniTimer) this.aniTimer = window.clearInterval(this.aniTimer);
  this.aniTimer = window.setInterval("Scroller.slide()", parseInt(100/SCROLL_ACCEL));
 }
}

Scroller.slide = function(){
 with(this){
  var now = (new Date()).getTime();
  var elapsed = now - startTime;
  if (elapsed > SCROLL_TIME) endScroll();
  else {
   var t = SCROLL_TIME - elapsed;
   var ny = endHeight - t * t * accel;
   jumpTo(ny);
  }
 }
}

Scroller.jumpTo = function(ny){
 var alpha = Math.abs(parseInt(ny*100/this.dist));
 with(this.aDiv){
  style.height = ny;
  scrollTop = ny;
  filters.alpha.opacity = alpha;
 }
}

Scroller.endScroll = function() {
 if (this.aniTimer) this.aniTimer = window.clearTimeout(this.aniTimer);
 with(this.aDiv){
  style.overflowY="";
  style.height = "";
  if(this.endHeight==0){
   style.display = "none";
   //filters.alpha.opacity = 0;
  }
  //else{
  filters.alpha.opacity = 100;
  //}
 }
}

function CheckRelative(objChk){
 var objDiv = objChk.parentNode.nextSibling;
 var objInput;
 var i;
 //选取所有子结点
 objInput = objDiv.getElementsByTagName("input");
 for(i=0;i<objInput.length;i++){
  objInput[i].checked = objChk.checked;
 }
 //选取所有父结点(如果需要)
 if(objChk.checked){
  objInput = objChk;
  //debugger;
  objDiv = objInput.parentNode.parentNode.previousSibling
  while(objDiv && objDiv.className=="TreeNode"){
   objInput = objDiv.getElementsByTagName("input");
   if(objInput){
    objInput[0].checked = true;
    objDiv = objInput[0].parentNode.parentNode.previousSibling;
   }
   else{
    objDiv = null;
   }
  }
 }
}

function FullExpand(divName,blnExpand){
 var objTree = document.getElementById(divName);
 var objDiv,objImg,objContent;
 var blnTransImg;
 var i,j;
 if(objTree){
  objDiv = objTree.getElementsByTagName("div");
  for(i=0;i<objDiv.length;i++){
   if(objDiv[i].className == "TreeNode"){
    objImg = objDiv[i].getElementsByTagName("img");
    objContent = objDiv[i].nextSibling;
    blnTransImg = (blnExpand != (objContent.style.display == 'block'))
    if(blnTransImg){
     for(j=0;j<objImg.length;j++){
      TransNodeImg(objImg[j]);
     }
    }
    if(blnExpand){
     objContent.style.display = "block";
    }
    else{
     objContent.style.display = "none";
    }
   }
  }
 }
}

function NodeExpand(objImg,divName){
 objDiv = document.getElementById(divName);
 if(objDiv){
  TransNodeImg(objImg);
  TransNodeImg(objImg.nextSibling);
  if(objDiv.style.display =='block'){
   if(isIE){
    objDiv.style.overflowY="hidden";
    Scroller.aDiv = objDiv;
    Scroller.hide();
   }
   else{
    objDiv.style.display = "none";
   }
  }
  else{
   if(isIE){
    objDiv.style.display = 'block';
    objDiv.filters.alpha.opacity = 100;
    objDiv.style.overflowY="hidden";
    objDiv.style.height=0;
    Scroller.aDiv = objDiv;
    Scroller.show();
   }
   else{
    objDiv.style.display = "block";
   }
  }
 }
}

function TransNodeImg(imgObj){
 var oldSrc,newSrc;
 
 oldSrc = imgObj.src.replace(/.*\/([a-zA-Z]+)\.gif/,"$1").toLowerCase();
 switch(oldSrc){
  case 'lminus':
   newSrc = TreeIcon['TI_LPLUS'];
   break;
  case 'lplus':
   newSrc = TreeIcon['TI_LMINUS'];
   break;
  case 'tminus':
   newSrc = TreeIcon['TI_TPLUS'];
   break;
  case 'tplus':
   newSrc = TreeIcon['TI_TMINUS'];
   break;
  case 'fclose':
   newSrc = TreeIcon['TI_OPEN'];
   break;
  case 'fopen':
   newSrc = TreeIcon['TI_CLOSE'];
   break;
 }
 if(newSrc){imgObj.src = newSrc};
}

//给关键字加上Tooltip
function SetKeyword(){
 var ObjA;
 var i;
 if(!document.getElementsByTagName){
  return false;
 }
 ObjA = document.getElementsByTagName("a");
 for(i=0;i<ObjA.length;i++){
  if(ObjA[i].className=="Keyword"){
   ObjA[i].onmouseover = Function("ddrivetip('" + ObjA[i].title + "')");
   ObjA[i].onmouseout = Function("hideddrivetip()");
   ObjA[i].title = "";
  }
 }
 return true;
}

//根据浏览器类型创建XMLHTTP对象
function jb() {
 var A=null;
 try {
  A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e) {
  try {
   A=new ActiveXObject("Microsoft.XMLHTTP")
  } catch(oc) {
   A=null
  }
 }
 if ( !A && typeof XMLHttpRequest != "undefined" ) {
  A=new XMLHttpRequest()
 }
 return A
}

//选择所有的CheckBox
function SelectAll(objForm,chkName,checked){
 var i;
 var objChks = objForm.document.getElementsByName(chkName);
 if(!objChks){
  return;
 }
 for(i=0;i<objChks.length;i++){
  objChks[i].checked = checked;
 }
}

//确认删除
function ConfirmDelete(objForm){
 if(!confirm(LPCommon("Str_ConfirmDelete"))){
  return false;
 }
 objForm.submit();
 return true;
}

//快速切换语言
function SetLanguage(objId,lCode){
 var obj = document.getElementById(objId);
 if(obj){
  obj.value = lCode;
  obj.form.submit();
 }
}

addLoadEvent(SetKeyword);


//debugger;
//var objTheme = new ActiveXObject("Microsoft.XMLDOM");
var themeName;


loadStyleSheet();
addLoadEvent(Function("initialThemeList('Theme')"));

// Appends a CSS file to a document.添加一个样式表
function AppendStyleSheet( documentElement, cssFileUrl )
{
 var e = documentElement.createElement( 'LINK' ) ;
 e.rel = 'stylesheet' ;
 e.type = 'text/css' ;
 e.title = 'Theme';
 e.href = cssFileUrl ;
 documentElement.getElementsByTagName("HEAD")[0].appendChild( e ) ;
}

//设置样式表
function setActiveStyleSheet(arrTheme) {
  var i, a, main;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title")) {
      if(a.getAttribute("title") == "Theme"){
    //正则表达式替换href
    themeName = arrTheme[0];
    a.href = a.href.replace(/(Style\/Theme\/)[^\/]+(\/)/i,"$1" + arrTheme[0] + "$2");
    setElementsContent(arrTheme);
      }
    }
  }
}

//设置页面主题元素内容
function setElementsContent(arrTheme){
 if (!document.getElementById) return;
 if (!document.getElementById("CurTheme")) return;
 document.getElementById("CurTheme").innerText = arrTheme[0];
 /*if (document.getElementById("CurThemeAuthor")){
  document.getElementById("CurThemeIntro").innerText = aName[1];
 }*/
 if (document.getElementById("CurThemeIntro")){
  document.getElementById("CurThemeIntro").innerHTML = '<div>' + arrTheme[2] + '</div><div align="right">Designed by <strong>' + arrTheme[1] + '</strong>&nbsp;</div>';
 } 
}

//载入页面以前加载样式表
function loadStyleSheet(){
 var strCookies;
 try{
  //获取当前主题名称
  //objTheme.async = false;
  //objTheme.load("/XML/Config/Theme.xml");
  
  var objXML = jb();
  objXML.open("GET","/XML/Config/Theme.xml",false);
  //objXML.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
  objXML.send("");
  
  objTheme = objXML.responseXML;
  
  //strCookies = readCookie("Theme");
  //debugger;
  //themeName = strCookies.replace(/(.*)Theme=([^&]+)(.*)/ig,"$2");
  themeName = readCookie("Theme");
  //debugger;
  //if(!themeName || strCookies.indexOf("Theme=") == -1){
  if(!themeName){
   //themeName = objTheme.selectSingleNode("//Theme/DefaultTheme").text;
   themeName = objTheme.getElementsByTagName("DefaultTheme")[0].firstChild.nodeValue;
  }
  AppendStyleSheet(document,"/Style/Theme/" + themeName + "/Main.css");
 }
 catch(e){
  alert("StyleSheet is not loaded:" + e.message);
 }
}

//初始化主题选择列表
function initialThemeList(themeId){
 var themeList;
 var aItem;
 var arrTheme = null;
 if (!document.getElementById) return false;
 themeList = document.getElementById(themeId);
 if (themeList){
  themeList.onchange = Function("setActiveStyleSheet(this.value.split('|'))");
  //themeList.innerHTML = "";.
  //for(var i=0;i<objTheme.selectNodes("//Theme/Item").length;i++){
  for(var i=0;i<objTheme.getElementsByTagName("Item").length;i++){
   aItem = document.createElement("option");
   //aItem.value = objTheme.selectNodes("//Theme/Item")[i].text;
   aItem.value = Array(objTheme.getElementsByTagName("Item")[i].getAttribute("Name"),
             objTheme.getElementsByTagName("Item")[i].getAttribute("Author"),
             objTheme.getElementsByTagName("Item")[i].firstChild.nodeValue).join("|");
   aItem.innerHTML = aItem.value.split("|")[0];
   if(aItem.value.split("|")[0]==themeName){
    aItem.setAttribute("selected","true");
    arrTheme = aItem.value.split("|");
   }
   themeList.appendChild(aItem);
   //themeList.innerHTML += aItem.outerHTML;
  }
 }
 if(arrTheme)setElementsContent(arrTheme);
}

posted on 2006-04-03 14:38 汪杰 阅读(120) 评论(0)  编辑 收藏 引用 所属分类: hengxing网站js
只有注册用户登录后才能发表评论。

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 459282
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜