function selectAll (form , newState) {
	for (var i=0;i<form.elements.length;i++)	{
		var e = form.elements[i];
		e.checked = newState;
	}
}

function ShowDetails (link,resultDiv) {
    if (resultDiv==null) resultDiv='MainDetailsData';
	$('#'+resultDiv).prepend('<div class="working_cursor"><img src="./img/icons/working.gif"></div>');

	if (!$('#'+resultDiv).hasClass('toggle_details')) {
		$(link).parent().siblings('li').children('a').removeClass('Selected'); $(link).addClass('Selected');
	}

	//~ $.get ('http://172.16.3.27:8067/foobar/',function (data) {
	return !$.ajax ({
		url : link.href ,
		success: function (data) {
				if (  $('#'+resultDiv).hasClass('toggle_details') ) { //in case we want to cache the data and toggle hide / display
					$('.working_cursor').remove();
					var toggle_js = '$(\'#'+resultDiv+'\').children().toggle();return false;';
					$('#'+resultDiv).removeClass('toggle_details').addClass('details_are_retreived') //switch class so we know we have the data
						.children('a').attr('OnClick', toggle_js ).hide().parent()					//change the link so we just display the data we already have
						.append( '<a class="icon_hide" href="#" OnCLick="'+toggle_js+'">[-]</a>' )		//add a link to hide
						.append( data ); // append the data
				} else {
					$('#'+resultDiv).html( data ) ;
				}
				if (self.effects_init) effects_init();
			} ,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
				//if timed out, redirect to main page
				window.location = this.url;
				//~ $('#'+resultDiv).html('<div id="Details">'+textStatus + ' ' + errorThrown+'</div>');
			}
	});
}

function multi_checkbox_select(event, ids, idx, override) {
	if (document._checkboxes ==undefined) document._checkboxes=[]

	if (event.ctrlKey==1) {
		if (override==1) {
			$("#"+ids+"_"+idx).attr('checked', true);
		}
		document._checkboxes[ids]=idx
	} else if (event.shiftKey!=1) {
		if (override==1) {
			$("[id*="+ids+"]").attr('checked', false);
			$("#"+ids+"_"+idx).attr('checked', true);
		}
	 //clear all
		//~ $("input[@id^='"+ids+"']").attr('checked', false)
		//check this one
		//~ $("#"+ids+"_"+idx).attr('checked', true);
		document._checkboxes[ids]=idx
	} else {
		if (override) {
			$("#"+ids+"_"+idx).attr('checked', !$("#"+ids+"_"+idx).attr('checked'));
		}
		checked = $("#"+ids+"_"+idx).attr('checked')
		if (checked==undefined) checked=false

		if (document._checkboxes[ids] > idx) {
			minval = idx
			maxval = document._checkboxes[ids]
		} else {
			minval = document._checkboxes[ids]
			maxval = idx
		}
		for(i=minval; i<=maxval; i++) {
			$("#"+ids+"_"+i).attr('checked', checked)
		}
		document._checkboxes[ids]=idx
	}
	return false
}

$(function() {
	if (self.effects_init) effects_init(); //Round corners, replace fonts ...
});

function ajaxify_veditor(targetdiv, subcmd, respcmd, rettype) {
	var options = {
			target:				targetdiv,	 // target element(s) to be updated with server response
			beforeSubmit:	subcmd,	// pre-submit callback
			success:			 respcmd,	// post-submit callback
			type: 'post'
		};

	// bind to the form's submit event
	$('#vdata_editor').submit(function() {
		$(options.target).prepend('<div class="working_cursor"><img src="./img/icons/working.gif"></div>');
		$('#veditor_return_type').val(rettype);
		$(this).ajaxSubmit(options);
		return false;
	});

	$('#vdata_editor *[type^="submit"]').each(function(index) {
		//~ alert(this.getAttribute('name'));
		var $target=$(this)
		$target.click(
			function() {
				$('#dummy').val($target.attr('name'));
				return true;
			}
		);
	});
}

function align_divs(toalign, dest, where) {
	var pos = $("#"+dest).offset();  
	var width = $("#"+dest).width();
	var height = $("#"+dest).height();
	
	var myheight = $("#"+toalign).height();

	if (where=='top') {
		$("#"+toalign).css( { "left": pos.left + "px", "top":(pos.top-myheight) + "px" } );
	}

	$("#"+toalign).show();
}

