function getObj(id)
{
	var obj = document.getElementById(id);
	if (obj)return obj;
}
	
function show_obj(obj)
{
	getObj(obj).style.display = 'block';
}

function hide_obj(obj)
{
	getObj(obj).style.display = 'none';
}

function getselected(obj)
{
	return obj.options[obj.selectedIndex].value;
}

function clearForm(form, sel) {
	$('#'+form+' :input').each(function() {
		var type = this.type;
		var tag = this.tagName.toLowerCase(); // normalize case
		if (type == 'text' || type == 'password' || tag == 'textarea' || type == 'file')
			this.value = "";
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select' && !sel)
			this.selectedIndex = 0;
	});
};

function discardElement(element) 
	{
    var garbageBin = document.getElementById('IELeakGarbageBin');
    if (!garbageBin) 
		{
        garbageBin = document.createElement('DIV');
        garbageBin.id = 'IELeakGarbageBin';
        garbageBin.style.display = 'none';
        document.body.appendChild(garbageBin);
	    }

    garbageBin.appendChild(element);
    garbageBin.innerHTML = '';
	document.body.removeChild(garbageBin);
	}

function clearFileInputField(Id) {
  document.getElementById(Id).innerHTML = document.getElementById(Id).innerHTML;
}

function show_w(id, middle)
{
	$("#hover").show();
	var block = $("#" + id);
	block.show();
	if(!middle)
	{
		var height = $(document).height() / 2 - block.height() / 2;
		block.css({'top': height, 'position': 'relative'});
	}
}

function close_w(id)
{
	$("#" + id).hide();
	$('#big_img').attr('src','/DESIGN/SITE/images/35.gif');
	$("#hover").hide();
}

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 select_onpage(num, path)
	{
	var today = new Date(); 
	var expires = 180 * 1000 * 60 * 60 * 24; 
	var expires_date = new Date( today.getTime() + (expires) ); 
	var a = expires_date.toGMTString();
	setCookie('onpage',num,a,path);	
	window.location = path;//location.reload('path');
	}

function close_timer(id, sec, clear)
{
	if(sec == 0) { if(clear) clear_pu_form(id); close_w(id); clearTimeout(timer); }
	else { var timer = setTimeout("close_timer('"+id+"', "+ (sec - 1) +", "+clear+")",1000); }
}

function clear_pu_form(form)
{
	$('#'+form+'_ok').hide(); $('#'+form+'_content').show(); clearForm(form+'_form', true);
}

function base64_decode( data ) {    // Decodes data encoded with MIME base64
	    //
	    // +   original by: Tyler Akins (http://rumkin.com)
	    data = escape(data);  
	 
	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';
	 
	    do {  // unpack four hexets into three octets using index points in b64
	        h1 = b64.indexOf(data.charAt(i++));
	        h2 = b64.indexOf(data.charAt(i++));
	        h3 = b64.indexOf(data.charAt(i++));
	        h4 = b64.indexOf(data.charAt(i++));
	 
	        bits = h1<<18 | h2<<12 | h3<<6 | h4;
	 
	        o1 = bits>>16 & 0xff;
	        o2 = bits>>8 & 0xff;
	        o3 = bits & 0xff;
 
	        if (h3 == 64)     enc += String.fromCharCode(o1);
	        else if (h4 == 64) enc += String.fromCharCode(o1, o2);
	        else               enc += String.fromCharCode(o1, o2, o3);
	    } while (i < data.length);
	 
     return unescape(enc);
	}
	
$(document).ready(function() {
var advice = $('.advice');
var advice1 = $('.advice');
var noclose = false;

advice.find('.close').click(function(){				
advice.hide();		
$('#fade1').remove();		
$('#fade').css({'display' : 'none'});
return false;			
});	



$('.send').click(function(){				 
$('#advice').show();		 
$('body').append('<div id="fade1"></div>');		
$('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn();return false;			
});	
	
$('#advice, .send').live('mouseover mouseout', function(event){		
if(event.type == 'mouseover'){			
noclose = true;		
}else{			
noclose = false;		
}	
});
			
$('html').live('click', function()
{		
if( noclose ){			
return false;		
}			
});
});

function create_advice(title, price, count)
{
$('body').append('<div id="advice1" class="advice"> <div class="t">Добавлено в корзину</div><p>Товар:'+ title + '</p><p>Цена: <span>'+price+'</span></p><p><a href="#" onclick="closss();return false;">Продолжить покупки</a></p></div>');	
var wid=((parseInt(document.body.clientWidth))/5)+document.body.scrollTop;
$('#advice1').css({'margin' : wid+'px 500px'});
$('#advice1').show();		 
$('body').append('<div id="fade1"></div>');		
$('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn();
return false;	
}


function change_count(id) 
{
$('#count' + id).val( $('#count' + id).val().replace(/\D/g, ''));

if (($('#count' + id).val()<1) && ($('#count' + id).val()!='') )
{

	$('#count' + id).val(1);
}
}

function closss()
{				
$('#fade1').remove();	
$('#advice1').remove();		
$('#fade').css({'display' : 'none'});

return false;			
}
function add_item(id)
{
if ($('#count'+id).val()=='')
{
	$('#count'+id).val(1);
}
	doLoad('', '/ajax/add/'+id+'/'+$('#count'+id).val()+'/');
	return false;
}

