﻿charset='gb2312';
var w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && !document.all)? true: false;
function onXClose(evt)
{
	evt = (evt) ? evt : window.event;
	clickY  = evt.clientY;
	altKey  = evt.altKey;
	keyCode = evt.keyCode;
	// Window Closing in IE
	// capturing ALT + F4 || capturing a window close by "X"
	if ( (altKey == true && keyCode == 115) || clickY < 0 )
	{
		msg = "------------------------------------------------------------------------\n\n";
		msg += "请不要点击窗口右上角的“X”按钮关闭\n数据不会被保存\n\n";
		msg += "正确关闭窗口的方式是点击页面上的'保存并关闭' 或 '关闭' 按钮 。\n\n点击'放弃'按钮，仍留在当前页面\n\n";
		msg += "-----------------------------------------------------------------------\n";		
		evt.cancelBubble=true;
		evt.returnValue=msg;
	} 
}
function IsNullObj(obj)
{
	return (obj ==null || obj=='undefined');
}
function IsValidObj(obj)
{
	return !IsNullObj(obj);
}
function MaxPopWindow()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
	window.focus();	
}
function ChangeContent(id,text)
{
	var d=document.getElementById(id);
	if (d==null) return ;
	if(!d.isExt)
	{		
		if(ns6)d.style.overflow="hidden";
		d.innerHTML=text;
		if(ns6)d.style.overflow="block";
	}
	else d.src=text;		//this is for id+'_ifrm'
}
function SkipSpace(str)
{
	var out='';
	for(i=0;i<str.length; i++) {
		var c = str.charAt(i);
		if (c!=' ') break;		
	}
	return str.substr(i, str.length-i); 
}
function StringReplaceAll(org, old, newstr)
{
	while(org.indexOf(old) >=0)
		org = org.replace(old, newstr);
	return org;
}
function getDiv_H(divobj)
{
	var isIE6 = (window.document.documentElement.clientHeight)? true : false;
	wnd_H=(isIE6)?divobj.clientHeight:((window.document.all)? window.document.body.clientHeight:window.innerHeight);
	return  wnd_H;
}
function getDiv_W(divobj)
{
	var isIE6 = (window.document.documentElement.clientHeight)? true : false;
	wnd_W=(isIE6)?divobj.clientWidth:((window.document.all)? window.document.body.clientWidth:window.innerWidth);		
	return  wnd_W;
}

function GetPos(w,h,otherstr) 
{ 
	var winleft = ((screen.width - w) / 2);
	var wintop = ((screen.height - h) / 2)-40;
	if (wintop<0) wintop=10	
	if (otherstr.length==0)
		otherstr='location=no,scrollbars=yes,status=yes,resizable=yes'
	return ('height=' + h + ',width=' + w + ',top=' + wintop + ',left=' + winleft + ',' + otherstr);	
} 	
function Pop(htmPage, wndName, w, h, style)
{	
	var today = new Date();
	htmPage +="&tm=" + today.getTime();
	var obj= window.open(htmPage, wndName, GetPos(w, h, style));	
	obj.focus();
	return obj;
}
function PopModal(htmPage, w, h, style)
{	
	var str ='dialogWidth:'+ w + 'px;dialogHeight:' + h + 'px;center:yes;help:no;status:no;';	
	window.showModalDialog(htmPage, window, str);
	return false ;	
}
function CloseReload()
{
	if (window.opener && !window.opener.closed)
		window.opener.location.reload();
	window.close();
}
function CloseRefreshOpener()
{
	if (window.opener && !window.opener.closed)
	{
		window.opener.focus();	
		window.opener.frm.submit();		
	}
	window.close();

}
function CloseSubmit(frm, page, pcmd)
{
	if (window.opener && !window.opener.closed)
	{
		if (page!='')
			frm.page.value=page;
		if (pcmd!='')
			frm.pcmd.value=pcmd;
		window.opener.focus();	
		frm.method='post';
		frm.submit();		
	}
	window.close();
}
function goSubmit(frm, page, cmd, action, method)
{
  if (action!='')
	  frm.action = action;
  if (method!='')
  	frm.method = method  
  frm.page.value=page;
  frm.pcmd.value = cmd; 	
  frm.submit();
  return true ;
}	
function srchIdx(frm, page, sortCol, pageIdx, pcmd)
{
	frm.pageIdx.value=pageIdx
	frm.sortCol.value=sortCol;
	if (pcmd.length>0)
		frm.pcmd.value=pcmd;
	goLink(frm,'','');
	return false ; 	
}
/*
function Sort(frm, col, page, pcmd)
{
	frm.sortCol.value=col;
	frm.page.value=page
	frm.pcmd.value=pcmd;
	frm.sortDir.value=(frm.sortDir.value=='DESC')? 'ASC' : 'DESC' ;
	goLink(frm,'','');
}
*/
function Sort(frm, col, page, pcmd,_target)
{
	frm.sortCol.value=col;
	frm.page.value=page
	frm.pcmd.value=pcmd;
	frm.sortDir.value=(frm.sortDir.value=='DESC')? 'ASC' : 'DESC' ;
	goLink(frm,'','',_target);
}
function ResetSrch(frm)
{
	//frm.Keyword.value='';	
	if(!IsNullObj(frm.sortCol))	frm.sortCol.value='';
	if(!IsNullObj(frm.sortDir)) frm.sortDir.value='';
	if(!IsNullObj(frm.pageIdx)) frm.pageIdx.value='1';	
}
function IsFloatZero(obj, msg)
{
	obj.value = SkipSpace(obj.value);
	var val =0.0;
	val = parseFloat(obj.value)	
	if (val==0.0 || isNaN(val))
	{
		if (msg.length>0)
		{
			alert(msg);
			obj.focus();
		}
		return true;
	}
	return false;	
}
function IsBlank(obj, msg)
{	
	obj.value = SkipSpace(obj.value);
	if (obj.value=="" || obj.value.length ==0 || obj.value=='0' || obj.value=='0.0' || obj.value=='0.00')
	{
		if (msg.length>0)
		{
			alert(msg);
			obj.focus();
		}
		return true;
	}
	return false;
}
function IsChecked(frm, nm, msg)
{
	for (i=0 ; i < frm.length ; i ++ )
	{
		if (frm.elements[i].name == nm && frm.elements[i].checked)
		{
			return true;
		}
	}
	if (msg.length>0)
		alert(msg);
	return false;
}
function MarkAllCheckBox(frm, nm, flag)
{
	for (i=0 ; i < frm.length ; i ++ )
	{
		if (frm.elements[i].name == nm )
		{
			frm.elements[i].checked=flag;
		}	
	}	
}
function UncheckAll(frm, nm)
{
	for (i=0 ; i < frm.length ; i ++ )
	{
		if (frm.elements[i].name == nm )
		{
			frm.elements[i].checked=false;
		}
	}	
}
function GetRadioBoxValue(objradio)
{
	for (i=0 ; i < objradio.length ; i ++ )
	{		
		if (objradio[i].checked)
		{
			return objradio[i].value;
		}
	}	
	return '';
}
function ToInt(str)
{
	if( str==null )
		return 0.0;
	var n = parseInt(str);
	if (isNaN(n))
		return 0;
	else 
		return n;
}
function ToDouble(str)
{
	if( str==null )
		return 0.0;
	var n = parseFloat(str);
	if (isNaN(n))
		return 0.0;
	else 
		return n;
}
function IsNumerical(field, num)
{	
	if (field.value.length > 0) 
	{
		for (i=0 ; i < field.value.length; i++)
		{
				if( field.value[i]<'0' || field.value[i]>'9')
					return false ;				
		}
		if (num>0 && field.value.length > num)
		{
				return false;
		}
	} else if ( num > 0 ) return false;
   return true;
}
function IsDecimal(field, num)
{
	if (field.value.length > 0) 
	{
		for (i=0 ; i < field.value.length; i++)
		{
				if( field.value[i]<'0' || field.value[i]>'9' || field.value[i]!='.')
					return false ;				
		}
		if (field.value.length > num)
		{
				return false;
		}
	} else if ( num > 0 ) return false;
   return true;
}

/**
Check phone # is valid or not.
*/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function IsPhoneNo(objPhone, msg)
{
	if (objPhone.value.length==0) return true;
	if (checkInternationalPhone(objPhone.value)==false)
	{
		if(msg.length > 0)
			alert(msg)
		objPhone.focus()
		return false
	}
	return true
 }


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
//		   alert("Invalid E-mail ID")
		alert("非法的E-mail帐号")   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")

		   alert("非法的E-mail帐号?")  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
			alert("非法的E-mail帐号?") 
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
			alert("非法的E-mail帐号?") 
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
			alert("非法的E-mail帐号?") 
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
			alert("非法的E-mail帐号?") 
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
			alert("非法的E-mail帐号?") 
		    return false
		 }
 		 return true					
	}

function IsEmail(objEmail, msg)
{
	if (objEmail.value.length==0) return true;
	if (echeck(objEmail.value)==false)
	{
		if (msg.length>0)
			alert(msg);
		objEmail.focus()
		return false
	}
	return true
 }
function ExpendRegion(divId, cmd,toggleFlag)
{
		var div = document.all[divId];
		if (cmd=='toggle')
		{
			if (div.style.display == "none")
			{
				div.style.display = "inline";
				if (!IsNullObj(toggleFlag))
					toggleFlag.value = '1';
			}
			else
			{
				div.style.display = "none";
				if (!IsNullObj(toggleFlag))
					toggleFlag.value = '0';	
			}
		} else
		{
			div.style.display = cmd;
		}
}



function FmtMoney(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+		
	//num = num.substring(0,num.length-(4*i+3))+','+	
	num.substring(num.length-(4*i+3));
	
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}

Math.hold = function(x,n)
{
        var N = Math.pow(10,n);
        return Math.round(x * N)/N;
}
 
function FmtDecimal(num, d)
{
	var N = Math.pow(10,d);
	return Math.round(num * N)/N;
}

function ShowElms(elmTag, show_hide) {
	for (i=0; i<document.all.tags(elmTag).length; i++){
		obj = document.all.tags(elmTag)[i];
		if (!obj || !obj.offsetParent) continue;
		obj.style.visibility = show_hide;
	}
}

function IsLess(obj, len, msg)
{
	if (obj.value.length <=len) return true;
	else 
	{
		if (msg.length > 0)
		{
			alert(msg);
		} else
			alert("字段" + obj.name + "长度超过最大值" +len);
		obj.focus();
		return false;
	}
}
function IsOverMaxLen(field, len, msg)
{
	return !IsLess(field, len, msg)
}

function noenter() 
{
	return !(window.event && window.event.keyCode == 13); 
}
function enter(nextfield) 
{
	if(window.event && window.event.keyCode == 13) 
	{
  		if (!IsNullObj(nextfield))
			nextfield.focus();
  		return false; 
  	}
	else
  		return true; 
}
function entsub(event,ourform) 
{
  if (event && event.which == 13)
    ourform.submit();
  else
    return true;
}

function MoveSelectedList(selList, toList)
{
	var selOptions = selList.options
	savedList = '';
	for (var i=0;i<selOptions.length;i++)
	{	
		if (selOptions[i].selected && selOptions[i].value != '0')
		{
			savedList += selOptions[i].value + ",";
			toList.options[toList.length] = new Option(selOptions[i].text, selOptions[i].value);			
		}
	}
	var ln = selOptions.length;
	for (var i=0; (i<ln && IsValidObj(selOptions[i]));i++)
	{	
		if (selOptions[i].selected )
		{
			selOptions[i]=null;
			i--;
		}
	}
	return savedList;
}
//============================================处理信息提示＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
//<script Language="JavaScript"> powered by 25175.net
//***********默认设置定义.*********************
tPopWait=50;//停留tWait豪秒后显示提示。
tPopShow=5000;//显示tShow豪秒后关闭提示
showPopStep=20;
popOpacity=99;
//***************内部变量定义*****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");

function showPopupText(){
	var o=event.srcElement;
	MouseX=event.x;
	MouseY=event.y;
	if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
	if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
	if(o.dypop!=sPop) {
		sPop=o.dypop;
		clearTimeout(curShow);
		clearTimeout(tFadeOut);
		clearTimeout(tFadeIn);
		clearTimeout(tFadeWaiting);
		
		if(sPop==null || sPop=="") {
			dypopLayer.innerHTML="";
			dypopLayer.style.filter="Alpha()";
			dypopLayer.filters.Alpha.opacity=0;
		}
		else {
			if(o.dyclass!=null) popStyle=o.dyclass
			else popStyle="cPopText";
			curShow=setTimeout("showIt()",tPopWait);
		}
	}
}

function showIt(){
	dypopLayer.className=popStyle;
	dypopLayer.innerHTML=sPop;
	popWidth=dypopLayer.clientWidth;
	popHeight=dypopLayer.clientHeight;
	if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
	else popLeftAdjust=0;
	
	if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
	else popTopAdjust=0;
	dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
	dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
	dypopLayer.style.filter="Alpha(Opacity=0)";
	fadeOut();
}


function fadeOut(){
	if(dypopLayer.filters.Alpha.opacity<popOpacity) {
	dypopLayer.filters.Alpha.opacity+=showPopStep;
	tFadeOut=setTimeout("fadeOut()",1);
	}
	else {
	dypopLayer.filters.Alpha.opacity=popOpacity;
	tFadeWaiting=setTimeout("fadeIn()",tPopShow);
	}
}

function fadeIn(){
	if(dypopLayer.filters.Alpha.opacity>0) {
	dypopLayer.filters.Alpha.opacity-=1;
	tFadeIn=setTimeout("fadeIn()",1);
	}
}
document.onmouseover=showPopupText;
//============================================处理信息提示＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝

