$().ready(function(){
  
  ft_regx = /^_ftnref(\d*)$/;
  ed_regx = /^_ednref(\d*)$/;

  $("a[name^='_ftnref']").each(function(){
    
    // cache jquery object
    $a = $(this);
    
    // parse the footnote number
    var results = ft_regx.exec( $a.attr('name') );
    var n = results[1];
    
    // set the footnote reference in the body
    $a.html("[" + n + "]").attr('href',"#_ftn" + n);
    
    // set the footnote reference in the footer
    $("a[name='_ftn" + n + "']").html("[" + n + "]").attr('href','#_ftnref' + n);
    
  });
  
  $("a[name^='_ednref']").each(function(){
    
    // cache jquery object
    $a = $(this);
    
    // parse the endnote number
    var results = ed_regx.exec( $a.attr('name') );
    var n = results[1];
    
    // set the endnode reference in the body
    $a.html("[" + n + "]").attr('href',"#_edn" + n);
    
    // set the endnode reference in the footer
    $("a[name='_edn" + n + "']").html("[" + n + "]").attr('href','#_ednref' + n);
    
  });  
    
});



var checkedCount = 0;

function clearSelections() {
    $(':input', '.content')
    .not(':button, :submit, :reset, :hidden')
    .removeAttr('checked')
    .removeAttr('selected');

    $('.content input').val("");
    $('.content textarea').val("");
    
    if(checkedCount != null)
        checkedCount = 0;
}

function ensureLocations() {
    if (checkedCount > 0) {
	    return true;
    }
    alert("Please select at least one location to graph.");
    return false;			
}

function copyToClipboard(controlId) {

    var control = document.getElementById(controlId);
    if (control == null) return;

    var text = control.value;

    if (window.clipboardData) {
        window.clipboardData.setData('text', text);
        return;
    } 
    
    var flashId = 'divclipboardswf';

    /* Replace this with your clipboard.swf location */
    var clipboardSWF = 'http://cssp.localhost/clipboard.swf';

    if (!document.getElementById(flashId)) {
        var div = document.createElement('div');
        div.id = flashId;
        document.body.appendChild(div);
    }
    document.getElementById(flashId).innerHTML = '';
    var content = '<embed src="' +
        clipboardSWF +
        '" FlashVars="clipboard=' + encodeURIComponent(text) +
        '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashId).innerHTML = content;
}

function _submit()
{
     var inputs = document.getElementsByTagName("input");
     for (var i=0; i<inputs.length; i++)  {
          if (inputs[i].className == "button-submit")  {
               inputs[i].onmouseover = function()
               {
                  this.src = this.src.replace(".gif", "-hover.gif");
               }
               inputs[i].onmouseout = function()
               {
                    this.src = this.src.replace("-hover.gif", ".gif");
               }
          }
		  if (inputs[i].className == "text-field")  {
				inputs[i].onfocus = function(){
					this.value = "";
				}
          }
     }
}
if (window.addEventListener)
     window.addEventListener("load", _submit, false);
else if (window.attachEvent)
    window.attachEvent("onload", _submit)
     
     
     

