﻿if (document.images) {
            preload_image_object = new Image();
            // set image url
            preload_image_object.src = "ajax-loader.gif";
    }
    $(document).ready(function() {
        $("#embSubmit").click(function(event) {
            event.preventDefault();
            var firstName = document.getElementById("embFirstName").value;
            var lastName = document.getElementById("embLastName").value;
            var company = document.getElementById("embCompany").value;
            var email = document.getElementById("embEmail").value;
            var phone = document.getElementById("embPhone").value;
            if (firstName == "" | lastName == "" | company == "" | email == "" | phone == "") {
                alert("You are missing some required fields.  Please make sure the entire form is completed.");
            }
            else {
                $("#embDiv").html("<div class='loader'><img src='/images/ajax-loader.gif' width='66' height='66' alt='Loading...' /><br /><strong>Please Wait</strong><br />Submitting Your Request</div>");

                PageMethod("DemoRequest", ["firstName", firstName, "lastName", lastName, "company", company, "email", email, "phone", phone], ShowResult, AjaxFailed);
            }
        });

        $(".lbox").lightBox();
        $(".embeddedform").corner('7px');
        $(".vertmenu").corner('7px');
        $(".redbutton").corner('7px');
        $(".bluebutton").corner('7px');
    });
    function ShowResult(result)
    {
        $("#embDiv").html(result.d);
    }
    function AjaxFailed(result)
    {
        alert("There was a problem with your request.");
    }
    function PageMethod(fn, paramArray, successFn, errorFn) 
    { 
            var pagePath = window.location.pathname; 
    //Create list of parameters in the form: 
    //{"paramName1":"paramValue1","paramName2":"paramValue2"} 
        var paramList = ''; 
        if (paramArray.length > 0) 
        { 
            for (var i=0; i<paramArray.length; i++)
            { 
                if (paramList.length > 0) paramList += ','; 
                paramList += '"' + paramArray[i] + '":"' + paramArray[i+1] + '"'; 
            } 
        } 
        paramList = '{' + paramList + '}'; 
    //Call the page method 
        $.ajax({ 
    type: "POST", 
        url: pagePath + "/" + fn, 
        contentType: "application/json; charset=utf-8", 
        data: paramList, 
        dataType: "json", 
        success: successFn, 
        error: errorFn 
        });
    }

