function disp_something(str){
	var obj=document.all(str);
	if(obj){
		if(obj.style.display==""){
			obj.style.display="none";
		}else if(obj.style.display=="none"){
			obj.style.display="";
		}
	}
}

function NewForm(newhtml,strWidth,strHeight){
	var wLeft,wTop,newName,wWidth,wHeight;

	if (parseInt(strWidth)>0)	wWidth = parseInt(strWidth);
	else	wWidth = 860;

	if (parseInt(strHeight)>0)	wHeight = parseInt(strHeight);
	else	wHeight = 600;

	wLeft = (screen.width - wWidth)/2;
	wTop = (screen.height - wHeight)/2;

	//newName =newhtml.substring(0,newhtml.length-4);
	newwindow=window.open(newhtml,newName,'height='+wHeight+',width='+wWidth+',top='+wTop+',left='+wLeft+',status=0,toolbar=0,menubar=0,location=0,resizable=0,scrollbars=0');
	newwindow.focus()
}

function encodeData(a)
{
    if (encodeURIComponent)
        return encodeURIComponent(a);
    if (escape)
    	return escape(a)
}

function NewWindow(newhtml,strWidth,strHeight){
	var wLeft,wTop,newName,wWidth,wHeight;

	if (parseInt(strWidth)>0)	wWidth = parseInt(strWidth);
	else	wWidth = 800;

	if (parseInt(strHeight)>0)	wHeight = parseInt(strHeight);
	else	wHeight = 600;

	wLeft = (screen.width - wWidth)/2;
	wTop = (screen.height - wHeight)/2;

	//newName = newhtml.substring(0,newhtml.length-4);

	newwindow=window.open(newhtml,newName,'height='+wHeight+',width='+wWidth+',top='+wTop+',left='+wLeft+',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=1');
	newwindow.focus()
}


function NewModalForm(newhtml,strWidth,strHeight){
	var wLeft,wTop,newName,wWidth,wHeight;

	if (parseInt(strWidth)>0)	wWidth = parseInt(strWidth);
	else	wWidth = 600;

	if (parseInt(strHeight)>0)	wHeight = parseInt(strHeight);
	else	wHeight = 400;

	//newName = newhtml.substring(0,newhtml.length-4);

	showModalDialog(newhtml,window,'dialogHeight:'+wHeight+'px;dialogWidth:'+wWidth+'px;center:yes;help:no;resizable:no;status:no');
}

function CheckChecked(form){
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall'&& e.type=="checkbox" && e.checked)
     return true;
    }

   return false;
}

function CheckAll(){
	for (var i=0;i<document.forms[0].elements.length;i++){
		var e = document.forms[0].elements[i];
		if (e.name != 'chkall'&& e.type=="checkbox" && e.name=='chkitem'){
			e.checked = document.forms[0].chkall.checked;
			if(e.onclick==null)
				e.onclick=function(){unCheckSingle(document.forms[0])};
		}

	}
}

function unCheckSingle(form) {
	for (var i = 0;i < form.elements.length; i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall' && e.type=="checkbox" ) {
			if (e.checked == 0) {
				form.chkall.checked = 0;
				return;
			}
		}
	}
	form.chkall.checked=1;
}

function IpCheck(ip){
	var ipValue = ip.value;
	var reg = /^\d{1,3}(\.\d{1,3}){3}$/;
	if(reg.test(ipValue)){
		var ary = ipValue.split('.');
		for(key in ary){
			if(parseInt(ary[key]) > 255){
				ip.focus();
				return false;
			}
		}
	}else{
		ip.focus();
		return false;
	}
	return true;
}

function strLen(str){
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++) {
		if (str.charCodeAt(i)>255)
			len+=2;
		else
			len++;
	}
	return len;
}
function doSort(order,actionMethod,orderType){
	if(order != ""){
		document.forms[0].order.value=order;
	}
	document.forms[0].actionMethod.value=actionMethod;
	if(orderType != ""){
		document.forms[0].orderType.value=orderType;
	}
	document.forms[0].submit();
}

function doAjaxSort(url,order,actionMethod,orderType){
	if(order != ""){
		document.forms[0].order.value=order;
	}
	document.forms[0].actionMethod.value=actionMethod;
	if(orderType != ""){
		document.forms[0].orderType.value=orderType;
	}
	OnAjaxSubmitByElements(url,"order|page|caseId|view|tabId",document.getElementById("ajaxContent"));
}

function moveUp(selectObj){
    var theObjOptions=selectObj.options;
    for(var i=1;i<theObjOptions.length;i++) {
        if( theObjOptions[i].selected && !theObjOptions[i-1].selected ) {
            swapOptionProperties(theObjOptions[i],theObjOptions[i-1]);
        }
    }
}
function moveDown(selectObj){
    var theObjOptions=selectObj.options;
    for(var i=theObjOptions.length-2;i>-1;i--) {
        if( theObjOptions[i].selected && !theObjOptions[i+1].selected ) {
            swapOptionProperties(theObjOptions[i],theObjOptions[i+1]);
        }
    }
}
function swapOptionProperties(option1,option2){
    var tempStr=option1.value;
    option1.value=option2.value;
    option2.value=tempStr;
    tempStr=option1.text;
    option1.text=option2.text;
    option2.text=tempStr;
    tempStr=option1.selected;
    option1.selected=option2.selected;
    option2.selected=tempStr;
}

function compareData(begDate,endDate){
	begDate = begDate.replace(/-/g,"/");
	endDate = endDate.replace(/-/g,"/");
	begDate = new Date(begDate);
	endDate = new Date(endDate);
	var times = endDate.getTime()-begDate.getTime();
	var days = parseInt(times/24/60/60/1000);
	return days;
}
//2009-03-29
function dateParse(dateStr)
{
	dateStr += " 00:00:00";
	return datehmsParse(dateStr);

}
//2009-03-29 10
function datehParse(dateStr)
{
	dateStr += ":00:00";
	return datehmsParse(dateStr)
}
//2009-03-29 10:30
function datehmParse(dateStr)
{
	dateStr += ":00";
	return datehmsParse(dateStr)
}
//2009-03-29 10:30:20
function datehmsParse(dateStr){

    var THIRTY_DAY={
       4:30,
       6:30,
       9:30,
       11:30
    }
    var dateArray=dateStr.split(" ");
    if(dateArray.length<=0){return false}

    var standDateArray=dateArray[0].split("-")
    if(standDateArray.length<=0){return false}
    var y = standDateArray[0]
    var m = standDateArray[1]-1
    var d = standDateArray[2]
    var testDate=new Date(y,m,d)
    var yTest=testDate.getFullYear()!=y
    var mTest=testDate.getMonth()!=m
    var dTest=testDate.getDate()!=d
    if(yTest||mTest||dTest){
        return false
    }
  m++;
    var runNianTest=y%4
    if(runNianTest==0&&m==2&&d>29){
        return false;
    }
    if(runNianTest!=0&&m==2&&d>28){
        return false;
    }

    if(THIRTY_DAY[m] && d>THIRTY_DAY[m]){
        return false;
    }

    var timeArray=dateArray[dateArray.length-1].split(":");
    if(timeArray.length!=3){return false};
    var hTest=((timeArray[0]>=0) && (timeArray[0]<=23)&&(timeArray[0]!='-0'))?true:false;
    var mTest=((timeArray[1]>=0) && (timeArray[1]<=59)&&(timeArray[1]!='-0'))?true:false;
    var sTest=((timeArray[2]>=0) && (timeArray[2]<=59)&&(timeArray[2]!='-0'))?true:false;
  m--;
    if(hTest&&mTest&&sTest){
    	var dd =new Date(y,m,d,timeArray[0],timeArray[1],timeArray[2]);
        return dd;
    }else{
        return false;
    }
}


function IsValidCode(str) {
	for (nIndex=0; nIndex<str.length;nIndex++){
		cCheck = str.charAt(nIndex);
		if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' )){
			return false;
		}
	}
	return true;
}
function IsDigit(cCheck){
	return (('0'<=cCheck) && (cCheck<='9'));
}
function IsAlpha(cCheck){
	return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
}
