// JavaScript Document

var xmlHttp;
var req;


function addtocart(form, submitbutton,formName) {
	theID=eval('document.'+form+'.'+formName+'.value');
	processAddCart(theID); 
}
 
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    }
}


//add to cart script
function processAddCart(thelink){
		createXMLHttpRequest();
		var url  = '/shop/cart/cartadd.cfm?AddMerchID='+thelink;
		
	
	if (window.XMLHttpRequest) {
        req.onreadystatechange = addComplete;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        if (req) {
            req.onreadystatechange = addComplete;
            req.open("GET", url, true);
            req.send();
        }
    }
		
}

function addComplete() {
    // only if req shows "complete"
    if (req.readyState == 4) {
		// only if "OK"
        if (req.status == 200) {			
			 alert('Item has been added to your cart');
		}
   
    }
}


//drop down script
function loadDropDownXML(productID, color){
	createXMLHttpRequest();
	url  = '/shop/process/sizes.cfm?product=' + productID + '&colorID=' + color;
	
   // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req.onreadystatechange = processDropDown;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        if (req) {
            req.onreadystatechange = processDropDown;
            req.open("GET", url, true);
            req.send();
        }
    }
}
 


function processDropDown() {
    // only if req shows "complete"
    if (req.readyState == 4) {
		// only if "OK"
        if (req.status == 200) {
			//parse the xml document 
			var list = req.responseXML.getElementsByTagName('sizes');
			var dropForm = document.cartadd.selectsize
			//clear drop down menu before repopulating it
			var currentdropNum = dropForm.options.length;
			for (var x=currentdropNum; x>=0; x--){
                    dropForm.options[x]=null;	
            } 
			//change the inventory id form value for the add cart feature
			idNum = list[0].getAttribute("theid");
			setINV('cartadd', idNum)
			
			//populate dropdown menu
			for(var i=0; i<list.length; i++){
					//grab values from xml document	
					listOpt = document.createElement("option");
        			var catID = list[i].getAttribute("theid");
					var ListName = list[i].getAttribute("name");
						
						listOpt.value = catID;
						listOpt.text = ListName;
						dropForm.add(listOpt);
						
      		}
			
			sizeID = list[0].getAttribute("sizeID");
			
			if (sizeID == '1'){
				var sizeDD= document.getElementById('sizeDrop');
				sizeDD.style.display="none";	
			}
			
			
        } 
    }
}

