// -----------------------------------------------------
// TalkNow sample javascript for customer integration. 
// This is intended as an example for customers to follow to add TalkNow to their website.
// Copyright Lekane 2008
// -----------------------------------------------------

/**
* These values would be generated by the customer server for a specific page 
*/
// proxyURL is a local proxy that is expected to understand HttpPost requests
// with a parameter named url whose value is the remote URL to retrieve.
var proxyURL = 'redirect.abc';

// lekaneServerURL is the URL and port that the Lekane TalkNow server is running on.
var lekaneServerURL = 'http://194.157.221.39:8080';

// This is the deploymentId unique identifier
var deploymentId = 'NetWheels';

// This is the data that is sent over as part of the call request
var data = new Array();
data[0] = new Array();
data[1] = new Array();
// -----------------------------------------------------

/**
* Lekane TalkNow uses the Protype Javascript library for cross browser ajax.
* The following shows how to request prototype to call the isAvailable method for
* id 444444U and to send the result to the method myAvailableCallback when the page
* is loaded.
* @see http://www.prototypejs.org
*/



Event.observe(window, 'load', function() { isAvailable(searchPattern, myAvailableCallback) });


/**
* This is where you define what you want to do when you receive a presence response.
* The presenceCallBack expects a boolean variable for true indicating that
* someone from the requested group is available or false if they aren't.
* @param isAvailable boolean 
*/
var myAvailableCallback = function availableCallback(isAvailable) {
    // We are using the prototype shorthand for getting the elements on the sample.html page.
    //var presenceText = $('talkNowPresenceText');
    //var presenceImage = $('talkNowPresenceImage');

    var presenceText = document.getElementById("TN_PrensenceText");
    //var presenceHeader = document.getElementById("talkNowPresenceHeader");
    // var presenceImage = document.getElementById("PresenceImage");

    if (isAvailable) {
        // Someone from the requested group is available, change the image and text to show this
        // presenceImage.setAttribute('src', '../TalkNow/kuvat/nainen.png');
        //presenceHeader.innerHTML = 'OLEMME VALMIIT PALVELEMAAN SINUA!';
        presenceText.innerHTML = 'Jätä puhelinnumerosi niin automyyjämme soittaa sinulle pian.';
    } else {
        // Someone from the requested group is not available, change the image and text to show this
        // presenceImage.setAttribute('src', '../TalkNow/kuvat/nainen.png');
        //presenceHeader.innerHTML = 'LÄHETÄ PUHELINNUMEROSI!';
        presenceText.innerHTML = 'Jätä puhelinnumerosi, Ensimmäinen vapautuva myyjä soittaa Sinulle.';
    }
};


/**
* This is where you define what you want to do when you receive a response to the callback request.
* @param caller is who will be calling the web user back, or null if the request timed out.
*/



/**
* An example function that shows the format of the data to send to TalkNow server.
* This example takes some data that was generated on the server side of the form key and value's
* stored in an Array. It adds in the phone number entered on the web page.
* This technique can be used to add any fields that are required to be broadcast to the mobile phones.
*/
function callRequestDataVaihtoautot() {

    //alert("vaihtoautot");
    // Get the phone number from the sample.html
    data[0][0] = 'year';
    data[1][0] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidVuosimalli").value;
    data[0][1] = 'title';
    data[1][1] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidAjoneuvonLiike").value + ': ' + document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidAuto").value;
    data[0][2] = 'price';
    data[1][2] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidHinta").value;
    data[0][3] = 'registration';
    data[1][3] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidRekisteri").value;
    data[0][4] = 'mileage';
    data[1][4] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_hidAjomaara").value;
    data[0][5] = 'phoneNumber';
    data[1][5] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_tbPhoneNumber").value;
    data[0][6] = 'requestType';
    data[1][6] = 'usedCar';

    // Call TalkNow Vaihtoautot send request
    sendCallRequest(searchPattern, data, myCallRequestCallback);
}

function callRequestDataEtusivu() {

    // Get the phone number from the sample.html
    // Further data can be passed to the TalkNow server in this way.
    data[0][0] = 'requestType';
    data[1][0] = 'feedback';
    data[0][1] = 'feedback';
    data[1][1] = 'Tavoittelen myyjää ' + document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_ddlToimipiste").value + ' toimipisteestä';
    data[0][2] = 'first';
    data[1][2] = 'Sivuston';
    data[0][3] = 'last';
    data[1][3] = 'Käyttäjä';
    data[0][4] = 'phoneNumber';
    data[1][4] = document.getElementById("ctl00_cphPageContent_nwuctrl_Talknow_tbPhoneNumber").value;
    
    // Call TalkNow Etusivu send Request
    sendCallRequest(searchPattern, data, myCallRequestCallback);
}
