function getURLParam(strParamName){
  var strReturn = "";
  //var strHref = window.location.href;
  var strHref = document.getElementById("surveyAdPromo").src;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

x = getURLParam("id"); 
logo = getURLParam("logo"); 
ad = getURLParam("ad"); 
to = getURLParam("to"); 
p = getURLParam("p"); 
bc = getURLParam("bc"); 
boc = getURLParam("boc"); 

var promo = new Object();

if (x && x!='') promo.survey = x;
else promo.survey = window.location.href;

if (to && to!='') promo.to = Math.floor(parseInt(to))*1000;
else promo.to = 15000;

if (p && p!='') promo.p = Math.floor(parseInt(p));
else promo.p = 10;

if (ad && ad!='') promo.ad_image = ad;
else promo.ad_image = 'http://www.countingopinions.com/survey/ad.jpg';
promo.ad_width = '720';
promo.ad_height = '480';

if (bc && bc!='') promo.bc = '#' + bc;
else promo.bc = 'green';
if (boc && boc!='') promo.boc = '#' + boc;
else promo.boc = 'blue';

function closeEm() {
	document.getElementById("promoAd").style.display = "none";
}
function gotoEm() {
	window.open(x);
	closeEm();
}

promo.putObjects = function () {
// <promoSmall>
	document.write('<div id="promoAd" style="position:absolute;width:'+ promo.ad_width +'px;height:'+ promo.ad_height +'px;z-index:9999;left:60px;top:60px;background-color:#ffffff;">');
// object
	document.write('<a href="'+promo.survey+'" alt="survey" target="_blank">');
	document.write('<img src="'+promo.ad_image+'" width="'+promo.ad_width+'" height="'+promo.ad_height+'"></a>');
	document.write('<p style="text-align: center; padding: 0; margin: 1px;"><button onClick="gotoEm()" style="background-color:'+promo.bc+'; color: white; font-weight: 600; cursor:hand;" onmouseover="this.style.backgroundColor=\''+promo.boc+'\';"  onmouseout="this.style.backgroundColor=\''+promo.bc+'\';">Yes, please connect me now!</button>');
	document.write('<p style="text-align: center; padding: 0; margin: 1px;" ><button onClick="closeEm()" style="background-color:'+promo.bc+'; color: #eeeeee;" onmouseover="this.style.backgroundColor=\''+promo.boc+'\';"  onmouseout="this.style.backgroundColor=\''+promo.bc+'\';">No thanks.</button>');
	document.write('</div>');
	document.write('</script>');
// </promoSmall>
// <promoBig>
// </promoBig>
	setTimeout('document.getElementById("promoAd").style.display = "none";',promo.to);
}
var ran_number=Math.floor(Math.random()*promo.p); 
if (ran_number==(promo.p-1)) promo.putObjects();