﻿// PIT Functions

// Local settings
var txtOtherRelatedProducts = "<div class='pit_OP'>Other related products:</div>";
// Root url for products: canine/feline
var strProductsURL_feline="/home/pvd/feline/";
var strProductsURL_canine="/home/pvd/canine/";
// Loading image
var LOADINGIMG = "<img src='/images/loading.gif' border='0'>";

// ==========================================================
// Define our products...
// ==========================================================
// FELINE
// ==========================================================
var aF = new Array();
// DM
aF[0] = new Object;
aF[0].code = "DM";                              // Product Code
aF[0].title = "Diabetes Management";            // Product title
aF[0].width = "106";                            // Product Image width
aF[0].height = "237";                           // Product Image height
// HA
aF[1] = new Object;
aF[1].code = "HA";
aF[1].title = "HypoAllergenic";
aF[1].width = "106";
aF[1].height = "237";
// NF
aF[2] = new Object;
aF[2].code = "NF";
aF[2].title = "ReNal Function";
aF[2].width = "106";
aF[2].height = "237";
// UR
aF[3] = new Object;
aF[3].code = "UR";
aF[3].title = "ST/OX URinary";
aF[3].width = "117";
aF[3].height = "232";
// CN
aF[4] = new Object;
aF[4].code = "CN";
aF[4].title = "CoNvalescence";
aF[4].width = "109";
aF[4].height = "117";
// OM
aF[5] = new Object;
aF[5].code = "OM";
aF[5].title = "Obesity Management";
aF[5].width = "106";
aF[5].height = "237";
// EN
aF[6] = new Object;
aF[6].code = "EN";
aF[6].title = "Gastro ENteric";
aF[6].width = "106";
aF[6].height = "237";
// FortiFlora
aF[7] = new Object;
aF[7].code = "FF";
aF[7].title = "FortiFlora";
aF[7].width = "162";
aF[7].height = "259";

// ==========================================================
// CANINE
// ==========================================================
var aC = new Array();
// CV
aC[0] = new Object;
aC[0].code = "CV";
aC[0].title = "CardioVascular";
aC[0].width = "126";
aC[0].height = "247";
// DCO
aC[1] = new Object;
aC[1].code = "DCO";
aC[1].title = "Diabetes COlitis";
aC[1].width = "91";
aC[1].height = "233";
// DRM
aC[2] = new Object;
aC[2].code = "DRM";
aC[2].title = "Derm";
aC[2].width = "102";
aC[2].height = "219";
// N
aC[3] = new Object;
aC[3].code = "EN";
aC[3].title = "GastroENteric";
aC[3].width = "111";
aC[3].height = "228";
// HA
aC[4] = new Object;
aC[4].code = "HA";
aC[4].title = "HypoAllergenic";
aC[4].width = "91";
aC[4].height = "224";
// JM
aC[5] = new Object;
aC[5].code = "JM";
aC[5].title = "Joint Mobility";
aC[5].width = "102";
aC[5].height = "228";
// NF
aC[6] = new Object;
aC[6].code = "NF";
aC[6].title = "ReNal Function";
aC[6].width = "98";
aC[6].height = "220";
// OM
aC[7] = new Object;
aC[7].code = "OM";
aC[7].title = "Obesity Management";
aC[7].width = "102";
aC[7].height = "219";
// UR
aC[8] = new Object;
aC[8].code = "UR";
aC[8].title = "URinary";
aC[8].width = "101";
aC[8].height = "224";
// CN
aC[9] = new Object;
aC[9].code = "CN";
aC[9].title = "CoNvalescence";
aC[9].width = "120";
aC[9].height = "175";

// FortiFlora
aC[10] = new Object;
aC[10].code = "FF";
aC[10].title = "FortiFlora";
aC[10].width = "154";
aC[10].height = "256";


// Precache images...
var imgF = new Array();
for (var n=0;n<aF.length;n++) {
    imgF[n] = new Image();
    imgF[n].src="/images/products/feline/"+aF[n]['code']+".png";
}
var imgC = new Array();
for (var n=0;n<aC.length;n++) {
    imgC[n] = new Image();
    imgC[n].src="/images/products/canine/"+aC[n]['code']+".png";
}

// ==========================================================
// Search functions
// ==========================================================
var pit_Type = "";
function pit_DoSearch() {
    if (pit_Type == "") return;
    var tb = document.getElementById("pitlist");
    if (tb!=null) tb.innerHTML = LOADINGIMG;
    DoAjaxRequest("/templates/pit.aspx?q=1&t="+pit_Type+"&search="+(encodeURI(document.forms[0].pitsearch.value)), "", "pit_EndRequest");
}
function pit_EndRequest(result) {
    var tb = document.getElementById("pitlist");
    if (tb!=null) tb.innerHTML = result;
}
function pit_keyup_send() {
    st = new String(document.forms[0].pitsearch.value);
    if (st.length >= 0)
        pit_DoSearch();
}

// Set timeout that when user stops typing THEN we send single request!
var pit_kuto = null;
function pit_keyup() {
    if (pit_kuto != null)
        clearTimeout(pit_kuto);
    pit_kuto = setTimeout('pit_keyup_send()', 400);
}

// ==========================================================
// Animate selected image
// ==========================================================
var pit_Anime_TMR=25;       // Timeout value for updating image animation/speed (lower=faster)
var fFactor = 0.1;
var fFactorTMR = null;
var pitW = 0;
var pitH = 0;
var pitC = "";
function pit_AnimateImg() {
    var img = document.getElementById("pimg");
    if (img != null) {
        img.width = pitW*fFactor;
        img.height = pitH*fFactor;
        fFactor += 0.08;
        // Final image size reached?
        if (parseFloat(fFactor) >= 0.85) {
            // stop
            clearInterval(fFactorTMR);
            // Show text
            var m = document.getElementById('mainimgdetails');
            if (m!=null) m.style.display = "block";
            m = document.getElementById('otherproducts');
            if (m!=null) m.style.display = "block";
        }
    }
}

// ==========================================================
// Show specific product
// ==========================================================
var lAid = "";
var bInit = false;
function pit_SP(aid, pids) {
    // Ensure timer stopped...
    clearInterval(fFactorTMR);
    // Highlight selected item in list...
    if (lAid != "") {
        // restore previous
        var zz = document.getElementById(lAid);
        if (zz!=null) zz.className = "normal";
    }
    // highlight current
    var zx = document.getElementById(aid);
    if (zx!=null) {
        lAid = aid;
        zx.className = "selected";
    }
    // Split the pids
    var aPids = pids.split(",");
    var ss = document.getElementById('otherproducts');
    if (ss!=null) ss.innerHTML = "";
    // Loop each
    for (var n = 0; n < aPids.length; n++) {
        // Get type
        var itype = aPids[n].substring(0, 1).toLowerCase();
        var icode = aPids[n].substring(1).toLowerCase();
        var aA;
        var ifolder = "";
        if (itype == 'c') {
            aA = aC;
            ifolder = "canine";
        } else {
            aA = aF;
            ifolder = "feline";
        }
        // Loop our products...
        for (var x=0;x<aA.length;x++) {
            // Is this ours?
            if (aA[x]['code'].toLowerCase() == icode) {
                // Yes... primary or secondary...
                if (n == 0) {
                    // Primary
                    var m = document.getElementById('mainimgdetails_title1');
                    if (m!=null) m.innerHTML = "<span class='product_"+icode+"'>"+icode.toUpperCase()+"</span>";
                    m = document.getElementById('mainimgdetails_title2');
                    if (m!=null) m.innerHTML = "<span class='product_"+icode+"'>"+aA[x]['title']+"</span>";
                    m = document.getElementById('themainimg');
                    if (m!=null) {
                        m.innerHTML = "<a href='javascript:pit_GoProduct();'><img id='pimg' src='/images/products/"+ifolder+"/"+aA[x]['code']+".png' border='0' alt='"+aA[x]['code']+" "+aA[x]['title']+"' width='0' height='0' /></a>";
                        // Turn text off for now and reshow once animation completed
                        m = document.getElementById('mainimgdetails');
                        if (m!=null) m.style.display = "none";
                        m = document.getElementById('otherproducts');
                        if (m!=null) m.style.display = "none";
                        // Setup animation
                        fFactor = 0.2;
                        pitW = aA[x]['width'];
                        pitH = aA[x]['height'];
//                        UpdateBackground(icode);
                        fFactorTMR = setInterval("pit_AnimateImg()", pit_Anime_TMR);
                    }
                    // Set the product link
                    if (itype=='c')
                        GP_URL = "/home/pvd/canine/"+icode.toLowerCase()+".htm";
                    else
                        GP_URL = "/home/pvd/feline/"+icode.toLowerCase()+".htm";
                    // FF link...
                    if (icode.toLowerCase() == "ff") 
                    {
                        if(itype=="c")
                        {
                            GP_URL='/home/pvd/nutritionalsupplements/fortiflora-canine.htm';
                        }
                        else
                        {
                            GP_URL='/home/pvd/nutritionalsupplements/fortiflora-feline.htm';
                        }
                    }
                    // Show the div
                    m = document.getElementById('mainimgdetails_view');
                    if (m!=null) m.style.display = "inline";
                } else {
                    // Secondary
                    var m = document.getElementById('otherproducts');
                    if (m!=null) {
                        if (n==1) m.innerHTML = txtOtherRelatedProducts;
                        var url = strProductsURL_feline+icode.toLowerCase()+".htm";
                        if (itype=='c')
                            url = strProductsURL_canine+icode.toLowerCase()+".htm";
                        if(icode=="ff")
                        {
                            if(itype=="c")
                            {
                                url='/home/pvd/nutritionalsupplements/fortiflora-canine.htm';
                            }
                            else
                            {
                                url='/home/pvd/nutritionalsupplements/fortiflora-feline.htm';
                            }
                        }
                            m.innerHTML += "<a href='"+url+"'>"+aA[x]['code']+" "+aA[x]['title']+"</a><br/>";
                    }
                }
            }
        }
    }
    // Hide intro graphic, show main...
    if (bInit == false) {
        bInit = true;
        var ww = document.getElementById('rightcol');
        if (ww!=null) ww.style.display = "block";
        ww = document.getElementById('rightcol_init');
        if (ww!=null) ww.style.display = "none";
    }
}

var GP_URL = "";
function pit_GoProduct() {
    if (GP_URL != "")
        document.location.href = GP_URL;
}


