/**
 * @author saument
 */
function select_by_category() {
    $('location-list').hide();
    $('category-list').show();
}

function select_by_location() {
    $('category-list').hide();
    $('location-list').show();
}

function selectCategory(category_id) {
    clearSelectedElements('cat-loc-column');
    $('cat-'+category_id).addClassName('selected');
    new Ajax.Updater('page-core-footer-buttons', '/categories/'+category_id+'/sel_buttons', { asynchronous:true, evalScripts:true, method:'get' });
}

function selectLocation(location_id) {
    clearSelectedElements('cat-loc-column');
    $('loc-'+location_id).addClassName('selected');
    new Ajax.Updater('page-core-footer-buttons', '/locations/'+location_id+'/sel_buttons', { asynchronous:true, evalScripts:true, method:'get' });
}

function selectItem(item_id) {
    clearSelectedElements('inventory-details');
    $('item-'+item_id).addClassName('selected');
}

function selectPhoto(photo_id) {
    clearSelectedElements('image-list');
    $('photo-'+photo_id).addClassName('selected');
}

function selectPolicy(policy_id) {
    clearSelectedElements('cat-loc-column');
    $('pol-'+policy_id).addClassName('selected');
    new Ajax.Updater('page-core-footer-buttons', '/policies/'+policy_id+'/sel_buttons', { asynchronous:true, evalScripts:true, method:'get' });
}

function clearSelectedElements(container) {
    selElements = $(container).getElementsByClassName('selected');
    
    for (i = 0; i < selElements.length; i++) {
        selElements[i].removeClassName('selected');
    }
}

function init() {
    loadButtons();
    loadTitle();
	// For some reason this part breaks in IE7 so i moved the important stuff up above it :) David
    if (document.forms[0]) {		
        document.forms[0].focus();
        document.forms[0].elements[0].select();        
    }
}

function loadTitle() {
    if ($('page-title') != null) {
        $('header-menu').innerHTML = $('page-title').innerHTML;
    }
}

function loadButtons() {
    if ($('buttons') != null) {
        $('page-core-footer-buttons').innerHTML = $('buttons').innerHTML;
    }
}

function submitSpecial()
{
	if(document.forms[0].item_description.value.length == 0)	
		alert('Please add a description to your item before adding a field.');
		document.forms[0].add_fields.value = "x";
		document.forms[0].submit();
}

function scrollToBottom(div_name)
{
	$('item-elements-notes').toggle();
	var objDiv = document.getElementById(div_name);
	objDiv.scrollTop = objDiv.scrollHeight;
}
