﻿function __doPostBack(eventTarget, eventArgument) {

    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }

    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

/* used for ajax*/
function getHTTPObject() {

  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;

}

/* END / used for ajax*/

function handleHttpResponse_StockInfo() {
 
  if (http.readyState == 4) {

    results = http.responseText;

    if(results == "true")
    {
        __doPostBack('ctl00$ContentPlaceHolder1$imbAddToCart','');
    }
    else
    {
        alert(results);    
    }
  }
}

function getObject(id) {

	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all[id]
	}
}

function getStockInfo(id) {
    
	http = getHTTPObject();
		
	url = "AjaxFunctions.aspx?function=getStockInfo&itemid=" + id + "&sizeid=" + getObject("ctl00_ContentPlaceHolder1_ddlSize").value +  "&qty=" + getObject("ctl00_ContentPlaceHolder1_txtQuantity").value;
	http.open("GET", url, true); 
	http.onreadystatechange = handleHttpResponse_StockInfo; 
	http.send(null);
 
}