// ********************************************************************************

function displayElementByMe(eventID, handlingID, display_type, center, matchingWidthID){
	var mtop, mleft, mwidth;

	mtop = getElementPosition(eventID).top;
	mleft = getElementPosition(eventID).left;



	if(matchingWidthID) mwidth = document.getElementById(matchingWidthID).offsetWidth;

	if(document.getElementById(handlingID)){
		var obj = document.getElementById(handlingID);

		obj.style.top = mtop;
		obj.style.left = mleft;
		obj.style.width = mwidth;
		obj.style.display= display_type;
	}
	return false;
}


// http://blog.josh420.com/archives/2007/10/centering-an-element-on-the-page-with-javascript-cross-browser.aspx
// how to call: centerElement(document.getElementById('divModalLayer'));

function centerElement(elem, display_type) {

	var viewport = getViewportDimensions();
	//var oWidth = document.getElementById(elem).offsetWidth;
	var oWidth = elem.offsetWidth;
	oWidth = parseInt(oWidth);
	//var wWidth = document.getElementById(elem).style.width;
	var wWidth = elem.style.width;
	wWidth = parseInt(wWidth);

	//alert("oWidth = " + oWidth);
	//alert("wWidth = " + wWidth);

	var tWidth;
	if(oWidth > 0){
		tWidth = oWidth;
		//alert("yes oWidth");
	}
	if(wWidth > 0){
		tWidth = wWidth;
		//alert("yes wWidth");
	}

	var left = (viewport.width == 0) ? 50 : parseInt((viewport.width - tWidth) / 2, 10);
	var top = (viewport.height == 0) ? 50 : parseInt((viewport.height - elem.offsetHeight) / 2, 10);
	//alert("top = " + top);
	//alert("left = " + left);

	elem.style.left = left + 'px';
	elem.style.top = top + 'px';
	if(display_type) elem.style.display = display_type;

	viewport, left, top, elem = null;
	return false;
}


// http://bytes.com/forum/thread148568.html
// how to call -->  alert(getElementPosition('popup1234').top+'|'+getElementPosition('popup1234').left);
function getElementPosition(elemID){
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail){
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft,top:offsetTop};
}
// ********************************************************************************
function getElementDimensions(id_in){
	if(!id_in) return false;

	/*var obj = document.getElementById(id_in);
	if(!obj) return false;
	if(obj) alert("yes this element exists");

	var oWidth = 0;
	var wWidth = 0;
	var oHeight = 0;
	var wHeight = 0;

	oHeight = obj.offsetHeight;
	//wHeight = parseInt(obj.style.height);

	oWidth = obj.offsetWidth;
	//wWidth = parseInt(obj.style.width);

	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
		oHeight += document.body.height;
		oWidth += document.body.width;
	}

	return {width: oWidth, height: oHeight};*/
	
}
// ********************************************************************************

// http://blog.josh420.com/archives/2007/10/centering-an-element-on-the-page-with-javascript-cross-browser.aspx
function getViewportDimensions() {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}

// ********************************************************************************




function isblank(s)
{
	//If spaces, new lines, or tabs are found, true is returned
	//true meaning signal the error message of batch validation

	for (var i=0; i<s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c !='\n') && (c != '\t')) return false;
	}//end for
	return true;
}//end isblank function


// ********************************************************************************


function onBlur_phone(str)
{
	alert(str.value.substr(0,3));
	alert(str.value.substr(3,3));
	alert(str.value.substr(6,4));
	var phonereturn = "(" + str.value.substr(0,3) + ")" + str.value.substr(3,3) + "-" + str.value.substr(6,4);

	if( (str.value.length != 10) && (str.value.length != 0) )
	{
		//alert("Please enter 10 numbers" + "\n" + "You entered " + str.value.length + " numbers.");
		alert("Please enter a 10-digit number with no dashes or spaces.");
		str.focus();
		str.select();
	}

	else if(str.value.length == 0) null;

	else
	{
		var legalChr = "0123456789";
		for(i=0;i<str.value.length;i++)
		{
			myChar = str.value.charAt(i);
			if(legalChr.indexOf(myChar) < 0)
			{
				alert("Please enter numbers only.");
				str.focus();
				str.select();
				break;
			}
		}
		//str.value = phonereturn;
	}
}


// ********************************************************************************


function onFocus_phone(str)
{
	var put_str = new String(str.value);
	var stripped = put_str.replace(/[\(\)\.\-\ ]/g, '');
	//str.value = stripped;
	str.focus();
	//str.select();
}


// ********************************************************************************


function Selected_Count(the_element)
{
	var checked_counter = 0;

	// IF RADIO BUTTON
   	if (( isNaN(the_element.length) ) || (the_element.length == null))
	{
		// IF RADIO BUTTON IS CHECKED, SET CHECKED_COUNTER = 1
		if (the_element.checked == true)
		{
          	checked_counter ++;
		}
	}

	// IF CHECKBOXES
   	else
	{
     	for (i=0; i<the_element.length; i++)
		{
			// DETERMINE HOW MANY CHECKBOXES ARE CHECKED
			if (the_element[i].checked == true)
			{
               	checked_counter ++;
			}
        	}
   	}

	return(checked_counter);
}

// ********************************************************************************