
var P_sPIPE = "%7C";	//"|";
var P_sEQ = "%3D";	//"=";

function addGBP(sKey, sURL, sWCfg, bUnd, bNclk, sSupp) {
	sKey=String(sKey);	//.toUpperCase();
	if(P_oPops==null) {
		P_oPops = new Object();
	}
	P_oPops[sKey] = { "key":sKey, "url":sURL, "wcfg":sWCfg, "und":bUnd, "nclk":bNclk, "ckdta":"", "shwd":false, "supp":sSupp };
}


function chkSupp(oPop, oCK, dtNow) {	//ZZZ
	var sCKD = String(oCK[String(oPop["key"])]);	//.toUpperCase()
	if(sCKD == null || sCKD == "undefined" || sCKD == "") {
		oCK[oPop["key"]] = oPop["supp"];
		return(false);
	} else {
		return(true);
	}
}

function chkExtLink(sURL, sDom) {	//ZZZ
	var sURL = String(sURL).toLowerCase();
	var reIntURLs = new RegExp(sDom,"i");
	if(sURL.match(reIntURLs)) {return(false);}
	return(true);
}


function defPopEvts() {	//ZZZ
	if (P_bNet==true) {
		window.captureEvents(Event.CLICK);
		window.onclick=handleClick;
	} else {
		document.onclick=handleClick;
	}
}



function getElementAnchor(objElement) {
	if(objElement == null || String(objElement) == "undefined") {return(null);}
	if(objElement.nodeName == "A") {return(objElement);}
	if(objElement.parentNode == null || String(objElement.parentNode) == "undefined") {return(null);}
	if(objElement.parentNode.nodeName == "A") {return(objElement.parentNode);}
	if(objElement.nodeName == "INPUT") {
		if (objElement.type == "image") { return(objElement); } else { return(null);}
	}
	return(null);
}


function handleClick(evt) {

	//alert("handleClick() new:  P_bExt = " + P_bExt);

	var objClickedElement = null;
	if (P_bNet==false) {
		objClickedElement = window.event.srcElement;
	} else {
		objClickedElement = evt.target;
	}

	var objAnchor = getElementAnchor(objClickedElement);

	if(objAnchor == null) {
		return;
	}

	P_bExt=true;
	var sTURL = String(objAnchor.href);
	if(sTURL=="" || sTURL=="undefined"){P_bExt=false;return;}
	if(sTURL.match(/javascript/i)){
		if(!(sTURL.match(/window\.open/i))) {P_bExt=false;}
		return;
	}

	P_bExt=chkExtLink(sTURL, P_sCDom);
	if(P_bExt==true) {
		showGBP("C");
	}
}



function handleUnload(evt) {
	//alert("handleUnload():  P_bExt = " + P_bExt);
	if (P_bExt==true) {
		showGBP("U");
	}
}



function showGBP(sSrc) {
	if(P_oPops == null) {
		return;
	}
	var sCK = "";
	var bMin = false;

	//alert("showGBP():  sSRC = " + sSrc);
	
	for(var vX in P_oPops) {
		var oPop = P_oPops[vX];
		if( (oPop != null) ) {
		
			//alert("showGBP():  oPop[\"shwd\"] = " + oPop["shwd"] + "\r\n" 
			//	+ "oPop[\"nclk\"] = " + oPop["nclk"]);

		
			if(oPop["shwd"]==false && oPop["key"]!="" && oPop["url"]!="" && oPop["wcfg"]!="") {
				if(sSrc=="U" && oPop["nclk"]==false) {
				}else{
					if(!chkSupp(oPop, P_oCK, P_dtSvNow)){
						var winGBP=window.open(oPop["url"], oPop["key"], oPop["wcfg"]);
						if(winGBP!=null) {
							if(oPop["und"]==true){
								winGBP.blur();
								window.focus();
							}else{
								winGBP.focus();
							}
							oPop["shwd"] = true;
							bMin = true;
						}
					}
				}				
			}
		}
	}
	
	if(bMin == true) {
		for(var vY in P_oCK) {
			if(P_oCK[vY] != null && P_oCK[vY] != "undefined" && P_oCK[vY] != "") {
				if(sCK!=""){
					sCK += P_sPIPE;
				}
				sCK += (vY + P_sEQ + P_oCK[vY]);
			}
		}
		if(sCK!="") {
			sCK = "PLGBPOP=" + sCK + P_sCKSuf;
			document.cookie = sCK;
		}
	}
}



window.addOnloadEvents(defPopEvts);
window.addUnloadEvents(handleUnload);

