
function update_adsense_id(f){
	$.post( f.action, {adsense_id:f.adsense_id.value} , function(r){ f.update.value=r;f.update.disabled=true; } );
	return false;
}
function mkf( u, obj ){
	rpc = new XmlRpc('/account/fav/');   
	try{
		rs = rpc.call('Fav.mk', u );
		if( rs ){
			obj.onclick=null;
			obj.style.color="#FF6600";
			obj.href='/account/fav/';
			obj.innerHTML = 'hinzugefügt - Verwalten';
			obj.onmouseout = function(){
				obj.innerHTML = 'Favorit';
			}
		}
		return false;
	}catch( e ){
	
	}
	return true;
}

function rd_delete( id, obj ){
	rpc = new XmlRpc('/rate/');   
	try{
		rs = rpc.call('rd_delete', id );
		if( rs ){
			obj.onclick=null;
			obj.style.color="#FF6600";
			obj.innerHTML = 'deteted';
			
		}
		return false;
	}catch( e ){
	
	}
	return true;
}

function rd_bann( id, obj ){
	rpc = new XmlRpc('/rate/');   
	try{
		rs = rpc.call('rd_bann', id );
		if( rs ){
			obj.onclick=null;
			obj.style.color="#FF6600";
			obj.innerHTML = 'banned';
		}
		return false;
	}catch( e ){
	
	}
	return true;
}

function watchlist( site, obj ){
	try{
		rpc = new XmlRpc('/account/watchlist/');   
		rs = rpc.call('WatchList.add', site );
		if( rs ){
			obj.onclick=null;
			obj.style.color="#FF6600";
			obj.href='/account/watchlist/';
			obj.innerHTML = 'hinzugefügt - Verwalten';
			obj.onmouseout = function(){
				obj.innerHTML = 'Watchliste';
			}
		}
		return false;
	}catch( e ){
	
	}
	return true;
}

function disa(){
rres = nz.get('regres');
nz.anim.dec(rres, 'opacity', 0, 33);
}
function vote_e( id ){
rres = nz.get('v'+id);
nz.anim.dec(rres, 'opacity', 0, 33);
}

function rate(id, dir, o, type){

	if( rate.id == id ){
		return false;
	}

	rate.id = id;

	o.style.outline='none';
	rpc = new XmlRpc('/rate/');   
	try{
		if( type == 'book' ){
			rs = rpc.call('NZ_MyNews.rateBook', id, dir );
		}else if( type == 'list' ){
			rs = rpc.call('NZ_MyNews.rateList', id, dir );
		}else if( type == 'ratePhoto' ){
			rs = rpc.call('NZ_MyNews.ratePhoto', id, dir );
		}else{
			rs = rpc.call('NZ_MyNews.rate', id, dir );
		}
			//alert(rs );
	if( rs ){
	
       }
	rating = nz.get('rating-'+id);
	if( dir=='up' ){
		rating.innerHTML = parseInt(rating.innerHTML)+1;
		return false;
	}
	rating.innerHTML = parseInt(rating.innerHTML)-1;
	return false;

	/*
	p = nz.get('ru'+id).parentNode;
	nz.rm(nz.get('ru'+id));
	nz.rm(nz.get('rd'+id));
	ok = nz.cr('img');
	ok.src='/img/ok.png';
	p.appendChild(ok);
	*/
   }catch(e){
	rres = nz.cr('div');
	rres.id='v'+id;
	//rres.style.display='';
	rres.innerHTML = e.message;
	rres.className='msgerror';
	nz.get('s'+id).appendChild(rres);
	//nz.check(rres);
	//rres.setOpac(100);
	rres.onComplete=function(){
		nz.rm(this);
	}
	//setTimeout('vote_e('+id+')', 600);
   }		 	
	
	return false;
	//return false;
}

function FR(){
}

FR.items = new Array();

FR.trySubmit = function(obj){
	 rpc = new XmlRpc('/submit/');
   try{
	rs = rpc.call('Rd_News.submit', obj.title.value, obj.text.value, obj.url.value, obj.cat.value, obj.tags.value );
	if( rs ){
              obj.sub.value='done';
              obj.sub.disabled=true;
		return false;
       }
   }catch(e){
  }	
  return true;
}

FR.preSubmit = function( p){
 if( p.hasSubmit ){
	return false;
 }
 item = FR.items[p.id];
 h='<form action="/submit/" method="post" onsubmit="return FR.trySubmit(this)">';
 h+='<br />Title: <input type="text" value="'+item.title+'" name="title">';
 h+='<input type="hidden" value="'+item.link+'" name="url">';
 h+='<input type="hidden" value="submit" name="cmd">';	
 h+='<br />Text: <textarea name="text">'+item.description+'</textarea>';
 h+='<br />Tags:<input type="text" name="tags">';	
  h+='<br />Thema: '+getOptions();
 h+=' <input type="submit" style="width:auto" name="sub" value="OK">';
 p.innerHTML+=h;
 p.hasSubmit = true;	
 return false;
}

FR.cache = {};
FR.fetch = function( site, p_id, obj, no_post ){
   
    if( obj.fetched ){
	if( !no_post ){
		return false;
	}
    }	
   
    if( no_post ){
	nz.get(p_id).innerHTML = '';
    }		
    fbx = nz.cr('div');
    fbx.className='fbx' 
    fbx.innerHTML = '<img src="/img/loading.gif">';	
     nz.get(p_id).appendChild(fbx);	
    var func = function ( data ) {                  // define call back function
	  FR.cache[site] = data;
	 //fbx.style.position='absolute'; 
	 //fbx.style.top='230px';
	 fbx.innerHTML = '';	

	if( data.exception ){
		fbx.innerHTML = data.exception.message;
		return false;	
	 }

	if( !data.rss.channel ){	
		fbx.innerHTML = 'Error';
		return false;	
	}
	if( !data.rss ){	
		fbx.innerHTML = 'Error';
		return false;	
	}

	items = data.rss.channel.item;
	if( !items ){	
		fbx.innerHTML = 'Error';
		return false;	
	}

	 
	 for( i = 0;i< items.length;i++ ){
		
		p = nz.cr('p');
		d = new Date();
		pid = d.getTime()+'_'+i;;
		p.id=pid;
		FR.items[pid] = items[i];	
		p.style.display='none';
		p.innerHTML=items[i].description+' <a href="'+items[i].link+'">more</a>';
		if( !no_post ){
			p.innerHTML+=' <a href="/submit/" onclick="return FR.preSubmit(this.parentNode)">publish</a>';
		}
		
		a = nz.cr('a');
		a.pid = pid;
		a.p = false;
		a.onclick=function(){
			pobj = nz.get(this.pid);
			if( !pobj.innerHTML ){
				return true;
			}
			if( this.p==false ){
				dis='';
				this.p = true;
			}else{
				this.p = false;
				dis='none';
			}
			pobj.style.display=dis;
			return false;
		}
              
		a.href=items[i].link;
		a.innerHTML = items[i].title+'<br />';
        	//alert(items[i].title); 
		fbx.appendChild(a);
		fbx.appendChild(p);

	}
    }
    obj.fetched = true; 	
    if( FR.cache[site] ){
	func(FR.cache[site]);
	return false;	
    }	
   
    if( typeof(JKL) == 'undefined' ){
	window.location='/login/';
    }	

    var url = "/reader/?method=getFeed&site="+site;
    
    var xml = new JKL.ParseXML( url );	
    xml.async( func );
    xml.parse();
	
	return false;
}