var tmpp= new Array();

function act_to_basket_time( act, id, count, page, time, load )
{
	document.getElementById( load ).innerHTML= '<img src="_images/loading19.gif" style="margin: 15px 15px 0px 0px;" alt="" />';
	
	clearTimeout( tmpp[ id ] );
	
	tmpp[ id ]= setTimeout( "act_to_basket( '"+act+"', '"+id+"', '"+count+"', '"+page+"' )", time );
}

function act_to_basket( act, id, count, page )
{
	var xmlhttp1;
	
	if( window.XMLHttpRequest )
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp1= new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp1= new ActiveXObject( "Microsoft.XMLHTTP" );
	}
	
	xmlhttp1.open("GET", "basket_items.php?act="+act+"&id="+id+"&count="+count+"&page="+page, false);
	xmlhttp1.send( null );
	
	if( ! xmlhttp1.getResponseHeader( "Date" ) ){ // 1
		var cached= xmlhttp1;
		
		var xmlhttp1;
		
		if( window.XMLHttpRequest )
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp1= new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp1= new ActiveXObject( "Microsoft.XMLHTTP" );
		}
		
		var ifModifiedSince= cached.getResponseHeader("Last-Modified");
		
		ifModifiedSince= (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
		xmlhttp1.open( "GET", "basket_items.php?act="+act+"&id="+id+"&count="+count+"&page="+page, false );
		xmlhttp1.setRequestHeader( "If-Modified-Since", ifModifiedSince );
		xmlhttp1.send( null );
		
		if( xmlhttp1.status == 304 )
		{
			xmlhttp1= cached;
		}
	}
	
	if( xmlhttp1.readyState == 4 && xmlhttp1.status == 200 )
	{
		if( act == 'add' && page == 'catalog' )
		{
			document.getElementById( "right_basket_count" ).innerHTML= xmlhttp1.responseText;
			document.getElementById( "cat_item_count_td_" + id ).innerHTML= count;
			document.getElementById( "cat_item_add_td_" + id ).innerHTML= '<a href="javascript: act_to_basket( \'del\', \''+ id +'\', \'0\', \'catalog\' );"><img src="_images/del_from_basket_1.png" alt="" /></a>';
		
		}else if( act == 'del' && page == 'catalog' ){
			document.getElementById( "right_basket_count" ).innerHTML= xmlhttp1.responseText;
			document.getElementById( "cat_item_count_td_" + id ).innerHTML= '<input id="catalog_item_count_'+ id +'" type="text" value="1" />';
			document.getElementById( "cat_item_add_td_" + id ).innerHTML= '<a href="javascript: act_to_basket( \'add\', \''+ id +'\', document.getElementById( \'catalog_item_count_'+ id +'\' ).value, \'catalog\' );"><img src="_images/add_to_basket_1.png" alt="" /></a>';
		
		}else if( ( act == 'del' || act == 'recount' ) && page == 'basket' ){
			document.getElementById( "page_basket" ).innerHTML= xmlhttp1.responseText;
		}
	}
}


function scs(  )
{
	var height= 0;
	
	if( self.screen )
	{
		width= screen.width;
		
		if( width < 1230 )
		{
			document.getElementById( "left_block" ).style.width= 150;
			document.getElementById( "right_block" ).style.width= 150;
		}
	}
}


function search( search_query, id )
{
	if( search_query.length > 2 || search_query.length == 0 )
	{
		var xmlhttp1;
		
		if( window.XMLHttpRequest )
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp1= new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp1= new ActiveXObject( "Microsoft.XMLHTTP" );
		}
		
		xmlhttp1.open("GET", "catalog_search.php?act=search&query="+search_query+'&id='+id, false);
		xmlhttp1.send( null );
		
		if( ! xmlhttp1.getResponseHeader( "Date" ) ){ // 1
			var cached= xmlhttp1;
			
			var xmlhttp1;
			
			if( window.XMLHttpRequest )
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp1= new XMLHttpRequest();
			}else{// code for IE6, IE5
				xmlhttp1= new ActiveXObject( "Microsoft.XMLHTTP" );
			}
			
			var ifModifiedSince= cached.getResponseHeader("Last-Modified");
			
			ifModifiedSince= (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
			xmlhttp1.open( "GET", "catalog_search.php?act=search&query"+search_query+'&id='+id, false );
			xmlhttp1.setRequestHeader( "If-Modified-Since", ifModifiedSince );
			xmlhttp1.send( null );
			
			if( xmlhttp1.status == 304 )
			{
				xmlhttp1= cached;
			}
		}
		
		if( xmlhttp1.readyState == 4 && xmlhttp1.status == 200 )
		{
			document.getElementById( 'content_text' ).innerHTML= xmlhttp1.responseText;
		}
	}
}
