/*初始化浏览器类型*/
var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var charset = "gbk";

var VirtualPath = "/StockInfo";//虚拟目录
var cookiePrefix = 'Fly_';//cookie前缀
var cookieDomain = '';//cookie 的域名
var report_error = true;//是否报告js错误

//var scrollbarWidth = parseInt(document.body.offsetWidth)-parseInt(document.body.scrollWidth);

function ResumeError() {
  return true;
}

if (!report_error){ //如果不允许报告错误
  window.onerror = ResumeError;
}

function ReturnFalse(){ //返回false
  return false;
}

function $(id) {/*查找控件*/
  if(!id){return null; }
  if(document.getElementById){
    return eval('document.getElementById("' + id + '")');
  }else if(document.layers){
    return eval("document.layers['" + id +"']");
  }else{
    return eval('document.all.' + id);
  }
}

function ExecScript(str){
  try{
    window.execScript(str);
  } catch (ex) {
    window.eval(str);//这个不是全局
    /*
    try {
      (new Function(str))();
    } catch (ex){

    };*/
  };
}

function RequireJS(u,id){//给head标签加js脚本
  var id = escape(u);
  if (!$(id)){
    var obj = document.createElement('script');
    var obj = document.getElementsByTagName('head')[0].appendChild(obj);
    obj.setAttribute('src',u);
    obj.setAttribute('language','javascript');
    obj.setAttribute('type','text/javascript');
    obj.setAttribute('id',id);
    if (!isUndefined(id)){
      obj.setAttribute('id',id);
    }

  }
}

function IncludeJS(u) {//读取js并执行,此项会优先于require执行
  var x = window.ActiveXObject ? new ActiveXObject("MSXML2.XMLHTTP") : new XMLHttpRequest();
  x.open("GET",u,false);
  x.send(null);
  try {
    var c = x.responseText;
  }  catch (ex){};
  var id = escape(u);
  if ((c != null) && (!document.getElementById(id))){
  var head = document.getElementsByTagName("head")[0];
  var script = document.createElement("script");
  script.language = "javascript";
  script.type = "text/javascript";
  script.id = id;
  script.defer = true;
  script.text = c;
  head.appendChild(script);
  }/*
  try{
    window.execScript(c);
  } catch (ex) {
    window.eval(c);
  }*/
}
function RequireCSS(u,media){//给head标签加css样式
  var id = escape(u);
  if (!$(id)){
    var obj = document.createElement('link');
    var obj = document.getElementsByTagName('head')[0].appendChild(obj);
    obj.setAttribute('href',u);
    obj.setAttribute('rel','stylesheet');
    obj.setAttribute('type','text/css');
    if (!isUndefined(media)){
      obj.setAttribute('media',media);
    }
  }
}

function htmlspecialchars(str){//将html标签转义
  str = str.replace(/&/g,"&amp;");
  str = str.replace(/</g,"&lt;");
  str = str.replace(/>/g,"&gt;");
  str = str.replace(/"/g,"&quot;");
  return str;
}

function Random(limit){
  if (isUndefined(limit)) limit = 1;
  return Math.floor(Math.random()*limit);
}

function in_array(needle, haystack) {/*是否存在于数组*/
  if(typeof needle == 'string') {
    for(var i in haystack) {
      if(haystack[i] == needle) {
          return true;
      }
    }
  }
  return false;
}

function isUndefined(variable) {/*是否underfined*/
  return typeof variable == 'undefined' ? true : false;
}

function findtags(parentobj, tag) { /*寻找Tag*/
  if(!isUndefined(parentobj.getElementsByTagName)) {
    return parentobj.getElementsByTagName(tag);
  } else if(parentobj.all && parentobj.all.tags) {
    return parentobj.all.tags(tag);
  } else {
    return null;
  }
}
function findcss(className,cssIndex){ /*查找CSS文件中的某样式*/
  cssIndex = !isUndefined(cssIndex) ? cssIndex : 0;
  var arr = document.styleSheets(cssIndex).rules;
  for (var i=0;i<arr.length;i++){
    if (arr(i).selectorText == className){
      return document.styleSheets(cssIndex).rules(i);
    }
  }
  return null;
}
function getStyle(oElm, strCssRule){ /*获取某控件的某个style属性*/
  /*注意，对于缩略式表达式，FF无法获取！例如“padding:4px”，在FF下面，只能按照标准返回"padding-left"。简言之var getPadding = getStyle(someElement, "padding");是无效的，需要用var getPadding = getStyle(someElement, "padding-left");*/
  var strValue = "";
  if(document.defaultView && document.defaultView.getComputedStyle){
    strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
  }
  else if(oElm.currentStyle){
    strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
      return p1.toUpperCase();
    });
    strValue = oElm.currentStyle[strCssRule];
  }
  return strValue;
}
function array_obj(){
  this.index = -1;
  this.arr = new Array();
  this.add = function(value) {
    if (value != 'undefined') {
      this.index++;
      this.arr[(this.index)] = value;
      this.arr.length  = (this.index) + 1;
    }
  }
  this.result = function() {
    return this.arr;
  }
}

function doane(event) {
  e = event ? event : window.event ;
  if(is_ie) {
    e.returnValue = false;
    e.cancelBubble = true;
  } else {
    e.stopPropagation();
    e.preventDefault();
  }
}

function arraypop(a) {/*数组最高项删除*/
  if(typeof a != 'object' || !a.length) {
    return null;
  } else {
    var response = a[a.length - 1];
    a.length--;
    return response;
  }
}

function arraypush(a, value) {/*添加一项到数组*/
  a[a.length] = value;
  return a.length;
}

function createXMLDOM()      { //创建一个XMLDOM对象
        if(window.ActiveXObject)
        {
            var arrSignatures = ["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0",
                                "MSXML2.DOMDocument","Microsoft.XmlDom"];
            for(var i = 0;i<arrSignatures.length;i++)
            {
                try
                {
                    var oXmlDom = new ActiveXObject(arrSignatures[i]);
                    return oXmlDom;
                }
                catch(oError)
                {}
            }
            throw new Error("MSXML is not installed on your system.");
        }
        else if(document.implementation && document.implementation.createDocument)
        {
            var oXmlDom = document.implementation.createDocument("","",null);
            oXml.parseError = {
                valueOf:function(){return this.errorCode;},
                toString:function(){return this.errorCode.toString()}};

            oXmlDom.__initError__();
            oXmlDom.addEventListener("load",function()
            {
                this.__checkForError__();
                this.__changeReadyState__(4);
            },false);

            return oXmlDom;
        }
        else
        {
            throw new Error("Your browser doesn't support an XML Dom Object。");
        }
}

//------------------------------------------------------------------------
function RaiseEnterSet(ControlID)
{
  if(event.keyCode==13)
  {
    var Control = $(ControlID);
    if (Control != null) Control.click();
    event.returnValue=false;
  }
}


//取查询字符串
String.prototype.getQueryString = function(name)
{
  var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
  if ((r=this.match(reg))!=null) return unescape(r[2]); return null;
}

//内部变量
tPopWait=50;//停留tWait豪秒后显示提示。
tPopShow=5000;//显示tShow豪秒后关闭提示
showPopStep=20;
popOpacity=99;

sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;

//Alt Title提示文本
document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText {  background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");

function showPopupText(){
var o=event.srcElement;
  MouseX=event.x;
  MouseY=event.y;
  if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
        if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  if(o.dypop!=sPop) {
      sPop=o.dypop;
      clearTimeout(curShow);
      clearTimeout(tFadeOut);
      clearTimeout(tFadeIn);
      clearTimeout(tFadeWaiting);
      if(sPop==null || sPop=="") {
        dypopLayer.innerHTML="";
        dypopLayer.style.filter="Alpha()";
        dypopLayer.filters.Alpha.opacity=0;
        }
      else {
        if(o.dyclass!=null) popStyle=o.dyclass
          else popStyle="cPopText";
        curShow=setTimeout("showIt()",tPopWait);
      }

  }
}

function showIt(){
    dypopLayer.className=popStyle;
    dypopLayer.innerHTML=sPop;
    popWidth=dypopLayer.clientWidth;
    popHeight=dypopLayer.clientHeight;
    if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
      else popLeftAdjust=0;
    if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
      else popTopAdjust=0;
    dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
    dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
    dypopLayer.style.filter="Alpha(Opacity=0)";
    fadeOut();
}

function fadeOut(){
  if(dypopLayer.filters.Alpha.opacity<popOpacity) {
    dypopLayer.filters.Alpha.opacity+=showPopStep;
    tFadeOut=setTimeout("fadeOut()",1);
    }
    else {
      dypopLayer.filters.Alpha.opacity=popOpacity;
      tFadeWaiting=setTimeout("fadeIn()",tPopShow);
      }
}

function fadeIn(){
  if(dypopLayer.filters.Alpha.opacity>0) {
    dypopLayer.filters.Alpha.opacity-=1;
    tFadeIn=setTimeout("fadeIn()",1);
    }
}

function rect_object(){ //Rect数据类型
  this.left = null;
  this.top = null;
  this.width = null;
  this.height = null;
}
function setRect(id,rect){ //以某一控件来设置Rect的值
  if (id.style.position != "absolute"){ //浮动层和固定层的算法不同
    var l = id.offsetLeft;
    var t = id.offsetTop;
    var vParent = id.offsetParent;
    while (vParent.tagName.toUpperCase() != "BODY") //相对于body的left和top
    {
      l += vParent.offsetLeft;
      t += vParent.offsetTop;
      vParent = vParent.offsetParent;
    }
    rect.left = l;
    rect.top = t;
    rect.width = id.clientWidth;
    rect.height = id.clientHeight;
  } else {
    rect.left = id.style.left;
    rect.top = id.style.top;
    rect.height = id.style.height;
    rect.width = id.style.width;
  }
}

function IsGusoArr(arr,garr,cookname){ /*验证garr数组是否含arr数组中的值*/
	for(var i=0;i<arr.length;i++){
     if(!in_array(arr[i],garr)){
       return false;
       break;
      }
    }
      return true;
}

