// JavaScript Document

function ajax_put_into_basket(idprod, id) {	
	var variants_count = document.getElementById('order_variants_count_'+idprod).value;
	var varr = new Array();
	if(variants_count > 0) {
		for(var i=0; i<variants_count; i++) {
			var v = document.getElementById('order_varianat_'+idprod+'_'+i);
			var vnh = new Array(v.name, v.value);
			varr[i] = vnh;
		}
	}
	
	if (!ajaxpack.getAjaxRequest("/basket.php", "ajax_action=put_into_basket&id="+idprod+"&count="+document.getElementById(id).value+(varr.length > 0 ? '&variants='+varr : ''), put_into_basket, "text"))		
	{ 
		return false; 		
	} 
	return true; 
}

function put_into_basket() {
	var ajax=ajaxpack.ajaxobj;

	if (ajax.readyState == 4) { 
		if (ajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
				var html = ajax.responseText.toString().split(";");
				if(html > '') {
					document.getElementById('NAKUPNI_KOSIK_ITEM_COUNT').innerHTML = html[0];
					document.getElementById('NAKUPNI_KOSIK_ITEM_ALLPRICE').innerHTML = html[1];
					
					createBastketConfirm();
					
				}
		}
	}	
}

function BasketUpdateHTML(response) {
	var html = response.toString().split(";");
	if(html.length > 1) {
		document.getElementById('NAKUPNI_KOSIK_ITEM_COUNT').innerHTML = html[0];
		document.getElementById('NAKUPNI_KOSIK_ITEM_ALLPRICE').innerHTML = html[1];
				
		createBastketConfirm();				
	}
}
function BasketUpdateKs(response) {
	var vars = response.toString().split(";");
	if(vars.length > 1) {
		document.getElementById(vars[1]).value = vars[0];
		alert('zmena');	
	}
}
	
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        
        xMousePos = window.event.clientX+document.body.scrollLeft; // bylo zde x coz bylo k elementu primo
        yMousePos = window.event.clientY+document.body.scrollTop;  // bylo zde y coz bylo k elementu primo
        xMousePosMax = document.body.clientWidth+
                        document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+
                        document.body.scrollTop;
        //alert(xMousePos+', '+yMousePos+', '+xMousePosMax+', '+yMousePosMax);
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function createBastketConfirm() {	
	
	var basket_confirm_box = document.getElementById('basket_confirm_box');
	//alert(yMousePos+', '+xMousePos+', '+xMousePosMax);
	basket_confirm_box.style.top = yMousePos+'px';
	basket_confirm_box.style.left = (xMousePos-((xMousePosMax-1015)/2))+'px';
	basket_confirm_box.style.display = 'block';
	;
}

function registrace_check(chflag) {
	if(chflag) {
		document.getElementById('registrer_flag').checked = true;
		document.getElementById('pass').disabled = false;
		document.getElementById('pass2').disabled = false;
		document.getElementById('email_requied').style.visibility = 'visible';
	}
	else {
		document.getElementById('registrer_flag').checked = false;
		document.getElementById('pass').disabled = true;
		document.getElementById('pass2').disabled = true;	
		document.getElementById('email_requied').style.visibility = 'hidden';
	}
}
