/// javascript document


function check_all(id,callback)
{
	$("#" + id).find("input:checkbox").each(function(){
		$(this).attr("checked",true);
		if(callback){
			callback($(this).parents("tr")[0]);
		}
	});
}



function uncheck_all(id,callback)
{
	$("#" + id).find("input:checkbox").each(function(){
		$(this).attr("checked",false);
		if(callback){
			callback($(this).parents("tr")[0]);
		}
	});
}



function getClock() {
    ddate= new Date();
	var sHour= ddate.getHours();
	var sMins= ddate.getMinutes();
	sMins= (sMins < 10)? "0"+sMins:sMins;
	
    document.getElementById("ttime").innerHTML = sHour+":"+sMins;
    window.setTimeout('getClock()',1000);
}



function confirmOption(elm,func)
{
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
		$( '#dialog' ).dialog({
			resizable: false,
			modal: true,
			buttons: {
				" Yes ": function() {
					
					if(elm){
						window.location= $(elm).attr('href');
					}
					
					if(func){
						func();
					}
					
					if($('#verfiyForm')){
						if(validForm($('#verfiyForm'))){
							$('#verfiyForm').submit();
						}
						
						return true;
					}
					
					$( this ).dialog( "close" );
					
					return true;
				},
				" No ": function() {
					$( this ).dialog( "close" );
					
					return false;
				}
			}
		});
		
		return false;
	});
	
	return false;
}



function validForm(form)
{
	elms= $(form).find('input');
	
	if(elms.length > 0){
		for(var x=0;x<elms.length;x++){
			if($(elms[x]).hasClass('required') && $.trim($(elms[x]).val()) == ''){
				$(elms[x]).focus();
				return false;
			}
			
			if($(elms[x]).hasClass('number') && isNaN($(elms[x]).val())){
				$(elms[x]).focus();
				return false;
			}
		}
	}
	
	return true;
}



