// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//function ChangeColor(tableRow, highLight, pointer){
//
//        var point = (pointer == null) ? true : pointer;
//
//        if (highLight)
//		{
//			//tableRow.style.backgroundColor = '#FEFF6F';
//			//tableRow.style.borderColor = '#3B3E39';
//			//tableRow.style.cssText="border:1px dotted #999";
//			tableRow.addClassName('box_highlight');
//			tableRow.addClassName('drag');
//
//                if(point){
//                   //tableRow.style.cursor = 'move';
//                }
//
//		}else{
//
//			tableRow.removeClassName('box_highlight');
//			tableRow.removeClassName('drag');
//
//			//tableRow.style.backgroundColor = '#FEFEC0';
//			//tableRow.style.borderColor = '#E3EDF4';
//			//tableRow.style.cursor = '';
//			//tableRow.style.cssText="border:1px solid transparent";
//
//
//		}
//	}

function showAjaxWorking(element,location){

		var html = '<img src="/images/ajax-roller.gif" id="ajax_loading" />';

		if(location=='top'){
			new Insertion.Top(element, html);
		}else{
			new Insertion.Bottom(element, html);
		}


}

function hideAjaxWorking(element){

		Element.hide('ajax_loading');
}

function DoNav(theUrl)
    {
	document.location.href = theUrl;
    }

function showSubmit(action){
		if(action != 'choose'){
				$('bulk_submit').show();
		}else{
				$('bulk_submit').hide();
		}
}

function checkAction()
{

	if ($F('actions')=='destroy')
	{
		return confirm('Are you sure you want to delete the selected lists?')
	}

	if ($F('actions')=='print')
	{

		var cbs = $('bulk_operation').getElementsByClassName('bulk');
		var ids = "";
		cbs.each(function(value,index){ if (value.checked){ids += value.value + "|";}});
		// make sure something got selected and pass through to controller if not
		if (ids.replace('|','')=='')
		{
			return true;
		}
		else
		{
			window.open('/lists/' + ids + ';print','print','height=600,width=600,resizable=1,scrollbars=1,menubar=1');
			return false;
		}
	}

	if ($F('actions')=='email')
	{
		return true;
		// var cbs = $('bulk_operation').getElementsByClassName('bulk');
		// 	var ids = "";
		// 	cbs.each(function(value,index){ if (value.checked){ids += value.value + "|";}});
		// 	window.open('/lists/' + ids + ';email?send_to=' + $F('send_to_email'),'email','height=600,width=600');
		// 	return false;

	}
	
	if ($F('actions')=='build')
	{
		$('bulk_operation').action = '/list_builders/new'
		$('bulk_operation').method = 'get'
		
	}else{
		$('bulk_operation').action = '/bulk_list_operation'
		$('bulk_operation').method = 'post'
		
	}

}

function checkForEmail(action)
{
	if (action=='email')
	{
		$('send_list_to').show();
		$('send_list_to_comments').show();
	}
	else
	{
		$('send_list_to').hide();
		$('send_list_to_comments').hide();
	}

	if (action=='copy')
	{
		$('copy_list_to').show();
	}
	else
	{
		$('copy_list_to').hide();
	}

}

function collapseAll(ids){
		ids.each(function(s) {
				collapse(s);
				return false;
		});
}

function expandAll(ids){
		ids.each(function(s) {
				expand(s);
				return false;
		});
}

function expand(id){
		$('cat_' + id).show();
		$('expand_' + id).hide();
		$('collapse_' + id).show();
		return false;
}

function collapse(id){
		$('cat_' + id).hide();
		$('expand_' + id).show();
		$('collapse_' + id).hide();
		return false;
}

function toggleAllInCategory(id){
	
		var cbs = $('cat_' + id).getElementsByClassName('item_cb');
		cbs.each(function(value,index){ if (value.checked){ value.checked=false }else{ value.checked=true }});
	
}
