<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ChatLiveGeneral.aspx.vb" Inherits="Visitors_ChatLiveGeneral" %>

<%@ Register Src="../Controls/CustomContent.ascx" TagName="CustomContent" TagPrefix="uc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link type="text/css" rel="stylesheet" href="../Styles/Charter.css" />

    <script type="text/javascript">

        var sValid = "";

        function validate(oForm) {
            sValid = "";
            bFocused = false;
            if (CheckReq(oForm, "fname", "lname", "email", "phone")) {
                if (oForm.email.value.length > 0) {
                    checkEmail(oForm.email);
                }
                if (oForm.phone.value.length > 0) {
                    checkPhone(oForm.phone);
                }
            }
            if (sValid > "") {
                alert(sValid);
                return false;
            } else {
                return true;
            }
        }

        /*
        @func bool | checkPhone | Makes certain that the input value has at least 10 digits
        @parm object | oField | Input object to validate
        @rdesc Returns true if compare works, otherwises adds error message to sValid
        */
        function checkPhone(oField) {
            var xText = new String(oField.value);
            xText = xText.replace(/[^0-9]+/g, "");
            if (xText.length != 10) {
                sValid += "Phone number is invald.\n";
                setFocus(oField);
                return false;
            }
            oField.value = xText.substr(0, 3) + "-" + xText.substr(3, 3) + "-" + xText.substr(6, 4);
            return true;
        }

        /*
        @func bool | checkEmail | Compares the value of the object passed in to a Regular Express
        @parm object | oField | Input object to validate
        @rdesc Returns true if compare works, otherwises adds error message to sValid
        */
        function checkEmail(oField) {
            var emailStr = oField.value;

            /* The following variable tells the rest of the function whether or not
            to verify that the address ends in a two-letter country or well-known
            TLD.  1 means check it, 0 means don't. */
            var checkTLD = 1;

            var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
            var emailPat = /^(.+)@(.+)$/;

            var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
            var validChars = "\[^\\s" + specialChars + "\]";

            /* The following pattern applies if the "user" is a quoted string (in
            which case, there are no rules about which characters are allowed
            and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
            is a legal e-mail address. */
            var quotedUser = "(\"[^\"]*\")";

            /* The following pattern applies for domains that are IP addresses,
            rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
            e-mail address. NOTE: The square brackets are required. */
            var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

            var atom = validChars + '+';
            var word = "(" + atom + "|" + quotedUser + ")";
            var userPat = new RegExp("^" + word + "(\\." + word + ")*$");

            /* The following pattern describes the structure of a normal symbolic
            domain, as opposed to ipDomainPat, shown above. */
            var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
            var matchArray = emailStr.match(emailPat);
            if (matchArray == null) {
                sValid += "E-mail address is invalid (must include '@' and '.').\n";
                setFocus(oField);
                return false;
            }

            var user = matchArray[1];
            var domain = matchArray[2];

            // Start by checking that only basic ASCII characters are in the strings (0-127).
            for (i = 0; i < user.length; i++) {
                if (user.charCodeAt(i) > 127) {
                    sValid += "E-mail user name contains invalid characters.\n";
                    setFocus(oField);
                    return false;
                }
            }

            // Check domain
            for (i = 0; i < domain.length; i++) {
                if (domain.charCodeAt(i) > 127) {
                    sValid += "E-mail domain name contains invalid characters.\n";
                    setFocus(oField);
                    return false;
                }
            }

            // Check user
            if (user.match(userPat) == null) {
                sValid += "E-mail user name is invalid.\n";
                setFocus(oField);
                return false;
            }

            /* If the e-mail address is at an IP address (as opposed to a symbolic
            host name) make sure the IP address is valid. */
            var IPArray = domain.match(ipDomainPat);
            if (IPArray != null) {
                for (var i = 1; i <= 4; i++) {
                    if (IPArray[i] > 255) {
                        sValid += "E-mail destination IP address is invalid.\n";
                        setFocus(oField);
                        return false;
                    }
                }
                return true;
            }

            // Domain is symbolic name.  Check if it's valid.
            var atomPat = new RegExp("^" + atom + "$");
            var domArr = domain.split(".");
            var len = domArr.length;
            for (i = 0; i < len; i++) {
                if (domArr[i].search(atomPat) == -1) {
                    sValid += "E-mail domain name is invalid.\n";
                    setFocus(oField);
                    return false;
                }
            }

            /* domain name seems valid, but now make sure that it ends in a
            known top-level domain (like com, edu, gov) or a two-letter word,
            representing country (uk, nl), and that there's a hostname preceding 
            the domain or country. */
            if (checkTLD && domArr[domArr.length - 1].length != 2 &&
			    domArr[domArr.length - 1].search(knownDomsPat) == -1) {
                sValid += "E-mail address must end in a well-known domain or two letter country.\n";
                setFocus(oField);
                return false;
            }

            // Make sure there's a host name preceding the domain.
            if (len < 2) {
                sValid += "E-mail address is missing a host name.\n";
                setFocus(oField);
                return false;
            }

            // If we've gotten this far, everything's valid!

            return true;
        }

        /*
        @func void | setFocus | Sets cursor focus to the first input object to validate false
        @parm object | oField | Input object to set focus to
        */
        var bFocused = false;
        function setFocus(oField) {
            if (!bFocused) {
                oField.focus();
                bFocused = true;
            }
        }

        /*
        @func bool | CheckReq | Checks to see if form objects have values
        @parm string | sForm | Name of the form to validate
        @parm string | sInput | List all of the Input object you want to validate
        @rdesc Returns true if all inputs have value, sets sValid if they do not
        */
        function CheckReq(oForm) {
            var oItem, LeftArg, RightArg, descTest, reqFlag;
            var sTemp = new String();

            for (var i = 1; i < arguments.length; i++) {
                LeftArg = arguments[i];
                var descTest = LeftArg.indexOf('~');
                if (descTest != -1) {
                    RightArg = " - " + LeftArg.slice(descTest + 1)
                    LeftArg = LeftArg.slice(0, descTest)
                }
                oItem = eval("oForm." + LeftArg);
                switch (oItem.type) {
                    case "radio":
                        if (oItem.selectedIndex == -1) {
                            sValid += "Required fields are missing.\n";
                            oItem.focus();
                            return false;
                        } else
                            break;
                    case "select-multiple":
                        if (oItem.selectedIndex == -1) {
                            sValid += "Required fields are missing.\n";
                            oItem.focus();
                            return false;
                        } else
                            break;
                    case "select-one":
                        if (oItem.selectedIndex == 0) {
                            sValid += "Required fields are missing.\n";
                            oItem.focus();
                            return false;
                        } else
                            break;
                    default:
                        if (oItem.type) {
                            if (!(Trim2(oItem.value))) {
                                if (RightArg) {
                                    sValid += "Required fields are missing " + RightArg + ".\n";
                                    oItem.focus();
                                }
                                else {
                                    sValid += "Required fields are missing.\n";
                                    oItem.focus();
                                    return false;
                                }

                                reqFlag = 1;
                                //return false;
                            }
                        } else {
                            //alert(arguments[i]);
                            var bSelected = false;
                            for (var x = 0; x < oItem.length; x++) {
                                //alert(oItem[x].checked)
                                if (oItem[x].checked)
                                    bSelected = true
                            }
                            if (!bSelected) {
                                sValid += "Required fields are missing.\n";
                                oItem[0].focus();
                                return false;
                            }
                        }
                        break;
                }
            }
            if (reqFlag == 1) { return false; }
            return true;
        }

        /*
        @func String Object | trim | Trims leading and trailing white space from string. Uses prototype definition  "String.prototype.trim = trim;".
        @rdesc Returns Copy of string with leading and trailing whitespace stripped off.
        */

        function trim() {
            return this.replace(/^\s+/, '').replace(/\s+$/, '');
        }

        /*
        ==================================================================
        LTrim(string) : Returns a copy of a string without leading spaces.
        ==================================================================
        */
        function LTrim(str) {
            /*
            PURPOSE: Remove leading blanks from our string.
            IN: str - the string we want to LTrim
            */
            var whitespace = new String(" \t\n\r");

            var s = new String(str);

            if (whitespace.indexOf(s.charAt(0)) != -1) {
                // We have a string with leading blank(s)...

                var j = 0, i = s.length;

                // Iterate from the far left of string until we
                // don't have any more whitespace...
                while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                    j++;

                // Get the substring from the first non-whitespace
                // character to the end of the string...
                s = s.substring(j, i);
            }
            return s;
        }

        /*
        ==================================================================
        RTrim(string) : Returns a copy of a string without trailing spaces.
        ==================================================================
        */
        function RTrim(str) {
            /*
            PURPOSE: Remove trailing blanks from our string.
            IN: str - the string we want to RTrim
     
            */
            // We don't want to trip JUST spaces, but also tabs,
            // line feeds, etc.  Add anything else you want to
            // "trim" here in Whitespace
            var whitespace = new String(" \t\n\r");

            var s = new String(str);

            if (whitespace.indexOf(s.charAt(s.length - 1)) != -1) {
                // We have a string with trailing blank(s)...

                var i = s.length - 1;       // Get length of string

                // Iterate from the far right of string until we
                // don't have any more whitespace...
                while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                    i--;


                // Get the substring from the front of the string to
                // where the last non-whitespace character is...
                s = s.substring(0, i + 1);
            }

            return s;
        }

        /*
        =============================================================
        Trim(string) : Returns a copy of a string without leading or trailing spaces
        =============================================================
        */
        function Trim2(str) {
            /*
            PURPOSE: Remove trailing and leading blanks from our string.
            IN: str - the string we want to Trim
     
            RETVAL: A Trimmed string!
            */
            return RTrim(LTrim(str));
        }

    </script>

</head>
<body id="centerBody" style="padding-left: 14px; background-position: 3px 0px; background-repeat: no-repeat; background-color: White;
    background-image: url('../Visitors/Images/chatBKG.jpg');">

    <script type="text/javascript" src="../Scripts/tooltip.js"></script>

    <form id="Chat" name="chat_form" method="post" action="https://admin.instantservice.com/Customer" onsubmit="return validate(this);">
    <table cellpadding="0" cellspacing="0" border="0">
        <tr style="">
            <td style="width: 100%" valign="top">
                <div style="float: left">
                    <img style="padding-left: 10px; padding-top: 5px; vertical-align: middle;" alt="" src="Images/supportGear.gif" />
                    &nbsp;&nbsp;<span style="font-size: 19px; vertical-align: text-top; font-family: Arial; font-weight: bolder; color: #0b607d;">Online
                        Chat</span></div>
                <div style="padding-left: 380px; padding-top: 3px; background-image: none;">
                    <img alt="" src="CMS_IMAGES/CharterLogo2010.ccom" style="background-image: none;" /></div>
            </td>
        </tr>
        <tr style="height: 275px">
            <td style="width: 4px" valign="top">
                &nbsp;
            </td>
        </tr>
    </table>
    <table cellpadding="0" cellspacing="0" border="0">
        <tr style="height: auto">
            <td align="left">
                <span style="font-style: normal; font-weight: lighter; font-family: Arial; text-decoration: underline; margin-left: 25px;">Please
                    supply the following information and click Submit to initiate a chat with our agents</span>
            </td>
        </tr>
        <tr style="height: auto">
            <td align="left" valign="top">
                &nbsp;<span class="smallInstOrange" style="margin-left: 15px;">* Required Fields</span><br />
                <br />
            </td>
        </tr>
    </table>
    <table cellpadding="2" cellspacing="0" border="0" style="font-family: Arial;">
        <tr>
            <td width="150" align="right" valign="middle">
                <span class="smallInstOrange">* </span>First Name&nbsp;&nbsp;
            </td>
            <td width="350" align="left" valign="middle">
                <input type="text" id="fname" name="fname" runat="server" size="43" value="" style="width: 195px" />
            </td>
        </tr>
        <tr>
            <td width="150" align="right" valign="middle">
                <span class="smallInstOrange">* </span>Last Name&nbsp;&nbsp;
            </td>
            <td width="350" align="left" valign="middle">
                <input type="text" id="lname" name="lname" runat="server" size="43" value="" style="width: 195px" />
            </td>
        </tr>
        <tr>
            <td width="150" align="right" valign="middle">
                <span class="smallInstOrange">* </span>E-mail Address&nbsp;&nbsp;
            </td>
            <td width="350" align="left" valign="middle">
                <input type="text" id="email" name="email" runat="server" size="43" value="" style="width: 195px" />
            </td>
        </tr>
        <tr>
            <td width="150" align="right" valign="middle">
                <span class="smallInstOrange">* </span>Phone Number&nbsp;&nbsp;
            </td>
            <td width="350" align="left" valign="middle">
                <input type="text" id="phone" name="phone" runat="server" size="43" value="" style="width: 195px" />&nbsp;&nbsp;(format:
                XXX-XXX-XXXX)
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right" valign="bottom">
                <br />
                <input style="margin-right: 15px" type="image" src="../Visitors/Images/submitButton.gif" value="Submit" />
            </td>
        </tr>
    </table>
    <input type="hidden" id="ai" name="ai" value="6092" />
    <input type="hidden" id="di" name="di" value="" runat="server" />
    <input type="hidden" id="optionaldata" name="optionaldata" runat="server" value="" />
    <input type="hidden" id="optionaldata5" name="optionaldata5" value="<% Response.Write(Request.QueryString("sessionid")) %>" />
    </form>
    <uc:customcontent id="ucGoogleAnalyticsScriptBlock" runat="server" contentkey="analytics:google:scriptblock" />

    <script type="text/javascript">
        document.forms['chat_form'].elements['fname'].focus();
    </script>

</body>
</html>
