// ========================================= //
// Parameters:                               //
// loc: location to open in the new window   //
// (STRING)                                  //
// w: proposed width of the window           //
// (INTEGER)                                 //
// h: proposed width of the window           //
// (INTEGER)                                 //
// xpos: 'left','center' or 'right'          //
// (STRING)                                  //
// ypos: 'top','middle' or 'bottom'          //
// (STRING)                                  //
// type: 'all', 'none', 'none_scroll',       // 
//       'none_status' or                    //
//       'none_scroll_status'                //
// (STRING)                                  //
// ========================================= //
function open_arw_win(loc,w,h,xpos,ypos,type)
{
	// Calculate the available width and height of the screen //
	var screenw=screen.availWidth;
	var screenh=screen.availHeight;
	
	// set the initial values //
	var windoww=screenw;
	var windowy=screenh;
	var windowx=0;
	var windowy=0;
	var windowp=0;
	var dimensionparams='';
	var additionalfixedparams='';
	var additionalvariableparams='';
	var params='';

	// Check for passed width less than, greater than screen width and is a number//
	if( (w<=0) || (w>screenw) || (isNaN(w)) )
	{
		windoww=screenw;
	}
	else
	{
		windoww=w;
	}
	// Check for passed height less than 0, greater than screen height and is a number//
	if( (h<=0) || (h>screenh) || (isNaN(h)) )
	{
		windowh=screenh;
	}
	else
	{
		windowh=h;
	}

	// Work out the x co-ordinate of the window based on the parameters passed //
	switch(xpos.toLowerCase())
	{
	case 'left':
		{
			windowx=0;
			break;
		}
	case 'center':
		{
			if(screenw>windoww)
			{
				windowx=Math.round((screenw-windoww)/2);
			}
			else
			{
				windowx=0;
			}
			break;
		}
	case 'right':
		{
			if(screenw>windoww)
			{
				windowx=Math.round(screenw-windoww);
			}
			else
			{
				windowx=0;
			}
			break;
		}
	default :
		{
			windowx=0;
			break;
		}
	}

	// Work out the y co-ordinate of the window based on the parameters passed //
	switch(ypos.toLowerCase())
	{
	case 'top':
		{
			windowy=0;
			break;
		}
	case 'middle':
		{
			if(screenh>windowh)
			{
				windowy=Math.round((screenh-windowh)/2);
			}
			else
			{
				windowy=0;
			}
			break;
		}
	case 'bottom':
		{
			if(screenh>windowh)
			{
				windowy=Math.round(screenh-windowh);
			}
			else
			{
				windowy=0;
			}
			break;
		}
	default :
		{
			windowy=0;
			break;
		}
	}

	// Set the dimension parameters //
	dimensionparams='width='+windoww+',height='+windowh+',left='+windowx+',top='+windowy;
	
	// Test for window type //
	switch(type.toLowerCase())
	{
	case 'all':
		{
			additionalvariableparams='directories=yes,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes';
			break;
		}
	case 'none':
		{
			additionalvariableparams='directories=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=no';
			break;
		}
	case 'none_scroll':
		{
			additionalvariableparams='directories=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes';
			break;
		}
	case 'none_status':
		{
			additionalvariableparams='directories=no,location=no,menubar=no,status=yes,toolbar=no,scrollbars=no';
			break;
		}
	case 'none_scroll_status':
		{
			additionalvariableparams='directories=no,location=no,menubar=no,status=yes,toolbar=no,scrollbars=yes';
			break;
		}
	default:
		{
			additionalvariableparams='directories=yes,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes';
			break;
		}
	}
	
	// Set the fixed additional parameters //
	additionalfixedparams='resizable=no';
	
	// Set the entire parameters //
	params=dimensionparams+','+additionalvariableparams+','+additionalfixedparams;

	// Open the window //
	var rand=Math.round(Math.random()*1000);
	eval("var arw_win"+rand+"=window.open(loc,'arw_win"+rand+"',params);");
	eval("arw_win"+rand+".focus();");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function void_func()
// call this function from the href, then call the open_arw_win from the onClick //
{
	
}

// Replacement for Favourites feature that adds page to browser favourites/bookmarks
function addFavourite()
{
  var pageUrl = ''+document.location;
  var FavpageUrl = pageUrl;
  var FavpageTitle = document.title;

  //alert('pageUrl = '+pageUrl);
  //alert('pageUrlPreCropNo = '+pageUrl.indexOf('.php?tok=',0));
  if (pageUrl.indexOf('.php?tok=',0) > -1)
  {
    var pageUrlCropNo = pageUrl.indexOf('.php?tok=',0);
    //alert('pageUrlCropNo = '+pageUrlCropNo);
    var FavpageUrl = ''+pageUrl.substring(0, (pageUrlCropNo+4));
  }
  //alert('FavpageUrl = '+FavpageUrl);

  if(arguments.length > 0)
  {
    var url_array = FavpageUrl.split("/");
    var FavpageUrl = url_array[0]+"//"+url_array[2]+arguments[0];
    var FavpageTitle = arguments[1];
  }

  //alert('FavpageUrl = '+FavpageUrl);

  if (window.sidebar) { 
    window.sidebar.addPanel( FavpageTitle ,FavpageUrl,""); 
  } else if( window.external && document.all ) {
    window.external.AddFavorite( FavpageUrl, FavpageTitle );
  } else {
      alert('Please manually add "'+FavpageTitle+'" (URL '+FavpageUrl+') through your browser.');
  }
}
