﻿// JavaScript Document

String.prototype.__trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.__HTMLEncode = function()
{
	var s=this;
	s = s.replace(/ /g,"&nbsp;");
	s = s.replace(/\n/g,"<br>");
	return s;
}
String.prototype.__ClearHTMLCode = function()
{
	var s=this;
	s = s.replace(/<[^>]*>/g, "");
	return s;
}
String.prototype.__TitleEncode = function()
{
	return this.replace(/"/g,'&quot;');
}

String.prototype.__JSStringEncode = function()
{
	var s = this;
	s = s.replace(/'/g,'\\\'');
	s = s.replace(/\n/g,'\\\n');
	return s;
}


String.prototype.__Keywords = function()
{
	var s = this;
	var ah='<a href="javascript:void(0)" onmouseover="this.style.color=\'#003399\';" onmouseout="this.style.color=\'\';" onclick="NewSearch(this.innerText,this.innerText);">';
	var ae='</a>';
	s = s.replace(/，/g,',');
	s = s.replace(/(^\s*)|(\s*$)/g, "");
	s = s.replace(/(^,*)|(,*$)/g, "");
	if (s != ''){
		s = s.replace(/,/g,ae+','+ah);
		s = ah+s+ae;
	}
	
	return s;
}

String.prototype.__substr = function(l)
{
	var s = this;
	var t = s.substr(0, l*2);
	t = t.replace(/[^\x00-\xFF]/g,'上海');
	t = t.substr(0, l);
	t = t.replace(/上/g, '');
	return s.substr(0, t.length);
}

function IsNull(parameter, defaultValue){
	return parameter == null ? defaultValue : parameter;
}

function LinkParameters(p, f){
	var s = '';
	for (o in p){
		s += '&'+o+'='+encodeURIComponent(p[o] == null ? '' : p[o]);
	}
	if (s != '' && f != null){
		s = s.replace(/\&/, f);
	}
	return s;
}

function CombineObject(object1, object2, override){
	var name;
	if (override == null){
		override = true;
	}
	for (name in object2){
		if (object1[name] == null || override == true)
			object1[name] = object2[name];
	}
}

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;
      
    elements.push(element);
  }
  
  return elements;
}

function LoadPng(target,src,sizingMethod, property)
{
	target.onload = null;
	var width, height;
	if (sizingMethod == null)
		sizingMethod = 'image';
	width = target.width;
	height = target.height;
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		target.src='images/space.gif';
		var oDiv = document.createElement("DIV")
		oDiv.style.width=height+'px';
		oDiv.style.height=height+'px';;
		oDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='"+sizingMethod+"'";
		target.applyElement(oDiv , "outside");
	}
	else
	{
		if (target.src.substring(target.src.length-src.length,target.src.length) != src)
			target.src = src;
	}
}

function $reload() { document.location.reload(true); }


function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images){
		if(!d.MM_p)
			d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
	}
}


function ResizeImage(image, newWidth, newHeight){
	var newImage = document.createElement("img");
	newImage.src=image.src;
	if (newImage.width > newWidth){
		newImage.height = newWidth / newImage.width * newImage.height;
		newImage.width = newWidth;
	}
	if (newImage.height > newHeight){
		newImage.width = newHeight / newImage.height * newImage.width;
		newImage.height = newHeight;
	}
	image.width = newImage.width;
	image.height = newImage.height;
}

function TextAndInputSwap(object,display,setFocus)
{
		var text = object.childNodes(1).childNodes[0].value;
		text = text.replace(/[\n]/g,"<br>");
		text = text.replace(/[ ]/g,"&nbsp;");
		object.childNodes[0].childNodes[0].firstChild.firstChild.firstChild.innerHTML = text;
	if (display == "text" && !object.childNodes[1].focused)
	{
		object.childNodes[0].style.display="block";
		object.childNodes[0].style.visibilty="visible";
		object.childNodes[1].style.display="none";
		object.childNodes[1].style.visibility="hidden";
	}
	else
	{
		object.childNodes[0].style.display="none";
		object.childNodes[0].style.visibilty="hidden";
		object.childNodes[1].style.display="block";
		object.childNodes[1].style.visibility="visible";
		if (setFocus == true)
			object.childNodes[1].childNodes[0].focus();
	}
}


function TextAndInputString(mainProperty,headProperty,bodyProperty,inputProperty){
	if (mainProperty == null)
		mainProperty = new Object();
	if (headProperty == null)
		headProperty = new Object();
	if (bodyProperty == null)
		bodyProperty = new Object();
	
	var mainStyle = mainProperty.style == null ? '' : mainProperty.style;
	var headStyle = headProperty.style == null ? '' : headProperty.style;
	var headText = headProperty.text == null ? '' : headProperty.text;
	
	var bodyStyle = bodyProperty.style == null ? '' : bodyProperty.style;
	var bodyName = bodyProperty.name == null ? '' : bodyProperty.name;
	var bodyStyle = bodyProperty.style == null ? '' : bodyProperty.style;
	var defaultText = bodyProperty.defaultText == null ? '' : bodyProperty.defaultText;
	var nullColor = bodyProperty.nullColor == null ? '#CCCCCC' : bodyProperty.nullColor;
	var notNullColor = bodyProperty.notNullColor == null ? '#000000' : bodyProperty.notNullColor;
	var blankString = bodyProperty.blankString == null ? '' : bodyProperty.blankString;
	var replaceBlankString = bodyProperty.replaceBlankString == null ? '' : bodyProperty.replaceBlankString;
	
	var singleLine = inputProperty.singleLine != false ? true : false;
	var inputStyle = inputProperty.style == null ? '' : inputProperty.style;
	var inputName = inputProperty.name == null ? 'input' : inputProperty.name;
	var inputOtherProperty = inputProperty.otherProperty == null ? '' : inputProperty.otherProperty.replace(/this.parentNode/g,'this.parentNode.parentNode.parentNode.parentNode');
	
	var returnHTML="";
	returnHTML += '<div style="position:relative;top:0px;left:0px;width:auto;height:16px;'+mainStyle+'">';
		returnHTML += '<div style="height:16px;font-size:12px;line-height:16px;float:left;width:auto;'+headStyle+'">'+headText+'</div>';
		returnHTML += '<div id="'+bodyName+'" style="color:#000000;float:left;width:auto;'+bodyStyle+'">';
			returnHTML += '<div id="text" style="height:16px;line-height:16px;width:auto;overflow:hidden;">';
				returnHTML += '<div style="float:left;color:'+nullColor+';" onmouseover="TextAndInput(this.parentNode.parentNode,\''+nullColor+'\',\''+notNullColor+'\',\'\',\''+replaceBlankString+'\',\'input\');" onmouseout="TextAndInput(this.parentNode.parentNode,\''+nullColor+'\',\''+notNullColor+'\',\''+blankString+'\',\''+replaceBlankString+'\',\'text\');">'+defaultText+'</div><div style="float:left;cursor:pointer;" onclick="TextAndInput(this.parentNode.parentNode,\''+nullColor+'\',\''+notNullColor+'\',\'\',\''+replaceBlankString+'\',\'input\', true);"><img src="images/fli3.gif" border="0" width="15" height="16" /></div>';
			returnHTML += '</div>';

			returnHTML += '<div style="height:auto;color:#CCCCCC;display:none;visibility:hidden;width:auto;">';
				returnHTML += '<input type="text" name="'+inputName+'" id="input" value="'+defaultText+'" style="height:14px;font-size:12px;line-height:14px;width:200px;'+inputStyle+'" onfocus="this.parentNode.focused=true;" onblur="this.parentNode.focused=false;TextAndInput(this.parentNode.parentNode,\''+nullColor+'\',\''+notNullColor+'\',\'\',\''+replaceBlankString+'\',\'text\');" '+inputOtherProperty+' />';
			returnHTML += '</div>';
		returnHTML += '</div>';
	returnHTML += '</div>';
	return returnHTML;
}

function TextAndInputSwap2(object,nullColor,notNullColor,blankString,replaceBlankString,display,setFocus){
	if (object.childNodes[1].childNodes[0].value==blankString || object.childNodes[1].childNodes[0].value == replaceBlankString){
		object.childNodes[0].childNodes[0].innerHTML = replaceBlankString;
		object.childNodes[0].childNodes[0].style.color=nullColor;
		object.childNodes[1].childNodes[0].value="";
	}else{
		var text = object.childNodes(1).childNodes[0].value;
		text = text.replace(/[\n]/g,"<br>");
		text = text.replace(/[ ]/g,"&nbsp;");
		object.childNodes[0].childNodes[0].innerHTML = text;
		object.childNodes[0].childNodes[0].style.color=notNullColor;
	}
	if (display == "text" && !object.childNodes[1].focused){
		object.childNodes[0].style.display="block";
		object.childNodes[0].style.visibilty="visible";
		object.childNodes[1].style.display="none";
		object.childNodes[1].style.visibility="hidden";
	}else{
		object.childNodes[0].style.display="none";
		object.childNodes[0].style.visibilty="hidden";
		object.childNodes[1].style.display="block";
		object.childNodes[1].style.visibility="visible";
		if (setFocus == true)
			object.childNodes[1].childNodes[0].focus();
	}
}




function NavigationBar2(page,pageCount,skipFunction,float){
	if (float != 'right')
		float = 'left';
	var loop;
	var navigationBarLayer = document.createElement("div");
	navigationBarLayer.id = 'DNavigationBar';
	navigationBarLayer.style.position = 'relative';
	navigationBarLayer.style.width = 'auto';
	navigationBarLayer.style.height = "14px";
	//navigationBarLayer.style.margin = "3px 15px 0px 15px";
	navigationBarLayer.style.top = '3px';
	if (float == 'left'){
		navigationBarLayer.style.left = '15px';
	}else{
		navigationBarLayer.style.right = '15px';
	}
	//navigationBarLayer.style.border = '1px solid #000000';
	navigationBarLayer.style.styleFloat = float;
	navigationBarLayer.style.cssFloat = float;
	//navigationBarLayer.innerHTML = 'aaaa';
	//navigationBarLayer.style.overflow = 'auto';
	if (pageCount <= 0)
		return navigationBarLayer;
	if (page<=0)
		page=1;
	if (page>pageCount)
		page=pageCount;

	var HTMLString="";
	var pageStart=1, pageEnd=1, pageLeft=0, loop=0;
	skipFunction = skipFunction.replace(/this\./g,'this.parentNode\.');
	//HTMLString += '<div style="border:0px solid #000000;float:left;width:40px;height:18px;margin-right:0px;line-height:16px;font-size:12px;">第<font color=red>'+page+'</font>页</div>';
	//显示前3页的页数
	pageStart=page-3;
		
	//如前3页小于1，则最前页为第一页
	if (pageStart<=0){
		//前3页少掉的页数，由后3页补齐，共7页
		pageLeft=pageStart-1;
		pageStart=1;
	}
	//后3页的页数+前3页少掉的页数
	pageEnd=page+3-pageLeft;
	//如后面的页数超出总数，则最后一页结束
	if (pageEnd>pageCount){
		//如前3页未从第一页开始，则重新计算前数页
		if (pageStart>1){
			pageStart=pageStart-(pageEnd-pageCount);
			//如计算结果超出第一页，则从第一页开始
			if (pageStart<=0)
				pageStart=1;
		}
		pageEnd=pageCount;
	}

	if (pageStart<=4){
		pageStart=1;
	}else{
		for (loop=1;loop<=3;loop++){
			HTMLString += '<div align="center" style="border:1px solid #EEEEEE;background-color:#FFFFFF;float:left;width:14px;height:14px;margin-left:5px;line-height:14px;font-size:12px;cursor:pointer;" onclick="'+skipFunction.replace(/page/g,loop)+'">'+loop+'</div>';
		}
		HTMLString += '<div align="center" style="float:left;width:14px;height:14px;margin-left:5px;line-height:14px;font-size:12px;">...</div>';
	}

	if (pageEnd>=pageCount-3){
		pageEnd=pageCount;
	}
	
	//循环显示前后3页
	for (loop=pageStart;loop<=pageEnd;loop++){
		HTMLString += '<div align="center" style="border:'+(loop == page?'1px solid #006699':'1px solid #EEEEEE')+';background-color: '+(loop == page?'#FFFFFF':'#FFFFFF')+';float:left;width:12px;height:12px;margin-left:5px;line-height:12px;font-size:12px;'+(loop == page?'color:#003366;':'')+'cursor:pointer;" onclick="'+skipFunction.replace(/page/g,loop)+'">'+loop+'</div>';
	}
	
	if (pageEnd<=pageCount-4){
		HTMLString += '<div align="center" style="float:left;width:14px;height:14px;margin-left:5px;line-height:14px;font-size:12px;">...</div>';
		for (loop=pageCount-2;loop<=pageCount;loop++){
			HTMLString += '<div align="center" style="border:1px solid #EEEEEE;background-color:#FFFFFF;float:left;width:14px;height:14px;margin-left:5px;line-height:14px;font-size:12px;cursor:pointer;" onclick="'+skipFunction.replace(/page/g,loop)+'">'+loop+'</div>';
		}
	}
	HTMLString += '<div style="border:0px solid #000000;float:left;height:14px;margin-left:15px;line-height:14px;font-size:12px;"><font color="#FF0000">'+page+'</font>/'+pageCount+'</div>';
	//alert(HTMLString);
//alert(1);
	//判断前一页，后一页
	if (page>1){
		HTMLString += '<div style="float:left;height:11px;width:11px;margin-left:10px;margin-top:1px;cursor:pointer;" onclick="'+skipFunction.replace(/page/g,page-1)+'"><img src="images/PreviewButton.gif" border="0" /></div>';
	}else{
		HTMLString += '<div style="float:left;height:11px;width:11px;margin-left:10px;margin-top:1px;"><img src="images/PreviewButtonDisable.gif" border="0" /></div>';
	}
	
	if (page<pageCount){
		HTMLString += '<div style="float:left;height:11px;width:11px;margin-left:5px;margin-top:1px;cursor:pointer;" onclick="'+skipFunction.replace(/page/g,page+1)+'"><img src="images/NextButton.gif" border="0" /></div>';
	}else{
		HTMLString += '<div style="float:left;height:11px;width:11px;margin-left:5px;margin-top:1px;"><img src="images/NextButtonDisable.gif" border="0" /></div>';
	}
	
	//'直接跳转翻页
	//'从原变量中分离变量名和变量，用隐藏变量保存，然后用get方式传递到下一页
	//CategoryArray=split(CategoryList,"&")
	//for CategoryLoop=0 to Ubound(CategoryArray)
		//ParameterArray=split(CategoryArray(CategoryLoop),"=")
		//Response.Write("<input type=hidden name="&ParameterArray(0)&" value="&ParameterArray(1)&">")
	//next
	//Response.Write("<input type=""text"" name=""page"" size=""1"" value="""" class=""PageInput""><input type=""submit"" value=""GO"" name=""submit"" class=""PageInput""></td></tr></form></table>")
	//alert(HTMLString);
	navigationBarLayer.innerHTML = HTMLString;
	navigationBarLayer.HTML = '<div id="DNavigationBar" class="CPR" style="width:auto;height:14px;margin:3px 15px 0px 15px;float:'+float+';">'+HTMLString+'</div>';

	//return HTMLString;
	//document.write(sReturn);
	return navigationBarLayer;
}




function GetNodeText(node){
	//if (node.childNodes.length==0){
	//	return '';
	//}else{
	//	return node.firstChild.nodeValue;
	//}
	var textNode = node.firstChild;
	return textNode == null ? '' : textNode.nodeValue;
}

function SetPageProperty(pageLayer, type, property){
	pageLayer.type=type;
	pageLayer.property=property;
}

function SetTabProperty(tab,type,property){
	tab.type=type;
	tab.property=property;
}


function DddDate(type,NumDay,dtDate){ 
	var date = new Date(dtDate) 
	type = parseInt(type) //类型  
	lIntval = parseInt(NumDay)//间隔 
	switch(type){ 
		case 6 ://年 
			date.setYear(date.getYear() + lIntval) 
			break; 
		case 7 ://季度 
			date.setMonth(date.getMonth() + (lIntval * 3) ) 
			break; 
		case 5 ://月 
			date.setMonth(date.getMonth() + lIntval) 
			break; 
		case 4 ://天 
			date.setDate(date.getDate() + lIntval) 
			break 
		case 3 ://时 
			date.setHours(date.getHours() + lIntval) 
			break 
		case 2 ://分 
			date.setMinutes(date.getMinutes() + lIntval) 
			break 
		case 1 ://秒 
			date.setSeconds(date.getSeconds() + lIntval) 
			break; 
		default: 	
	}
	return date;
}



function DelayCall(f, time){
	//if (time == null)
	//	time = 1;
	window.setTimeout(f,time);
}

function KeywordsBuild(s){
	if (s == null){
		return null;
	}else{
		return s.Keywords();
	}
}


function GetBrowserType(){
	var browserType = '';
	switch (navigator.appName){
	case 'Microsoft Internet Explorer':
		browserType = 'IE';
		break;
	case 'Netscape':
		browserType = 'FF';
		break;
	default:
		browserType = 'Other';
		break;
	}
	return browserType;
}


function DisplayTransfer(object,id){
	var loop;
	var activePage = null;
	var objectChildren = GetChildren(object,'',true);
	//alert(objectChildren.length);
	for (loop=0;loop<objectChildren.length;loop++){
		if (objectChildren[loop].id == id){
			objectChildren[loop].style.display = 'block';
			objectChildren[loop].style.visibility = 'visible';
			activePage = objectChildren[loop];
		}else{
			objectChildren[loop].style.display = 'none';
			objectChildren[loop].style.visibility = 'hidden';
		}
	}
	/*
	for (loop=0;loop<object.childNodes.length;loop++){
		if (object.childNodes[loop].parentNode == object && object.childNodes[loop].tagName != null){
			if (object.childNodes[loop].id == id){
				object.childNodes[loop].style.display = 'block';
				object.childNodes[loop].style.visibility = 'visible';
				activePage = object.childNodes[loop];
			}else{
				object.childNodes[loop].style.display = 'none';
				object.childNodes[loop].style.visibility = 'hidden';
			}
		}
	}*/
	return activePage;
}

function GetChild(object, childID, direct){
	var child = null;
	var children = GetChildren(object, childID, direct);
	if (children.length>=1)
		child = children[0];
	return child;
}

function GetChildren(object,childID,direct){
	var loop;
	if (direct != true)
		direct = false;
	var children = [];
	for (loop=0;loop<object.childNodes.length;loop++){
		if (object.childNodes[loop].tagName != null){
			if ((childID != '' && object.childNodes[loop].id == childID) || (childID == '')){
				children.push(object.childNodes[loop]);
			}
			if (!direct){
				children = children.concat(GetChildren(object.childNodes[loop],childID,direct));
			}
		}
	}
	return children;
}

function GetChildrenByTagName(object,tagname,direct){
	if (direct != true)
		direct = false;
	var children = [];
	tagname = tagname.toLowerCase();
	if(direct)
	{
		var loop;
		for (loop=0;loop<object.childNodes.length;loop++)
		{
			if (object.childNodes[loop].tagName == null)
				continue;
			if (object.childNodes[loop].tagName.toLowerCase() == tagname)
				children.push(object.childNodes[loop]);
		}
	}
	else
	{
		children = object.getElementsByTagName(tagname);
	}
	
	return children;
}


function GetChildCount(object){
	var count = 0;
	var child;
	for (child in object)
		count++;
	return count;
}

function SetVisible(layer){
	layer.style.visibility = 'visible';
	layer.style.display = 'block';
}
function SetHidden(layer){
	layer.style.visibility = 'hidden';
	layer.style.display = 'none';
}

function SetHeight(object, height){
	var nav = NavigatorType();
	if (nav == 'IE'){
		object.style.height = height;
	}else{
		object.style.minHeight = height;
		object.style.height = 'auto';
	}
}

function NavigatorType(){
	var nav = 'other';
	switch(navigator.appName){
		case 'Microsoft Internet Explorer':
			nav = 'IE';
			break;
		case 'Netscape':
			nav = 'FF';
			break;
		default:
			nav = 'Other';
	}
	return nav;
}

function DebugOutput(s){
	var text = $('DebugText');
	if (text != null){
		text.value += s + '\n';
	}
}

function SetVisible(object){
	object.style.visibility = 'visible';
	object.style.display = 'block';
}

function SetHidden(object){
	object.style.visibility = 'hidden';
	object.style.display = 'none';
}

function PreviewText(t, l, s)
{
	var nt = t.__substr(l);
	if (nt != t)
		nt = nt + s;
	return nt;
}

function NewImage(src, width, height, border, className, style, property){
	var image;
	image = document.createElement("IMG");
	image.src = src;
	if (width != null)
		image.width = width;
	if (height != null)
		image.height = height;
	if (border != null)
		image.border = border;
	if (className != null)
		image.className = className;
	if (style != null){
		for (styleName in style){
			image.style[styleName] = style[styleName];
		}
	}
	if (property != null){
		for (propertyName in property){
			image[propertyName] = property[propertyName];
		}
	}
	return image;
}

function NewDiv(id, className, style, property, innerHTML){
	var styleName, propertyName;
	var div = document.createElement('div');
	if (id != null)
		div.id = id;
	if (className != null)
		div.className = className;
	if (style != null){
		for (styleName in style){
			div.style[styleName] = style[styleName];
		}
	}
	if (property != null){
		for (propertyName in property){
			div[propertyName] = property[propertyName];
		}
	}
	if (innerHTML != null)
		div.innerHTML = innerHTML;
	return div;
}


function NewElement(type, id, className, style, property, innerHTML){
	var styleName, propertyName;
	var element = document.createElement(type);
	if (id != null)
		element.id = id;
	if (className != null)
		element.className = className;
	if (style != null){
		for (styleName in style){
			element.style[styleName] = style[styleName];
		}
	}
	if (property != null){
		for (propertyName in property){
			element[propertyName] = property[propertyName];
		}
	}
	if (innerHTML != null)
		element.innerHTML = innerHTML;
	return element;
}

