﻿//+++++++++++++++++++++++++
// time and date function
//+++++++++++++++++++++++++
function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function openWindow(swap1, swap2) {
    if ((isClicked) && (newWindow.closed == false)) {
        newWindow.close()
    }
    newWindow = window.open(swap1, '', swap2)
    temp = ""
    isClicked = true
}

function initArray() {
    for (i = 0; i < initArray.arguments.length; i++)
        this[i] = initArray.arguments[i];
}
var isnMonths = new initArray("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var isnDays = new initArray("(SUN)", "(MON)", "(TUE)", "(WED)", "(THU)", "(FRI)", "(SAT)", "(SUN)");
today = new Date();
hrs = today.getHours();
min = today.getMinutes();
sec = today.getSeconds();
clckh = "" + ((hrs > 12) ? hrs - 12 : hrs);
clckm = ((min < 10) ? "0" : "") + min;
clcks = ((sec < 10) ? "0" : "") + sec;
clck = (hrs >= 12) ? "p.m." : "a.m.";

var stnr = "";
var ns = "0123456789";
var a = "";




//REQUIRES onUnload="closeWindow()" IN THE BODY TAG///////////////////////////////////////////////
var isClicked = false
var newWindow = null

function openWindow(swap1, swap2) {
    if ((isClicked) && (newWindow.closed == false)) {
        newWindow.close()
    }
    newWindow = window.open(swap1, '', swap2)
    isClicked = true
}


function closeWindow() {
    if (newWindow) {
        newWindow.close()
    }
}




///open window function
var isClicked = 0
var newWindow = null
function openWindow(swap1, swap2) {
    if ((isClicked > 0) && (newWindow.closed == false)) {
        newWindow.close();
    }
    newWindow = window.open(swap1, '', swap2);
    isClicked++
}
function closeWindow() {
    if (newWindow) {
        newWindow.close()
    }
}



/////////////////////////////////////////////////////////////////////////////////////////////////

function valLogin() {
    if (document.summary.username.value == "") {
        alert("Please fill in this field as it is required.")
        document.summary.username.focus()
    }
    else if (document.summary.password.value == "") {
        alert("Please fill in this field as it is required.")
        document.summary.password.focus()
    }
    else { document.summary.submit() }
}











////////////

//FORM VALIDATION///////////////////////////////////////////////////////////////////////////////////////

// "t-" = TEXTBOX OR TEXTAREA
// "s-" = SELECT BOX (DROP-DOWN MENU)
// "r-" = RADIO BUTTONS
// "n-" = NUMBER in TEXTBOX
// "#"  = NUMBER WITH SPECIFIC LENGTH   example name : #-9socnum
// "e-" = EMAIL

var validateCounter
var myElement

function validate(swap) {
    myform = swap
    mySwitch = false
    counter = 0
    formTemp = ""



    for (validateCounter = 0; validateCounter < myform.length; validateCounter++) {
        if (myform.elements[validateCounter].name.charAt(1) == "-") {
            myElement = myform.elements[validateCounter].name
            if (myElement.charAt(0) == "t") { emptyField() }
            else if (myElement.charAt(0) == "s") { validateSelect() }
            else if (myElement.charAt(0) == "r") { validateRadio() }
            else if (myElement.charAt(0) == "n") { validateNumber() }
            else if (myElement.charAt(0) == "#") { validateNumLen() }
            else if (myElement.charAt(0) == "e") { validateEmail() }
        }
        if (mySwitch) { break }
    }

    if (!mySwitch) { myform.submit() }
}



//VALIDATE THERE'S SOMETHING IN TEXTFIELD//////////////////////////////////////////////////////////////

function emptyField() {
    mySwitch = false
    var space
    space = false

    for (var a = 0; a < myform.elements[validateCounter].value.length; a++) {
        if (myform.elements[validateCounter].value.charAt(a) == " ") {
            space = true
        }
        else {
            mySwitch = true
        }
    }

    if (space && !mySwitch) {
        mySwitch = true
    }
    else {
        mySwitch = false
    }

    if (mySwitch || myform.elements[validateCounter].value == "") {
        if (formBytes[myElement] != null) {
            alert(formBytes[myElement])
            mySwitch = true
        }
        else { alert("Please fill in this field as it is required.") }
        myform.elements[validateCounter].value = ""
        myform.elements[validateCounter].focus()
        mySwitch = true
    }
    else { mySwitch = false }
}


//SELECT / DROPDOWN MENUS///////////////////////////////////////////////////////////////////////////////

function validateSelect() {
    mySwitch = false

    if (myform.elements[validateCounter].selectedIndex == 0) {
        if (formBytes[myElement] != null) {
            alert(formBytes[myElement])
        }
        else {
            alert("Please make a selection from this dropdown menu as it is required.")
        }
        myform.elements[validateCounter].focus()
        mySwitch = true
    }
}






//RADIO BUTTONS//////////////////////////////////////////////////////////////////////////////////////

function validateRadio() {
    mySwitch = false
    counter = 0

    while (myform.elements[validateCounter + counter].name == myElement) {
        if (myform.elements[validateCounter + counter].checked) {
            mySwitch = true
        }
        counter++
    }

    if (!mySwitch) {
        if (formBytes[myElement] != null) {
            alert(formBytes[myElement])
        }
        else {
            alert("Please select one of the following options as it is required.")
        }
        myform.elements[validateCounter].focus()
        mySwitch = true
    }
    else {
        validateCounter = validateCounter + (counter - 1)
        mySwitch = false
    }
    counter = 0
}


//VALIDATE NUMBER////////////////////////////////////////////////////////////////////////////////////////////

function validateNumber() {
    emptyField()
    if (!mySwitch && isNaN(myform.elements[validateCounter].value)) {
        alert("Please fill this field in using ONLY valid numerals.")
        myform.elements[validateCounter].value = ""
        myform.elements[validateCounter].focus()
        mySwitch = true
    }
}


//VALIDATE NUMBER////////////////////////////////////////////////////////////////////////////////////////////

function validateNumLen() {
    emptyField()
    if (!mySwitch) { validateNumber() }
    if (!mySwitch) {
        counter = 2
        var num = ""
        while (!isNaN(myform.elements[validateCounter].name.charAt(counter))) {
            num = num + myform.elements[validateCounter].name.charAt(counter)
            counter = counter + 1
        }

        num = parseInt(num)
        if (!charCount(num)) {
            if (num == 1) {
                alert("This field requires " + num + " numeral to be valid.")
            }
            else {
                alert("This field requires " + num + " numerals to be valid.")
            }
            myform.elements[validateCounter].value = ""
            myform.elements[validateCounter].focus()
            mySwitch = true
        }
    }
}




//COUNT THE CHARACTERS////////////////////////////////////////////////////////////////////////////////

function charCount(swap) {
    if (myform.elements[validateCounter].value.length == swap) {
        return true
    }
}



//EMAIL//////////////////////////////////////////////////////////////////////////////////////////////

function validateEmail() {
    emptyField()
    if (!charCheck("@") && !mySwitch) {
        alert("Certain characters required for a valid email address are missing in this field.")
        myform.elements[validateCounter].focus()
        myform.elements[validateCounter].value = ""
        mySwitch = true
    }
    else if (!charCheck(".") && !mySwitch) {
        alert("Certain characters required for a valid email address are missing in this field.")
        myform.elements[validateCounter].focus()
        myform.elements[validateCounter].value = ""
        mySwitch = true
    }
}




//VALIDATE SPECIFIC CHARACTERS///////////////////////////////////////////////////////////////////

function charCheck(swap) {
    formTemp = myform.elements[validateCounter].value

    for (var i = 0; i < formTemp.length; i++) {
        if (formTemp.charAt(i) == swap) {
            return true
        }
    }
}



//////
//validate function
//////////

function noEntry() {
    mt = document.contact.eventType.value;
    if ((mt.length < 1) || (mt.substring(0, 6) == "******")) {
        alert("You must include your event type");
        document.contact.eventType.value = "Complete This Entry";
        document.contact.eventType.focus();
        return false;
    }
    else { return true; }
}

//////
//validate function register
//////////

function noEntryR() {
    mt = document.register.storelocation.value;
    if ((mt.length < 1) || (mt.substring(0, 6) == "******")) {
        alert("You must include a store location");
        document.register.storelocation.value = "Complete This Entry";
        document.register.storelocation.focus();
        return false;
    }
    else { return true; }
}

/////////////
//reset function
////////

function resetform() {
    document.contact.reset()
}

////////////


///////////////
//open window function
///////////////

var isClicked = 0
var newWindow = null
function openWindow(swap1, swap2) {
    if ((isClicked > 0) && (newWindow.closed == false)) {
        newWindow.close();
    }
    newWindow = window.open(swap1, '', swap2);
    isClicked++
}
function closeWindow() {
    if (newWindow) {
        newWindow.close()
    }
}




//MODIFY ACCORDINGLY FOR WEBSPEED

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// popup window script
var isClicked = 0
var newWindow = null

function openWindow2() {
    if ((isClicked > 0) && (newWindow.closed == false)) {
        newWindow.close();
    }
    newWindow = window.open('difference.html', '', 'width=600,height=400,top=25,left=150,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes');
    isClicked++
}


function closeWindow2() {
    if (newWindow) {
        newWindow.close()
    }
}

///////////////////
//rollover script
//////////////////

//ALL ROLLOVERS REQUIRE A NAMING PROTOCOL SUFFIXING IMAGE NAMES WITH "_ON" AND "_OFF"///////////////

function rollOn(number, type) {
    document[number].src = "images/" + number + "_on." + type
}

function rollOff(number, type) {
    document[number].src = "images/" + number + "_off." + type
}


var preload = new Array("nav_about", "nav_product", "nav_programs", "nav_education", "nav_ordering")
var jpgpreload = new Array()
var gifpreload = new Array()

for (var a = 0; a < preload.length; a++) {
    gifpreload[a] = new Image()
    gifpreload[a].src = 'images/' + preload[a] + '_on.gif'

    jpgpreload[a] = new Image()
    jpgpreload[a].src = 'images/' + preload[a] + '_on.jpg'
}

function window.onbeforeprint() {
    myReference = document.getElementById('menus')
    myReference.style.visibility = 'hidden'
    if (ie4)
        menus[0].main.style.visibility = "hidden";
    else if (ie5_mac)
        menus[0].main.style.visibility = "hidden";
    else if (ie55)
        menus[0].main.style.visibility = "hidden";
    else if (nn4)
        menus[0].main.hidden = true;
    else if (dom)
        menus[0].main.style.visibility = "hidden";
    else
        menus[0].main.style.visibility = "hidden";
    menus[0].main.hidden = true;
}

function window.onafterprint() {
    if (ie4)
        menus[0].main.style.visibility = "visible";
    else if (ie5_mac)
        menus[0].main.style.visibility = "visible";
    else if (ie55)
        menus[0].main.style.visibility = "visible";
    else if (nn4)
        menus[0].main.hidden = false;
    else if (dom)
        menus[0].main.style.visibility = "visible";
    else
        menus[0].main.style.visibility = "visible";
    menus[0].main.hidden = false;
}


