function Hsd()
{
    this.container = null;
    this.contactForm = null;

    this.load = function()
    {
        this.container = $(document.body).getElement("div.container");
        this.windowResize();
        this.setupStuurDoor();
        
        window.addEvent("resize",function(){
           hsd.windowResize();
        });
    }

    this.windowResize = function()
    {
        var left = (window.getWidth()/2)-(990/2)-51;
        var top = (window.getHeight()/2)-(700/2)-66;
        var logo = $(document.body).getElement("div.container a.logo");

        if( left < -37 )
        {
            left = -37;
        }

        if( top < -136 )
        {
            top = -136;
        }

        var logoTop = 27;
        if( top < 27 )
        {
            logoTop = Math.abs(top)+3;
        }

        this.container.setStyle("left",left);
        this.container.setStyle("top",top);
        logo.setStyle("top",logoTop);

        if( 990+left-54 < 990 )
        {
            this.container.setStyle("width",990+left-54);
        }
        else
        {
            this.container.setStyle("width",990);
        }

        if( 700+top-54 < 700 )
        {
            this.container.setStyle("height",700+top-54);
        }
        else
        {
            this.container.setStyle("height",700);
        }
    }

    this.contactSubmit = function()
    {
        if( ($("frmContact_name").value = $("frmContact_name").value.trim()).length < 2 )
        {
            alert("Vul aub uw voor- en achternaam in.");
            $("frmContact_name").focus();
            return false;
        }

        if(
            ( ($("frmContact_email").value = $("frmContact_email").value.trim()).length < 5 ) ||
            ( $("frmContact_email").value.indexOf("@") == -1 ) ||
            ( $("frmContact_email").value.indexOf(".") == -1 )
        )
        {
            alert("Vul aub uw e-mailadres in.");
            $("frmContact_email").focus();
            return false;
        }

        if( ($("frmContact_telephone").value = $("frmContact_telephone").value.trim()).length < 10 )
        {
            alert("Vul aub uw telefoonnummer in.");
            $("frmContact_telephone").focus();
            return false;
        }

        if( ($("frmContact_request").value = $("frmContact_request").value.trim()).length < 10 )
        {
            alert("Vul aub uw aanvraag in. Deze dient minimaal uit 10 tekens te bestaan.");
            $("frmContact_request").focus();
            return false;
        }

        $("frmContact_send").value = "True";

        return true;
    }

    this.setupStuurDoor = function(){

        var back = new Element("div");
        back.addClass("stuurdoorback");
        back.setStyle("opacity",0.6);
        back.setStyle("display","none");
        back.inject($(document.body));
        back.addEvent("click",function(){
            var back = $(document.body).getElement("div.stuurdoorback");
            back.setStyle("display","none");
            var form = $(document.body).getElement("form.stuurdoorbox");
            form.setStyle("display","none");
        });

        var box = new Element("form");
        box.addClass("stuurdoorbox");
        box.setAttribute("method","post");
        box.setAttribute("action","stuurdoor.php");
        box.setStyle("display","none");

        box.inject($(document.body));

            var nameLabel = new Element("label");
            nameLabel.innerHTML = "Uw naam:";
            nameLabel.inject(box);

            var senderName = new Element("input");
            senderName.setAttribute("type","text");
            senderName.setAttribute("name","senderName");
            senderName.inject(box);

            var receipientNameLabel = new Element("label");
            receipientNameLabel.innerHTML = "Naam van ontvanger:";
            receipientNameLabel.inject(box);

            var receipientName = new Element("input");
            receipientName.setAttribute("type","text");
            receipientName.setAttribute("name","receipientName");
            receipientName.inject(box);

            var receipientEmailLabel = new Element("label");
            receipientEmailLabel.innerHTML = "E-mailadres van ontvanger:";
            receipientEmailLabel.inject(box);

            var receipientEmail = new Element("input");
            receipientEmail.setAttribute("type","text");
            receipientEmail.setAttribute("name","receipientEmail");
            receipientEmail.inject(box);

            var submitButton = new Element("button");
            submitButton.setAttribute("type","submit");
            submitButton.inject(box);
            submitButton.instance = this;
            submitButton.addEvent("click",function(e){
                e = new Event(e);
                if( !this.instance.stuurDoorSubmit() )
                {
                    e.stop();
                }
            });

        var button = new Element("div");
        button.setAttribute("id","stuurdoor");
        button.addEvent("click",function(){
            var back = $(document.body).getElement("div.stuurdoorback");
            back.setStyle("display","block");
            var form = $(document.body).getElement("form.stuurdoorbox");
            form.setStyle("display","block");
        });
        button.inject($(document.body).getElement("div.container"));
    }

    this.stuurDoorSubmit = function(){

        var senderName = $(document.body).getElement("form.stuurdoorbox input[name=senderName]");
        var receipientName = $(document.body).getElement("form.stuurdoorbox input[name=receipientName]");
        var receipientEmail = $(document.body).getElement("form.stuurdoorbox input[name=receipientEmail]");

        if( (senderName.value = senderName.value.trim()).length < 2 )
        {
            alert("Vul aub uw naam in.");
            senderName.focus();
            return false;
        }

        if( (receipientName.value = receipientName.value.trim()).length < 2 )
        {
            alert("Vul aub de naam van de ontvanger in.");
            receipientName.focus();
            return false;
        }

        if(
            ( (receipientEmail.value = receipientEmail.value.trim()).length < 5 ) ||
            ( receipientEmail.value.indexOf("@") == -1 ) ||
            ( receipientEmail.value.indexOf(".") == -1 )
        )
        {
            alert("Vul aub het e-mailadres van de ontvanger in.");
            receipientEmail.focus();
            return false;
        }

        pageTracker._trackPageview("/click/stuurdoor-submit");

        return true;
    }
}

var hsd = new Hsd();

document.addEvent("domready",function(){
   hsd.load();
});
