$('html').removeClass('no-js').addClass('javascript');  // javascript
$(document).mousemove(function(){$('html').addClass('usingMouse');
$(this).unbind("mousemove");}); // использование мышы

$(document).ready(function(){

	$('.count-next').click(function(){
		val = $('.range',$(this).parent()).val();
		$('.range',$(this).parent()).val(val*1+1);
	});
	
	$('.count-prev').click(function(){
		val = $('.range',$(this).parent()).val();
		if(val>1)
		$('.range',$(this).parent()).val(val*1-1);
	});

    $(".check-out tr:nth-child(even)").addClass("tr-bg");

    $('.images li a').click(function(){
		$('.images li a').removeClass('active');
		$(this).addClass('active');

		var id = $(this).attr('id');
		$('.image_preview li').hide();
		$('li#cont_'+id).fadeIn('fast');
	});
	
	$('#popup_close').click(function(){
		$('#popup').hide();
	});

	$('#popup_open').click(function(){
		$('#popup').show();
		$('#formBillig_error-block').hide();
		$('#formBillig').show();

        var p_height = $('.popup').height();
        var p_width = $('.popup').width();

        $('.p-block').css('margin-left', -p_width / 2);
        $('.p-block').css('margin-top', -p_height / 2);
	});
		
    $('#formBillig').ajaxForm({
    		beforeSubmit: validate, 
    		success: function(){     			
            	$('#popup').hide();             	
        	}
    });
    
	
	cmfBasket();
	setTimeout("cmfBasket();", 500);
	
});

function validate(formData, jqForm, options) 
{    
	var error = false;	
    for (var i=0; i < formData.length; i++) 
    { 
    	var item = formData[i].name;
        $('#'+item+'').removeClass();
        
        if (!formData[i].value) 
        {         	
        	$('#'+item+'').addClass('error-field');    
        	error = true;         
        } 
    }
    
    if(error)
    {
    	alert('Заполните обязательные поля'); 
        return false;
    }
    $('#formBillig_error-block').show();
    $('#formBillig').hide();
    
    return false;
}

function cmfGetCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function cmfSetCookie( name, value, expires, path, domain, secure )
{
	if (!path) path='/';
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
            
function cmfFormNoError(id) 
{
	$(id.previousSibling).html('');
	$(id.previousSibling).attr('class', 'errorDiv');
}

/* select */
function cmfSelectChildDelete(selectObj) {
	while (selectObj.childNodes.length) {
		if (selectObj.firstChild.tagName == 'optgroup') {
			while (selectObj.firstChild.childNodes.length)
				selectObj.firstChild.removeChild(selectObj.firstChild.firstChild);
		}
		selectObj.removeChild(selectObj.firstChild);
	}
}

function cmfSelectOption(parent, text, value, selected, selected2) {
	parent.options.add(new Option(text,value,selected,selected2));
	return parent.lastChild;
}

function cmfSelectOptgroup(parent, text, value, selected, selected2) {
	var opt1 = new Option(text,value,selected,selected2);
	parent.appendChild(opt1);
	opt1.text = text;
	opt1.value = value;
	return opt1;
}

function cmfDeleteChildTag(line, tag) 
{
	while(line.tagName.toUpperCase()!=tag)
		line = line.parentNode;
	line.parentNode.removeChild(line);
}

function cmfDeleteChildTag(line) 
{
	line.parentNode.removeChild(line);
}

function cmfGetChildTag(line, tag) 
{
	while(line.tagName.toUpperCase()!=tag)
		line = line.parentNode;
	return line;
}

function cmfRedirect(url) 
{
	document.location = url;
}

function cmfReload() 
{
	cmfRedirect(document.location);

}

function cmfAjaxLog(text) 
{
	$('#idAjaxLog').show().html('' + text + '');
}

function cmfAjaxSendForm(form, url) 
{
	return cmfAjaxSend(url, { form: form });
}

function cmfAjaxSend(url, value, func, cache) 
{    
	
	var req = new JsHttpRequest();     
    req.onreadystatechange = function() 
    {
        if (req.readyState == 4) 
        {      	
            cmfAjaxLog(req.responseText);

            if(func) 
            {
            	func(req);
            }
            
            if(req.responseJS && req.responseJS.js) 
            {
            	$.globalEval(req.responseJS.js);
            } 
        }              
    }

    req.open(null, url, true);
    req.send(value);
    return false;	
}







