function maybe_send_form(form){
	if(!form) form=document.forms[0];
	var elements=form.elements;
	for(var i=0; i<elements.length; i++){
		var element=elements[i];
		var required=element.getAttribute("required");
		if(required){
			var title=element.getAttribute("title");
			var name=element.getAttribute("name");
			var value=element.value;
			var title_or_name=title?title:name;
			if(!value){
				alert("Пожалуйста, заполните поле \""+title_or_name+"\"");
				return;
			}
		}
	}
	form.submit();
}

function openPopup(url,w,h){
  win=open(url,
    "popup","toolbar=no,location=no,directories=no,"+
    "status=no,scrollbars=no,resizable=no,"+
    "copyhistory=no,left="+(window.screen.width-w)/2+",top="+
    (window.screen.height-h)/2+",width="+w+",height="+h);
  win.focus();
}
function popImage(imageURL, ttl, width, height){
	if(!width) width=100;
	if(!height) height=100;
	if(!ttl) ttl="...";
        var opt='scrollbars=no,width='+width+',height='+height+',left='+(window.screen.width-width)/2+',top='+(window.screen.height-height)/2+',status=yes';
        imgWin = window.open('','',opt);
        with (imgWin.document) {
                writeln('<html><head><title>'+ttl+'</title><style type="text/javascript">body {overflow: auto; margin: auto; margin:0; padding: 0;}</style>');
                writeln('<sc'+'ript type="text/javascript">');
                writeln('function resizePopup() {');
	                writeln('width = document.images[0].width + 10; ');
        	        writeln('height = document.images[0].height + 50; ');
                	writeln('window.resizeTo(width,height); ');
	                writeln('if (window.innerWidth) { window.innerWidth = width - 10; window.innerHeight = height - 30; }');
	                writeln('window.moveTo((window.screen.width-width)/2, (window.screen.height-height)/2);');
                writeln('}');
                writeln('</s' + 'cript>');
		writeln('</head><body bgcolor="#FFFFFF" onload="resizePopup();">')
                writeln('<img src="'+imageURL+'" alt="Закрыть" onclick="window.close();" border="0" style="position: absolute; left: 0px; top: 0px; cursor: pointer;"/></body></html>');
                close();
        }
}
function add2basket(good_id, amount){
	var requestUrl="/main/add2basket.json?id="+good_id+"&qty="+amount;
	var a = jQuery.ajax({
		url: requestUrl,
		type:'post',  
		success: function(msg){
			var response = msg;
			if(response>0){
				if(typeof(korzina_setCount) == "function"){
					korzina_setCount(response);
					alert("Товар добавлен в корзину!");
				}
			}
			else{
				if(typeof(korzina_setCount) == "function"){
					//alert("Ошибка добавления товара в корзину!");
					korzina_setCount(response);
				}
			}
		},
		error: function(){
			alert('Ошибка доступа!');
		}
	});
}

function PingSession(){
  var a = jQuery.get("/null.php");
}
//setInterval("PingSession()", 300000);