﻿
var VFArr;
var OldClassName;

function initVFArr() {
	var arr = document.getElementsByTagName("input");
	VFArr = new Array();
	for(var i=0; i < arr.length - 1; i++)
	{
		if(arr[i].type == "text" || arr[i].type == "password") {
			VFArr[i] = arr[i].id;
		}
	}
	VFArr[arr.length] = "";
}

function getAbsoluteLeft(objectId) {
	o = $(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	o = $(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}

function getElementWidth(objectId) {
	x = $(objectId);
	return x.offsetWidth;
}

function tipInfo(info)
{
	return '<div class="formTip"><div class="content">' + 
			info + 
			'</div><div class="bottom"></div></div>';
}

function showtip(objectId, tipId, _innerHTML, isHide)
{		
	if(!isHide) {
		var arrowOffset = getElementWidth(objectId) + 10;
		var clickElementy = getAbsoluteTop(objectId);
		var clickElementx = getAbsoluteLeft(objectId) + arrowOffset;
		$(tipId).style.left = clickElementx + "px";
		$(tipId).style.top = clickElementy + "px";
		$(tipId).style.position = "absolute";
		$(tipId).innerHTML = _innerHTML;
		$(tipId).style.display = "block";
	} else {
		$(tipId).style.display = "none";
	}	
}

//显示绿色对勾
function showtip_ok(objectId)
{
	$(objectId + "_tip2").style.display = "none";
}

//显示提示信息层
function showtip_info(objectId, info)
{
	for(var i=0; i < VFArr.length - 1; i++)
	{
		if (!$(VFArr[i] + "_tip2"))
		{
			continue;
		}
		if ($(VFArr[i] + "_tip2").style.display == "block"
			&& objectId != VFArr[i])
		{
			return;
		}
	}
    
	for(var i=0; i < VFArr.length - 1; i++)
	{
		if (!$(VFArr[i] + "_tip2"))
		{
			continue;
		}
		if (objectId == VFArr[i])
		{
            showtip(objectId, objectId + "_tip2", tipInfo(info), false);
		}
		else
		{
			$(VFArr[i] + "_tip2").style.display = "none";
		}
	}
}

//得到焦点
function VF_onfocus(objectId)
{
    showtip_info(objectId, $(objectId).attributes["tip"].nodeValue);
}

//失去焦点
function VF_onblur(objectId)
{
    showtip_ok(objectId);
}

