var isNN = (navigator.appName.indexOf("Netscape")!=-1);

var posx = 0;
var posy = 0;
var ev;
var bAutotab = true;
var objGhItem,objGMaxLength,objGlinkItem;

//Dummy function declare for implementing any page 
//function doEnterKeyAction(){}

function getMousePositionReg(e)
{
	try
	{	
		if (!e) 
		{
			if( window.event ) 
			{
				var e = window.event;
			}
		}
		if (e) 
		{
			if (e.pageX || e.pageY)
			{
				posx = e.pageX;
				posy = e.pageY;
			}
			
			else if (e.clientX || e.clientY)
			{
				posx = e.clientX + document.body.scrollLeft;
				posy = e.clientY + document.body.scrollTop;
			}
		}
	} catch(e){}
}

function hideallTD()
{
		document.getElementById('Datatext').className = "hideit";
		document.getElementById('custCode').className = "hideit";
		document.getElementById('checkImg').className = "hideit";
		
		var objTrFiosData = document.getElementById('tdFiosData')
		if (objTrFiosData != null)
			objTrFiosData.className = "hideit";
}

function showCallout(a_strParentObjName,a_strHeaderText)
{
	var objTblMainCopy	= null;
	var objTblMain		= null;
	var objContainer	= null;
	
	try
	{
		//Close all existing windows
		closeAccPopReg();
		
		//Build the content for callout
		displayHelpReg(0, 0, a_strHeaderText)
		
		objTblMain	= document.getElementById('tblHelp');
		
		objTblMainCopy = objTblMain.cloneNode(true);
		objTblMainCopy.className	= "helpTableClass";
		
		objContainer = document.getElementById(a_strParentObjName);
		
		if (objContainer != null)
		{
			objContainer.innerHTML = "";
			objContainer.appendChild(objTblMainCopy);
		}
	}
	catch(e){}

}	
	
function closeAccPopReg()
{
	var objAccountContainer = null;
	var objAvailContainer = null;
	
	try
	{	
		document.getElementById('tblHelp').className = "hideit";
		document.getElementById('tblHelp').style.display="none";
		objAccountContainer = document.getElementById("spanCalloutAccount");
		objAvailContainer = document.getElementById("spanCalloutContainer");
		
		if(objAccountContainer != null)
			objAccountContainer.innerHTML = "";
			
		if(objAvailContainer != null)
			objAvailContainer.innerHTML = "";
		
		
	}catch(e){}
}

function displayHelpReg(a_intPosX, a_intPosY, a_strHeaderText)
{
	var C_STR_COMMONTEXT_CSS = "commtext";
	var C_STR_COMMONDATA_CSS = "commtextData";
	var C_STR_AVAILABILITY_CSS = "padded_content_rc_left";	 
	var intTblWidth;
	var strUserIdText;
	var objExistNode;
	var objTdTextNode; 
	var objTbl;
	var objTblMain;
	var strDetailText = "";
	
	strUserIdText	= 'dummyuser';
	intTblWidth		= 100;
	objTbl			= document.getElementById('helpheader1');
	document.getElementById("Datatext").style.width = "175px";
	
	if (a_strHeaderText == "FiosData Account Number")
		objTdTextNode	= document.createTextNode("Account Number");
	else	
		objTdTextNode	= document.createTextNode(a_strHeaderText);
		
	//If any text node exist then it will removed
	if (objTbl.childNodes.length > 0 )
	{
		objExistNode = objTbl.childNodes[0];
		objTbl.removeChild(objExistNode);
	}

	objTbl.appendChild(objTdTextNode);
	
	hideallTD();
	
	if (a_strHeaderText == "Bank Routing Number")
	{
		document.getElementById('checkImg').className = C_STR_COMMONTEXT_CSS;
	}
	else if(a_strHeaderText == "Account Number")
	{
		document.getElementById('checkImg').className = C_STR_COMMONTEXT_CSS;
	}
	else if(a_strHeaderText == "FiosData Account Number")
	{
		var objTrFiosData = document.getElementById('tdFiosData')
		if (objTrFiosData != null)
			objTrFiosData.className = C_STR_COMMONTEXT_CSS;
	}
	else if(a_strHeaderText == "Customer Code")  
	{
		a_intPosX = 320;
		document.getElementById('custCode').className = C_STR_COMMONTEXT_CSS;
	}
	else if(a_strHeaderText == "Check User ID Availability")  
	{
		document.getElementById('Datatext').className = C_STR_AVAILABILITY_CSS;

		if (document.getElementById('hdnUserID').value != '') 
			strUserIdText = document.getElementById('hdnUserID').value;
			
		strDetailText = strUserIdText;
	}
	else if(a_strHeaderText == "Temporary PIN")  
	{
		document.getElementById('Datatext').className = C_STR_COMMONTEXT_CSS;	
		strDetailText = "Your request to deliver the PIN to your home phone is being processed. ";
		strDetailText += "Your home phone will be called shortly. <B>Please be prepared to write the PIN down so you can continue with the registration process.</B>";	
		
		document.getElementById("Datatext").style.width = "300px";		
		
		if ( document.getElementById('hdPinCalloutMsg') != null ) 
		{
			if (document.getElementById('hdPinCalloutMsg').value == "EMAIL")
				strDetailText = "Your request to deliver the PIN to your email is being processed.  Please check your email in 15 minutes.  Once you receive the email, you can complete the registration process."
			
			if ( document.getElementById('hdPinCalloutMsg').value == "USMAIL")
				strDetailText = "Your request to deliver the PIN to your mailing address was processed.  Once you receive your PIN in the mail, please come back to verizon.com to complete the registration process."
				
			if ( document.getElementById('hdPinCalloutMsg').value == "RESETPIN_ADIALER")
				strDetailText = "Your request to deliver a PIN to your home phone is being processed. Your home phone will be called shortly. <b>Please be prepared</b> <b>to write the PIN down so you can continue with the process. Or, you can return later and select the Forgot User ID/Password link again</b>.";
				
			if ( document.getElementById('hdPinCalloutMsg').value == "RESETPIN_USMAIL")
				strDetailText = "Your request to deliver the PIN to your mailing address was processed. Once you receive your PIN in the mail, please come back to verizon.com and select the Forgot User ID/Password link.";				
			
			if ( document.getElementById('hdPinCalloutMsg').value == "RESETPIN_EMAIL")
				strDetailText = "Your request to deliver the PIN to your email is being processed.  Please check your email in 15 minutes.  Once you receive the email, please come back to verizon.com and select the Forgot User ID/Password link.";
				
		}
	}
	else if (a_strHeaderText == "Password Hint")
	{
		document.getElementById('Datatext').className = C_STR_COMMONTEXT_CSS;
		intTblWidth = 250;
		a_intPosX	= 335;
	}
	else if (a_strHeaderText == "Security Code")
	{
		document.getElementById('Datatext').className = C_STR_COMMONTEXT_CSS;
		intTblWidth = 250;
	}
	else 
	{
		document.getElementById('Datatext').className = C_STR_COMMONDATA_CSS;
		strDetailText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex."
		intTblWidth = 375;
	}
	if (strDetailText != "")
	{
		var objLabel		= document.getElementById('lblTxt');
		objLabel.innerHTML  = strDetailText;
	}
	
	objTblMain				= document.getElementById('tblHelp');
	objTblMain.style.width	= intTblWidth;
	
	if (( a_intPosX > 0 )&& (a_intPosY > 0 ))
	{
		objTblMain.style.left	= a_intPosX;
		objTblMain.style.top	= a_intPosY;
		objTblMain.className	= "helpTableClass";
	}
	
}

function IsNumeric(a_objInput)
{
	var intKeyCode;
	if (navigator.appName.indexOf("Netscape") < 0)
	{
		if (a_objInput != null)
		{
			intKeyCode	=	event.keyCode;
			
			if(intKeyCode	==	9 && (eval(a_objInput).focus == true)) 
			{ 
				event.returnValue=false; 
			}
			if((intKeyCode > 47 && intKeyCode < 58)||(intKeyCode == 8)||(intKeyCode == 9))
			{
				return true;
			}
			else
			{
				event.returnValue = false;
			}
		}
	}
}

function AutoTab( a_objHItem, a_intMaxLength, a_objLinkItem )
{
	objGhItem			=	a_objHItem;
	objGMaxLength		=	a_intMaxLength;
	objGlinkItem		=	a_objLinkItem;
	//IsNumeric(a_objHItem);
	document.onkeydown	=	EventAutoTab;
}

function EventAutoTab(e)
{
	var vKeyCode,oItem;
	try
	{
		if (navigator.appVersion.indexOf('Mac') != -1)
		{
			return;
		}
		else
		{
			// validate the browser, If the browser the Netscape 
			if (isNN)
			{
				oItem = eval('document.'+objGlinkItem);
			}
			else
			{
				oItem = eval(objGlinkItem);
			}

			e = e||window.event;

			vKeyCode =  e.keyCode? e.keyCode : 
						e.charCode? e.charCode :
						e.which? e.which : void 0;
			
			if(e.shiftKey || e.ctrlKey || e.altKey);
			
			if(vKeyCode == 9 && e.shiftKey && e.ctrlKey)
			{	return;}

			switch(e.keyCode)
			{
				//case 13 : doEnterKeyAction(); return;
				case 37 : return;
				case 39 : return;
				case 16 : return;
				case 46 : return;
			}
			
			if (e.keyCode != 9 )
			{
				if( oItem != null )
				{
					if(bAutotab && (String(oItem.value).length == 0) && (String(objGhItem.value).length == objGMaxLength) && (e.keyCode != 8))
					{
						oItem.focus();
					}
				}
			}
		}
	}
	catch(e){}
	finally
	{
		bAutotab			= true;
		document.onkeydown	= "";
	}
	
}


function stopAutoTab()
{
	bAutotab = false;
}

function autoTab2(objInput,intLen, e) 
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(objInput.value.length >= intLen && !containsElement(filter,keyCode)) 
	{
		objInput.value = objInput.value.slice(0, intLen);
		objInput.form[(getIndex(objInput)+1) % objInput.form.length].focus();
	}
	
	function containsElement(arr, ele) 
	{
		var blnFound = false, index = 0;
		while(!blnFound && index < arr.length)
			if(arr[index] == ele)
				blnFound = true;
			else
			index++;
		return blnFound;
	}

	function getIndex(objInput) 
	{
		var index = -1, i = 0, blnFound = false;
		while (i < objInput.form.length && index == -1)
			if (objInput.form[i] == objInput)index = i;
			else i++;
		return index;
	}
	return true;
}
	

