function RGUtil() { }
/**
 * 
 * @see http://getahead.ltd.uk/dwr/browser/util/useloadingmessage
 */
RGUtil.useLoadingMessage = function(message) {
  var loadingMessage;
  if (message) loadingMessage = message;
  else loadingMessage = "Loading";
  var disabledZone = $('disabledZone');
  if (!disabledZone) {
    disabledZone = document.createElement('div');
    disabledZone.setAttribute('id', 'disabledZone');
    disabledZone.style.position = "absolute";
    disabledZone.style.zIndex = "1000";
    disabledZone.style.left = "0px";
    disabledZone.style.top = "0px";
    disabledZone.style.width = "100%";
    disabledZone.style.height = "100%";
    document.body.appendChild(disabledZone);
    var messageZone = document.createElement('div');
    messageZone.setAttribute('id', 'messageZone');
    messageZone.style.position = "absolute";
    messageZone.style.top = "0px";
    messageZone.style.right = "0px";
    messageZone.style.background = "red";
    messageZone.style.color = "white";
    messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";
    messageZone.style.padding = "4px";
    disabledZone.appendChild(messageZone);
    var text = document.createTextNode(loadingMessage);
    messageZone.appendChild(text);
  }
  else {
    $('messageZone').innerHTML = loadingMessage;
    disabledZone.style.visibility = 'visible';
  }
}

//
RGUtil.popCenter = function(url,w,h){
    x=w;
    y=h;
    l=(screen.width/2)-(x/2);
    t=(screen.height/2)-(y/2);
    s="toolbar=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes";
    s+=" width=" + x + ", height=" + y + ", left=" + l + ", top=" + t;
    MRV=window.open(url,"",s);
}

//
RGUtil.subValidForm=function(dForm,ftype){
	if(Validator.Validate(dForm,ftype)){
		dForm.submit();
	}
}
//
RGUtil.editR = function(dForm,url,w,h){
	var felements=dForm.elements;
	var id;
	var count=0;
	var popurl;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				id=felements[i].value;
				count++;				
			}
			if(count>1){
				alert('对不起，只能选择一条记录！！');
				return;
			}
		}
	}
	if(count<=0){
		alert('对不起,请选择一条记录！！');
		return;
	}else{
		popurl=url+id;
		//alert(popurl);
		RGUtil.popCenter(popurl,w,h);	
	}
}

//
RGUtil.deleteR = function(dForm,url,w,h){
	var felements=dForm.elements;
	var ids='';
	var count=0;
	var popurl;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				ids+=felements[i].value+',';
				count++;				
			}

		}
	}
	if(count<=0){
		alert('对不起，请至少选择一条记录！！');
		return;
	}else{
		popurl=url+ids;
		if(confirm('您确定要删除这　'+count+'　条记录吗？')){
			RGUtil.popCenter(popurl,w,h);
		}			
	}
}




//
RGUtil.operateR = function(dForm,url,w,h,msg){
	var felements=dForm.elements;
	var ids='';
	var count=0;
	var popurl;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				ids+=felements[i].value+',';
				count++;				
			}

		}
	}
	if(count<=0){
		alert('对不起，请至少选择一条记录！！');
		return;
	}else{
		popurl=url+ids;
		if(confirm('您确定要'+msg+'这　'+count+'　条记录吗？')){
			RGUtil.popCenter(popurl,w,h);
		}			
	}
}

//
RGUtil.operateE = function(felements,url,w,h,msg){

	var ids='';
	var count=0;
	var popurl;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				ids+=felements[i].value+',';
				count++;				
			}
		}
	}
	if(count<=0){
		alert('对不起，请至少选择一条记录！！');
		return;
	}else{
		popurl=url+ids.substring(0,ids.length-1);
		if(confirm('您确定要'+msg+'这　'+count+'　条记录吗？')){
			RGUtil.popCenter(popurl,w,h);
		}			
	}
}


RGUtil.operateSelect=function(dForm,url,w,h,msg){
	var felements=dForm.elements;
	var id;
	var count=0;
	var popurl;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				id=felements[i].value;
				count++;				
			}
			if(count>1){
				alert('对不起，只能选择一条记录！！');
				return;
			}
		}
	}
	if(count<=0){
		alert('对不起,请选择一条记录！！');
		return;
	}else{
		popurl=url+id;
		if(confirm(msg)){
			RGUtil.popCenter(popurl,w,h);	
		}	
	}
}
//	
RGUtil._selectFCount = function(dForm){
	var felements=dForm.elements;
	var count=0;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				count++;				
			}
		}
	}	
	return count;
}

RGUtil.selectListItem = function(ele, val) {
  // We deal with select list elements by selecting the matching option
  // Begin by searching through the values
  var found  = false;
  var i;
  for (i = 0; i < ele.options.length; i++) {
    if (ele.options[i].value == val) {
      ele.options[i].selected = true;
      found = true;
    }
    else {
      ele.options[i].selected = false;
    }
  }

  // If that fails then try searching through the visible text
  if (found) return;

  for (i = 0; i < ele.options.length; i++) {
    if (ele.options[i].text == val) {
      ele.options[i].selected = true;
    }
    else {
      ele.options[i].selected = false;
    }
  }
}

RGUtil.goToPage=function(goPage){
	var page=document.getElementById("pageNo");
	page.value=goPage;
	var pageSubControlForm=document.getElementById("pagerform");
	pageSubControlForm.submit();
}

RGUtil.setPageNo=function(goPage){
	var page=document.getElementById("pageNo");
	page.value=goPage;
}

RGUtil.checkKeyPress=function(submitId){
	if(event.keyCode==13){
		document.getElementById(submitId).click();		
	}
}

//全选
RGUtil.checkAll=function(dForm){
	var felements=dForm.elements;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			felements[i].checked=true;
		}
	}
}
//反选
RGUtil.checkReverse=function(dForm){
	var felements=dForm.elements;
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'||felements[i].type=='radio'){
			if(felements[i].checked==true){
				felements[i].checked=false;
			}else{
				felements[i].checked=true;
			}
		}
	}	
}
//多选
RGUtil.setSelectCheckBox=function(sName,svalue){
	var objArr=svalue.split(',');
	var objboxArr=document.getElementsByName(sName);
	for(i=0;i<objboxArr.length;i++){
		for(j=0;j<objArr.length;j++){
			if(objboxArr[i].value==objArr[j]){
				objboxArr[i].checked=true;
				break;
			}	
		}
	}
}
RGUtil.maskKeyPress=function(objEvent){
	var reValidChars = /\d/;
	var iKeyCode, strKey;
	iKeyCode = objEvent.keyCode;
	strKey = String.fromCharCode(iKeyCode);
	if (!reValidChars.test(strKey)) {
		return false;
	}	
}
function alertDialog(originalRequest){
	Dialog.alert(originalRequest.responseText,{className: "alphacube",okLabel:"确定"});
}
function delData(url){
	var felements=document.forms[1].elements;
	var ids="";
	var count=0;
	//var url="opCardInfo.do";
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'){
			if(felements[i].checked==true){
				ids+=felements[i].value+',';
				count++;
			}
		}
	}
	if(count<=0){
		alert('对不起，请至少选择一条记录！！');
		return;
	}else{
		var param="action=delete&ids="+ids;
		if(confirm('您确定要将这　'+count+'　条记录设为暂存状态吗？')){
			//利用AJAX来删除
			var myAjax=new Ajax.Request(url,{method:'post',parameters:param,onComplete:function(originalRequest){alert(originalRequest.responseText);document.forms[2].submit();}});
		}
	}
}
function resumeData(url){
	var myAjax=new Ajax.Request(url,{method:'post',onComplete:function(originalRequest){alert(originalRequest.responseText);document.forms[2].submit();}});
}
function resumeData2(url){
	var felements=document.forms[1].elements;
	var ids="";
	var count=0;
	//var url="opCardInfo.do";
	for(i=0;i<felements.length;i++){
		if(felements[i].type=='checkbox'){
			if(felements[i].checked==true){
				ids+=felements[i].value+',';
				count++;
			}
		}
	}
	if(count<=0){
		alert('对不起，请至少选择一条记录！！');
		return;
	}else{
		var param="action=resume2&ids="+ids;
		if(confirm('您确定要恢复这　'+count+'　条记录的状态吗？')){
			//利用AJAX来删除
			var myAjax=new Ajax.Request(url,{method:'post',parameters:param,onComplete:function(originalRequest){alert(originalRequest.responseText);document.forms[2].submit();}});
		}
	}	
	
}