var UrlBase;

var jscomIsDebug=true;
function jscomDebugAlert(message)
{
    if(jscomIsDebug)
    {
        alert(message);
    }
}

function jscomNewOpenBySize(url,target,width,height)
{
		var tt,w,left,top;
		left=(screen.width-width)/2;
		if(left<0){ left=0;}

		top=(screen.height-height)/2;
		if(top<0){ top=0;}

		tt="toolbar=no, menubar=no, scrollbars=yes,resizable=yes,location=no, status=no,";
		tt=tt+"width="+width+",height="+height+",left="+left+",top="+top;
		w=window.open(url,target,tt);
		if(w!=null)
		{
			w.focus();
		}
}

function jscomNewOpenBySizePos(url,target,width,height,left,top)
{
		var tt;
		tt="toolbar=no, menubar=no, scrollbars=no,resizable=yes,location=no, status=no,";
		tt=tt+",width="+width+",height="+height;
		tt=tt+",left="+left+",top="+top;
		w=window.open(url,target,tt);
		if(w!=null)
		{
			w.focus();
		}
}


//过滤特殊符号（如' "） 
function jscomFiltrateSomeKeyForKeyPress()
{
	if(event.keyCode==39 || event.keyCode==34)
	{
		event.keyCode=0;
	}
}

//判断是否有检查框被选中
//返回 true有  false 无
function jscomIsCheckBoxSelect(frm)
{
	var src;

	flag=false;
	for (var i=0;i<frm.elements.length;i++)
	{
		src=frm.elements[i];
		if(src.type=="checkbox" && src.checked)
		{
				flag=true;
				break;
		}
	}
	return flag;
}

//全选框事件
function jscomToggleAllCheckBox()
{
    var e = event.srcElement;
    if(e==null || e.type != "checkbox")
    {
        return;
    }
    var flag=e.checked;
    
    var inputs = document.forms[0].elements;
    for (var i=0; i < inputs.length; i++)
    {
        if (inputs[i].type == "checkbox" && inputs[i].name.indexOf("chkSelect") >=0)
        {
            inputs[i].checked = flag;
        }
    }
}

/*
格式化数字
	num  要格式化的数值
	decimal_num	小数位数 
	has_split 是否要千分为分割符 true or false
	
	返回 格式化的字符串
*/
function jscomFormatNumber(num,decimal_num,has_split)
{
	//非数值，直接返回
	if(isNaN(num))
	{
		return num;
	}
	
	var tmp_num,tmp_decimal_num;
	
	tmp_decimal_num=decimal_num;
	if(isNaN(decimal_num))
	{
		tmp_decimal_num=0;
	} 
	
	tmp_num=num*Math.pow(10,tmp_decimal_num);
	tmp_num=Math.round(tmp_num);
	tmp_num=tmp_num / Math.pow(10,tmp_decimal_num);
	if(!has_split)
	{ 
		return tmp_num;
	}
	//千分为分割符 以后处理
	return tmp_num;
}


BakupBodyFocus=null;
BackupWaitBodyContext=null;
CanCancelWait=true;

function jscomLockScreenToWait(msg)
{
	if (BakupBodyFocus==null && BackupWaitBodyContext==null)
	{
		BakupBodyFocus = document.body.onfocus+"";
		BackupWaitBodyContext = document.body.oncontextmenu+'';
		document.body.onfocus = jscomLockScreenToWait;
		document.body.oncontextmenu = jscomCancelClick;
	}
	var div = document.getElementById("divLockWaiting");
	if (div+''=="undefined")
	{
		div = document.createElement("DIV");
		div.setAttribute("id","divLockWaiting");
		div.className = "WaitBox";
		div.title="点击可以取消";
		div.style.padding = 10;
		div.style.paddingLeft = 30;
		div.style.paddingRight = 30;
		div.innerHTML = msg;
		document.body.appendChild(div);
	}
	var x =(document.body.clientWidth-div.offsetWidth)/2;
	var y = (document.body.clientHeight-div.offsetHeight)/2;
	div.style.pixelLeft = x;
	div.style.pixelTop = y;
	div.style.visibility = "visible";
	div.onclick = jscomCancelClick;
	div.setCapture();
}

function jscomUnlockScreenWait()
{
	var div = document.getElementById("divLockWaiting");
	if (div+''=="undefined")
	{
		return;
	}
	div.style.visibility = "hidden";
	document.body.onfocus = BakupBodyFocus;
	document.body.oncontextmenu = BackupWaitBodyContext;
	BakupBodyFocus = null;
	BackupWaitBodyContext = null;
	document.releaseCapture();
}

function jscomCancelClick()
{
	var elem = event.srcElement;
	if (CanCancelWait==true && elem.className=='WaitBox')
	{
		jscomUnlockScreenWait();
		event.cancelBubble = false;
		return false;
	}
	return false;
}

function jscomShowScreenWait(msg)
{
	var div = document.getElementById("divWaiting");
	if (div+''=="undefined")
	{
		div = document.createElement("DIV");
		div.setAttribute("id","divWaiting");
		div.className = "WaitBox";
		div.style.padding = 10;
		div.style.paddingLeft = 30;
		div.style.paddingRight = 30;
		div.innerHTML = msg;
		document.body.appendChild(div);
	}
	var x =(document.body.clientWidth-div.offsetWidth)/2;
	var y = (document.body.clientHeight-div.offsetHeight)/2;
	div.style.pixelLeft = x;
	div.style.pixelTop = y;
	div.style.visibility = "visible";
}

function jscomHiddlenScreenWait()
{
	var div = document.getElementById("divWaiting");
	if (div+''=="undefined")
	{
		return;
	}
	div.style.visibility = "hidden";
}

//显示键盘输入密码
function jscomShowKeyBoard(objInputID)
{
	var objInput = document.getElementById(objInputID);
	if(objInput)
	{
		var intLeft = 100+Math.random()*400;
		while(intLeft>(screen.width-282)){intLeft = 100+Math.random()*400;}
		var intTop= 100+Math.random()*300;
		while(intLeft>(screen.width-95)){intTop = 100+Math.random()*300;}
		//var intLeft=document.body.scrollLeft+event.clientX; //获取当前鼠标位置的X坐标
		//var intTop=document.body.scrollTop+event.clientY; //获取当前鼠标位置的Y坐标
		var strUrl = "Modules/KeyBorad.htm";
		var strStyle = "dialogLeft="+intLeft+"pt;dialogTop="+intTop+"pt;dialogWidth=282pt;dialogHeight=95pt;center=no;resizable=no;status=NO;help=off;"
		var strDate  = objInput.value;
		var strData = window.showModalDialog(strUrl, objInput, strStyle);
	}
}


function jscomSelectTab(name,cursel,n)
{
    for(i=1;i<=n;i++)
    {
        var menu=document.getElementById(name+i);
        if(menu!=null)
        {
            menu.className=i==cursel?"hover":"";
        }
        var con=document.getElementById("con_"+name+"_"+i);
        if(con!=null)
        {
            con.style.display=i==cursel?"block":"none";
        }
    }
}

/* 检查是否在限制的字符内*/
function jscomIsStrInLimitChars(str, charList) {
    var retValue = true;
    if (str.trim().length <= 0) {
        retValue = false;
    }
    else {
        for (var i = 0; i < str.trim().length; i++) {
            if (charList.indexOf(str.trim().substring(i, i + 1)) < 0) {
                retValue = false;
                break;
            }
        }
    }
    return retValue;
}

function jscomAddFavorite(sUrl, sTitle) {
    if (window.sidebar && "object" == typeof (window.sidebar) && "function" == typeof (window.sidebar.addPanel)) {
        window.sidebar.addPanel(sTitle, sUrl, '');
    }
    else if (document.all && "object" == typeof (window.external)) {
        window.external.addFavorite(sUrl, sTitle);
    }
}

function jscomDisplay(imgObj, s)
{
    if (!$(s)) return;
    if ($(s).style.display == "none")
    {
        $(s).style.display = "block";
        imgObj.src = UrlBase+"Images/Icon/up.gif";
    }
    else
    {
        $(s).style.display = "none";
        imgObj.src = UrlBase+"Images/Icon/down.gif";
    }
}

/**
 * 打开通用查询列表的模式窗口
 * dialogId 在Config/Common/DialogConfig.xml 中定义的dialog id
 * width 默认650 可选
 * height 默认480 可选
 * isMulti 是否为多选 true / false 默认false
 * ids 已经选中的内码 ,分开 可选
 * names 已经选中的名称 ,分开 可选
 * searchWord 查询的默认值
 * appendTitle 其他传入的查询条件 标题
 * appendType 其他传入的查询条件 类型
 * appendText 其他传入的查询条件 名称
 * appendValue 其他传入的查询条件 值
 * rightCode 权限编码
 * 返回的是Object obj对象 有obj.Value,obj.Name,obj.Desc  如果obj为空(null) 表示没有选择 清除的时候是obj.Key obj.Name obj.Desc都为""
 * 用法例子：
 *
 *    //默认查出通用代码
 *   var v = jscomShowQueryDialog("ComCode",650,480,"false","","","","","代码类型","1");
 *   if(v!=null){
 *		document.forms[0].codeID.value = v.Value;
 *		document.forms[0].codeName.value = v.Name;
 *		document.forms[0].codeDesc.value = v.Desc;
 *   }
 */
//jscomShowQueryDialog(dialogID,width,height,isMulti,ids,names,searchWord,appendTitle,appendType,appendText,appendValue,rightCode) 
function jscomShowQueryDialog(dialogID,width,height,isMulti,ids,names,searchWord,
    appendTitle,appendType,appendText,appendValue,rightCode) 
{
	if(width==null || typeof(width)=="undefined" || width=="")
	{
		width="650";
	}
	if(height==null || typeof(height)=="undefined" || height=="")
	{
		height="480";
	}
	if(isMulti==null || typeof(isMulti)=="undefined" || (isMulti!="true" && isMulti!="True" && isMulti!="false" && isMulti!="False"))
	{
		isMulti="false";
	}
	if(ids==null || typeof(ids)=="undefined")
	{
		ids="";
	}
	if(names==null || typeof(names)=="undefined")
	{
		names="";
	}
	if(searchWord==null || typeof(searchWord)=="undefined")
	{
		searchWord="";
	}
	if(appendTitle==null || typeof(appendTitle)=="undefined")
	{
		appendTitle="";
	}
	if(appendType==null || typeof(appendType)=="undefined")
	{
		appendType="";
	}
	if(appendText==null || typeof(appendText)=="undefined")
	{
		appendText="";
	}
	if(appendValue==null || typeof(appendValue)=="undefined"){
		appendValue="";
	}
	if(rightCode==null || typeof(rightCode)=="undefined")
	{
		rightCode="";
	}
	var url="../Common/DialogFrame.aspx?DialogID="+dialogID+"&Multi="+isMulti+"&SearchWord="+searchWord;
	url=url+"&AppendTitle="+appendTitle+"&AppendType="+appendType+"&AppendText="+appendText+"&AppendValue="+appendValue;
	url=url+"&IDs="+ids+"&Names="+names+"&RightCode="+rightCode;;
	//alert(url);
	//jscomNewOpenBySize(url,"aaa",680,450);
 	return window.showModalDialog(url,"","help: No; scroll:No;resizable: No; status: No;dialogWidth:"+width+"px;dialogHeight:"+height+"px");
}

//加载一个或多个函数到window.onload方法
function jscomAddLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

//加载一个或多个函数到任一元素的任一事件
function jscomAddEvent(E,e,fn)
{
    if(E.attachEvent)
    {
        E.attachEvent(e,function(){fn.call(E)})
    }
    else
    {
        E.addEventListener(e.slice(2),fn,false);
    }
}

//通用的输入表单检查  弹出ALERT对话框
/*
*   inputID  要检查的表单ID
*   errMessage  错误提示信息
*   checkType  检查类型：为空、电话号码格式、邮件格式、身份证号码
*/
function jscomCheckInputPopAlert(inputID,errMessage,checkType)
{
    if(!document.getElementById(inputID))
    {
        alert("检查的表单["+ inputID +"]不存在！");
        return false;
    }
    
    var obj = document.getElementById(inputID)
    if(checkType == "isNull")
    {
        if(obj.value == "")
        {
            alert(errMessage);
            obj.focus();
            return false;
        }
    }
    else if(checkType == "eMail")
    {
        if(obj.value == "")
        {
            return true;
        }
        if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)) == false) 
        {
            alert("请检查您的邮箱地址是否有误！");
            obj.focus();
            return false;
        }
    }
    else if(checkType == "phone")
    {
        if(obj.value == "")
        {
            return true;
        }
        if (/[0-9\-]{8,30}/.test(obj.value) == false) 
        {
            alert("请检查您的电话格式是否有误！");
            obj.focus();
            return false;
        }
    }
    else if(checkType == "userName")
    {
        if(obj.value == "")
        {
            return true;
        }
        if (/[a-zA-Z0-9@_\-\.]{3,30}/.test(obj.value) == false) 
        {
            alert("用户名只能由数字,字母及'-_@.'组成,3-30位！");
            obj.focus();
            return false;
        }
    }
    else if(checkType == "realName")
    {
        if(obj.value == "")
        {
            return false;
        }
        if (/[^\u4E00-\u9FA5]/g.test(obj.value)) 
        {
            alert("真实姓名只能是中文！");
            obj.focus();
            return false;
        }
    }
    else if(checkType == "userIDCard")
    {
        if(obj.value == "")
        {
            return true;
        }
        if (/\d{17}[\d|X|x]|\d{15}/.test(obj.value) == false) 
        {
            alert("请检查您的身份证号码是否有误！");
            obj.focus();
            return false;
        }
    }
    else
    {
        alert("检查类型不明确！");
        return false;
    }
    return true;
}
//通用的输入表单检查  发送文本信息
/*
*   infoID  文本类型的提示需要提供消息提示元素的ID
*   allowNull  是否必填
*/
function jscomCheckInputSendMessage(inputID,infoID,errMessage,allowNull,checkType)
{
    if(!document.getElementById(infoID))
    {
        alert("信息提示区["+ infoID +"]不存在！");
        return false;
    }
    var infoObj = document.getElementById(infoID);
    if(!document.getElementById(inputID))
    {
        infoObj.innerHTML = "<font color='red'>检查的表单["+ inputID +"]不存在！</font>";
        return false;
    }
    
    var obj = document.getElementById(inputID)
    if(!allowNull)
    {
        if(obj.value == "")
        {
            infoObj.innerHTML = "<font color='red'>" + errMessage + "</font>";
            return false;
        }
    }
    
    if(checkType == "eMail")
    {
        if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)) == false) 
        {
            infoObj.innerHTML = "<font color='red'>邮箱地址有误！</font>";
            return false;
        }
    }
    else if(checkType == "phone")
    {
        if(/[0-9\-]{8,30}/.test(obj.value) == false) 
        {
            infoObj.innerHTML = "<font color='red'>电话格式有误！</font>";
            return false;
        }
    }
    else if(checkType == "userName")
    {
        if (/[a-zA-Z0-9@_\-\.]{3,30}/.test(obj.value) == false) 
        {
            infoObj.innerHTML = "<font color='red'>用户名只能由数字,字母及'-_@.'组成,3-30位！</font>";
            return false;
        }
    }
    else if(checkType == "realName")
    {
        if (/[^\u4E00-\u9FA5]/g.test(obj.value)) 
        {
            infoObj.innerHTML = "<font color='red'>真实姓名只能输入中文！</font>";
            return false;
        }
    }
    else if(checkType == "userIDCard")
    {
        if (/\d{17}[\d|X|x]|\d{15}/.test(obj.value) == false) 
        {
            infoObj.innerHTML = "<font color='red'>身份证号码有误！</font>";
            return false;
        }
    }
    else if(checkType == "bankNo")
    {
        if (/\d{5,20}/.test(obj.value) == false) 
        {
            infoObj.innerHTML = "<font color='red'>银行账号有误！</font>";
            return false;
        }
    }
    else
    {
        infoObj.innerHTML = "<font color='red'>检查类型不明确！</font>";
        return false;
    }
    return true;

}
//通用的输入表单检查  弹出蒙板提示框信息
function jscomCheckInputPopDialog(inputID,errMessage,checkType)
{
    if(!document.getElementById(inputID));
}

