function OpenWindow( file, windowName, width, height, windowID, scroll, resizable, statusBar )
{
  var screen_width = screen.availWidth;
  var screen_height = screen.availHeight;

  var X = (screen_width  / 2) - (width  / 2);
  var Y = (screen_height / 2) - (height / 2);

  if( windowID != null )
  {
    if( windowID.closed == false )
    {
      windowID.close();
    }
  }

  var openString = "width=" + width +",height=" + height + ",left=" + X + ",top=" + Y;

  if( resizable )
  {
    openString += ", resizable=yes";
  }
  else
  {
    openString += ", resizable=no";
  }

  if( scroll )
  {
    openString += ", scrollbars=1";
  }

  if( statusBar )
  {
    openString += ", statusbar=yes";
  }
  else
  {
    openString += ", statusbar=no";
  }

  windowID = window.open( file, windowName, openString );
  windowID.focus();

  return windowID;
}

function getPageParam( key )
{
  var page = document.location.href;
  var paramStartIndex = page.indexOf( "?" );
  
  if( paramStartIndex > -1 )
  {
     var params = page.substring( paramStartIndex + 1 );
     var paramsCollection = params.split( '&' );

     for( var i=0;i<paramsCollection.length;i++ )
     {
		 var index = paramsCollection[ i ].indexOf( "=" );
       if( index > -1 )
       {
          var currentKey = paramsCollection[ i ].substring( 0, index );
	  
          if( currentKey == key )
          {
			  var value = paramsCollection[ i ].substring( index+1, paramsCollection[ i ].length );
              return value;
          }
       }
     }
  }
  else
  {
    return "";
  }
}

var reset = "false";

function setReset( val )
{
	if( val == "true" || val == "false" )
	{
	  reset = val;	
	}
}

var productWin = null;

function openProductWin( productname, workspace, schema, showHTMLBlock, showIntro, width, height, userDefinedParams )
{
	if( userDefinedParams != null )
	{
		if( userDefinedParams.length > 0 )
		{
			if( userDefinedParams.substring( 1 ) != "&" )
			{
				userDefinedParams = "&" + userDefinedParams;
			}
		}
	}
	else
	{
		userDefinedParams = "";
	}
  var location = "flex_component.html?style=" + schema + "&workspace=" + workspace + "&productname=" + productname + "&showHTMLBlock=" + showHTMLBlock + "&showIntro=" + showIntro + "&reset=" + reset + userDefinedParams;
  productWin = OpenWindow( location, 'flexcomponentwin', width, height, productWin, false, true, false );
}

