
function check_login(login_status, customer_status)
{
	if (login_flag == 0)
	{
	    if (login_status == 1)
	    {
    	    window.location = inc_level + "home.asp";
    	}
    	else if (login_status == 0 || login_status == -1)
    	{
	        /* - moved this script to my.js to make use of jQuery
			document.getElementById("login_id").style.display = "inline";
	        document.getElementById("logout_id").style.display = "none";
	        document.getElementById("webreports_id").style.display = "none";
			document.getElementById("salesatlas_id").style.display = "none";
	        document.getElementById("updateaccount_id").style.display = "none";
			*/
    	}
	}
	else
	{
	    if (login_status == -1)
	    {
    	    window.location = inc_level + "home.asp";
    	}
    	else if (login_status == 0 || login_status == 1)
    	{
	        /* - moved this script to my.js to make use of jQuery
			document.getElementById("login_id").style.display = "none";
	        document.getElementById("logout_id").style.display = "inline";
	        document.getElementById("webreports_id").style.display = "inline";
	        document.getElementById("salesatlas_id").style.display = "inline";
	        document.getElementById("updateaccount_id").style.display = "inline";
			*/
	    }
	}
}

function login_click()
{
    document.getElementById("login_form").action = "home.asp?f=login";
    document.getElementById("login_form").submit();
}

function logout_click()
{
    window.location = inc_level + "home.asp?f=logout";
}

function enable_register()
{
    if (document.getElementById("termsAgreement").checked == false)
        document.getElementById("btnCustomerInfo").disabled = true;
    else
        document.getElementById("btnCustomerInfo").disabled = false;
}

function newaccount_click()
{
    if (CheckElements() == 0)
    {
        document.getElementById("customerInfo_form").action = "home.asp?f=newaccount";
        document.getElementById("customerInfo_form").submit();
    }
}

function updateaccount_click()
{
    if (CheckElements() == 0)
    {
        document.getElementById("customerInfo_form").action = "home.asp?f=updateaccount";
        document.getElementById("customerInfo_form").submit();
    }
}

function requestpresentation_click()
{
    if (CheckElements() == 0)
    {
        document.getElementById("customerInfo_form").action = "home.asp?f=requestpresentation";
        document.getElementById("customerInfo_form").submit();
    }
}

function bLinkedScheduleRequest_click()
{
    if (CheckElements() == 0)
    {
        document.getElementById("bLinkedDemo_form").action = inc_level + "home.asp?f=blinkedschedulerequest";
        document.getElementById("bLinkedDemo_form").submit();
    }
}

function contactus_click()
{
    if (CheckElements() == 0)
    {
        document.getElementById("customerInfo_form").action = "home.asp?f=contactus";
        document.getElementById("customerInfo_form").submit();
    }
}

function CheckElements()
{
    var EmptyFields
    EmptyFields = 0

    //if (GetElementLength("firstName") == 0)
    //    EmptyFields = 1;
    //else if (GetElementLength("lastName") == 0)
    //    EmptyFields = 1;
    //else if (GetElementLength("companyName") == 0)
    //{
    //    if (customer_type == 1)
    //        EmptyFields = 1;
    //}
    
    bus_phone_1 = GetElementValue("bus_phone1", 1)
    bus_phone_2 = GetElementValue("bus_phone2", 1)
    bus_phone_3 = GetElementValue("bus_phone3", 1)
    if(bus_phone_1.length != 3 || bus_phone_2.length != 3 || bus_phone_3.length != 4 || isNaN(bus_phone_1) || isNaN(bus_phone_2) || isNaN(bus_phone_3))
    {
        SetElementValue("bus_phone1", "");
        SetElementValue("bus_phone2", "");
        SetElementValue("bus_phone3", "");
    //    EmptyFields = 1;
    }

    cell_phone_1 = GetElementValue("cell_phone1", 1)
    cell_phone_2 = GetElementValue("cell_phone2", 1)
    cell_phone_3 = GetElementValue("cell_phone3", 1)
    if(cell_phone_1.length != 3 || cell_phone_2.length != 3 || cell_phone_3.length != 4 || isNaN(cell_phone_1) || isNaN(cell_phone_2) || isNaN(cell_phone_3))
    {
        SetElementValue("cell_phone1", "");
        SetElementValue("cell_phone2", "");
        SetElementValue("cell_phone3", "");
        //EmptyFields = 1;
    }

    emailStr = GetElementValue("email", 1);
    SetElementValue("email", emailStr);
    
    if (emailStr.length == 0)
        EmptyFields = 1;

    if (EmptyFields == 1)
    {
        if (document.getElementById("requiredFields") != null)
            document.getElementById("requiredFields").style.display = "block";
    }
    return EmptyFields
}

function GetElementValue(ElementName, RemoveSpaces)
{
    var ElementValue;
    ElementValue = ""

    if (document.getElementById(ElementName) != null)
    {
        ElementValue = document.getElementById(ElementName).value;
        if (RemoveSpaces == 1) ElementValue = ElementValue.replace(/ /g, "");
    }

    return ElementValue;
}

function SetElementValue(ElementName, ElementValue)
{
    var ElementExists;
    ElementExists = 0;
    
    if (document.getElementById(ElementName) != null)
    {
        document.getElementById(ElementName).value = ElementValue;
        ElementExists = 1;
    }

    return ElementExists;
}

function GetElementLength(ElementName)
{
    var CheckElement;
    CheckElement = -1;

    if (document.getElementById(ElementName) != null)
    {
        ElementValue = document.getElementById(ElementName).value;
        ElementValue = ElementValue.replace(/ /g, "");
        CheckElement = ElementValue.length;
    }

    return CheckElement;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AJAX functions
////////////////////////////////////////////////////////////////////////////////////////////////////////////

var serverResponseElemName
serverResponseElemName = "";

function XHConn()
{
    var xmlhttp, bComplete = false;

    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e)
    {
        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch(e)
        {
            try { xmlhttp = new XMLHttpRequest(); }
            catch(e) { xmlhttp = false; }
        }
    }

    if (!xmlhttp) return null;

    this.connect = function(sURL, sMethod, sVars, fnDone)
    {
        if (!xmlhttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();
        try
        {
            if (sMethod == "GET")
            {
                xmlhttp.open(sMethod, sURL+"?"+sVars, true);
                sVars = "";
            }
            else
            {
                xmlhttp.open(sMethod, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }

            xmlhttp.onreadystatechange = function()
            {
                if (xmlhttp.readyState == 4 && !bComplete)
                {
                    bComplete = true;
                    fnDone(xmlhttp);
                }
            };
  
            xmlhttp.send(sVars);
        }
        catch(z) { return false; }
        return true;
    };
return this;
}

// doAJAXCall : Generic AJAX Handler, used with XHConn
// PageURL : the server side page we are calling
// ReqType : either POST or GET, typically POST
// PostStr : parameter passed in a query string format 'param1=foo&param2=bar'
// FunctionName : the JS function that will handle the response
var doAJAXCall = function(PageURL, ReqType, PostStr, FunctionName)
{
	var myConn = new XHConn(); // create the new object for doing the XMLHTTP Request
	if (myConn) // XMLHTTPRequest is supported by the browser, continue with the request
    {
        myConn.async = false;
        myConn.connect('' + PageURL + '', '' + ReqType + '', '' + PostStr + '', FunctionName); 
    } 
	else // Not support by this browser, alert the user
    { alert("Your browser doesn't support some of the technologies used in this report. If possible, please update your browser and try again."); }
}

var getServerResponse = function(oXML) // The function for handling the response from the server
{ 
    var serverResponseAJAX = oXML.responseText; // get the response text, into a variable
    if (serverResponseElemName.length > 0)
    {
	    try { document.getElementById(serverResponseElemName).innerHTML = serverResponseAJAX; } // update the element to show the result from the server
        catch(e) {  }
        try { document.getElementById(serverResponseElemName).onchange(); }
        catch(e) {  }
    }
}

var sendClientRequest = function(urlStr, paramStr, elemName)
{
    serverResponseElemName = elemName;
    doAJAXCall(urlStr, 'GET', paramStr, getServerResponse); // use the generic function to make the request
}

