function getObj(name) {
	if (document.getElementById) {
		if(document.getElementById(name)) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		}
	}
	else if (document.all) {
		if(document.all[name]) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
	}
	else if (document.layers) {
		if (document.layers[name]) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		}
	}
}


function checkLen(target, targetCharsCounter, maxChars) {
	len = target.value.length;
	
	if ( len == 1 && target.value.substring(0, 1) == " " ) {
		target.value = ""; len = 0;
	}
	
	if ( len > maxChars ) {
		target.value = target.value.substring( 0, maxChars );
		charsLeft = 0;
	} else {
		charsLeft = maxChars - len;
	}
	oCounter = new getObj(targetCharsCounter);
	oCounter.obj.value = charsLeft;
}


//------ resizer
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function resizeContent(originalSize) {
	if(originalSize == undefined)
		iOriginalSize = null;
	else
		iOriginalSize = originalSize;
		
	//get objects
	oLeftContainer 	= new getObj('container_left');
	oRightContainer = new getObj('container_right');
	oContent 				= new getObj('alt_middle_3');
	
	//test to see if they exist
	if(oLeftContainer.obj && oRightContainer.obj && oContent.obj && oContent.style) {
		//iLeftContainerY		= findPosY(oLeftContainer.obj);
		//iRightContainerY	= findPosY(oRightContainer.obj);
		
		//get sizes
		iOffset							= 20;
		iLeftContainerSize	= oLeftContainer.obj.offsetHeight;
		iRightContainerSize	= oRightContainer.obj.offsetHeight;
		iContentSize 				= oContent.obj.offsetHeight;

		if(iOriginalSize == null)
			iOriginalSize			= iContentSize;
		
		//choose the larger one
		iSize = Math.max(iLeftContainerSize, iRightContainerSize);
		iSize = Math.max(iSize, iOriginalSize);
		
		oContent.style.height = iSize + 'px';
		if(iOriginalSize != null)
			return iOriginalSize;

		return 0;
	}
}


function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}


//used on home page only
function resizeIndex() {
	oLeftColumn 	= new getObj('middle_middle_1');;
	oRightColumn 	= new getObj('middle_middle_3');

	oLeftContainer 	= new getObj('container_left');
	oRightContainer = new getObj('container_right');
	
	iLeftHeight 	= oLeftColumn.obj.offsetHeight;
	iRightHeight 	= oRightColumn.obj.offsetHeight;
	iMax = Math.max(iLeftHeight, iRightHeight);

	iLeftCHeight 	= oLeftContainer.obj.offsetHeight;
	iRightCHeight 	= oRightContainer.obj.offsetHeight;
	iCMax = Math.max(iLeftCHeight, iRightCHeight);

	if( iCMax > iMax ) {
		iCMax -= 0;
		oLeftColumn.style.height 		= iCMax + 'px';
		oRightColumn.style.height 	= iCMax + 'px';
	}
	else {
		iMax -= 0;
		oLeftColumn.style.height 		= iMax + 'px';
		oRightColumn.style.height 	= iMax + 'px';
	}
}
	
	
function getWW() {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			return window.innerWidth-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			return document.body.offsetWidth-20;
		}
	}
}


function popItUp() {
	mywidth = 300;
	myheight = 300;
	myright =	getWW();
	myright -= (25 + mywidth);
	mytop = 10;

	window.open('homepopup.php', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width = ' + mywidth + ',height = ' + myheight + ',left = ' + myright + ',top = ' + mytop);
}
	
	
function showHide( subNum ) {	
		oB = new getObj('sub' + subNum);
		oBox = oB.obj;
		oBoxStyle = oB.style;
		
		oF = new getObj('foot' + subNum);
		oFooter = oF.obj;
		oFooterStyle = oF.style;
		
		oI = new getObj('img' + subNum);
		oImage = oI.obj;

		if( !oBox || !oFooter || !oImage )
			return false;
			
		if( oBoxStyle.display != 'block' ) { //box closed - open it
			oBoxStyle.display = 'block';
			oFooterStyle.display = 'none';
			oImage.src = _globalPathRoot + 'images/icons/btn_minus.gif';
    }
		else { //box opened - close it
			oBoxStyle.display = 'none';
			oFooterStyle.display = 'block';
			oImage.src = _globalPathRoot + 'images/icons/btn_plus.gif';
		}
		
		//call the resize function each time when the box closes/opens
		resizeContent(origSize);
		adjustBoxes();
}
	
	function changeSubmit() {
		oSubmit = new getObj('submitMemberInfoID');
		oAgree = new getObj('agree');
		
		if(oSubmit.obj && oAgree.obj) {
			if(oAgree.obj.value) {
				oSubmit.obj.disabled = false;
			}
			else {
				oSubmit.obj.disabled = true;
			}
		}
		else
			return false;
	}

	function checkSubmit() {
		oSubmit = new getObj('submitMemberInfoID');
		oAgree = new getObj('agree');

		if(oSubmit.obj && oAgree.obj) {
			if(!oAgree.obj.checked) {
				oSubmit.obj.disabled = true;
				alert('You have to read the Terms of Use and Privacy Policy and agree.');
				return false;
			}
			else
				return true;
		}
		else
			return false;
	}

function setStyles(object) {
	object.T_BGCOLOR='#0E7982';
	object.T_BORDERWIDTH=0;
	object.T_FONTCOLOR='#C5F3F6';
	object.T_OFFSETX=-20;
	object.T_OFFSETY=20;
	object.T_FONTFACE="arial,helvetica,sans";
	object.T_FONTSIZE="11px";
	object.T_WIDTH = "150px";
	object.T_OPACITY = 85;
	object.T_PADDING = 3;
	object.T_TEXTALIGN='center';
}

//-------- AJAX ----------
function createRequestObject() {
	req = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		}
		catch(e) {
			req = false;
		}

		// branch for IE/Windows ActiveX version
	}
	else if(window.ActiveXObject) {
	 	try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				req = false;
			}
		}
	}
	
	return req;	
}

/*
function createRequestObject2() {
	var oRequest;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer") {
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		oRequest = new XMLHttpRequest();
	}
	
	return oRequest;
}
*/

// -- create xmlhttprequest object --
var http = createRequestObject(); 
// -- create xmlhttprequest object --

function voteForPoll() {
	if( !http ) {
		return false;
	}

	oChoiceSelected = new getObj('choiceSelected');

	if( !oChoiceSelected.obj ) {
		return false;
	}
	
	if( !oChoiceSelected.obj.value ) {
		return false;
	}

	http.open( 'get', _globalPathIndex + 'ajax/polls.php?answer=' + oChoiceSelected.obj.value );
	http.onreadystatechange = handlePoll; 
	http.send(null);
}

function voteForTrivia() {
	if( !http ) {
		return false;
	}

	oChoiceSelected = new getObj('choiceSelected');

	if( !oChoiceSelected.obj ) {
		return false;
	}
	
	if( !oChoiceSelected.obj.value ) {
		return false;
	}

	http.open('get', _globalPathIndex + 'ajax/trivia.php?answer=' + oChoiceSelected.obj.value + '');
	http.onreadystatechange = handleTrivia; 
	http.send(null);
}


function handlePoll() {
	/* 
		Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished 
	*/
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		
		oPollResults = new getObj('pollResults');
		oPollCastVote = new getObj('pollCastVote');
		
		if( !oPollResults.obj || !oPollCastVote.style )
			return false;
			
		oPollResults.obj.innerHTML = response;
		oPollCastVote.style.display = 'none';
	}
}

function handleTrivia() {
	/* 
		Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished 
	*/
	if(http.readyState == 4){ // Finished loading the response
		var response = http.responseText;
		
		oTriviaResults = new getObj('triviaResults');
		oTriviaCastVote = new getObj('triviaCastVote');
		
		if( !oTriviaResults.obj || !oTriviaCastVote.style ) 
			return false;
		
		oTriviaResults.obj.innerHTML = response;
		oTriviaCastVote.style.display = 'none';
	}
}
//-------- AJAX END ----------
