// Pop-Up Window

function popWinQuick( theURL ) {
  popWin( theURL, theURL );
}

function popWinName( theURL, winName ) {
  popWin( theURL, winName, 500, 450, 1, 0, 0, 0, 1 );
}

function popWinSize( theURL, width, height ) {
  popWin( theURL, 'popWinSize', width, height, 1, 0, 0, 0, 1 );
}

function popWinSizeTools( theURL, width, height ) {
  popWin( theURL, 'popWinSize', width, height, 1, 0, 1, 0, 1 );
}

function popWin( theURL, winName, width, height, scrollBars, toolBar, menuBars, addressField, resizable ) {
  var features =
    'width='        + width +
    ',height='      + height +
    ',scrollbars='  + scrollBars +
    ',toolbar='     + toolBar +
    ',menubar='     + menuBars +
    ',location='    + addressField +
    ',resizable='   + resizable +
    ',status=0';
  var winRef = window.open( theURL, winName, features);
  winRef.focus();
}


function setcookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
	curCookie += ";";
//        alert(curCookie);
    if (value) document.cookie = curCookie.replace('257C', '7C');
}

// cookiez by joe
var affinfo;
var referer = document.referrer;
var expdate = new Date ();
var uniquid =(expdate.getTime()+""+Math.floor((Math.random()*8999)+1000));
var expired = new Date(expdate.getTime() - 48 * 60 * 60 * 1000);
expdate.setTime(expdate.getTime() + (86400 * 30));

// ensure cookie is not set again
if (document.cookie.length < 43) {
    if ((!document.cookie.match("affinfo=")) || (document.cookie.match("affinfo=") == "affinfo=")) {
		if (document.URL.match("affid=")) {
            // grab referral part of URL "affid=1012|PR7004001"
			affinfo = document.URL.substr(document.URL.indexOf("affid"));
			if( affinfo.lastIndexOf("|") == -1 || affinfo.lastIndexOf("|") == affinfo.length-1 )
				affinfo += "|0|" + uniquid + "|" + referer; // affiliate known, ad unknown
			else
				affinfo += "|" + uniquid + "|" + referer; // affiliate and ad known
            setcookie('affinfo', affinfo.replace("affid=", ""), expdate, '/');
        } else if (!document.cookie.match("affinfo=")) {
            affinfo = "0|0|" + uniquid + "|" + referer; // affiliate and ad unknown
            setcookie('affinfo', affinfo, expdate, '/');
        }
    }
}
