<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ChatForm.aspx.vb" Inherits="Visitors_ChatForm" title="Charter.com - Chat" %>

<%@ 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 id="Head1" runat="server">
		<title>Charter.com - Chat</title>
		<link type="text/css" rel="stylesheet" href="../Styles/Charter.css" />
		<script language="javascript">
		
		var sValid = "";
		
function validate(oForm)
{
	sValid = "";
	bFocused = false;
	if(CheckReq(oForm,"fname","lname"))
	{
	if (oForm.email.value.length > 0) {
		checkEmail(oForm.email);
		}
	if (oForm.phone.value.length > 0) {
		checkPhone(oForm.phone, "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
	@parm string | sInput | Label for input object
	@rdesc Returns true if compare works, otherwises adds error message to sValid
	*/	
	function checkPhone(oField, sInput){
		var xText = new String(oField.value);
		var oPattern = /^\d{3}-\d{3}-\d{4}.{0,}/;
		if(!oPattern.test(oField.value) && oField.value > "") {
			xText = xText.replace(".","-");
			oField.value = xText.replace(".","-");
			if(!oPattern.test(oField.value) && oField.value > "") {
				sValid += "Please enter a valid phone number for " + sInput + "\nFormat : ###-###-####...\n";
				setFocus(oField);
				return false;
			}
			return true;
		}
		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 (check for '@' 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 += "The e-mail username contains invalid characters\n";
				setFocus(oField);
				return false;
			}
		}

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

		// Check user
		if (user.match(userPat)==null) {
			sValid += "The e-mail username 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 += "The 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 += "The 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 += "The 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 += "This e-mail address is missing a hostname\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 += "Some required fields are missing\n";
						oItem.focus();
						return false;
					} else
						break;
				case "select-multiple":
					if(oItem.selectedIndex == -1)
					{
						sValid += "Some required fields are missing\n";
						oItem.focus();
						return false;
					} else
						break;				
				case "select-one":
					if(oItem.selectedIndex == 0)
					{
						sValid += "Some required fields are missing\n";
						oItem.focus();
						return false;
					} else
						break;
				default :
					if(oItem.type) {
						if(!(Trim2(oItem.value))) {
							if(RightArg) {
								sValid += "Some required fields are missing " + RightArg + "\n";
								oItem.focus();
							}
							else {
								sValid += "Some 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 += "Some 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="background-color:White;">
		<form id="Chat" name="chat_form" method="post" action="https://admin.instantservice.com/Customer" onsubmit="return validate(this);">
		
		    <asp:Panel runat="server" ID="pnlChatForm" Visible=True>
		    <img alt="" src="../Images/charterLogo.gif" border="0" />
		    <div align="center">
		    
		        <asp:Panel runat="server" ID="pnlORderVerbiage" Visible=false>
		        <strong>Charter Communications Live Chat</strong><br />
		        Please verify the following information and click Submit to initiate a chat with our agents to complete your order.<br /><br />
		        </asp:Panel>
		    <asp:Panel runat="server" ID="pnlRegularVerbiage" Visible=false>
		    <strong>Charter Communications Live Chat</strong><br />
		        <span class="mainPageText">Please supply the following information and click Submit to initiate a chat with our agents.<span class="smallInstOrange">(* Required)</span></span><br /><br />
		    </asp:Panel>
			    			
			    <table cellpadding=2 cellspacing=0 border=0>
				    <tr><td align="right"><span class="smallInstOrange">* </span>First Name:&nbsp;&nbsp;</td><td><input type="text" ID="fname" name="fname" value="<%Response.write(request.querystring("u")) %>" /><br /></td>
				        <td align="right" width="140"><span class="smallInstOrange">* </span>Last Name:&nbsp;&nbsp;</td><td><input type="text"  ID="lName" name="lname" value="<% Response.write(request.querystring("ln")) %>" /><br /></td>
				    </tr>
				    <tr><td align="right">E-mail:&nbsp;&nbsp;</td> <td><input type="text"  ID="email" name="email" value="<% Response.write(request.querystring("m")) %>" /><br /></td>
				        <td align="right">Phone Number:&nbsp;&nbsp;</td> <td><input type="text" id="phone" name="phone"  value="<% Response.write(request.querystring("p")) %>" /><br /></td>
				    </tr>
				    			    <!-- -->
				    <tr><td colspan=4><br />
				    <input type=image src="../Visitors/Images/submit.jpg" value="Submit" /><br /><br /></td></tr>
				 </table>   
    				<input type="hidden" id="ai" name="ai" value="6092" />
				    <input type="hidden" id="di" name="di" value="<% Response.Write(Request.QueryString("d")) %>" />		
				    <input type="hidden" id="optionaldata" name="optionaldata"  value="<% Response.write(request.querystring("o")) %>" />
				    <%--ROD COPELAND    JULY 27, 2009   ISSUE ID 6808   TAKE INTELLIRESPONSE SESSION ID AND PASS TO INSTANCE SERVICE--%>
				    <input type="hidden" id="optionaldata5" name="optionaldata5"  value="<% Response.write(request.querystring("sessionid")) %>" />
			    </div>
	        </asp:Panel> 
		</form>
		

<uc:CustomContent ID="ucGoogleAnalyticsScriptBlock" runat="server" ContentKey="analytics:google:scriptblock" />


    		
	</body>
</html>