function popUP(url,width,height) {
	if(!width) { width = 600; }
	if(!height) { height = 400; }
	var posx = 200;
	var posy = 200;
	var w=window.open(url,'wind','left='+posx+',top='+posy+',width='+width+',height='+height+',status:no, help:no');
	return false;
}


/* Функция изменения значения переменной(ых до 2 штук) GET в адресной строке и переход по измененному адресу (с выключеным ЧПУ) */
function changeGetVal(searchKeyOne,newValueOne,searchKeyTwo,newValueTwo){
	var tmp = new Array();		// два вспомагательных
	var tmp2 = new Array();		// массива
	var param = new Array();
	var col_el_param = 0;		// количество ключей в адресной строке
	var col_el_show = 0;		// количество разделителей "&"
	var getRequest = "";				// результат (GET запрос с внесенными изменениями)

	var get = location.search;	// строка GET запроса
	
	if(get != '') {
		tmp = (get.substr(1)).split('&');// разделяем переменные
		for(var i=0; i < tmp.length; i++) {
			tmp2 = tmp[i].split('=');		// массив param будет содержать
			param[tmp2[0]] = tmp2[1];		// пары ключ(имя переменной)->значение
			col_el_param++;
		}
		
		for (var key in param) {
			if (key == searchKeyOne) {
				param[key] = newValueOne;
			}
			if (key == searchKeyTwo) {
				param[key] = newValueTwo;
			}
			getRequest += key + "=" + param[key];
			if ((col_el_param - col_el_show) != 1){
				getRequest += "&";
				}
			col_el_show++;
		}
		document.location.href = "http://" + location.host + location.pathname + "?"+getRequest;
	}
}

/* Функция изменения значения переменной(ых до 2 штук) GET в адресной строке и переход по измененному адресу (с включенным ЧПУ) */
function changeGetValFurl(searchKey,newValue,searchKeySecond,newValueSecond){
	var val_array = location.href.match(/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)/);	// массив с значениями GET запроса
	var new_link = "";
	if (searchKey == "num" && !searchKeySecond){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,newValue+"-"+val_array[2]+"-"+val_array[3]+"-"+val_array[4]);
	} else if (searchKey == "pages" && !searchKeySecond){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+newValue+"-"+val_array[3]+"-"+val_array[4]);
	} else if (searchKey == "sort" && !searchKeySecond){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+val_array[2]+"-"+newValue+"-"+val_array[4]);
	} else if (searchKey == "filter" && !searchKeySecond){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+val_array[2]+"-"+val_array[3]+"-"+newValue);
	} else if (searchKey == "num" && searchKeySecond == "pages"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,newValue+"-"+newValueSecond+"-"+val_array[3]+"-"+val_array[4]);
	} else if (searchKey == "num" && searchKeySecond == "sort"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,newValue+"-"+val_array[2]+"-"+newValueSecond+"-"+val_array[4]);
	} else if (searchKey == "num" && searchKeySecond == "filter"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,newValue+"-"+val_array[2]+"-"+val_array[3]+"-"+newValueSecond);
	} else if (searchKey == "pages" && searchKeySecond == "sort"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+newValue+"-"+newValueSecond+"-"+val_array[4]);
	} else if (searchKey == "pages" && searchKeySecond == "filter"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+newValue+"-"+val_array[3]+"-"+newValueSecond);
	} else if (searchKey == "sort" && searchKeySecond == "filter"){
		new_link = location.href.replace(/([0-9]+-[0-9]+-[0-9]+-[0-9]+)/,val_array[1]+"-"+val_array[2]+"-"+newValue+"-"+newValueSecond);
	}
	document.location.href = new_link;
}

//Отображение/скрытие описания товара
function showHideDescription(id){
	$("#"+id).slideToggle("slow");
}

//Отправка рейтинга товара
function sendRating(id,val){
	$.post("../index.php", {"add_rating_goods":"","div_id":id,"mark":val},function(data, textStatus){
		var result_msg = data.match(/<p\sclass='er'>(.+?)<\/p>/);
		if (textStatus == "success" && result_msg == null){
			$('body').append("<div id='message'>Ваш голос учтен!</div>");
			$("#message").fadeIn("slow");
			setTimeout("function(){$('#message').fadeOut('slow',function(){$('#message').remove();});}",1000);
			$("#"+id).fadeOut("slow");
		}
	});
}

//Всплывающее сообщение
function showAlertMessage(msg,timer){
	$('body').append("<div id='alert_message'><b class='mes1'></b><b class='mes2'></b><b class='mes3'></b><b class='mes4'></b><div id='mess_contentb'>"+ msg +"<div id='close_window' onclick='closeAlertMessage();'></div></div><b class='mes4'></b><b class='mes3'></b><b class='mes2'></b><b class='mes1'></b></div>");
	$("#alert_message").fadeIn("slow");
	if (timer){
		setTimeout("closeAlertMessage();",timer);
	}
}

//Закрываем "alert_message"
function closeAlertMessage(){
	$("#alert_message").fadeOut("slow",function(){$(this).remove();});
}


$(document).ready(function(){
	
	//конфиг fancybox
	$("a.smallmodal").fancybox({
		'hideOnContentClick': false,
		'speedIn'		:	400, 
		'speedOut'		:	400, 
		'overlayShow'	:	true,
		'centerOnScroll' : true,
		'scrolling' : 'auto',
		'hideOnOverlayClick' : false,
		'showCloseButton' : true,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade',
		'autoDimensions' : true
	});
	$("a.bigmodal").fancybox({
		'hideOnContentClick': false,
		'speedIn'		:	400, 
		'speedOut'		:	400, 
		'overlayShow'	:	true,
		'centerOnScroll' : true,
		'width' : 460,
		'height' : 350,
		'scrolling' : 'auto',
		'hideOnOverlayClick' : false,
		'showCloseButton' : true,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade',
		'autoDimensions' : false
	});
	
	//конфиг вкладок
	$("#tabs").tabs({cookie: { expires: 1, name: "startTab" }});
	

	//submenu
	$("div.active, a.active").parents("div.side_subcategory").css({display:"block"});
    
    
    $('a.modal_a').click(function(){
        var src_url = $(this).attr('href');
        var query= src_url.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1];
        var atext = $(this).text();
        $('.modal_window').children('div:first-child').html('<span>'+atext+'</span>');
        $('.modal_window').children('div:first-child').next('div').load('/includes/modal_page.php',{'page':popWidth},function(){
            
            $('.modal_window').css('display','block');

       }); 
       return false;
    });
    
    $('.close').click(function(){
        $('.modal_window').css('display','none');        
    });  
	
});


function changeLang(lang) {
    $.cookie('lang',lang, {expires: 1, path: '/'});
    location.reload();
} 


//изменение порядка сортировки
function change_sort(table,id,val) {
    $.post('/includes/jprocessing.php',{'change_sort':id,'table':table,'value':val},function(data){
        if(data.substr(0,16) == '<p class="erok">') {
            var hr = location.href;
            document.location.href = hr;
        } else {
            alert('Произошла ошибка!');
        }

    });
}
