/*

Pre-Launch, Beta Version

WARNIING: This code is unoptimised and not too pretty to look at.

*/

function phone_check(el)
{
    if(document.getElementById("label_phone_form").childNodes[0].className != "")
    document.getElementById("label_email_form").childNodes[0].className = (el.value.trim() != "") ? "" : "highlight";
}
;
function email_check(el)
{
    if(document.getElementById("label_email_form").childNodes[0].className != "")
    document.getElementById("label_phone_form").childNodes[0].className = (el.value.trim() != "") ? "" : "highlight";
}
;
String.prototype.trim=function()
{
    return this.replace(/^\s*|\s*$/g,'');
}
;
function valid()
{
    var result = true;
    var form = document.forms[0];
    if(form.elements["name_form"].value.trim() == "")
    {
        result = false;
        document.getElementById("name_form").style.borderColor = "red";
    }
    if(form.elements["phone_form"].value.trim() == "" && form.elements["email_form"].value.trim() == "")
    {
        result = false;
        document.getElementById("phone_form").style.borderColor = "red";
        document.getElementById("email_form").style.borderColor = "red";
    }
    if(form.elements["message_form"].value.trim() == "")
    {
        result = false;
        document.getElementById("message_form").style.borderColor = "red";
        if(document.getElementById("phone_form").value.trim() != "" && document.getElementById("name_form").value.trim() != "")
        {
            document.getElementById("message_form").value = "Please call me at the above number.";
        }
    }
    return result;
}
;
function clear()
{
    document.getElementById("required-message").style.color = "black";
    document.getElementById("name_form").style.borderColor = "#636262";
    document.getElementById("phone_form").style.borderColor = "#636262";
    document.getElementById("email_form").style.borderColor = "#636262";
    document.getElementById("message_form").style.borderColor = "#636262";
}
;
function toggle_hidden(id)
{
    if(document.getElementById(id).className.indexOf(" hidden") > 0)
    {
        document.getElementById(id).className = document.getElementById(id).className.replace(" hidden", "");
        return true;
    }
    else
    {
        document.getElementById(id).className += " hidden";
        return false;
    }
}
;
var myrules =
{
    'a' : function(el)
    {
        el.onclick = function()
        {
            if(this.href.indexOf("#") != -1)
            {
                var name = this.href.replace(/^[^#]*#/, "");
                switch(name)
                {
                    case "standards" :
                    if(toggle_hidden("sub-section_standards"))
                    ScrollWin.scroll(name);
                    break;
                    case "promises" :
                    if(toggle_hidden("sub-section_promises"))
                    ScrollWin.scroll(name);
                    break;
                    case "item_news-one" :
                    if(toggle_hidden("sub-section_news-one"))
                    ScrollWin.scroll(name);
                    break;
                    case "item_news-two" :
                    if(toggle_hidden("sub-section_news-two"))
                    ScrollWin.scroll(name);
                    break;
                    case "item_news-three" :
                    if(toggle_hidden("sub-section_news-three"))
                    ScrollWin.scroll(name);
                    break;
                    case "item_news-four" :
                    if(toggle_hidden("sub-section_news-four"))
                    ScrollWin.scroll(name);
                    break;
                    default :
                    ScrollWin.scroll(name);
                }
                return false;
            }
        }
    }
    ,
    '#work_section .pseudo-link' : function(el)
    {
        el.onmouseover = function()
        {
            this.style.color = "white";
            this.style.backgroundColor = "#53449B";
        }
        ;
        el.onmouseout = function()
        {
            this.style.color = "#53449B";
            this.style.backgroundColor = "transparent";
        }
    }
    ,
    '#pseudo-link_see-more' : function(el)
    {
        el.onclick = function()
        {
            if(document.getElementById("pair_work-two").className.indexOf("hidden") != -1)
            {
                document.getElementById("pair_work-two").className = document.getElementById("pair_work-two").className.replace("hidden", "");
                ScrollWin.scroll("work-two");
            }
            else if(document.getElementById("pair_work-three").className.indexOf("hidden") != -1)
            {
                document.getElementById("pair_work-three").className = document.getElementById("pair_work-two").className.replace("hidden", "");
                ScrollWin.scroll("work-three");
            }
            else if(document.getElementById("pair_work-four").className.indexOf("hidden") != -1)
            {
                document.getElementById("pair_work-four").className = document.getElementById("pair_work-two").className.replace("hidden", "");
                ScrollWin.scroll("work-four");
            }
            else if(document.getElementById("pair_work-five").className.indexOf("hidden") != -1)
            {
                document.getElementById("pair_work-five").className = document.getElementById("pair_work-two").className.replace("hidden", "");
                ScrollWin.scroll("work-five");
                this.parentNode.parentNode.removeChild(this.parentNode);
            }
        }
    }
    ,
    '#contact_section .pseudo-link' : function(el)
    {
        el.onmouseover = function()
        {
            this.style.color = "white";
            this.style.backgroundColor = "#A89637";
        }
        ;
        el.onmouseout = function()
        {
            this.style.color = "#A89637";
            this.style.backgroundColor = "transparent";
        }
    }
    ,
    '#pseudo-link_calling' : function(el)
    {
        el.onclick = function()
        {
            if(document.getElementById("phone_detail_contact").childNodes[0].childNodes[0].nodeValue == "086 60 32 755")
            {
                document.getElementById("phone_detail_contact").childNodes[0].childNodes[0].nodeValue = "+353 86 60 32 755";
                this.childNodes[0].childNodes[0].nodeValue = "Calling from inside Ireland?";
            }
            else
            {
                document.getElementById("phone_detail_contact").childNodes[0].childNodes[0].nodeValue = "086 60 32 755";
                this.childNodes[0].childNodes[0].nodeValue = "Calling from outside Ireland?";
            }
        }
        ;
        el.onmouseover = function()
        {
            this.style.color = "white";
            this.style.backgroundColor = "#A89637";
        }
        ;
        el.onmouseout = function()
        {
            this.style.color = "#A89637";
            this.style.backgroundColor = "transparent";
        }
    }
    ,
    'form input' : function(el)
    {
        el.onfocus = function()
        {
            if(this.id == "send_form")
            {
                this.style.color = "white";
                if(valid())
                {
                    this.style.backgroundColor = "#A89637";
                }
                else
                {
                    this.style.backgroundColor = "red";
                    document.getElementById("required-message").style.color = "red";
                }
            }
            else
            {
                this.style.backgroundColor = "#F1F0ED";
            }
        }
        ;
        el.onblur = function()
        {
            this.style.backgroundColor = "transparent";
            clear();
            if(this.id == "send_form")
            this.style.color = "#A89637";
            else
            this.style.color = "#494848";
        }
    }
    ,
    'form textarea' : function(el)
    {
        el.onfocus = function()
        {
            this.style.backgroundColor = "#F1F0ED";
        }
        ;
        el.onblur = function()
        {
            this.style.backgroundColor = "transparent";
        }
    }
    ,
    '#send_form' : function(el)
    {
        el.onmouseover = function()
        {
            if(! valid())
            {
                this.style.backgroundColor = "red";
                this.style.color = "white";
                document.getElementById("required-message").style.color = "red";
            }
            else
            {
                this.style.backgroundColor = "#A89637";
                this.style.color = "white";
            }
        }
        ;
        el.onmouseout = function()
        {
            this.style.backgroundColor = "transparent";
            this.style.color = "#A89637";
            clear();
        }
    }
    ,
    'form' : function(el)
    {
        el.onsubmit = function()
        {
            return valid();
        }
    }
    ,
    '#phone_form' : function(el)
    {
        el.onkeyup = function()
        {
            phone_check(this);
        }
    }
    ,
    '#email_form' : function(el)
    {
        el.onkeyup = function()
        {
            email_check(this);
        }
    }
}
;
Behaviour.register(myrules); 