
function getElement(id) {
	return document.getElementById(id);
}
function createElement(type) {
	return document.createElement(type);
}
function removeElement(element) {
	try {
		if (element) {
			element.parentNode.removeChild(element);
		}
	}
	catch (e) {
	}
}



function GetOffsetPos(element) {
	
	var flag = element.tagName.toUpperCase() == "INPUT" ? true : false;
	var posTop = 0, posLeft = 0;
	do {
		posTop += element.offsetTop || 0;
		posLeft += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1 && flag) {
		posLeft++;
	}
	return [posLeft, posTop];
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return([myWidth,myHeight]);
}   

function hideSelects(zIndexNow) {
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) {
			if (selects[i].zIndexNow != zIndexNow && selects[i].style.visibility != "hidden") {
				selects[i].style.visibility = "hidden";
				selects[i].zIndexNow = zIndexNow;
			}
		}
	}
}

function showSelects(zIndexNow) {
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) {
			if (selects[i].zIndexNow == zIndexNow) {
				selects[i].style.visibility = "";
				selects[i].zIndexNow = -1;
			}
		}
	}
}

var Mask = function () {
	this.zIndexNow = 100;
	this.maskDiv = null;
	this.indexArr = [];
	this.show = function () {
		this.zIndexNow += 10;
		if (this.indexArr.length == 0){
			var maskHeight = document.documentElement.scrollHeight > getWindowSize()[1] ? document.documentElement.scrollHeight : getWindowSize()[1];
			this.maskDiv = createElement("div");
			this.maskDiv.onclick = function () {
				var event = arguments[0] || window.event;
				event.cancelBubble = true;
			};
			this.maskDiv.className = "mask";
			this.maskDiv.style.width = "100%";
			this.maskDiv.style.height = maskHeight + "px";
			document.body.appendChild(this.maskDiv);
		}
		this.maskDiv.style.zIndex = this.zIndexNow - 1;
		this.indexArr.push(this.zIndexNow - 1);
		hideSelects(this.zIndexNow);
	};
	this.clean = function () {
		showSelects(this.zIndexNow);
		this.indexArr.pop();
		if (this.indexArr.length > 0){
			this.maskDiv.style.zIndex = this.indexArr[this.indexArr.length - 1];
			this.zIndexNow = this.indexArr[this.indexArr.length - 1] + 1;
		}
		else {
			document.body.removeChild(this.maskDiv);
			this.zIndexNow = 100;
		}
	};
	this.booleanLoading = false;
	this.showLoading = function () {
		this.booleanLoading = true;
		this.zIndexNow += 10;
		if (this.indexArr.length == 0){
			var maskHeight = document.documentElement.scrollHeight > getWindowSize()[1] ? document.documentElement.scrollHeight : getWindowSize()[1];
			this.maskDiv = createElement("div");
			this.maskDiv.className = "loading";
			this.maskDiv.style.backgroundPositionY = (getWindowSize()[1] - 73) / 2 + document.documentElement.scrollTop + "px";
			this.maskDiv.style.width = "100%";
			this.maskDiv.style.height = maskHeight + "px";
			document.body.appendChild(this.maskDiv);
		}
		this.maskDiv.style.zIndex = this.zIndexNow - 1;
		this.indexArr.push(this.zIndexNow - 1);
		hideSelects(this.zIndexNow);
	};
	this.cleanLoading = function () {
		if (this.booleanLoading == true) {
			this.booleanLoading = false;
			showSelects(this.zIndexNow);
			this.indexArr.pop();
			if (this.indexArr.length > 0){
				this.maskDiv.style.zIndex = this.indexArr[this.indexArr.length - 1];
				this.zIndexNow = this.indexArr[this.indexArr.length - 1] + 1;
			}
			else {
				document.body.removeChild(this.maskDiv);
				this.zIndexNow = 100;
			}
			if (opts == "1") {
				opts = "0";
				HelpTips.Init();
			}
		}
	};
};



if( typeof $ff == 'undefined' ){
	$ff = function (objName){
		if(document.getElementById){
			return document.getElementById(objName);
		}else{
			return document.all.objName;
		}
	}
}

if( typeof $ffC == 'undefined' )$ffC = function(t){return document.createElement(t)};
var HelpTips = {
	indexNow: 0,
	flicker: null,
	arr: [],
	wLocation: null,
	transparentMask: null,
	targetElement: null,
	Init: function(arrDivObj){
		if(arrDivObj)
		{
			this.arr = arrDivObj;
			this.indexNow = 0;

			this.flicker = $ffC("DIV");
			this.flicker.className = "flicker";
			this.flicker.style.display = "none";
			document.body.appendChild(this.flicker);

			this.transparentMask = $ffC("DIV");
			this.transparentMask.style.height = document.documentElement.scrollHeight + "px";
			this.transparentMask.className = "transparentMask";
			document.body.appendChild(this.transparentMask);

			this.generateDiv.apply(this,this.arr[0]);
			mask.show();
		}
	},
	
	generateDiv: function(tipWidth,tipHeight,targetElement,tipAnchor,tipX,tipY,arrowType,textIndex,plusOrLower){
		if (typeof plusOrLower == "string"){
			switch (plusOrLower)
			{
			case "plus":
				this.indexNow++;
				break;
			
			case "lower":
				this.indexNow--;
				break;
			}
		}
		if (typeof plusOrLower == "number"){
			this.indexNow = plusOrLower;
		}

		if ((this.indexNow == 3 || this.indexNow == 4) && targetElement.style.display == "none"){
			switch (plusOrLower)
			{
			case "plus":
				this.generateDiv.apply(this,this.arr[this.indexNow + 1].concat("plus"));
				break;
			
			case "lower":
				this.generateDiv.apply(this,this.arr[this.indexNow - 1].concat("lower"));
				break;
			}
			
			return;
		}
		if (this.indexNow == 4  && targetElement.firstChild.className == "dataTableRecordList"){
			switch (plusOrLower)
			{
			case "plus":
				this.generateDiv.apply(this,this.arr[this.indexNow + 1].concat("plus"));
				break;
			
			case "lower":
				this.generateDiv.apply(this,this.arr[this.indexNow - 1].concat("lower"));
				break;
			}
			
			return;
		}

		if (targetElement){
			if (this.targetElement){
				this.targetElement.style.position = "";
				this.targetElement.style.zIndex = "";
			}
			this.targetElement = targetElement;
			var tempArr = GetOffsetPos(targetElement);
			var tempX = tempArr[0] + tipX;
			var tempY = tempArr[1] + tipY;

//			if (tipAnchor){
//				if (tipAnchor == 1){
//					window.scrollTo(0,tempArr[1] - 20);
//				}
//				else {
//					window.scrollTo(0,0);
//				}
//			}
			if (tipAnchor){
				if (tipAnchor == 1){
					this.anchorScroll.start(tempArr[1] - 20);
				}
				else {
					this.anchorScroll.start(0);
				}
			}

			this.targetElement.style.position = "relative";
			this.targetElement.style.zIndex = 8000;

			this.flicker.style.width = targetElement.clientWidth  + "px";
			this.flicker.style.height = targetElement.clientHeight  + "px";
			this.flicker.style.left = tempArr[0] - 2 + "px";
			this.flicker.style.top = tempArr[1] - 2 + "px";
			if (this.flicker.style.display == "none"){
				this.flicker.style.display = "";
			}
		}
		else {
			var tempArr = getWindowSize();
			var tempX = (tempArr[0] - tipWidth) / 2;
			var tempY = (tempArr[1] - tipHeight) / 2;
			this.targetElement = null;
		}

		this.tipOuter = $ffC("DIV");
		this.tipOuter.className = "tips";

		this.tipOuter.head = this.generateHeadAndFoot("tipHead",tipWidth);
		this.tipOuter.foot = this.generateHeadAndFoot("tipFoot",tipWidth);

		this.tipOuter.tipBody = $ffC("DIV");
		this.tipOuter.tipBody.className = "tipBody";
		this.tipOuter.tipBody.style.width = tipWidth + "px";

		this.tipOuter.content = $ffC("DIV");
		this.tipOuter.content.className = "content";		
		this.tipOuter.content.style.height = tipHeight + "px";

		if (arrowType){
			var arrow = this.generateArrow(tipWidth,tipHeight,arrowType);
			this.tipOuter.content.appendChild(arrow);
		}		

		this.tipOuter.textContainer = $ffC("DIV");
		this.tipOuter.textContainer.innerHTML = this.modules[textIndex];
		this.tipOuter.content.appendChild(this.tipOuter.textContainer);

		this.tipOuter.inputContainer = $ffC("DIV");
		this.tipOuter.inputContainer.className = "inputContainer";

		this.tipOuter.inputArr = this.generateInputs();
		for (var i = 0;i < this.tipOuter.inputArr.length ;i++ ){
			this.tipOuter.inputContainer.appendChild(this.tipOuter.inputArr[i]);
		}

		this.tipOuter.content.appendChild(this.tipOuter.inputContainer);

		this.tipOuter.closeButton = this.generateCloseButton(tipWidth);
		this.tipOuter.content.appendChild(this.tipOuter.closeButton);

		this.tipOuter.tipBody.appendChild(this.tipOuter.content);

		this.tipOuter.appendChild(this.tipOuter.head);
		this.tipOuter.appendChild(this.tipOuter.tipBody);
		this.tipOuter.appendChild(this.tipOuter.foot);

		this.tipOuter.style.left = tempX + "px";
		this.tipOuter.style.top = tempY + "px";

		document.body.appendChild(this.tipOuter);
		
	},

	generateHeadAndFoot: function(headOrFoot,theWidth){
		var obj = $ffC("DIV");
		obj.className = headOrFoot;
		var tempWidth = theWidth - 14;

		var objLeft = $ffC("DIV");
		objLeft.className = "Left";
		var objCenter = $ffC("DIV");
		objCenter.className = "Center";
		objCenter.style.width = tempWidth + "px";
		var objRight = $ffC("DIV");
		objRight.className = "Right";

		obj.appendChild(objLeft);
		obj.appendChild(objCenter);
		obj.appendChild(objRight);

		return obj;
	},

	anchorScroll: {
		start: function(targetY){
			this.toTop = document.documentElement.scrollTop;
			this.targetY = targetY;		
			this.scrollPace = (targetY - this.toTop) / 10;
			if (this.scrollPace != 0){
				this.scrollTimes = 0;
				this.tempScrollTop = this.toTop + this.scrollPace;
				this.scrollInterval = window.setInterval(this.scroll,20);
			}
		},
		scroll: function(){
			if (HelpTips.anchorScroll.scrollTimes < 10){
				window.scrollTo(0,HelpTips.anchorScroll.tempScrollTop);
				HelpTips.anchorScroll.tempScrollTop += HelpTips.anchorScroll.scrollPace;
				HelpTips.anchorScroll.scrollTimes++;
			}
			else {
				window.clearInterval(HelpTips.anchorScroll.scrollInterval);
			}
		}
	},

	generateArrow: function(tipWidth,tipHeight,arrowType){
		var arrow = $ffC("DIV");
		switch (arrowType)
		{
		case "arrowLeft":
			arrow.className = "arrowLeft";
			arrow.style.left = "-15px";
			arrow.style.top = (tipHeight - 22) / 2 + "px";
			break;

		case "arrowRight":
			arrow.className = "arrowRight";
			arrow.style.left = tipWidth - 8 + "px";
			arrow.style.top = (tipHeight - 22) / 2 + "px";
			break;
		
		case "arrowUp":
			arrow.className = "arrowUp";
			arrow.style.left = (tipWidth - 25) / 2 + "px";
			arrow.style.top = "-19px";
			break;
		
		case "arrowDown":
			arrow.className = "arrowDown";
			arrow.style.left = (tipWidth - 25) / 2 + "px";
			arrow.style.top = tipHeight + 3 + 25 + "px";
			break;
		}
		return arrow;
	},

	generateInputs: function(){
		var inputArr = [];
		var nextpage =this.nextpage;
		var isnextpage =this.isnextpage;
		if (this.arr[this.indexNow - 1]){
			var inputPre = $ffC("INPUT");
			inputPre.type = "button";
			if (this.arr[this.indexNow + 1]){
				inputPre.value = "上一条";
				inputPre.onclick = function(){
					HelpTips.tipOuter.closeButton.onmouseover = "";
					HelpTips.tipOuter.closeButton.onmouseout = "";
					HelpTips.tipOuter.closeButton.onclick = "";
					for (var i = 0;i < HelpTips.tipOuter.inputArr.length ;i++ ){
						HelpTips.tipOuter.inputArr[i].onclick = "";
					}
					if (HelpTips.flicker.style.display != "none"){
						HelpTips.flicker.style.display = "none";
					}
					
					document.body.removeChild(HelpTips.tipOuter);
					HelpTips.generateDiv.apply(HelpTips,HelpTips.arr[HelpTips.indexNow - 1].concat("lower"));
				}
			}
			else {
				inputPre.value = "关闭";
				inputPre.onclick = function(){
					HelpTips.tipOuter.closeButton.onmouseover = "";
					HelpTips.tipOuter.closeButton.onmouseout = "";
					HelpTips.tipOuter.closeButton.onclick = "";
					for (var i = 0;i < HelpTips.tipOuter.inputArr.length ;i++ ){
						HelpTips.tipOuter.inputArr[i].onclick = "";
					}
					if (HelpTips.flicker.style.display != "none"){
						HelpTips.flicker.style.display = "none";
					}
					mask.clean();
					HelpTips.targetElement.style.position = "";
					HelpTips.targetElement.style.zIndex = "";
					document.body.removeChild(HelpTips.transparentMask);
					document.body.removeChild(HelpTips.tipOuter);
				}
				if(isnextpage){
					var inputPre1 = $ffC("INPUT");
					inputPre1.type = "button";
					inputPre1.value = "下一页";
					
					inputPre1.onclick = function(){					
						window.location.href="/passport/"+nextpage+"?isn=1";
						
					}
					inputArr.push(inputPre1);
				}
				
			}
			inputArr.push(inputPre);
		}

		if (this.arr[this.indexNow + 1]){
			var inputNext = $ffC("INPUT");
			inputNext.type = "button";
			if (this.arr[this.indexNow - 1]){
				inputNext.value = "下一条";
			}
			else {
				inputNext.value = "继续";
			}
			inputNext.onclick = function(){
				HelpTips.tipOuter.closeButton.onmouseover = "";
				HelpTips.tipOuter.closeButton.onmouseout = "";
				HelpTips.tipOuter.closeButton.onclick = "";
				inputNext.onclick = "";
				document.body.removeChild(HelpTips.tipOuter);
				HelpTips.generateDiv.apply(HelpTips,HelpTips.arr[HelpTips.indexNow + 1].concat("plus"));
			}		
			inputArr.push(inputNext);
		}
		return inputArr;
	},

	generateCloseButton: function(tipWidth){
		var closeButton = $ffC("DIV");
		closeButton.className = "close";
		var tempLeft = tipWidth - 25;
		closeButton.style.left = tempLeft + "px";
		closeButton.style.top = "0px";
		closeButton.onmouseover = function(){
			closeButton.className = "closeOver";
		}
		closeButton.onmouseout = function(){
			closeButton.className = "close";
		}
		if (this.arr[this.indexNow + 1]){
			closeButton.onclick = function(){
				closeButton.onmouseover = "";
				closeButton.onmouseout = "";
				closeButton.onclick = "";
				for (var i = 0;i < HelpTips.tipOuter.inputArr.length ;i++ ){
					HelpTips.tipOuter.inputArr[i].onclick = "";
				}
				if (HelpTips.flicker.style.display != "none"){
						HelpTips.flicker.style.display = "none";
					}
				document.body.removeChild(HelpTips.tipOuter);				
				HelpTips.generateDiv.apply(HelpTips,HelpTips.arr[HelpTips.arr.length - 1].concat(HelpTips.arr.length));
			}
		}
		else {
			closeButton.onclick = function(){
				closeButton.onmouseover = "";
				closeButton.onmouseout = "";
				closeButton.onclick = "";
				for (var i = 0;i < HelpTips.tipOuter.inputArr.length ;i++ ){
					HelpTips.tipOuter.inputArr[i].onclick = "";
				}
				if (HelpTips.flicker.style.display != "none"){
					HelpTips.flicker.style.display = "none";
				}
				mask.clean();
				HelpTips.targetElement.style.position = "";
				HelpTips.targetElement.style.zIndex = "";
				document.body.removeChild(HelpTips.transparentMask);
				document.body.removeChild(HelpTips.tipOuter);
			}
		}
		
		return closeButton;
	},

	modules: []
}


function $ff(objName){
	if(document.getElementById){
		return document.getElementById(objName);
	}else{
		return document.all.objName;
	}
}
if( typeof $ffC == 'undefined' )$ffC = function(t){return document.createElement(t)};

