function createCookie(name,value,days)
{
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function ride()
{//alert('Скоро на нашем сайте заработает опрос.');
	if(document.getElementById("int1").style.width != '800px')
	{
		$("#fulil").animate({width: "890px"}, 500 );
		$("#int1").animate({width: "800px"}, 500 );
		$("#int2").animate({width: "610px"}, 500 );
		$("#int1").animate({height: "1000px"}, 500 );
		$('#fullik').fadeIn();
	}
	else
	{
		$("#fulil").animate({width: "190px"}, 500 );
		$("#int1").animate({height: "0px"}, 500 );
		$("#int1").animate({width: "0px"}, 500 );
		$("#int2").animate({width: "0px"}, 500 );
		$('#fullik').fadeOut();
	}
}
function nal()
{
	$("#pay_pal").fadeIn();
}
function rt()
{
	$("#rostest").fadeIn();
}
function show_image()
{
	$("#full_image").fadeIn();
}
function show_acc_image(numb)
{
	$("#image_"+numb).fadeIn();
}
function hide_acc_image(numb)
{
	$("#image_"+numb).fadeOut();
}
function hide_image()
{
	$("#full_image").fadeOut();
}
function auth()
{
     $.ajax({
          url: "index.php",
          global: false,
          type: "POST",
          data: ({
              'log' : document.getElementById("log").value,
              'pwd' : document.getElementById("pwd").value,
              'auth' : "1"
          }),
          dataType: "html",
          async:false,
          success: function(msg){
            document.getElementById("tmp").innerHTML = '  <META HTTP-EQUIV="REFRESH" CONTENT="0.1; URL=index.php">';
          }
       }
    );
}
function quit()
{
    createCookie("log",0,1);
    createCookie("pwd",0,1);
    document.getElementByI("tmp").innerHTML = '<META HTTP-EQUIV="REFRESH" CONTENT="0.1; URL=index.php"';
}

function list_order()
{
    if(document.getElementById("city").value == "Другой город")
	{
		$("#metro").fadeOut();
		$("#index").fadeIn();
	}
	else if(document.getElementById("city").value == "Москва")
	{
		$("#index").fadeOut();
		$("#metro").fadeIn();
	}
    //document.getElementById('order').innerHTML = str;
}
function filter_list(ind)
{
	if(document.getElementById("filter_"+ind).style.display == "none")
	{
		$("#filter_"+ind).fadeIn();
	}
	else
	{
		$("#filter_"+ind).fadeOut();
	}
}
function quantity(id,price)
{
	var quan = document.getElementById('id_'+id).value;
	$.ajax({
          url: "index.php",
          global: false,
          type: "POST",
          data: ({
              'quan' : quan,
              'id' : id,
              'quantity' : "1"
          }),
          dataType: "html",
          async:false,
          success: function(msg){
          },
          complete: function(data){
				document.getElementById("price_"+id).innerHTML = quan*price;
				//document.getElementById("refresh").innerHTML = '<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=index.php">';
				location.href="index.php";
            }
       }
    );
}
function recount_pl(fp)
{
	$.ajax({
          url: "index.php",
          global: false,
          type: "POST",
          data: ({
              'pl_invoice' : 1,
              'fp' : fp,
          }),
          dataType: "html",
          async:false,
          success: function(msg){
          },
          complete: function(data){
				location.href="index.php";
            }
       }
    );
}
function del_pl(oi,fp)
{
	var sum = document.getElementById("del_cost").value;
	location.href = "index.php?oi="+oi+"&fp="+fp+"&pay=4&del_cost="+sum;
}
function enter()
{
	$.ajax({
          url: "ent.php",
          global: false,
          type: "POST",
          data: ({
              'mail' : document.getElementById("e_mail").value,
              'pass' : document.getElementById("e_pass").value,
              'ent' : "1"
          }),
          dataType: "html",
          async:false,
          success: function(msg){
          location.href="index.php?enter=1&comp=1";}
       }
    );
}
function next_image()
{
	if(document.getElementById("full_image").style.display != 'none')
	{
		$("#image_0").fadeIn();
	}
	else
	{
		for(var i=0;i<4;i++)
		{
			if(document.getElementById("image_"+i))
			{
				if(document.getElementById("image_"+i).style.display != 'none')
				{
					break;
				}
			}
		}
		$("#image_"+(i+1)).fadeIn();
	}
}
function book_list(ct)
{
	var wd = ct* 20;
	$("#prod").animate({height: wd+"px"}, 500 );
}
function open_help(ct)
{
	var wd = ct* 50;
	if(document.getElementById("help").style.height == wd+'px')
		$("#help").animate({height: "0px"}, 500 );
	else
		$("#help").animate({height: wd+"px"}, 500 );

}
// function check_p()
// {
	// var str = document.getElementById("phone").value;
	// if(!str)
	// {
		// document.getElementById("X").style.opacity = 1;
	// }
	// var re = /^[0-9\-]*$/;
	// if (re.test(str))
	// {
		// $("#X").animate({opacity: "0"}, 10 );
	// }
	// else
	// {
		// $("#X").animate({opacity: "1.0"}, 10 );
	// }

// }
function prev_image()
{
	if(document.getElementById("image_0").style.display != 'none')
	{
		$("#full_image").fadeIn();
	}
	else
	{
		for(var i=0;i<3;i++)
		{
			if(document.getElementById("image_"+i))
			{
				if(document.getElementById("image_"+i).style.display != 'none')
				{
					break;
				}
			}
		}
		$("#image_"+(i-1)).fadeIn();
	}
}
function exit()
{
	$.ajax({
          url: "ent.php",
          global: false,
          type: "POST",
          data: ({
              'ext' : "1"
          }),
          dataType: "html",
          async:false,
          success: function(msg){
          location.href="index.php?enter=1";}
       }
    );
}
function search()
{
	var str = document.getElementById("query").value;
	location.href="index.php?search=1&str="+str;
}
function show_chars(ind)
{
	if(document.getElementById('char_'+ind).style.display == "none")
	{
		document.getElementById('arrow_'+ind).innerHTML = '<img src="img/interface/arrow2.png" />';
		$('#char_'+ind).fadeIn();	
	}
	else
	{
		$('#char_'+ind).fadeOut();
		document.getElementById('arrow_'+ind).innerHTML = '<img src="img/interface/arrow.png" />';
	}
}
var star = 0;
function star_click(ind)
{
	for(var i=1;i<ind+1;i++)
	{
		document.getElementById('star'+i).innerHTML = '<img src="img/interface/star.png">';
	}
	for(var i=ind+1;i<6;i++)
	{
		document.getElementById('star'+i).innerHTML = '<img src="img/interface/star2.png">';
	}
	star = ind;
}
function publish_rating(ind)
{
	$.ajax({
          url: "ent.php",
          global: false,
          type: "POST",
          data: ({
              'rating' : star,
			  'product_id': ind
          }),
          dataType: "html",
          async:false,
          success: function(msg){$('#mark').fadeOut();
          alert('Спасибо, ваш голос учтён!');}
       }
    );
}
