﻿// JScript 文件

/*使用地方：该文件只能加载在框架的center页面。既使用在显示gridview的页面中的按钮上。

			且form的名字默认位form1，不要改动


使用前操作：如果操作的数据表中没有工作流需要使用的字段instanceId，那么在给checkbox绑定数据的时候和和以前一样

			没有区别。

			表中如果有instanceId字段。那么在给checkbox绑定数据的时候书写格式为:
			value='<%# Eval("bfhlsh").ToString()+","+Eval("instanceId").ToString() %>' 
			其中bfhlsh就是业务表主键字段，instanceId为工作流中用的id。根据自己的表字段进行修改。

			 
  使用说明：点击删除，发送等不需要输入意见并且不打开新窗口的调用方法 simpleOper('operName')，参数为你要操

			作的名字。如不需要弹出提示窗口的调用方法 noConfirmOper('operName')
			点击编辑按钮时调用方法 editOper('operName','url','size')参数url为要打开新窗口的地址，size为新打

			开窗口的大小。输入格式为：'height=420,width=500,top=220,left=300'
			点击回退，审核，审批等需要输入意见并且如果是选择一条记录的时候显示该条记录的详细信息，多条记录的时候

			只弹出输入审核意见的窗口
			的操作时调用方法 multiOper('operName','url1','size1','url2','size2').参数url1为操作一条记录时的

			地址，对应的大小为size1.
			url2为多条记录时需要打开页面的地址，size2为控制它的大小。


	  提示：在调用需要打开页面的某个方法时一定要写它的size参数写上，要不然它就无法屏蔽调新打开窗口的菜单栏，工具栏，

			地址栏等不需要的东西。


	返回值：不管是那种需要打开页面的方法。执行完之后都会将checkbox的value值获取到(已除去全选按钮)并连接成以逗号
			隔开的字符串传递到新的页面。并且已经将字符串最末尾的逗号去掉了。

			在新页面中只用使用方法 Request.QueryString["bid"] 获得业务主键ID；

			使用方法 Request.QueryString["sid"]获得工作流ID。根据自己需要的情况。选择您要获得的东西。


注解：李 龙  2009年4月1日。

*/
var counts = 0;  //选中的记录数
var info="";    //要操作的信息
var str="";     //业务主键ID
var insID = ""; //副主键（如工作流主键）

var chkValue="";

//解志杰注 2009年5月27日 12:38:02
function simpleConfirm(information, DatatypeName) 
{
	info = information;
	if (getCount()) {

		return confirm("您确定要" + info + "该" + (DatatypeName == "" ? "数据记录" : DatatypeName) + "吗？");
	}
	else
		return false;
}

//解志杰注 2009年5月27日 12:38:02
function directlyConfirm(information, DatatypeName) {
	info = information;

	return confirm("您确定要" + info + "该" + (DatatypeName == "" ? "数据记录" : DatatypeName) + "吗？");
}



//页面跳转方法，用于跳转到给定页面，并返回是否继续执行该按钮的其他方法（如：服务器端事件）
//pageDir:目标页面路径；isIontinue:完成后是否有其他事件需要继续执行
//解志杰注 2009年6月3日 11:06:06
function RedirectTo(pageDir, isContinue) 
{
	window.location = pageDir;
	return isContinue;
}

function getCount() {

	if (!theForm) {
		theForm = document.aspnetForm;
	}
	if (!theForm) {
		theForm = document.form1;
	}

	var elem = theForm.elements; 
	str = "";
	insID = "";
	chkValue="";
	counts = 0;
	n=0;            
	for(var i=0;i<elem.length;i++)
	{
		if(elem[i].type=="checkbox") 
		{            
			n++;
			if( n!=1 && elem[i].checked==true )
			{
			   counts++;
			   chkValue = elem[i].value;
			   if( chkValue.indexOf(',') == -1)
					str += chkValue + ",";
			   else
			   {
				   str += chkValue.substring(0,chkValue.indexOf(',')) + ",";
				   insID += chkValue.substring(chkValue.indexOf(',')+1,chkValue.length)+ ",";
			   }		       
			}
		}
	}
	if( n == 1 )
	{
		alert('没有可'+ info +'的记录了！');
		return false;
	}
	else if( counts == 0 )
	{
		alert('请选择要'+ info +'的记录！');
		return false;
	}
	else
		return true;
}

function getSelectedValues() {

	if (!theForm) {
		theForm = document.aspnetForm;
	}
	if (!theForm) {
		theForm = document.form1;
	}

	var elem = theForm.elements;
	chkValue = "";
	for (var i = 0; i < elem.length; i++)
	{
		if (elem[i].type == "checkbox"&&elem[i].checked == true && elem[i].value!="")
		{
			chkValue += elem[i].value+",";
		}
	}

	if (chkValue.lastIndexOf(",") == chkValue.length-1)
		chkValue = chkValue.substring(0, chkValue.lastIndexOf(","));
	
	return chkValue;
}

function simpleOper(information)
{
	info = information;
	if( getCount() )
	   return  confirm("您确定要"+info+"这 "+ counts +" 条记录吗？");
	else
	   return false;
}

function noConfirmOper(information)
{ 
	info = information;
	return getCount();
}

function editOper(information,url,size)
{
	info = information;
	if( getCount() )
	{
		str = str.substring(0,str.indexOf(','));
		insID = insID.substring(0,insID.indexOf(','));
		window.open(url+"?bid="+str+"&sid="+insID,"newWindow",size);
	}
	else
		return false;
}   

function multiOper(information,url1,size1,url2,size2)
{
	info = information;
	if( getCount() )
	{
		if( counts > 1 )
		{
			str = str.substring(0,str.lastIndexOf(','));
			insID = insID.substring(0,insID.lastIndexOf(','));
			window.open(url2+"?bid="+str+"&sid="+insID,"newWindow",size2);		
		}
		else
		{
			str = str.substring(0,str.lastIndexOf(','));
			insID = insID.substring(0,insID.lastIndexOf(','));
			window.open(url1+"?bid="+str+"&sid="+insID,"newWindow",size1);
		}
	}
	else
		return false;        
}

//给页面加载CheckBox全选功能

//页面初始时给所有复选框动态添加单击事件


//注解：洪建峰  2008年6月6日。

window.onload = function () {

    try {
        if (!theForm) {
            theForm = document.aspnetForm;
        }
        if (!theForm) {
            theForm = document.form1;
        }

        var elem = theForm.elements;
        var flag = 0;
        for (var i = 0; i < elem.length; i++) {
            if (elem[i].type == "checkbox" && elem[i].disabled == false) {
                flag++;
                if (flag === 1) {
                    elem[i].onclick = function () { setAll(this) }
                }
                else {
                    elem[i].onclick = function () { setSingle(this); }
                }
            }
        }
    } catch (exception) {

    }
}

function ClearSource() {
//var Source=document.body.firstChild.data;
//document.open();
//document.close();
//document.title="";
//document.body.innerHTML=Source;

}

function setAll(obj) {

	if (!theForm) {
		theForm = document.aspnetForm;
	}
	if (!theForm) {
		theForm = document.form1;
	}
	var elem = theForm.elements;
	
	for(var i=0;i<elem.length;i++)
	{
		if(elem[i].type=="checkbox"&&elem[i].disabled==false)
		{
			elem[i].checked=obj.checked;
		}
	}
}

function setSingle(obj) {

	if (!theForm) {
		theForm = document.aspnetForm;
	}
	if (!theForm) {
		theForm = document.form1;
	}

	var elem = theForm.elements;
	var count=0;
	var sum=0;
	var chk;
	for(var i=0;i<elem.length;i++)
	{
		if(elem[i].type=="checkbox"&&elem[i].disabled==false)
		{
			sum++;
			if(sum===1)
			{
				chk=elem[i];
			}
		   
		   if((elem[i].checked)&&(elem[i].id!=chk.id))
			  count++;
		}
	}
	if(count==(sum-1))
	{
		chk.checked=true;
	}
	else
	{
		chk.checked=false;
	}
}

//页面GridView行点击和鼠标经过时时颜色改变

//注解：李 龙 2009年4月1日

RowManager={Color:'yellowgreen',overColor:'yellow',oldColor:null,prColor:null,Player:null,Car:null};
RowManager.Listen=function(o,m){
	with(this){       
		if(!o) return;
		if(m){        
			if(Player!=o){
				if(Player) Player.style.backgroundColor = oldColor;                   
				Player = o;
				oldColor = Player.style.backgroundColor;
				Player.style.backgroundColor=Color;                 
			}
		}
		else{
//            if(Car&&Car!=Player) Car.style.backgroundColor = oldColor;    
//            Car=o;
//            oldColor = Car.style.backgroundColor;
//            if(o!=Player) o.style.backgroundColor = overColor;
		}
	}
}   

function ItemOver(o){
	RowManager.Listen(o,0);//0:MouseOver
}

function ItemClick(o){
	RowManager.Listen(o,1);//1:MouseClick
}

//用来显示类似于回退意见的DIV，与页面的AddMsgDIV1及AddMsgDIV2配合使用
//解志杰注 2009年6月16日8:42:39
function showAddMsgDIV() {
	var AddMsgDIV1_ = document.getElementById("AddMsgDIV1");
	var AddMsgDIV2_ = document.getElementById("AddMsgDIV2");

	AddMsgDIV1_.style.display = "block";
	AddMsgDIV2_.style.display = "block";

	//解志杰注 2009年6月3日 17:01:04
//	AddMsgDIV1_.style.width = "110%";
//	AddMsgDIV1_.style.height = "110%";
//	AddMsgDIV2_.style.width = "110%";
//	AddMsgDIV2_.style.height = "110%";

	window.scrollTo(0, 0); //如果当前窗口有滚动条，则滚动到（0，0）坐标

	window.document.body.scroll = "no";
	document.body.onselectStart = function() { return false; }

	return false;
}

//保留两位小数JS计算器，直接返回结果 解志杰注 2009年6月21日9:35:35
//参数：numberA（第1个文本框的ID，用于获取第1个计算数据）
//参数：numberB（第2个文本框的ID，用于获取第2个计算数据）
//参数：calType（运算符号：'+'、'-'、'*'、'/'）
function money(numberA, numberB, calType) {

	numberA = document.getElementById(numberA).value;
	numberB = document.getElementById(numberB).value;

	numberA = numberA.replace(/[^\d\.]/mg, '');
	numberA = isNaN(numberA) ? '' : numberA;

	numberB = numberB.replace(/[^\d\.]/mg, '');
	numberB = isNaN(numberB) ? '' : numberB;

	var valueEnd;

	switch (calType) {
		case '+':
			valueEnd = parseFloat(numberA + numberB).toFixed(2);
			break;
		case '-':
			valueEnd = parseFloat(numberA - numberB).toFixed(2);
			break;
		case '*':
			valueEnd = parseFloat(numberA * numberB).toFixed(2);
			break;
		case '/':
			valueEnd = parseFloat(numberA / numberB).toFixed(2);
			break;
	}
	return valueEnd;
}

//保留两位小数JS计算器，自动将计算结果输出到指定文本框 解志杰注 2009年6月19日 20:36:52
//参数：numberA（第1个文本框的ID，用于获取第1个计算数据）
//参数：numberB（第2个文本框的ID，用于获取第2个计算数据）
//参数：numberC（第3个文本框的ID，计算结果输出到的位置）
//参数：calType（运算符号：'+'、'-'、'*'、'/'）
function money(numberA, numberB, numberC, calType) {

	numberA=document.getElementById(numberA).value;
	numberB = document.getElementById(numberB).value;
	numberC = document.getElementById(numberC);

	numberA = numberA.replace(/[^\d\.]/mg, '');
	numberA = isNaN(numberA) ? '' : numberA;

	numberB = numberB.replace(/[^\d\.]/mg, '');
	numberB = isNaN(numberB) ? '' : numberB;

	var valueEnd;

	switch (calType) {
		case '+':
			valueEnd = parseFloat(numberA + numberB).toFixed(2);
			break;
		case '-':
			valueEnd = parseFloat(numberA - numberB).toFixed(2);
			break;
		case '*':
			valueEnd = parseFloat(numberA * numberB).toFixed(2);
			break;
		case '/':
			valueEnd = parseFloat(numberA / numberB).toFixed(2);
			break;
	}
	numberC.value = valueEnd;
	
//    if (numberA) {
//        numberA = parseFloat(numberA.value).toFixed(2); //四舍五入，保留2位
//    }

//    if (o.id == "ysje" | o.id == "xj_xj" | o.id == "zkje") {
//        var xjxj_ = document.getElementById("xj_xj"); //现金
//        var zkje_ = document.getElementById("zkje"); //折扣
//        var ysje_ = document.getElementById("ysje"); //应收
//        var xjzl_ = document.getElementById("xj_zl"); //找零
//        var ssje_ = document.getElementById("ssje"); //实收


//        //alert("xj-ys:"+( (xjxj_.value.toString(16)) - (ysje_.value.toString(16)) ).toString(16) );//十六进制转换
//        xjzl_.value = parseFloat(xjxj_.value - ysje_.value + (-(-zkje_.value))).toFixed(2); //现金找零 = 现金 - 应收金额 + 折扣金额  *方法 1
//        //xjzl_.value=Math.round((xjxj_.value - ysje_.value + (-(-zkje_.value)) )*100)/100;//现金找零 = 现金 - 应收金额 + 折扣金额 *方法 2
//        //xjzl_.value=-(- (xjxj_.value - ysje_.value + (-(-zkje_.value)) ) ).toFixed(2);//现金找零 = 现金 - 应收金额 + 折扣金额    *方法 3

//        ssje_.value = parseFloat(xjxj_.value - xjzl_.value).toFixed(2); //实收
//    }
}

//智能微缩图片JS方法 解志杰注 2009年6月21日 9:26:27
//参数：imgID（图片的标识ID）
//参数：maxWidth（图片的最大宽度，值为0则表示不限制宽度）
//参数：maxHeight（图片的最大高度，值为0则表示不限制高度）
function setImgSize(imgID, maxWidth, maxHeight) {
	var img = document.images[imgID];
	if (maxWidth < 1) {
		if (img.height > maxHeight) {
			img.height = maxHeight;
		}
		return true;
	}
	if (maxHeight < 1) {
		if (img.width > maxWidth) {
			img.width = maxWidth;
		}
		return true;
	}
	if (img.height > maxHeight || img.width > maxWidth) {
		if ((img.height / maxHeight) > (img.width / maxWidth)) {
			img.height = maxHeight;
		}
		else {
			img.width = maxWidth;
		}
		return true;
	}
}

//获取字符串长度，一个汉字的长度=2
//参数：controlId（要校验长度控件ID）
//参数：maxLength（最大长度限制）
//解志杰注 2009年6月21日 12:04:14
function checkLength(controlId,maxLength,dispName) {
	var controlValue = document.getElementById(controlId).value;
	var valueLength = controlValue.replace(/[^\x00-\xff]/g, "**").length;

	if (valueLength > maxLength) {
		alert(dispName + "的长度超出了限制长度：" + maxLength + "个字符！");
		return false;
	}
	return true;
}

//获取字符串长度，一个汉字的长度=2
//参数：controlId（要校验长度控件ID）
//参数：minLength（最小长度限制，为0时意味着可以不输入，为1时意味着必须输入）
//参数：maxLength（最大长度限制）
//解志杰注 2009年6月21日 12:20:27
function checkLength(controlId,minLength, maxLength,dispName) {
	var controlValue = document.getElementById(controlId).value;
	var valueLength = controlValue.replace(/[^\x00-\xff]/g, "**").length;

	if (valueLength < minLength) {
		if (valueLength == 0) {
			alert("请输入" + dispName + "！");
			return false;
		}
		else {
			alert(dispName + "的长度不应小于" + minLength + "个字符！");
			return false;
		}
	}
	else if (valueLength > maxLength) {
		alert(dispName + "的长度超出了限制长度：" + maxLength + "个字符！");
		return false;
	}
	return true;
}

//防止SQL注入 为用于检测查找页面对应的类型后的文本框而编写 解志杰注 2008年8月18日12:24:22
function checkParamString(ele) {
	if (ele.indexOf("'") != -1) {
		return "不能包含单引号！";
	}
	if (ele.indexOf("\"") != -1) {
		return "不能包含双引号！";
	}
	if (ele.indexOf(":") != -1) {
		return "不能包含冒号！";
	}
	return "";
}

//当页面行双击时显示日志查看页面
//解志杰注 2009年6月25日 10:53:33
function ShowLogViewPage(jtbh, logtype) {

	showModalDialog("../../ShowView.aspx?jtbh=" + jtbh + "&logtype=" + logtype, "", "dialogWidth:900px; dialogHeight:505px;center:yes;status:0; help:0;");

}

//=====================↓↓↓↓↓↓↓↓↓↓↓↓↓↓=====//解志杰注 2009年6月25日 20:07:10================================
function document.onkeydown() {

	if (event.keyCode == 8) {

		if (event.srcElement.type == "file") {
			event.returnValue = false;
		}
		else if ('text,textarea'.indexOf(event.srcElement.type) > -1) {

			if (event.srcElement.readOnly == true) {

				event.keyCode = 0;
				event.returnValue = false;
			}

		} else {

			event.keyCode = 0;
			event.returnValue = false;
		}
	}
	if (//(event.keyCode == 8) ||                  //屏蔽退格删除键
	   (event.ctrlKey && event.keyCode == 82) || //Ctrl + R
	   (window.event.ctrlKey && window.event.keyCode == 110) ||  //屏蔽Ctrl+n    
	   (window.event.altKey && window.event.keyCode == 115) ||  //屏蔽Alt+F4    
	   (event.keyCode == 116) ||                  //屏蔽 F5 刷新键  
	   (window.event.shiftKey && window.event.keyCode == 121) || //shift+F10   
	   (window.event.keyCode == 122)) //屏蔽 F11   6.
	{
		event.keyCode = 0;
		event.returnValue = false;
	}
}

function   getURL(str){   
  var   reg   =   new   RegExp("//\\S*/(\\S+\\.\\w+)[\\?]?");   
  return   reg.exec(str)[1];   
}

//解志杰注 2010年12月31日 14:03:33
function ShowContextmenu() {
    if (document.getElementById("Contextmenu")) {
        //var ContextmenuElement = document.createElement('<div id="Contextmenu" style="z-index:99;position:absolute;font-family:Tahoma;font-size:12px;padding:2px;visibility:hidden"> <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" bgcolor="#cecece" style="font-family:Tahoma;font-size:12px;"> <TR bgcolor="#ececec" style="cursor:hand" onclick="window.location=window.location"> <TD style="color:red">刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新刷新</TD> </TR> </TABLE> </div>');
        //theForm.appendChild(ContextmenuElement);
        document.getElementById("Contextmenu").style.visibility = "visible";
        //alert('event.clientX' + event.clientX + 'event.clientY' + event.clientY + 'document.body.scrollLeft' + document.body.scrollLeft + 'document.body.scrollTop' + document.body.scrollTop);

        document.getElementById("Contextmenu").style.left = document.documentElement.scrollLeft + event.clientX;
        document.getElementById("Contextmenu").style.top = document.documentElement.scrollTop + event.clientY;
    }
    return false;
}
function document.onclick() {
    if (document.getElementById("Contextmenu"))
        document.getElementById("Contextmenu").style.visibility = "hidden";
}

//if (window.Event)
//    document.captureEvents(Event.MOUSEUP);
//    
//页面右键选择性屏蔽 解志杰注 2009年6月26日 15:07:24    
document.oncontextmenu = nocontextmenu; // for IE5+
//document.onmousedown = norightclick; // for all others

function nocontextmenu() {
    if (getSelectedText() != '' || 'text,textarea'.indexOf(event.srcElement.type) > -1)
        return true;
    else {
//        window.location = window.location;
        return ShowContextmenu();
    } 
}

//function norightclick(e) {
//    if (window.Event) {
//        if (e.which == 2 || e.which == 3)
//            return false;
//    }
//    else
//        if (event.button == 2 || event.button == 3) {
//        event.cancelBubble = true
//        event.returnValue = false;
//        return false;
//    }
//}


//javascript 选择网页文本
//用鼠标选取当前网页中的文本
function getSelectedText() {
	if (window.getSelection) {
		return window.getSelection().toString();
	}
	else if (document.getSelection) {
		return document.getSelection();
	}
	else if (document.selection) {
		return document.selection.createRange().text;
	}
}

//有更简练的写法 
//return window.getSelection ? window.getSelection().toString() : 
//                            document.getSelection ? document.getSelection() :
//                                             document.selection.createRange().text;
//
//上面的代码在firefox下不能选取<input>和<textarea>中的元素 用下面这段代码

//function getTextFiledSelection(e){
//    if(e.selectionStart != undefined && e.selectionEnd != undefined){
//       var start = e.selectionStart;
//       var end = e.selectionEnd;
//       return e.value.substring(start,end);
//    }
//    else return "";
//}
//=====================↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑=========================================

//检测SQL注入及是否为空//岳耀锋 2009年7月31日 
function checkText(txtid)
{
	var textBox_ = document.getElementById(txtid);
	if (checkParamString(textBox_.value) != "") {//检测SQL注入 //解志杰注 2009年6月21日 20:13:07
		alert("查询条件"+checkParamString(textBox_.value));
		return false;
	}
	return true;
}

function CheckValidateBox(textBoxId) {

    var value_ = document.getElementById(textBoxId).value

    if (value_ == "" || value_.length < 5) {
        alert("请输入5位验证码!");
        return false;
    }
    return true;

}
