function cart_http_request(url) {
	if (window.XMLHttpRequest) {
		var xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				location.href= "/cart.xml" ;	
			}
		}
	}
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(null);
}

function hurt_cart_http_request(url) {
	if (window.XMLHttpRequest) {
		var xmlhttp = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				location.href= "/hurt/hurtcart.xml" ;	
			}
		}
	}
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send(null);
}


function hurt_add_to_cart(symbol) {
		// FF Safari Opera Konqueror
		var size=document.getElementById('rozmiar');
		var ilosc=document.getElementById('ilosc');
		var color=document.getElementById('color');

		if (!size) { size_v=''; } else { size_v=size.value; }
		//if (!size_v || size_v='undefined') { size_v='UNIWERSAL'; }
		if (!ilosc) { ilosc_v=1; } else { ilosc_v=ilosc.value; }
		if (!color) { color_v='-'; } else { color_v=color.value }

	hurt_cart_http_request("/hurt/hurtcart.xml?action=add&symbol="+symbol+"&quantity="+ilosc_v+"&size="+size_v+"&color="+color_v);

}



function add_to_cart(symbol) {
		// FF Safari Opera Konqueror
		var size=document.getElementById('rozmiar');
		var ilosc=document.getElementById('ilosc');
		var color=document.getElementById('color');

		if (!size) { size_v=''; } else { size_v=size.value; }
		//if (!size_v || size_v='undefined') { size_v='UNIWERSAL'; }
		if (!ilosc) { ilosc_v=1; } else { ilosc_v=ilosc.value; }
		if (!color) { color_v='-'; } else { color_v=color.value }

	cart_http_request("/cart.xml?action=add&symbol="+symbol+"&quantity="+ilosc_v+"&size="+size_v+"&color="+color_v);

}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function add_to_cart_extended() {
	symbol=getCheckedValue(document.subproducts.subsymbol);
	if (symbol.length > 0) {
		var size=document.getElementById(symbol+'_rozmiar');
		var ilosc=document.getElementById('ilosc');
		var color=document.getElementById(symbol+'_color');
		var reg=/\s+/;
		if (!size) { size_v=''; } else { size_v=size.innerHTML.replace(reg,""); }
		if (!ilosc) { ilosc_v=1; } else { ilosc_v=ilosc.value; }
		if (!color) { color_v='-'; } else { color_v=color.innerHTML.replace(reg,""); }

		cart_http_request("/cart.xml?action=add&symbol="+symbol+"&quantity="+ilosc_v+"&size="+size_v+"&color="+color_v+"&sub=1");
	} else {
		p=document.getElementById("p_table");
		if (p) {
			p.style.backgroundColor="#FF8C66";
		}	
	}

}


function hurt_add_to_cart_extended() {
	symbol=getCheckedValue(document.subproducts.subsymbol);
	if (symbol.length > 0) {
		var size=document.getElementById(symbol+'_rozmiar');
		var ilosc=document.getElementById('ilosc');
		var color=document.getElementById(symbol+'_color');
		var reg=/\s+/;
		if (!size) { size_v=''; } else { size_v=size.innerHTML.replace(reg,""); }
		if (!ilosc) { ilosc_v=1; } else { ilosc_v=ilosc.value; }
		if (!color) { color_v='-'; } else { color_v=color.innerHTML.replace(reg,""); }

		hurt_cart_http_request("/hurt/hurtcart.xml?action=add&symbol="+symbol+"&quantity="+ilosc_v+"&size="+size_v+"&color="+color_v+"&sub=1");
	} else {
		p=document.getElementById("p_table");
		if (p) {
			p.style.backgroundColor="#FF8C66";
		}	
	}

}


function add_to_cart_cat(symbol) {
		// FF Safari Opera Konqueror
		var size=document.getElementById('rozmiar_'+symbol);
		var ilosc=document.getElementById('ilosc_'+symbol);
		var color=document.getElementById('color_'+symbol);

		if (!size) { size_v=''; } else { size_v=size.value; }
		if (!ilosc) { ilosc_v=1; } else { ilosc_v=ilosc.value; }
		if (!color) { color_v='-'; } else { color_v=color.value }

	cart_http_request("/cart.xml?action=add&symbol="+symbol+"&quantity="+ilosc_v+"&size="+size_v+"&color="+color_v);

}


function select_color(color) {
	c=document.getElementById('c');
	d=document.getElementById('d');
	a=document.getElementById('color');
	if (color=='BIAŁY') { d.style.background='#ffffff'; }
	else if (color=='CZARNY') { d.style.background='#000000'; }
	else if (color=='CZERWONY') { d.style.background='red'; }
	else if (color=='NIEBIESKI') { d.style.background='blue'; }
	else if (color=='ZIELONY') { tyle.background='green';}
	a.value=color;
	c.style.display="";
}
