function Jtrim(str) {
    var i = 0;
    var len = str.length;
    if (str == "") {
        return (str);
    }
    j = len - 1;
    flagbegin = true;
    flagend = true;
    while (flagbegin == true && i < len) {
        if (str.charAt(i) == " ") {
            i = i + 1;
            flagbegin = true;
        } else {
            flagbegin = false;
        }
    }
    while (flagend == true && j >= 0) {
        if (str.charAt(j) == " ") {
            j = j - 1;
            flagend = true;
        } else {
            flagend = false;
        }
    }
    if (i > j) {
        return ("");
    }
    trimstr = str.substring(i, j + 1);
    return trimstr;
}
function textFocus(id){
	document.getElementById(id).focus();
}
String.prototype.trim = function()
{
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;
}
/**
* ibframe paginate method 
*/

function callPaginate(formId,pageIndex){
	var form=$(formId);
	try{
	if(form){
	var e=document.createElement("input")
		e.name="paginate.pageIndex";
		e.type="hidden";
		e.value=pageIndex;
		form.appendChild(e);
		form.submit();
	}else{
		alert("查询Form的id不存在"+formId);
	}
	}catch(e){
		throw e;
	}
}

function selectedAll(self,name){
	var objs=document.getElementsByName(name);
	if(self&&self.checked){
		for(var i=0;i<objs.length;i++){
			objs[i].checked=true;
		}
	}else{
		for(var i=0;i<objs.length;i++){
			objs[i].checked=false;
		}
	}
}

function selectedReverse(name){
		var objs=document.getElementsByName(name);
		for(var i=0;i<objs.length;i++){
			if(!objs[i].checked){
			objs[i].checked=true;
			}else{
			objs[i].checked=false;
			}
		}

}

function deleteObject(formId,ids){
	var objs=document.getElementsByName(ids);
	var selected=false;
	for(var i=0;i<objs.length;i++){
		if(objs[i].checked){
			selected=true;
		}
	}
	if(!selected){
		alert("请选择要删除的数据！");
		return;
	}
	if(confirm("确认要删除选择的数据？")){
		if(confirm("再次确认要删除的数据")){
		var form=$(formId);
		form.method="post";
		form.submit();
		}
	}
	
}

function validateUnique(self, actionUri, params, spanId, text1, text2){
    //alert(actionUri);
    if (self.value.trim().length == 0) {
        Element.Methods.update(spanId, "&nbsp;&nbsp;<font style='color:#ea6554'>●&nbsp;不能为空</font>");
        self.style.border = "1px solid #ea6554"
    }
    else {
        new Ajax.Request(actionUri, {
            method: 'post',
            parameters: params,
            onComplete: validateDealWith,
            onLoading: function(){
                "loading";
            },
            onLoaded: function(){
                "onLoaded";
            }
        });
		
        function validateDealWith(obj){
			
            if (eval("(" + obj.responseText + ")").returnValue == true) {
                Element.Methods.update(spanId, "&nbsp;&nbsp;<font style='color:45ea45'>●&nbsp;" + text1 + "</font>");
                self.style.border = "1px solid #45ea45";
            }
            else {
                Element.Methods.update(spanId, "&nbsp;&nbsp;<font style='color:#ea6554'>●&nbsp;" + text2 + "</font>");
                self.style.border = "1px solid #ea6554"
                self.select();
                self.focus();
            }
        }
    }
}



//取时间部分
function dtGetTimeString(format) {
  ptr = format.indexOf("%"); old = 0; time="";
  while(ptr != -1) {
    ch = format.charAt(ptr+1);
    time += format.substring(old,ptr) + dtGetFormat(ch);
    old = ptr+2;
    ptr = format.indexOf("%",old);
  }
  time += format.substring(old,format.length);
  return time;
}

function dtSetDigits(num, howmany) {
  str = num.toString();
  if (str.length >= howmany) return str;
  for (i = str.length; i < howmany; i++) str = "0" + str;
  return str;
}

function dtGetFormat(ch) {
  now = new Date();
  if(ch=='h') {
    hour = now.getHours();
    if(hour == 0) { hour = 12; }
    else if (hour > 12) { hour -= 12; }
    return hour; }
  else if(ch=='H') { return now.getHours(); }
  else if(ch=='m') { return dtSetDigits(now.getMinutes(),2); }
  else if(ch=='s') { return dtSetDigits(now.getSeconds(),2); }
  else if(ch=='d') { return now.getDate(); }
  else if(ch=='D') {
    dayArray = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
    return dayArray[now.getDay()]; }
  else if(ch=='w') { return now.getMonth()+1; }
  else if(ch=='W') {
	 monArray = new Array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
	 return monArray[now.getMonth()]; }
  else if(ch=='y') {
    return ((now.getYear() <= 99) ? now.getYear() : dtSetDigits(now.getYear()-2000,2));}
  else if(ch=='Y') {
    return ((now.getYear() <= 99) ? "19"+now.getYear() : now.getYear());}
  else if(ch=='a') {
    if(now.getHours() == 0 || now.getHours() > 11) return "PM";
    else return "AM"; }
  else return "";
}
function dtChangeText(id, str) {
  if(document.layers) { // if Navigator 4.0+
    with(document[id].document) {
      open();
      write(str);
      close();
    }
  } else { // Internet Explorer 4.0+
    document.all[id].innerHTML = str;
  }
}

function dtStartClock(id,format) {
  ClockID = setInterval(function(){dtChangeText(id,dtGetTimeString(format))},500)
}
function dtGetClockCombo(id,format){
if(document.all||document.layers) dtStartClock(id,format);
}
//取时间结束
//返回焦点
function textFocus(id){
	document.getElementById(id).value="";
	document.getElementById(id).focus();
}
function  isEmail(mail){     
 return(new   RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));     
}
function   isTel(ui){   
   var   valid=/(^0\d{2,3}\-\d{7,8}$)|(^[0-9]{8}$)|(^1\d{10}$)/;   
   return   (valid.test(ui));
}

function showLabelInCenter(id,display){
		var label=$(id);
		var height=Element.Methods.getHeight(id);
		var width=Element.Methods.getWidth(id);
		var layoutHeight=document.body.clientHeight;
		if(layoutHeight==0){
			layoutHeight=750;
		}
		label.style.position="absolute";
		label.style.left=(document.body.clientWidth-width)/2;
		label.style.top=(layoutHeight-height)/2-45;
		if(display){
		label.style.display="block";
		}
}
function setDocBodyMaxSize(id,display){
	var label = $(id);
	var height = document.body.offsetHeight ;//+ document.body.scrollHeight;
	var width = document.body.offsetWidth;
	if(height<=10 || height==null){
		height = 750;
	}
	label.style.position="absolute";
	label.style.left="0";
	label.style.top="0";
	if(display){
	label.style.display="block";
	}
	label.style.height=height;
	label.style.width=width;	
}

///判断是否为中文名
 function chineseName(name){
		if ((/.*[\u4E00-\u9FA5 ].*/.test(document.getElementById(name).value))) {
			alert("登录名称不允许有汉字！");
			document.getElementById(name).value = "";
			return false;
		}
		return true;
	}
//判断用户名或密码的最大长度
function maxLen(str, n, name){
    var str1 = document.getElementById(str).value;
    var strLen = document.getElementById(str).value.length;
    if (strLen > n) {
        alert(name + "字符过长！");
        document.getElementById(str).value = str1.substring(0, strLen - 1);
        return true;
    }
    return false;
}
 ///判断用户名或密码的最小长度 
 function minLen(str, n, name){
     var str1 = document.getElementById(str).value;
     var strLen = document.getElementById(str).value.length;
     if (strLen < n) {
         alert(name + "字符过短！");
         return true;
     }
     return false;
 }
 //鼠标放上颜色变换
 function overIt(){
   var the_obj = event.srcElement;
   if(the_obj.tagName.toLowerCase() == "td"){
       the_obj=the_obj.parentElement;
       the_obj.oBgc=the_obj.currentStyle.backgroundColor;    
	   the_obj.oFc=the_obj.currentStyle.color;
       the_obj.style.backgroundColor='#fefe97';
        the_obj.style.cursor='hand';
   }
}
//鼠标移走的
function outIt(){
   var the_obj = event.srcElement;
   if(the_obj.tagName.toLowerCase() == "td"){
       the_obj=the_obj.parentElement;
       the_obj.style.backgroundColor=the_obj.oBgc;
       the_obj.style.color=the_obj.oFc;
   }
}