//javascript document

function check_close()
{
    if(confirm("您确定要关闭吗？"))
      return true;
    else
      return false;  
}

function check()
{
	if(confirm("请确认你要删除的记录！"))
		return true;
	else
		return false;
}

function check_del()
{
	if(confirm("请确认你要删除的记录！"))
		return true;
	else
		return false;
}

function DelCheck(str) {
	if(confirm(str))
		return true;
	else
		return false;
}


//选择和清除所有的复选框
function checkall(form)
{
	for(var i=0;i<form.elements.length;i++)
	{	
		var e = form.elements[i];
		if(form.elements[i].type=='checkbox' && form.chkall.value == '全选')
		{
			e.checked = true;
		}
		else
			e.checked = false;
	}
	
	if(form.chkall.value == '全选')
		form.chkall.value = '清除';
	else
		form.chkall.value = '全选';
}

//判断是否是日期
function isdate(strDate){

	var re=/^\d{4}-\d{1,2}-\d{1,2}$/;
	var r=strDate.match(re);
	if (r==null) return false;


   var strSeparator = "-"; //日期分隔符
   var strDateArray;
   var intYear;
   var intMonth;
   var intDay;
   var boolLeapYear;
   
   strDateArray = strDate.split(strSeparator);
   
   if(strDateArray.length!=3) return false;
   
   intYear = parseInt(strDateArray[0],10);
   intMonth = parseInt(strDateArray[1],10);
   intDay = parseInt(strDateArray[2],10);
   
   if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
   
   if(intMonth>12||intMonth<1) return false;
   
   if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;
   
   if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;
   
   if(intMonth==2){
      if(intDay<1) return false;
      
      boolLeapYear = false;
      if((intYear%100)==0){
         if((intYear%400)==0) boolLeapYear = true;
      }
      else{
         if((intYear%4)==0) boolLeapYear = true;
      }
      
      if(boolLeapYear){
         if(intDay>29) return false;
      }
      else{
         if(intDay>28) return false;
      }
   }
   
   return true;
}

function alertDate(input) {
	strDate = input.value;
	if (strDate == '') return;
	if(!isdate(strDate)) {
		alert("请输入正确地的日期格式[YYYY-MM-DD]。");
		input.focus();
		input.select();
	}
}

function alertDate1(input) {
	strDate = input.value;
	if (strDate == '') return;
}


function checkemail(input) {
	str = input.value;
	if ( str!="" )
	{
	if (str.indexOf('@', 0) == -1)
	{
		alert("这不是正确的e-mail address! 请再输入一次!");
		input.focus();
		input.select();}
	}
}

function isEmail(input) {
	str = input.value;
	if ( str=="" ) {
		return false;
	}
	if (str.indexOf('@', 0) == -1) {
		return false;
	}
	return true;
}

function callpage(htmlurl,width,height) {
	
	//var ts=document.getElementById("ts");	
	//ts.innerHTML+="正在处理...";
	window.open(htmlurl,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=2,width='+width+',height='+height);
	//ts.innerHTML="处理成功!";
	return false;
}

function isInt(e)
{
    var charCode=e.keyCode;
	status=charCode;
	if(charCode==45) return true;
	if(charCode>31 &&(charCode<48||charCode>57)) {
		//alert("请输入数字.");
		return false;
	}
	return true;
}

function checkInt(input) {
	var str = input.value;
	if(str.substring(0,1)=='-') str = str.substring(1,str.length);
	var re=/^\d{0,8}$/;
	var r=str.match(re);
	if (r == null) {
		alert('错误提示：请输入正确的数字！');
		input.focus();
		input.select();
	}

}

function isNumber(input) { 
	var str = input.value;
	if (str=='') return true;
	var re=/^\d{1,8}$|\.\d{1,2}$/;
	var r=str.match(re);
	if (r==null) {
		alert("错误提示：请输入正确的数值，小数点后保留两位小数。");
		input.focus();
		input.select();
	}
	return true;
}

function checkNumber(e) {
	var charCode = e.keyCode;
	if(charCode==45) return true;
	if(charCode==46) return true;
	if(charCode>31 &&(charCode<48||charCode>57)) {
		//alert("请输入数字.");
		return false;
	}
	return true;
}


function copyright() {
	document.write("<br><center>Copyright 2001-2002版权所有，All right Reserved </center><br>");
}

function setSubject(s) {
	document.write("<table width='100%' border=0 cellspacing=1 cellpadding=1 align=center><tr><td><img src='../images/arron1.gif'><font color=#f67a00><b>"+s+"</b></font></td></tr></table>");
}

//显示、隐藏Search
function toSearch(){
	var args=toSearch.arguments;
	theObj=eval("document.all[\'"+args[0]+"\']");
	if(theObj) {
		if(theObj.style.visibility=='visible')
			theObj.style.visibility = 'hidden';
		else
			theObj.style.visibility = 'visible';
	}
}

function openCalender() {
	var width = 440;
	var height = 420;
	var lastMouseX;
	var lastMouseY;
	var features;
	var e,FileName;
	FileName = arguments[0];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	if (lastMouseX - width < 0) {
		lastMouseX = width;
	}
	if (lastMouseY + height > screen.height) {
		lastMouseY -= (lastMouseY + height + 50) - screen.height;
	}
	lastMouseX -= width;
	lastMouseY += 10;
	features = "width="+width+",height="+height+",status=no,resizable=no,"
	features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	vWinCal = window.open(FileName, "Calendar", features,false);
	vWinCal.focus();
}

function showCalendar() {
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var width,height;
	width = 230;
	height = 200;
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	if (lastMouseX - width < 0) {
		lastMouseX = width;
	}
	if (lastMouseY + height > screen.height) {
		lastMouseY -= (lastMouseY + height + 50) - screen.height;
	}
	lastMouseX -= width;
	lastMouseY += 10;
	features = "width="+width+",height="+height+",status=no,resizable=no,"
	features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;

	FileName = "admin/inc/Calendar.asp?formElt=" + arguments[0];
	vWinCal = window.open(FileName, "Calendar", features,false);
	vWinCal.focus();
}

function setComboxValue() {
	var Dwidth = 190;
	var Dheight = 260;
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var FileName,formElt,showformElt, e;
	
	FileName = arguments[0];
	formElt = arguments[1];
	showformElt = arguments[2];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	
	if (lastMouseX - Dwidth < 0) {
		lastMouseX = Dwidth;
	}
	if (lastMouseY + Dheight > screen.height) {
		lastMouseY -= (lastMouseY + Dheight + 50) - screen.height;
	}
	lastMouseX -= Dwidth;
	lastMouseY += 10;
	features = "dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px; scroll:0; help:0; status:No; fullscreen;";
	features +=	"screenX:" + lastMouseX + ";dialogLeft:" + lastMouseX + ";screenY:" + lastMouseY + ";dialogTop:" + lastMouseY;

	

	rv=window.showModalDialog(FileName,null,features);
	//rv=window.showModalDialog(FileName,null,"dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px;center:1;scroll:0;help:0;status:0");
	if ( rv == null) return false;
	if ( showformElt != "" && formElt != "") {
		var i = formElt.indexOf('.');
		var formName,formEltName;
		//设置显示的值
		if( rv[0] == "") {
			//清空ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			//清空显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			return false;
		}
		else {
			//设置ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[0]);
			//设置显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[1]);
			return true;
		}
	}
	return false;
}

//清除空格
function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split("　");
	for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
	return temp;
}

var objPrevElement = null;
function ChangeColor() {
	source=event.srcElement;

	if(objPrevElement!=null && objPrevElement.tagName=='TR')
	objPrevElement.style.backgroundColor='#EEEEEE';

	//for(i in document.all){
	//	if(document.all[i].t==1){//用户触发:重新设置属性
	//		document.all[i].style.backgroundColor='#EEEEEE';
	//	}
	//}
	//if(source.tagName=="INPUT") {
		//if(source.checked)
	//}
	if(source.tagName=="INPUT") return;
	if(source.tagName=="IMG") return;
	if(source.tagName=="TABLE") return;
	while(source.tagName!="TR") {
		source=source.parentElement;
	}
	if (source.style.backgroundColor!='#CFDFFF'&&source.id!="ignore") {
		source.style.backgroundColor='#CFDFFF';
		objPrevElement=event.srcElement.parentElement;
	} else {
		source.style.backgroundColor='#EEEEEE';
	}
}

//按取消关闭窗口
function onClose() {
	if(event.keyCode==27) window.close();
	return true;
}


function openSelect() {
	var width = 520;
	var height = 400;
	var features;
	var e,FileName;
	FileName = arguments[0];
	features = "width="+width+",height="+height+",status=no,resizable=auto,scrollbars=yes"
	//features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	selWin = window.open(FileName, "selectWindow", features,false);
	selWin.focus();
}



//此处为string类添加三个成员 
String.prototype.Trim = function(){ return Trim(this);} 
String.prototype.LTrim = function(){return LTrim(this);} 
String.prototype.RTrim = function(){return RTrim(this);} 

//此处为独立函数 
function LTrim(str) 
{ 
   var i; 
   for(i=0;i<str.length;i++) 
     { 
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
     } 
   str=str.substring(i,str.length); 
   return str; 
} 
function RTrim(str) 
{ 
   var i; 
   for(i=str.length-1;i>=0;i--) 
     { 
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
      } 
   str=str.substring(0,i+1); 
   return str; 
} 
function Trim(str) 
{ 
   return LTrim(RTrim(str)); 
} 

/*
 * 清空字符头尾的空格。
 */
function trim(str)
{
    var i=0;
    var i2=-1;
    var chr;
    if (str) {
        for(i=0;i<str.length-1;i++)	{
            chr=str.charAt(i);
            if(chr!=' ')
            break;
        }
        for(i2=str.length-1;i2>=0;i2--)	{
            chr=str.charAt(i2);
            if(chr!=' ')
            break;
        }
    }
    if(i<=i2) {
        return str.substring(i,i2+1);
    } else {
        return "";
    }
}

/*
 * 获取字符串长度，中文字符当成两个
 */
function getLength(strTemp)
{
    var i,sum;
    sum = 0;
    for(i=0;i<strTemp.length;i++)
    {
        if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
            sum = sum + 1;
        else
            sum = sum + 2;
    }
    return sum;
}

