﻿var isOpen = "no";

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var trailimage = ["", 400, 183] //image path, plus width and height
var offsetfrommouse = [25, -15] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset    
var displayduration = 0 //duration in seconds image should remain visible. 0 for always.

if (displayduration > 0) setTimeout("hidetrail()", displayduration * 1000)

if (document.getElementById || document.all) {
    document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:0px;width:auto;height:auto;padding:10px;border-top:solid 2px grey;border-left:solid 2px grey;border-right:solid 3px black;border-bottom:solid 3px black;background:white;"><img id="theimage" src="_skins/cssst/img/loading.gif" style="border: solid 1px grey;"></div>');
}


function gettrailobj() {
    if (document.getElementById)
        return document.getElementById("trailimageid").style
    else if (document.all)
        return document.all.trailimagid.style
}

function truebody() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function showtrail(whichimage) {
    var theImage = document.getElementById('theimage');
    if (theImage != null) {
        theImage.setAttribute('src', whichimage);
        document.onmousemove = followmouse;
        gettrailobj().visibility = "visible";
    }
}


function hidetrail() {
    gettrailobj().visibility = "hidden";
    var theImage = document.getElementById('theimage');
    if (theImage != null) {
        theImage.setAttribute('src', '_skins/cssst/img/loading.gif');
    }
    document.onmousemove = "";

}

function followmouse(e) {

    var xcoord = 0;
    var ycoord = 0;

    if (typeof e != "undefined") {
        xcoord += e.pageX;
        ycoord += e.pageY;
    }
    else if (typeof window.event != "undefined") {
        xcoord += truebody().scrollLeft + event.clientX;
        ycoord += truebody().scrollTop + event.clientY;

    }
    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

    if (xcoord + trailimage[1] + 3 > docwidth) {
        //gettrailobj().display = "none"
        gettrailobj().left = xcoord - trailimage[1] - 50 - offsetfrommouse[0] + "px"
    }
    else {
        //gettrailobj().display = ""
        gettrailobj().left = xcoord + offsetfrommouse[0] + "px"
    }
    if (ycoord + trailimage[2] > truebody().scrollTop + truebody().clientHeight) {
        //gettrailobj().display = "none"
        gettrailobj().top = ycoord - trailimage[2] + offsetfrommouse[1] + "px"
    }
    else {
        //gettrailobj().display = ""
        gettrailobj().top = ycoord + offsetfrommouse[1] + "px"
    }

}




function SwitchImage(imageobject, imagename) {
    var myObj = document.getElementById(imageobject);
    myObj.src = imagename;
}

function queryString(parameter) {
    var loc = location.search.substring(1, location.search.length);
    var param_value = false;

    var params = loc.split("&");
    for (i = 0; i < params.length; i++) {
        param_name = params[i].substring(0, params[i].indexOf('='));
        if (param_name == parameter) {
            param_value = params[i].substring(params[i].indexOf('=') + 1)
        }
    }
    if (param_value) {
        return param_value;
    }
    else {
        return false;
    }
}

function moveXY() {
    var myObject = queryString("mt");
    if (myObject != null && myObject != false) {
        var obj2 = document.getElementById('placeholder');
        var myObject_array = myObject.split("|");
        var i = 0;
        while (i < myObject_array.length) {
            var obj = document.getElementById(myObject_array[i]);
            if (obj != null) {
                obj2.appendChild(obj);
            }
            i++;
        }
    }
}

function setFlyout(e, p, d) {
    if (isOpen == "yes") {
        closeFlyout();
        isOpen = "no";
    }
    ctl00_pgBody_FlyoutProd.AttachTo(e);
    ctl00_pgBody_FlyoutProd.setPosition(d, 'LEFT')
    document.getElementById('flyoutProdContainer').innerHTML = "<iframe src='_skins/cssst/related_products_popup.aspx?qfCriteria=" + p + "' width='100%' height='100%' scrolling='AUTO' frameborder='0'></iframe>";
    isOpen = "yes";
    ctl00_pgBody_FlyoutProd.Open();

}

function setFlyoutSearch(e, p, d) {
    if (isOpen == "yes") {
        closeFlyout();
        isOpen = "no";
    }
    ctl00_ContentPlaceHolder1_searchMain_FlyoutProd.AttachTo(e);
    ctl00_ContentPlaceHolder1_searchMain_FlyoutProd.setPosition(d, 'LEFT')
    document.getElementById('flyoutProdContainer').innerHTML = "<iframe src='_skins/cssst/related_products_popup.aspx?qfCriteria=" + p + "' width='100%' height='100%' scrolling='AUTO' frameborder='0'></iframe>";
    isOpen = "yes";
    ctl00_ContentPlaceHolder1_searchMain_FlyoutProd.Open();

}

function closeFlyout() {
    ctl00_pgBody_FlyoutProd.Close();
    isOpen = "no";
}

function closeFlyoutSearch() {
    ctl00_ContentPlaceHolder1_searchMain_FlyoutProd.Close();
    isOpen = "no";
}

function ShowEmailForm(sProdID, sName, sImage) {
    // get reference to modal popup using the AJAX api $find() function
    // this funciton gets a reference to a ajax control toolkit object if the behavior
    // id property is specified
    var mpe = $find('MPE');
    if (mpe) {
        var divForm = document.getElementById('divForm');
        if (divForm != null) {
            divForm.style.visibility = "visible";
            divForm.style.display = "block";
        }
        var divSending = document.getElementById('divSending');
        if (divSending != null) {
            divSending.style.visibility = "hidden";
            divSending.style.display = "none";
        }
        var hProduct = document.getElementById('ctl00_pgBody_hProduct');
        if (hProduct != null) {
            hProduct.value = sProdID;
        }
        var hProductName = document.getElementById('ctl00_pgBody_hProductName');
        if (hProductName != null) {
            hProductName.value = sName;
        }
        var iImage = document.getElementById('ctl00_pgBody_idMediumGif');        
        if (iImage != null) {
            iImage.src = sImage;
        }
        var lName = document.getElementById('ctl00_pgBody_lProductName');
        if (lName != null) {
            lName.innerHTML = sName;
        }
        mpe.show();
    }
}

function CheckEmailForm() {
    var bReturn = true;
    var lEmailTo = document.getElementById('ctl00_pgBody_txtTo');
    if (lEmailTo != null) {
        if (lEmailTo.value == "") bReturn = false;
    }
    var lEmailFrom = document.getElementById('ctl00_pgBody_txtFrom');
    if (lEmailFrom != null) {
        if (lEmailFrom.value == "") bReturn = false;
    }
    if (!bReturn) {
        alert("Email To Address & Email From Address are required.  Please correct and try again.");
    }
    else {
        var divForm = document.getElementById('divForm');
        if (divForm != null) {
            divForm.style.visibility = "hidden";
            divForm.style.display = "none";
        }
        var divSending = document.getElementById('divSending');
        if (divSending != null) {
            divSending.style.visibility = "visible";
            divSending.style.display = "block";
        }
    }

    return bReturn;
}


function ShowEmailFormSearch(sProdID, sName, sImage) {
    // get reference to modal popup using the AJAX api $find() function
    // this funciton gets a reference to a ajax control toolkit object if the behavior
    // id property is specified
    var mpe = $find('MPE');
    if (mpe) {
        var divForm = document.getElementById('divForm');
        if (divForm != null) {
            divForm.style.visibility = "visible";
            divForm.style.display = "block";
        }
        var divSending = document.getElementById('divSending');
        if (divSending != null) {
            divSending.style.visibility = "hidden";
            divSending.style.display = "none";
        }
        var hProduct = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_hProduct');
        if (hProduct != null) {
            hProduct.value = sProdID;
        }
        var hProductName = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_hProductName');
        if (hProductName != null) {
            hProductName.value = sName;
        }
        var iImage = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_idMediumGif');
        if (iImage != null) {
            iImage.src = sImage;
        }
        var lName = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_lProductName');
        if (lName != null) {
            lName.innerHTML = sName;
        }
        mpe.show();
    }
}

function CheckEmailFormSearch() {
    var bReturn = true;
    var lEmailTo = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_txtTo');
    if (lEmailTo != null) {
        if (lEmailTo.value == "") bReturn = false;
    }
    var lEmailFrom = document.getElementById('ctl00_ContentPlaceHolder1_searchMain_txtFrom');
    if (lEmailFrom != null) {
        if (lEmailFrom.value == "") bReturn = false;
    }
    if (!bReturn) {
        alert("Email To Address & Email From Address are required.  Please correct and try again.");
    }
    else {
        var divForm = document.getElementById('divForm');
        if (divForm != null) {
            divForm.style.visibility = "hidden";
            divForm.style.display = "none";
        }
        var divSending = document.getElementById('divSending');
        if (divSending != null) {
            divSending.style.visibility = "visible";
            divSending.style.display = "block";
        }
    }

    return bReturn;
}

function CloseEmailForm() {
    // get reference to modal popup using the AJAX api $find() function
    // this funciton gets a reference to a ajax control toolkit object if the behavior
    // id property is specified
    var mpe = $find('MPE');
    if (mpe) {
        mpe.hide();
    }
}

function ShowLargerImage(sProdID, sName, sImage) {
    // get reference to modal popup using the AJAX api $find() function
    // this funciton gets a reference to a ajax control toolkit object if the behavior
    // id property is specified
    var mpe = $find('MPELargerImage');
    if (mpe) {
        var divForm = document.getElementById('divLargerImage');
        if (divForm != null) {
            divForm.style.visibility = "visible";
            divForm.style.display = "block";
        }        
        var iImage = document.getElementById('ctl00_pgBody_idMediumGif2');
        if (iImage != null) {           
            iImage.src = sImage;
        }       
        mpe.show();
    }
}

function CloseLargerImage() {
    // get reference to modal popup using the AJAX api $find() function
    // this funciton gets a reference to a ajax control toolkit object if the behavior
    // id property is specified
    var mpe = $find('MPELargerImage');
    if (mpe) {
        mpe.hide();
    }
}

//function ShowProdInfo(sProdID) {
//    // get reference to modal popup using the AJAX api $find() function
//    // this funciton gets a reference to a ajax control toolkit object if the behavior
//    // id property is specified
//    var mpe = $find('MPEProdInfo');
//    if (mpe) {
//        var divProdInfo = document.getElementById('divProdInfo');
//        divProdInfo.innerHTML = "<iframe src='_skins/cssst/productinfo_popup.aspx?qfCriteria=" + sProdID + "' width='100%' height='500px' frameborder='0'></iframe>";
//        mpe.show();
//    }
//}

//function CloseProdInfoForm() {
//    // get reference to modal popup using the AJAX api $find() function
//    // this funciton gets a reference to a ajax control toolkit object if the behavior
//    // id property is specified
//    var mpe = $find('MPEProdInfo');
//    if (mpe) {
//        mpe.hide();
//    }
//}

function ClosePopup(ctrlID) {
  var mpe = $find(ctrlID);
  if (mpe) {
    mpe.hide();
  }
}

function ShowPopup(ctrlID) {
  var mpe = $find(ctrlID);
  if (mpe) {
    mpe.show();
  }
  return true;
}

