window.onload = Client_Initialize;
/***************************************鼠标动作函数*******************************************/
function Client_Initialize(){
	document.onmouseover = MouseOver;
	document.onmouseout = MouseOut;
	document.onmousedown = MouseDown;
	document.onmouseup = MouseUp;
	if(window.document.forms.length > 0) AddScript("/Public/Code/Validator.Js")
	try{
		initSelectForm()
	}catch(e){}
}

function AddScript(sUrl){
	var ds = document.getElementsByTagName("SCRIPT")
	for(var i=0;i<ds.length;i++){
		if(ds[i].src==sUrl) return;
	}
	var o = document.createElement("SCRIPT");
	o.src = sUrl;
	//document.getElementsByTagName("head")[0].insertAdjacentElement("afterbegin", o)
	document.getElementsByTagName("head")[0].appendChild(o)
	ds = null;
	o = null;
}

function AddStyle(sUrl){
	var ds = document.getElementsByTagName("LINK")
	for(var i=0;i<ds.length;i++){
		if(ds[i].src==sUrl) return;
	}
	var o = document.createElement("LINK");
	o.rel="stylesheet"
	o.href=sUrl
	o.type="text/css"
	document.getElementsByTagName("head")[0].appendChild(o)
	ds = null;
	o = null;
}

function Print(){
	print()
}

function MouseOver(){
	var srcElement,clsName,chk
	srcElement = window.event.toElement;
	clsName = srcElement.className;
	chk = clsName.substr(0,3)
	switch(chk){
		case "btn":
		case "lnk":
		//case "grd":
			if(clsName.charAt(4)!="4"){
				srcElement._oldClass = clsName
				srcElement.className = chk + "02" + clsName.substring(5)
			}
			break
		default:
			return true
	}
	return false
}

function MouseOut(){
	var srcElement,clsName,chk
	srcElement = window.event.fromElement;
	clsName = srcElement.className;
	chk = clsName.substr(0,3)
	switch(chk){
		case "btn":
		case "lnk":
		//case "grd":
			if(clsName.charAt(4)!="4") 	srcElement.className = srcElement._oldClass
			break
		default:
			return true
	}
	return false
}

function MouseDown(){
	var srcElement,clsName,chk
	if(window.event.button != 1) return true;
	srcElement = window.event.srcElement;
	clsName = srcElement.className;
	chk = clsName.substr(0,3)
	switch(chk){
		case "btn":
		case "lnk":
			if(clsName.charAt(4)!="4"){
				srcElement._dwnClass = clsName;
				srcElement.className = chk + "03" + clsName.substring(5);
			}
			break
/*		//case "grd":
			if(clsName.charAt(4)!="4"){
				clsName = chk + "03" + clsName.substring(5);
				if(!srcElement._dwnstate){
					srcElement._dwnstate = true;
					srcElement._dwnClass = srcElement._oldClass;
					srcElement._oldClass = clsName;
				}else{
					srcElement._dwnstate = false;
					srcElement._oldClass = srcElement._dwnClass;
				}
				srcElement.className = clsName;
			}
			break
*/		default:
			switch(clsName){
				case "inputtime":
					IsCalendarTime = true;
					GetCalendar(srcElement);
					break;
				case "inputdate":
					IsCalendarTime = false;
					GetCalendar(srcElement);
					break;
				default:
					return true
			}
	}
	return false
}

function MouseUp(){
	var srcElement,clsName,chk,lnk,target
	if(window.event.button != 1) return true;
	srcElement = window.event.srcElement;
	clsName = srcElement._dwnClass;
	if(!clsName) clsName = srcElement.className;
	chk = clsName.substr(0,3)
	switch(chk){
		case "btn":
		case "lnk":
			if(clsName.charAt(4)!="4"){
				srcElement.className = clsName;
				lnk = srcElement.getAttribute("href");
				if (lnk==null) break
				if(lnk.indexOf("(")>0){
					eval(lnk);
				}else{
					target = srcElement.getAttribute("target");
					if(target == null) target = "_self";
					window.open(lnk,target);
				}
			}
			break
		//case "grd":
		default:
			return true
	}
	return false
}
/*************************************************************************************************/
function OpenSelectWin(URI){
	loc_x = document.body.scrollLeft+event.clientX-event.offsetX - 50;
	loc_y = document.body.scrollTop+event.clientY-event.offsetY + 20;
//	var sUser = window.showModalDialog(userURL,this,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:460px;dialogHeight:300px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	var childWin = window.open(URI, "NewWin", "scrollbars=1,width=760px,height=500px,top=50px,left=100px");
	childWin.opener = this
	childWin.focus()
}

function UpdateFormSelect(frmId, frmName, sError){
	var theForm = window.document.forms["SelectForm"]
	for(var i = 0;i < theForm.length; i++){
		if(theForm[i].checked){
			var v = theForm[i].value;
			a = v.split(":");
			theForm = window.opener.window.document.forms[0];
			theForm[frmId].value = a[0];
			theForm[frmName].value = a[1];
			window.opener.focus();
			window.opener = null;
			self.close();
			return false;
		}
	}
	alert(sError)
	return false;
}

function CheckUserExist(){
	var theForm,chk
	theForm = window.document.forms["RegForm"]
	chk = theForm["Accounts"].value
	if(chk == ""){
		alert("请输入账号！")
		theForm["Accounts"].focus();
		return false
	}
	window.location.href = theForm.action + "?step=6&Accounts=" + chk + "&Domain=" + theForm["Domain"].value
}

function InitEditForm(){
	var theForm,Parts,Items,Fields,i
	theForm = window.document.forms["PartEditForm"]
	Parts = theForm["PurviewSign"].value
	if(Parts != ""){
		Items = Parts.split("|")
		for(i=0;i<Items.length;i++){
			Fields = Items[i].split("@")
			theForm["PartEdit"].options.add(new Option(Fields[1],Fields[0]))
		}
	}
}

function CloseWindow(){
	self.window.close();
}

function FormKeyDown(formname,i){
	var theForm
	if(typeof(formname) == "object") theForm = formname;
	else theForm = window.document.forms[formname];
	if(window.event.keyCode != 13) return true;
	if(window.event.srcElement.tagName != "INPUT") return true;
	SubmitForm(theForm,i)
	window.event.returnValue = false;
}

function FireEvent(divEvent,evtName)
{
    var evt = document.createEventObject();
    evt.button = 2;
    evt.type = evtName;
    var rect = divEvent.getBoundingClientRect();
    evt.offsetX = (rect.right + rect.left)/2;
    evt.offsetY = (rect.bottom - rect.top)/2;
    divEvent.fireEvent(evtName, evt);
}

function SubmitForm(formname,i){
	var theForm
	window.event.cancelBubble = true;
	if(typeof(formname) == "object") theForm = formname
	else theForm = window.document.forms[formname]
	if(Validator.Validate(theForm,i)){
		theForm.onsubmit = BlockSubmit;
		theForm.submit()
		return true;
	}
	window.event.returnValue = false;
}

function CheckForm(formname,i){
	var theForm
	window.event.cancelBubble = true;
	if(typeof(formname) == "object") theForm = formname
	else theForm = window.document.forms[formname]
	if(Validator.Validate(theForm,i)){
		theForm.onsubmit = BlockSubmit;
		return true;
	}
	window.event.returnValue = false;
	return false
}

function ResetForm(formname){
	var theForm
	if(typeof(formname) == "object") theForm = formname
	else theForm = window.document.forms[formname]
	var count = theForm.elements.length;
	for(var i = 0;i < count;i++) Validator.ClearState(theForm.elements[i]);
	theForm.reset()
}

function BlockSubmit(){
	window.event.cancelBubble = true;
	alert("您已提交过表单了！");
	window.event.returnValue = false;
}

function PromptInfo(msg,href){
	if(window.confirm(msg)) 	window.location.href = href
}

function AddEditPart(){
	userURL = "/public/selectpart.asp?st=2";
	loc_x=document.body.scrollLeft+event.clientX-event.offsetX - 200;
	loc_y=document.body.scrollTop+event.clientY-event.offsetY - 80;
	Parts = window.showModalDialog(userURL,window,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:390px;dialogHeight:240px;dialogTop:"+200+"px;dialogLeft:"+200+"px");
	if(Parts != ""){
		var theForm = window.document.forms["PartEditForm"]
		Items = Parts.split("|||")
		for(i=0;i<Items.length;i++){
			Fields = Items[i].split("@@@")
			theForm["PartEdit"].options.add(new Option(Fields[1],Fields[0]))
		}
	}
	ModPartValue()
}
function DelEditPart(){
	var theForm = window.document.forms["PartEditForm"]
	var PartObj = theForm["PartEdit"].options
	for(i = 0;i < PartObj.length;i++){
		if(PartObj[i].selected) PartObj.remove(i)
	}
	ModPartValue()
}
function ModPartValue(){
	var theForm = window.document.forms["PartEditForm"]
	var PartObj = theForm["PartEdit"].options
	var Parts = ""
	for (i=0;i< PartObj.length;i++){
		Parts += "|" + PartObj[i].value + "@" + PartObj[i].text
	}
	theForm["PurviewSign"].value = Parts.substring(1)
}

function InitPartForm(){
	var theForm,vParts,Part,Items,i,Fields
	theForm = window.document.forms["SelectPartForm"]
	vParts = theForm["Parts"].value
	if(vParts != ""){
		Items = vParts.split("|||")
		for(i=0;i<Items.length;i++){
			Fields = Items[i].split("@@@")
			theForm["PartEdit"].options.add(new Option(Fields[2] + "(" + Fields[3] + ")",Fields[0]))
		}
	}
}

function SelectPart(n){
	var theForm,pg,sUrl,Parts
	theForm = window.document.forms["SelectPartForm"]
	sUrl = theForm.action + "?kw=" + theForm["kw"].value + "&st=" + theForm["st"].value
	switch(n){
		case 0:
			window.open(sUrl,"_self")
			break
		case 1:
			pg = theForm["pg"].value
			if(pg<1) return
			pg--
			this.location.href = sUrl + "&pg=" + pg
			break
		case 2:
			pg = theForm["pg"].value
			if(pg>=theForm["mg"].value) return
			pg++
			this.location.href = sUrl + "&pg=" + pg
			break
		case 3:
			window.returnValue = ""
			window.close()
			break
		case 4:
			window.returnValue = false
			break
		default:
			Parts = ""
			var PartObj = theForm["PartEdit"].options
			for(i = 0;i < PartObj.length;i++){
				if(PartObj[i].selected){
					Parts = Parts + "|||" + PartObj[i].value + "@@@" + PartObj[i].text
				}
			}
			if(Parts!="") Parts = Parts.substring(3)
			window.returnValue = Parts
			window.close()
			//parent_window = parent.dialogArguments
	}
}
function ShowHideFilterDiv(ftName){
	var filterDiv = document.getElementById(ftName);
	if(filterDiv.style.display == "none"){
		filterDiv.style.display = "block";
	}else{
		filterDiv.style.display = "none";
	}
}
/*-------------------------------------栅格函数--------------------------------------------*/
function GridOver(){
	var po,clsName,chk
	po = window.event.toElement;
	while(po.tagName.toLowerCase() != "tr"){po = po.parentElement}
	clsName = po.className;
	chk = clsName.substr(0,5)
	switch(chk){
		case "grd02":
		case "grd03":
		case "grd04":
		case "grd05":
			po._oldClass = clsName
			po.className = chk.substr(0,4) + "4" + clsName.substring(5)
			break
		default:
			return true;
	}
	return false
}
function GridOut(){
	var po,clsName,chk
	po = window.event.fromElement;
	while(po.tagName.toLowerCase() != "tr"){po = po.parentElement}
	clsName = po.className;
	chk = clsName.substr(0,5)
	switch(chk){
		case "grd02":
		case "grd03":
		case "grd04":
		case "grd05":
			po.className = po._oldClass
			break
		default:
			return true;
	}
	return false
}
function GridDown(){
	var po,clsName,chk
	if(window.event.button != 1) return true;
	po = window.event.srcElement;
	while(po.tagName.toLowerCase() != "tr"){po = po.parentElement}
	clsName = po.className;
	chk = clsName.substr(0,5)
	switch(chk){
		case "grd02":
		case "grd03":
		case "grd04":
			clsName = chk.substr(0,4) + "5" + clsName.substring(5);
			if(!po._dwnstate){
				po._dwnstate = true;
				po._dwnClass = po._oldClass;
				po._oldClass = clsName;
			}else{
				po._dwnstate = false;
				po._oldClass = po._dwnClass;
			}
			po.className = clsName;
			break
		default:
			return true;
	}
	return false
}
/*------------------------------------------------------------------------------*/
function SelectItemAll(formname){
	var theForm = window.document.forms[formname]
	var chkObj = theForm["ItemId"]
	for(i=0;i<chkObj.length;i++){
		if(chkObj[i].checked){
			chkObj[i].checked = false;
		}else{
			chkObj[i].checked = true;
		}
	}
}
/*------------------------显示消息-----------------------------------------*/
function DymancMessage(){
	if(typeof(window._msgbox)!="object"){
		var o = document.createElement("DIV");
		
		
		
		
	}
}





/*-------------------------------上传文件-----------------------------------*/
function UploadImage(sUrl){
	//打开上传对话框
	var childWin = window.open(sUrl)
	childWin.opener = this
}

function UpLoadComplete(sName){
	var obj = window.opener.window.document.all["ImagePreview"]
	if(obj){
		obj.innerHTML = '<img src="/Public/Asp/ImagePreview.asp?Id='+ sName + '" class="UserImage" alt="照片">'
	}
	window.opener.focus()
	self.close()
}

function SelectMember(fn){
	var href = new String(location.href), host = location.host;
	var userURL = href.substr(href.indexOf(host) + host.length + 1)
	userURL = "http://" + host + "/" + userURL.substr(0, userURL.indexOf("/")) + "/include/user_select/index1.asp?fn=" + fn;
	loc_x=document.body.scrollLeft+event.clientX-event.offsetX - 100;
	loc_y=document.body.scrollTop+event.clientY-event.offsetY + 80;
//	var sUser = window.showModalDialog(userURL,this,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:460px;dialogHeight:300px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	var childWin = window.open(userURL,"NewWin","scroll:0;status:0;Width:460px;Height:300px;Top:"+loc_y+"px;Left:"+loc_x+"px");
	childWin.opener = this
	childWin.focus()
}

function SelectMultiMember(fn){
	var href = new String(location.href), host = location.host;
	var userURL = href.substr(href.indexOf(host) + host.length + 1)
	userURL = "http://" + host + "/" + userURL.substr(0, userURL.indexOf("/")) + "/include/user_select/index2.asp?fn=" + fn;
	loc_x=document.body.scrollLeft+event.clientX-event.offsetX - 100;
	loc_y=document.body.scrollTop+event.clientY-event.offsetY + 80;
//	var sUser = window.showModalDialog(userURL,this,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:460px;dialogHeight:300px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	var childWin = window.open(userURL,"NewWin","scroll:0;status:0;Width:460px;Height:300px;Top:"+loc_y+"px;Left:"+loc_x+"px");
	childWin.opener = this
	childWin.focus()
}

function OpenSelectPerson(formId, formName, isMore, sUrl){
	var href = new String(location.href), host = location.host;
	var userURL = href.substr(href.indexOf(host) + host.length + 1)
	userURL = "http://" + host + "/" + userURL.substr(0, userURL.lastIndexOf("/") + 1) + sUrl + "?formId=" + formId + "&formName=" +formName + "&isMore=" + isMore ;
	loc_x=document.body.scrollLeft+event.clientX-event.offsetX - 100;
	loc_y=document.body.scrollTop+event.clientY-event.offsetY + 80;
//	var sUser = window.showModalDialog(userURL,this,"edge:raised;scroll:0;status:0;help:0;resizable:1;dialogWidth:460px;dialogHeight:300px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px");
	var childWin = window.open(userURL, "NewWin","scroll:0;status:0;Width:460px;Height:300px;Top:"+loc_y+"px;Left:"+loc_x+"px");
	childWin.opener = this
	childWin.focus()
}

function SelectComplete(v){
	var a = v.split(":")
	var fn = a[0]
	document.all[fn].value = a[2]
	this.window.focus()
}
function Add_user(v){
	var a = v.split(":")
	var fn = a[0]
	var oldvalue = document.all[fn].value;
    newvalue = a[2];
    if(oldvalue != ""){
        var arr = oldvalue.split(",");
        for(var i = 0; i < arr.length; i++){
            if(arr[i] == newvalue) return false;
        };
        document.all[fn].value = oldvalue + "," + newvalue;
    }else document.all[fn].value = newvalue;
}
