﻿function callTracker() {
    pageTracker._trackPageview("/ajax/deal-expired/");    
}

function DealLike() {

    this.IDDeal = null;
    this.SpanDealLikeCount = null;
    this.SpanDealLikeTitle = null;

    //Private objects
    var oXmlHttp = null;
    var oLikeResponseElementID = null;
    var oSpanDealLikeCount = null;
    var oSpanDealLikeTitle = null;

    function Initialize() {
        if (window.XMLHttpRequest) {
            oXmlHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
        }
        else {

        }
    }

    this.Set = function() {

        Initialize();

        oSpanDealLikeCount = this.SpanDealLikeCount;
        oSpanDealLikeTitle = this.SpanDealLikeTitle;

        oXmlHttp.open("POST", "/WebService/DealCommets.asmx", true);
        oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

        oXmlHttp.setRequestHeader("SOAPAction", "http://www.cheaptoday.com/UpdateLikeDeal");

        sendText = new String();

        sendText = sendText.concat('<?xml version="1.0" encoding="utf-8"?>');
        sendText = sendText.concat('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">');
        sendText = sendText.concat('<soap:Body>');
        sendText = sendText.concat('<UpdateLikeDeal xmlns="http://www.cheaptoday.com/">');
        sendText = sendText.concat('<IDDeal>' + this.IDDeal + '</IDDeal>');
        sendText = sendText.concat('</UpdateLikeDeal>');
        sendText = sendText.concat('</soap:Body>');
        sendText = sendText.concat('</soap:Envelope>');

        oXmlHttp.send(sendText);

        oXmlHttp.onreadystatechange = doReadyStateChange;
    }

    // Handles asynchronous request
    function doReadyStateChange() {


        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {

                if (oXmlHttp.responseText.indexOf('OK') != -1) 
                {
                    var objSpanDealLikeCount = document.getElementById(oSpanDealLikeCount);
                    var objSpanDealLikeTitle = document.getElementById(oSpanDealLikeTitle);

                    var oldLikeValue = parseFloat(objSpanDealLikeCount.innerHTML);
                    var newLikeValue = oldLikeValue + 1;

                    objSpanDealLikeCount.innerHTML = newLikeValue;

                    objSpanDealLikeCount.style.display = '';
                    objSpanDealLikeTitle.style.display = '';
                }
            }
        }
    }
}

function SetLikeComment(idDeal, spanDealLikeCount, spanDealLikeTitle) 
{
    var oDealLike = new DealLike();

    oDealLike.IDDeal = idDeal;
    oDealLike.SpanDealLikeCount = spanDealLikeCount;
    oDealLike.SpanDealLikeTitle = spanDealLikeTitle;

    oDealLike.Set();
}