/**
 * Used to Hide and Show elements on the page
 *
 * @package Hotwire
 * @author Mark Koberlein
 * @version
 **/
function Display ()
{
    /**
     * Display elements based on their tag (div,tr)
     * @param string id
     * @param string tag
     **/
    this.show = function(id,tag) {
       var type = "";
        switch (tag)
        {
            case "tr":
                // Detect for IE or Mozilla
                if (document.all) type = "block";
                if (document.layers) type = "table-row";
                break

            case "div":
                type = "block";
                break
        }
        document.getElementById(id).style.display=type;
    }
    /**
     * Hide the specified element
     * @param string id
     **/
    this.hide = function(id) {
        document.getElementById(id).style.display="none";
    }
    /**
     * Hide multiple elements that are specified in a CSV list
     * @param string ids
     **/
    this.hideAll = function(ids) {
        var idArray = ids.split(",");
        for (var i = 0; i < idArray.length; i++){
            if (idArray[i]) document.getElementById(idArray[i]).style.display="none";
        }
    }
    /**
     * Displays content inside of an element
     * @param string id
     * @param string content
     **/
   this.inside = function(id,content) {
         document.getElementById(id).innerHTML=content;
   }
   /**
    * Swaps the src of an image tag
    * @param string id
    * @param string content
    **/
   this.swap = function(id,content) {
     document.getElementById(id).src=content;
   }
   /**
    * Opens up a popup window
    * @param string loc
    * @param string w
    * @param string h
    **/
   this.open = function(loc,w,h) {
     var params = 'toolbar=no, location=no, directories=no, status=no, '+
                  'menubar=no, scrollbars=yes, resizable=no, '+
                  'copyhistory=yes, width='+w+', height='+h;
     window.open(loc,'_blank',params);
   }
}
display = new Display();


/**
 * Controls the properties of page elements
 *
 * @package Hotwire
 * @author Mark Koberlein
 * @version
 **/
function Element () {
    /**
     * @param string id
     **/
    this.height = function(id) {
        return document.getElementById(id).offsetHeight;
    }
}
element = new Element();



function Overlay() {
  this.open = function(id,fm) {
    viewerOn = true;
    if (window.innerHeight) {
      this.overlayHeight = window.innerHeight;
      this.overlayWidth = window.innerWidth;
    } else if (document.body.clientHeight) {
      this.overlayHeight = document.body.clientHeight+40;
      this.overlayWidth = document.body.clientWidth;
    } else if (document.documentElement.clientHeight) {
      this.overlayHeight = document.documentElement.clientHeight+40;
      this.overlayWidth = document.documentElement.clientWidth;
    } else {
      this.overlayHeight = document.body.scrollHeight+40;
      this.overlayWidth = document.body.scrollWidth;
    }
    document.getElementById(id).style.display="block";
    document.getElementById(id).style.height = this.overlayHeight + "px";
    document.getElementById(id).style.width = this.overlayWidth + "px";

    // // Loop through the form to hide any dropdowns
    // var form = document.getElementById(fm);
    // if (form) {
    //   for (i=0; i < form.elements.length; i++) {
    //     if(form.elements[i].type == "select-one")
    //       form.elements[i].style.display = 'none';
    //   }
    // }
  }
  this.close = function(id,fm) {
    viewerOn = false;
    document.getElementById(id).style.display="none";

    // Loop through the form to show any dropdowns
    var form = document.getElementById(fm);
    if (form) {
      for (i=0; i < form.elements.length; i++) {
        if (form.elements[i].type == "select-one")
          form.elements[i].style.display = 'block';
      }
    }
  }
  this.reload = function(id) {
    if (viewerOn) {

      this.overlayHeight = document.body.scrollHeight;
      this.overlayWidth = document.body.scrollWidth;

      if (this.windowWidth < maxWidth) { this.windowWidth=maxWidth; };
      document.getElementById(id).style.display="block";
      document.getElementById(id).style.height = this.overlayHeight + "px";
      document.getElementById(id).style.width = this.overlayWidth + "px";
    }
  }
}
overlay = new Overlay();


function Cookie() {
  this.create = function(name, value, days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else
      var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }
  this.read = function(name) {
    var ca = document.cookie.split(';');
    var nameEQ = name + "=";
    for(var i=0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0)==' ')
        c = c.substring(1, c.length); //delete spaces
      if (c.indexOf(nameEQ) == 0)
        return c.substring(nameEQ.length, c.length);
    }
    return null;
    }
  this.erase = function(name) {
    this.create(name, "", -1);
  }
}
cookie = new Cookie();


function CheckEnter(e,f){
  var characterCode;

  //if which property of event object is supported (NN4)
  if(e && e.which){
    e = e;
    characterCode = e.which;
  }
  else{
    e = event;
    //character code is contained in IE's keyCode property
    characterCode = e.keyCode
  }

  //if generated character code is equal to ascii 13 (if enter key)
  if(characterCode == 13){
    switch (f) {
      case 'Search':
        Search.search();
        break;
      case 'SearchContact':
        Search.contact();
        break;
      case 'IndexLogin':
        IndexLogin.submit();
        break;
      case 'PropLogin':
        PropLogin.submit();
        break;
      case 'register':
        document.getElementById('register_form').submit();
        break;
      default:
        //document.forms[0].submit();
        break;
    }
    return false;
  }
  else{
    return true;
  }
}

function PromoCodeCheck(c) {
  if (c == "leasing agent" || c == "sales agent") {
    display.show("agentname","tr");
    display.show("agentnumber","tr");
    display.show("agentemail","tr");
    display.show("agentnotes","tr");
  }
}
