var section=false;
$(function(){
		   
   $(".wbe_button_approve").click(function(){
		wbe_approve(this.form);
	});
   $(".wbe_button_deny").click(function(){
		selector="#map_id_"+this.form.map_id.value+"_extended";
		className=this.name;
		$(selector+" div").each(function(){
			currentClassName=$(this).attr('class');
			if(currentClassName!='' && currentClassName!='wbe_hide_extended' && currentClassName!=className){
				$(this).hide();
			}else if(currentClassName!='wbe_hide_extended'){
				$(this).show();
			}
													  
		});
		$(selector).fadeIn('normal');
		$(selector+" .wbe_extended_hide").click(function(e){
			$(selector).fadeOut('normal');
		});	
		$(selector+' div.wbe_deny_form .wbe_button_deny_submit').click(function(){
			wbe_deny(this.form);
		});
	});
		   
	$("#wbe_section_hide").click(function(e){
		$("#wbe_section_extended").fadeOut('normal',function(){
			$("#wbe_section_extended_content").empty();
		});
	});
	
	$(".wbe_button_extend").each(function(){
		$(this).click(function(){
			selector="#map_id_"+this.value+"_extended";
			className=this.name;
			$(selector+" div").each(function(){
				currentClassName=$(this).attr('class');
				if(currentClassName!='' && currentClassName!='wbe_hide_extended' && currentClassName!=className){
					$(this).hide();
				}else if(currentClassName!='wbe_hide_extended'){
					$(this).show();
				}
			});
			// $(selector).fadeIn('normal');
			$(selector).show();
		});
	});
	
});
function wbe_mapper_rpc(func,id,msg){
	this.func=func;
	this.id=id;
	this.msg=msg;
	this.callback=false;
	this.rpc=API.RPC.New('webdesign_editorial_rpc',this.func);
	this.execute=function(){
		this.rpc.parent=this;
		this.rpc.setParameter('map_id',this.id);
		this.rpc.setParameter('message',this.msg);
		this.rpc.parent=this;
		this.rpc.callBack=function(status,xml,text) {
			switch(status) {
				case 200:
					node=xml.firstChild;
					switch(node.nodeName) {
						case 'error': alert(node.firstChild.nodeValue);	break;
						case 'function':
							node=node.firstChild;
							switch(node.nodeName) {
								case 'error': alert(node.firstChild.nodeValue);	break;
								case 'success':
									if(this.parent.callback){
										this.parent.callback();
									}
								break;
							}
						break;
					}
					break;
				default: alert('RPC failed with statuscode '+status); break;
			}
		}
		this.rpc.execute();
	}
}
function wbe_approve(form){
	rpc=new wbe_mapper_rpc('approve',form.map_id.value);
	if(form.email_user!= undefined){ 
				rpc.rpc.setParameter('email_user',(form.email_user.checked?1:0));
	}
	rpc.callback=function(){
		document.location.href=	document.location.href;
	}
	rpc.execute();
}

function wbe_delete(id){
	rpc=new wbe_mapper_rpc('delete',id);
	rpc.callback=function(){
		document.location.href=	document.location.href;
	}
	rpc.execute();
}
function wbe_deny(form){
	rpc=new wbe_mapper_rpc('deny',form.map_id.value,form.message.value);
	if(form.rollback != undefined){ 
				rpc.rpc.setParameter('rollback',(form.rollback.checked?1:0));
	}
	if(form.email_user!= undefined){ 
				rpc.rpc.setParameter('email_user',(form.email_user.checked?1:0));
	}
	rpc.callback=function(){
				document.location.href=document.location.href;
	}
	rpc.execute();
}
