/**
 * general site setup
 * 
 * @author alec hill
 */

var site = Site.getInstance();


function setupFormDefaultsHandling(){
    function handleEvents(input){
        if(input.form && input.form.className.indexOf('handle_defaults') == -1) return;
        if(input.nodeName == 'INPUT' && input.type != 'text') return;
        input.onfocus = function(e){
            if(this.value == this.defaultValue) this.value = '';
        }
        input.onblur = function(e){
            if(this.value == '') this.value = this.defaultValue;
        }
    }
    var inputs = document.getElementsByTagName('input') || [];
    var textareas = document.getElementsByTagName('textarea') || [];
    for(var i = 0, len = inputs.length; i < len; i++){
        handleEvents(inputs[i]);
    }
    for(var j = 0, len = textareas.length; j < len; j++){
        handleEvents(textareas[j]);
    } 
}

site.addLoadEvent(setupFormDefaultsHandling);


// must setup validation after the input default value stuff or events will be overwritten
function setupContactFormValidation(){
    if(!document.getElementById('contactus')) return false;
    new LiveValidation('ctitle', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('ctitle').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} );
    new LiveValidation('surname', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('surname').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} );
    new LiveValidation('phone', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('phone').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} ).add( Validate.Numericality );
    new LiveValidation('email', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('email').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} ).add( Validate.Email,{failureMessage: 'Must be valid email!'} );
    new LiveValidation('enquiry', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('enquiry').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} );
    new LiveValidation('scramble', {onlyOnBlur: true, insertAfterWhatNode: document.getElementById('scramble').previousSibling.previousSibling.firstChild} ).add( Validate.Presence, {failureMessage: 'Required!'} );
}

site.addLoadEvent( setupContactFormValidation );

/*
// uncomment this to add the image text functinality on the primary navigation

// preload the rollover images
site.preload('images/navitemhover/home.jpg');
site.preload('images/navitemhover/about%20gogo.jpg');
site.preload('images/navitemhover/uses%20for%20gogo.jpg');
site.preload('images/navitemhover/technology.jpg');
site.preload('images/navitemhover/news.jpg');
site.preload('images/navitemhover/case%20studies.jpg');
site.preload('images/navitemhover/contact%20us.jpg');

// sets up the hover swaps on the nav images
var setupNav = function(){
    this._images = document.getElementById('nav').getElementsByTagName('img');
    for(var i = 0, len = this._images.length; i < len; i++ ){
        var img = this._images[i];
        img.iname = img.src.substring( img.src.lastIndexOf('/') + 1 );
        img.onmouseover = function(e){
            this.src = 'images/navitemhover/' + this.iname;
        }
        img.onmouseout = function(e){
            this.src = 'images/navitem/' + this.iname;
        }
    }
}

site.addLoadEvent( setupNav );
*/


