// JavaScript Document

function checkForm(which) {

    var ret = true;
    var errorStr = "";
    var theForm = document.forms[which];

    if (which == "registerForm") {
        if (theForm["Name"].value == "") {
            errorStr += "- Username can't be empty \n";
            setFormField(theForm["Name"], true);
        }
        else { setFormField(theForm["Name"], false); }

        if (theForm["Email1"].value == "") {
            errorStr += "- E-Mail can't be empty \n";
            setFormField(theForm["Email1"], true);
        }
        else { setFormField(theForm["Email1"], false); }


        if (theForm["Password"].value != theForm["Password2"].value) {
            errorStr += "- Your passwords do not match \n";
            setFormField(theForm["Password"], true);
            setFormField(theForm["Password2"], true);
        }
        else { setFormField(theForm["Password"], false); setFormField(theForm["Password2"], false); }

        if (theForm["Password"].value == "") {
            errorStr += "- Password can't be empty \n";
            setFormField(theForm["Password"], true);
        }
        else { setFormField(theForm["Password"], false); }

        if (theForm["Phone1"].value == "") {
            errorStr += "- Phone can't be empty \n";
            setFormField(theForm["Phone1"], true);
        }
        else { setFormField(theForm["Phone1"], false); }

        if (theForm["Address1"].value == "") {
            errorStr += "- Address 1 can't be empty \n";
            setFormField(theForm["Address1"], true);
        }
        else { setFormField(theForm["Address1"], false); }

        if (theForm["Postcode"].value == "") {
            errorStr += "- Postcode can't be empty \n";
            setFormField(theForm["Postcode"], true);
        }
        else { setFormField(theForm["Postcode"], false); }

        if (theForm["Town"].value == "") {
            errorStr += "- Town/City can't be empty \n";
            setFormField(theForm["Town"], true);
        }
        else { setFormField(theForm["Town"], false); }

        if (theForm["CountryID"].selectedIndex == 0) {
            errorStr += "- you have to select a country \n";
            setFormField(theForm["Country"], true);
        }
        else { setFormField(theForm["Country"], false); }

        if (!theForm["Agree"].checked) {
            errorStr += "- You have to agree to the Terms & Conditions \n";
            setFormField(theForm["Agree"], true);
        }
        else { setFormField(theForm["Agree"], false); }
    }
    else if (which == "payForm") {
        if (!theForm["Agree"].checked) {
            errorStr += "- You have to agree to the Terms & Conditions \n";
            setFormField(theForm["Agree"], true);
        }
        else { setFormField(theForm["Agree"], false); }
    }
    if (errorStr != "") {
        alert("You had an error in your form. Please review.\n" + errorStr);
        ret = false;
    }
    return ret;
}

function setFormField(which,isError) {
    which.style.border = isError ? "1px solid red" : "1px inset";
}

function loadFlash(flashWidth,flashHeight,flashName)
{
	AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
										'width',flashWidth,
										'height',flashHeight,
										'align','middle',
										'src',flashName,
										'quality','high',
										'bgcolor','#fffff',
										'name','foo',
										'allowscriptaccess','always',
										'wmode','transparent',
										'pluginspage','http://www.macromedia.com/go/getflashplayer',
										'movie',flashName);

}

var accordion2selected = "slider5";
var newselected;





/*
* Image preview script 
* powered by jQuery (http://www.jquery.com)
* 
* written by Alen Grakalic (http://cssglobe.com)
* 
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/


var isOver = false;
this.imagePreview = function () {
    /* CONFIG */


    xOffset = 15;
    yOffset = 30;
    fadeOutDiv = 0;
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result

    /* END CONFIG */
    $("area.prev").hover(function (e) {
        this.t = this.title;
        this.title = "";
        isOver = true;
        $("#how_" + this.t).stop(true,true).show();
        if ($("#prev" + this.t).length == 0) {
            $("body").append("<p id='prev" + this.t + "' class='pr'><img src='" + this.alt + "' alt='Image preview' /></p>");
        }
        yOffset = $("#prev" + this.t).height();
        $("#prev" + this.t)
			.css("top", (e.pageY - yOffset) + "px")
			.css("left", (e.pageX + xOffset) + "px")
            .css("position", "absolute")
            .css("display", "none")
			.stop(true,true).show();
    },
	function () {
	    this.title = this.t;
	    $("#how_" + this.t).stop(true,true).hide();
	    fadeOutDiv = this.t;
	    $("#prev" + fadeOutDiv).stop(true, true).hide();
	    isOver = false;
	});
    $("body").mousemove(function (e) {
        //alert(e.pageY - xOffset + " x " + eval(e.pageX + yOffset));
        $(".pr")
			.css("top", (e.pageY - yOffset) + "px")
			.css("left", (e.pageX + xOffset) + "px")
            .css("position", "absolute");
    });

};

$(document).ready(function () {


    $("a.flashFancybox").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'width': 630,
        'height': 600,
        'overlayShow': false,
        'titleShow': false,
        'type': 'iframe'
    });

    $("a.presentationFancybox").fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'speedIn': 600,
        'speedOut': 200,
        'width': 452,
        'height': 413,
        'overlayShow': true,
        'titleShow': false,
        'type': 'iframe'
    });

    $("a.ajaxFancybox").fancybox({
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'speedIn': 600,
        'speedOut': 200,
        'width': 680,
        'height': 600,
        'overlayShow': true,
        'titleShow': false,
        'type': 'ajax'
    });

    $(".accordion2").click(function () {
        newselected = this.id;
        $("#" + accordion2selected + "box").slideUp(100, function () { $("#" + newselected + "box").slideDown(100); });
        accordion2selected = this.id;
        return false;
    });
    imagePreview();

    $(".foldable").click(function () {
        var theID = $(this).attr("id");
        var thePos = theID.indexOf("_");
        var theName = theID.substring(0, thePos);
        if ($("#" + theName).is(":visible") == true) {
            $("#" + theName + "_header").removeClass("foldableHeader").addClass("foldableHeaderOff");
            $("#" + theName).slideUp("medium");
        }
        else {
            $("#" + theName + "_header").removeClass("foldableHeaderOff").addClass("foldableHeader");
            $("#" + theName).slideDown("medium");
        }
    });

    $(".vanishy").fadeTo(0, 0.75);

    $(".vanishy").mouseover(function () {
        $(this).fadeTo("fast", 1);
    });

    $(".vanishy").mouseleave(function () {
        $(this).fadeTo("fast", 0.75);
    });

    $(".descriptorField").focus(function () {
        $(this).css("background-position", "-100px 5px");
    });

    $(".descriptorField").blur(function () {
        var newPos = $(this).val() == "" ? "3px 5px" : "-100px 5px";
        $(this).css("background-position", newPos);
    });

    if ($("#timeZoneloader").length > 0) {
        getTimeZone();
    }
    $("#timeZoneSelector").change(function () {
        changeTimeZone($(this).val()); ;
    });

    $(".beautytipsFocus").bt({
        trigger: ['focus', 'blur'],
        fill: '#cecece',
        strokeWidth: 0, /*no stroke*/
        spikeLength: 150,
        spikeGirth: 10,
        centerPointY: 0,
        cornerRadius: 10, 
        positions: ['right'],
        cssStyles: {
            color: '#333333',
            fontSize: '1em'
        },
        shadow: true,
        shadowColor: 'rgba(0,0,0,.5)',
        shadowBlur: 8,
        shadowOffsetX: 4,
        shadowOffsetY: 4
    });

    $(".beautytipsHover").bt({
        fill: '#cecece',
        strokeWidth: 0, /*no stroke*/
        spikeLength: 120,
        spikeGirth: 10,
        positions: ['right'],
        cssStyles: {
            color: '#333333',
            fontSize: '1em'
        }
    });

    $("[class=datepicker]").datepicker({
        dateFormat: "dd/mm/yy",
        changeMonth: true,
        changeYear: true

    });

    //alert($("timeZones:has(select)"));
});

function getTimeZone() {
    var now = new Date();
    var timeZoneOffset = now.getTimezoneOffset();
    timeZoneOffset = timeZoneOffset / -60;
    var target = $("#timeZoneTarget").val() + "/Get/" + timeZoneOffset;
    $.ajax({ url: target, context: document.body, success: function (data) {
        $("#timeZones").html(data);
        $("#timeZoneSelector").change(function () {
            changeTimeZone($(this).val()); ;
            });
        }
    });
}

function changeTimeZone(newTimeZone) {
    var target = $("#timeZoneTarget").val() + "/Set/" + newTimeZone;
    $("#timeZones").html("<br />Updating timezone<blink>...</blink>");
    $.ajax({ url: target, context: document.body, success: function (data) {
        $("#timeZones").html(data);
        $("#timeZoneSelector").change(function () {
            changeTimeZone($(this).val()); ;
            });
        }
    });

    if (typeof(classArray)!="undefined") {

    }
}
