﻿function popupwin(str_url, h, w, scrolling) {
    vars = "height=" + h + ",width=" + w + ",left=" + (screen.width / 2 - (w / 2)) + ",top=" + (screen.height / 2 - (h / 2)) + ",scrollbars=" + scrolling + ",toolbar=no,status=no"
    focus_win = window.open(str_url, 'newwin', vars)
    focus_win.window.focus()
}


var gblPhotoShufflerDivId = "header-graphic";
var gblPhotoShufflerImgId = "photoimg";
var gblImg = new Array(
    "sitepix/header_swaps/1.jpg",
    "sitepix/header_swaps/2.jpg",
	"sitepix/header_swaps/3.jpg",
	"sitepix/header_swaps/4.jpg",
	"sitepix/header_swaps/5.jpg"
    );

var gblPauseSeconds = 5.5;
var gblFadeSeconds = 1.25;
var gblRotations = 999;

var jscript/*@cc_on = @_jscript_version@*/
if (self.jscript < 5.7)
{ gblFadeSeconds = 0 }

// End Customization section

var gblDeckSize = gblImg.length;
var gblOpacity = 100;
var gblOnDeck = 0;
var gblStartImg;
var gblImageRotations = gblDeckSize * (gblRotations + 1);

window.onload = photoShufflerLaunch;

function photoShufflerLaunch() {
    var theimg = document.getElementById(gblPhotoShufflerImgId);
    gblStartImg = theimg.src; // save away to show as final image

    document.getElementById(gblPhotoShufflerDivId).style.backgroundImage = 'url(' + gblImg[gblOnDeck] + ')';
    setTimeout("photoShufflerFade()", gblPauseSeconds * 1000);
}

function photoShufflerFade() {
    var theimg = document.getElementById(gblPhotoShufflerImgId);

    // determine delta based on number of fade seconds
    // the slower the fade the more increments needed
    var fadeDelta = 100 / (30 * gblFadeSeconds);

    // fade top out to reveal bottom image
    if (gblOpacity < 2 * fadeDelta) {
        gblOpacity = 100;
        // stop the rotation if we're done
        if (gblImageRotations < 1) return;
        photoShufflerShuffle();
        // pause before next fade
        setTimeout("photoShufflerFade()", gblPauseSeconds * 1000);
    }
    else {
        gblOpacity -= fadeDelta;
        setOpacity(theimg, gblOpacity);
        setTimeout("photoShufflerFade()", 30);  // 1/30th of a second
    }
}

function photoShufflerShuffle() {
    var thediv = document.getElementById(gblPhotoShufflerDivId);
    var theimg = document.getElementById(gblPhotoShufflerImgId);

    // copy div background-image to img.src
    theimg.src = gblImg[gblOnDeck];
    // set img opacity to 100
    setOpacity(theimg, 100);

    // shuffle the deck
    gblOnDeck = ++gblOnDeck % gblDeckSize;
    // decrement rotation counter
    if (--gblImageRotations < 1) {
        // insert start/final image if we're done
        gblImg[gblOnDeck] = gblStartImg;
    }

    // slide next image underneath
    thediv.style.backgroundImage = 'url(' + gblImg[gblOnDeck] + ')';
}

function setOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;

    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

function verify_email(str) {
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) { return false }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false }
    if (str.indexOf(at, (lat + 1)) != -1) { return false }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { return false }
    if (str.indexOf(dot, (lat + 2)) == -1) { return false }
    if (str.indexOf(" ") != -1) { return false }
    return true
}

function ensureNumeric(strString, mini, maxi) {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    if (strString.length < mini | strString.length > maxi) return false;
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function check_form(str_form, str_args) { // v0 copyright Andrew Watson Paligap 2004 (CALL) onClick="check_form('frm_subscribe','str_name|t|1|You have not entered your name.,str_email|e|1|You have entered an invalid e-mail address.');return document.check_form_return;"
    var arr_args = str_args.split(",")
    str_error_message = ""
    for (i = 0; i < arr_args.length; i++) {
        var arr_this_element = arr_args[i].split("|")
        str_field = arr_this_element[0]
        str_type = arr_this_element[1]
        bln_required = arr_this_element[2]
        str_message = arr_this_element[3]
        this_value = eval("document." + str_form + "." + str_field + ".value")
        this_value = this_value.replace(" ", "")
        if (str_type == "t") { //Check String
            if (bln_required == 1) {
                if (this_value == '') { str_error_message = str_error_message + str_message + "\n\n" }
            }
        } else if (str_type == "e") { //Check Email
            if (bln_required == 1) {
                if (this_value == '' || !verify_email(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            } else {
                if (this_value != '' && !verify_email(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            }
        } else if (str_type == "n") { //Check Numeric
            if (bln_required == 1) {
                if (this_value == '' || isNaN(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            } else {
                if (this_value != '' && isNaN(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            }
        } else if (str_type == "d") { //Check Date
            if (bln_required == 1) {
                if (this_value == '' || !verify_date(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            } else {
                if (this_value != '' && !verify_date(this_value)) { str_error_message = str_error_message + str_message + "\n\n" }
            }
        }
    }
    if (str_error_message != "") {
        str_error_message = "Incomplete Form Information!                              \n________________________\n\n" + str_error_message
        alert(str_error_message)
        document.check_form_return = false
    } else {
        document.check_form_return = true
        //eval("document.forms." + str_form + ".submit();")
    }
}
	
	