/**
 * Displays/hides elements that use 'display:none' to hide
 */
 function toggleDisplay(targetId){
    var target = document.getElementById(targetId);

    if(target.style.display == "none"){
        target.style.display = "block";
    }else{
        target.style.display = "none";
    }
}

/**
 * Displays/hides elements that use 'visibility=hidden' to hide
 */
 function toggleVisibility(targetId){
     target = document.getElementById(targetId);
     if(target.style.visibility == "hidden"){
         target.style.visibility = "visible";
     }else{
         target.style.visibility = "hidden";
     }
 }

function working(){
    toggleDisplay("working");
    toggleDisplay("content");
}

function go(URL){
    working();
    var theForm = document.forms["MenuForm"];
    theForm.action = URL;
    theForm.submit();
}

function submitForm(objForm){
    working();
    objForm.submit();
}

/**
 * Changes the style class of an element
 */
 function swapClass(obj, newStyle){
     obj.className = newStyle;
 }

/**
 * Determines if an object is undefined
 */
 function isUndefined(value){
     var undef;
     return value == undef;
 }

/**
 * Sets a cookie
 */
 function setCookie(name, value, expires, path, domain, secure){
    document.cookie = name + "=" + escape(value) +
    	((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path: "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets a cookie
 */
 function getCookie(name){
     var prefix = name + "=";
     var start = document.cookie.indexOf(prefix);

     if(start == -1){
         return null;
     }

     var end = document.cookie.indexOf(";", start + prefix.length);

     if(end == -1){
         end = document.cookie.length;
     }

     var value = document.cookie.substring(start + prefix.length, end)

     return unescape(value);
 }

/**
 * Deletes a cookie
 */
 function deleteCookie(name, path, domain){
     if(getCookie(name)){
         document.cookie = name + "=" +
         	((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
  }

/**
 * Strips leading and trailing spaces from a string
 */
 function trim(str){
     if(str != null){
         for(var i = 0; i < str.length; i++){
             if(str.charAt(i) != " "){
                 str = str.substring(i, str.length);
                 break;
             }
         }

         for(i = str.length; i >= 0; i--){
             if(str.charAt(i) != " "){
                 str = str.substring(0, i + 1);
                 break;
             }
         }

         if(str.charAt(0) == " "){
             return "";
         }else{
             return str;
         }
     }
 }

/**
 * Adds highlighting to input fields
 */
 function highlightFormElements()
 {
     addFocusHandlers(document.getElementsByTagName("input"));
     addFocusHandlers(document.getElementsByTagName("textarea"));
 }

/**
 * Adds focus event handlers to elements
 */
 function addFocusHandlers(elements){
     for(var i = 0; i < elements.length; i++){
         if(elements[i].type != "button" && elements[i].type != "submit" &&
         	elements[i].type != "reset" && elements[i].type != "checkbox"){
                elements[i].onfocus=function(){
                    this.className="focus"; this.select()};
                elements[i].onblur=function(){this.className=""};
        }
    }
}

/**
 * Confirms delete before proceeding
 */
 function confirmDelete(obj){
     var msg = "Are you sure you want to delete this " + obj + "?";
     ans = confirm(msg);
     if(ans){
         return true;
     }else{
         return false;
     }
 }

/**
 * Prepares an item for deletion
 */
 function deleteItem(sMessage){
     if(confirmDelete(sMessage)){
         working();
         return true;
     }else{
         return false;
     }
 }

 window.onload = highlightFormElements;
 window.defaultStatus=document.title;
