/*
** scwartz.js - Schwartz Javascript Library
** jgriffith
** need to update to reflect schwartz site
*/

(function($){

var Centennial = {
    
    init: function() {
        Centennial.topnav();
    },
    
    
     /*
      * Add an 'on' class to the top nav
      */
     
     topnav: function() {
        function sethere(id) {
            var img = document.getElementById(id+'-nav');
            if (!img){return};
            img.className = "";
            img.src = img.src.replace('.gif','-on.gif');
        }
        var loc = document.location.href;
        if (loc.indexOf('/conversation/') > -1) {
            sethere('conversation');
        } else if (loc.indexOf('/im/') > -1) {
            sethere('im');
        } else if (loc.indexOf('/businesssummit/') > -1) {
            sethere('businesssummit');
        } else if (loc.indexOf('/globaloutreach/') > -1) {
            sethere('globaloutreach');
        } else if (loc.indexOf('/colloquia/') > -1) {
            sethere('colloquia');
        } else if (loc.indexOf('/press/') > -1) {
            sethere('press');
        } else if (document.body.className.indexOf('home') > -1) {
            sethere('home');
        }

    },
    
    /*
     * Handles the "search" text in the search box
     */
    
     search_input: function(text,input) {  
       input = document.getElementById(input);
       if (!input) return false;
       input.onfocus = function() {
          if (this.value == text) {this.value = "";}
       }
       input.onblur = function() {
          if (this.value == "") {this.value = text;}
       }
     },

     validate_comment: function(form){ 
        if (!form.C.value) {
           alert("Please provide a comment");
           return false;
        }
        Centennial.clean_comments(form)
        return true;
     },
     

     clean_comments: function(form) {
        form["C"].value = Centennial.clean_chars(form["C"].value);
     },

     clean_chars: function(text) {
        var replacements = {
            "\xa0": " ",
            "\xa9": "(c)",
            "\xae": "(r)",
            "\xb7": "*",
            "\u2018": "'",
            "\u2019": "'",
            "\u201c": '"',
            "\u201d": '"',
            "\u2026": "...",
            "\u2002": " ",
            "\u2003": " ",
            "\u2009": " ",
            "\u2013": "-",
            "\u2014": "--",
            "\u2122": "(tm)"};
            for (key in replacements) {
              var rx = new RegExp(key, 'g');
              text = text.replace(rx,replacements[key])
            }
        return text
     },
     
     
     last:''
    
}
    
window.Centennial = Centennial;
$(document).ready(function(){Centennial.init()});

})(jQuery);
