﻿function getXMLHTTPObject() {
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
    } catch (e) {
        try { // Internet Explorer
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    var obj = document.getElementById(id);
    if(opacStart == 0) {
        obj.style.top = (tempY-90) + "px";
    }

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    if(opacity <= 10) { object.display = "none"; } else { object.display = "block"; }
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function addProduct(productID, quantity) {

    opacity("preProductAddedPopup", 0, 100, 1);
    
    if(typeof(quantity) == 'undefined') {
        quantity = 1;
    }
    ajaxObj = getXMLHTTPObject();
    var url = "/shopping/cart/addproductrealtime.aspx?action=add&productSizeID=" + productID;
    url = url + "&quantity=" + quantity;
    url = url + "&randid=" + Math.random();
    ajaxObj.onreadystatechange = stateChanged;
    ajaxObj.open("GET", url, true);
    ajaxObj.send(null);
}

function stateChanged() {
    if(ajaxObj.readyState == 4) {
        cartSpanDom.innerHTML = ajaxObj.responseText;
        opacity("productAddedPopup", 0, 100, 400);
        opacity("preProductAddedPopup", 100, 0, 400);
    }
}

function hidePopup() {
    opacity("productAddedPopup", 100, 0, 400);
}

function getProductQuantity(quantityID) {
    return document.getElementById(quantityID).value;
}





var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseY;

// Temporary variables to hold mouse x-y pos.s
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    var scrollTopVal = 0;
    if (document.documentElement && !document.documentElement.scrollTop) {
        // IE6 +4.01 but no scrolling going on
        scrollTopVal = 0;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        // IE6 +4.01 and user has scrolled
        scrollTopVal = document.documentElement.scrollTop;
    } else if (document.body && document.body.scrollTop) {
        // IE5 or DTD 3.2
        scrollTopVal = document.body.scrollTop;
    }
    tempY = event.clientY + scrollTopVal;
  } else {  // grab the x-y pos.s if browser is NS
    tempY = e.pageY
  }  
  if (tempY < 0){tempY = 0}  
  return true
}
