﻿//--------------------------------------- Google Maps Shiznit -----------------------------------------

var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        setDirections("1200 Brooks Avenue, Rochester, NY 14624 (Greater Rochester International Airport)", "833 Phillips Rd, Victor, NY 14564", "en_US");
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
    }
}

function setDirections(fromAddress, toAddress, locale) {
    gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
}

function handleErrors() {
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
        alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
        alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
        alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

    //   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
    //     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus().code == G_GEO_BAD_KEY)
        alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
        alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

    else alert("An unknown error occurred.");

}

function onGDirectionsLoad() {
    // Use this function to access information about the latest load()
    // results.

    // e.g.
    // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
    // and yada yada yada...
}


//--------------------------------- initialize accordions ----------------------------------

ddaccordion.init({
    headerclass: "ProductFormHeader", //Shared CSS class name of headers group
    contentclass: "ProductForm", //Shared CSS class name of contents group
    revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
    mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
    defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
    animatedefault: false, //Should contents open by default be animated into view?
    persiststate: false, //persist state of opened contents within browser session?
    toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    togglehtml: ["prefix", "<img src='/images/plus.gif' class='statusicon' />", "<img src='/images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    oninit: function(headers, expandedindices) { //custom code to run when headers have initalized
        //do nothing
    },
    onopenclose: function(header, index, state, isuseractivated) { //custom code to run whenever a header is opened or closed
        //do nothing
    }
})


//----------------------------Product form validation--------------------------------------
EmailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

function CheckAreas1() {
    varflag = 0
    errmsg = ''

    if (document.ProductForm.first_name.value == '') {
        document.ProductForm.first_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your First Name.\n";
        varflag = 1
    }
    if (document.ProductForm.last_name.value == '') {
        document.ProductForm.last_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Last Name.\n";
        varflag = 1
    }
    if (document.ProductForm.title.value == '') {
        document.ProductForm.title.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Title.\n";
        varflag = 1
    }

    if (document.ProductForm.email.value.search(EmailReg) == -1) {
        document.ProductForm.email.style.backgroundColor = '#FF0000';
        errmsg += "Please enter a valid Email Address.\n";
        varflag = 1
    }
    if (document.ProductForm.phone.value == '') {
        document.ProductForm.phone.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Phone Number.\n";
        varflag = 1
    }
    if (document.ProductForm.company.value == '') {
        document.ProductForm.company.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Company.\n";
        varflag = 1
    }
    
    if (varflag == 1) {
        alert(errmsg);
        return false;
    }
    else {
        document.ProductForm.submit.style.cursor = 'wait'; document.body.style.cursor = 'wait';
        document.ProductForm.submit.value = 'Please Wait...';
        return true;
    }
}

//--------------------------------- Partner form validation ---------------------------------------
function CheckAreas2() {
    varflag = 0
    errmsg = ''

    if (document.PartnerForm.first_name.value == '') {
        document.PartnerForm.first_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your First Name.\n";
        varflag = 1
    }
    if (document.PartnerForm.last_name.value == '') {
        document.PartnerForm.last_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Last Name.\n";
        varflag = 1
    }
    if (document.PartnerForm.title.value == '') {
        document.PartnerForm.title.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Title.\n";
        varflag = 1
    }

    if (document.PartnerForm.email.value.search(EmailReg) == -1) {
        document.PartnerForm.email.style.backgroundColor = '#FF0000';
        errmsg += "Please enter a valid Email Address.\n";
        varflag = 1
    }
    if (document.PartnerForm.phone.value == '') {
        document.PartnerForm.phone.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Phone Number.\n";
        varflag = 1
    }
    if (document.PartnerForm.company.value == '') {
        document.PartnerForm.company.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Company.\n";
        varflag = 1
    }

    if (varflag == 1) {
        alert(errmsg);
        return false;
    }
    else {
        document.PartnerForm.submit.style.cursor = 'wait'; document.body.style.cursor = 'wait';
        document.PartnerForm.submit.value = 'Please Wait...';
        return true;
    }
}

//--------------------------------- Media form validation ---------------------------------------
function CheckAreas3() {
    varflag = 0
    errmsg = ''

    if (document.MediaForm.first_name.value == '') {
        document.MediaForm.first_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your First Name.\n";
        varflag = 1
    }
    if (document.MediaForm.last_name.value == '') {
        document.MediaForm.last_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Last Name.\n";
        varflag = 1
    }
    if (document.MediaForm.title.value == '') {
        document.MediaForm.title.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Title.\n";
        varflag = 1
    }

    if (document.MediaForm.email.value.search(EmailReg) == -1) {
        document.MediaForm.email.style.backgroundColor = '#FF0000';
        errmsg += "Please enter a valid Email Address.\n";
        varflag = 1
    }
    if (document.MediaForm.phone.value == '') {
        document.MediaForm.phone.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Phone Number.\n";
        varflag = 1
    }
    if (document.MediaForm.company.value == '') {
        document.MediaForm.company.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Company.\n";
        varflag = 1
    }

    if (varflag == 1) {
        alert(errmsg);
        return false;
    }
    else {
        document.MediaForm.submit.style.cursor = 'wait'; document.body.style.cursor = 'wait';
        document.MediaForm.submit.value = 'Please Wait...';
        return true;
    }
}

//--------------------------------- Demo form validation ---------------------------------------
function CheckAreas4() {
    varflag = 0
    errmsg = ''

    if (document.DemoForm.first_name.value == '') {
        document.DemoForm.first_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your First Name.\n";
        varflag = 1
    }
    if (document.DemoForm.last_name.value == '') {
        document.DemoForm.last_name.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Last Name.\n";
        varflag = 1
    }
    if (document.DemoForm.title.value == '') {
        document.DemoForm.title.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Title.\n";
        varflag = 1
    }

    if (document.DemoForm.email.value.search(EmailReg) == -1) {
        document.DemoForm.email.style.backgroundColor = '#FF0000';
        errmsg += "Please enter a valid Email Address.\n";
        varflag = 1
    }
    if (document.DemoForm.phone.value == '') {
        document.DemoForm.phone.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Phone Number.\n";
        varflag = 1
    }
    if (document.DemoForm.company.value == '') {
        document.DemoForm.company.style.backgroundColor = '#FF0000';
        errmsg += "Please enter your Company.\n";
        varflag = 1
    }

    if (varflag == 1) {
        alert(errmsg);
        return false;
    }
    else {
        document.DemoForm.submit.style.cursor = 'wait'; document.body.style.cursor = 'wait';
        document.DemoForm.submit.value = 'Please Wait...';
        return true;
    }
}