//@FIXED
function ge(el) {
	return document.getElementById(el);
}
function top_nav(t) {

	titles = t.title;
	ge('top_nav').innerHTML = t.title;
	t.title = '';
	t.onmouseout = function() {
		ge('top_nav').innerHTML = '';
		t.title = titles;
	}

}
function img_chmurka(e, v, obrazek, wev, zev) {
	asd = 'asd';
	if (asd) {
		var t = document.createElement("div");
		t.className = "img_chmurka";
		t.style.cursor = "hand;"
			titl = asd;
		s = asd;
		t.innerHTML = '<div class="img_chmurka_top"></div><div class="img_chmurka_box"><table width="350" border="0"><tr><td colspan="2" ><strong>'
			+ wev
			+ '</strong></td></tr><tr><td><img src="'
			+ obrazek
			+ '" alt=""></td><td align="left" valign="top">'
			+ zev
			+ '</td></tr></table></div><div class="img_chmurka_bottom"></div>';
		asd = "";
		v.move = function(e) {
			t.style.cursor = "hand;"
				e = e || event;
			t.style.left = e.clientX + document.body.scrollLeft + -20 + "px";
			t.style.top = e.clientY + 25 + document.body.scrollTop + "px";
		}
		v.move(e);
		document.body.appendChild(t);
		v.onmousemove = function(e) {
			v.move(e);
		}
		v.onmouseout = function(e) {
			s = t.innerHTML;
			document.body.removeChild(t);
			asd = titl;
		}
	}
}

function getObject(name) {
	var ns4 = (document.layers) ? true : false;
	var w3c = (document.getElementById) ? true : false;
	var ie4 = (document.all) ? true : false;

	if (ns4)
		return eval('document.' + name);
	if (w3c)
		return document.getElementById(name);
	if (ie4)
		return eval('document.all.' + name);
	return false;
}

var req;
function loadXMLDoc(key, file, loc, tmp) {
	var url = file + "?" + key;
	if (tmp) {
		getObject(loc).innerHTML = '&nbsp;<img style="vertical-align:middle" src="images/loading.gif">Czekaj...';
	}
	try {
		req = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			req = null;
		}
	}
	if (!req && typeof XMLHttpRequest != "undefined") {
		req = new XMLHttpRequest();
	}
	if (req != null) {
		req.onreadystatechange = function() {
			if (req.readyState != 4)
				return;
			if (req.status == 200) {
				getObject(loc).innerHTML = req.responseText
			}
		};
		req.open("GET", url, true);
		req.send(null);
	}
}
//@FIXED
var reqPOST;
function loadXMLPOST(key, file, loc, tmp, parameters) {
	var url = file + "?" + key;
	if (tmp) {
		ge(loc).innerHTML = '&nbsp;<img style="vertical-align:middle" src="images/loading.gif">Czekaj...';
	}
	try {
		reqPOST = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			reqPOST = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			reqPOST = null;
		}
	}
	if (!reqPOST && typeof XMLHttpRequest != "undefined") {
		reqPOST = new XMLHttpRequest();
		if (reqPOST.overrideMimeType) {
			reqPOST.overrideMimeType('text/html');// set type accordingly to
			// anticipated content type
		}
	}
	if (reqPOST != null) {
		reqPOST.onreadystatechange = function() {
			if (reqPOST.readyState != 4)
				return;
			if (reqPOST.status == 200) {
				ge(loc).innerHTML = reqPOST.responseText;
				update();// @FIXED
			}
		};
		reqPOST.open("POST", url, true);
		reqPOST.setRequestHeader("Content-type",
		"application/x-www-form-urlencoded");
		reqPOST.setRequestHeader("Content-length", parameters.length);
		reqPOST.setRequestHeader("Connection", "close");
		reqPOST.send(parameters);
	}
}
//@FIXED
function highlight(prefix, arr, callback) {
	for (var i = 0; i < arr.length; i++) {  		
		callback(ge(prefix + arr[i]));
	}
}
//@FIXED
function change_form(_selected) {
	for(i in _selected){
		change_selected(ge(i).options, _selected[i]);
	}
}

//@FIXED
function change_selected(my_option, value) {
	for (var index = 0; index < my_option.length; index++) {
		if (my_option[index].value == value) {			
			my_option[index].setAttribute('selected', 'selected');
			my_option.selectedIndex = index;			
			return;
		}
	}
}

//@FIXED
function syncTotals() {
	ge('top_count_items_id').innerHTML = ge('bottom_count_items_id').innerHTML;
	ge('top_total_id').innerHTML = ge('bottom_total_id').innerHTML;
}
//@FIXED
function update() {
	// if(window.location.href.indexOf("shopping_cart.php") > 0){
	// zmiana value przycisku
	ge("confirm_updates_id").setAttribute("value", "Usuń");

	// pokaz plusy i minusy przy liczbie towarów
	var imgs = ge("shop_cart_quantity_id").getElementsByTagName("img");
	for (var i = 0; i < imgs.length; i++) {
		if (imgs[i].className == "images_PM") {
			imgs[i].style.display = "inline";
		}
	}

	// aktualne wartosci
	syncTotals();
}


/**
 * Przełącza element którego id został podany na widoczny/niewidoczny
 * @param szDivID
 * @return
 */
function toggleBox(szDivID) 
{
	if (document.layers) { // NN4+
		if (document.layers[szDivID].visibility == 'visible') {
			document.layers[szDivID].visibility = "hide";
			document.layers[szDivID].display = "none";
			document.layers[szDivID+"SD"].fontWeight = "normal";
		} else {
			document.layers[szDivID].visibility = "show";
			document.layers[szDivID].display = null;
			document.layers[szDivID+"SD"].fontWeight = "bold";
		}
	} else if (document.getElementById) { // gecko(NN6) + IE 5+
		var obj = document.getElementById(szDivID);
		var objSD = document.getElementById(szDivID+"SD");

		if (obj.style.visibility == 'visible') {
			obj.style.visibility = "hidden";
			obj.style.display = "none";
			objSD.style.fontWeight = "normal";
		} else {
			obj.style.visibility = "visible";
			obj.style.display = null;
			objSD.style.fontWeight = "bold";
		}
	} else if (document.all) { // IE 4
		if (document.all[szDivID].style.visibility == 'visible') {
			document.all[szDivID].style.visibility = "hidden";
			document.all[szDivID].style.display = "none";
			document.all[szDivID+"SD"].style.fontWeight = "normal";
		} else {
			document.all[szDivID].style.visibility = "visible";
			document.all[szDivID].style.display = null;
			document.all[szDivID+"SD"].style.fontWeight = "bold";
		}
	}
}

/**
 * Pokazanie elementu o danym id
 * @param szDivID
 * @return
 */
function show(szDivID)
{
	if (document.layers) // NN4+
	{
		document.layers[szDivID].visibility = "show";
		document.layers[szDivID].display = "block";//"table-row";
	} 
	else if (document.getElementById) // gecko(NN6), IE 5+, opera
	{
		var obj = document.getElementById(szDivID);

		obj.style.visibility = "visible";
		obj.style.display = "block";//"table-row";
	} 
	else if (document.all) // IE 4, IE 6
	{
		document.all[szDivID].style.visibility = "visible";
		document.all[szDivID].style.display = "block";
	}
}

/**
 * Ukrycie elementu o danym id
 * @param szDivID
 * @return
 */
function hide(szDivID)
{
	if (document.layers) // NN4+
	{
		document.layers[szDivID].visibility = "hide";
		document.layers[szDivID].display = "none";
	} 
	else if (document.getElementById) // gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(szDivID);

		obj.style.visibility = "hidden";
		obj.style.display = "none";
	} 
	else if (document.all) // IE 4
	{
		document.all[szDivID].style.visibility = "hidden";
		document.all[szDivID].style.display = "none";
	}
}


