﻿function getElementById(id)
{
	return (isAll) ? document.all[id] : document.getElementById(id) == null;
}

function $(s)
 {
     return document.getElementById(s);
 }
var isAll = (document.all) ? true : false;
/*
方法名：WinOpen
功能：打开页面
参数1：strURL，页面地址
参数2：strTitle，被打开页面标题
参数3：winwidth，被打开页面宽
参数4：winheight，被打开页面高
*/
function WinOpen(strURL,strTitle,winwidth,winheight){
	var winleft=(screen.availwidth-winwidth)/2;
	var wintop=(screen.availheight-winheight)/2;
	window.open(strURL,strTitle,"width="+winwidth+",top="+wintop+",left="+winleft+",height="+winheight+",location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=yes,status=yes,resizable=no");
}
function WinOpenNO(strURL,strTitle,winwidth,winheight){
	var winleft=(screen.availwidth-winwidth)/2;
	var wintop=(screen.availheight-winheight)/2;
	window.open(strURL,strTitle,"width="+winwidth+",top="+wintop+",left="+winleft+",height="+winheight+",location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=no,status=no,resizable=no");
}
function WinOpenHidden(strURL){
	var winleft = screen.availwidth;
	var wintop= screen.availheight;
	var winwidth = 2;
	var winheight = 2;
	window.open(strURL,"win95598hide","width="+winwidth+",top="+wintop+",left="+winleft+",height="+winheight+",location=no,menubar=no,titlebar=no,toolbar=no,scrollbars=no,status=no,resizable=no");
	//window.open(strURL);
}
/*
方法名：EditSelect
功能：带参数打开页面
参数1：strURL，页面地址
参数2：strParam，参数名
参数3：strParamVal,参数值
参数4：strTitle，被打开页面标题
参数5：winwidth，被打开页面宽
参数6：winheight，被打开页面高
*/
function EditSelect(strURL,strParam,strParamVal,strTitle,winwidth,winheight){
	winleft=(screen.availwidth-winwidth)/2;
	wintop=(screen.availheight-winheight)/2;
	window.open(strURL+"?"+strParam+"="+strParamVal,strTitle,"width="+winwidth+",top="+wintop+",left="+winleft+",height="+winheight+",location=no,menubar=no,titlebar=no,toolbar=no,status=no,resizable=no")
}
/*
功能：设置ImageButton是否可用
参数1：obj 字符串 按钮名称
参数2：flag 布尔型 true：可用 false：不可用
*/
function SetImageButton(obj,flag)
{
	var ImgTrue = "url(/ig_common/images/ig_butXP1s.gif)";
	var ImgFalse = "url(/ig_common/images/ig_butXP5s.gif)";
	if(flag)
	{
		document.getElementById(obj).setAttribute("disabled",false);
		document.getElementById(obj+"__5").style.background = ImgTrue+" no-repeat top left";
		document.getElementById(obj+"__6").style.background = ImgTrue+" no-repeat top right";
		document.getElementById(obj+"__7").style.background = ImgTrue+" no-repeat bottom left";
		document.getElementById(obj+"__8").style.background = ImgTrue+" no-repeat bottom right";
		document.getElementById(obj+"__5").setAttribute("disabled",false);
	}
	else
	{
		document.getElementById(obj).setAttribute("disabled",true);
		document.getElementById(obj+"__5").style.background = ImgFalse+" no-repeat top left";
		document.getElementById(obj+"__6").style.background = ImgFalse+" no-repeat top right";
		document.getElementById(obj+"__7").style.background = ImgFalse+" no-repeat bottom left";
		document.getElementById(obj+"__8").style.background = ImgFalse+" no-repeat bottom right";
		document.getElementById(obj+"__5").setAttribute("disabled",true);
	}
}
function SetDateType(strDate)
{
	var dd =strDate.split(" ");
	var dd1 = dd[0].split("-");
	var dd2 = dd[1].split(":");
	var dd4 = new Date(dd1[1],dd1[2],dd1[0],dd2[0],dd2[1],dd2[2]);
	return dd4;
}

//关闭当前窗口并刷新父窗口
function closeAndRefreshParent()
{
	try
	{
	if(self.opener != null)
	{
		window.opener.location.href = window.opener.location.href
		window.close() ;
	}
	}
	catch(e)
	{}

}

//=============================================================================================
//	********************* String 基本方法增强 *********************
//=============================================================================================

function getElementById(id)
{
	return (isAll) ? document.all[id] : document.getElementById(id);
}

//=============================================================================================
//	是否为空
//=============================================================================================
String.prototype.isEmpty = function (){
	var temp = this;
	if(this == null)
		return true;
	else
		return temp.trim() == "";
}
//=============================================================================================
//	去除左边字符(相当于VBScript的LTrim())
//=============================================================================================
String.prototype.lTrim = function (){
	var temp = this;
	return temp.replace(/^\s*/, "");
}
//alert("\r\n           askdfasdf     \r\n sadfasdf".lTrim().replace(/[\s]/gim, "_"));
//alert("\r\n                \r\n ".lTrim().replace(/[\s]/gim, "_"));
//=============================================================================================
//	去除左边字符(相当于VBScript的RTrim())
//=============================================================================================
String.prototype.rTrim = function (){
	var temp = this;
	return temp.replace(/\s*$/, "");
}
//alert("asd  \r\naskdfasdf           \r\n".rTrim().replace(/[\s]/gim, "_"));
//alert("\r\n                \r\n ".rTrim().replace(/[\s]/gim, "_"));
//=============================================================================================
//	去除左边字符(相当于VBScript的Trim())
//=============================================================================================
String.prototype.trim = function (){
	var temp = this;
	temp = temp.lTrim();
	temp = temp.rTrim();
	return temp;
}
function getParameter(varName)
{
	var query = location.search;
	if (query != null || query != "")
	{
		query = query.replace(/^\?+/, "");
		var qArray = query.split("&");
		var len = qArray.length;
		if (len > 0)
		{
			for (var i=0; i<len; i++)
			{
				var sArray = qArray[i].split("=", 2);
				if (sArray[0] && sArray[1] && sArray[0] == varName)
				{
					return unescape(sArray[1]);
				}
			}
		}
	}
	return null;
}

//=============================================================================================
//	是否为数字			zzj		07.11.30
//=============================================================================================
String.prototype.isNumber = function()
{
	var re = /^([0-9]+)$/ig;
	//var re = /^([0-9]+)$/ig;
	return re.test(this);
}


//=============================================================================================
//	是否为正数字			zzj		08.2.26  
//=============================================================================================
String.prototype.isUnsignedNumeric = function()
{	
	var re = /^\d+(\.\d+)?$/ig;
	return re.test(this);
}

//=============================================================================================
//	是否为正浮点数			zzj		08.3.28
//=============================================================================================
String.prototype.isUnsignDouble = function()
{	
	var re=/^\+?\d+(\.\d+)?$/;
	return re.test(this);
}

//=============================================================================================
//	是否为大于0的数字			zzj		08.2.26  
//=============================================================================================
String.prototype.isZero = function()
{
	var re = this * 1;
	if ( re == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//=============================================================================================
//	是否为正负浮点的数字，包括0			zzj		08.4.30
//=============================================================================================
String.prototype.isufloat = function()
{
	var re =/^[-+]?\d+(\.\d+)?$/; 
	return re.test(this);
}




//全选-取消函数,返回当前全选/取消状态的布尔值, 全选返回true, 未全选返回 false		zzj 07.12.14
function selectAllCheckbox(oForm, bState, sName)
{
	//		oForm:		当前表单
	//		bState:		当前的改变的状态(tru|false)
	//		sName:		CheckBox的name  局限于某一部分的CheckBox,不至于影响到其他的CheckBox	
	var items = oForm.elements;
	for(var i=0; i<items.length; i++)
	{
		if(items[i].type=="checkbox" && items[i].name.toUpperCase()==sName.toUpperCase())
		{
			items[i].checked = bState;
		}
	}	
	return bState;	
}


//=============================================================================================
//	列表常用的CheckBox函数(部分函数依赖于 base.string)		zzj 增加原先选择的	07.12.14
//=============================================================================================

//是否有选择一条以上的记录,返回是否有选择记录的布尔值, 有返回true, 否返回 false
function checkBoxIsChecked(oForm, sName)
{
	//		oForm:		当前表单
	//		sName:		CheckBox的name,局限于某一部分的CheckBox,不至于影响到其他的CheckBox
	
	var items = oForm.elements;

	for(var i=0; i<items.length; i++)
	{
		if (items[i].type=="checkbox" && items[i].name.toUpperCase()==sName.toUpperCase() && items[i].checked)
		{
			return true;
		}
	}
	
	return false;
}


//=============================================================================================
//		zzj 增加原先选择的	07.12.14
//=============================================================================================
function CheckBoxCheck(oForm, sID)
{
	if( checkBoxIsChecked(oForm, sID) )
	{
		return true;
	}
	else
	{
		alert("请选择要操作的项!");
		return false;
	}
}


//=============================================================================================
//		zzj 修改 判断是否窗体原素中的checkbox是否有选择的	07.12.19
//=============================================================================================
function CheckifChecked(oForm)
{
	var items = oForm.elements;
	for(var i=0; i<items.length; i++)
	{
		if (items[i].type=="checkbox" && items[i].checked)
		{
			return true;
		}
	}
	return false;		
}

//=============================================================================================
//		zzj 检查窗体原素中的checkbox 是否有选择的公用函数	07.12.19
//=============================================================================================
function ifCheckboxChecked(oForm)
{
	if ( CheckifChecked(oForm))
	{
		return true;
	}
	else
	{
		alert('请选择要操作的项!');
		return false;
	}
}


//	获取URL参数值
function GetParValue(url, ParName, unEsc){
	var Par = GetPar(url, ParName);
	if ((Par == null)||(Par == '')){
		return null;
	}
	Par = Par[0].split('=');
	return (unEsc == true ? unescape(Par[1].toString()) : Par[1].toString());
}

//	获取URL参数串
function GetPar(url, ParName){
	url = url.split('?');
	//	如果没有发现?号的话，说明没有参数，不做分析

	if (url[1] == undefined || url[1] == null)
		return null;
	url = url[1];
	var test = new RegExp(ParName + "=\\w*");
	return url.match(test);
}

//	设置URL参数值
function SetParValue(url, ParName, ParValue, escape){
	var Par = GetPar(url, ParName);
	
	if (Par != null){
		url = url.replace(Par,'');
		Par = Par.split('=');
		Par[1] = ParValue;
	}
	else{
		
		Par = new Array();
		Par[0] = (url.indexOf('?') + 1 > 0 ? '&': '?') + ParName;
		Par[1] = ParValue;
	}
	
	url += Par[0] + '=' + (escape== true ? escape(Par[1]) : Par[1]);
	
	return url;
}


function SetSizeForm( obj,iuserwidth)
{
    var iWidth   =   document.body.clientWidth;
    var iheight   =  document.body.clientHeight;
    var objtmp = getElementById(obj);
    if ( objtmp != null)
    {
        objtmp.style.width = iWidth -iuserwidth;      
        objtmp.style.height = iheight-150+"px";
        
    }
}
