//<script language="JavaScript">
 var uagent    = navigator.userAgent.toLowerCase();
 var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
 var is_opera  = (uagent.indexOf('opera') != -1);
 var is_webtv  = (uagent.indexOf('webtv') != -1);
 var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
 var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
 var is_moz    = ( (navigator.product == 'Gecko')  && (!is_opera) && (!is_webtv) && (!is_safari) );
 var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
 var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
 var is_kon    = (uagent.indexOf('konqueror') != -1);

 var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
 var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
 var ua_vers   = parseInt(navigator.appVersion);

 var mbut_left=1;
 if (is_moz || is_opera) mbut_left=0;
 var mbut_right=2;

 var timeout=null;
 var locations=new Array();
 var request=new Array();
   request.disabled=false;
   request.data=new Array();
 var num=0;
 var stats=new Array();
 var item_drag=0;

 var baseopacity=0

 function into(id,text,show){
   // ~ alert(id);

   document.getElementById(id).innerHTML=text;
   if (show==1) document.getElementById(id).style.display='inline';
   if (show==0) document.getElementById(id).style.display='none';
  }

 function into_add(id,text){
   document.getElementById(id).innerHTML=document.getElementById(id).innerHTML+text;
  }

 function div_show(id){
   document.getElementById(id).style.display='inline';
  }

 function div_hide(id){
   document.getElementById(id).style.display='none';
  }

 function send_action(action,id){
   if (action) request.data.action=action;
   div_show('wait');
   doload();
  }


 function buy_item(id){
		request.data.item_id=id;
		div_hide('profile_item_try');
		div_hide('profile_item_try_2');
		send_action('one_item');
 }

 function my_save(){
		div_hide('inner_inv_stat');
		div_hide('profile_item');
		div_hide('inner_inv');
		div_hide('all_mags');
		div_hide('buy_item');
		close_invent();
		send_action('save_invent');
 }

 function close_item(){
		div_hide('buy_item');
	}

	function buy_do(id){
		div_hide('profile_item_try');
		div_hide('profile_item_try_2');
		request.data.item_id=id;
		send_action('buy_do');
	}

	function try_do(id){
		div_hide('buy_item');
		div_hide('profile_item_try');
		div_hide('profile_item_try_2');
		request.data.item_id=id;
		send_action('try_do');
	}

	function close_try(){
		div_hide('profile_item_try');
		div_hide('profile_item_try_2');
	}

 function profile_action(act,id){
   if (id>0) request.data.id=id;
   request.data.dl=1;
   request.data.profile_action=act;
   send_action('profile_act');
  }

	function add_item(form){

		div_hide('but');
		request.data.form=form;
		send_action('item_add');
	}

	function book_view(form){
		request.data.form=form;
		send_action('book');
	}

	function delete_book(id){
		request.data.bid=id;
		send_action('delete_book');
	}

	function take_flag(book, page, member){
		request.data.book=book;
		request.data.page=page;
		request.data.member=member;
		send_action('take_book_flag');
	}

	function delete_flag(book, page){
		request.data.book=book;
		request.data.page=page;
		send_action('delete_flag');
	}

		function edit_item(form){
		div_hide('but');
		request.data.form=form;
		send_action('item_edit');
	}

	function show_all_mag(){
		div_hide('inner_inv_stat');
		div_hide('profile_item');
		div_hide('inner_inv');
		div_hide('link_1');
		close_invent();
		send_action('show_all_mag');
	}

	function show_mag(id){
		request.data.mag_id=id;
		send_action('show_mag');
	}

	function show_cat_mag(id, st){
		request.data.cat_id=id;
		request.data.st=st;
		send_action('show_cat_mag');
	}

 function show_invent(gr, st){
	 div_hide('inner_inv_stat');
	 div_hide('inner_inv_stat');
	 div_hide('inner_inv_2');
	 if(!gr){
		 gr=3;
	 }
	 if(!st){
		 st=0;
	 }
	 request.data.group_item=gr;
	 request.data.st=st;
   close_invent();
   send_action('invent');
  }

 function show_anketa(id){
		div_hide('member_ank');
		if (id) request.data.ank_id=id;
		send_action('show_ank');
	}

function load_reg_form()
{
    var action = 'load_reg_form';
    request.data.cc=1;
    send_action(action);
}


function showtext(thetext){
	document.getElementById("tabledescription").innerHTML=thetext
}


 function close_invent(){
   div_hide('invent_item');
  }

 function choose_rep(type){
   if(type){
     mes='Понижение репутации';
     val='minus';
    }
   else{
     mes='Повышение репутации';
     val='plus';
    }
   into('rep_podpis',mes);
   document.getElementById('rep_edit').style.display='';
   document.getElementById('rep_type').value=val;
  }

 function close_profile(){
   div_hide('invent_item');
   div_hide('inner_inv');
  }

	function show_city(){
		div_hide('country_all');
		send_action('city');
	}

	function show_city_end(id){
		div_hide('regions');
		request.data.region_id=id;
		send_action('city_all');
	}

	function show_all_country(){
		div_hide('country_all');
		send_action('country_all');
	}

	function v_nachalo(){
		div_hide('regions');
		div_hide('all_city');
		div_hide('country_all_end');
		div_show('country_all');
	}

 function upgrade_item(in_id){
   close_invent();
   request.data.invent_id=in_id;
   send_action('upgrade');
  }

 function upgrade_itemto(inv,it){
   into('item_board','',0);
   request.data.invent_id=inv;
   request.data.upgrade_id=it;
   send_action('upgrade');
  }

 function doload(value){
   if (timeout) clearTimeout(timeout);
request.disabled=false;
   // Create new JsHttpRequest object.
   if (!request.disabled){

     request.disabled=true;
     var req = new JsHttpRequest();
     
     // Code automatically called on load finishing.
     req.onreadystatechange = function() {
       if (req.readyState == 4){
           
         div_hide('wait');
         // Write result to page element ($_RESULT become responseJS).
         if (req.responseJS.doit!=''){
           //~ into_add('debug',req.responseJS.doit+'<br>---------------------------------------<br>');
           eval(req.responseJS.doit);
          }
         // Write debug information too (output become responseText).
         if(req.responseText!=''){
           alert(req.responseText);
          }
         request.disabled=false;
         if (timeout) clearTimeout(timeout);
         //timeout = setTimeout('doload()', 3000);
        }
      }
     // Prepare request object (automatically choose GET or POST).
     if (value){
       get='';
       for (key in request.data){
         get=get+'&'+key+'='+request.data[key];
        }
       req.open('POST', '/index.php?act=profile_item'+get, true);
       req.send({'file':value});
      }
     else{
       req.open('POST', '/index.php?act=profile_item', true);
       req.send(request.data);
      }
      
     //num++;
     //document.getElementById('debug').innerHTML=num;
     request.data=new Array();
    }
  }

 function item_md(evt,id,move,action,group){
   if (evt.button==mbut_left){
     if(move==1){
       item_drag=id;
       emi_action=action;
       StartDrag(evt,document.getElementById('items_'+id));
      }
    }
   else if(evt.button==mbut_right && item_drag==0){
     request.data.invent_id=id;
     request.data.dl=1;
     send_action('get_item_info');
    }
  }

 function item_md_t(evt,id,move,action,mem_id){
   if (evt.button==mbut_left){
		 //alert('t');
     if(move==1){
       item_drag=id;
			 person = mem_id;
       emi_action=action;
       StartDrag_t(evt,document.getElementById('items_pu_'+id));
      }
    }
  }

 function item_drag_end(x,y){
   old_x=DraggingItem.old_x.replace(/px/,'')*1;
   if ((old_x>500 && x>500) ||(old_x<500 && x<500)){
     DraggingItem.This.style.left=DraggingItem.old_x;
     DraggingItem.This.style.top=DraggingItem.old_y;
    }
   else{
     request.data.move_invent_x=x;
     request.data.move_invent_id=item_drag;
     request.data.emi_action=emi_action;
     switch (emi_action){
       case 'upgrade':
         upgrade_item(item_drag);
       break;
       case 'sell':
         send_action('sell',item_drag);
       break;
       case 'storage':
         send_action('move',item_drag);
       break;
       default:
         send_action('move_invent');
       break;
      }
    }
   item_drag=0;
  }

  function item_drag_end_t(x,y){
		var str="<a style=\"color:#ffffff; font-size:14px;\" href='#' onclick=\"show_me('"+item_drag+"','"+x+"','"+y+"','"+person+"'); return false;\">Запулить</a>";
		if(y>548){
			alert('Подвиньте предмет выше');
			div_hide('pul');
		}
		else if(x<0){
			alert('Подвиньте предмет правее');
			div_hide('pul');
		}
		else{
			div_show('pul');
			into('pul',str,1);
		}
	}

	function show_me(item_drag,x,y){
		request.data.item_drag_id=item_drag;
		request.data.item_drag_x=x;
		request.data.item_drag_mid=person;
		request.data.item_drag_y=y;
		send_action('pul_me');
	}

	function show_throw_stat(id){
		request.data.mid=id;
		send_action('show_throw_stat');
	}

	function wash_and_throw(pull_id){
		request.data.pull_id=pull_id;
		send_action('wash_and_throw');
	}

	function wash_profile(pull_id){
		request.data.pull_id=pull_id;
		send_action('wash_profile');
	}

	function confirm_tarif(theURL) {
       if (confirm('Вы уверены, что хотите получить этот тариф?')) {
          window.location.href=theURL;
       }
       else {
          alert ('Тогда оставайтесь.');
       }
    }


    function edit_status(){
        var text = document.getElementById('status_test').value;
        request.data.status_text=text;
        send_action('edit_status');
    }

//<script>
