// Default client-side JavaScript by Perros @ stylebility.com
// Ver: $Id: default.js,v 1.0 2010/03/05 12:00:00 perros Exp $

//<!--

var REDROOM = window.REDROOM || {};


REDROOM.getWindowHeight = function() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
// Browser innerHeight
	windowHeight=window.innerHeight;
        }
        else {
            if (document.documentElement&&
                document.documentElement.clientHeight) {
// IE 6< in 'standards compliant mode'
                windowHeight=
                document.documentElement.clientHeight;
            }
        else {
            if (document.body&&document.body.clientHeight) {
// IE 4 compatible
                windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

REDROOM.setLayout = function() {
    if (!(document.getElementById)) {
        return;
    }

// Input Placeholder Text, automatic population of form fields with contents of title attributes
// Add the following classes to text inputs or textareas to get the desired behaviour:
// auto-select, will pre-populate the input with the title attribute and select the text when it receives focus.
// auto-clear, will pre-populate the input with the title attribute and clear the text when it receives focus.
// populate, will just populate the input with the title attribute.
    if (!document.getElementsByTagName) return true;

    ourForms = document.getElementsByTagName('form');

// go through each form
    var numForms = ourForms.length;
    for (var i=0;i<numForms;i++) {

// go through each form element
        var numFormElements = ourForms[i].elements.length;
        for (var j=0;j<numFormElements;j++) {

            var el = ourForms[i].elements[j];

// ignore submit buttons
            if (el.type == "submit") continue;

// if we got a text type input
            if (el.type == "text") {
// only populate if we want it to
                var ourClassName = el.className;
                if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
// only populate if empty
                    if (el.value == '') el.value = el.title;
                }

// add auto select if class contains auto-select
                if (el.className.match('auto-select')) {
                    el.onfocus = function () {
                        if (this.value == this.title) this.select();
                    }
                    if (el.captureEvents) el.captureEvents(Event.FOCUS);
                }

// add auto clear if class contains auto-clear
                else if (el.className.match('auto-clear')) {
                    el.onfocus = function () {
                        if (this.value == this.title) this.value = '';
                    }
                    if (el.captureEvents) el.captureEvents(Event.FOCUS);

                    el.onblur = function () {
                        if (this.value == '') this.value = this.title;
                    }
                    if (el.captureEvents) el.captureEvents(Event.BLUR);
                }
            }

// if we got a textarea
            if (el.type == "textarea") {
// only populate if we want it to
                var ourClassName = el.className;
                if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
// only populate if empty
                    if (el.value == '') el.value = el.title;
                }

// add auto select if class contains auto-select
                if (el.className.match('auto-select')) {
                    el.onfocus = function () {
                        if (this.value == this.title) this.select();
                    }
                    if (el.captureEvents) el.captureEvents(Event.FOCUS);
                }

// add auto clear if class contains auto-clear
                else if (el.className.match('auto-clear')) {
                    el.onfocus = function () {
                        if (this.value == this.title) this.value = '';
                    }
                    if (el.captureEvents) el.captureEvents(Event.FOCUS);

                    el.onblur = function () {
                        if (this.value == '') this.value = this.title;
                    }
                    if (el.captureEvents) el.captureEvents(Event.BLUR);
                }
            }
        }
    }
}


// Event hooks
$(document).ready(function () {
    REDROOM.setLayout();
});

//-->
