/*
+-----------------------------------------------------------------+
| Fn name:    popwin                                              |
+-----------------------------------------------------------------+
| Purpose:    Opens popup window w/fixed window options           |
+-----------------------------------------------------------------+
| Inputs:     string URL                                          |
|             string name (name of popup window)                  |
|             int w (width of popup window)                       |
|             int h (height of popup window)                      |
+-----------------------------------------------------------------+
| Returns:    nothing                                             |
+-----------------------------------------------------------------+
*/
function popwin(URL, name, w, h)
{
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
	window.open(URL, name, "width="+w+", height="+h+", status=yes, scrollbars=yes, resizable=no, menubar=no, toolbar=no, left="+winl+", top="+wint);
}


/*
+-----------------------------------------------------------------+
| Fn name:    popwin2                                             |
+-----------------------------------------------------------------+
| Purpose:    Opens popup window w/customizable window options    |
+-----------------------------------------------------------------+
| Inputs:     string URL                                          |
|             string name (name of popup window)                  |
|             int w (width of popup window)                       |
|             int h (height of popup window)                      |
|             string opts (other popup window options)            |
+-----------------------------------------------------------------+
| Returns:    nothing                                             |
+-----------------------------------------------------------------+
| History:    10/31/2005 - cpn_id is set to empty string if not   |
|                          passed instead of "undefined" [ft]     |
+-----------------------------------------------------------------+
*/
function popwin2(URL, name, w, h, opts)
{
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
	window.open(URL, name, "width="+w+", height="+h+", left="+winl+", top="+wint + opts);
}


/*
+-----------------------------------------------------------------+
| Fn name:    cWin                                                |
+-----------------------------------------------------------------+
| Purpose:    Opens coupon popup window for online FS which       |
|             adjusts path to site root folder                    |
+-----------------------------------------------------------------+
| Inputs:     int client_id                                       |
|             int cpn_id                                          |
|             string linkshare_id                                 |
+-----------------------------------------------------------------+
| Returns:    nothing                                             |
+-----------------------------------------------------------------+
| History:    11/29/2007 - added test to check if pop-up window   |
|                          opened, if not we alert the user [ft]  |
|             03/16/2006 - yes status b/c IE 6 SP2 shows it       |
|                          regardless for some reason,            |
|                          top/left added [ft]                    |
|             12/01/2005 - linkshare tracking argument added [ft] |
|             10/31/2005 - cpn_id is set to empty string if not   |
|                          passed instead of "undefined" [ft]     |
+-----------------------------------------------------------------+
*/
function cWin(client_id, cpn_id, linkshare_id)
{
   if (!cpn_id) { cpn_id = ''; }
   
   var host = location.host;
   var pathname = location.pathname;
   var path = '';
   
   // include linkshare tracking id in query string if present
   if (linkshare_id)
      var url = '/html/client/coupon_ofs_popup.php?client_id=' + client_id + '&cpn_id=' + cpn_id +
                '&u1=' + linkshare_id;
   else
      var url = '/html/client/coupon_ofs_popup.php?client_id=' + client_id + '&cpn_id=' + cpn_id;
   
   var opts = 'width=755, height=417, resizable=no, scrollbars=yes, top=50, left=50';
   
   /*
   // test for fabuloussavings.com in URL
   myRegExp = /fabuloussavings.com/i;
   var host_online = myRegExp.test(host);
   
   // test for test server
   myRegExp = /192.168./i;
   var host_test = myRegExp.test(host);
   
   // test for test server
   myRegExp = /.localhost/i;
   var host_localhost = myRegExp.test(host);
   
   myRegExp = /[\/]/g;
   var str = pathname.match(myRegExp);
   
   if (host_online || host_test || host_localhost)
      path_adj = str.length - 1
   else
      path_adj = str.length - 3;
   
   // exclude fwd slashes after domain name & end of url and adjust if local
   //path_adj = (host_online) ? str.length - 1 : str.length - 3;
   
   for (i = 1; i <= path_adj; ++i) { path += '../'; }
   */
   
   var open_test = window.open('http://www.fabuloussavings.com' + url, '', opts);
   
   // pop-up did not open successfully (pop-up blocker most likely), so redirect to
   // pop-up blocker help page
   if (!open_test)
   {
      /*
      alert('Pop-up blockers must be disabled in order to view our coupons properly.\n\n' +
            'Please disable any pop-up blockers and try again.');
      */
      location.href='help_popups.php?client_id=' + client_id;
   }
}