﻿var path = "";

//屏蔽鼠标右键
//window.document.oncontextmenu=function()
//{
//    return(false);
//}
////屏蔽F5和Ctrl+R
//window.document.onkeydown=function()
//{
//    if(event.keyCode==116 || (event.ctrlKey&&event.keyCode==82)){
//        event.keyCode=0;
//        return(false);
//    }
//}

//通过模拟点击某按钮或者重置Location刷新窗口
function RefreshPage(objid)
{
    var obj;
    if(typeof(objid)!="undefined"){
        obj=getObject(objid);
    }
    if(obj!=null && obj.onclick){
        obj.onclick();
    }
    else{
        var url=window.location.href;
        var tmp=url.substring(url.length-1,url.length);
        if(tmp=="#"){
            url=url.substring(0,url.length-1);
        }
        window.location=url;
        window.focus();
    }

}
function RefreshParentPage(objid)
{//alert("RefreshParentPage");
    if(window.opener!=null && typeof(window.opener)!="undefined"){
        try
        {
            window.opener.setTimeout("RefreshPage('"+objid+"')",10);
        }
        catch(e)
        {
            //window.close();
        }
    }
}
//去除字符串两端空格
String.prototype.Trim=function()
{
    return this.replace(/^\s+|\s+$/,"");
}
//去除字符串左端空格
String.prototype.LTrim=function()
{
    return this.replace(/^\s+/,"");
}
//去除字符串右端空格
String.prototype.RTrim=function()
{
    return this.replace(/\s+$/,"");
}
//按回车后模拟点击指定控件
function KeyPress2Submit(targetbtnid){
    if(event.keyCode==13){
        document.getElementById(targetbtnid).click();
    }
}
//打开新窗口
function openNewWin(url,winName,width,height,attribute){
	
	if(attribute==null) attribute="";
	if(winName==null) winName="";
	if(width==null) width="600";
	if(height==null) height="400";
	var tyWin=window.open(url,winName,'width='+width+'px height='+height+'px left=' + (screen.availWidth-width )/2 + ' top=' + (screen.availheight-height )/2 + ' '+attribute);
	tyWin.focus();
}
function OpenNewWin(url,winName,width,height,attribute){
    openNewWin(url,winName,width,height,attribute);
}
//关闭窗口
function Close(confirm,message){
  var mess="确定要关闭窗口吗?";
  if(confirm!=null && confirm==true){
	if(message!=null && message.length>0){
		mess=message;
	}
	if(!window.confirm(mess)){
		return;
	}
  }
  CloseWithoutConfirm();
}
//删除确认
//DuiXingMC 要删除对象的名称
//DuiHuaID  要执行删除的对话数据组的ID
function  ConfirmBeforeDelete(DuiXingMC,DuiHuaID)
{ 
    for(var i=0;i<document.getElementById("_qam_rowcount_"+ DuiHuaID ).value;i++)
    {
    //debugger;
        var id="_qam_del_check_"+ DuiHuaID +"_"+i;
        if(document.getElementById(id).disabled)
        {
            continue;
        }else if(document.getElementById(id).checked)
        {
            return window.confirm("您确定要删除所选"+DuiXingMC+"？");
        }
    }
    alert("您未选择任何"+DuiXingMC+"！");
    return false;
}
function DoClose(){
    Close(true,null);
}
//不提示直接关闭窗口
function CloseWithoutConfirm(){
	window.opener=null;
	window.close();
}
//刷新页面
function Refresh(){
    this.location=this.location;
}
//刷新父窗口
function RefreshOpener(){
    if(window.opener!=null && typeof(window.opener)!="undefined"){
        window.opener.location=window.opener.location;
    }
}
function MaxWin(){
         if (top.location.href == window.location.href && window.location.href.indexOf("no_full_screen") == -1 )
         {
          self.moveTo(-4,-4);
          self.resizeTo((screen.availWidth+8),(screen.availHeight+8));
         }
}
//不允许当前页面在框架页内
function KeepTop(){
    if(this.location!=top.location){
        top.location=this.location;
    }
}
//改变行状态
function changeRowState(i,rowStateId){	
        //alert(getObject(rowStateId+"_"+i).value);
		if(getObject(rowStateId+"_"+i).value=="n"){
			getObject(rowStateId+"_"+i).value = "u";
		}
		else if(getObject(rowStateId+"_"+i).value==""){
			getObject(rowStateId+"_"+i).value = "i";
		}	
		//alert(getObject(rowStateId+"_"+i).value);
}
//删除
function changeRowDel(obj,i,rowStateId,stateValue){	
		if(typeof(stateValue)=="undefined")
			stateValue = "u";
		if(obj.checked)
			getObject(rowStateId+"_"+i).value="u";
		else
			getObject(rowStateId+"_"+i).value=stateValue;
		
}
//全选并改变行状态
function selAllDelCheck(obj,rowStateId,delId,groupId,stateValue){	
    
       if(typeof(stateValue)=="undefined")
			stateValue = "u";
			
		var rowCount = getObject("_qam_rowcount_"+groupId).value;
		if(obj.checked){
			for(var i=0;i<rowCount;i++){
                if(!getObject(delId+i).disabled){
					getObject(rowStateId+"_"+i).value = "u";
					getObject(delId+i).checked=true;
				}				
			}
		}
		else{
			for(var i=0;i<rowCount;i++){          
            if(!getObject(delId+i).disabled){
					getObject(rowStateId+"_"+i).value = stateValue;
					getObject(delId+i).checked=false;
				}				
			}
		}
}
//全选
function selAllCheck(obj,childId,groupId){	
		var rowCount = getObject("_qam_rowcount_"+groupId).value;
		if(obj.checked){
			for(var i=0;i<rowCount;i++){
				var childObj = getObject(childId+"_"+i);
				if(childObj.disabled){
					continue;
				}
				childObj.checked = true;					
			}
		}
		else{
			for(var i=0;i<rowCount;i++){
				var childObj = getObject(childId+"_"+i);
				if(childObj.disabled){
					continue;
				}
				childObj.checked = false;
						
			}
		}
}
//加行
function insertTable(tb,str){
	var o=document.createElement("div"),ol;
	o.innerHTML="<table>"+str+"</table>";
	ol=o.childNodes[0].tBodies[0].rows;
	for(var i=0;i<ol.length;i++){
	    tb.tBodies[0].appendChild(ol[i]);
	}
}
//定位
function SetPosition (obj,pos){
	var ttop  = obj.offsetTop;     
	var thei  = obj.clientHeight;  
	var tleft = obj.offsetLeft;   

	while (obj = obj.offsetParent){
		ttop+=obj.offsetTop;
		tleft+=obj.offsetLeft;
	}

	pos[0] = window.screenLeft + tleft - 1  -document.body.scrollLeft;
	pos[1] = window.screenTop + ttop + thei + 2 - document.body.scrollTop;

	var st = window.screen.height - pos[2] - 33;
	if (pos[1]> st) pos[1] = st;
}

//获取对象
function getObject(objectid){
	return document.getElementById(objectid);
}
//获取虚拟目录
function getContextPath(){
    if(getObject("__ContextPath")){
        var ctxpath=getObject("__ContextPath").value;
        if(ctxpath.length>1 && "/"==ctxpath.substring(0,1)){
            path=ctxpath;
        }
    }
    return path;
}
function DoActionToChildren(obj,action){
    if(action!=null && typeof(action)=='function'){
        for(var i=0;i<obj.childNodes.length;i++){
            action(obj.childNodes[i]);
            DoActionToChildren(obj.childNodes[i],action);
        }
    }
}
//点选
function SelectValue(objId,targets,url,width,height){
	if(targets==undefined)
		return;
	if(width==undefined)
		width=600;
	if(height==undefined)
		height=500;
	var pos = [0,0,height,width];
	SetPosition(getObject(objId),pos);
	var x = pos[0];
	var y = pos[1];
	var h = pos[2];
	var w = pos[3];
    //window.open(url);
    //return;
	var ReturnValues =window.showModalDialog(url,"select",'dialogWidth=' + (w) +'px;dialogHeight=' + (h) + 'px;status:0;resizable:yes;');
	
	if(ReturnValues!=undefined && ReturnValues!=null){		
		for(var i=0;i<targets.length;i++){
			var targetObj = targets[i];
			for(var j=0;j<ReturnValues.length;j++){
				var returnObj = ReturnValues[j];
				if(targetObj[0]==returnObj[0]){
					var obj = getObject(targetObj[1]);
					if(typeof(obj) == 'object'){
						obj.value =returnObj[1];
						obj.fireEvent("onchange");
					}
				}
			}
		}
	}
}
//======================================================================
//时间点选
function SetDateValue(obj,s){
    if(obj.className=="DataPicker"){
        return;
    }
	var v = [obj.value,s];
	var pos = [0,0,230,185];
	SetPosition(obj,pos);
	var x = pos[0];
	var y = pos[1];
	var h = pos[2];
	var w = pos[3];
	
	if (typeof(obj) == 'object')
	{
		var result = window.showModalDialog(getContextPath()+'/common/page/Calendar.html',v,'dialogleft=' + (x) + 'px;dialogtop=' + (y) + 'px;dialogWidth=' + (w) + 'px;dialogHeight=' + (h) + 'px;status:0');
		if (result != undefined) {
			obj.value = result;
		}
	}
}

//=================================Tab Control ====================
function TabSelectedChange(prefix,index,TabCount){
	//前缀，当前tab索引，总tab数量
	//onclick="TabSelectedChange('QWebTab',0,3);"   onmouseover="JScript:this.className='movetab';"  onmouseout="JScript:this.className='outtab';"  onmousedown="JScript:this.className='clicktab';"   onmouseup="JScript:this.className='outtab';"
	for(var i=0;i<TabCount;i++){
	    var str=prefix+i;
	    var o=getObject(str);
	    var selObj=getObject(prefix+"SelectedIndex");
	    if(i==index){
	        o.className="clicktab";
	        getObject(prefix+"Content"+i).style.display="";
	        if(selObj!=null) selObj.value=index;
	    }else{
	        o.className="outtab";
	        getObject(prefix+"Content"+i).style.display="none";
	    }
	}
	return false;
}
//不改变样式
function TabChange(prefix,index,TabCount){
	//前缀，当前tab索引，总tab数量
	//onclick="TabSelectedChange('QWebTab',0,3);"   onmouseover="JScript:this.className='movetab';"  onmouseout="JScript:this.className='outtab';"  onmousedown="JScript:this.className='clicktab';"   onmouseup="JScript:this.className='outtab';"
	for(var i=0;i<TabCount;i++){
	    var str=prefix+i;
	    var o=getObject(str);
	    var selObj=getObject(prefix+"SelectedIndex");
	    if(i==index){
	        getObject(prefix+"Content"+i).style.display="";
	        if(selObj!=null) selObj.value=index;
	    }else{
	        getObject(prefix+"Content"+i).style.display="none";
	    }
	}
	return false;
}
function ResetTabPage(prefix,index,TabCount){
    if(index==null || index.length<=0){
        index=0;
    }
    TabSelectedChange(prefix,index,TabCount);
}
//改变Tab页样式
function ChangeTabStyle(obj){
    if(obj.className='clicktab'){
        obj.className='outtab';
     }
     else
     {
      obj.className='clicktab';
      }
}
//===========================
//生成XMLDOM对象
function createXMLDOM(){ 
	var xmldom;
	if (window.ActiveXObject){
		xmldom = new ActiveXObject("Microsoft.XMLDOM");
	} else {
		if (document.implementation && document.implementation.createDocument) {
			xmldom = document.implementation.createDocument("","doc",null);
		}
	}
	xmldom.async = false;
	xmldom.resolveExternals = false;
	xmldom.validateOnParse = false;
	xmldom.preserveWhiteSpace = true;
	return xmldom;
}
function UrlEncode(str){ 
  var ret=""; 
  var strSpecial="!\"#$%&()*+,/:;<=>?[]^`{|}~%"; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    tt += chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
} 
function UrlDecode(str){ 
  var ret=""; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    if(chr == "+"){ 
      ret+=" "; 
    }else if(chr=="%"){ 
     var asc = str.substring(i+1,i+3); 
     if(parseInt("0x"+asc)>0x7f){ 
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
      i+=5; 
     }else{ 
      ret+=asc2str(parseInt("0x"+asc)); 
      i+=2; 
     } 
    }else{ 
      ret+= chr; 
    } 
  } 
  return ret; 
} 
/*
*   当鼠标经过对象时设置背景色
*/
var Self_LastColor="";
var Self_LastClass="";
function RowMouseOver(obj)
{
    Self_LastColor=obj.style.backgroundColor;
    Self_LastClass=obj.ClassName;
    //obj.style.color="#0000ff";
    //obj.style.textDecoration = "underline";
    //obj.style.backgroundColor="#feeeee";
    obj.className="MouseOver";
}
/*
*   当鼠标离开对象时设置背景色
*/
function RowMouseOut(obj)
{
    //obj.style.backgroundColor=Self_LastColor;
    obj.className=Self_LastClass;
    //obj.style.color="";
    //obj.style.textDecoration = "";
}
