/*  ------------------------------------------------------------------
    Variables -------------------------------------------------------- */
    var parentDomain = 'http://sgill.main.iabcanada.theniceagency.com';
    var parentSite = 'http://sgill.main.iabcanada.theniceagency.com/fr';

/*  ------------------------------------------------------------------
    Environment detect & redirect ------------------------------------ */
    var currentURL = window.location.href;
    if (currentURL.match('\.dev') || currentURL.match('twistimage')) {
        // do nothing, as we are in internal enviroment
    } else {
        // redirect to main site URL
        if (top == self) { location.href = parentSite + '/events-courses'; }
    }


/* ------------------------------------------------------------- 
iFrame Resize ---------------------------------------------- */

function iframeResizePipe() {
// What's the page height?
var height = $(document.body).height();
//var height = $('#frm_reg').height();	

// Going to 'pipe' the data to the parent through the helpframe..
var pipe = document.getElementById('helpframe');

// Cachebuster a precaution here to stop browser caching interfering
pipe.src = parentSite + '/helper.html?height=' + height + '&cacheb=' + Math.random();

}

$(document).ready(iframeResizePipe); // resize on DOM ready
$(window).resize(iframeResizePipe); // resize on window resize


/* ------------------------------------------------------------- 
iFrame Resize NoScroll ----------------------------------------- */

function iframeResizePipeNoScroll() {
    // What's the page height?
    var height = $(document.body).height();
    //var height = $('#frm_reg').height();	

    // Going to 'pipe' the data to the parent through the helpframe..
    var pipe = document.getElementById('helpframe');

    // Cachebuster a precaution here to stop browser caching interfering
    pipe.src = parentDomain + '/helper_noscroll.html?height=' + height + '&cacheb=' + Math.random();

}


/* ------------------------------------------------------------- 
Forms  ------------------------------------------ */

function generateProvinces(prefix) {
    //alert(document.getElementById(prefix + 'country').value);
    if (document.getElementById(prefix + 'country').options.value != "") {
        //remove all options
        the_field_select = document.getElementById(prefix + 'state').options;
        remove_all_options(the_field_select);
        if (document.getElementById(prefix + 'country').value == "United States") {
            the_field_select[the_field_select.length] = new Option('Select...', '');
            the_field_select[the_field_select.length] = new Option('Alaska', 'US-AK');
            the_field_select[the_field_select.length] = new Option('Alabama', 'US-AL');
            the_field_select[the_field_select.length] = new Option('Arkansas', 'US-AR');
            the_field_select[the_field_select.length] = new Option('Arizona', 'US-AZ');
            the_field_select[the_field_select.length] = new Option('California', 'US-CA');
            the_field_select[the_field_select.length] = new Option('Colorado', 'US-CO');
            the_field_select[the_field_select.length] = new Option('Connecticut', 'US-CT');
            the_field_select[the_field_select.length] = new Option('District of Columbia', 'US-DC');
            the_field_select[the_field_select.length] = new Option('Delaware', 'US-DE');
            the_field_select[the_field_select.length] = new Option('Florida', 'US-FL');
            the_field_select[the_field_select.length] = new Option('Georgia', 'US-GA');
            the_field_select[the_field_select.length] = new Option('Hawaii', 'US-HI');
            the_field_select[the_field_select.length] = new Option('Iowa', 'US-IA');
            the_field_select[the_field_select.length] = new Option('Idaho', 'US-ID');
            the_field_select[the_field_select.length] = new Option('Illinois', 'US-IL');
            the_field_select[the_field_select.length] = new Option('Indiana', 'US-IN');
            the_field_select[the_field_select.length] = new Option('Kansas', 'US-KS');
            the_field_select[the_field_select.length] = new Option('Kentucky', 'US-KY');
            the_field_select[the_field_select.length] = new Option('Louisiana', 'US-LA');
            the_field_select[the_field_select.length] = new Option('Massachusetts', 'US-MA');
            the_field_select[the_field_select.length] = new Option('Maryland', 'US-MD');
            the_field_select[the_field_select.length] = new Option('Maine', 'US-ME');
            the_field_select[the_field_select.length] = new Option('Michigan', 'US-MI');
            the_field_select[the_field_select.length] = new Option('Minnesota', 'US-MN');
            the_field_select[the_field_select.length] = new Option('Missouri', 'US-MO');
            the_field_select[the_field_select.length] = new Option('Mississippi', 'US-MS');
            the_field_select[the_field_select.length] = new Option('Montana', 'US-MT');
            the_field_select[the_field_select.length] = new Option('North Carolina', 'US-NC');
            the_field_select[the_field_select.length] = new Option('North Dakota', 'US-ND');
            the_field_select[the_field_select.length] = new Option('Nebraska', 'US-NE');
            the_field_select[the_field_select.length] = new Option('New Hampshire', 'US-NH');
            the_field_select[the_field_select.length] = new Option('New Jersey', 'US-NJ');
            the_field_select[the_field_select.length] = new Option('New Mexico', 'US-NM');
            the_field_select[the_field_select.length] = new Option('Nevada', 'US-NV');
            the_field_select[the_field_select.length] = new Option('New York', 'US-NY');
            the_field_select[the_field_select.length] = new Option('Ohio', 'US-OH');
            the_field_select[the_field_select.length] = new Option('Oklahoma', 'US-OK');
            the_field_select[the_field_select.length] = new Option('Oregon', 'US-OR');
            the_field_select[the_field_select.length] = new Option('Pennsylvania', 'US-PA');
            the_field_select[the_field_select.length] = new Option('Rhode Island', 'US-RI');
            the_field_select[the_field_select.length] = new Option('South Carolina', 'US-SC');
            the_field_select[the_field_select.length] = new Option('South Dakota', 'US-SD');
            the_field_select[the_field_select.length] = new Option('Tennessee', 'US-TN');
            the_field_select[the_field_select.length] = new Option('Texas', 'US-TX');
            the_field_select[the_field_select.length] = new Option('Utah', 'US-UT');
            the_field_select[the_field_select.length] = new Option('Virginia', 'US-VA');
            the_field_select[the_field_select.length] = new Option('Vermont', 'US-VT');
            the_field_select[the_field_select.length] = new Option('Washington', 'US-WA');
            the_field_select[the_field_select.length] = new Option('Wisconsin', 'US-WI');
            the_field_select[the_field_select.length] = new Option('West Virginia', 'US-WV');
            the_field_select[the_field_select.length] = new Option('Wyoming', 'US-WY');
            document.getElementById(prefix + 'state').disabled = false;

        } else if (document.getElementById(prefix + 'country').value == "Canada") {
            the_field_select[the_field_select.length] = new Option('Veuillez choisir...', '');
            the_field_select[the_field_select.length] = new Option('Alberta', 'CA-AB');
            the_field_select[the_field_select.length] = new Option('Columbie-Britannique', 'CA-BC');
            the_field_select[the_field_select.length] = new Option('Manitoba', 'CA-MB');
            the_field_select[the_field_select.length] = new Option('Nouveau-Brunswick', 'CA-NB');
            the_field_select[the_field_select.length] = new Option('Terre-Neuve-et-Labrador', 'CA-NF');
            the_field_select[the_field_select.length] = new Option('Nouvelle-Écosse', 'CA-NS');
            the_field_select[the_field_select.length] = new Option('Territoires-du-Nord-Ouest', 'CA-NT');
            the_field_select[the_field_select.length] = new Option('Ontario', 'CA-ON');
            the_field_select[the_field_select.length] = new Option('Île-du-Prince-Édouard', 'CA-PE');
            the_field_select[the_field_select.length] = new Option('Québec', 'CA-QC');
            the_field_select[the_field_select.length] = new Option('Saskatchewan', 'CA-SK');
            the_field_select[the_field_select.length] = new Option('Yukon', 'CA-YK'); 
            document.getElementById(prefix + 'state').disabled = false;
        } else if (document.getElementById(prefix + 'country').value == "Australia") {
            the_field_select[the_field_select.length] = new Option('Select...', '');
            the_field_select[the_field_select.length] = new Option('Australian Capital Territory', 'AU-AC');
            the_field_select[the_field_select.length] = new Option('New South Wales', 'AU-NS');
            the_field_select[the_field_select.length] = new Option('Northern Territory', 'AU-NT');
            the_field_select[the_field_select.length] = new Option('Queensland', 'AU-QL');
            the_field_select[the_field_select.length] = new Option('South Australia', 'AU-SA');
            the_field_select[the_field_select.length] = new Option('Tasmania', 'AU-TA');
            the_field_select[the_field_select.length] = new Option('Victoria', 'AU-VI');
            the_field_select[the_field_select.length] = new Option('Western Australia', 'AU-WA');
            document.getElementById(prefix + 'state').disabled = false;

        } else {
            the_field_select[the_field_select.length] = new Option('N/A', 'XX');
            document.getElementById(prefix + 'state').disabled = true;
        }
    }
}



function remove_all_options(the_field_select) {
    while (the_field_select.length > 0) {
        the_field_select[0] = null;
    }
}

/* ------------------------------------------------------------- 
Add an attendees  ---------------------------------------------- */

number_attendees = 1

function firstAttendees() {

    theHTMLTAG = document.createElement("tr");
    theHTMLTAG.setAttribute("id", "tr_id_" + number_attendees);

    theHTMLTAG1 = document.createElement("td");
    theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_" + number_attendees + "' id='attendees_firstname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='114' />"
    theHTMLTAG.appendChild(theHTMLTAG1);

    theHTMLTAG2 = document.createElement("td");
    theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_" + number_attendees + "' id='attendees_lastname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='115' />"
    theHTMLTAG.appendChild(theHTMLTAG2);

    theHTMLTAG3 = document.createElement("td");
    theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_" + number_attendees + "' id='attendees_email_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='116' />"
    theHTMLTAG.appendChild(theHTMLTAG3);

    theHTMLTAG4 = document.createElement("td");
    theHTMLTAG4.innerHTML = "<input type='text' name='attendees_company_" + number_attendees + "' id='attendees_company_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='117' />"
    theHTMLTAG.appendChild(theHTMLTAG4);

    theHTMLTAG5 = document.createElement("td");
    theHTMLTAG5.innerHTML = "<input type='text' name='attendees_title_" + number_attendees + "' id='attendees_title_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='118' />"
    theHTMLTAG.appendChild(theHTMLTAG5);

    theHTMLTAG6 = document.createElement("td");
    theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees(" + number_attendees + "));'  onmouseover='rollOver(\"b_minus" + number_attendees + "\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus" + number_attendees + "' alt='Remove' /></a>"
    theHTMLTAG.appendChild(theHTMLTAG6);

    document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
}



function add_attendees() {
    if (number_attendees <= 8) {
        if (document.getElementById("attendees_firstname_" + number_attendees) != null) {
            if (document.getElementById("attendees_firstname_" + number_attendees).value == "" || document.getElementById("attendees_lastname_" + number_attendees).value == "" || document.getElementById("attendees_email_" + number_attendees).value == "" || document.getElementById("attendees_company_" + number_attendees).value == "" || document.getElementById("attendees_title_" + number_attendees).value == "") {
                //alert("Please fill attendee #" + number_attendees + "'s names, email, company and title before adding another attendee.");
                $('#errors_attend').html("Please fill attendee #" + number_attendees + "'s names, email, company and title before adding another attendee.");
            } else {
                $('#errors_attend').html('');
                number_attendees += 1;

                theHTMLTAG = document.createElement("tr");
                theHTMLTAG.setAttribute("id", "tr_id_" + number_attendees);

                theHTMLTAG1 = document.createElement("td");
                theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_" + number_attendees + "' id='attendees_firstname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='1" + number_attendees + "4' />"
                theHTMLTAG.appendChild(theHTMLTAG1);

                theHTMLTAG2 = document.createElement("td");
                theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_" + number_attendees + "' id='attendees_lastname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='1" + number_attendees + "5' />"
                theHTMLTAG.appendChild(theHTMLTAG2);

                theHTMLTAG3 = document.createElement("td");
                theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_" + number_attendees + "' id='attendees_email_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "6' />"
                theHTMLTAG.appendChild(theHTMLTAG3);


                theHTMLTAG3 = document.createElement("td");
                theHTMLTAG3.innerHTML = "<input type='text' name='attendees_company_" + number_attendees + "' id='attendees_company_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "7' />"
                theHTMLTAG.appendChild(theHTMLTAG3);

                theHTMLTAG3 = document.createElement("td");
                theHTMLTAG3.innerHTML = "<input type='text' name='attendees_title_" + number_attendees + "' id='attendees_title_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "8' />"
                theHTMLTAG.appendChild(theHTMLTAG3);

                theHTMLTAG6 = document.createElement("td");
                theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees(" + number_attendees + "));' onmouseover='rollOver(\"b_minus" + number_attendees + "\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus" + number_attendees + "' alt='Remove' /></a>"
                theHTMLTAG.appendChild(theHTMLTAG6);

                document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
                document.getElementById("number_attendees").value = number_attendees;
            }

        } else if (document.getElementById("attendees_firstname_" + number_attendees) == null) {
            number_attendees += 1;

            theHTMLTAG = document.createElement("tr");
            theHTMLTAG.setAttribute("id", "tr_id_" + number_attendees);

            theHTMLTAG1 = document.createElement("td");
            theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_" + number_attendees + "' id='attendees_firstname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='1" + number_attendees + "4' />"
            theHTMLTAG.appendChild(theHTMLTAG1);

            theHTMLTAG2 = document.createElement("td");
            theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_" + number_attendees + "' id='attendees_lastname_" + number_attendees + "' style='display:inline;width:80px;' tabindex='1" + number_attendees + "5' />"
            theHTMLTAG.appendChild(theHTMLTAG2);

            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_" + number_attendees + "' id='attendees_email_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "6' />"
            theHTMLTAG.appendChild(theHTMLTAG3);


            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_company_" + number_attendees + "' id='attendees_company_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "7' />"
            theHTMLTAG.appendChild(theHTMLTAG3);

            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_title_" + number_attendees + "' id='attendees_title_" + number_attendees + "'  style='display:inline;width:80px;' tabindex='1" + number_attendees + "8' />"
            theHTMLTAG.appendChild(theHTMLTAG3);

            theHTMLTAG6 = document.createElement("td");
            theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees(" + number_attendees + "));' onmouseover='rollOver(\"b_minus" + number_attendees + "\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus" + number_attendees + "' alt='Remove' /></a>"
            theHTMLTAG.appendChild(theHTMLTAG6);

            document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
            document.getElementById("number_attendees").value = number_attendees;
        }


        /*if(document.getElementById("attendees_email_"+ number_attendees).value == "" || document.getElementById("attendees_email_"+ number_attendees).value == " " || document.getElementById("attendees_company_"+ number_attendees).value == "" || document.getElementById("attendees_company_"+ number_attendees).value == " "){
        alert("Please fill attendee #" + number_attendees + "'s email and company before adding another attendee.");
        }else if(!checkEmail(document.getElementById("attendees_email_" + number_attendees).value)){
        alert("You must enter a valid email address");
        }*/

        /*if(document.getElementById("attendees_firstname_"+ number_attendees).value == "" || document.getElementById("attendees_lastname_"+ number_attendees).value == "" || document.getElementById("attendees_email_"+ number_attendees).value == "" || document.getElementById("attendees_company_"+ number_attendees).value == "" || document.getElementById("attendees_title_"+ number_attendees).value == ""){
        alert("Please fill attendee #" + number_attendees + "'s name before adding another attendee.");
        }*/
        else {
            number_attendees += 1;

            theHTMLTAG = document.createElement("tr");
            theHTMLTAG.setAttribute("id", "tr_id_" + number_attendees);

            theHTMLTAG1 = document.createElement("td");
            theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_" + number_attendees + "' id='attendees_firstname_" + number_attendees + "' style='display:inline;width:95px;' tabindex='1" + number_attendees + "4' />"
            theHTMLTAG.appendChild(theHTMLTAG1);

            theHTMLTAG2 = document.createElement("td");
            theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_" + number_attendees + "' id='attendees_lastname_" + number_attendees + "' style='display:inline;width:95px;' tabindex='1" + number_attendees + "5' />"
            theHTMLTAG.appendChild(theHTMLTAG2);

            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_" + number_attendees + "' id='attendees_email_" + number_attendees + "'  style='display:inline;width:95px;' tabindex='1" + number_attendees + "6' />"
            theHTMLTAG.appendChild(theHTMLTAG3);


            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_company_" + number_attendees + "' id='attendees_company_" + number_attendees + "'  style='display:inline;width:95px;' tabindex='1" + number_attendees + "7'/>"
            theHTMLTAG.appendChild(theHTMLTAG3);

            theHTMLTAG3 = document.createElement("td");
            theHTMLTAG3.innerHTML = "<input type='text' name='attendees_title_" + number_attendees + "' id='attendees_title_" + number_attendees + "'  style='display:inline;width:95px;' tabindex='1" + number_attendees + "8' />"
            theHTMLTAG.appendChild(theHTMLTAG3);

            theHTMLTAG6 = document.createElement("td");
            theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees(" + number_attendees + "));' onmouseover='rollOver(\"b_minus" + number_attendees + "\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus" + number_attendees + "' alt='Remove' /></a>"
            theHTMLTAG.appendChild(theHTMLTAG6);

            document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
            document.getElementById("number_attendees").value = number_attendees;

            if (number_attendees == 8) {
                document.getElementById("b_add").style.display = 'none';
            };
        }
        document.getElementById("attendees_firstname_" + number_attendees).focus();
        document.getElementById("number_attendees").value = number_attendees;
    };
}

function RemoveAttendees(no) {
    if (number_attendees > 1 && no <= number_attendees) {
        for (i = no; i <= number_attendees; i++) {
            if (number_attendees > 1) {
                number_attendees--;
                document.getElementById("number_attendees").value = number_attendees; //update the hidden field
                theTR = document.getElementById("tr_id_" + no);
                if (theTR != null) {
                    var container = theTR.parentNode;
                    container.removeChild(theTR);
                } break;
            } else {
                number_attendees--;
                document.getElementById("attendees_firstname_" + no).value = '';
                document.getElementById("attendees_lastname_" + no).value = '';
                document.getElementById("attendees_email_" + no).value = '';
                document.getElementById("attendees_company_" + no).value = '';
                document.getElementById("attendees_title_" + no).value = '';
            }
        }
    } else if (number_attendees <= 1 && no <= number_attendees) {
        document.getElementById("attendees_firstname_" + no).value = '';
        document.getElementById("attendees_lastname_" + no).value = '';
        document.getElementById("attendees_email_" + no).value = '';
        document.getElementById("attendees_company_" + no).value = '';
        document.getElementById("attendees_title_" + no).value = '';
    } else {
        ;
        if (number_attendees > 1) {
            number_attendees--;
            document.getElementById("number_attendees").value = number_attendees; //update the hidden field
            theTR = document.getElementById("tr_id_" + no);
            if (theTR != null) {
                var container = theTR.parentNode;
                container.removeChild(theTR);
            }
        } else if (number_attendees <= 1) {
            document.getElementById("attendees_firstname_" + no).value = '';
            document.getElementById("attendees_lastname_" + no).value = '';
            document.getElementById("attendees_email_" + no).value = '';
            document.getElementById("attendees_company_" + no).value = '';
            document.getElementById("attendees_title_" + no).value = '';
        }
    }
}



/* ------------------------------------------------------------- 
Validate Form  ---------------------------------------------- */

function validate_checkout() {
    var msg = "";
    var error = 0;

    //Firstname Validation
    if (!noScript(document.getElementById("first_name").value) || document.getElementById("first_name").value == "") {
        error = "1";
        document.getElementById("first_name").className = "error";
    } else {
        document.getElementById("first_name").className = "";
    }


    //lastname Validation
    if (!noScript(document.getElementById("last_name").value) || document.getElementById("last_name").value == "") {
        document.getElementById("last_name").className = "error";
        msg = msg + "Last Name is empty.<br>";
        error = 1;
    } else { document.getElementById("last_name").className = ""; }
    //title Validation
    if (!noScript(document.getElementById("title").value) || document.getElementById("title").value == "") {
        document.getElementById("title").className = "error";
        msg = msg + "Title is empty.<br>";
        error = 1;
    } else { document.getElementById("title").className = ""; }
    //company Validation
    if (!noScript(document.getElementById("company").value) || document.getElementById("company").value == "") {
        document.getElementById("company").className = "error";
        msg = msg + "Company is empty.<br>";
        error = 1;
    } else { document.getElementById("company").className = ""; }

    //address Validation
    if (!noScript(document.getElementById("address").value) || document.getElementById("address").value == "") {
        document.getElementById("address").className = "error";
        msg = msg + "Address is empty.<br>";
        error = 1;
    } else { document.getElementById("address").className = ""; }
    //city Validation
    if (!noScript(document.getElementById("city").value) || document.getElementById("city").value == "") {
        document.getElementById("city").className = "error";
        msg = msg + "City is empty.<br>";
        error = 1;
    } else { document.getElementById("city").className = ""; }
    //zipcode Validation
    if (!noScript(document.getElementById("zip").value) || document.getElementById("zip").value == "") {
        document.getElementById("zip").className = "error";
        msg = msg + "ZIP Code / Postal Code is empty.<br>";
        error = 1;
    } else { document.getElementById("zip").className = ""; }
    //Country Validation
    if (document.getElementById("country").value == "") {
        document.getElementById("country").className = "error";
        msg = msg + "Country is empty.<br>";
        error = 1;
    } else { document.getElementById("country").className = ""; }

    //State Validation
    if (document.getElementById("state").value == "") {
        document.getElementById("state").className = "error";
        msg = msg + "State is empty.<br>";
        error = 1;
    } else { document.getElementById("state").className = ""; }


    //Email
    if (!noScript(document.getElementById("email").value) || !checkEmail(document.getElementById("email").value)) {
        error = "1"; document.getElementById("email").className = "error";
    } else {
        document.getElementById("email").className = "";
    }
    //phone

    if (!noScript(document.getElementById("phone").value) || !checkPhone(document.getElementById("phone").value)) {
        error = "1"; document.getElementById("phone").className = "error";
    } else if (document.getElementById("phone").value.length < 10) {
        error = "1"; document.getElementById("phone").className = "error";
    } else {
        document.getElementById("l_phone").className = "";
    }

    //Yes or No checkbox //

    if (document.getElementById("attending").checked == false && document.getElementById("notAttending").checked == false) {
        error = "1";
        document.getElementById("l_attending").className = "error";
        document.getElementById("l_notAttending").className = "error";
    } else {
        document.getElementById("l_attending").className = "";
        document.getElementById("l_notAttending").className = "";
    }

    //extra attendee fields*/    

    if (document.getElementById("attendees_firstname_" + number_attendees) != null) {
        if (document.getElementById("attendees_firstname_" + number_attendees).value != "" || document.getElementById("attendees_lastname_" + number_attendees).value != "" || document.getElementById("attendees_title_" + number_attendees).value != "") {

            /* First name */
            if (!noScript(document.getElementById("attendees_firstname_" + number_attendees).value) || document.getElementById("attendees_firstname_" + number_attendees).value == "" || document.getElementById("attendees_firstname_" + number_attendees).value == " ") {
                document.getElementById("x_firstname").className = "error";
            } else { document.getElementById("x_firstname").className = ""; }
            /* Last name */
            if (!noScript(document.getElementById("attendees_lastname_" + number_attendees).value) || document.getElementById("attendees_lastname_" + number_attendees).value == "" || document.getElementById("attendees_lastname_" + number_attendees).value == " ") {
                document.getElementById("x_lastname").className = "error";
                error = 1;
            } else { document.getElementById("x_lastname").className = ""; }

            /* Email */
            if (!noScript(document.getElementById("attendees_email_" + number_attendees).value) || document.getElementById("attendees_email_" + number_attendees).value == "" || document.getElementById("attendees_email_" + number_attendees).value == " " || !checkEmail(document.getElementById("attendees_email_" + number_attendees).value)) {
                document.getElementById("x_email").className = "error";
                error = 1;
            } else { document.getElementById("x_email").className = ""; }

            /* Company */
            if (!noScript(document.getElementById("attendees_company_" + number_attendees).value) || document.getElementById("attendees_company_" + number_attendees).value == "" || document.getElementById("attendees_company_" + number_attendees).value == " ") {
                document.getElementById("x_company").className = "error";
                error = 1;
            } else { document.getElementById("x_company").className = ""; }

            /* Title */
            if (!noScript(document.getElementById("attendees_title_" + number_attendees).value) || document.getElementById("attendees_title_" + number_attendees).value == "" || document.getElementById("attendees_title_" + number_attendees).value == " ") {
                document.getElementById("x_title").className = "error";
                error = 1;
            } else { document.getElementById("x_title").className = ""; }
        }

    }


    //Discount Code	    
    if (document.getElementById("membre3").checked) {
        if (document.getElementById("discount_code").value == "") {
            document.getElementById("l_discount_code").className = "error";
            msg = msg + "Discount Code is empty.<br>";
            error = 1;
        } /*else if (document.getElementById("discountCode").value != discountCode){
			    document.getElementById("l_discount_code").className = "error";
			}*/
        else { document.getElementById("l_discount_code").className = ""; }
    } else if (document.getElementById("membre1").checked == false && document.getElementById("membre2").checked == false && document.getElementById("membre3").checked == false) {
        document.getElementById("l_membre1").className = "error";
        document.getElementById("l_membre2").className = "error";
        document.getElementById("l_membre3").className = "error";
        error = 1;
    } else if (document.getElementById("membre3").checked || document.getElementById("membre2").checked) {
        document.getElementById("discount_code").value = "";
    } else {
        document.getElementById("l_membre1").className = "";
        document.getElementById("l_membre2").className = "";
        document.getElementById("l_membre3").className = "";
    }

    /* Checks if the payee is an attendee. If not, remove one from the total number of attendees */
    if (document.getElementById("notAttending").checked) {
        //alert(number_attendees);
        if (number_attendees <= 1 && (document.getElementById("attendees_firstname_" + number_attendees).value == "" || document.getElementById("attendees_lastname_" + number_attendees).value == "" || document.getElementById("attendees_email_" + number_attendees).value == "" || document.getElementById("attendees_company_" + number_attendees).value == "" || document.getElementById("attendees_title_" + number_attendees).value == "")) {
            document.getElementById("enterAttendee").style.display = 'block';
            document.getElementById("enterAttendee").className = 'error';
            error = 1;
        }
        else if (number_attendees > 1) { error = 0; }
    }

    // Event Id

    if (document.getElementById("event_id").value == 0) {
        error = 1;
        //document.getElementById("l_event_id").className = "error";
    } else {
        //document.getElementById("l_event_id").className = "";
    }




    if (error == 1) {
        document.getElementById("validate_checkout").style.display = "block";
        $("#errors_main").show();
        iframeResizePipe();
    } else {
        document.getElementById("checkout_confirm").submit();
    }



}


function validate_creditcard() {
    var pattern_email = /([A-Za-z0-9\.\_]{1,})\@([A-Za-z0-9\.\_]{1,})\.([A-Za-z]{2,})/;
    var pattern_phone = /[^\d\s() -]/;
    var pattern_extension = /\d{0,}/;
    //var patternNoScript = /[^0-9a-zA-Z-@.\(\)\*\_\"\']/;
    var msg = "";
    var error = 0;

    //cc Cardholder
    if (!noScript(document.getElementById("cardholder").value) || document.getElementById("cardholder").value == "") {
        document.getElementById("l_cardholder").className = "error";
        msg = msg + "Cardholder is empty.<br>";
        error = 1;
    } else { document.getElementById("l_cardholder").className = ""; }

    //cc Card Type
    if (document.getElementById("card_type").value == "") {
        document.getElementById("l_card_type").className = "error";
        msg = msg + "Card Type is empty.<br>";
        error = 1;
    } else { document.getElementById("l_card_type").className = ""; }

    //cc Validation
    if (document.getElementById("card_num").value == "") {
        document.getElementById("l_card_num").className = "error";
        msg = msg + "Card Number is empty.<br>";
        error = 1;
    } else { document.getElementById("l_card_num").className = ""; }
    //expiry Validation
    if (document.getElementById("exp_month").value == "" || document.getElementById("exp_year").value == "") {
        document.getElementById("l_exp_month").className = "error";
        msg = msg + "Credit Card Expiry Date is invalid.<br>";
        error = 1;
    } else { document.getElementById("l_exp_month").className = ""; }


    if (error == 1) {
        //alert("Information is missing or invalid. Please correct the following fields:\n" + msg)
        document.getElementById("validate_checkout").style.display = "block";
    } else {
        document.getElementById("validate_checkout").style.display = "none";
        document.getElementById("b_back").style.display = "none";
        document.getElementById("b_continue").style.display = "none";
        document.getElementById("processing").style.display = "block";


        //document.getElementById("checkout_confirm").action = SSL_URL + "/course/4105/confirmation.asp";
        document.getElementById("checkout_confirm").submit();
    }

}




function checkDiscount(status) {
    if (status == "open") {
        document.getElementById("dv_discount_code").style.display = "block";
    } else {
        document.getElementById("dv_discount_code").style.display = "none";
    }
}



/* ------------------------------------------------------------- 
AJAX -------------------------------------------------------- */


function createRequestObject() {
    var ro;
    if (browserName == "MSIE") {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();





/* ------------------------------------------------------------- 
Send to A Friend -------------------------------------------- */


function sendtoafriend() {
    document.getElementById("popin").style.display = "block";
}

function closeSend() {
    document.getElementById("popin").style.display = "none";
}

function validate_form() {
    Goon = "0";
    var msg = "";
    if (document.getElementById("s_name").value == "") { Goon = "1"; document.getElementById("t_s_name").className = "error"; } else { document.getElementById("t_s_name").className = "text"; }
    if (!checkEmail(document.getElementById("s_email").value)) { Goon = "1"; document.getElementById("t_s_email").className = "error"; } else { document.getElementById("t_s_email").className = "text"; }
    if (document.getElementById("s_friendname").value == "") { Goon = "1"; document.getElementById("t_s_friendname").className = "error"; } else { document.getElementById("t_s_friendname").className = "text"; }
    if (!checkEmail(document.getElementById("s_friendemail").value)) { Goon = "1"; document.getElementById("t_s_friendemail").className = "error"; } else { document.getElementById("t_s_friendemail").className = "text"; }
    if (Goon == "0") {
        name = document.getElementById("s_name").value;
        email = document.getElementById("s_email").value;
        friendname = document.getElementById("s_friendname").value;
        friendemail = document.getElementById("s_friendemail").value;
        message = document.getElementById("s_message").value;
        path_query_url = document.getElementById("path_query_url").value;

        http.open('get', '/course/4105/db_send.asp?path_query_url=' + path_query_url + '&name=' + name + '&email=' + email + '&friendname=' + friendname + '&friendemail=' + friendemail + '&message=' + escape(message));
        http.onreadystatechange = handleLoginResponse;
        http.send(null);
    } else {
        document.getElementById("validate_send").style.display = "block";
        document.getElementById("validate_send").innerHTML = "Please fill or correct all the fields in <span class='error'>red</span>, then click send.";
    }
}


function handleLoginResponse() {
    if (http.readyState == 4) {
        if (http.responseText == "good") {
            document.getElementById("validate_send").style.display = "block";
            document.getElementById("validate_send").innerHTML = "<br /><b>Thank you.</b><br />An email has been sent to your friend.";
            document.getElementById("s_name").value = "";
            document.getElementById("s_email").value = "";
            document.getElementById("s_friendname").value = "";
            document.getElementById("s_friendemail").value = "";
            document.getElementById("s_message").value = "";
        } else {
            document.getElementById("validate_send").style.display = "block";
            document.getElementById("validate_send").innerHTML = "<br /><b>Sorry.</b><br />An error occurred. Please try again.";
        }
    }
}
