/* Popup blocker detection */
windowOpened = 0;
function checkForWindow() {
	if (!windowOpened) {
		alert('Please disable your popup blocker\nin order to use some of our advanced features.');
	} else {
		windowOpened = 0;
	}
}

function showActivity() {
	element = document.getElementById('activity_icon');
	if (element) {element.src='img/indicator.gif';}
}

function hideActivity() {
	element = document.getElementById('activity_icon');
	if (element) {element.src='img/spacer.gif';}
}

function makeAjaxRequest(target_url) {
	if (callInProgress(xmlhttp)) {
		xmlhttp.abort();
	}
	
	xmlhttp.open("GET", target_url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			response = xmlhttp.responseText; 
			if (response!='ERR' && response>0) {
				launchWin('popups/popup_im.cfm?im_id='+xmlhttp.responseText,'IM_'+Math.round(Math.random()*100000000000),400,400,0,0,1);
				setTimeout("checkForWindow()",5000);
			}
        }
    }
    xmlhttp.send(null);
}

function updateAjaxElement(target_element, target_url) {
	if (document.getElementById(target_element)) {
		var element = document.getElementById(target_element);
		
		if (callInProgress(xmlhttp)) {
			xmlhttp.abort();
		}
		
		xmlhttp.open("GET", target_url);
	    xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
		        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		            element.innerHTML = xmlhttp.responseText;
					
					if (ajx_ctr_MembersOnline != '' && element.innerHTML != ajx_ctr_MembersOnline) {
						highlightElement('ajx_OnlineMembersString');
					}
					ajx_ctr_MembersOnline = element.innerHTML;
		        }
				hideActivity();
			}
	    }
	    xmlhttp.send(null);
	}
}

function makeCalls() {
	if (document.getElementById('ajx_OnlineMembersValue')) {
		showActivity();
	}
	
	// Text Message Check
	makeAjaxRequest('ajax/ajax_requests.cfm?request_type=1&nocache='+Math.round(Math.random()*100000000000));
	
	// Online Member Count Update
	if (document.getElementById('ajx_OnlineMembersValue')) {
		setTimeout("updateAjaxElement('ajx_OnlineMembersValue', 'ajax/ajax_requests.cfm?request_type=2&nocache='+Math.round(Math.random()*100000000000))",2000);
	}
}