$(document).ready(function(){ 

	if(jQuery().datepicker) {
	   $(".datepick").datepicker({dateFormat: "yy-mm-dd"});
	}
	if(jQuery().clockpick) {
	  //$(".clockpick").clockpick();
	  $(".clockpick").clockpick({military:true,minutedivisions:12});
	}
	
	if(jQuery().tablesorter) {
		$(".sorttable table").tablesorter();
	}
	if(jQuery().validate) {
		$(".validate").validate();
	}	
	
	
	$("input:radio, input:checkbox").addClass('radio');
	$(".zebra tr:nth-child(odd)").css("background","#cccccc");
	
	
	$(".hovertable tr, .contentbody table tr").live("mouseenter",function(){
		$(this).addClass('hover');
	}).live("mouseleave",function(){
		$(this).removeClass('hover');
	});  
	
	$(".sup").hover(function(){
		$('.sub', this).show();
	},function(){
		$('.sub', this).hide('fast');
	});

$(".supper").live("mouseenter",function(){
	if($('.subbar', this).css("display")!='none')return false;
	$('.subbar').hide();
	$(".subbar", this).slideDown('fast');
}).live("mouseleave",function(){
	$(".subbar").slideUp('fast');
});  
  



$("#loading").live("ajaxSend", function(){
   $(this).show();
 }).live("ajaxComplete", function(){
   $(this).hide();
});
  

$(".button").live("click",function(){
	$(this).addClass("selected"); 
});

$(".confirm, .delete").live("click",function(){
	return confirm(' \n Before you click OK be sure you do right action! \n\n\n Note: This may take a some troubles \n\n\n');
});


  
$(".onhover").live("mouseenter",function(){
	$(".onhover").removeClass('hover');
	$(this).addClass('hover');
}).live("mouseleave",function(){
	$(".onhover").removeClass('hover');});


$(".closewin, .winclose").live("click",function(){
	$(this).closest('.window').fadeOut('fast'); return false;//	winclose(this);
});


///////////////////////////////////////////// form field default text from field title  
$(".def_text").bind("focus",function(){
	 if ($(this).val() == $(this).attr('title')){
            $(this).removeClass("defaultTextActive"); $(this).val("");
        }
}).bind("blur",function(){
	 if ($(this).val() == ""){
            $(this).addClass("defaultTextActive");
            $(this).val($(this).attr('title'));
        }
}); $(".def_text").blur();

$("form").bind("submit",function(){
	 if ($('.def_text', this).val() == $('.def_text', this).attr('title')){
            $('.def_text', this).val("");
        }
});
/////////////////////////////////////////////
  
$(".tdig").bind("focusout", function(){
	var vall = $(this).val(); vall = Math.round(vall);
	if(vall=='0'){vall=''; }
	
	if((vall>=1 && vall<=10) || vall==''){
		$(this).val(vall).removeClass('alertbrd');return false;
	}else{ $(this).val('').addClass('alertbrd'); }
});

$(".hdig").bind("focusout", function(){
	var vall = $(this).val(); vall = Math.round(vall);
	if(vall=='0'){vall=''; }
	
	if((vall>=1 && vall<=100) || vall==''){
		$(this).val(vall).removeClass('alertbrd');return false;
	}else{ $(this).val('').addClass('alertbrd'); }
});

$(".showtip").bind("mouseenter",function(){
	$(".tipcontent", this).fadeIn('fast');
}).bind("mouseleave",function(){
	$(".tipcontent", this).hide();
});

$(".ctextarea").bind("focus",function(){
	$(".ctextarea").removeClass('grovetextarea');
	$(this).addClass('grovetextarea');
}).bind("focusout",function(){
	$(".ctextarea").removeClass('grovetextarea');
});
	
	
$(".tabs li").live("click",function(){
	//alert('ssss');
	var toid = $(this).attr('toid');
	var et = $("#"+toid).css("display");
	
	if(et=='block'){ return false; }
	$(".tabs li").removeClass('selected');
	$(".tabb").hide();
	
	$(this).addClass('selected');
	$("#"+toid).show();
	
}); $(".tabs li:first").click();

	
$(".fastselect").live("mouseenter",function(){
	$('.'+$(this).attr('subclass'), this).show('fast');
}).live("mouseleave",function(){
	$('.'+$(this).attr('subclass'), this).hide('fast');
});	
	
$(".hvr").live("mouseenter",function(){
	if($(this).attr('hvr')){ $(this).css('background-image','url(images/'+$(this).attr('hvr')+'.png)') }
}).live("mouseleave",function(){
	if($(this).attr('nrml')){ $(this).css('background-image','url(images/'+$(this).attr('nrml')+'.png)') }
});
	

$(".dinload").live("click",function(){
	dinload($(this).attr('toid'), $(this).attr('tourl') ,$(this).attr('varr'));
});
	
})



function dinload( id, get, post){
	///id - loading container id
	if(id==''){return false;}
	var d = new Date();
	var dcontrol = d.getHours();
	
	$("#loading").bind("ajaxSend", function(){
	   $("#"+id).hide();
	}).bind("ajaxComplete", function(){
	   $("#"+id).show();
	});
	
	if(get=='' || !get)return false;
	if(id=='' || !id)id='dformplace';
	$("#"+id).load(get,{val: post, control: dcontrol });

}
	



/////// calendar selector
function calendar_selector(get, post){
	var year = $('#phpcalendary').val();
	var month = $('#phpcalendarm').val();
	var post = year+month;
	dinload('phpcalendarcontainer', get, post);
//	alert(get);
	
}

function fast_load(from, to){
	$("#"+to).html('').hide();
	var tt = $('#'+from).html();
	//alert(tt);
	$("#"+to).html(tt).show();
//	$("#"+to).show();
}


