/* required vars */
var clearFormValues = new Object();

/* highlight vars */
if (!highlightDelay) {
	var highlightDelay = 500;
}
if (!highlightSpeed) {
	var highlightSpeed = 500;
}
var highlightIndex = 1;
var highlightHolder = new Array();

/* disabled vars */
var disabledMessage = 'You cannot access this area at this time';

/* when document is ready, do stuff */
jQuery(document).ready(function()
{
    /* forms that should be submitted on document ready */
	jQuery('form.frm_expedite').each(function(i){
	
        jQuery(this).submit();

	});

    /* for form elements that are cleared upon focus */
	jQuery('.frm_clr').each(function(i){
	
        jQuery(this).focus(function(){

            clearFormValue(jQuery(this), jQuery(this).val());
    
        });
        
        /* this for some reason does not work */
        /* something to do with the function below */
/*        jQuery(this).blur(function(){ */

/*            clearFormValue(jQuery(this), jQuery(this).val()); */
    
/*        }); */

	});
	
    /* for form elements that submit the form upon change */
	jQuery('.frm_change_submit').change(function(i){

		jQuery(this).parents().filter('form').submit();

	});
	
    /* for links that will submit */
    /* doesn't work */
	jQuery('.frm_submit, .frm_submit a').click(function(i){

		var frm_id = jQuery(this).attr('href');
		if (!frm_id) {
			frm_id = jQuery(this).children('a').attr('href');
		}
//alert(frm_id);
		var frm_action = jQuery(frm_action).attr('action');
//alert(frm_action);
		jQuery(frm_action).submit();

	});
	
	/* coming soon links */
	jQuery("a[@href='#']").each(function(i){
	
        jQuery(this).click(function(){

        	alert(jQuery(this).attr('title') + ' coming soon!');
        	return false;
        
        });
            
	});
	
	/* disabled links */
	jQuery("a.disabled, .disabled a").click(function(i){
        	alert(disabledMessage);
        	return false;
	});
	
	/* add to bookmarks function */
	jQuery("a[@href='Add to favourites'], a[@href='Add to bookmarks'], a[@title='Add to favourites'], a[@title='Add to bookmarks'], a.add_bookmark").click(function(i){

		if (window.sidebar) { /* Mozilla Firefox Bookmark */
			window.sidebar.addPanel(document.title, window.location.href,"");
		} else if( window.external ) { /* IE Favorite */
			window.external.AddFavorite( window.location.href, document.title); }
		else if(window.opera && window.print) { /* Opera Hotlist */
			alert("Sorry! Your browser doesn't support this function.");
		}
		
		return false;
            
	});
    
    /* a img hovers */
	jQuery('a.jq_rollover').hover(
	    function() {
	        /* over */
	        var newImage = jQuery(this).find('img').attr('src').replace(/^(.*?)(\.(?:gif|jpg|png))$/, "$1.on$2");
	        if (newImage.indexOf('.on.on') == -1)
	        {
	           jQuery(this).find('img').attr('src', newImage);
	        }
	        
	    },
	    function() {
	        /* out */
	        var newImage = jQuery(this).find('img').attr('src').replace('.on', '');
	        jQuery(this).find('img').attr('src', newImage);
	        
	    }
	);
	
    /* highlight things */
	jQuery('.jq_highlight').each(function() {
		
		highlightHolder[highlightIndex-1] = jQuery(this);
		highlightDelay = highlightDelay * highlightIndex;
		setTimeout('highlightElement(' + highlightIndex + ')', highlightDelay)
		highlightIndex++;
	        
	});
    
   /* stripey li stuff */
    jQuery(".stripey li").hover(
        function() {
            
            /* over */
            
            /* switch class */
            jQuery(this).addClass("hover");
        },
        function() {

           /* out */
           
           /* switch class */
           jQuery(this).removeClass("hover");
        }
    );
   
    jQuery(".stripey li:even").addClass("altrow");
    
   /* stripey table stuff */
    jQuery(".stripey tr").hover(
        function() {
            
            /* over */
            
            /* switch class */
            jQuery(this).addClass("hover");
        },
        function() {

           /* out */
           
           /* switch class */
           jQuery(this).removeClass("hover");
        }
    );
   
    jQuery(".stripey tr:even").addClass("altrow");
    
    /* make buttons have a hover state */
if (false) {
    jQuery("div.submit input").hover(
        function() {
            
            /* over */
            
            /* switch class */
            /*jQuery(this).addClass("frm_but_hover"); */
            jQuery(this).css('background-color','#ff1100');
        },
        function() {

           /* out */
           
           /* switch class */
           /*jQuery(this).removeClass("frm_but_hover"); */
           jQuery(this).css('background-color','#80001c');
        }
    );
}
    
});

function clearFormValue(clearInput, defaultValue)
{
    if (clearInput.val() == defaultValue) {
        clearFormValues[clearInput.attr('id')] = clearInput.val();
        clearInput.val('');
    } else if (clearInput.val() == '') {
        /*alert(clearFormValues[clearInput.attr('id')]); */
        /*$('#test_input').val('we made it'); */
        clearInput.val(clearFormValues[clearInput.attr('id')]);
    }
}

function printPage()
{
	window.print();
	
	return false;
}

/*
 * @TODO
 * I can't get the highlight effect to work
 * So I'm going to show them instead
 */
function highlightElement(highIndex)
{
	highlightHolder[highIndex-1].show(highlightSpeed);
}

function openUrl(url)
{
	window.open(url, '_self');
}

function formSetValue(frmSelector, frmVal)
{
	var frm_element = jQuery(frmSelector);
	if (!frm_element) {
		alert('A form element for ' + frmSelector + ' could not be found.');
		return false;
	}

	frm_element.val(frmVal);
	return true;
}

function formSubmit(frmSelector)
{
	var frm = jQuery(frmSelector);
	var frm_action = frm.attr('action');
	if (!frm || frm_action == undefined) {
		alert('A form for ' + frmSelector + ' could not be found.');
		return false;
	}

	frm.submit();
	return true;
}

function old_createShortcut() {
	alert('Function not available.');
}

      function createShortcut() {
       title = document.title;
       url = window.location.href;
          if (window.sidebar) { // Mozilla Firefox Bookmark
              window.sidebar.addPanel(title, url,"");
          } else if( window.external ) { // IE Favorite
              window.external.AddFavorite( url, title); }
          else if(window.opera && window.print) { // Opera Hotlist
          	return true; }
       }


