// ---------------------------------------------------------------------
// Create an interstitial survey solicitation.
// Copyright 2007 Desert.Net

var dnInterstitial = {};
function dnShowInterstitial (url, freq, pubId, sectionId) {
    return;
		/*
		if (freq == 0) return;
    if (dnReadCookie("dnPreventInterstitial")) return;
    if (dnRandomRange(0, freq) != 0) return;
    
    var div = document.createElement("div");
    div.id = "dnInterstitialDiv";
    div.style.display = "none";
    
    var blurDiv = document.createElement("div");
    blurDiv.id = "dnInterstitialBlurDiv";
    blurDiv.style.display = "none";
    
    var pageDim = dnPageDimensions();
    blurDiv.style.width = pageDim[0] + "px";
    blurDiv.style.height = pageDim[1] + "px";
    
    document.body.appendChild(blurDiv);
    document.body.appendChild(div);
    
    dnInterstitial.pubId = pubId;
    dnInterstitial.sectionId = sectionId;
    dnXHR(url, _dnShowInterstitial);
		*/
}

function _dnShowInterstitial () {
    if (dnReq.readyState == 4 && dnReq.status == 200) {
        var div = document.getElementById("dnInterstitialDiv");
        var blurDiv = document.getElementById("dnInterstitialBlurDiv");
      
        div.innerHTML = dnReq.responseText;
        blurDiv.style.display = "block";
        div.style.display = "block";
    }
}

// ---------------------------------------------------------------------
// Handle interstitial button clicks.

function dnInterstitialClose () {
    dnCreateCookie("dnPreventInterstitial", "1", 1);
    document.getElementById("dnInterstitialDiv").style.display = "none";
    document.getElementById("dnInterstitialBlurDiv").style.display = "none";
}

function dnInterstitialTakeSurvey () {
    dnInterstitialClose();
    window.open(_dnInterstitialUrl());
}

function dnInterstitialTakeSurveyLater () {
    dnInterstitialClose();
    var popunder = window.open(_dnInterstitialUrl());
    popunder.blur();
    window.focus();
}

function _dnInterstitialUrl () {
    var url = "http://www.magsurveys.com/surveys/001421/start.asp?";
    url += "SID=1421";
    url += "&XID=" + encodeURIComponent(dnInterstitial.pubId);
    url += "&XCK=" + encodeURIComponent(dnInterstitial.sectionId);
    
    return url;
}

// ---------------------------------------------------------------------
// dnXHR() - Basic XMLHttpRequest wrapper.

var dnReq;
function dnXHR (url, callback) {
	dnReq = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			dnReq = new XMLHttpRequest();
        } catch(e) {
			dnReq = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	dnReq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		dnReq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		dnReq = false;
        	}
		}
    }
	if(dnReq) {
		dnReq.onreadystatechange = callback;
		dnReq.open("GET", url, true);
		dnReq.send("");
	}
}

// ---------------------------------------------------------------------
// dnRandomRange() returns a random integer between 'from' and 'to',
// 'from' inclusive, 'to' exclusive. Assumes it'll be passed positive
// integers, where to > from.

function dnRandomRange (from, to) {
    if (from == to) return from;
    
    var range = to - from;
    var seed = (new Date()).getSeconds();
    return Math.floor((Math.random()*(seed + 1)*1000) % range) + from;
}

// ---------------------------------------------------------------------
// Cookie manipulation functions from quirksmode.org

function dnCreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function dnReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function dnEraseCookie(name) {
	dnCreateCookie(name,"",-1);
}

// ---------------------------------------------------------------------
// Page width and height.

function dnPageDimensions () {
    var res = [0,0];
    var woh = ["Width","Height"];
    var doc = document.documentElement ?
        document.documentElement : document.body;
    
    for (var i = 0; i < woh.length; i++) {
        if (doc["client" + woh[i]] && doc["client" + woh[i]]) {
    		res[i] = doc["client" + woh[i]];
    	}

    	if (doc["scroll" + woh[i]] && doc["scroll" + woh[i]] > res[i]) {
    		res[i] = doc["scroll" + woh[i]];
    	}

    	if (doc["offset" + woh[i]] && doc["offset" + woh[i]] > res[i]) {
    		res[i] = doc["offset" + woh[i]];
      	}

      	if (self["inner" + woh[i]] && self["inner" + woh[i]] > res[i]) {
      	    res[i] = self["inner" + woh[i]];
      	}
    }
      	  	
  	return res;
}

// ---------------------------------------------------------------------