var CMS = {
    popwin : function (url,width,height)
	{
		if ( !width ) width = '800';
		if ( !height ) height = '540';

	    var popupWin = window.open(url,'popupWin','width='+width+'px,height='+height+'px,left=100,top=100,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=no,screenX=100,screenY=100,directories=no,location=no');

		popupWin.focus();
        return false;
	},

    printView : function ()
    {
        CMS.popwin('?print');
    }
};

var Contacts = {

    clearField : function (item, text)
    {
        if( $(item).val() == text)
		{
			$(item).attr('value', '');
		}
    },

    sendM : function (thisFom)
    {
        Contacts.actualForm = thisFom;

        $.post("/",
            'Func=contacts.sendMessage&'+$(thisFom).serialize(),
            function(data) {

                if (data.error)
                {
                    jQuery.each(data.items, function(i, val) {
                        $('#contact_'+i).val(val);
                    });
                }
                else
                {

                    Contacts.actualForm.reset();
                    alert(data.message);
                }
            },
		"json"
		);
    }
};

var BuyUp = {
	initInfos : function ()
	{
        $('div.info, div.error').hover(
			function () {
				$(this).addClass('show-info');
			}, 
			function () {
				$(this).removeClass('show-info');
			}
		);
	}
}

$(document).ready(function()
{
    BuyUp.initInfos();
});


var Products = {
    
    selectType : function(name)
    {
        css = $(name).attr('class');
        id = $(name).attr('id');
        
        if(id == css)
        {
            $('.'+css).addClass(id+'-act');
            $('#'+css+'_checkbox').attr('checked',   true);
        }
        else
        {
            $('#'+id).removeClass(id+'-act');
            $('#'+id+'_checkbox').attr('checked',   false);
        }
    },
    
    checkBox :function() {
    	
		$('label.checkbox').click (function()
		{
			if ( $('#' + $(this).attr('for')).attr('checked') )
				{
					$('#'+$(this).attr('for')).attr('checked',false);
					$(this).removeClass('checked');
				}
				else
				{
					$('#'+$(this).attr('for')).attr('checked',true);
					$(this).addClass('checked');
				}		
			
			return false;
			
		});
		
	},
	
	selectModel : function(brand) {
		$.post("/",
            'Func=products.default.getModel&brand='+brand,
            function(data) {
				$('#models').html(data.models);
			},
		"json"
		);
	},
	
}

$(document).ready(function()
{	
	if ($('label.checkbox')) {
		
		$.each($('label.checkbox'), function(key, val) {
			if ( $('#' + $(val).attr('for')).attr('checked') )
			{
				$(val).addClass('checked');
			}
		});
	}
    
    Products.checkBox();
	$("input.text100").number_format({precision: 0, decimal: '', thousands: ' '}); 
    
});

