function l_o_g_append(data){
	if(data){
		$('#order_elements').html(data);
	}
	$('#loader').css('visibility','hidden');
	$('#recycle_t > tr:nth-child(odd)').addClass("even");

}
function to_recycle_append(data){
if (confirm(data) ) {
	$('#loader').css('visibility','hidden');
	window.location.href = "/order/recycle";
} else {
	$('#loader').css('visibility','hidden');
	window.location.reload();
}
}

function refresh(data){
	window.location.reload(true);
}
function ok(data){
$('#loader').css('visibility','hidden');	
}

function ok2(data){
	$('#loader').css('visibility','hidden');
	alert(data);
	window.location.reload(true);
}
function ok3(data){

	$('#loader').css('visibility','hidden');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "sendMailTo", data:data
		}
	);
	alert('Ваш заказ принят');
	window.location.href = "/order/recycle/?end";
}
function order_start(){
	$('#loader').css('visibility','visible');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "l_o_g1"						
		},
		l_o_g_append
	);	
}

function search_step_0(){
	$('#loader').css('visibility','visible');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "search_step_0"						
		},
		l_o_g_append
	);
}

function Filled(value){		
if (value != "")
{
valid_chars = "1234567890";
str=value;
valid_string = true;
    for(i=0; i < str.length; i++ )
     {
       current_valid_char = false;
       for(j=0; j < valid_chars.length; j++)
         {
           if(str.charAt(i) == valid_chars.charAt(j))
             {
               current_valid_char = true;
             }
         }
       if(current_valid_char == false)
         {
          valid_string = false;
         }
     }
     return valid_string;
   }
else
{
    return false;
} 
}

function set_qnt(this_elm){
	var p = this_elm.parentNode.parentNode;
	
	var cost	  = $(p).find('#cost').html();
	var sale 	  = $(p).find('#sale').html();
	//sale = sale*1;
	var qnt 	  = $(this_elm).attr('value');
	//alert(qnt);
	var result    = $(p).find('#result');
	var summ_cost = $('#summ_cost');
	var summ_sale = $('#summ_sale');
	var itog_summ = $('#itog_summ');
	var scv = 0;
	var we =0; 
	var sl =0;
	var res =0;
	if(Filled(qnt)){
		res = (cost-sale)*qnt;
		//alert(cost-sale);
		result.html(res.toFixed(2));
		$('#recycle_t > tr').each(
							function(){
								scv = $(this).find('#cost').html();
								slt = $(this).find('#sale').html();
								this_cnt = $(this).find('#count').attr('value');
								we = we+scv*this_cnt;
								sl = sl+ slt*this_cnt;
							}	
		)
		summ_cost.html(we.toFixed(2));
		summ_sale.html(sl.toFixed(2));
		itog_summ.html(we.toFixed(2)- sl.toFixed(2));
	
	}
}
function compare_it_append(data){
	$('#compare_table').html(data);
	$('#compare_table > tr:nth-child(odd)').addClass("even");
	$('#f_fon').css('visibility','visible');
	$('#loader').css('visibility','hidden');
	
	$('#ex4').css('width','890px');
	$('#ex4').css('height','650px');
	
	var w_l2 = window.screen.availWidth/2-450;
	$('#ex4').css('left',w_l2);
	
	$('#ex4').css('visibility','visible');
	$('#ex4').css('margin-top',document.documentElement.scrollTop+'px');	
}

function get_discount_append(data){
	$('#compare_table').html(data);
	$('#compare_table > tr:nth-child(odd)').addClass("even");
	$('#f_fon').css('visibility','visible');
	$('#loader').css('visibility','hidden');
	
	$('#ex4').css('width','890px');
	$('#ex4').css('height','650px');
	
	var w_l2 = window.screen.availWidth/2-450;
	$('#ex4').css('left',w_l2);
	
	$('#ex4').css('visibility','visible');
	$('#ex4').css('margin-top',document.documentElement.scrollTop+'px');
}

function show_image_append(data){
	$('#compare_table').html(data);
	$('#compare_table > tr:nth-child(odd)').addClass("even");
	$('#f_fon').css('visibility','visible');
	$('#loader').css('visibility','hidden');
	
	$('#ex4').css('width','890px');
	$('#ex4').css('height','650px');
	
	var w_l2 = window.screen.availWidth/2-450;
	$('#ex4').css('left',w_l2);
	
	$('#ex4').css('visibility','visible');
	$('#ex4').css('margin-top',document.documentElement.scrollTop+'px');	
}



function search_items_append(data){
$('#oi_table').html(data);	
$('#loader').css('visibility','hidden');
}
function l_o_g2(group_id){
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "l_o_g2", group_id:group_id								
		},
		l_o_g_append
	);
}
function l_o_g3(group_id,subgroup_id){
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "l_o_g3", group_id:group_id, subgroup_id:subgroup_id								
		},
		l_o_g_append
	);
}
function l_o_i(group_id,subgroup_id,subgroup2_id,page){
	$('#loader').css('visibility','visible');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "l_o_i", group_id:group_id, subgroup_id:subgroup_id, subgroup2_id:subgroup2_id, page:page								
		},
		l_o_g_append
	);	
}

function load_item(articul){
	$('#loader').css('visibility','visible');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "load_item", articul:articul								
		},
		l_o_g_append
	);	
}
function to_recycle(articul){	
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "to_recycle", articul:articul								
		},
		to_recycle_append
	);	
}
function open_recycle(){
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "open_recycle"								
		},
		l_o_g_append
	);		
}
function unset_item(articul,this_elm){
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "unset_item", articul:articul								
		},
		refresh	
	);		
}
function go_prev(){
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "go_prev"								
		},
		refresh	
	);			
}
function recycle_step1_append(){
	$('#loader').css('visibility','visible');
var this_cnt = 0;
var ret = document.getElementById('order_form');
var transp = ret.transp;
          for ( var i = 0; i < transp.length; i++ ){
                if ( transp[i].checked === true ){
                	var return_value_transp = transp[i];
                }
          }

$('#recycle_t > tr').each(
							function(){
								this_cnt = $(this).find('#count').attr('value');
								this_articul = $(this).find('#count').attr('articul');

								$.post(															
									'/_templates/afunc.inc.php',
									{
										func: "add_count", this_cnt:this_cnt, this_articul:this_articul						
									},
									ok	
								);
							}	
		)
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "recycle_append_step1", transport:$(return_value_transp).attr('value')							
		},
		refresh	
	);

}

function recycle_step2_append(){
	$('#loader').css('visibility','visible');
var ret = document.getElementById('order_form');

var wish= $('#wish').attr('value');
var time_d = $('#time_d').attr('value');
var time_call = $('#time_call').attr('value');
var cost_func = $('#cost_func').attr('value');

var chet = ret.chet;
          for ( var i = 0; i < chet.length; i++ ){
                if ( chet[i].checked === true ){
                	var return_value_chet =chet[i];	
                }
          }

	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "recycle_append_step2", chet:$(return_value_chet).attr('value'), wish:wish, time_d:time_d, time_call:time_call, cost_func:cost_func 							
		},
		refresh	
	);

}
function recycle_step3_append(data){	
	$('#loader').css('visibility','visible');
$('#recycle_t > tr').each(
							function(){
								this_cnt = $(this).find('#count').attr('value');
								this_articul = $(this).find('#count').attr('articul');

								
								$.post(															
									'/_templates/afunc.inc.php',
									{
										func: "add_count", this_cnt:this_cnt, this_articul:this_articul						
									},
									ok	
								);
							}	
)

	ch_fio_ch    = $('#ch_fio_ch').attr('value');
	ch_mail_ch   = $('#ch_mail_ch').attr('value');
	ch_tel_ch    = $('#ch_tel_ch').attr('value');
	ch_city_ch   = $('#ch_city_ch').attr('value');
	ch_street_ch = $('#ch_street_ch').attr('value');
	ch_corp_ch   = $('#ch_corp_ch').attr('value');
	ch_kv_ch     = $('#ch_kv_ch').attr('value');
	
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "recycle_append_step3", ch_fio_ch:ch_fio_ch, ch_mail_ch:ch_mail_ch, ch_tel_ch:ch_tel_ch, ch_city_ch:ch_city_ch, ch_street_ch:ch_street_ch, ch_corp_ch:ch_corp_ch, ch_kv_ch:ch_kv_ch						
		},
		ok3
	);
}
function compare4(articul, toDo){
	$('#loader').css('visibility','visible');
	//
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "compare_it", articul:articul, toDo:toDo								
		},
		compare_it_append
	);	
	
}

function compare_it(articul, toDo, h1, w1){
//$.get("/_templates/afunc.inc.php?func=compare_it=&articul="+articul+"&toDo="+toDo+"&height="+h1+"&width="+w1, function(data){});
tb_show('Thickbox Title', "/_templates/afunc.inc.php?func=compare_it=&articul="+articul+"&toDo="+toDo+"&height="+h1+"&width="+w1, null);
}

function delete_compared(this_elm,articul){
$.get("/_templates/afunc.inc.php?func=unset_compared_item=&articul="+articul, function(data){});
}

function show_image(articul){
	$('#loader').css('visibility','visible');
	//
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "show_image", articul:articul								
		},
		show_image_append
	);	
	
}

function search_items(group_id,subgroup_id,subgroup2_id){
	$('#loader').css('visibility','visible');
	var p = document.getElementById('select_brand');
	var brand =p.options[p.selectedIndex].text;
	var cost_to = $('#cost_to').attr('value');
	var cost_do = $('#cost_do').attr('value');
	
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "search_items",			 group_id:group_id, 
			subgroup_id:subgroup_id, subgroup2_id:subgroup2_id,
			brand:brand, 			 cost_to:cost_to,
			cost_do:cost_do							
		},
		search_items_append
	);
}

function get_discount(articul){
	$('#loader').css('visibility','visible');
	//
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "get_discount", articul:articul								
		},
		get_discount_append
	);	
	
}

function show_comment(articul){
	$('#loader').css('visibility','visible');
	//
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "show_comment", articul:articul								
		},
		show_comment_append
	);	
	
}

function add_comment(com_name,com_text,articul){
	$('#loader').css('visibility','visible');
	$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "add_comment", com_name:com_name,com_text:com_text,articul:articul								
		},
		show_comment_append
	);
}

function show_comment_append(data){
	$('#compare_table').html(data);
	$('#compare_table > tr:nth-child(odd)').addClass("even");
	$('#f_fon').css('visibility','visible');
	$('#loader').css('visibility','hidden');
	
	$('#ex4').css('width','410px');
	$('#ex4').css('height','420px');
	
	var w_l2 = window.screen.availWidth/2-205;
	$('#ex4').css('left',w_l2);
	
	$('#ex4').css('visibility','visible');
	$('#ex4').css('margin-top',document.documentElement.scrollTop+'px');
}

function sbrand(){
	var p = document.getElementById('grp');
	var grp =p.options[p.selectedIndex].text;
	
	var p2 = document.getElementById('subgroup');
	var sbgrp =p2.options[p2.selectedIndex].text;
	$('#loader').css('visibility','visible');
	$('#oth_sb').html('');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "select_brand", grp:grp, sbgrp:sbgrp					
		},
		select_brand_append
	);
}

function select_brand_append(data){
$('#brand').html(data);
$('#loader').css('visibility','hidden');
}

function ssubgrp(){
	var p = document.getElementById('grp');
	var grp =p.options[p.selectedIndex].text;
	$('#loader').css('visibility','visible');
	$('#oth_sb').html('');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "select_subgrp", grp:grp					
		},
		select_subgrp_append
	);
}

function select_subgrp_append(data){
$('#subgroup').html(data);
$('#loader').css('visibility','hidden');
}


function sother(){
	var p_brand = document.getElementById('brand');
	var p_grp = document.getElementById('grp');
	var brand =p_brand.options[p_brand.selectedIndex].text;
	var grp =p_grp.options[p_grp.selectedIndex].text;
	var p_sbgrp = document.getElementById('subgroup');
	var sbgrp =p_sbgrp.options[p_sbgrp.selectedIndex].text;
	$('#loader').css('visibility','visible');
		$.post(															
		'/_templates/afunc.inc.php',
		{
			func: "select_other", brand:brand, grp:grp, sbgrp:sbgrp					
		},
		select_other_append
	);	
}

function select_other_append(data){
	//alert(data);
$('#oth_sb').html(data);
$('#loader').css('visibility','hidden');
}