﻿// JScript File

function sendAJAXRequest(url, params, callback_function)
{ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    xmlHttp.open('POST',url);
    
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState==4)
        { 
            callback_function(xmlHttp.responseText);
        }
    };
    
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(params);  
}

function GetXmlHttpObject()
{
    var xmlHttp1=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp1=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp1;
}

function SizeChange(sizeBox)
{
    document.getElementById('ChosenSize').value = GetDDLValue(sizeBox.value);
    AjaxUpDatePrice();
}
function ColorChange(colorBox)
{
    document.getElementById('ChosenColor').value = GetDDLValue(colorBox.value);
    AjaxUpDatePrice();
}
function AjaxUpDatePrice()
{
    var size = document.getElementById('ChosenSize').value;
    var color = document.getElementById('ChosenColor').value;
    var hasSize = false;
    var hasColor = false;
    if(document.getElementById('ChosenSize')) { hasSize = true; }
    if(document.getElementById('ChosenColor')) { hasColor = true; }
    var productID = document.getElementById('ChosenProductID').value;
        var callPage = 'JCApparelAjaxPriceRequest.aspx?S='+size+'&C='+color+'&PID='+productID+'&hasColor='+hasColor+'&hasSize='+hasSize;
            sendAJAXRequest(callPage,'',
            function (Price){
                if(Price != '')
                {
                    document.getElementById('FormattedPrice').innerHTML = Price;
                }
            });
}
function GetDDLValue(val)
{
    var toReturn;
    if(val == '-,-')
    {
        toReturn = '';
    }
    else
    {
        toReturn = val.substring(0,val.length-1);
    }
    return toReturn;
}
function ShowPriceVariables(){
    alert("size : " + document.getElementById('ChosenSize').value + "\nColor : " + document.getElementById('ChosenColor').value + "\nPID : " + document.getElementById('ChosenProductID').value);
}