var APP_PREFIX = '/';
var tab = null;

function getElement(id) {
	return (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
}

function setRowColor(table_element) {
	$(table_element+' tr:even').css('background-color', '#f8f7f6');
}

function formatRequired(id,field) {
	var obj = getElement('title_'+id+'_'+field);
	obj.innerHTML = '<b>*'+field.capitalize()+'</b>:';
}
String.prototype.capitalize = function(){ //v1.0
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};

function changeTab(id) { 
	$('.content_tab').removeClass('on'); 
	$('.tab_div').hide();  
	$('#tab_'+id).addClass('on');  
	$('#tab_div_'+id).show();
}

function rebuildAjaxHistoryLinks() {
	$("a[rel='history']").unbind('click');
	$("a[rel='history']").bind('click', buildAjaxHistoryLink);
}

function checkUploadAlert()
{
	if($('.file_upload[value!=""]').length > 0)
	{
		Ext.Msg.show({ msg: 'Please wait while your upload is being processed.', closable: false, wait: true, progress: true, width: 300});
	}
	
	return true;
}

var buildAjaxHistoryLink = function(){
	var hash = this.href;
	hash = hash.replace(/^.*#/, '');
	$.history.load(hash);
	return false;
};

$(document).ready(function() {  
	//$('.data_table tr:even').css('background-color', '#f8f7f6');
	$('.data_table').each(function(i) {
		$(this).find('tr:even').css('background-color', '#f8f7f6');
	});
	
	// Only load the ajax history handling on pages that support it.
	// 1. Define a function ajaxPageInit that handles page loads.
	// 2. Set the rel attribute of links to history to enable them.
	if(typeof ajaxPageInit == 'function') {
		$.history.init(ajaxPageInit);
		rebuildAjaxHistoryLinks();
	}
}); 