// JavaScript Document
//JQUERY
$(document).ready(function(){
	xOffset = 10;
	yOffset = 20;
	$(".tooltip").hover(
		function(e){
			this.t = this.title;
			this.title = "";									  
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");		
		},
		function(){
			this.title = this.t;		
			$("#tooltip").remove();
	});	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	$(".view_offer").hide();
	$(".open_offer").toggle(
		function () {
			$(this).next(".view_offer").show('blind');
		},
		function () {
			$(this).next(".view_offer").hide('blind');
		}
	);
	$(".shop").hide();
	$(".shop_a").toggle(
		function () {
			$(".shop").show('blind');
		},
		function () {
			$(".shop").hide('blind');
		}
	);
	$(".zayv").hide();
	$(".zayv_a").toggle(
		function () {
			$(this).next(".zayv").show('blind');
		},
		function () {
			$(this).next(".zayv").hide('blind');
		}
	);
	$("#edit_companent").hide();
});
	
	
//FUNCTION
	function openDiv(id){if(document.getElementById(id).style.display=="none"){document.getElementById(id).style.display = "";
	}else{document.getElementById(id).style.display = "none";}}
	function del(id){
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
		summ();
	}
	function summ(){
		var sum=count=0;
		
		summa_mas=$(".many_of");
		count_mas=$(".count_of");
		summa_count=summa_mas.length;
		for(i=0;i<=summa_count;i++){
			if(summa_mas[i]){
				sum+=parseInt(summa_mas[i].innerHTML);
				count+=parseInt(count_mas[i].innerHTML);
			}
		}
		document.getElementById('count').innerHTML=count;
		document.getElementById('summa').innerHTML=sum;
	}
	function close_companent(){$('#edit_companent').hide('blind');document.getElementById('edit_companent').innerHTML='<div align="center"><img src="/template/images/load.gif"></div>';ID_POLE = 0;}
//AJAX
var AJAX_PATCH = '/lib/ajax.php';
var ID_POLE = 0;
function edit_new_companent(type,pid,id){
	if(!pid)pid=0;
	if(!id)id=0;
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=edit_new_companent&id="+id+"&pid="+pid+"&type="+type,
		success: function(msg){
			document.getElementById('edit_companent').innerHTML=msg;
		}
	});
}
function appaneds(type,id,count){
	count_price=$("#price_offer tr");
	len=count_price.length-2;
	gid=0;
	if(type=='new'){
		num_mas=$(".id_pole");
		num_count=num_mas.length;
		for(i=0;i<=num_count;i++){
			if(num_mas[i])gid=parseInt(num_mas[i].innerHTML);
		}
		gid+=1;
		$("#price_offer").append('<tr id="component_'+gid+'"></tr>');
		tr_id=gid;
	}else tr_id=ID_POLE;
	close_companent();
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=view_tovars&id="+id+"&count="+count+"&tr_id="+tr_id,
		success: function(msg){
			document.getElementById('component_'+tr_id).innerHTML=msg;
			summ();
		}
	});
	
	
}
function zayv_tovar(id,mail){
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=zayv_tovar&id="+id+"&mail="+mail,
		success: function(msg){
			document.getElementById('edit_companent').innerHTML=msg;
		}
	});
}
function del_shop(id){
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=del_shop&id="+id,
		success: function(msg){
			div="order_shop_"+id;
			document.getElementById(div).parentNode.removeChild(document.getElementById(div));
		}
	});
}
function summa_info(){
	var s = new Array();
	var el=document.getElementsByName('liste[]');
    for(i = 0; i < el.length; i++) {
        s[i] = el[i].value;
	}
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=summa_info&list="+s,
		success: function(msg){
			document.getElementById('itog_many').innerHTML=msg;
		}
	});
}


/*
function plus_val(id,type){
	val=document.getElementById(type+'_'+id).value;
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=plus_val&id="+id+"&type="+type+"&val="+val,
		success: function(msg){
			document.getElementById(type+'_'+id).value=msg;
			document.getElementById('view_'+type+'_'+id).innerHTML=msg;
		}
	});
}
function product_view(id,obj){
	if(obj)pid=obj.options[obj.selectedIndex].value;
	else pid=0;
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=product_view&id="+id+"&pid="+pid,
		success: function(msg){
			document.getElementById('product_view_'+id).innerHTML=msg;
		}
	});
}
function product_view_f_id(id,num){
	$.ajax({
		type: "POST",
		cache: false,
		url: AJAX_PATCH,
		data: "function=product_view_f_id&id="+id+"&num="+num,
		success: function(msg){
			document.getElementById('product_view_'+id).innerHTML=msg;
		}
	});
}
*/