function popup( url, width, height )
{
    if ( !width )
        width = 800;

    if ( !height )
        height = 400;

    window.open( url, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=' + width + ',height=' + height + ',left=320,top=250' );
}

function tab_load( tab, url, form )
{
    if ( form )
    {
        url += '?tab_load=1';
        for ( var i = 0; i < form.elements.length; i++ )
        {
            var elem = form.elements[i];
            url += '&' + elem.name + '=' + elem.value;
        }

        alert( url );
    }

    tab.set( 'dataSrc', url );
    tab.refresh();
}


// functiont hat takes the an element (such as an image parent node (containing dib or box)) and a css property.
// for divs an spans, the height, width etc are defined thru a css property on the object and not on the obj itself.
// css('property') returns a number w/ "px" ending, meaning the measurement of that side, and in order to do some
// mathematical comprarisons, we need to strip out the "px", for that get the number, and get a substring from the
// begining til the "px" word.
function get_css_number( name, css_property )
{
   return parseInt(jQuery(name).css(css_property).substring(0,jQuery(name).css(css_property).indexOf("px")))
}

// function that takes the id of an image and scales it according to its container class name.
function scale_image_to_fit( image_id, class_name )
{
	var image = document.getElementById( image_id );
		
	// Grab the image's dimensions, cos Image has height & width associated with it
	var imgH = image.height;
	var imgW = image.width;
	// grab the box'es dimensions by using the above function that returns the css height property as a Number
	// div doesn't have height atribute, just a style
	
	//note that JQuery can look up for the element around my img by giving it the .class_name
	var boxH = get_css_number("."+class_name,'height');
	var boxW = get_css_number("."+class_name,'width');
	// Find which dimension is scaled the most
	var scaleH = boxH / imgH;
	var scaleW = boxW / imgW;

	// Scale the image
	if (scaleH < scaleW) 
	{
		// img is higher than box
		image.height = boxH; //scale img down to height of box
		image.width = Math.round(imgW * scaleH); //scale img width as per ratio
	} 
	else 
	{
		// img is wider than box
		image.width = boxW; //scale img width down to box
		image.height = Math.round(imgH * scaleW); // scale height down as per ratio
	}

}

// function for preloading images while lading them with ajax, and putting a spinning icon while the ajax call is still loading
function ajax_preload( path )
{
    jQuery( path ).preload({ placeholder:'/static/images/rotation_animation_loading.gif' });
}



