﻿var MLP = {
    updateShoppingCart: function() {
        jQuery.post('UpdateCart.aspx', {}, function(data) {
            if (data.indexOf("ERROR") != -1) {
                var msg = data.split("||");
                jQuery('#ctl00_lblMasterError').html(msg[1]);
                jQuery('#ctl00_countdown_dashboard').stopCountDown();
                jQuery('#ctl00_countdown_dashboard').html("");
                jQuery('#ctl00_spnTimeOutText').html("");
                jQuery('#ctl00_lnkShoppingCart').html("MyLittlePuppy Cart: 0 Items");
            }
            else {
                if (data == null || data == "") {
                    jQuery('#ctl00_countdown_dashboard').stopCountDown();
                    jQuery('#ctl00_countdown_dashboard').html("");
                    jQuery('#ctl00_spnTimeOutText').html("");
                    jQuery('#ctl00_lnkShoppingCart').html("MyLittlePuppy Cart: 0 Items");
                }
                else {
                    var restValues = data.split(",");
                    jQuery('#ctl00_countdown_dashboard').stopCountDown();
                    jQuery('#ctl00_countdown_dashboard').setCountDown({
                        targetDate: {
                            'day': parseInt(restValues[0]),
                            'month': parseInt(restValues[1]),
                            'year': parseInt(restValues[2]),
                            'hour': parseInt(restValues[3]),
                            'min': parseInt(restValues[4]),
                            'sec': parseInt(restValues[5])
                        },
                        serverDate: {
                            'day': parseInt(restValues[6]),
                            'month': parseInt(restValues[7]),
                            'year': parseInt(restValues[8]),
                            'hour': parseInt(restValues[9]),
                            'min': parseInt(restValues[10]),
                            'sec': parseInt(restValues[11])
                        }
                    });
                    jQuery('#ctl00_lnkShoppingCart').html("MyLittlePuppy Cart: " + restValues[12] + " Items");
                    jQuery('#ctl00_countdown_dashboard').startCountDown();
                }
            }
            var shopCartObj = window.document.getElementById("ctl00_ContentPlaceHolder1_hdnShoppingCartMode");
            if (shopCartObj != null) {
                window.document.getElementById("ctl00_ContentPlaceHolder1_hdnShoppingCartMode").value = "refresh";
                window.document.forms[0].submit();
            }
        });
    },

    getVideo: function(collarNumber) {
        currentCollarNumber = collarNumber;
        jQuery.post('GetVideo.aspx?P=' + collarNumber, {}, function(data) {
            if (data.indexOf("ERROR") != -1) {
                var msg = data.split("||");
                jQuery('#ctl00_lblMasterError').html(msg[1]);
            }
            else {
                if (data == null || data == "") {
                    jQuery('#slidevideo_' + collarNumber).html("");
                }
                else {
                    var vidValues = data.split(",");
                    var videoName = vidValues[0];
                    var profileVideoWidth = vidValues[1];
                    var profileVideoHeight = vidValues[2];
                    var videoOutput = "<div style=\"font-size: 10px; float: right; padding: 0px; margin-top: -7px; margin-bottom: -2px; clear: both;\">Optimized For Windows/IE&nbsp;&nbsp;&nbsp;&nbsp;<a target=\"_blank\" href=\"http://windows.microsoft.com/en-US/windows/downloads/windows-media-player\" style=\"font-size: 10px; color: white; text-decoration: underline;\">Get Media Player</a></div><br /><div style=\"margin-top: -10px; padding: 0px;\">";
                    videoOutput += "<OBJECT ID=\"MediaPlayer\" WIDTH=\"" + profileVideoWidth + "\" HEIGHT=\"" + profileVideoHeight + "\" CLASSID=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" STANDBY=\"Loading Windows Media Player components...\" TYPE=\"application/x-oleobject\">\n";
                    videoOutput += "<PARAM NAME=\"FileName\" VALUE=\"ftpimages/" + videoName + "\">\n";
                    videoOutput += "<PARAM name=\"autostart\" VALUE=\"true\">\n";
                    videoOutput += "<PARAM name=\"ShowControls\" VALUE=\"true\">\n";
                    videoOutput += "<PARAM name=\"ShowStatusBar\" value=\"false\">\n";
                    videoOutput += "<PARAM name=\"ShowDisplay\" VALUE=\"false\">\n";
                    videoOutput += "<EMBED TYPE=\"application/x-mplayer2\" SRC=\"ftpimages/" + videoName + "\" NAME=\"MediaPlayer\" WIDTH=\"" + profileVideoWidth + "\" HEIGHT=\"" + profileVideoHeight + "\" ShowControls=\"1\" ShowStatusBar=\"0\" ShowDisplay=\"0\" autostart=\"0\"></EMBED>\n";
                    videoOutput += "</OBJECT></div><br>\n";
                    jQuery('#slidevideo_' + collarNumber).html(videoOutput);
                }
            }
        });
    },

    updateMarketingMessage: function() {
        jQuery.post('GetRandomMarketingMessage.aspx', {}, function(data) {
            if (data.indexOf("ERROR") != -1) {
                var msg = data.split("||");
                jQuery('#ctl00_lblMasterError').html(msg[1]);
            }
            else {
                if (data == null || data == "") {
                }
                else {
                    var mmValues = data.split(",");
                    jQuery('#promo').html(mmValues[0]);
                }
            }
            setTimeout("MLP.updateMarketingMessage()", 10000);
        });
    },

    updateBreeds: function(i) {
        if (window.document.getElementById("ctl00_flImg" + i) != null) {
            var breedCode = window.document.getElementById("ctl00_hdnBreed" + i).value;
            if (breedCode != "") {
                jQuery.post('GetRandomFeaturedBreed.aspx?B=' + breedCode + 'I=' + i, {}, function(data) {
                    if (data.indexOf("ERROR") != -1) {
                        var msg = data.split("||");
                        jQuery('#ctl00_lblMasterError').html(msg[1]);
                    }
                    else {
                        if (data == null || data == "") {
                        }
                        else {
                            var breedValues = data.split(",");
                            var imgURL = breedValues[0];
                            var breedName = breedValues[1];
                            var pupName = breedValues[2];
                            var collarNum = breedValues[3];
                            var hasVideo = breedValues[4];
                            var videoWidth = breedValues[5];
                            var videoheight = breedValues[6];
                            window.document.getElementById("ctl00_spnImageVideo" + i).style.display = "none";
                            window.document.getElementById("ctl00_flImg" + i).style.display = "";
                            window.document.getElementById("ctl00_flImg" + i).style.display = "";
                            window.document.getElementById("ctl00_flImageLink" + i).style.display = "";
                            window.document.getElementById("ctl00_flPupName" + i).style.display = "";
                            window.document.getElementById("ctl00_flBreedName" + i).style.display = "";
                            window.document.getElementById("ctl00_flImageLink" + i).href = "PuppyDetail.aspx?P=" + collarNum;
                            window.document.getElementById("ctl00_flPupName" + i).href = "PuppyDetail.aspx?P=" + collarNum;
                            window.document.getElementById("ctl00_flBreedName" + i).href = "Puppies.aspx?B=" + breedCode;
                            if (imgURL != "") {
                                window.document.getElementById("ctl00_flImg" + i).src = "ftpimages/" + imgURL;
                            }
                            else {
                                window.document.getElementById("ctl00_flImg" + i).src = "images/shim.gif";
                            }
                            if (pupName != "") {
                                window.document.getElementById("ctl00_flPupName" + i).innerHTML = "Take " + pupName + " Home";
                            }
                            else {
                                window.document.getElementById("ctl00_flPupName" + i).innerHTML = "Click for More Info";
                            }
                            if (breedName != "") {
                                window.document.getElementById("ctl00_flBreedName" + i).innerHTML = breedName;
                            }
                            else {
                                window.document.getElementById("ctl00_flBreedName" + i).innerHTML = "";
                            }
                            if (hasVideo.toLowerCase() == "true") {
                                window.document.getElementById("ctl00_spnImageVideo" + i).style.display = "";
                                var videoURL = "<ul class=\"gallery clearfix\" style=\"display: inline;\">\n";
                                videoURL += "<li><a href=\"javascript:PlayVideo('" + collarNum + "'," + videoWidth + "," + videoheight + ");\" title=\"Play Me\"><img src=\"images/play-btn.png\" alt=\"\" style=\"width: 28px; height: 28px; border: none;\" /></a></li>\n";
                                videoURL += "</ul>\n"
                                window.document.getElementById("ctl00_spnImageVideo" + i).innerHTML = videoURL;
                            }
                        }
                    }
                });
            }
        }
        setTimeout("MLP.updateBreeds('" + i + "')", 15000);
    }
};
