﻿function submitform() {

    // Get all raw_ text inputs
    var allTextAreas = document.getElementsByTagName('textarea');
    for (i = 0; i < allTextAreas.length; i++) {
        var aDiv = allTextAreas[i];
        var sID = aDiv.id;
        if (sID.indexOf('raw_') == 0) {
            // Set textbox content to the related editable div content (id without leading raw_)

            document.getElementById(sID).value = document.getElementById(sID.substring(4)).innerHTML;
        }
    }

    document.getElementById("pageContent").submit();
}

$(function() {
    $(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });

    var pic1 = new picture(1);

    $('.picture').hover(function() {

        var Id = $(this).attr('id');
        var position = $('#' + Id + 'Holder').position();

        pic1.getOverlayInfo(position, Id);
        pic1.getLargeDiv();

    }, function() {

        // Slide down main img
        var Id = $(this).attr('id');
        $("#overlay").stop(true, true).hide();
        $('#' + Id).stop(true, true).css({ "z-index": "0" });
        $('#overlay').stop(true, true).css({ "height": "120px", "width": "350px" });

    });

    //slide up main img
    $('.mainPicture').hover(function() {

        $('#mainBackgroundImg').stop(true, true).animate({ "top": "-205px" }, 300)

    }, function() {

        $('#mainBackgroundImg').stop(true, true).animate({ "top": "0px" }, 300)

    });

});

function picture() {
if (document.getElementById("stage") != null) {
    if ($('#stage')) {
        this.fromTheEdge = $('#stage').offset().left + 1;
        this.leftPos;
        this.topPos;
        this.iD;
        this.text;
        this.direction;
        this.content;

        this.getOverlayInfo = function(position, id) {

            this.leftPos = position.left;
            this.topPos = position.top
            this.iD = id;
            this.iDNumber = id.substring(3);
            $('#overlay').css({ "top": "0px", "left": "0px", "diplay": "none" });

            switch (this.iDNumber) {
                case "1":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "2":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "3":
                    break;
                case "4":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "5":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "6":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "7":
                    this.direction = "R";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "8":
                    this.direction = "L";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                case "9":
                    this.direction = "L";
                    this.content = $('#' + id + ' img').attr('title');
                    break;
                default:
                    break;
            }
        }
        }
    }

    this.getLargeDiv = function() {

        if (this.direction == "R") {

            $('#overlay').stop(true, true).css({ "z-index": "1", "top": (this.topPos - 10) + "px", "left": (this.leftPos - 10) + "px", "opacity": "0" });
            $('#' + this.iD).stop(true, true).css({ "z-index": "2" });
            $('#overlay').stop(true, true).animate({ "height": "140px", "width": "380px", "opacity": "1", "top": (this.topPos - 20) + "px", "left": (this.leftPos - 20) + "px" }, 100);
            $('#overlay #content h4').stop(true, true).css({ "padding": "0px 0px 0px 180px", "width": "180px" }).html(this.content);

        }
        else {

            $('#overlay').stop(true, true).css({ "z-index": "1", "top": (this.topPos - 10) + "px", "left": (this.leftPos - 200) + "px", "opacity": "0" });
            $('#' + this.iD).stop(true, true).css({ "z-index": "2" });
            $('#overlay').stop(true, true).animate({ "height": "140px", "width": "380px", "opacity": "1", "top": (this.topPos - 20) + "px", "left": (this.leftPos - 210) + "px" }, 100);
            $('#stage #content h4').stop(true, true).css({ "padding": "6px 0px 0px 18px", "width": "180px" }).html(this.content);

        }

    }

}


//Drag and drop sorting
$(document).ready(function() {

    $("#sortable").sortable({ update: function() {
        var x = $("#sortable").sortable('toArray');
        $("#hiddenorder").val('');
        for (var t = 0; t < x.length; t++) {
            var hiddenord = $("#hiddenorder").val();
            $("#hiddenorder").val(hiddenord + x[t] + '|');
        }
        //alert($("#hiddenorder").val())
    }
    });

    $('#closeBookingForm').click(function() {
        $('#bookingForm').hide()
        $('#blackoutGrid').hide();
    });

    $(function() {
        var tabContainers = $('div.views > div');
        tabContainers.hide();
        $('#process-chart a').click(function() {
            tabContainers.hide().filter(this.hash).show();
            $('.default').hide();
            $('process-chart a').removeClass('selected');
            $(this).addClass('selected');

            return false;
        });
    });

    $(function() {
        var tabContainers = $('div.views > div');
        tabContainers.hide();
        $('#start-diagram a').click(function() {
            tabContainers.hide().filter(this.hash).show();
            $('.default').hide();
            $('start-diagram a').removeClass('selected');
            $(this).addClass('selected');

            return false;
        });
    });

    $("#call-back").click(function() {
        // Sit right edge with right edge of nav bar
        $left = $('#header').position().left;
        $leftpos = $left + 620;
        $('#enquiry-flyout').css('left', $leftpos + 'px');
        // Show flyout
        $('#enquiry-flyout').slideToggle(200);
        return false;
    });

});

function opencallback() {
    $left = $('#header').position().left;
    $leftpos = $left + 620;
    $('#enquiry-flyout').css('left', $leftpos + 'px');
    // Show flyout
    $('#enquiry-flyout').show();
}


function book(day, month, year) {
    $('#bookingForm').css({ position: "absolute", top: "+70px", left: "+30px" });
    $('.date').hide()
    $('#bookingForm').fadeIn(1400);
    $('#blackoutGrid').show();
    $('#dateChosen').show();
    $('#dateChosentd').html(day + "/" + month + "/" + year);
    $('#Day').val(day);
    $('#Month').val(month);
    $('#Year').val(year);
}

function stayForValidation(day, month, year) {
    $('#bookingForm').css({ position: "absolute", top: "+70px", left: "+30px" });
    $('.date').hide()
    $('#bookingForm').show()
    $('#dateChosen').show()
    $('#blackoutGrid').show();
    $('#dateChosentd').html(day + "/" + month + "/" + year);
    $('#Day').val(day);
    $('#Month').val(month);
    $('#Year').val(year);
}

function listBook() {
    $('.bookingForm').css({ position: "absolute", top: "+70px", left: "+30px" });
    //$('.date').hide()
    $('.bookingForm').fadeIn(1400);
    $('#blackoutGrid').show();
    $('#dateChosen').show();
    $('#dateChosentd').html(1 + "/" + 1 + "/" + 2010);
    $('#Day').val(1);
    $('#Month').val(1);
    $('#Year').val(2010);
}



