//0941201 PM 0446
function openwindow(p_url, p_winname) {
	var mywidth, myheight
	var myleft, mytop
	mywidth = 800;
	myheight = 600;
	myleft = (screen.width - mywidth) / 2;
	mytop = (screen.height - myheight) / 2;
	window.open(p_url,p_winname,'center=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+mywidth+',height='+myheight+',left='+myleft+',top='+mytop);
}

function openwindowfull(p_url, p_winname) {
	window.open(p_url,p_winname,'center=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+screen.width+',height='+screen.height+',left=0,top=0');
}

function removeLeadingZeros(str)
{
  while (str.charAt(0) == '0')
    str = str.substr(1);
  return str;
}

function fillingZero(val, count)
{
 var retValue
 retValue = val.toString()
 while (retValue.length<count)
   retValue = '0' + retValue ;
 return retValue;
}

function cDate(str){
    arr = str.split('/');
	year = parseInt(removeLeadingZeros(arr[0]));
    month = parseInt(removeLeadingZeros(arr[1]));
    day = parseInt(removeLeadingZeros(arr[2]));
	if (arr[0].length == 4) {
		year = year - 1911;
		return fillingZero(year, 3) + '/' + fillingZero(month, 2) + '/' + fillingZero(day, 2);
	}

	if (arr[0].length < 4){
		year = year + 1911;
		return fillingZero(year, 4) + '/' + fillingZero(month, 2) + '/' + fillingZero(day, 2);
	}
}

function isDate(str){
  try
  { 
    var arr, yaer, month, day;
    arr = str.split('/');
	year = parseInt(removeLeadingZeros(arr[0]));
    month = parseInt(removeLeadingZeros(arr[1])) - 1;
    day = parseInt(removeLeadingZeros(arr[2]));
	if (arr[0].length < 4){
		year = year + 1911;
	}
    var d = new Date(year, month, day);   
    return (d.getMonth() == month) && (d.getFullYear() == year) && (d.getDate() == day);
  }
  catch(err)
  {
    return false;
  }
}

function SetObjSize(obj,w,h){ 
	var newW,newH,r; 
	r=w/h; 
	imgObj = new Image(); 
	imgObj.src = obj.href; 
	if ((imgObj.width !=0) && (imgObj.height !=0)){ 
		if (imgObj.width > w || imgObj.height >h){ 
			if ((imgObj.width)>r*(imgObj.height)){ 
				obj.height=imgObj.height*w/(imgObj.width); 
				obj.width=w; 
			} 
			else{ 
				obj.width=imgObj.width*h/(imgObj.height); 
				obj.height=h; 
			} 
		} 
		else{ 
			obj.height=imgObj.height; 
			obj.width=imgObj.width; 
		} 
	} 
	else{ 
		setTimeout("checkImg('" + theObj + "','"+w+"','"+h+"')", 100); 
	} 
} 

function isEmail(Field,str) {
  if (str=="") {
    CannotNull(Field,"Email")
    return false;
    exit;
  }
  var supported = 0;
  var ValidEmail=false
  if (window.RegExp) { 
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1; 
  } 
  if (!supported) { ValidEmail=(str.indexOf(".") > 2) && (str.indexOf("@") > 0); }
  else {
    var r1 = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9_.-]+\\@[a-zA-Z0-9\\-\\._]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    ValidEmail=r1.test(str);
  }
  if (!ValidEmail) {
    window.alert("Email的格式不正確");
    Field.focus();
    return false;
  }
  else {
    ValidEmail=true;
    return true;
  }
}