/*****************************************************
 * ypSlideOutMenu
 * 3/04/2001
 * 
 * a nice little script to create exclusive, slide-out
 * menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
 * mac and win32. I've got no linux or unix to test on but 
 * it should(?) work... 
 *
 * --youngpup--
 *****************************************************/

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 600
ypSlideOutMenu.hideDelay = 250
ypSlideOutMenu.minCPUResolution = 10

// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
    this.ie  = document.all ? 1 : 0
    this.ns4 = document.layers ? 1 : 0
    this.dom = document.getElementById ? 1 : 0

    if (this.ie || this.ns4 || this.dom) {
        this.id          = id
        this.dir         = dir
        this.orientation = dir == "left" || dir == "right" ? "h" : "v"
        this.dirType     = dir == "right" || dir == "down" ? "-" : "+"
        this.dim         = this.orientation == "h" ? width : height
        this.hideTimer   = false
        this.aniTimer    = false
        this.open        = false
        this.over        = false
        this.startTime   = 0

        // global reference to this object
        this.gRef = "ypSlideOutMenu_"+id
        eval(this.gRef+"=this")

        // add this menu object to an internal list of all menus
        ypSlideOutMenu.Registry[id] = this

        var d = document
        d.write('<style type="text/css">')
        d.write('#' + this.id + 'Container { visibility:hidden; ')
        d.write('left:' + left + 'px; ')
        d.write('top:' + top + 'px; ')
        d.write('overflow:hidden; }')
        d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ')
        d.write('width:' + width + 'px; ')
        d.write('height:' + height + 'px; ')
        d.write('clip:rect(0 ' + width + ' ' + height + ' 0); ')
        d.write('}')
        d.write('</style>')

        this.load()
    }
}

ypSlideOutMenu.prototype.load = function() {
    var d = document
    var lyrId1 = this.id + "Container"
    var lyrId2 = this.id + "Content"
    var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
    if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
    var temp

    if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
    else {
        this.container  = obj1
        this.menu       = obj2
        this.style      = this.ns4 ? this.menu : this.menu.style
        this.homePos    = eval("0" + this.dirType + this.dim)
        this.outPos     = 0
        this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 

        // set event handlers.
        if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
        this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
        this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

        //set initial state
        this.endSlide()
    }
}
    
ypSlideOutMenu.showMenu = function(id)
{
    var reg = ypSlideOutMenu.Registry
	var obj = ypSlideOutMenu.Registry[id]
	    
    if (obj.container) {
        obj.over = true

        // close other menus.
      //for (menu in reg)  if (id != menu)  ypSlideOutMenu.hide(menu)

        // if this menu is scheduled to close, cancel it.
        if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

        // if this menu is closed, open it.
        if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
    }
}

ypSlideOutMenu.hideMenu = function(id)
{
    // schedules the menu to close after <hideDelay> ms, which
    // gives the user time to cancel the action if they accidentally moused out
    var obj = ypSlideOutMenu.Registry[id]
    if (obj.container) {
        if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
        obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
    }
}

ypSlideOutMenu.hide = function(id)
{
    var obj = ypSlideOutMenu.Registry[id]
    obj.over = false

    if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
    
    // flag that this scheduled event has occured.
    obj.hideTimer = 0

    // if this menu is open, close it.
    if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

ypSlideOutMenu.prototype.startSlide = function(open) {
    this[open ? "onactivate" : "ondeactivate"]()
    this.open = open
    if (open) this.setVisibility(true)
    this.startTime = (new Date()).getTime() 
    this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
    var elapsed = (new Date()).getTime() - this.startTime
    if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
    else {
        var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
        if (this.open && this.dirType == "-")       d = -d
        else if (this.open && this.dirType == "+")  d = -d
        else if (!this.open && this.dirType == "-") d = -this.dim + d
        else                                        d = this.dim + d

        this.moveTo(d)
    }
}

ypSlideOutMenu.prototype.endSlide = function() {
    this.aniTimer = window.clearTimeout(this.aniTimer)
    this.moveTo(this.open ? this.outPos : this.homePos)
    if (!this.open) this.setVisibility(false)
    if ((this.open && !this.over) || (!this.open && this.over)) {
        this.startSlide(this.over)
    }
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
    var s = this.ns4 ? this.container : this.container.style
    s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
    this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
    return parseInt(this.style[c])
}

// events
ypSlideOutMenu.prototype.onactivate     = function() { }
ypSlideOutMenu.prototype.ondeactivate   = function() { }


//functions

//constants
var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

if(navigator.appName == "Microsoft Internet Explorer") 
{
   http = new ActiveXObject("Microsoft.XMLHTTP");
} 
else 
{
   http = new XMLHttpRequest();
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str) {
  return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checknumber(value){
   if (value != '')
   {
      var x=value;
      var anum=/(^\d+$)|(^\d+\.\d+$)/
      if (anum.test(x))
      {
         testresult=true;
      }
      else
      {
         testresult=false;
      }
      return (testresult);
   }
   else
   {
      return true;
   }
}

/*
  Check if a form element is empty.
  If it is display an alert box and focus
  on the element
*/
function isEmpty(formElement, message) {
  formElement.value = trim(formElement.value);
  _isEmpty = false;
  if (formElement.value == '') {
    _isEmpty = true;
    alert(message);
    formElement.focus();
  }
  return _isEmpty;
}

function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Invalid E-mail ID")
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Invalid E-mail ID")
      return false
  }
  if (str.indexOf(at,(lat+1))!=-1){
      alert("Invalid E-mail ID")
      return false
  }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Invalid E-mail ID")
      return false
  }
    if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail ID")
      return false
  }
  if (str.indexOf(" ")!=-1){
      alert("Invalid E-mail ID")
      return false
  }
  return true         
}

 function validateEmail(emailID) {
  if ((emailID.value==null)||(emailID.value=="")) {
    alert("Please enter your Email Address")
    emailID.focus()
    return false
  }
  if (echeck(emailID.value)==false) {
    emailID.value=""
    emailID.focus()
    return false
  }
  return true;
 }

function validateUSPhoneNumber(phonenumber)
{
   var isValid = (/^[1-9]\d{2}-\d{3}-\d{4}$/.test(phonenumber));
   return isValid;
}

function verify_contact1_form_input() {
 
 if(document.getElementById('disclaimer').checked){ 

 } else {
    alert('You must check the box that indicates you have read the disclaimer');
    return false;
 }

 with (window.document.contact) {
    if (document.getElementById('firstname').value == 'First Name')
        document.getElementById('firstname').value = '';
    if (isEmpty(firstname, 'Please enter your name'))
      return false;
  }      

 with (window.document.contact) {
    if (document.getElementById('lastname').value == 'Last Name')
    document.getElementById('lastname').value = '';
    
    if (isEmpty(lastname, 'Please enter your name'))
      return false;
 }
 
 with (window.document.contact) {
    if (document.getElementById('address1').value == 'Address Line 1')
        document.getElementById('address1').value = '';
 
    if (isEmpty(address1, 'Please enter your address'))
      return false;  
 }
    
    
 with (window.document.contact) { 
 
  if (document.getElementById('city').value == 'City')
    document.getElementById('city').value = '';
  if (isEmpty(city, 'Please enter your city'))
      return false;      
 }
 
 with (window.document.contact) { 
    if (isEmpty(state, 'Please select your state'))
      return false;      
}

with (window.document.contact) { 
    if (document.getElementById('zip').value == 'Zip')
        document.getElementById('zip').value = '';
    if (isEmpty(zip, 'Please enter your zip'))
      return false;      
}

with (window.document.contact) { 
    if (document.getElementById('phone').value == 'Phone')
        document.getElementById('phone').value = '';
    
    if (isEmpty(phone, 'Please enter your phone number'))
      return false;      
}

with (window.document.contact) { 
    if (document.getElementById('text').value == 'Your comments or questions')
        document.getElementById('text').value = '';
    if (isEmpty(text, 'Please enter a message'))
      return false;  
}

with (window.document.contact) { 
 if (document.getElementById('email').value == 'Email')
    document.getElementById('email').value = '';
 if ((echeck(email.value)==false)) {
      email.value="";
      email.focus();
      return false;
    }
  }

 return true;  
}

function verify_contact2_form_input() {
 
 if(document.getElementById('disclaimer').checked){ 

 } else {
    alert('You must check the box that indicates you have read the disclaimer');
    return false;
 }

with (window.document.contact) {
    if (document.getElementById('name').value == 'Name')
        document.getElementById('name').value = '';
    if (isEmpty(name, 'Please enter your name'))
      return false;
} 

with (window.document.contact) { 
    if (document.getElementById('phone').value == 'Phone')
        document.getElementById('phone').value = '';
    
    if (isEmpty(phone, 'Please enter your phone number'))
      return false;      
}

with (window.document.contact) { 
 if (document.getElementById('email').value == 'Email')
    document.getElementById('email').value = '';
 if ((echeck(email.value)==false)) {
      email.value="";
      email.focus();
      return false;
    }
  }
  
 return true; 
  
}


