var Contacts = {
	
	Errors : Array(),
	FieldStack : 0,
	
	clearField : function (item)
    {

        if($(item).val() == $(item).attr('title'))
		{
			$(item).attr('value', '');
		}
		
		
		if($(item).val() == $(item).attr('alt'))
		{
			$(item).val('');
		}
		
    },
	
    sendM : function (modul, formData)
    {
        $.post("/",
            'Func='+modul+'&'+$(formData).serialize(),
            function(response) {

                if (response.error)
                {
                    jQuery.each(response.data, function(i, val) 
                    {                       
                        $('#'+i).attr('alt', val);
						$('#'+i).val(val);
                        
                    	Contacts.Errors[i] = true;
                    });
                }
                else
                {
					$(formData).html(response.data);
                }
            },
		"json"
		);
    },

    sendInquiry : function (modul, formData)
    {
        $.post("/",
            'Func=contacts.inquiry.sendMessage&'+$(formData).serialize(),
            function(response) {

                if (response.error)
                {
                    jQuery.each(response.data, function(i, val) 
                    {                       
                        $('#'+i).attr('alt', val);
						$('#'+i).val(val);
                        
                    	Contacts.Errors[i] = true;
                    });
                }
                else
                {
					$(formData).html(response.data);
					window.location = '#';
                }
            },
		"json"
		);
    },

	increaseProductNum : function ()
	{
		Contacts.FieldStack++;
	},

	setupFormElements : function(num)
	{
		$('#inq-material'+num+'-egyeb').bind('change', function() {

			if ( $(this).attr('checked') == 'checked' )
			{
				$('#inq-material-desc'+num).show();
			}
		});
	
		$('#inq-build'+num+'-ker-beepitest').bind('change', function() {

			if ( $(this).attr('checked') == 'checked' )
			{
				$('#inq-build'+num+'-desc').show();
			}
		});
		
		$('#inq-build'+num+'-nem-ker-beepitest, #inq-build'+num+'-csak-kiszallitast-ker').change(function() {

			if ( $(this).attr('checked') == 'checked' )
			{
				$('#inq-build'+num+'-desc').hide();
			}
		});

		$('#inq-build'+num+'-egyeb').bind('change', function() {

			if ( $(this).attr('checked') == 'checked' )
			{
				$('#inq-build'+num+'-description').show();
			}
		});

		
	},

	newProduct : function()
	{
		Contacts.increaseProductNum();

        $.post("/",
            'Func=contacts.inquiry.getNewProduct&num='+Contacts.FieldStack,
            function(response) {

                $('tbody.item:last').after( response );
				Contacts.setupFormElements(Contacts.FieldStack);
            },
		"text"
		);		
	}
};

$(function() {

	$('.text220').focus(function() {
		
		var id = $(this).attr('id');
		
		if ( Contacts.Errors[id] == true )
		{
			$(this).val('');
			Contacts.Errors[id] = false;
		}
	});

});
