﻿  function $O(pageURL, innerWidth, innerHeight)
  {    
     var ScreenWidth = screen.availWidth
     var ScreenHeight = screen.availHeight
     var StartX = (ScreenWidth - innerWidth) / 2
     var StartY = (ScreenHeight - innerHeight) / 2
     window.open(pageURL, 'window', 'left='+ StartX + ', top='+ StartY + ', Width=' + innerWidth +', height=' + innerHeight + ', resizable=yes, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no')
     return false
 }
function $M(url,width,height)
{
     var date=new Date();
     var n=url.indexOf('?');
     if(n>0)
     {
        url+="&randomtime="+date.getTime();
     }
     else
     {
        url+="?randomtime="+date.getTime();
     }   
     //alert(url); 
	 var ScreenWidth = screen.availWidth;
     var ScreenHeight = screen.availHeight;
     var leftx = (ScreenWidth - width) / 2;
     var topy = (ScreenHeight - height) / 2;
     var returnValue=window.showModalDialog(url,window,"dialogLeft:"+leftx+"px;dialogTop:"+topy+"px;dialogwidth:"+width+"px;dialogHeight:"+height+"px;resizable:yes;toolbar=no;location:no;directories:no;status:0;menubar:no;help:no;scrollbars:no");
	var date=returnValue;
	if(date=="undefined"||date==null)
	{return false;}
	else{return date}
}
function goHistory()
{
    window.history.go(-1);
}
/***************************
功能:统一编码(一般用在IE连接地址)
***************************/
function HTMLEncode(str)
{	
	return encodeURIComponent(str);
}
/***************************
功能:统一解码(一般用在IE连接地址)
***************************/
function HTMLDecode(str)
{
	return decodeURIComponent(str);
}
/***************************
功能:对危险字符进行编码
***************************/
function getHTMLEncode(str)
{
	str=str.replace(/\n/g,"<BR>");
	str=str.replace(/&/g,"&amp;");
	str=str.replace(/</g,"&lt;");
	str=str.replace(/>/g,"&gt;");
	str=str.replace(/\'/g,"&apos;");
	str=str.replace(/\"/g,"&quot;");
	
	str=str.replace(/\s/g," ");
	str=str.replace(/\s\s/g,"&nbsp; ");
	return str;
}
/***************************
功能:对危险字符进行解码
***************************/
function getHTMLDecode(str)
{
	str=str.replace(/<BR>/g,"\n");
	str=str.replace(/&amp;/g,"&");
	str=str.replace(/&lt;/g,"<");
	str=str.replace(/&gt;/g,">");
	str=str.replace(/&apos;/g,"\'");
	str=str.replace(/&quot;/g,"\"");
	
	str=str.replace(/\"\" /g,"\s");
	str=str.replace(/&nbsp; /g,"\s\s");
	return str;
}
/***************************
  上传图片前预览
   <div id="imgView" style="width:80px; height:120px">  
   </div>
  <input id="myfile" type="file" onchange="preview(this,'imgView')" /> 
***************************/
   function preview(E,divID)
    {
        var ip = document.getElementById(E.id);
        ip.select();
        var imgUrl=document.selection.createRange().text;
        if(isImage(imgUrl))
        {
           var imgDiv=document.getElementById(divID);        
            imgDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
            imgDiv.filters.item ("DXImageTransform.Microsoft.AlphaImageLoader").src = imgUrl;  
            imgDiv.innerHTML="";
            return imgUrl;
        }
        else
        {
           alert("不是图片文件？请选择文件格式如：[.jpg]、[.jpeg]、[.png]、[.gif]、[.triff]、[.bmp]");
           return false;
        }    }
/***************************
  判断文件是否是图片，是近回true,否则返回false
***************************/ 
  function isImage(fileName)           
   {
        var pointIndex=fileName.lastIndexOf('.');
        var type=fileName.substring(pointIndex);        
        var arr=new Array(".jpg",".jpeg",".png",".gif",".triff",".bmp");
        var len=arr.length;
        for(var i=0;i<len;i++)
        {
            if(arr[i]==type.toLowerCase())                   
           {
                return true; 
           } 
        }
        return false;
   } 
  /***************************
  trim(string):去除前后空格
***************************/
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function()
{
    for (var i=0; this.charAt(i)==' '; i++);
	return this.substring(i,this.length);
}
String.prototype.rtrim = function()
{
    for (var i=this.length-1; this.charAt(i)==' '; i--);
	return this.substring(0,i+1);
}
String.prototype.len=function()
{
	var i,str1,str2,str3,nLen;
	str1 = this;
	nLen = 0;
	for(i=1;i<=str1.length;i++)
	{
	str2=str1.substring(i-1,i)
	str3=escape(str2);
	if(str3.length>3)
	{
		nLen = nLen + 2;
	}
	else
	{
		nLen = nLen + 1;
	}
	}
	return nLen;
}
  //图标自动缩放
  //eg onload="ImgAutoResize(this,'222','167')"
function ImgAutoResize(i,MaxWidth,MaxHight){
     
     var MaxW=MaxWidth; //定义图片显示的最大宽度
     var MaxH=MaxHight; //定义图片显示的最大高度
     var o=new Image();o.src=i.src;var w=o.width;var h=o.height;var t;if (w>MaxW){t=MaxW;}else{t=w;}
     if ((h*t/w)>MaxH){i.height=MaxH;i.width=MaxH/h*w;}else{i.width=t;i.height=t/w*h;}
}
 /***************************
功能:得到IE地址传递的参数值
參數:name(传递参数名称)
***************************/
 function $GP(name)
{
	var str="";
	var has=new $H();
	var herf=window.location.href.toString();
	var are=herf.split('?')[1];
	
	if(typeof(are)=="undefined")return null;
	var arr=are.split('&');
	for(var i=0;i<arr.length;i++)
	{				
		has.add(arr[i].split('=')[0],arr[i].split('=')[1])
	}			
	if(has.contains(name))
	{
		str=has.items(name);
	}
	if(!has.contains(name))
	{
		//alert("不存在参数名称 :"+name);
	}
	return str;
}
//哈希表
function $H()
{
    this._hash = new Object();
    this.add = function(key, value)
    {
        if (typeof (key) != "undefined")
        {
            if (this.contains(key) == false)
            {
                this._hash[key] = typeof (value) == "undefined" ? null : value;
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    this.remove = function(key) { delete this._hash[key]; }
    this.count = function() { var i = 0; for (var k in this._hash) { i++; } return i; }
    this.items = function(key) { return this._hash[key]; }
    this.contains = function(key) { return typeof (this._hash[key]) != "undefined"; }
    this.clear = function() { for (var k in this._hash) { delete this._hash[k]; } }
    this.getItems = function()
    {
        var val = "";
        for (var i in this._hash)
        {
            val += this.items(i) + "|";
        }
        return val.substring(0, val.length - 1);
    }
    this.getKeys = function()
    {
        var val = "";
        for (var i in this._hash)
        {
            val += i + "|";
        }
        return val.substring(0, val.length - 1);
    }
    this.getTextByKey = function(key) { return this._hash[key]; }
    this.getKeyByText = function(text)
    {
        var str = "";
        for (var i in this._hash)
        {
            var val = this.items(i);
            if (val == text)
            {
                str = i;
            }
        }
        return str;
    }
    this.getKeyText = function()
    {
        var val = "";
        for (var i in this._hash)
        {
            val += i + "=" + this.items(i) + "|";
        }
        return val.substring(0, val.length - 1);
    }
}
function delRecord() 
{
    if (document.getElementById("txtIndex").value == "")
     {
        alert("请选择记录！");
        return false;
    }
    return confirm('确定删除吗?');
}
function btnSubmit() 
{
    return confirm('确定提交吗?');
}
/***************************
功能:显示团队管理成员图片
參數:
***************************/
var imgobj;
function showImage(e)
{
    var img = document.getElementById("imgDiv");
    if ($("#imgdiv").html() == null)
    {
        if (img != null)
        {
            document.body.removeChild(document.getElementById("imgDiv"));
        }
        $("body").append("<div id='imgdiv'style='width:94px;height:126px;background:url(../Images/floatdivbg.png) no-repeat;padding:9px'><img width='77px' height='110px' src=" + $(e).attr("img") + " alt='' /></div>");
    }
    var p = $(e);
    var position = p.offset();
    $("#imgdiv").css(
			    {
			        position: "absolute",
			        left: p.offset().left + $(e).width() + 10 + "px",
			        top: p.offset().top + "px"
			    });
}
function removeImage(e)
{
    var img = document.getElementById("imgdiv");

    if (img != null)
    {
        document.body.removeChild(document.getElementById("imgdiv"));
    }
}

function googlesearch(str)
{   
    var wq = document.getElementById(str).value;
    var link = "http://www.google.com/search?domains=www.ofcapital.com&sitesearch=www.ofcapital.com/&q=" + wq;
    window.open(link);
}