beBaseModule.prototype._transport;
beBaseModule.prototype._channelId = 'site.shared';

function beBaseModule() {}

beBaseModule.prototype.initialize = function(transport){
	this._transport = transport;
    
    $('search').observe('keyup', function(event){if(event.keyCode == 13){this.search(event);}}.bind(this));
    $('searchSubmit').observe('click', this.search.bind(this));
    
    if($('providerRegions')){$('providerRegions').observe('change', function(event){if(event.element().value != ''){window.location = event.element().value;}});}    
    if($('contactForm')){$('contactSubmit').observe('click', this.contactSubmit.bind(this));}
    if($('assessmentForm')){$('contactSubmit').observe('click', this.assessmentSubmit.bind(this));}    
}

beBaseModule.prototype.search = function(event){
    if($('search').value.length > 2){
        window.location = '/search/' + encodeURIComponent($('search').value);
    }
}
 
beBaseModule.prototype.assessmentSubmit = function(event){
    var errorList = '';
    var concerns = new Array();
    var services = new Array();
    
    $('concerns').select('input').each(function(input){if(input.checked){concerns.push(input.value);}});
    $('services').select('input').each(function(input){if(input.checked){services.push(input.value);}});
    
    if($('contactAge').value == ''){errorList += '<li>Select the individuals age</li>';}
    if(concerns.length == 0){errorList += '<li>Select at least one concern</li>';}
    if(services.length == 0){errorList += '<li>Select at least one service</li>';}
    if($('contactName').value == ''){errorList += '<li>Enter your name</li>';}
    if($('contactEmail').value == ''){errorList += '<li>Enter your email address</li>';}
    if($('contactPhone').value == ''){errorList += '<li>Enter a phone number to call</li>';}
    if($('contactComments').value == ''){errorList += '<li>Enter your comments and questions</li>';}
    
    if(errorList != ''){
        $('contactError').update('<ul>' + errorList + '</ul>');
        $('contactError').show();
    }else{
        $('contactError').hide();
        
        var request = {
            name : $('contactName').value,
            email : $('contactEmail').value,
            phone : $('contactPhone').value,
            comments : $('contactComments').value,
            age : $('contactAge').value,
            concerns : concerns.join(','),
            concernsOther : $('contactConcernOther').value,
            services : services.join(','),
            servicesOther : $('contactServicesOther').value,
            insurance : $('contactInsurance').value
        };
        
        this._transport.transmitRequest(this._channelId, 'setformassessment', request, this.assessmentSubmitted.bind(this));
    }        
}    
    
beBaseModule.prototype.assessmentSubmitted = function(o){
    $('assessmentForm').hide();
    $('assessmentFormSuccess').show();
    window.scrollTo(0,0);
    be_globalSiteFramework.trackPageview('/contact-us-completed'); 
    pageTracker._trackPageview('/assessment-completed');     
}
    
beBaseModule.prototype.contactSubmit = function(event){
    var errorList = '';

    if($('contactName').value == ''){errorList += '<li>Enter your name</li>';}
    if($('contactEmail').value == ''){errorList += '<li>Enter your email address</li>';}
    if($('contactPhone').value == ''){errorList += '<li>Enter a phone number to call</li>';}
    if($('contactComments').value == ''){errorList += '<li>Enter your comments and questions</li>';}

    if(errorList != ''){
        $('contactError').update('<ul>' + errorList + '</ul>');
        $('contactError').show();
    }else{
        $('contactError').hide();

        var request = {
            name : $('contactName').value,
            email : $('contactEmail').value,
            phone : $('contactPhone').value,
            comments : $('contactComments').value
        };

        this._transport.transmitRequest(this._channelId, 'setformcontact', request, this.contactSubmitted.bind(this));
    }    
}
    
beBaseModule.prototype.contactSubmitted = function(o){
    $('contactForm').hide();
    $('contactFormSuccess').show();
    be_globalSiteFramework.trackPageview('/contact-us-completed');    
}


beHome.prototype._transport;
beHome.prototype._channelId = 'site.shared';
beHome.prototype._homeSplashExecuter = null;
beHome.prototype._homeSplashCount = 0;
beHome.prototype._homeSplashCurrent = 0;

function beHome() {}

beHome.prototype.initialize = function(transport){
	this._transport = transport;

	var me = this;
	if($('homeslider')){
        this._homeSplashCount = $$('.slide').length;
        this._homeSplashCurrent = 1;
        this._homeSplashExecuter = new PeriodicalExecuter(this.homeToggleSplash.bind(this), 10);
        
        $$('.nav')[0].select('a').each(function(a){
            a.observe('click', me.homeSplashNavTo.bind(me));
        });
	}
}	

beHome.prototype.homeToggleSplash = function(event){
    this.homeSplashHide(this._homeSplashCurrent);    
    if(this._homeSplashCurrent + 1 > this._homeSplashCount){this._homeSplashCurrent = 1;}else{this._homeSplashCurrent += 1;}    
    this.homeSplashShow(this._homeSplashCurrent);
};

beHome.prototype.homeSplashNavTo = function(event){
    this._homeSplashExecuter.stop();
    this.homeSplashHide(this._homeSplashCurrent);
    this.homeSplashShow(event.element().identify().replace('nav',''));
};

beHome.prototype.homeSplashHide = function(elementId){
    $('slide' + elementId).hide();
    $$('.nav')[0].select('a').each(function(a){a.className = ''});
};

beHome.prototype.homeSplashShow = function(elementId){
    $('slide' + elementId).show();
    $('nav' + elementId).className = 'current';
    this._homeSplashCurrent = elementId;
};
