function getChecked(obj)
{
	checkedItems = ''
	if(obj.length)
	{
		for(i=0; i < obj.length; i++)
		{
			if(obj[i].checked)
			{
				if(checkedItems)
					checkedItems += ',' + obj[i].value;
				else
					checkedItems = obj[i].value;
				
			}
		}
	} else {
		if(obj.checked)
			checkedItems = obj.value;
	}
	return checkedItems;
}
function showLoadingBar()
{
	if($('loadingBar'))
		$('loadingBar').style.display = 'block';
}

function hideLoadingBar()
{
	if($('loadingBar'))
		$('loadingBar').style.display = 'none';
}
function signUp()
{
	DWREngine._execute('Functions/CFCs/SearchSchools.cfc', null, 
			'signup', 
			$('emailAddrss').value,
			signUpFinish);
}
function signUpFinish()
{
	$('EmailDiv').innerHTML = 'Thanks!';
	$j('#EmailDiv').animate({ height: 'hide', opacity: 'hide' }, 'slow');
}
var helpBoxHovered = new Array();
function setHelpBoxes()
{
	$j(".helpButton").each(function(index) {
		$j(this).attr({
    		id: "helpButton_" + (index+100)
    	});
		$j(this).next(".popupBalloon").attr({
    		id: "helpPopup_" + (index+100)
    	});
	});
	
	/*var browser=navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		leftAdjust = 10;
		topAdjust = -10;
	} else {
		leftAdjust = 0;
		topAdjust = 0;
	}*/
	$j(".helpButton").unbind("hover");
	$j(".helpButton").hover(function() {
		var currentID = $j(this).attr("id").replace("helpButton_","");
		helpBoxHovered[currentID] = 0;
		$j("#helpPopup_"+currentID).hover(function() {
			helpBoxHovered[currentID] = 1;
		}, function() {
			helpBoxHovered[currentID] = 0;	
			setTimeoutHideHelpBox(currentID);
		})
		ifIE6HideSelect();
		document.body.appendChild(document.getElementById('helpPopup_'+currentID));
		//Set to position of the help box
		newLeft = $j(this).offset().left;
		newTop = $j(this).offset().top;

		//Move left
		newLeft -= 50;
		//Move by the height of the popup box (plus a general offset number)
		newTop -= ($j("#helpPopup_"+currentID).height() + 100);
		

		$j("#helpPopup_"+currentID).css({left: newLeft, top: newTop});
		
		newTop -= 50;
		
		$j("#helpPopup_"+currentID).stop(true, true).animate({opacity: "show", top: newTop}, "slow");
	}, function() {
		var temp = $j(this).attr("id").replace("helpButton_","");
		setTimeoutHideHelpBox(temp);
	});
}
function setTimeoutHideHelpBox(temp)
{
	setTimeout("hideHelpBox(" + temp + ");",500);
}
function hideHelpBox(id)
{	
	if (helpBoxHovered[id] == 0) {
		button_id="helpButton_"+id;
		popup_id="helpPopup_"+id;
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			leftAdjust = 10;
			topAdjust = -10;
		}
		else {
			leftAdjust = 0;
			topAdjust = 0;
		}
		ifIE6UnhideSelect();
		
		newTop = $j("#" + button_id).offset().top ;
		newTop -= ($j("#"+popup_id).height() + 150);

		
		$j("#" + popup_id).animate({
			opacity: "hide",
			top: newTop
		}, "fast");
		
		
		setTimeout("moveBackUnderButton(" + id + ");",500);
	}
}
function moveBackUnderButton(id)
{
	button_id="helpButton_"+id;
	popup_id="helpPopup_"+id;
	$j("#"+button_id).after($j("#"+popup_id));
}


function ifIE6HideSelect()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if((navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1))
		$j("select").css({
			"visibility": "hidden"
		});
}

function ifIE6UnhideSelect()
{
	$j("select").css({
		"visibility": "visible"
	});
}
function ajaxReturn(r)
{
	setHelpBoxes();
	hideLoadingBar();
	var iFrame = document.getElementById('mainIframe');
	iFrame.src = '';
	iFrame.contentWindow.document.open();
	iFrame.contentWindow.document.write(r);
	iFrame.contentWindow.document.close();
}
function searchNearThisSchool(address,city)
{
	hidePopup();
	document.getElementById('Address').value = address;
	for (i = 0; i < document.getElementById('City').options.length; i++) 
		if (document.getElementById('City').options[i].value == city) 
		{
			document.getElementById('City').selectedIndex = i;
			break;
		}
	document.getElementById('Distance').selectedIndex = 1;
	document.getElementById('SearchMethod_Address').checked = true;
	searchSchools();
}
