function switchDisplay(objId) {
	obj = document.getElementById(objId);
		if (obj.style.display=='block') {
			obj.style.display='none';
		} else {
		obj.style.display='block';
	}
	return false;
}

function openWindow(url) {
window.open(url,'obrazek','toolbar=0,status=0,location=0,scrollbars=0,width=600,height=600,resizable=0,top=50,left=50');
}

function getObj(id) {
	if (typeof id != "string") return id;
	else return document.getElementById(id);
}

function getMyClass(id) {
	obj = getObj(id);
	return obj.className;
}

function switchImg(obj) {
	subj = obj.parentNode;
	if (getMyClass(subj)=='switch close') {
		subj.className='switch open';
	} else subj.className='switch close';

	return false;
}

function confirmAction(req) {
	if (req) return confirm(req);
	else return true;
}

var DOM = (document.getElementById);

function testInput(obj) {
	objType = obj.type;
	switch (objType) {
		case 'checkbox':
		case 'radio': return obj.checked;
		default: return obj.value!='';
	}
}

function checkForm(msg, objArray) {
	var okStatus = true;
	for (i=0; i<objArray.length; i++) {
		if (typeof(objArray[i])=='string') {
			obj = getObj(objArray[i]);
			if (testInput(obj)) {
				obj.style.border='2px inset #ccc';
			} else {
				obj.style.border='2px solid #f00';
				okStatus = false;
			}
		} else {
			var localOkStatus = false;
			for (j=1; j<objArray[i].length; j++) {
				obj2 = getObj(objArray[i][j]);
				if (testInput(obj2)) {
					localOkStatus = true;
				}
			}
			if (localOkStatus) {
				getObj(objArray[i][0]).style.border = 'none';
			} else {
				getObj(objArray[i][0]).style.border = '2px solid #f00';
			}
			okStatus = (okStatus && localOkStatus);
		}
	}
	
	if (!okStatus) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function bookmarks(objId) {
	document.getElementById('podrobnyPopis').style.display = 'none';
	document.getElementById('parametryZbozi').style.display = 'none';
	document.getElementById('dalsiObrazky').style.display = 'none';
	document.getElementById('souboryKeStazeni').style.display = 'none';
	document.getElementById(objId).style.display = 'block';
	return false;
}

jQuery(document).ready(function() {
	jQuery('#jcarousel').jcarousel();
	jQuery('a.fancybox').fancybox({
		'scrolling': 'no',
		'onClosed': function() {
			jQuery('p.highlight').hide();
		}
	});
	jQuery('p.highlight').hide();
	jQuery('#zeptejteSeProdavace').bind('submit', function() {
		if (jQuery('#f1_jmeno').val().length < 1 || jQuery('#f1_prijmeni').val().length < 1 || jQuery('#f1_email').val().length < 1 || jQuery('#f1_dotaz').val().length < 1) {
			jQuery('p.highlight').show();
			return false;
		}
		jQuery.fancybox.showActivity();
		jQuery.ajax({
			type: 'POST',
			cache: false,
			url: '/dotaz.php',
			data: jQuery(this).serializeArray(),
			success: function(data) {
				jQuery.fancybox(data);
			}
		});
		return false;
	});
	jQuery('#doporucitProdukt').bind('submit', function() {
		if (jQuery('#f2_jmeno').val().length < 1 || jQuery('#f2_email').val().length < 1) {
			jQuery('p.highlight').show();
			return false;
		}
		jQuery.fancybox.showActivity();
		jQuery.ajax({
			type: 'POST',
			cache: false,
			url: '/poslat_odkaz.php',
			data: jQuery(this).serializeArray(),
			success: function(data) {
				jQuery.fancybox(data);
			}
		});
		return false;
	});
});

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function platbyUpdate() {
	var box = document.getElementById('platbyBox'); // box s vypisem plateb
	var stat1 = document.getElementById('uf_stat'); // stat v adrese
	var stat2 = document.getElementById('d_stat'); // stat v dodaci adrese
	var dodaci = document.getElementById('pouzit_doruc_ne'); // dodaci adresa ano/ne

	if (box) {
		var plabyA = new Array();
		plabyA = getElementsByClassName(box, 'tr', 'platbyItem'); // pole s jednotl. platbami

		if ((dodaci.checked && (stat1.value != 'Česká republika')) || (!dodaci.checked && (stat2.value != 'Česká republika'))) {
			plabyA[0].style.display = 'none';
			plabyA[1].style.display = 'table-row';
			plabyA[2].style.display = 'table-row';
			plabyA[3].style.display = 'none';
			plabyA[4].style.display = 'none';
			plabyA[5].style.display = 'none';
			plabyA[1].getElementsByTagName('input')[0].checked = true;
		} else {
			plabyA[0].style.display = 'table-row';
			plabyA[1].style.display = 'none';
			plabyA[2].style.display = 'none';
			plabyA[3].style.display = 'table-row';
			plabyA[4].style.display = 'table-row';
			plabyA[5].style.display = 'table-row';
			plabyA[0].getElementsByTagName('input')[0].checked = true;
		}

	}
}

