function getXMLHTTPRequest() {
   var req =  false;
   try {
      /* for Firefox */
      req = new XMLHttpRequest(); 
   } catch (err) {
      try {
         /* for some versions of IE */
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (err) {
         try {
            /* for some other versions of IE */
            req = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (err) {
            req = false;
         }
     }
   }
   
   return req;
}

function getConnectors(show_now_var) {
  var thePage = 'lookupconnectors.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = document.getElementById('conn_type').value;
  var show_now = show_now_var || 'no';
  if (conn_type.length == 0) {
	  conn_type = "%";
  }
  var conn_gender = document.getElementById('conn_gender').value;
  if (conn_gender.length == 0) {
	  conn_gender = "%";
  }
  var conn_shape = document.getElementById('conn_shape').value;
  if (conn_shape.length == 0) {
	  conn_shape = "%";
  }
  var attach_by = document.getElementById('attach_by').value;
  if (attach_by.length == 0) {
	  attach_by = "%";
  }
  var fcc_part15 = document.getElementById('fcc_part15').value;
  if (fcc_part15.length == 0) {
	  fcc_part15 = "%";
  }
  var cable_mfr = document.getElementById('cable_mfr').value;
  if (cable_mfr.length == 0) {
	  cable_mfr = "%";
  }
  var cable_modelno = document.getElementById('cable_modelno').value;
  if (cable_modelno.length == 0) {
	  cable_modelno = "%";
  }
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_gender=" + encodeURIComponent(conn_gender) + "&";
  var params = params + "conn_shape=" + encodeURIComponent(conn_shape) + "&";
  var params = params + "attach_by=" + encodeURIComponent(attach_by) + "&";
  var params = params + "fcc_part15=" + encodeURIComponent(fcc_part15) + "&";
  var params = params + "cable_mfr=" + encodeURIComponent(cable_mfr) + "&";
  var params = params + "cable_modelno=" + encodeURIComponent(cable_modelno) + "&";
  var params = params + "show_now=" + encodeURIComponent(show_now) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function getFiberConnectors(show_now_var) {
  var thePage = 'lookupfiberconnectors.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = document.getElementById('conn_type').value;
  var show_now = show_now_var || 'no';
  if (conn_type.length == 0) {
	  conn_type = "%";
  }
  var conn_interface = document.getElementById('conn_interface').value;
  if (conn_interface.length == 0) {
	  conn_interface = "%";
  }
  var ferrule_hole = document.getElementById('ferrule_hole').value;
  if (ferrule_hole.length == 0) {
	  ferrule_hole = "%";
  }
  var conn_mode = document.getElementById('conn_mode').value;
  if (conn_mode.length == 0) {
	  conn_mode = "%";
  }
  var jacket_size = document.getElementById('jacket_size').value;
  if (jacket_size.length == 0) {
	  jacket_size = "%";
  }
  var channels = document.getElementById('channels').value;
  if (channels.length == 0) {
	  channels = "%";
  }
  var mil_cots = document.getElementById('mil_cots').value;
  if (mil_cots.length == 0) {
	  mil_cots = "%";
  }
  var tunable = document.getElementById('tunable').value;
  if (tunable.length == 0) {
	  tunable = "%";
  }
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_interface=" + encodeURIComponent(conn_interface) + "&";
  var params = params + "ferrule_hole=" + encodeURIComponent(ferrule_hole) + "&";
  var params = params + "conn_mode=" + encodeURIComponent(conn_mode) + "&";
  var params = params + "jacket_size=" + encodeURIComponent(jacket_size) + "&";
  var params = params + "channels=" + encodeURIComponent(channels) + "&";
  var params = params + "mil_cots=" + encodeURIComponent(mil_cots) + "&";
  var params = params + "tunable=" + encodeURIComponent(tunable) + "&";
  var params = params + "show_now=" + encodeURIComponent(show_now) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function getFiberBuildaCable(show_now_var) {
  var thePage = 'lookupfiberbuildacable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = document.getElementById('conn_type').value;
  var show_now = show_now_var || 'no';
  if (conn_type.length == 0) {
	  conn_type = "%";
  }
  var conn_interface = document.getElementById('conn_interface').value;
  if (conn_interface.length == 0) {
	  conn_interface = "%";
  }
  var ferrule_hole = document.getElementById('ferrule_hole').value;
  if (ferrule_hole.length == 0) {
	  ferrule_hole = "%";
  }
  var conn_mode = document.getElementById('conn_mode').value;
  if (conn_mode.length == 0) {
	  conn_mode = "%";
  }
  var jacket_size = document.getElementById('jacket_size').value;
  if (jacket_size.length == 0) {
	  jacket_size = "%";
  }
  var channels = document.getElementById('channels').value;
  if (channels.length == 0) {
	  channels = "%";
  }
  var mil_cots = document.getElementById('mil_cots').value;
  if (mil_cots.length == 0) {
	  mil_cots = "%";
  }
  var tunable = document.getElementById('tunable').value;
  if (tunable.length == 0) {
	  tunable = "%";
  }
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_interface=" + encodeURIComponent(conn_interface) + "&";
  var params = params + "ferrule_hole=" + encodeURIComponent(ferrule_hole) + "&";
  var params = params + "conn_mode=" + encodeURIComponent(conn_mode) + "&";
  var params = params + "jacket_size=" + encodeURIComponent(jacket_size) + "&";
  var params = params + "channels=" + encodeURIComponent(channels) + "&";
  var params = params + "mil_cots=" + encodeURIComponent(mil_cots) + "&";
  var params = params + "tunable=" + encodeURIComponent(tunable) + "&";
  var params = params + "show_now=" + encodeURIComponent(show_now) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function getBuildaCable(show_now_var) {
  var thePage = 'lookupbuildacable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = document.getElementById('conn_type').value;
  var show_now = show_now_var || 'no';
  if (conn_type.length == 0) {
	  conn_type = "%";
  }
  var conn_gender = document.getElementById('conn_gender').value;
  if (conn_gender.length == 0) {
	  conn_gender = "%";
  }
  var conn_shape = document.getElementById('conn_shape').value;
  if (conn_shape.length == 0) {
	  conn_shape = "%";
  }
  var attach_by = document.getElementById('attach_by').value;
  if (attach_by.length == 0) {
	  attach_by = "%";
  }
  var fcc_part15 = document.getElementById('fcc_part15').value;
  if (fcc_part15.length == 0) {
	  fcc_part15 = "%";
  }
  var cable_mfr = document.getElementById('cable_mfr').value;
  if (cable_mfr.length == 0) {
	  cable_mfr = "%";
  }
  var cable_modelno = document.getElementById('cable_modelno').value;
  if (cable_modelno.length == 0) {
	  cable_modelno = "%";
  }
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_gender=" + encodeURIComponent(conn_gender) + "&";
  var params = params + "conn_shape=" + encodeURIComponent(conn_shape) + "&";
  var params = params + "attach_by=" + encodeURIComponent(attach_by) + "&";
  var params = params + "fcc_part15=" + encodeURIComponent(fcc_part15) + "&";
  var params = params + "cable_mfr=" + encodeURIComponent(cable_mfr) + "&";
  var params = params + "cable_modelno=" + encodeURIComponent(cable_modelno) + "&";
  var params = params + "show_now=" + encodeURIComponent(show_now) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadConnectors() {
  var thePage = 'lookupconnectors.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = "%";
  var conn_gender = "%";
  var conn_shape = "%";
  var attach_by = "%";
  var fcc_part15 = "%";
  var cable_mfr = "%";
  var cable_modelno = "%";
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_gender=" + encodeURIComponent(conn_gender) + "&";
  var params = params + "conn_shape=" + encodeURIComponent(conn_shape) + "&";
  var params = params + "attach_by=" + encodeURIComponent(attach_by) + "&";
  var params = params + "fcc_part15=" + encodeURIComponent(fcc_part15) + "&";
  var params = params + "cable_mfr=" + encodeURIComponent(cable_mfr) + "&";
  var params = params + "cable_modelno=" + encodeURIComponent(cable_modelno) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadRFComponents(param) {
  var thePage = 'lookuprfcomponents.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "param=" + encodeURIComponent(param) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadRFComponents2(show_now_var) {
  var thePage = 'lookuprfcomponents.php';
  var param = document.getElementById('param').value;
  var choice = document.getElementById('choice').value;
  var show_now = show_now_var || 'no';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "param=" + encodeURIComponent(param) + "&";
  var params = params + "choice=" + encodeURIComponent(choice) + "&";
  var params = params + "show_now=" + encodeURIComponent(show_now) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadFiberConnectors() {
  var thePage = 'lookupfiberconnectors.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = "%";
  var conn_interface = "%";
  var ferrule_hole = "%";
  var conn_mode = "%";
  var jacket_size = "%";
  var channels = "%";
  var mil_cots = "%";
  var tunable = "%";
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_interface=" + encodeURIComponent(conn_interface) + "&";
  var params = params + "ferrule_hole=" + encodeURIComponent(ferrule_hole) + "&";
  var params = params + "conn_mode=" + encodeURIComponent(conn_mode) + "&";
  var params = params + "jacket_size=" + encodeURIComponent(jacket_size) + "&";
  var params = params + "channels=" + encodeURIComponent(channels) + "&";
  var params = params + "mil_cots=" + encodeURIComponent(mil_cots) + "&";
  var params = params + "tunable=" + encodeURIComponent(tunable) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadBuildaCable() {
  var thePage = 'lookupbuildacable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = "%";
  var conn_gender = "%";
  var conn_shape = "%";
  var attach_by = "%";
  var fcc_part15 = "%";
  var cable_mfr = "%";
  var cable_modelno = "%";
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_gender=" + encodeURIComponent(conn_gender) + "&";
  var params = params + "conn_shape=" + encodeURIComponent(conn_shape) + "&";
  var params = params + "attach_by=" + encodeURIComponent(attach_by) + "&";
  var params = params + "fcc_part15=" + encodeURIComponent(fcc_part15) + "&";
  var params = params + "cable_mfr=" + encodeURIComponent(cable_mfr) + "&";
  var params = params + "cable_modelno=" + encodeURIComponent(cable_modelno) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function loadFiberBuildaCable() {
  var thePage = 'lookupfiberbuildacable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var conn_type = "%";
  var conn_interface = "%";
  var ferrule_hole = "%";
  var conn_mode = "%";
  var jacket_size = "%";
  var channels = "%";
  var mil_cots = "%";
  var tunable = "%";
  var params = "conn_type=" + encodeURIComponent(conn_type) + "&";
  var params = params + "conn_interface=" + encodeURIComponent(conn_interface) + "&";
  var params = params + "ferrule_hole=" + encodeURIComponent(ferrule_hole) + "&";
  var params = params + "conn_mode=" + encodeURIComponent(conn_mode) + "&";
  var params = params + "jacket_size=" + encodeURIComponent(jacket_size) + "&";
  var params = params + "channels=" + encodeURIComponent(channels) + "&";
  var params = params + "mil_cots=" + encodeURIComponent(mil_cots) + "&";
  var params = params + "tunable=" + encodeURIComponent(tunable) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse;
  myReq.send(null);
}

function theHTTPResponse() {
  if (myReq.readyState == 4) {
    if(myReq.status == 200) {
       var response = myReq.responseText;
	   document.getElementById('da_response').innerHTML = response;
    }
  } else {
    //document.getElementById('da_response').innerHTML = '<img src="pics/ajax-loader.gif"/>';
  }
}

function theHTTPResponse2() {
  if (myReq.readyState == 4) {
    if(myReq.status == 200) {
       var response = myReq.responseText;
	   document.getElementById('da_cart').innerHTML = response;
	   document.getElementById('da_cart2').innerHTML = response + '<br />';
    }
  } else {
    //document.getElementById('da_cart').innerHTML = 'Adding to RFQ...';
  }
}

function theHTTPResponse3() {
  if (myReq.readyState == 4) {
    if(myReq.status == 200) {
       window.location.reload();
    }
  } else {
    //document.getElementById('da_cart').innerHTML = 'Adding to RFQ...';
  }
}

function addtorfq(da_conn) {
  da_img = 'pic_' + da_conn;
  document.images[da_img].src = "pics/addedtorfq.png";
  var thePage = 'addtorfq.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "modelno=" + encodeURIComponent(da_conn) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse2;
  myReq.send(null);
}

function addtorfq2(da_conn,da_qty) {
  da_img = 'pic_' + da_conn;
  document.images[da_img].src = "pics/addedtorfq.png";
  var thePage = 'addtorfq2.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "modelno=" + encodeURIComponent(da_conn) + "&" + "qty=" + encodeURIComponent(da_qty) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse2;
  myReq.send(null);
}

function addtorfcable(da_conn,da_group) {
  da_img = 'pic_' + da_conn;
  document.images[da_img].src = "pics/addedtocable.png";
  var cable_mfr = document.getElementById('cable_mfr').value;
  var cable_modelno = document.getElementById('cable_modelno').value;
  var thePage = 'addtorfcable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "conn=" + encodeURIComponent(da_conn) + "&";
  var params = params + "cable_mfr=" + encodeURIComponent(cable_mfr) + "&";
  var params = params + "cable_modelno=" + encodeURIComponent(cable_modelno) + "&";
  var params = params + "cable_group=" + encodeURIComponent(da_group) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse3;
  myReq.send(null);
}

function addtofibercable(da_conn) {
  da_img = 'pic_' + da_conn;
  document.images[da_img].src = "pics/addedtocable.png";
  var conn_mode = document.getElementById('conn_mode').value;
  var jacket_size = document.getElementById('jacket_size').value;
  var thePage = 'addtofibercable.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "conn=" + encodeURIComponent(da_conn) + "&";
  var params = params + "conn_mode=" + encodeURIComponent(conn_mode) + "&";
  var params = params + "jacket_size=" + encodeURIComponent(jacket_size) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse3;
  myReq.send(null);
}

function loadCart() {
  var thePage = 'addtorfq.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var theURL = thePage + "?" + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse2;
  myReq.send(null);
}

function changeqty(conn,qty) {
	//alert (conn + ' ' + qty);
  var thePage = 'updateqty.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "conn=" + encodeURIComponent(conn) + "&";
  var params = params + "qty=" + encodeURIComponent(qty) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  if (!qty || qty=='0') {
  	myReq.onreadystatechange = theHTTPResponse3;
  }
  myReq.send(null);
}

function changeinfo(da_field,da_value) {
  var thePage = 'updateinfo.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "da_field=" + encodeURIComponent(da_field) + "&";
  var params = params + "da_value=" + encodeURIComponent(da_value) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.send(null);
}

function deleteconn(da_conn) {
  var thePage = 'deleteconn.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "da_conn=" + encodeURIComponent(da_conn) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse3;
  myReq.send(null);
}

function deleteitem(item) {
	dalen = item.length - 4;
	item = item.substring(0,dalen);
	document.getElementById(item).value=0;
	changeqty(item,0);
}

function deleterfcomponent(item) {
  var thePage = 'deleterfcomponent.php';
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "item=" + encodeURIComponent(item) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  myReq.open("GET", theURL, true);
  myReq.onreadystatechange = theHTTPResponse3;
  myReq.send(null);
}

function loadComponents(category) {
  if (category == 'RF'){
	  var thePage = 'rfcomponents.php';
  } else {
	  var thePage = 'compbrowse.php';
  }
  var myRand = parseInt(Math.random()*999999999999999);
  var params = "category=" + encodeURIComponent(category) + "&";
  var theURL = thePage + "?" + params + "rand=" + myRand;
  document.location.href = theURL;
}