function voteCheck()
{
    g=document.getElementById('total').value;
    for (var i=1; i<=g; i++)
    {
        if(document.getElementById('choice'+i).checked)
        {
            return true;
        }
    }
    alert('Выберите вариант!');
    return false;
}
function authCheck()
{
    if(document.getElementById('a1').value!='')
    {
        if(document.getElementById('a2').value!='')
        {
            return true;
        }
        else
        {
            alert('Введите пароль!');
            return false;
        }
    }
    else
    {
        alert('Введите E-mail!');
        return false;
    }
}
var m = 0; 
function winOpen5(pic, width, height, title)
{
	m++;
	x = (640 - width)/2, y = (480 - height)/2;
	if (screen) {
		var y = (screen.availHeight - height)/2;
		var x = (screen.availWidth - width)/2;
	}
		if (screen.availWidth > 1800) {
		var x = ((screen.availWidth/2) - width)/2;
	}

	var win = window.open("", m, 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',titlebar=no,resizable=no,scrollbars=no');

	win.document.open();
	win.document.writeln('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"><title>'+title+'</title></head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	win.document.writeln('<table align="center" width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>');
 	win.document.writeln('<a title="Закрыть окно" href="#" onclick="self.close()"><img src="/'+pic+'" width="'+width+'" height="'+height+'" border="0" alt="'+title+'"></a>');
	win.document.writeln('</td></tr></table></body></html>');
	win.document.close();
}

function add_cart(id)
{
	quantity = $('#add_'+id).val();
	$.post("/catalogue/cart/", {'id':id, 'action':'add', 'quantity':quantity}, 
	function(data){
		$("#added-"+id).show();
		$("#cart-link span").html(data);
	});
}

function remove_item(id)
{
	$.post("/catalogue/cart/", {'id':id, 'action':'delete'}, function(){$("#item-"+id).remove();});

}

function return_send_order()
{
	var err = 0;
	err = error_object('name', 'Введите ФИО', err);
	err = error_object('city', 'Введите город', err);
	err = error_object('phone', 'Введите телефон', err);
	err = error_object('company', 'Введите название компании', err);
	err = error_object('email', 'Введите электронную почту', err);
	if($('#email').val() != '')
	{
		if(($('#email').val()).match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/) && $('#email').val() != '')
		{
				$("#email").removeClass('error');
				$("#email").addClass('cust-input');
				$("#email").next('.error').eq(0).remove();
		}else
		{
			if($("#email").next(".error").length == 0)
			{	
				$("#email").addClass('error');
				$("#email").removeClass('cust-input');
				$("#email").after('<span class="error">Неверный Email</span>');
			}
			err++;	
		}
	}	
	if(err != 0)
	{
		return false;
	}else
	{
		return true;
	}
}

function error_object(id, text, err)
{
		if($("#"+id).val() == '')
		{
			if($("#"+id).next(".error").length == 0)
			{	
				$("#"+id).addClass('error');
				$("#"+id).removeClass('cust-input');
				$("#"+id).after('<span class="error">'+text+'</span>');
			}
			err++;	
		}else
		{
			$("#"+id).removeClass('error');
			$("#"+id).addClass('cust-input');
			$("#"+id).next('.error').eq(0).remove();		
		}	
	return err;
}

function subscribe()
{
	email = $('#subscribe').val();
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email))
	{
		$.post('/include/modules/subscribe.php', {'email':email}, function(){$("#status").html('<div class="send">Спасибо за подписку!</div>')});
	}
}

function reset_form()
{
	$('#form_search :text').val('');
	$('#form_search select').val('0');
	$('#form_search :checkbox').removeAttr('checked');
}