function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

function parseSetDiv(response) {
	var aData = new Array();
	if(response.indexOf('||' != -1)) {
		aData = response.split('||');
		divid = trim(aData[0]);
		obj = getElement(divid);
		if(obj != null) {
			obj.innerHTML = aData[1];
		}
	}
}

function ajax(page, qstr, divid, async) {
	var http = createRequestObject();
	http.open('get', page + '?divid=' + divid + '&' + qstr, async);

	if(async) {
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				parseSetDiv(http.responseText);				
			}
		};
		http.send(null);
	} else {
		http.send(null);
		parseSetDiv(http.responseText);
	}
	return true;
}

function ajaxPOST(page, qstr, divid, aPostVars, async) {
	var http = createRequestObject();
	var postdata = aPostVars.join('&');
	http.open('POST', page + '?divid=' + divid + '&' + qstr, async);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postdata.length);
	http.setRequestHeader("Connection", "close");
	if(async) {
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				parseSetDiv(http.responseText);
			}
		};
		http.send(postdata);
	} else {
		http.send(postdata);
		parseSetDiv(http.responseText);
	}
	return true;
}



function customBannerSelectionChange(divid, prodgroup, category) {
	var aPostVars = new Array();
	aPostVars.push( "prod_group=" + encodeURIComponent(prodgroup) );
	aPostVars.push( "category=" + encodeURIComponent(category) );

	var oColor = getElement(divid + '-color');
	if(oColor != null) {
		aPostVars.push( divid + '-color=' + encodeURIComponent(oColor.value) );		
	}

	var oHeight = getElement(divid + '-banner_height');
	if(oHeight != null) {
		aPostVars.push( divid + '-banner_height=' + encodeURIComponent(oHeight.value) );		
	}

	var oWidth = getElement(divid + '-banner_width');
	if(oWidth != null) {
		aPostVars.push( divid + '-banner_width=' + encodeURIComponent(oWidth.value) );		
	}

	var oFinish = getElement(divid + '-banner_finish');
	if(oFinish != null) {
		aPostVars.push( divid + '-banner_finish=' + encodeURIComponent(oFinish.value) );		
	}
	
	ajaxPOST("ajax-custom-banner.php", "", divid, aPostVars, true);
}

