function openPopUp(id,itemid) {
		window.open("/contactmember.php?id="+id+"&itemid="+itemid, "contactmember", "height=430,width=500,scrollbars=1,resizable=1");
		return true;
}

function openPopUp2(id) {
	window.open("/sendtofriend.php?id="+id, "sendtofriend", "height=420,width=620,scrollbars=1,resizable=1");
	return true;
}

function openPopUpPicture(id) {
	window.open("/largerimage.php?id="+id, "BIG_PICTURE", "height=150,width=300,resizable=1");
	return true;
}

function openPopUpHelp(docURL, wndName, wndWidth, wndHeight) {
	var newWindow;
	newWindow = window.open('/help/'+docURL, wndName, "WIDTH="+wndWidth+", HEIGHT="+wndHeight+",  scrollbars, resizable, left=150, top=100");
	newWindow.focus();
}

function openPopupLarge(id,togowhr) {
	window.open("/largerimage2.php?id="+id+"&opnpc="+togowhr, "BIG_PICTURE2", "height=400,width=600,resizable=1,scrollbars=1");
	return true;
}

function ShowPopUp(id) {
	if (id) {
		window.open("/printitem.php?id="+id, "printwnd", "height=500,width=650,scrollbars=1,resizable=1");
		return true;
	}
	else {
		window.open("/register.php", "register", "height=400,width=500,scrollbars=1,resizable=1");
		return true;
	}
}

function SearchFormValidate(vFrm) {

	vFrm.q.value = trim(vFrm.q.value);

	if (!vFrm.q.value) {
		alert('Unesite ključne reči za pretragu.');
		vFrm.q.className += " bg_white";
		vFrm.q.focus();
		return;
	}
	vFrm.submit();
}

function SearchBgWhite(o) {
	o.className = "bg_white";
}

function openTourPopUp(docURL, wndName, wndWidth, wndHeight) {
	var newWindow;
	newWindow = window.open('/help/tour/'+docURL, wndName, "WIDTH="+wndWidth+", HEIGHT="+wndHeight+",  scrollbars, resizable, left=150, top=100");
	newWindow.focus();
}

function galPopUp(URL) {
	var newWindow = window.open(URL, "Galerija", "WIDTH=730, HEIGHT=550, scrollbars, resizable, left=150, top=100");
	newWindow.focus();
}

function submitRate() {
	if (document.rateFrm.selectedIndex<1)
		return;

	document.rateFrm.submit();
}

function sortList(from,orderby,param_list) {
	location.href = location.href.replace(/\?(.*)$/, '')+'?from=0'+''+'&qorderby='+orderby; 
}

function mlOpenPopUp()
{
	window.open("/mailinglist.php?action=pre_add&id_cat="+document.getElementById('id_cat').value+"&id_sub_cat="+document.getElementById('id_sub_cat').value,"AddMailingListPopUp","width=520, height=370, scrollbars");
}

function mlOpenPopUpDelete()
{
	var actionValue = document.mlistform.akcija.value;
	window.open("/mailinglist.php?action=" + actionValue,"RemoveMailingListPopUp","width=650, height=450, scrollbars");
}


function trim(str){
	return str.replace(/^\s+|\s+$/g, "");
}


$(document).ready(function () {

	if ($('#mailinglist_submit').size()) {

		$('#mailinglist_submit').bind("click", function() {

			if ($("#mailinglist_email").val() != '') {
				var get_data = "action=add&id_cat="+escape($("#id_cat").val())+"&id_sub_cat="+escape($("#id_sub_cat").val())+"&email="+escape($("#mailinglist_email").val());

				$.ajax({
					type: "GET",
					url: "/ajax/mailinglist.php",
					data: get_data,
					success: function(msg) {
						if (msg.search("Hvala") != -1) {
							$("#maillist_input_holder").remove();
							$(".maillist").append("<p>"+msg+"</p>");
						}
						else {
							alert(msg);
							$("#mailinglist_email").focus();
						}
					}
				});
			}
			else {
				alert("Unesite email adresu!");
			}


			return false;
		});

		$('#mailinglist_email').bind("focus", function() {
			if ($(this).val() == "Unesi svoj email") {
				$(this).val("");
			}
		});
	}
});
