function include(file){
	var script  = document.createElement('script');
	script.src  = 'js/' + file;
	script.type = 'text/javascript';
	document.getElementsByTagName('head').item(0).appendChild(script);
}
function open_hide(id){
	var nino = $("#"+id).css("display");
	if(nino == 'none'){
		$("#"+id).show();		
	}else{
		$("#"+id).hide();	
	}
}
jQuery(document).ready(function() {
	$("#catalog table.item").hover(
		function () {	
			$(this).removeClass("item");
			$(this).addClass("item_select");
		}, 
		function () {
			$(this).removeClass("item_select");
			$(this).addClass("item");
		}
	);
	$("#catalog table.item").click(
		function () {	
			var link = $(this).attr("rel");
			location.href = link;
		}
	);
    $('.js-tabs').delegate('li:not(.active)', 'click', function() {
        $(this).addClass('active').siblings().removeClass('active')
            .parents('.actions').find('.js-box ').hide().eq($(this).index()).show();
    });

    $(".js-consult-tab").click(function(){
        var par = $(this).closest(".consult");
        var w = par.width() == 240 ? 63 : 240;
		if(par.width() == 63){
			newWindow = window.open('http://tech.home.web2b.ru/consultant/client.php?locale=ru', 'consult', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1');
			newWindow.focus();
			newWindow.opener=window;
		}
        par.animate({"width": w});
    });

    $(".js-stars a").click(function(){
        var self = $(this);
        var parent = self.closest(".js-stars");
        var value = parseInt(self.text());
        $("input[rel='stars']", parent).val(value);
        var id = $("input[name='id']", parent).val();
        $(".star-rating", parent).removeClass("star-rating_1 star-rating_2 star-rating_3 star-rating_4 star-rating_5").addClass("star-rating_" + value);
		$(".star-rating__01,.star-rating__02,.star-rating__03,.star-rating__04,.star-rating__05", parent).remove();
		setCookie('ft'+id,value,0);
		$(parent).removeClass('js-stars');
        return Golos(id, value);
    });

    $(".gallery__item a").colorbox({rel:'group1', previous : "Предыдущее фото", next : "Следующее фото", close : "Закрыть" });
	$(".photos__item .photos__img a").colorbox({rel:'group2', previous : "Предыдущее фото", next : "Следующее фото", close : "Закрыть" });
});

function hasActive(id){
	var nino = $("#"+id).hasClass("active");
	if(nino)
		$("#"+id).removeClass("active");
	else
		$("#"+id).addClass("active");
}
function newWin(nameImg,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open("","",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition);
	win.document.write('<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table cellpadding=0 cellspacing=0 border=0><tr><td><img src="'+nameImg+'" style="cursor:hand;" onclick="window.close();" alt=""></td></tr></table></body></html>');
  	win.document.close();
}
function newWinHtml(urlHtml,width,height){
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
 	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	win=open(urlHtml,"",'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition);
}
function open_window(link,w,h) {
 LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 var win = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=no,location=no,scrollbars=yes,resizable=yes';
 newWin = window.open(link,'newWin'+w+h,win);
}
function openWindow(width,height,url,target){
	if(!target) target = 'my';
	var left = Math.round((screen.width-width)/2);
	var top = Math.round((screen.height-height)/2)-40;
	var win = window.open(url, target, 'resizable=yes,width='+width+',height='+height+',scrollbars=1,top='+top+',left='+left);
	win.focus();
}
function procSubscribe(frm, proc, w, h) {
	ofrm = document.getElementById(frm);
	window.open('', frm, 'width='+w+',height='+h);
	eval("ofrm.subscribe_type.value="+proc);
	ofrm.submit();
}
function procFocus(ob, txt) {
	if (ob.value == txt) {
		ob.value = '';
	}	
}
function procBlur(ob, txt) {
	if (ob.value == '') {
		ob.value = txt;
	}	
}

/* xajax */	
	
	try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
	xajax.config.requestURI = "/procajax.php";
	xajax.config.statusMessages = false;
	xajax.config.waitCursor = true;
	xajax.config.version = "xajax 0.5 rc1";
	xajax.config.legacy = false;
	xajax.config.defaultMode = "asynchronous";
	xajax.config.defaultMethod = "POST";
	
	xajax_Golos = function() {
		return xajax.request( { xjxfun: 'Golos' }, { parameters: arguments } );
	}
	xajax_showComm = function() {
		return xajax.request( { xjxfun: 'showComm' }, { parameters: arguments } );
	}
	xajax_newComm = function() {
		return xajax.request( { xjxfun: 'newComm' }, { parameters: arguments } );
	}
	xajax_sendThx = function() {
		return xajax.request( { xjxfun: 'sendThx' }, { parameters: arguments } );
	}
	xajax_sendQ = function() {
		return xajax.request( { xjxfun: 'sendQ' }, { parameters: arguments } );
	}
	function Golos(id,ocenka){
		xajax_Golos(id,ocenka);
		return false;
	}
	function showComm(id){
		xajax_showComm(id);
		return false;
	}
	function newComm(id){
		var comm = $('#newcomm').val();
		xajax_newComm(id,comm);
		return false;
	}
	function sendThx(){
		var fnm = $('#fnm').val();
		var numd = $('#numd').val();
		var text = $('#text').val();
		var code = $('#code').val();
		xajax_sendThx(fnm,numd,text,code);
		return false;
	}
	function sendQ(){
		var from = $('#from').val();
		var mail = $('#email').val();
		var phon = $('#phone').val();
		var body = $('#body').val();
		var code = $('#code').val();
		xajax_sendQ(from,mail,phon,body,code);
		return false;
	}
	
	function sendNewFoto(){
		var error = "";
		if($("#fio").val()=="")
			error += " - представьтесь;\n";
		if($("#name").val()=="")
			error += " - назовите Ваше фото как-нибудь;\n";
		if($("#isok").attr("checked")!="checked")
			error += " - необходимо Ваше согласие на размещение Вашего фото;\n";
		if($("#file").val()=="")
			error += " - выберите файл;\n";
		if(error != ''){
			error = "Найдены следующие ошибки:\n"+error;
			alert(error);
		}else{
			$("#formNew").submit();
		}
	}
	
/* end xajax */
function centerPopUp(){
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
		// IE 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
		// Остальные версии IE
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}

	var width = $(window).scrollLeft();
	var height = $(window).scrollTop();
	
	var halfX = x /2;
	var halfWidth = width / 2;
	var Wy = -300;
	var leftPad = halfX + Wy;

	var halfY = y /2;
	var halfHeight = height / 2;
	var Hy = 50;
	var topPad = halfY + Hy;

	$("#pop_up").css('top', topPad);
	$("#pop_up").css('left', leftPad);
}

function popUp() {
	centerPopUp();
	$.dimScreen(500, 0.7, function() {$('#pop_up').fadeIn('fast')});
}

var closePopupTimer;
var mdelay = 2000;

function closePopUpTime() {
	closePopupTimer = setTimeout('closePopUp()', mdelay);
}

function closePopUp() {
	clearTimeout(closePopupTimer);
	$('#pop_up').css('display', 'none');
	$.dimScreenStop();
	return false;
}

function checkForm(form) {
	// Заранее объявим необходимые переменные
	var el, // Сам элемент
	elName, // Имя элемента формы
	value, // Значение
	type; // Атрибут type для input-ов
	// Массив списка ошибок, по дефолту пустой
	var errorList = [];
	// Хэш с текстом ошибок (ключ - ID ошибки)
	var errorText = {
	1 : "Не заполнено поле 'Имя'",
	2 : "Не заполнено поле 'E-mail'",
	3 : "Не заполнено поле 'Телефон'",
	4 : "Неизвестная ошибка"
	}
	// Получаем семейство всех элементов формы
	// Проходимся по ним в цикле
	//form = document.getElementById(frm);
	for (var i = 0; i < form.elements.length; i++) {
	el = form.elements[i];
	elName = el.nodeName.toLowerCase();
	value = el.value;
	if (elName == "input") { // INPUT
	// Определяем тип input-а
	type = el.type.toLowerCase();
	// Разбираем все инпуты по типам и обрабатываем содержимое
	switch (type) {
	case "text" :
	if (el.title != "" && value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	break;
	case "file" :
	//if (value == "") errorList.push(3);
	break;
	case "checkbox" :
	// Ничего не делаем, хотя можем
	break;
	case "radio" :
	// Ничего не делаем, хотя можем
	break;
	default :
	// Сюда попадают input-ы, которые не требуют обработки
	// type = hidden, submit, button, image
	break;
	}
	} else if (el.title != "" && elName == "textarea") { // TEXTAREA
	if (value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	} else if (el.title != "" && elName == "select") { // SELECT
	if (value == 0) errorList.push("Не выбран элемент в поле '"+el.title+"'");
	} else {
	// Обнаружен неизвестный элемент ;)
	}
	}
	// Финальная стадия
	// Если массив ошибок пуст - возвращаем true
	if (!errorList.length) {
		return true;
	}
	// Если есть ошибки - формируем сообщение, выовдим alert
	// и возвращаем false
	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
	for (i = 0; i < errorList.length; i++) {
	errorMsg += errorList[i] + "\n";
	}
	alert(errorMsg);
	return false;
}
a = document.all;

bazedomen = 'tech.home.web2b.ru';
function getCookie(a){var b = document.cookie;a = a + "=";var c = b.indexOf("; " + a);if (c == -1) {c = b.indexOf(a);	if (c != 0) return "";} else c += 2;var d = document.cookie.indexOf(";", c);if (d == -1) d = b.length;return unescape(b.substring(c + a.length, d))}
function setCookie(a, b, c){if (c == null || c == 0) c = 365;var d = new Date;d.setTime((new Date).getTime() + c * 24 * 60 * 60 * 1E3);document.cookie = a + "=" + escape(b) + "; expires=" + d.toGMTString() + "; path=/" + (bazedomen ? "; domain=." + bazedomen : "");}
function delCookie(a){document.cookie = a + "=; expires=" + (new Date(0)).toGMTString()}

