﻿
var divError;

function CreateSalesProspectToCRM() 
{

try
    {
    divError = $('#divError');
    divError.text(''); 
    var lname = $("#txtLName").val();
    var fname = $("#txtFName").val(); 
    var company = $("#txtCompany").val(); 
    var email = $("#txtEmail").val(); 
    var phone = $("#txtPhone").val(); 
    var zip = $("#txtZip").val();
    var comments = $("#txtComments").val(); 
    var contactmethod = $('input[id=chkContactMethod]:checked').val(); 
    var smartgrid = $('input[id=chkSmartGrid]:checked').val(); 
    var interest = $('#cboInterest').val();

    if(lname.length == 0 || fname.length == 0 || company.length == 0 || email.length == 0 || phone.length == 0 || !regIsEmail(email))
        {
        divError.text('Please complete the required fields, marked with an asterisk below.'); 
        return false;
        }
        
    WebService.CreateSalesProspectToCRM(fname, lname, company, email, phone,contactmethod, zip, interest, smartgrid, comments, onAddSuccess, onAddFailure, showBox, null);

    }
catch (e)
    {
    //alert(e);
    }

return false;
}

function regIsEmail(email)
{
  var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
  return pattern.test(email); 
}


function showBox()
  { 
    var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

    var layer = document.createElement('div');
    layer.style.zIndex = 2;
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.6';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=55)");
    document.body.appendChild(layer); 
   
    var div = document.createElement('div');
    div.style.zIndex = 3;
    div.id = 'box';
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    div.style.top = '200px';
    div.style.left = (width / 2) - (400 / 2) + 'px'; 
    div.style.height = '50px';
    div.style.width = '300px';
    div.style.backgroundColor = 'white';
    div.style.border = '1px solid silver';
    div.style.padding = '20px';
    div.style.textAlign = 'center';
    document.body.appendChild(div); 
   
    var p = document.createElement('p');
    p.innerHTML = 'Thank you for your request. We will contact you soon.';
    div.appendChild(p);
   
    var a = document.createElement('a');
    a.innerHTML = 'OK';
    a.style.fontWeight = 'bold'
    a.style.border = '1px solid silver';
    a.style.backgroundColor = '#cccccc';
    a.style.textDecoration = 'none';
    a.style.padding= '3px ';
    a.href = 'http://gridpoint.com';
    a.onclick = function()
    {
      window.location ='http://gridpoint.com';
    };
     
    div.appendChild(a);
  }


function onAddSuccess(result) //, context, functionName
{    
$("#txtLName").val('');
$("#txtFName").val('');
$("#txtCompany").val('');
$("#txtEmail").val('');
$("#txtPhone").val('');
$("#txtZip").val('');
$("#txtComments").val('');
$('input[id="chkContactMethod"]')[1].checked = true;
$('input[id="chkSmartGrid"]')[0].checked = true;
$("#cboInterest").val('Home Energy Management');

showBox();

//window.location = 'LeadGenSuccess.aspx';

}

function onAddFailure(error) //, context, functionName
{
    //alert('Error: ' + error);
} 




