// JavaScript Document
//===gotCode 2004-11-3===
//===for global.js===
/*
_global.js所包含的函数有
giveItShaow( which , sDiv ,type )		---给选定层加上阴影
											which:指定对象,type:(show:显示,hide:隐藏),sDiv:阴影对象id(shadowDiv)
giveItEffect( which  , type , obj )		---给菜单加上效果
											which:指定对象,type:(show:显示,hide:隐藏),obj(不填:取父级为对象,self:自己未对象)
toCntColor( str ,type ,addMore )		---计算对比色(暂时只支持数字形式)
											str:颜色字符串,type:(1:更亮，2:更暗,不填代表是对比色)，addMore:额外添加的值[非必要]
String.prototype.trim 					---除前后空格
											参数1:除前空格,2:除后空格,不填:除前后空格
String.prototype.isDate					---日期判断
											参数:显示错误信息的对象id
String.prototype.cLength 				---判断含有中文的字符串长度
											参数:(number:只计算含有数字,chinese:只计算含有中文,english:只计算含有英文,space:只计算含有空格)
requestString( str )					---取得网页传递参数
											str:要取得的字符串 说明:如果网页并没有传递此参数，返回空值[""]
relocation(str,cTarget)					---重定向网页---
											str:网址,cTarget:指定对象(例如:parent,iframe的name)
my_confirm( text )						---代替confirm()函数
											text:说明文字
											运行时例子
											function do_confirmBox(){
    											if ( my_confirm( "是否真的要退出?" ) ){
													my_confirmF = function(){
																	alert("do anything")
																}
    											}
											}

my_alert( text )						---代替alert()函数
											text:说明文字

*/




var has_global_js = true	//---让页面判断是否加载有此文件

//===界面类===
//---建立阴影层---
var UI_effect = true		//---是否允许显示效果
function drawShadowDiv(){
	sDiv = 	'<div id="shadowDiv" '+
			'style="'+
			'position:absolute;'+
			'left:0px;top:0px;'+
			'z-index:1;'+
			'background-color:#2C6C85;'+
			'layer-background-color:#2C6C85;'+
			'display:none;'+
			'FILTER:progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=10,finishOpacity=20,startX=0,finishX=0,startY=0,finishY=100);'+
			'border:2px solid #7fbffa;'+
			'"></div>'
			
	document.write(sDiv)
}
drawShadowDiv()
//---给选定层加上阴影---
function giveItShaow( which , sDiv ,type ){
 if( UI_effect ){
	if( type == "show" ){
		sDiv.style.zIndex = 1
		sDiv.style.left = which.offsetLeft + which.parentNode.offsetLeft + 4;
		sDiv.style.top = which.offsetTop + which.parentNode.offsetTop + 4;
		sDiv.style.width = which.offsetWidth ;
		sDiv.style.height = which.offsetHeight ;
		sDiv.style.display = "";
	}else{
		sDiv.style.display = "none"
		sDiv.style.zIndex = 1
	}
 }
}
//---建立效果层---
function drawEffectDiv(){
	//---高光---
	hDiv =	'<div id="menuHilite" '+
			'style="'+
			'display:none;'+
			'position:absolute;'+
			'top:-1px;'+
			'left:0px;'+
			'width:100%;'+
			'height:10px;'+
			'background-color: #ffffff;'+
			'overflow:hidden;'+
			'FILTER:progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=40,finishOpacity=0,startX=0,finishX=0,startY=0,finishY=80);'+
			'"></div>\n'
	//---阴影---		
	pDiv =	'<div id="menuPoorlite" '+
			'style="'+
			'display:none;'+
			'position:absolute;'+
			'top:-1px;'+
			'left:0px;'+
			'width:100%;'+
			'height:4px;'+
			'background-color: #000033;'+
			'overflow:hidden;'+
			'FILTER:progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=60,finishOpacity=0,startX=0,finishX=0,startY=100,finishY=40);'+
			'"></div>\n'
	//---边带---
	sDiv =	'<div id="menuStrap" '+
			'style="'+
			'display:none;'+
			'position:absolute;'+
			'top:-2px;'+
			'left:0;'+
			'width:6px;'+
			'height:10px;'+
			'background-color: #000066;'+
			'overflow:hidden;'+
			'FILTER:progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=20,finishOpacity=0,startX=0,finishX=0,startY=100,finishY=40);'+
			'"></div>\n'
	document.write( hDiv )
	document.write( pDiv )
	document.write( sDiv )
}
drawEffectDiv()
//---给菜单加上效果---
function giveItEffect( which  , type , obj ){
 if( UI_effect ){
	if( type == "show" ){
		if( obj == undefined ){
 			z_Index = which.parentNode.currentStyle.zIndex+1
		}else{
			z_Index = which.currentStyle.zIndex+1
		}
	
		menuHilite.style.zIndex 	= z_Index
		menuHilite.style.left 		= which.offsetLeft + which.parentNode.offsetLeft+2
		menuHilite.style.top 		= which.offsetTop + which.parentNode.offsetTop+1;
		menuHilite.style.width 		= which.offsetWidth-5 ;
		menuHilite.style.display 	= "";
		
		menuPoorlite.style.zIndex 	= z_Index
		menuPoorlite.style.left		= which.offsetLeft + which.parentNode.offsetLeft+1
		menuPoorlite.style.top 		= which.offsetTop + which.parentNode.offsetTop+which.offsetHeight-5;
		menuPoorlite.style.width 	= which.offsetWidth-1 ;
		menuPoorlite.style.display 	= "";
		
		menuStrap.style.zIndex 		= z_Index
		menuStrap.style.left 		= which.offsetLeft + which.parentNode.offsetLeft+1
		menuStrap.style.top 		= which.offsetTop + which.parentNode.offsetTop+1;
		menuStrap.style.height 		= which.offsetHeight-3 ;
		menuStrap.style.display		= "";
	}else{
		menuHilite.style.display 	= "none"
		menuPoorlite.style.display 	= "none"
		menuStrap.style.display 	= "none"
	}
 }
}
//===计算对比色===(暂时只支持数字形式)
function toCntColor( str ,type ,addMore){//str:颜色字符串,type:(1:更亮，2:更暗,不填代表是对比色)，addMore:额外添加的值[非必要]
	var colors 	=	{
						a:10,
						b:11,
						c:12,
						d:13,
						e:14,
						f:15,
						10:"a",
						11:"b",
						12:"c",
						13:"d",
						14:"e",
						15:"f"
					}
					
		if( str == "transparent"){								//如果没有颜色，返回黑色
			return "#000000"
		}
					
		str		= str.replace(/\#/,"")							//去除符号	
		_count	= str.length
		if( str.length < 6 ){		
			for( var i = 0 ; i < 6 - _count ; i ++ ){
				str = str + "0"
			}
		}
		
		str		= str.toLowerCase()								//使大小写忽略
		str		= str.substr(0,6)	
		
			
	if( addMore == null ){										//额外的值
		addMore = 0
	}	
	var getStr 	= str.split(/\B/)		
	var newStr	= ""											
	var offseColor = 6 + addMore
					
	
	
	if( type == null ){
		for( var i = 0 ; i < getStr.length ; i++ ){			//建立对比色数值
			currentStr = getStr[i]	
		
			if( isNaN(currentStr)){	
				if( colors[currentStr] == null ){	
					getNum = 0
				}else{
					getNum = 15 - eval(colors[currentStr])		//计算出对比色数值		
				}	
				if( getNum >= 10 ){		
					newStr = newStr + colors[getNum]		
				}else{	
					newStr = newStr + getNum	
				}
			}else{
				getNum = 15 - eval(currentStr)					//计算出对比色数值	
				if( getNum >= 10 ){		
					newStr = newStr + colors[getNum]				
				}else{
					newStr = newStr + getNum
				}
			}
		}
	}
	if( type == 1 ){
		for( var i = 0 ; i < getStr.length ; i++ ){			//建立对比色数值
			currentStr = getStr[i]	
		
			if( isNaN(currentStr)){	
				if( colors[currentStr] == null ){
					getNum = 0
				}else{
					getNum = eval(colors[currentStr]) + offseColor//计算出对比色数值		
				}	
				if( getNum >= 10 ){		
					if( getNum > 15 ){		
						newStr = newStr + "f"					
					}else{
						newStr = newStr + colors[getNum]
					}		
				}else{	
					newStr = newStr + getNum	
				}
			}else{
				getNum = eval(currentStr) + offseColor			//计算出对比色数值	
				if( getNum >= 10 ){	
					if( getNum > 15 ){		
						newStr = newStr + "f"					
					}else{
						newStr = newStr + colors[getNum]
					}				
				}else{
					newStr = newStr + getNum
				}
			}
		}
	}
	if( type == 2 ){
		for( var i = 0 ; i < getStr.length ; i++ ){			//建立对比色数值
			currentStr = getStr[i]	
		
			if( isNaN(currentStr)){	
				if( colors[currentStr] == null ){
					getNum = 0
				}else{
					getNum = eval(colors[currentStr]) - offseColor//计算出对比色数值		
				}	
				if( getNum >= 10 ){		
					if( getNum < 0 ){								
						newStr = newStr + "0"					
					}else{
						newStr = newStr + colors[getNum]		//取得对应的字符
					}		
				}else{	
					newStr = newStr + getNum	
				}
			}else{
				getNum = eval(currentStr) - offseColor		//计算出对比色数值	
				if( getNum >= 10 ){	
					newStr = newStr + colors[getNum]
				}else{
					if( getNum < 0 ){								
						newStr = newStr + "0"					
					}else{
						newStr = newStr + getNum
					}
				}
			}
		}
	}	
	return "#"+newStr
}
//===end==========





//===程序应用类===
//---除前后空格---(参数1:除前空格，2:除后空格)
function String_trim( type ){
	var cStr	= ""
	var cutHead	= 0
	var cutFoot	= 0
	var iLength	= this.length
	for( var i = 0 ; i < iLength ; i ++ ){				//找出开头有多少个空格
		if( this.substr(i,1) == " " && type != 2 ){
			cutHead ++
		}else{
			break
		}
	}
	for( var i = iLength - 1 ; i > 0 ; i -- ){			//找出末尾有多少个空格
		if( this.substr(i,1) == " "  && type != 1 ){
			cutFoot ++
		}else{
			break
		}
	}
	cStr = this.substr(cutHead,iLength - (cutFoot+cutHead))
	return cStr
}
//---日期重组格式---
function String_formatDate( type ){
	iDate	= this;
	while( iDate.substr(iDate.length-1,1) == iDate.substr(iDate.length-1,1).match(/\D/) ){
		iDate = iDate.substr(0,iDate.length - 1)
	}
	reDate	= iDate + "-"
	count	= 0;
	len		= 0;
	str		= "";
	
	for( var i = 0; i < reDate.length ; i++ ){
		if( reDate.substr(i,1) == reDate.substr(i,1).match(/\D/) ){
			count	= count + 1
			if( len < 2 ){
				str = str + "0" + reDate.substr(i-len,len)
			}else{
				str = str + reDate.substr(i-len,len)
			}
			len = 0
		}else{
			len	= len+ 1
		}
	}
	
	if( type != null ){
		str = str.substr(0,4) + type +　str.substr(4,2) + type +　str.substr(6,2) 
	}
	return str
}
//---日期判断---
function String_isDate( showErrorInfo ){
	iDate	= this;
	reDate	= iDate + "-"
	count	= 0;
	len		= 0;
	str		= "";
	
	for( var i = 0; i < reDate.length ; i++ ){
		if( reDate.substr(i,1) == "-" ){
			count	= count + 1
			if( len < 2 ){
				str = str + "0" + reDate.substr(i-len,len)
			}else{
				str = str + reDate.substr(i-len,len)
			}
			len = 0
		}else{
			len	= len+ 1
		}
	}
	//----------------------------------\判断showErrorInfo是否存在-|
	function errorInfo( str ){
		if( document.all(showErrorInfo) != null && showErrorInfo != null ){
			document.all(showErrorInfo).innerText = str
		}
	}
	//-------------------------------------------------------------
 	var isBigYear , year , month , day
	year  = str.substr( 0 , 4 );
	month = str.substr( 4 , 2 );
	day   = str.substr( 6 , 2 );
	isBigYear = true ;
	var monthType1 = new Array()
		monthType1[0] = "01";
		monthType1[1] = "03";
		monthType1[2] = "05";
		monthType1[3] = "07";
		monthType1[4] = "08";
		monthType1[5] = "10";
		monthType1[6] = "12";
	var monthType2 = new Array()
		monthType2[0] = "04";
		monthType2[1] = "06";
		monthType2[2] = "09";
		monthType2[3] = "11";

	//----------------------------------\判断是否由数字组成-|	
	if( isNaN(str) || str.toLowerCase().split('e').length > 1 ){
		errorInfo("日期不是数字")
		return false
	}
	//----------------------------------\判断日期格式是否合法-|
	if( iDate.split('-').length  -  1 == 2){
		//return true
	}else{
		errorInfo("日期格式有误(例子:2004-12-28)")
		return false
	}	
	//----------------------------------\判断年月日是否合法-|
	if( year == "0000"){
		errorInfo("年份非法，不能全为“0”")
		return false
	}
	if( month == "00"){
		errorInfo("月份非法，不能为“0”")
		return false
	}
	if( day == "00"){
		errorInfo("日子非法，不能为“0”")
		return false
	}
	//----------------------------------\判断长度是否足够-|
	if( str.length < 8){
		errorInfo("日期长度不足")
		return false
	}
	if( str.length > 8){
		errorInfo("超出日期长度")
		return false
	}
	//----------------------------------\判断润年-|
	if( eval(year)%4 == 0 ){
		isBigYear = true;
	}else{
		isBigYear = false ;
	}
	//----------------------------------\判断2月最大日-|
	if( month == "02" && isBigYear == false ){
		if ( eval(day) >28 ){
			errorInfo(year+"年2月最后一日是28号")
			return false;
		}
	}else if( month == "02" && isBigYear == true ){
			if ( eval(day) >29 ){
				errorInfo(year+"年2月最后一日是29号")
				return false ;
			}
	}
	//----------------------------------\判断大小月最大日-|
	for (var iM1 = 0 ; iM1 < monthType1.length ; iM1++ ){
		if( str.substr( 4 , 2 ) == monthType1[iM1] ){
			if ( eval(day) >31 ){
				errorInfo(eval(month)+"月最后一日是31号")
				return false ;
			}
		}
	}
	for (var iM2 = 0 ; iM2 < monthType2.length ; iM2++ ){
		if( month == monthType2[iM2] ){
			if ( eval(str.substr( 6 , 2 )) >30 ){
				errorInfo(eval(month)+"月最后一日是30号")
				return false ;
			}
		}
	}
	//-------------------------------------------------/end/------
	if( eval(month) >12 ){
		errorInfo("一年最多12个月")
		return false ;
	}
	if( eval(year) < 1800 ){
		errorInfo("年份小于1800年")
		return false ;
	}
	errorInfo("")
	return true
}
//---判断含有中文的字符串长度---
function String_cLength( type ) { 
	var _num 	= this.length
	var chinese	= this.match(/[^\x00-\x80]/ig)	//符合中文的集合	
	var english	= this.match(/[a-z]/ig)			//符合英文的集合	
	var number	= this.match(/[0-9]/ig)			//符数字的集合	
	var space	= this.match(/ /ig)				//符合空格的集合	
	
	if( type == "chinese" ){					//符合中文字符串的长度				
		if( chinese != null ){
			return chinese.length
		}else{
			return 0
		}
	}else if( type == "english"){				//符合英文字符串的长度
		if( english != null ){
			return english.length
		}else{
			return 0
		}	
	}else if( type == "number"){				//符合数字字符串的长度			
		if( number != null ){
			return number.length
		}else{
			return 0
		}
	}else if( type == "space"){				//符合空格字符串的长度
		if( space != null ){
			return space.length
		}else{
			return 0
		}
	}else{
		if( chinese != null ){					//整个字符串的长度	
			_num = _num + chinese.length
		}
		return _num
	}
} 
String.prototype.trim 		= String_trim
String.prototype.isDate 	= String_isDate
String.prototype.cLength 	= String_cLength
String.prototype.formatDate =String_formatDate
//--取得网页传递参数---
function replaceFilters_requestString( str ){
	str = str.replace(/=/g,':')
	str = str.replace(/:/g,':"')
	str = str.replace(/  /g,' ')
	str = str.replace(/:"\/\//g,'://')
	str = str.replace(/javascript:"/g,'javascript:')
	str = str.replace(/&/g,'",')
	str = str + '"'
	str = str.replace(/""/g,'"')
	str = str.replace(/:"&/g,':"",')
	str = "{" + str + "}"
	return str
}
function requestString( str ){
	var getURL 		= window.location.href
	var getString	= null
	var strFilter	= {}
	
	if( getURL.indexOf("?") > 0 ){
		getString = getURL.split("?")[1]
		if( getString.indexOf("=") < 0){
			return ""		
		}else{
			eval( "strFilter=" + replaceFilters_requestString(getString))
		}
	}
	
	oString = strFilter[str]

	if( oString == undefined || oString == null ){
		oString = ""
	}else{
		oString = unescape(strFilter[str])
	}
	return oString
}

//---重定向网页---
function relocation(str,cTarget){
	if( cTarget == null ){
		window.location.href = str
	}else{
		cTarget.window.location.href = str
	}
}
//---写读cookie---
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
//---对话框---
/*运行时例子
function do_confirmBox(){
    if ( my_confirm( "是否真的要退出?" ) ){
		my_confirmF = function(){
								alert("do anything")
							}
    }
}
*/
var my_confirmF = function(){}				//当按确定时执行函数
		
function my_confirm( text ){					//--代替confirm()函数		
	show_dialogBox('confirm',text)				//显示对话框
	confirmBox_cancel.focus()
	return true	
}

function my_alert( text ){						//--代替alert()函数		
	show_dialogBox('alert',text)				//显示对话框
	alert_do.focus()	
} 

function show_dialogBox( type , text ){		//--显示对话框
	oInfo 	= document.all('my_'+type+'Info')
	oBox	= document.all('my_'+type+'Box')
	
	oInfo.innerText 	= text
	oBox.style.display 	= ""			
	oBox.style.top		= ( document.body.clientHeight - my_confirmBox.offsetHeight)/2
	oBox.style.left		= ( document.body.clientWidth  - my_confirmBox.offsetWidth  )/2
	
	dialogBoxMaskDiv.style.display	= ""

	setTimeout(function(){giveItShaow(oBox,shadowDiv,"show")},10)			//赋予阴影(注意！其他地方调用时请删除)
	setTimeout(function(){giveItEffect(oBox,"show","self")},10)			//赋予效果(注意！其他地方调用时请删除)
}

function hide_dialogBox( type ){				//--取消对话框
	oInfo 	= document.all('my_'+type+'Info')
	oBox	= document.all('my_'+type+'Box')
	
    oInfo.innerText		= ""
	oBox.style.display 	= "none"
	
	dialogBoxMaskDiv.style.display	= "none"
	
	giveItShaow(oBox,shadowDiv,"hide")
	giveItEffect(oBox,"hide")	
}

function draw_confirmBox(){					//--建立confirm对话框
	oHtml =	'<div id="my_confirmBox" '+
				'style="'+
					'position:absolute;'+
					'z-index:30;'+
					'padding:16px;'+
					'border:1px outset #C9CDCF;'+
					'background:#C9CDCF;'+
					'display:none;'+
					'font:9pt;'+
				'"'+
			'>\n'+
			'<span id="my_confirmInfo"></span>\n'+
			'<br>\n<br>\n'+
			'<input type="button" name="confirmBox_do" value="确 定" onClick="my_confirmF();hide_dialogBox(\'confirm\')" 	style="background:white;border:2px groove;border-color:none;padding-top:2px;FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=white,endColorStr=#ffffee)">\n'+
			'&nbsp;'+
			'<input type="button" name="confirmBox_cancel" value="取 消" onclick="hide_dialogBox(\'confirm\')" 			style="background:white;border:2px groove;border-color:none;padding-top:2px;FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=white,endColorStr=#ffffee)">\n'+
			'</div>\n'
	document.write(oHtml)
}
draw_confirmBox()

function draw_alertBox(){					//--建立alert对话框
	oHtml =	'<div id="my_alertBox" '+
				'style="'+
					'position:absolute;'+
					'z-index:30;'+
					'padding:16px;'+
					'border:1px outset #C9CDCF;'+
					'background:#C9CDCF;'+
					'display:none;'+
					'font:9pt;'+
				'"'+
			'>\n'+
			'<span id="my_alertInfo"></span>\n'+
			'<br>\n<br>\n'+
			'<input type="button" name="alert_do" value="确 定" onClick="hide_dialogBox(\'alert\')" 	style="background:white;border:2px groove;border-color:none;padding-top:2px;FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=white,endColorStr=#ffffee)">\n'+
			'</div>\n'
	document.write(oHtml)
}
draw_alertBox()

function draw_dialogBoxMaskDiv(){			//---建立一个透明mask
	oHtml =	'<div id="dialogBoxMaskDiv" '+
			'style="'+
			'position:absolute;'+
			'z-index:1;'+
			'top:0px;'+
			'left:0px;'+
			'width:100%;'+
			'height:100%;'+
			'background:blue;'+
			'filter:alpha(opacity=0);'+
			'display:none;'+
			'"></div>'
	document.write(oHtml)
}
draw_dialogBoxMaskDiv()
//===============================================================
