﻿var CompleteTileURL;

function createStatsJson(affMicCode, trackingCode, countValue) {
    var statsJson = { "mic": affMicCode, "tc": trackingCode, "cv": countValue }
    return statsJson;
}
function postStats(objJson) {
    $.ajax({
        type: "GET",
        contentType: "text/json; charset=utf-8",
        url: "/Handlers/CarWizHandler.ashx",
        data: objJson,
        dataType: "json",
        cache: false,
        success: function() { },
        async: false
    });
};
function saveStatsPoint(total, noMic, haveMic) {
    //saveStatsPoint(total, noMic, haveMic);
    saveStatsPoint2(total, noMic, haveMic);
}
function saveStatsPoint(total, noMic, haveMic) {
    var affMicCode = '';
    var sTrackingCode = '';
    if (typeof (aff_micCode) != "undefined" && aff_micCode != '') {
        affMicCode = aff_micCode;
        sTrackingCode = total + ',' + haveMic;
        //alert(aff_micCode);
    }
    else {
        affMicCode = '';
        sTrackingCode = total + ',' + noMic;

    }

    postStats(createStatsJson(affMicCode, sTrackingCode, '1'));
}
function saveStatsPoint2(total, noMic, haveMic, isWait) 
{
    var affMicCode = '';
    var sTrackingCode = '';
    if (typeof (aff_micCode) != "undefined" && aff_micCode != '') 
    {
        affMicCode = aff_micCode;
        sTrackingCode = total + ',' + haveMic;
        //alert(aff_micCode);
    }
    else 
    {
        affMicCode = '';
        sTrackingCode = total + ',' + noMic;

    }
    if (isWait) 
    {

        callServiceSync(affMicCode, sTrackingCode, this);
    }
    else 
    {
        callServiceAsync(affMicCode, sTrackingCode,this);
    }
}
/* ********************* */
function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

// Method: CallService:
function callServiceAsync(affMicCode,TrackingCode, callBack) {
    var IsMultiple = (TrackingCode.indexOf(",") != -1);
    var xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var Param_tc = 'tc=' + TrackingCode;
    var Param_mic = 'mic=' + affMicCode;
    var Param_cv = 'cv=' + '1';
    var proxyUrl = '/Handlers/CarWizHandler.ashx' + '?' + Param_tc + '&' + Param_mic + '&' + Param_cv;
    if (xmlhttp.readyState == 4) {
        if (callBack != null) {
            callBack(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", proxyUrl, true);
    xmlhttp.send(null);
}

// Method: CallService:
function callServiceSync(affMicCode,TrackingCode, callBack) {
    var IsMultiple = (TrackingCode.indexOf(",") != -1);
    var xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var Param_tc = 'tc=' + TrackingCode;
    var Param_mic = 'mic=' + affMicCode;
    var Param_cv = 'cv=' + '1';
    var proxyUrl = '/Handlers/CarWizHandler.ashx' + '?' + Param_tc + '&' + Param_mic + '&' + Param_cv;
    xmlhttp.open("GET", proxyUrl, false);
    xmlhttp.send(null);

    //alert(xmlhttp.responseText);
    
    if (callBack != null) {
        callBack(xmlhttp.responseText);
    }
}

// Method: CallService:
function callGEOSync(locID,callback) {
    
    var xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Browser does not support HTTP Request");
        return;
    }
    var Param_locID = 'locID=' + locID;
    var proxyUrl = '/Handlers/GeoHandler.ashx' + '?' + Param_locID;
    xmlhttp.open("GET", proxyUrl, false);
    xmlhttp.send(null);

    alert(xmlhttp.responseText);

    if (callBack != null) {
        callBack(xmlhttp.responseText);
    }
}