﻿// JScript File

function openPart(delunik, avd, context) {
	var url = 'Part.aspx?delunik=' + delunik + "&avd=" + avd + "&ctx=" + context;
	popupWin = window.open(url, '_blank', 'width=700,height=842,resizable=yes,scrollbars=yes');
	popupWin.focus();
}

function addToCart(wnd, delunik) {
	if (addToCartInner(wnd, delunik)) {
		wnd.window.close();
	}
}

function addToCartInner(wnd, delunik) {
	if (wnd.window.opener == undefined) {
		return false;
	}
	var txtDelunik = wnd.window.opener.document.getElementById('RightColumn1_ShoppingCartSmall1_txtDelunik');
	var btnAddToCart = wnd.window.opener.document.getElementById('RightColumn1_ShoppingCartSmall1_btnAddToCart');
	if (btnAddToCart != null) {
		txtDelunik.value = delunik;
		btnAddToCart.click();
		wnd.window.opener.focus();
		return true;
	} else {
		return addToCartInner(wnd.window.opener, delunik);
	}
	return false;
}

function openImage(url) {
	popupWin = window.open(url, 'ImageViewer', 'width=680,height=566,resizable=yes');
}

function openCabasImage(url) {
	popupWin = window.open(url, 'ImageViewer', 'width=680,height=566,resizable=yes');
}

function viewInfo(url) {
	popupWin = window.open(url, 'ViewInfo', 'width=800,height=566,resizable=yes,scrollbars=yes');
	return null;
}

function toggleObj(objId) {

	if (objId != "") {
		if (document.getElementById(objId).style.display != 'block') {
			document.getElementById(objId).style.display = 'block';
		} else {
			document.getElementById(objId).style.display = 'none';
		}
	}
}

function makeNumeric(str) {

	var num = (str.replace(",", ".") * 1);
	if (isNaN(num)) {
		return 0;
	}
	return num;
}

function formatNumeric(num) {

	var str = (num + "").replace(".", ",");
	if (str.indexOf(",") < 0)
		str += ",00";
	if (str.length > 6) {
		return str.substr(0, str.length - 6) + " " + str.substr(str.length - 6);
	} else {
		return str;
	}
}

