// JavaScript Document

$(document).ready(function(){
	//$("#tabbar").tabs(".menu_container",{tabs: 'ul.tabs a',initialIndex:null});		   
	$("form.filterForm").corner("10px").parent().css({'padding':'4px'}).corner("10px").find("div.status").corner("8px");	
	
	
						   
});

function custom_controlClick(x,e){
	var ct = _val(x,'ct');  // ct = ctrl type
	//alert('custom control ct='+ct);
	//alert($(x).attr("class"));
	var loc = _val(x,'loc');
	var grploc = _val(x,'grploc');
	var tar = _val(x,'tar');
	var pid = _val(x,'pid');
	var btn = $(x);
	var cg = $(btn).parents(".ctrlgrp");
	var xbkt = $("#"+tar);
	var mb = $(xbkt).closest(".moxblok");
	var $tar=$("#"+tar);
	//alert(tar);
	//alert(btn);
	//alert(cg.size());
	switch(ct){
		case "xblokADDMulti_custom":
			$("#multiItemForm").slideDown();
		break;
	}
	return false;
}

function custom_frmSubmitted($frm,response){
	var msg= response.msg;
	var cls = "success";
	//alert("frmid="+$frm.attr("id")+"\ndefid="+$.fn.collection.defaults.addFormId);
	switch($frm.attr("id")){
		case $.fn.collection.defaults.addCollectionFormId:
			//alert("added collection");
		break;
		case $.fn.collection.defaults.addItemFormId:
			//alert("added item");
			//console.dir({response_data:response.data});
			//var $col = $("#collections .collection.col_"+colid);
			//if(!$col.size()) console.dir({"col not found":$col});
			$frm[0].reset();
			//console.dir({'col before':col});
			var itmid= response.xkeyval;
			items[response.xkeyval]=response.data;
			//console.dir({items:items});
			col.items.push(response.xkeyval);
			$clone= $("#newItem").clone();
			$clone.metadata()['itmid']= response.xkeyval;
			itm_api.addItem($clone.collectionItem(),true);
			//console.dir({'col after':col});
			
		break;
		default:
			msg="";
			if(response.msg!=undefined && response.msg!="Saved.") msg=response.msg;
			dump(response,"default custom ajax saved");
			dump($frm.attr("id"),"the formid");
			$frm.announce(msg);
			$frm.input();
		break;
	}
	
	var result= {msg:msg,cls:cls};
	return result;
}


	
function custom_init(tip,disable){
	var action='init';
	if(disable) action='disable';
	if($("#collections").is(".scrollable")){
		//alert('scrollable');
		$(".xblok,.rg,.rok",$("#collections")).unbind('.xblok');
	} 
	$("#editItems").removeClass("hidden").hide();
	if(appMode=="EDIT") {
		$("#editItems").show();
		
	} 
	$("#collections .collection",tip).collection(action);
	$("#multiItemForm").removeClass("hidden").hide();
	
}





			

