function goTo (page) {

	if (page != "" ) {
		document.location.href = page;
	}
	return false;
}

function showprint( URL, Page ) {
	window.open( URL+'print.php?page='+Page,'printversion', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=700,left = 262,top = 134');
}

function showSzakertoi() {
	document.getElementById('szakertoi_div').style.display = 'block';
}

function changeShow( obj ) {

	for( var i=0; i<obj.childNodes.length; i++ ) {
		if ( obj.childNodes[i].currentStyle ) {
			style = obj.childNodes[i].currentStyle.display;
		} else {
			style = document.defaultView.getComputedStyle(obj.childNodes[0],null).getPropertyValue('display');
		}

		if ( style == 'block' ) {
			obj.childNodes[i].style.display = 'none';
		} else {
			obj.childNodes[i].style.display = 'block';
		}
	}

}

function changeLinkNews() {

	changeVisible('linknews_ul');

}

function setHeight( id ) {
alert(id);
if(id == ""){
}else{
	h = document.getElementById(id).offsetHeight;
	document.getElementById(id).style.height = h+'px';
}
}

function getWindowSize() {

	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
			_offsetY = window.pageYOffset;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.documentElement.clientHeight;
			_offsetY = document.documentElement.scrollTop;
		}
	}

	ret = Array( winW, winH, _offsetY );

	return ret;

}
function changeForumComment() {

	winSize = getWindowSize();
	winW = winSize[0];
	winH = winSize[1];
	_offsetY = winSize[2];

	cover = document.getElementById('bg_layer');
	cover.style.left = '0px';
	cover.style.top = _offsetY+'px';
	cover.style.height = winH;
	cover.style.width = winW;

	layer = document.getElementById('newCommentForm');
	layer.style.left = ( (winW/2) - 250 )+'px';
	layer.style.top = ( (winH/2) - 100 + _offsetY )+'px';

	changeVisible('newCommentFormCover');

}

function changeVisible(id_name) {

	obj = document.getElementById(id_name);

	if ( obj.currentStyle ) {
		style = obj.currentStyle.display;
	} else {
		style = document.defaultView.getComputedStyle(obj,null).getPropertyValue('display');
	}

	if ( style == 'block' ) {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
	}

}

var sentCommentTimer;

function hideSentComment() {
	clearInterval(sentCommentTimer);
	changeVisible('sentComment_cover');
}

function sentComment() {
	winSize = getWindowSize();
	winW = winSize[0];
	winH = winSize[1];
	_offsetY = winSize[2];

	cover = document.getElementById('bg_layer_sc');
	cover.style.left = '0px';
	cover.style.top = _offsetY+'px';
	cover.style.height = winH;
	cover.style.width = winW;

	layer = document.getElementById('sentComment');
	layer.style.left = ( (winW/2) - 250 )+'px';
	layer.style.top = ( (winH/2) - 100 + _offsetY )+'px';

	sentCommentTimer = setInterval( "hideSentComment()", 2000 );
}

function copyData( id ) {

	if ( confirm("Ugyanaz mint a számlázási adatai?") ) {
		$('#szamlaDiv').find('input').each( function() {
		
			$('[name="'+id+'_'+($(this).attr('name').replace('billing_', ''))+'"]').val($(this).val());
		});
		
		if($('#szemelyesadatok input[name="email"]').length == 0)
		{
			if($('#loggindiv input[name="checkemail"]').length == 0)
			{
				if($('#szamlaDiv input[name="ownemail"]').length == 0)
				{	
				}else
				{
					$('input[name="deliver_email"]').val($('#szamlaDiv input[name="ownemail"]').val());
				}
			}else
			{
				$('input[name="deliver_email"]').val($('#loggindiv input[name="checkemail"]').val());
			}
		}else
		{
			$('input[name="deliver_email"]').val($('#szemelyesadatok input[name="email"]').val());
		}
	}
}

function copyData2( id ) {

	if ( confirm("Ugyanaz mint a rendelő adatai?") ) {
		$('#szemelyesadatok').find('input').each( function() {
			$('[name="'+id+'_'+$(this).attr('name')+'"]').val($(this).val());
		});
	}
}

function addMainMessage(text, error) {
	classN = 'errorSucc'
	if (error) classN = 'errorMess';
	mmb = $('#messageBox');
	
    mmb.show();
	mmb.append('<div class="mainMessage '+classN+'">'+text+'<span class="close">[X]</span><span class="ltimg"></span><span class="rtimg"></span><span class="lbimg"></span><span class="rbimg"></span></div>');
	mmb.find('.mainMessage').show("slow");
	mmb.find('.close').click(function() {$(this).parent().hide("slow", function() {$('.iveskeret').remove();});})
	//mmb.find('.mainMessage').delay(2000).hide();

	
	
}


function priceBg(className, spanClass) {
	if (!className) return false;
	if (!spanClass) spanClass = className;
	$('.'+className).html(function() {
		return '<span class="'+spanClass+'l"></span><span class="'+spanClass+'c">'+$(this).html()+'</span><span class="'+spanClass+'r"></span>';
	});
}

function setErrorLogs(obj) {
	$('.comm').html('');
	if ( obj.rettype == 'error' ) {
		if (obj.params) {
			for( i in obj.params ) { $('[name="'+i+'"]').parent().next('.comm').html(obj.params[i]); }
		} else if (obj.message) {
			addMainMessage(obj.message, 1);
		}
	} else if ( obj.rettype == 'succ' ) {
		if (obj.page) { goTo(obj.page); }
		else if (obj.message) {
		$('#submitSpan').show('slow');
			addMainMessage(obj.message, 0);
		}
	}
}

function setLoginText(obj) {
	if (obj.type == 'loggdin') {
		if ( obj.text ) goTo(obj.text);
		else history.go(0);
	} else { alert(obj.text); }
}

function ajaxform(){
		$("form.addToCart, .formClass, form.addToFav, form.delfav").bind("submit", function(){
			retText = '&time='+ new Date().getTime();
			$.post(
				$(this)[0].action+retText,
				$(this).serialize(),
				function(responseText) {
					if ( responseText ) {
						resObj = eval(responseText);
						if (resObj.mod == 'cart') setCartText(resObj);
						if (resObj.mod == 'login') setLoginText(resObj);
						if (resObj.mod == 'fav') setFavText(resObj, resObj.html);
						//if ( $(".product_detailsDiv").length ) { getGroup(); }
					
					}
				}
			);

			return false;
	});
}

$(document).ready(function() {

	$(".iveskeret").html(function() {
		$(this).css('position', 'relative');
		return $(this).html()+'<span class="ltimg"></span><span class="rtimg"></span><span class="lbimg"></span><span class="rbimg"></span>';
	});
	
	ajaxform();
	
	priceBg('gomb');
	
	/*$("#sliderbox").easySlider({
		auto: false,
		continuous: true
	});*/
	
});	
