var total = 0;
var totalPrice = 0;

function RotaiteShirt(obj) {
	if ( obj.parentNode.className == 'click' ) {
		obj.parentNode.className = '';
	} else {
		obj.parentNode.className = 'click';
	}
}
function IncreaseTshirt(size, id, d) {
	var obj = document.getElementById('qty_' + size + '_' + id);
	var qty = parseInt0(obj.value);
	if (!obj.oldValue) obj.oldValue = qty;
	qty += d;
	if (qty > max_count) {
		qty = max_count;
		ShowError( err_maximum_exceeded );
	}
	if (qty <= 0 ) {
		obj.value = 0;
		qty = 0;
	} else {
		obj.value = qty;
	}
	CountSubtotal(size, id, obj);
}

function ChangeTshirt(size, id, obj) {
	var qty = parseInt0(obj.value);
//	if (!obj.oldValue) obj.oldValue = qty;
	if ( qty <= 0) obj.value = '';
	CountSubtotal(size, id, obj);
}
function FocusTshirt(obj) {
	var qty = parseInt0(obj.value);
	if (!obj.oldValue) obj.oldValue = qty;
}




function CountSubtotal(size, id, obj) {
	var d = parseInt0(obj.value) - parseInt0(obj.oldValue)
	count[price[id]] = count[price[id]] + d;
	var subtotal = '';
	var isSecond = false;
	totalPrice = 0;
	total = 0;
	for (price1 in count) {
		if (count[price1] > 0) {
			if (isSecond) {
				subtotal += ' + ';
			}			subtotal += count[price1] + ' x $' + price1;
			totalPrice += count[price1] * price1;
			isSecond = true;
			total += count[price1];
		} else {
			count[price1] = 0;
		}
	}
	if (totalPrice > 0) {
		subtotal += ' = <span class="fc_white">$' + totalPrice + '</span>';
	}
	document.getElementById("span_subtotal").innerHTML = subtotal;
	obj.oldValue = obj.value;

	if (total > max_count) {
		ShowError( err_maximum_exceeded );
		isValid = false;
	} else {		isValid = true;
		ShowError( '' );
	}	CountTotal();
}
function SetDelivery() {
	var form = document.getElementById('tshits_form');
	var country_id;
	if (form['Country.id']) {
		country_id = form['Country.id'].value;
	} else {
		var i;
		for ( i = form.length-1; i>=0; i-- ) {
			if (form[i].name == 'Country.id') {
				country_id = form[i].value;
				break;
			}		}
	}	if (country_id > 0) {
		delivery_cost = dp[country_id];
	} else  {
		delivery_cost = 0;
	}
	var span = document.getElementById('deliverySum');
	span.innerHTML = "$" + delivery_cost;
	CountTotal();
}

function CountTotal() {
	var total = delivery_cost + totalPrice;
	var span = document.getElementById('totalSum');
	span.innerHTML = "$" + total;
}


function ShowError(msg) {
	var span = document.getElementById('err_subtotal');
	span.innerHTML = msg;
}


function ShowBalloon1(obj) {
	var pos = getCoords(obj);
	var top = (pos.y + 20)+ "px";
	var left = (pos.x - 50) + "px";
	if ( obj && ( confirm_bal.style.display != "block" || current_popup != confirm_bal || (top != current_popup.style.top || left != current_popup.style.left))) {
		confirm_bal.style.top = top;
		confirm_bal.style.left = left;
		current_popup = confirm_bal; 
		confirm_bal.style.display = "block";
	} else {
		confirm_bal.style.display = "none";
		current_popup = null; 
	}
	setTimeout("current_popup = null", 10);
}

function HilightLink(obj) {
//	obj.parentNode.childNodes.item(0).style = "background-position: 50% 0 !important";
//	obj.parentNode.childNodes.item(0).style.backgroundPosition = "50% 0 !important";
	obj.parentNode.firstChild.className = "hover";
	obj;
}
function DeHilightLink(obj) {
//	obj.parentNode.childNodes.item(0).style = "background-position: 50% -30px !important";
//	obj.parentNode.childNodes.item(0).style.backgroundPosition = "50% -30px !important";
	obj.parentNode.firstChild.className = "";
	obj;
}

function MouseWhell(ev) {
        var event = ev || window.event;
        var target = event.target || event.srcElement;
}

function AttachMouseWhell(obj) {

    if (obj.addEventListener) {
        /** DOMMouseScroll is for mozilla. */
        obj.addEventListener('mousewheel', MouseWhell, false);
        obj.addEventListener('DOMMouseScroll', MouseWhell, false);
    } else if (document.attachEvent) {
        /** IE/Opera. */
        obj.attachEvent('onmousewheel', MouseWhell);
    } else {
        obj.onmousewheel = MouseWhell;
    }
}

function CheckTshirtForm() {
	return true;
}
