var winID = 0;
function OpenWin(link,t,w,h,modal)
{
//window.open(link,'_blank','width='+(width||720)+',height='+(height||600)+',toolbar=0,location=0,menubar=0,top=0,left=0,scrollbars=1,resizable=1');
   if (parent.winID) {
		parent.winID++;
		id = parent.winID;
   } else {
      winID++;
      id = winID;
   }
	win = new Window('target' + id,
						{
							url: link,
							className: "dialog",
							title: t,
							width:w, height:h, zIndex:100+id,
							resizable:true,
							wiredDrag:true,
							showEffectOptions: {duration:1}
						});
	win.setDestroyOnClose();
	win.showCenter(modal);
}

function fpage(target, href)
{
	new Ajax.Updater(target,
			href,
			{asynchronous:true,
			 onComplete:function(request){
					Element.hide('throbber');
					aI.init();
				},
			 onLoading:function(request){
					Element.show('throbber');
					aI.destroy();
				}
			}

);
}
function pageupdate(target, href, name_id, title)
{
	var a = document.getElementById(name_id);
	a.innerHTML = title;
	fpage(target, href);
}

function FindWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function FindWindowHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function FitWindowWidth(width, factor) {
    WinWidth = FindWindowWidth();

    if (width > WinWidth*factor)
    {
	return WinWidth*factor;
    }
    else
    {
	return width;
    }
}

function FitWindowHeight(height, factor) {
    WinHeight = FindWindowHeight();

    if (height > WinHeight*factor)
    {
	return WinHeight*factor;
    }
    else
    {
	return height;
    }
}
function CreateControl(DivID, url, name, width, height, more){
  var d = document.getElementById(DivID);
  d.innerHTML = '<object style="" classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="' + DivID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="' + width + '" height="' + height + '"><param name="movie" value="' + url + '" /><param name="quality" value="High" /><' + 'embed src="' + url + '" type="application/x-shockwave-flash" name="' + name + '" pluginspage="http://www.macromedia.com/go/getflashplayer" width="' + width + '" height="' + height + '" ' + more + ' /&gt;<' + '/object>';
}
