﻿// JScript 文件

function $(id)
{
    return document.getElementById(id);
}
function $$(id)
{
    return top.document.getElementById(id);
}

//检查控件长度
function checkLen()
{
    var t = arguments.length;
		if(t%4!=0)
		{
		    alert("参数数目出错");
			return false;
		}
		for(var i=0;i<t/4;i++)
		{
		    var len = $(arguments[i*4]).value.length;
			if(len < parseInt(arguments[i*4+1]) || len >parseInt(arguments[i*4+2]))
			{
				alert(arguments[i*4+3]);
				return false;
			}
		}
		return true;
}

//检测几个控件中的一个必须不为空，第一个参数为控件个数
function checkOneIsNotEmpty()
{
    var t = arguments.length;
    if(arguments[0]!=t-1)
    {
        alert("参数数目出错");
		return false;
    }
    var tf = false;
    for(var i=1;i<t;i++)
		{
			if($(arguments[i]).value!="")
			{
				tf = true;
				break;
			}
		}
	return tf;

}

//检查控件值是否为空
function checkIsEmpty()
	{
		var t = arguments.length;
		if(t%2!=0)
		{
		    alert("参数数目出错");
			return false;
		}
		for(var i=0;i<t/2;i++)
		{
			if($(arguments[i*2]).value=="")
			{
				alert(arguments[i*2+1]);
				return false;
			}
		}
		return true;
	}
	
	//检查控件的值是否相等 
	function checkIsEqual()
	{
		var t = arguments.length;
		if(t%3!=0)
		{
		    alert("参数数目出错");
			return false;
		}
		for(var i=0;i<t/3;i++)
		{
			if($(arguments[i*3]).value != $(arguments[i*3+1]).value)
			{
				alert(arguments[i*3+2]);
				return false;
			}
		}
		return true;
	}
	
	//检测邮箱
	function regTestMailBox(id)
	{
	    var reg = /^\s*([\w-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*$/;
        return reg.test($(id).value);        
    }
    
    //检测图片域
    function regTestImg(id)
    {
        return /^.*(jpg|gif|bmp)$/.test($(id).value.toLowerCase());
        
    }
    
    //打开一个新的窗口，第一个参数为url，后面为名称与职
function openNewWindow()
{
//	debugger;
    var t = arguments.length;
//	var method = "get";
	var frm = document.createElement("form");
    if((t+1)%2!=0)
        return false;//参数数目出错
    var url= arguments[0];
	if(t!=1)
	{		
		for(var i=0;i<(t-1)/2;i++)
		{
			var input = document.createElement('<INPUT name="'+ arguments[i*2+1] +'"/>');
			input.id = arguments[i*2+1] ;
			input.value = arguments[i*2+2] ;
			frm.appendChild(input);			
		}
	}
	
    frm.method = "get";
    frm.target = "_blank";
    frm.action = url;
    document.body.appendChild(frm);
    frm.submit();
	frm.style.display = "none";
}

	//获取url的查询字符串的 参数
	function getPara(query)
	{
	 var str = document.URL;
	 var num = str.indexOf(query+"=");
	 if(num>-1)
	 {
	  var joinIndex = str.indexOf("&",num);
	  if(joinIndex>-1)
	  {
	   return str.substring(num+query.length+1,joinIndex);
	  }
	  else
	   return str.substr(num+query.length+1);
	 }
	 else
	  return null;  
	}

    //设置iframe高度
    function SetWinHeight(obj)
    {
		var h;
        var win = obj;
        if (document.getElementById)
        {
            if (win && !window.opera)
            {
                if (win.contentDocument && win.contentDocument.body.offsetHeight)
                {
                    win.height = h = win.contentDocument.body.offsetHeight; 
					//win.style.height = pt.x = win.contentDocument.body.offsetHeight; 
					//win.width = win.contentDocument.body.scrollWidth;
                }
                else if (win.Document && win.Document.body.scrollHeight)
                {
                    win.height = h = win.Document.body.scrollHeight;
					//win.style.height = pt.y = win.Document.body.scrollHeight;
					//win.width = win.Document.body.scrollWidth;
                }
            }
        }
		return h;
    }
	
	// 获取一个元素的决对位置
	function getXY(id)
    {
      var oTmp = $(id);
      var pt = new Point(0,0);
      do {
      pt.x += oTmp.offsetLeft;
      pt.y += oTmp.offsetTop;
      oTmp = oTmp.offsetParent;
      } while(oTmp.tagName!="BODY");
      return pt;
    }
	
	//-- Point 表示一个点的坐标 --
	function Point(iX, iY)
	{
		this.x = iX;
		this.y = iY;
	}
