var strLLF = "<p class='livelink'>Enter your name and phone number to be connected to a live agent now.</p> ";
strLLF = strLLF + "<form name=LiveLinkForm>\n<table border=0 width=100%>\r\n";
strLLF = strLLF + "<tr>\r\n<td align='right'><span class='LiveLink'>Name:</span></td>\r\n";
strLLF = strLLF + "<td><input class='LiveLink' type=text name=Name></td>\r\n</tr>\r\n";
strLLF = strLLF + "<tr><td align='right'><span class='LiveLink'>Phone:</span></td>\r\n";
strLLF = strLLF + "<td><input class=LiveLink type=text name=Phone></td>\r\n</tr>\r\n";
strLLF = strLLF + "<tr>\r\n<td colspan=2 align=middle>";
strLLF = strLLF + "<input class='LiveLink' type=button name=Submit value=Submit onClick='retrieveRecord(document.all.LiveLinkForm.Name.value,document.all.LiveLinkForm.Phone.value);'>";
strLLF = strLLF + "&nbsp;<input class='LiveLink' type=button name=Submit value=Cancel onClick='javascript:closeDiv();'>\r\n";
strLLF = strLLF + "</td>\r\n</tr>\r\n</table>\r\n</form>\r\n";

document.all.LiveLinkDiv.innerHTML = strLLF;

var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function LiveLink() {
  document.all.LiveLinkDiv.style.visibility = "visible";
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
    s=stripCharsInBag(strPhone,validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhoneNumber(strPhone){

    if ((strPhone==null)||(strPhone=="")){
	alert("Please Enter your Phone Number")
	return false
    }
    if (checkInternationalPhone(strPhone)==false){
	alert("Please Enter a Valid Phone Number")
	return false
    }
    return true
}

function retrieveRecord(strName,strPhone) {
    
    if (ValidatePhoneNumber(strPhone)) {
        var strFormValues = "Name="+strName+"&Phone="+strPhone
        xmlHttp = GetXmlHttpObject();
        xmlHttp.open("POST","LiveConnect.asp",true)
        xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        	document.getElementById("LiveLinkDiv").innerHTML=xmlHttp.responseText;
           }
  	}
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        xmlHttp.send(strFormValues);
    }
}

function closeDiv() {
  document.all.LiveLinkDiv.style.visibility='hidden';
  document.getElementById("LiveLinkDiv").innerHTML = strLLF;
}

function GetXmlHttpObject() { 
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
   {
    alert("This example doesn't work in Opera") 
    return;  
   }
if (navigator.userAgent.indexOf("MSIE")>=0)
   { 
   var strName="Msxml2.XMLHTTP"
   if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
      {
      strName="Microsoft.XMLHTTP"
      } 
   try
      { 
      objXmlHttp=new ActiveXObject(strName)
      //objXmlHttp.onreadystatechange=handler 
      return objXmlHttp
      } 
   catch(e)
      { 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
      } 
    } 
if (navigator.userAgent.indexOf("Mozilla")>=0)
   {
   objXmlHttp=new XMLHttpRequest()
   //objXmlHttp.onload=handler
   //objXmlHttp.onerror=handler 
   return objXmlHttp
   }
}

