﻿var clWin = new Array();

function open_w(url, name, features) {
    var p = clWin.length;
    for (var i = 0; i < clWin.length; i++) {
        if (clWin[i] == null) {
            p = i;
        } else {
            if (clWin[i].closed) {
                clWin[i] = null;
            } else {
                if (clWin[i].name == name) {
                    clWin[i].close();
                    clWin[i] = null;
                }
            }
        }
    }
    clWin[p] = window.open(url, name, features);
    clWin[p].focus();
    clWin[p].moveTo((screen.availWidth - 320) / 2, (screen.availHeight - 309) / 2);
}

function open_x(url, name, features, width, height) {
    var p = clWin.length;
    for (var i = 0; i < clWin.length; i++) {
        if (clWin[i] == null) {
            p = i;
        } else {
            if (clWin[i].closed) {
                clWin[i] = null;
            } else {
                if (clWin[i].name == name) {
                    clWin[i].close();
                    clWin[i] = null;
                }
            }
        }
    }
    clWin[p] = window.open(url, name, features);
    clWin[p].focus();
    clWin[p].moveTo((screen.availWidth - width) / 2, (screen.availHeight - height) / 2);
}

function inputInitialise(element, test) {
    if (!element)
        return;
	if (element.value != test)
		element.style.color = '#000';
    else
        element.style.color = '#888';
}

function initPage() {
    inputInitialise(document.getElementById("search-search"), "Enter search keywords...");
    inputInitialise(document.getElementById("newsletter"), "Enter e-mail address...");
    inputInitialise(document.getElementById("email"), "Enter e-mail address...");

    if (document.getElementById("frontimageblock") != null)
        startFrontPage();

    if (document.getElementById("myGallery") != null)
        startGallery();
}

function startGallery() {
    var myGallery = new gallery($('myGallery'), {
        timed: true,
        showArrows: false,
        showCarousel: false,
        embedLinks: false
    });
}

function inputFocus(element, test) {
	defaultString = test;
	if (element.value == test) {
		element.value = "";
		element.style.color = '#000';
	}
}

function inputBlur(element) {
	if (element.value == '') {
		element.value = defaultString
		element.style.color = '#888';
	}
	defaultString = '';
}

function butOn(element) {
	var image = element.src.toString();
	if (image.lastIndexOf(".") != -1)
		element.src = image.substring(0, image.lastIndexOf(".")) + "-on" + image.substring(image.lastIndexOf("."));
}

function butOff(element) {
	var image = element.src.toString();
	if (image.lastIndexOf(".") != -1)
		element.src = image.substring(0, image.lastIndexOf(".") - 3) + image.substring(image.lastIndexOf("."));
}

function verifyEmail() {
    var text = document.getElementById("email-link");
    if (text.value == "Enter e-mail address...") {
        alert("Please enter an e-mail address.");
        return false;
    }
    return true;
}

function verifyEmailAddress() {
    var text = document.getElementById("email");
    if (text.value == "") {
        alert("Please enter an e-mail address.");
        return false;
    }
    text = document.getElementById("name");
    if (text.value == "") {
        alert("Please enter a name.");
        return false;
    }
    return true;
}

function verifySendEmail() {
    var text = document.getElementById("email");
    if (text.value == "") {
        alert("Please enter an e-mail address.");
        return false;
    }
    text = document.getElementById("name");
    if (text.value == "") {
        alert("Please enter your name.");
        return false;
    }
    text = document.getElementById("details");
    if (text.value == "") {
        alert("Please enter a message.");
        return false;
    }
    return true;
}

function verifySearch() {
    var text = document.getElementById("search-search");
    if (text.value == "Enter search keywords...") {
        alert("Please enter some search keywords.");
        return false;
    }
    return true;
}

function verifyNewsletter() {
    var text = document.getElementById("newsletter");
    if (text.value == "Enter e-mail address...") {
        alert("Please enter an e-mail address.");
        return false;
    }
    return true;
}

function showVideo(path) {
    win = new Window({ className: "alphacube", url: "/Video/Show-Video.aspx?file=" + path, width: 480, height: 360, zIndex: 100, resizable: false, title: "Video Presentation", showEffect: Effect.Appear, hideEffect: Effect.Fade, draggable: false, minimizable: false, maximizable: false })
    win.showCenter(true);
}
