﻿// Default wizards script file
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



function HackAgentsOfArtificeLink()
{
    var links = document.getElementsByTagName('a');

    for(var i = 0; i < links.length; i++)
    {
        var link = links[i];
        
        if(link.className == 'smalllink' && link.innerHTML == 'Agents of Artifice')
        {
            link.href = 'http://www.wizards.com/Magic/Novels/Product.aspx?x=mtg/novels/product/agentsofartifice';
        }
    }
}

function onSearchKeyDown()
{
    if (event.keyCode == 13) 
    {                
        var searchBox = document.getElementById("_wotcSimpleSearchBox");
        var searchText = searchBox.value;
        searchSubmitText(searchText) ;
    }            
}
function searchSubmit()
{            
    var searchBox = document.getElementById("_wotcSimpleSearchBox");
    searchSubmitText(searchBox.value) ;    
}
function searchSubmitText(searchText)
{        
    searchText = TrimString(searchText);     
    searchText = escape(searchText) ;   
    if (searchText == "")
    {
        rejectEmptySearch();
    }
    else
    {
        var url = "http://www.google.com/cse?q=" + searchText + "&sa=Search&cx=010753050335830773696%3Ases62ofhwsq&ie=UTF-8";
        location.href = url ;
    }
}

function rejectEmptySearch ()
{
    alert('No search term was supplied.');
}

function TrimString(sInString) 
{
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}   


/*
Function: makeWinXY
Description: pop up window, opening a new simple window that is scrollable
Parameters: 
Returns: Target href in a new window that is scrollable
Remarks: site wide function
Revisions: 5/03/06, brady, ported over from the asp site
*/

function makeWinXY(url, nWidth, nHeight) {  // pop up window with height/width

              agent = navigator.userAgent;
              windowName = "xywindow";

              params  = "";
              params += "toolbar=0,";
              params += "location=0,";
              params += "directories=0,";
              params += "status=0,";
              params += "menubar=0,";
              params += "scrollbars=1,";
              params += "resizable=1,";
              params += "width=" + nWidth + ",";
              params += "height=" + nHeight;

              win = window.open(url, windowName , params);

              if (agent.indexOf("Mozilla/2") != -1 &&
agent.indexOf("Win") == -1) {
                  win = window.open(url, windowName , params);
              }

              if (!win.opener) {
                  win.opener = window;
              }

}

/*
Function: loadMovie
Description: loads a swf file in a manner that gets around the "click here to activate" issue
Parameters: url of the swf file
Returns: 
Remarks: 
Revisions: 3/19/2007 Stephen Spates: Ported from goblin project
*/
function loadMovie(url, width, height)
{
		document.write("<embed id=\"embedSwf\" src=\"" + url + "\""  
		+ " swLiveConnect=\"true\" quality=\"high\""
		+ " type=\"application/x-shockwave-flash\" allowScriptAccess=\"always\""
		+ " width=\"" + width + "\""
		+ " height=\"" + height + "\""	
		+ " />");
}


