var isMinNN4  = document.layers         ? true : false;
var isMinIE4  = document.all            ? true : false;
var isW3C     = document.getElementById ? true : false; // W3C stands for the W3C standard, implemented in Mozilla (  and Netscape 6  ) and IE5
var isMinIE5  = isW3C;
var mouseLeft = 0;
var mouseTop  = 0;

function setMouseCoordinate( e ) {
	var newLeft = 0;
	var newTop  = 0;
	
	if ( isMinIE4 ) {
		newLeft = document.body.scrollLeft + event.clientX
		newTop  = document.body.scrollTop  + event.clientY
	} else if ( isMinNN4 || isW3C ) {
		newLeft = e.pageX;
		newTop  = e.pageY;
	}
	
	if ( Math.abs( newLeft - mouseLeft ) > 10 ) mouseLeft = newLeft;
	if ( Math.abs( newTop  - mouseTop  ) > 10 ) mouseTop  = newTop;
}

document.onmousemove = setMouseCoordinate;

function findElementPos( obj ) {
	var curleft = 0;
	var curtop  = 0;
	if ( obj.offsetParent ) {
		curleft = obj.offsetLeft;
		curtop  = obj.offsetTop;
		while ( obj = obj.offsetParent ) {
			curleft += obj.offsetLeft;
			curtop  += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function ttDisplay( pObj, pLayer ) {
	ttDisplay2( pObj, pLayer, 20, 30 );
}

function ttDisplay2( pObj, pLayer, pLeft, pTop ) {
	var theObj  = document.getElementById( pObj );
	var leftTop = findElementPos( theObj );
	var newLeft = leftTop[0] + pLeft;
	var newTop  = leftTop[1] + pTop;

	ttDisplayLayer( pLayer, newLeft, newTop );
}

function ttDisplayLayer( pLayer, pLeft, pTop ) {

	if ( isMinIE4 || isW3C ) {
		if ( isW3C ) {
		    document.getElementById( pLayer ).style.left = pLeft;
		    document.getElementById( pLayer ).style.top  = pTop;

		} else {
			document.getElementById( pLayer ).style.pixelLeft = pLeft;
    		document.getElementById( pLayer ).style.pixelTop  = pTop;
    	}
		document.getElementById( pLayer ).style.display    = "inline";
		document.getElementById( pLayer ).style.visibility = "visible";
	} else if ( isMinNN4 ) {
		document.getElementById( pLayer ).left       = pLeft;
		document.getElementById( pLayer ).top        = pTop;
		document.getElementById( pLayer ).display    = "inline";
		document.getElementById( pLayer ).visibility = "show";
	}
}

function ttHide( pLayer ) {
	if ( isMinIE4 || isW3C ) {
		document.getElementById( pLayer ).style.visibility = "hidden";
	} else if ( isMinNN4 ) {
		document.getElementById( pLayer ).visibility = "hidden";
	}
}


function DeletetionVerify( pMessage, pActionCode, pIdName, pIdValue )
{
	if ( pMessage.length < 1 ) pMessage = 'Confirm Delete';
	
	doConfirm = ( pMessage == 'skip' ? true : confirm( pMessage ) );
	
	if ( doConfirm ) {
		document.forms.theForm.actionCode.value = pActionCode;
		pIdName.value = pIdValue;
		document.forms.theForm.submit();
	}
}

function AcceptReturn( e, pForm, pPageCode, pActionCode )
{
	if ( e.keyCode == 13 ) {
		pForm.pageCode.value   = pPageCode;
		pForm.actionCode.value = pActionCode;
		pForm.submit();
	}
}

function PhoneFormat( pPhone )
{
	origString = pPhone;
	testString = pPhone;
	newString  = '';

	if ( testString != '' ) {

		var textLen   = testString.length;
		var newString = '';
		var testChar  = '';

		for ( currPos = 0; currPos < textLen; currPos++ ){
			testChar = testString.substr( currPos, 1 );
			
			if ( testChar == '*' ) {
				newString = origString;
				break;
			}

			if ( testChar >= '0' && testChar <= '9' ) {

				switch ( newString.length ) {
					case 3:  newString = newString + "-"; break;
					case 7:  newString = newString + "-"; break;
					case 12: newString = newString + "x"; break;
				}

				newString = newString + testChar;
			}
		}
	}
	
	return ( newString );
}

function PhoneCheck( pWhichPhone )
{
	testString = PhoneFormat( pWhichPhone.value );
	if ( testString != '' ) pWhichPhone.value = testString;
}

function PhoneCheck2( pWhichPhone )
{
	origString = pWhichPhone.value;
	testString = pWhichPhone.value;
	
	if ( testString != '' ) {

		var textLen   = testString.length;
		var newString = '';
		var testChar  = '';

		for ( currPos = 0; currPos < textLen; currPos++ ){
			testChar = testString.substr( currPos, 1 );
			
			if ( testChar == '*' ) {
				newString = origString;
				break;
			}

			if ( testChar >= '0' && testChar <= '9' ) {
				
				switch ( newString.length ) {
					case 3:  newString = newString + "-"; break;
					case 7:  newString = newString + "-"; break;
				}

				if ( newString.length < 12 ) newString = newString + testChar;
			}
		}
		
		pWhichPhone.value  = newString;
	}
}

function openNewWindow( pURL, pWindowName, pWidth, pHeight ) {
	var windowOptions = "toolbar = 0, "
					  + "location = 0, "
					  + "directories = 0, "
					  + "status = 0, "
					  + "menubar = 0, "
					  + "scrollbars = 1, "
					  + "resizable = 1, "
					  + "width = " + pWidth + ", "
					  + "height = " + pHeight;
	newWindow = window.open( pURL, pWindowName, windowOptions );
	newWindow.focus();
}
