//------------------------------------------------
//Function to pop up a window for Linked Documents
//------------------------------------------------
var PopUpURL = "";
var PopUpTitle = "";
var PopWinUrl = "";
var PopUpURLTree = null;
function popupLink( url, title, width, height, stuff, popWinUrl, popUpURLTree )
{
   //set via function param
   PopWinUrl    = (PopWinUrl    || popWinUrl);
   PopUpURLTree = (PopUpURLTree || popUpURLTree);

  var winName = "pop" + (new Date()).valueOf();
  if( typeof( title )  == 'undefined' ) title = "LoislawConnect";/*K->A 10/25*/
  if( typeof( width )  == 'undefined' ) width  = 850;
  if( typeof( height ) == 'undefined' ) height = 500;
  if( typeof( stuff )  == 'undefined' ) stuff  = true;
  if( !stuff || Site =='MPS') 
       stuff = 'scrollbars,status=no,toolbar=no,menubar=no,resizable,width='+width+',height='+height;
  else stuff = 'scrollbars,status,menubar,resizable,width='+width+',height='+height;
 
  url = url.replace( //g, "^15" );
  url = url.replace( /\"/g, "%22" ); 
  PopUpURL   = url;
  PopUpTitle = title;

  PopWinUrl  = (PopWinUrl||"/snp/fpopwind.htm");
  //if( url.match(/^(https?:\/\/[^\/]+)?\/pns\/[^\.]+\.htp/i )){//want to filter this to only possible tree loading windows, or call a new popuplink function
  
  //if( url.match(/^(https?:\/\/[^\/]+)?\/pns\/(searchtree|searchtreeStart|gcresult|gctree)\.htp/i ) )
  //  {//want to filter this to only possible tree loading windows, or call a new popuplink function
	//  PopWinUrl = "/pns/index.htp?isPopWin=1";
  //}
  //if( url.match(/^(https?:\/\/[^\/]+)?\/pns\/[^\.]+\.htp/i ) 
  //  && !url.match(/^(https?:\/\/[^\/]+)?\/pns\/(tcresult|gcresult|doc)\.htp/i ))//remove when SearchTree can do all these
   // {//want to filter this to only possible tree loading windows, or call a new popuplink function
	//  PopWinUrl = "/pns/index.htp?isPopWin=1";
 // }
  
  //CR 3454
  if(url=="spotlight")
  {
    PopUpURL = "/info/product/pubrecordscorp.htm"; //Content frame url
  	PopWinUrl = "/spotlight.htm?linkid=home_spotlight"; // framset url
  }
  
  popupWin = window.open( PopWinUrl, winName, stuff);
  //return popupWin;
}

function popupNoFrameLink( url, title, width, height, stuff )
{
  url = url.replace( //g, "^15" );
  url = url.replace( /\"/g, "%22" );
  var winName = "pop" + (new Date()).valueOf();
  if( typeof( title )  == 'undefined' ) title = winName;
  if( typeof( width )  == 'undefined' ) width  = 790;
  if( typeof( height ) == 'undefined' ) height = 480;
  if( typeof( stuff )  == 'undefined' ) stuff = true;
  if( !stuff || Site == 'MPS' )
  	popupWin = window.open( url, winName, 'scrollbars,status=no,toolbar=no,menubar=no,resizable,width='+width+',height='+height);
  else
  	popupWin = window.open( url, winName, 'scrollbars,status,menubar,resizable,width='+width+',height='+height);
}

//Pop a new window from DHTML content string
var popupHTML = PopupHTML; //function alias - bottom framed window version
function popupNoFrameHTML( content, title, width, height, stuff ){ //No bottom frame
  PopupHTML(content, title, width, height, stuff, false, true);
}

//WritePopInfoLink: Pop a new bottom framed window with Content frame DHTML
function WritePopInfoLinkOLD(linkTitle, content, width, height, stuff, emptyPage, noReuse){
  var winID = "InfoLink"+(new Date()).valueOf();
  var title = linkTitle.replace(/\'/g,"\\\'").replace(/\"/g,"&quot;");
  window[winID] = content;//<a target="mywin" onclick="return GiveFocus(this)">
  var s = "<a class=\"infoRedLink\" onclick=\"try{top['w"+winID+"'].focus();}catch(e){}\""
    +" href=\"javascript:PopInfoText('"+winID+"','"+title+"',window."+winID+","+emptyPage+","+width+","+height+");\"><span class=\"infoRedLink\">"+linkTitle+"</span></a>";
  return s;
}
function WritePopInfoLink( linkTitle, content, width, height, stuff, emptyPage ){
  return WritePopupHTMLLink( linkTitle, content, GetSafeInt(width,400), GetSafeInt(height,300), stuff, emptyPage, "infoRedLink" );
}
function PopInfoText(winID, title, content, emptyPage, width, height ){

  if( typeof( title )  == 'undefined' ) title = "Loislaw.com";
  width=(width||400);
  height=(height||300);
  
  var win = window.open("", winID, 'scrollbars,status=no,toolbar=no,menubar=no,resizable,width='+width+',height='+height);
  win.document.open();
  var Content = content;
  if( typeof content == 'string'){ Content = function(){ return content; }; }
  var html = (emptyPage)?Content()
    : ""
     +"<html><head><title>"+title+"</title><link rel='stylesheet' type='text/css' href='/css/lois.css'>"
     +"<script type='text/javascript' src='/js/onload.js'><\/script>"
     +"<script type='text/javascript'>function Sync(){ try{bottom.BottomSync('close',self);}catch(e){} }<\/script>"
     +"</head><body onload='Sync()'>"+Content()
     +"<div class='bottomContainer' style='position:absolute;bottom:0;'><center><span class='bottomButton'><span class='button' onclick='window.close()'>Close</span></span></center></div>"
     +"</body></html>"
     ;
  win.document.write(html);
  win.document.close();
  top["w"+winID] = win;
}


//All params optional
// content - string or function that returns a string
// title - window title - also used to derive IDs for named window reuse and focus
// width & height - defaults 600 x 500 
// !stuff - no window tool bars
// emptyPage - Don't enclose in <html><body>...
// noReuse - Unique win, otherwise reuse named win if exists

//Returns an HTML <A link> string - clicking will Pop Up a window with DHTML content (calls PopUpHTML)
function WritePopupHTMLLink( linkTitle, content, width, height, stuff, emptyPage, className, noReuse ){
  var winID = GetSafeWinID( linkTitle, true );
  var title = linkTitle.replace(/(\"|\')/g,"\\$1");
  window["c"+winID] = content;  //<a target="mywin" onclick="return GiveFocus(this)">
  var s = "<a onclick=\"try{top['"+winID+"'].focus();}catch(e){}\" " + ((className)?"class="+className:"")
    +" href=\"javascript:PopupHTML(window.c"+winID+",'"+title+"',"+GetSafeInt(width,null)+","+GetSafeInt(height,null)+","+GetSafeBool(stuff)+","+GetSafeBool(emptyPage)+","+GetSafeBool(noReuse)+",'"+winID+"');\"><span class=\"infoRedLink\">"+linkTitle+"</span></a>";
  return s;
}
//Pop Up a window with DHTML content
function PopupHTML(content, title, width, height, stuff, emptyPage, noReuse, winID)
{  
  title  = GetSafeWinTitle( title, "Loislaw.com" );
  width  = GetSafeInt( width, 600 );
  height = GetSafeInt( height, 500 );
  if( typeof( stuff )=='undefined') stuff = true;
  if( !stuff || Site =='MPS') 
       stuff = 'scrollbars,status=no,toolbar=no,menubar=no,resizable,width='+width+',height='+height;
  else stuff = 'scrollbars,status,menubar,resizable,width='+width+',height='+height;
  
  winID = (winID||GetSafeWinID(title,noReuse)); //use winID if given
  
  var Content = (typeof(content)=='string')? function(){return content;}:content;//content can be static string OR dynamic function that returns a string
  var html = (emptyPage)? Content()
    : "<html><head><title>"+title+"</title><link rel='stylesheet' type='text/css' href='/css/lois.css'>"
     +"<script type='text/javascript' src='/js/onload.js'><\/script>"
     +"<script type='text/javascript'>function Sync(){ try{bottom.BottomSync('close',self);}catch(e){} }<\/script>"
     +"</head><body onload='Sync()'>"+ GetHeaderHTML(title) + Content() + GetFooterHTML()
     //"<div id='Main' class='Main'><div class='"+cls+"' id='pageHeading' style='text-align:center'>"+t+"</div><hr>"
     +"<div class='bottomContainer' style='position:absolute;bottom:0;'><center><span class='bottomButton'><span class='button' onclick='window.close()'>Close</span></span></center></div></body></html>";
  //alert(GetHeaderHTML(title));
  //alert(GetFooterHTML());
  var win = window.open("", winID, stuff);
  win.document.write(html);
  win.document.close();
  top[winID] = win;
}
//helpers
function GetSafeWinID(s,noReuse){ return s.replace(/^(PWin)*/,"PWin").replace(/[^a-z0-9]/gi,"") + ((noReuse)?(new Date()).valueOf():""); }//noReuse? unique win, otherwise reuse named win
function GetSafeWinTitle(s,sDefault){ return GetSafeStr(s,sDefault).replace(/<\/?[^>]*>/g, ""); }
function GetSafeStr(s,sDefault){ return String(s||sDefault); }
function GetSafeInt(i,iDefault){ return ( isNaN(i))?iDefault:i; }
function GetSafeBool(b){ return new Boolean(b); }//default is false

