// call quicktake survey
GenRandomSurvey();
//*************************************************** 
function GenRandomSurvey() 
{ 
       
        // CUSTOMIZE THIS SECTION
		// Percentage of people asked to take survey 
        var pctOfferedSurvey = 80; 
        // CUSTOMIZE !!! URL to the html page to open in the popup 
        //  The URL of the survey
        var popupLocation = "/asq-survey.html"; 
        // CUSTOMIZE !!! 
	// Properties of the pop-up - width,height,resizable,scrollbars 
        var popupProps="width=600,height=600,left=0,resizable=yes,scrollbars=yes"; 
        // CUSTOMIZE !!! 
	//  For every survey you will want to use another cookie name. Use org identifier plus serial number. Original survey cookies were ASQ01, ASQ2  
        var cookieSurveyDisplayed = "asqsurvey01";
        // CUSTOMIZE !!! Number of repeat survey invitations allowed 
        var numInvitationsAllowed = 1; 

        var expDate = new Date (); 
        var milOneYear = (365 * 24 * 60 * 60 * 1000); 
        var storedValue; 
       
        // Set cookieSurveyDisplayed expiration to one year from now 
        expDate.setTime (expDate.getTime() + milOneYear); 
               
        // Check for survey displayed previously 
        var numReturns = GetCookie(cookieSurveyDisplayed); 
       
        if ( numReturns == "" ) { 
                numReturns = 1; 
        } else if (numReturns <= numInvitationsAllowed ) { 
                numReturns ++; 
        } 
       
        SetCookie(cookieSurveyDisplayed, numReturns, expDate); 
               
        // Get random value using the current time in milliseconds 
        var dd=new Date(); 
        cn= Math.round(dd.getTime() / 100) % 100; 
                               
        // Check for random condition met 
        if ((cn <= pctOfferedSurvey) &&
		(numReturns <= numInvitationsAllowed)) 
        { 
                window.open(popupLocation,'new_window',popupProps); 
        } 
       
} 
function GetCookie (name) 
{ 
        var arg = name + "="; 
        var alen = arg.length; 
        var clen = document.cookie.length; 

        if( (document.cookie == null) ||
		(document.cookie.length == null)) 
        { 
                return null; 
        } 

        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 getCookieVal(offset) { 
        var endstr = document.cookie.indexOf(";", offset); 
        if (endstr == -1) 
                endstr = document.cookie.length; 
        return unescape(document.cookie.substring(offset, endstr)); 
} 
function SetCookie (name,value,expires,path,domain,secure) 
{ 
        document.cookie = name + "=" + escape (value) + 
        ((expires) ? "; expires=" + expires.toGMTString() : ""); 
        ((path) ? "; path=" + path : "") + 
        ((domain) ? "; domain=" + domain : "") + 
        ((secure) ? "; secure" : ""); 
}
