var myWindow;
function openCenteredWindow(url, width, height) {
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height +
        ",scrollbars,status,resizable,left=" + left + ",top=" + top +
        "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}

function searchSubmit(obj)
{
	var choice = obj.filter.value;
	switch (choice) {
		case 'all':
			obj.type.value = '';
			break;
		case 'system':
			obj.type.value = 'system';
			break;
		case 'sku':
		case 'competitor_sku':
		case 'oem_sku':
		case 'product':
			obj.type.value = 'product';
			break;
	}
	document.search.submit();
	return false;
}

function clickSubmit(obj, serp, path, docId)
{
	obj = (obj) ? obj : ((window.event) ? event : null);
	if (obj) {
		var id = document.click.logid.value;
		var type = serp.substring(0, 1);
		var position = serp.substring(1);
		var baseHref = '';
		if (document.topSearchForm.baseUrl) {
			baseHref = document.topSearchForm.baseUrl.value;
		}
		baseHref = encodeURIComponent(baseHref);
		var url = 'upgrades/search/xt_click_through.php?logId='+id+'&path='+path+'&type='+type+'&position='+position+'&docId='+docId+'&baseUrl='+baseHref;
		if (navigator.appName == 'Microsoft Internet Explorer') {
			obj.pathname = url;
		} else {
			window.location = url;
		}
	}
	return true;
}

function navigate(selection)
{
	var url = selection.options[selection.selectedIndex].value;
	var base_url = '';
	if (document.redirect.use_base && document.redirect.use_base.value) {
		base_url = document.redirect.base_url.value;
	}
	if (url != '') {
		url = decodeURIComponent(url);
		url = base_url + url + '/';
		if (url) {
			location.href = url;
		}
	} else {
		return false;
	}
}

function forward(selection)
{
	var url = selection.options[selection.selectedIndex].value;
	var base_url = '/upgrades/';
	if (url != '') {
		url = decodeURIComponent(url);
		url = base_url + url + '/';
		if (url) {
			location.href = url;
		}
	} else {
		return false;
	}
}

function startSystemScan()
{
//	alert(document.systemscanner.agree.checked);
	if (!document.systemscanner.agree.checked) {
		alert('Please Accept the Terms and Conditions');
		document.systemscanner.agree.focus();
	} else {
		var WndPos = "";
		var x = 600;
		var y = 350;
		if (screen != null) {
			var Left = (screen.width  - x) / 2;
			var Top  = (screen.height - y) / 2;
			WndPos = ",ScreenY=" + Top + ",Top=" + Top + ",ScreenX=" + Left + ",Left=" + Left;
		}
		window.open("http://w4s.work4sure.com/e/runclient.w4s?c=" + "simpletech" + "&n=" + "0" + "&l=" + "en" + "&tmpl=" + "min", "w4sWizard", "toolbar=no,location=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width="+x+",height="+y+WndPos);
	}
	return false;
}

/**
 * BEGIN AJAX SECTION
 */
var http_request = false;
function makeRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
}

function alertContents() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        var xmldoc = http_request.responseXML;
        var root = xmldoc.getElementsByTagName('root').item(0);
        for (var i = 0; i < root.childNodes.length; i++) {
           var node = root.childNodes.item(i);
           var subNode = node.childNodes.item(0);
           var value = subNode.data;
           var txt = document.createTextNode(value);
           var j = i+1;
           var elem = document.getElementById("inventory"+j);
           while (elem.childNodes.length > 0) {
           		elem.removeChild(elem.firstChild);
           }
           elem.appendChild(txt);
        }
     } else {
        alert('There was a problem with the request.');
     }
  }
}
function loadInventory(parts) {
	var url = '/upgrades/inventory.php';
	var params = '?sku='+parts;
	makeRequest(url, params);
}
/**
 * END AJAX SECTION
 */
