function ge(ident) {
	try {
		return document.getElementById(ident);
	} catch (error) {
		if (_debug) alert(error);
		return null;
	}
}

function trim(_str) {
    try {
        return _str.replace(/^\s*|\s*$/g, "");
    } catch (error) {
        return _str;
    }
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    	if (confirm("Your browser is unable to handle tampabay.com advanced search functionality.\n\nPress OK to upgrade"))
    		document.location.href='http://www.getfirefox.com/';
    }
}

function isNumeric(strString) {
	if (strString.length == 0)
		return false;

	var strValidChars = "0123456789.-";
	var strChar;
	var _result = true;

	for (i = 0; i < strString.length && _result; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			_result = false;
	}

	return _result;
}

//-- RANTS -------------------------------------------------------------------

var RANT_MAX_LEN = 250;

function hilite(obj, state) {
    obj.style.backgroundColor = (state) ? "FloralWhite" : "Snow";
    return true;
}

function limitRantText(obj) {
    var elem = document.forms['rant'].elements['comment'];
    if (elem.value.length > RANT_MAX_LEN)
        elem.value = elem.value.substring(0, RANT_MAX_LEN);
    else
        document.getElementById("rantCharCount").innerHTML = RANT_MAX_LEN - elem.value.length;
}

function canSubmitRantForm() {
	var _f = document.forms['rant'];

	document.getElementById('rantMessages').innerHTML = '';

	var _name = trim(_f.elements['name'].value);
	var _loc  = trim(_f.elements['location'].value);
	var _rant = trim(_f.elements['comment'].value);

	var _errorMsg = '';

	if (_name == '' || _loc == '' || _rant == '') {
		_errorMsg += 'Please address the following:<ul>';

		if (_name == '')
			_errorMsg += '<li>Please enter your name</li>';
		if (_loc == '')
			_errorMsg += '<li>Please enter your location</li>';
		if (_rant == '')
			_errorMsg += '<li>Please enter a comment</li>';

		_errorMsg += '</ul>';

		document.getElementById('rantMessages').innerHTML = _errorMsg;
		return false;
	}

	return true;
}

function unhideRantBox() {
	document.getElementById('story-rant-submit-container').style.display = "none";
	document.getElementById('story-rant-form-container').style.display = "block";
}

function unhideEmailBox() {
	document.getElementById('story-email-message-container').style.display = "none";
	document.getElementById('story-email-form-container').style.display = "block";
}

//-- Email Functionality -----------------------------------------------

function tpc_email_story() {

	try {
		if ($('#story-email-message-container').is(':visible'))
			tpc_unhide_email_box();
	} catch (error) {
	}
	

	if ($('#story-email-friend').is(':visible')) {
		$('#story-email-friend').hide('fast');
	} else {
		$('#story-email-friend').show('fast');
		tpc_loadCaptchaImage();	
	}
}

function tpc_unhide_email_box() {
	$('#story-email-message-container').hide();
	$('#story-email-form-container').show();
	tpc_loadCaptchaImage();
}

function tpc_loadCaptchaImage() {
	var img = new Image();	
	$('#captcha-image').html('');
	$('#captchacode').val('');
	
	$(img).load(function() {
		$(this).hide();
		$('#captcha-image').removeClass('loading').append(this);
		$(this).fadeIn();
		$('#captcha-audio-synth-text').show();
		//$('#captcha-audio-synth-swf').show();
		$('#captcha-enter-code').show();
		$('#captcha-email-form-submit').show();
	}).attr('src', '/captchaImage.do?cacheToken=' + Math.floor(Math.random() * 100000001));
	
	$('#captcha-validation-code-msg').html('Validation Code');
	
	tpc_refreshAudioSynthSwf();
}

function tpc_refreshAudioSynthSwf() {
	var _rnd = Math.floor(Math.random() * 100000001);
	$('#captcha-audio-synth-swf').html('').hide();
	var _host = $('#captcha-swf-header-host').html();
	var _swf = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n" + 
		"id=\"AudioCaptcha\" width=\"40\" height=\"40\"\n" + 
		"codebase=\"http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab\">\n" + 
		"<param name=\"movie\" value=\"/resource/captcha/AudioCaptcha.swf?rnd" + _rnd + "\" />\n" + 
		"<param name=\"quality\" value=\"high\" />\n" + 
		"<param name=\"bgcolor\" value=\"#ffffff\" />\n" + 
		"<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n" + 
		"<param name=\"flashVars\" value=\"serverHost=" + _host + "&serverPort=80\" />\n" + 
		"<embed src=\"/resource/captcha/AudioCaptcha.swf?rnd" + _rnd + "\" quality=\"high\" bgcolor=\"#ffffff\"\n" + 
		"width=\"40\" height=\"40\" name=\"AudioCaptcha\" align=\"middle\"\n" + 
		"flashVars=\"serverHost=" + _host + "&serverPort=80\"\n" + 
		"play=\"true\"\n" + 
		"loop=\"false\"\n" + 
		"quality=\"high\"\n" + 
		"allowScriptAccess=\"sameDomain\"\n" + 
		"type=\"application/x-shockwave-flash\"\n" + 
		"pluginspage=\"http://www.adobe.com/go/getflashplayer\">\n" + 
		"</embed>\n" + 
		"</object>\n";
    $('#captcha-audio-synth-swf').html(_swf).show();
}