ie=navigator.appName.indexOf("Microsoft") >= 0;
ff=navigator.userAgent.indexOf("Firefox") >= 0;

function getCookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function setCookie(name,value,expires,path,domain,secure) {
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}

function deleteCookie(name,path,domain) {
   if (getCookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fillSelect(ele, arr, _clear,defaultText){
  ele = getElement(ele);
  if(_clear) {
    ele.options.length=0;
    if(defaultText) ele.options[0] = new Option(defaultText);
  }
  for(var i=0;i<arr.length;i++){
    ele.options[i+1] = new Option(arr[i].name,arr[i].id);
  }
}

function isNumber(sText){
  if(!sText)return false;
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++){
    Char = sText.charAt(i);
    if(ValidChars.indexOf(Char) == -1){
      IsNumber = false;
    }
  }
  return IsNumber;
}


function alertAndReturn(message){
  alert(message);
  return false;
}

function dump(f){
  for(var i in f){
    alert(i+":" + f[i]);
    var x = f[i];
//    dump(x);
  }
}

function getMultiSelectValue(name, ob){
 var res = "";
 if(ob){
   if(!name) name=ob.name;
   for (var i = 0; i < ob.options.length; i++){
     if (ob.options[i].selected) {
       if(i!=0)res+="&";
       res+=name+"="+ob.options[i].value;
     }
   }
 }
 return res;
}

//function $(name){
//  return document.getElementById(name);
//}


function createElement(name, attribs, message){
 var el = document.createElement(name);
 fillElement(el, attribs, message);
 return el;
}

function fillElement(el, attribs, message){
 if(attribs){
   for(var i = 0;i<attribs.length; i+=2){
     el.setAttribute(attribs[i], attribs[i+1]);
     if(ie && "class" == attribs[i])el.className=attribs[i+1];
   }
 }
 if(!message) message = document.createElement("div");
 if("string"==typeof(message)){
   message = document.createTextNode(message);
 }
 try{
 el.appendChild(message);
 }catch(e){
 }
}

function createLink(url, message, attribs){
  if(!attribs) attribs = new Array();
  attribs[attribs.length] = "href";
  attribs[attribs.length] = url;
  return createElement("a", attribs, message);
}

function createImage(url, attribs){
 var image = new Image();
 image.src = url;
 fillElement(image, attribs);
 return image;
}

function createCell(row, attribs, simpleText){
 var cell= row.insertCell(row.cells.length);
 fillElement(cell, attribs, simpleText);
 return cell;
}

function isString(s){
  return "string" == typeof(s);
}

function getElement(ele){
  if(isString(ele)) ele = document.getElementById(ele);
  return ele;
}

function showPane(pane){
  pane = getElement(pane);
  if(pane)
    pane.style.display="";
}
function hidePane(pane){
  pane = getElement(pane);
  if(pane)
    pane.style.display="none";
}
function showHidePane(pane){
  pane = getElement(pane);
  if(pane)
    pane.style.display=!pane.style.display?"none":"";
}
function removeChildren(node){
  var len = node.childNodes.length;
  for(var i = len-1; i >= 0; i--){
    node.removeChild(node.childNodes[i]);
  }
}

//====popup=================
var popup = {
    masker:(function() {
        function E(id) {
            return document.getElementById(id);
        }

        var s = false;
        var maskNode = document.createElement("div");
        maskNode.id = "__mask"
        maskNode.className = "mask";
        maskNode.style.display = "block";

        return {
            show:function() {
                var oldMaskNode = E("__mask");
                if (oldMaskNode) {
                    oldMaskNode.style.display = "block";
                    oldMaskNode.style.visibility = "visible";
                } else {
                    if (document.body) {
                        document.body.appendChild(maskNode);
                    } else {
                        document.appendChild(maskNode);
                    }
                }
                s = true;
            },
            hide:function() {
                var oldMaskNode = E("__mask");
                if (oldMaskNode) {
                    oldMaskNode.style.display = "none";
                }
                s = false;
            },
            visible:function() {
                return s;
            }
        };
    })(),

    open:function (src, w, h) {
        if(!w) w=0;
        if(!h) h=0;
        
        this.masker.show();
        var popupId = "__popup";
        var popup = document.createElement("div");
        var popupContent = document.createElement("div");
        var iframe = document.createElement("iframe");

        popup.id = popupId;
        popup.className = "popup";
        popup.style.display = "block";
        popup.style.visibility = "visible";

        iframe.src = src;
        iframe.width = w;
        iframe.height = h;

        iframe.scrolling = "auto";
        iframe.frameBorder = 0;

        //如果宽度和高度都是0，大概就是不想显示此层了。。
        popupContent.style.display = (!w&&!h)?"none":"";
        popupContent.style.width = w+"px";


        popupContent.appendChild(iframe);
        popup.appendChild(popupContent);

        var oldPupup = document.getElementById(popupId);
        if (oldPupup) {
            document.body.removeChild(oldPupup);
        }
        document.body.appendChild(popup);
    },
    close:function () {
        this.masker.hide();
        var popupId = "__popup";
        var oldPupup = document.getElementById(popupId);
        if (oldPupup) {
            document.body.removeChild(oldPupup);
        }
    }
}

function toggle_popup(src, w, h) {
    if (popup.masker.visible() || !src) {
        popup.close();
    } else if(src){
        popup.open(src, w, h);
    }
}