var_POPUP_URL = 'http://clicktools.com/survey?iv=b41138b66d6a119';
var_NO_POPUP_DAYS = 30;
var_SAMPLE_PER_THOUSAND = 1000;
var_DDA_DELAY_SECS = 0;

function popupwindow(url, w, h){
  window.open(url,"popup","toolbar=no,location=no,directories=no,"+
   "status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,"+
   "width="+w+",height="+h).blur();
  return false;
}

function getcookieval (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) {
    endstr = document.cookie.length;
  }
  return unescape(document.cookie.substring(offset, endstr));
}

function getcookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if(document.cookie.substring(i, j) == arg)
      return getcookieval (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function setcookie (name, value) {
  var argv = setcookie.arguments;
  var argc = setcookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
}

function sample() {
  s = Math.floor(Math.random()*1000)+1;
  return (s < var_SAMPLE_PER_THOUSAND);
}

function survey() {
  if(getcookie('surveyedthismonth') == null) {
    if(sample()) {
      setTimeout('popupwindow(\''+var_POPUP_URL+'\', 750, 500)', var_DDA_DELAY_SECS*1000);
      var expdate = new Date();
      expdate.setTime(expdate.getTime()+(var_NO_POPUP_DAYS*24*60*60*1000));
      setcookie('surveyedthismonth','true',expdate);
    }
  }
}

survey();
var gotFlash6 = false;
var gotFlash7 = false;
var gotFlash8 = false;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if(isIE && isWin)
{
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n'); 
	document.write('gotFlash6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'); 
	document.write('gotFlash7 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n'); 
	document.write('gotFlash8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n'); 
	document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

function check_flash(strFlashSrc,strFlashUrl,strImageSrc,strImageAltText,strImageUrl,strText,strSmallText)
{
	var strString = '';
	var blnDebug = false;

	strString = 'Debug scriping:-\n\n' + strFlashSrc + '\n' + strFlashUrl + '\n' + strImageSrc + '\n' + strImageAltText + '\n' + strImageUrl + '\n' + strText + '\n' + strSmallText;
	
	if(blnDebug){alert(strString);}

	if(hasFlashPlayer())
	{
		var strFlashString = '';

		strFlashString += '<div id="divFlashHomepage">';
		strFlashString += '	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="378" height="219" id="" align="top" border="-1">';
		strFlashString += '		<param name="allowScriptAccess" value="sameDomain"/>';
		strFlashString += '		<param name="movie" value="' + strFlashSrc + '?clickTag=' + strFlashUrl + '"/>';
		strFlashString += '		<param name="quality" value="high"/>';
		strFlashString += '			<embed src="' + strFlashSrc + '?clickTag=' + strFlashUrl + '" quality="high" bgcolor="#ffffff" width="378" height="219" name="" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		strFlashString += '	</object>';
		strFlashString += '</div>';

		document.write(strFlashString);
		
		if(blnDebug){alert(strFlashString);}
	}
	else
	{
		var strNonFlashString = '';

		//Flash in .dcr file, but no flash player on client machine : display static image

		//Restructure homepage will pass both strText and strSmallText an undefined due to differences in homepage dcrs
		//Only build html for the reskin homepage(s) for this reason

		strNonFlashString += '<a href="' + strImageUrl + '" target="_blank"><img src="' + strImageSrc + '" title="' + strImageAltText + '" width="378" border="0"></a>';

		if(typeof(strText) != "undefined")
		{
			strNonFlashString += '<div class="spacer-2px"><img src="/shared/images/spacer.gif" height="2" width="1" alt=""></div>';
			strNonFlashString += '	<table width="378" border="0" cellpadding="0" cellspacing="0">';
			strNonFlashString += '		<tr>';
			strNonFlashString += '			<td class="padding-left-11px">';
			strNonFlashString += '				<div class="homepage-section-plain-title"><a class="directory-section-title" href="' + strImageUrl + '" title="' + strText + '">' + strText + '</a></div>';

			if(typeof(strSmallText) != "undefined")
			{			
				strNonFlashString += '				<div class="homepage-section-summary">' + strSmallText + '</div>';
			}

			strNonFlashString += '			</td>';
			strNonFlashString += '		</tr>';
			strNonFlashString += '	</table>';
			strNonFlashString += '</div>';
		}

		document.write(strNonFlashString);

		if(blnDebug){alert(strNonFlashString);}
	}
}

function hasFlashPlayer()
{
	if(navigator.plugins && navigator.plugins["Shockwave Flash"])
	{
		var flashDesc = navigator.plugins["Shockwave Flash"].description;
		var flashVer = parseInt(flashDesc.charAt(flashDesc.indexOf(".") - 1));

		if (flashVer == 6) gotFlash6 = true;
		if (flashVer == 7) gotFlash7 = true;
		if (flashVer == 8) gotFlash8 = true;	
		
	}
	
	if (gotFlash6 == true || gotFlash7 == true || gotFlash8 == true)
	{
		var showFlash = "true";
		
	}
	return (showFlash);
}
