// JavaScript Document

function open_window_sized(url, width, height, copyright) 
{
     winOptions = 'toolbar=no,status=no,location=yes,menubar=no,scrollbars=no,resizable=yes,width=' + width + ',height=' + height;
     winName = 'mediawindow';
     if (copyright == 1) {
          new_copyright_window = window.open('dp/copyright.php?url='+url, winName, winOptions); 
          new_copyright_window.focus(); 
     } else { 
          new_window = window.open(url, winName, winOptions);  
          new_window.focus(); 
     } 
}

// group_toggle_enabled:	Pass in an array of objects to be disabled/enabled.
function group_toggle_enabled( objects_array )
{
	for(var i=0; i<objects_array.length; ++i)
	{
		objects_array[i].disabled = !objects_array[i].disabled;
		objects_array[i].value = null;
	}
}

function group_set_enabled(enabled, objects_array)
{
	var isEnabled = (enabled == true || enabled == 1);
	for(var i=0; i<objects_array.length; ++i)
	{
		objects_array[i].disabled = !isEnabled;
		if(objects_array[i].disabled)
			objects_array[i].value = null;
	}
}

// selecText;      Auto selects text in textarea; used to copy the big ugly urls
function selectText(element)
{
	element.select();
}

// functions to "expand/collapse" or "show/hide" page elements
function toggle(n) {
     var el, i = 1;
     for (i; i<=number_of_panels; ++i) {
          if (i == n) {
              el = document.getElementById('T' + i);
              if (el.style.display == 'block') {
                  el.style.display = 'none';
         }
              else el.style.display = 'block';
      }
          else {
              el = document.getElementById('T' + i);
              if (el.style.display == 'block') 
              el.style.display = 'none';
      }
   }
}


function GetInnerSize () {
    var x,y;
    if (self.innerHeight) // all except Explorer
    {
        x = self.innerWidth;
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
    {
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        x = document.body.clientWidth;
        y = document.body.clientHeight;
    }
    return [x,y];
}


function ResizeToInner (w, h, x, y) {
    // http://www.hypergeneric.com/corpus/javascript-inner-viewport-resize/
    // http://goodies.zitez.net/resizeinnerheight.html
    // make sure we have a final x/y value
    // pick one or the other windows value, not both
    if (x==undefined) x = window.screenLeft || window.screenX;
    if (y==undefined) y = window.screenTop || window.screenY;
    // for now, move the window to the top left
    // then resize to the maximum viewable dimension possible
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth,screen.availHeight);
    // now that we have set the browser to it's biggest possible size
    // get the inner dimensions.  the offset is the difference.
    var inner = GetInnerSize();
    var ox = screen.availWidth-inner[0];
    var oy = screen.availHeight-inner[1];
    // now that we have an offset value, size the browser
    // and position it

	var fudgeWidth = 0;
	var fudgeHeight = 0;

    window.resizeTo(w+ox+fudgeWidth, h+oy+fudgeHeight);
    window.moveTo(x,y);
}

function resizeDocumentTo(setw,seth){
    return window.resizeTo(setw,seth),window.resizeTo(setw*2-((typeof window.innerWidth ==
    'undefined')?document.body.clientWidth:window.innerWidth),seth*2-((typeof window.innerHeight ==
    'undefined')?document.body.clientHeight:window.innerHeight));
}

function uberResize(w,h) {
     
	// fudge width
    w += 4;
    // fudge height
    h += 8;
     
    //var docRef=document.referrer;
    //alert(docRef.search(/copyright/));
    //if (docRef.search(/copyright/) == -1)
    //{
        //alert('copyright found in referer!');
        var browserName=navigator.appName;
        if (browserName=="Microsoft Internet Explorer")
        {
            //alert("Inner Width: " + iW + "px Inner Height:" + iH + " px");
            //alert("called with " + w + " - " + h);
            
            //alert("ie. called with " + w + " - " + h);
            ResizeToInner(w,h);
            //window.resizeDocumentTo(w,h);
        }
        else 
        {
            window.resizeDocumentTo(w,h);
            //window.innerHeight(h);
            //window.innerWidth(w);
        }
    //}
    //else
    //{
        //alert('copyright NOT found in referer!');
        // size should be good then.  don't resize !
    //}
}
