// JavaScript Document
/*function shuffle_array(ary) {
var s = []; while (ary.length) s.push(ary.splice(Math.random() * ary.length, 1)); while (s.length) ary.push(s.pop());
}
Array.prototype.shuffle_ = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
}
*/function fadeIn(element, opacity) {
	var reduceOpacityBy = 5;
	var rate = 30;	// 15 fps


	if (opacity < 100) {
		opacity += reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity < 100) {
		setTimeout(function () {
			fadeIn(element, opacity);
		}, rate);
	}
}
function el_create(id_name, DOM_type_of_element, place_to_view)
{
	if(!el_have(id_name)){
	var ele = document.createElement(DOM_type_of_element);
	ele.setAttribute("id", id_name);
	yyy = el(place_to_view);
	yyy.appendChild(ele);
	return true;
	}
	else
	{return false;}
}
function el_have(element)
{
	return document.getElementById(element) != null ? true : false;
}
function slice_by_space_(str, num)
{
	// var str = "";
	var  found  =  false;
	
	// alert(str.length);
	if(str.length > num)
	{
		for(i=num;i>0;i--)
		{
			if(str[i] == ' '){str = str.slice(0, i); found = true; break;}
		}			
		if(found != true || str.indexOf(' ') == -1)
		{
			if(str.length < num)
			{
				str = str.slice(0, str.length);
			}
				else
			{
				str = str.slice(0, num);
			}
		}
	}
  return str;
}
function slice_by_space(str, num)
	{
		for(i=num;i>0;i--)
		{
			if(str[i] == ' '){str = str.slice(0, i); found = true; break;}
		}
		if(found != true){str = str.slice(0, num);}
		
		return str;
	}
createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
function nop(){var i =i++;};

function hide_el(el) {document.getElementById(el).style.display='none';};

function show_el(el) {document.getElementById(el).style.display='block';};

function jq_hide_el(el) {$(el).css({display:"none"});};

function jq_show_el(el) {$(el).css({display:"block"});};
/////////////////////////////////////////////////////////////////////////////////////
function do_cookie(id_tov, count_)
{
	zapros = 'mode=cookie'+'&id_tov='+id_tov+'&count='+count_+'&str='+getCookie('cart');
	post_(zapros,'engine.php');
}
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
function setCookie3(name, value)
{
   /* Счетчик числа посещений и определение срока хранения в 1 год. */
   var expireDate = new Date();

   // Установка даты автоматического удаления.
   expireDate.setYear(expireDate.getYear() + 1);
   // Сохранение числа посещений.
   document.cookie = name+"="+escape(value)+ ";expires="+expireDate.toGMTString()+";"; 
}
function setCookie2 (name, value) {
        var argv = setCookie2.arguments;
        var argc = setCookie2.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}
function getCookie(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 msg_to_user(text_, hide_time, place_to_view)
{
	var div = document.createElement("div");
	div.setAttribute("id", "msg_span");
	div.setAttribute("style", "font-size: 14px; font-weight: bold; color: red; min-width: 200px; min-height: 40px; background: #D8E6FA; position:fixed; top:35%; left: 45%; border: 1px solid blue; padding:10px;");
	div.setAttribute("align", "center");
	yyy = el(place_to_view);
	yyy.appendChild(div);
	div.innerHTML=text_;
	$('#msg_span').hide();
	$('#msg_span').fadeIn();
	setTimeout('$("#msg_span").fadeOut();', hide_time);
	setTimeout('$("#msg_span").remove();', hide_time+200);		
}
String.prototype.stripTags = function() {
  return this.replace(/<\/?[^>]+>/g, '');
};
function slice_by_space(str, num)
{
	for(i=num;i>0;i--)
	{
		if(str[i] == ' '){str = str.slice(0, i); break;}
	}
  return str;
}
