function randomSurvey(scale)
 {
    var expdate = new Date ();
    var surveyCookieName = "IExpress2005";
    var percentOfferedSurvey = 100;  //CHANGE THIS PARAMETER TO CONTROL SAMPLING RATE
    //var surveyLocation = "http://www.insightexpress.com/s/WebT79991?onfinish=close";
    var surveyLocation = "http://www.insightexpress.com/s/eMar88181?UID2=site";  //sep05 url
    var popupNewWindow = true;  //or show the survey in the same window.

    expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // 1 year from now
                  var stored_value = GetCookie(surveyCookieName);
    var dd=new Date();
    cn= Math.round(dd.getTime() / 100) % 100;
    if ((cn <= percentOfferedSurvey) && (stored_value == null))
    {
//            SetCookie(surveyCookieName, "alreadyOffered", expdate);
            SetCookie(surveyCookieName, "alreadyOffered");  //MJ 20041119  - by removing the date, the cookie will expire when they close the browser..
//        window.open(surveyLocation,'new_window','width=640,height=500,resizable=yes,scrollbars=yes');
        window.open(surveyLocation,'new_window','width=320,height=250,resizable=yes,scrollbars=yes');  //MJ 20041119 - making popup smaller
    }
    //MJ 20041119:
    else if (location.search.indexOf("popup=y") != -1)
    {
        window.open(surveyLocation,'new_window','width=320,height=250,resizable=yes,scrollbars=yes');  //MJ 20041119 - making popup smaller
    }

 }

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" : "");
}

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;
        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;
}

var goToSearch = false;
function searchYes()
{
        goToSearch = true;
}
function searchNo()
{
        goToSearch = false;
}
window.onload = function() { document.onkeydown = register; var x = document.forms[0].elements[0];      x.onkeydown = register; }
function register(e)
{
        if (!e) e = window.event;
        var keyInfo = e['keyCode']; //keyCode 13 is equivalent to the enter key
        //if enter is pressed and search field is highlighted, do search, else, do nothing
        if (keyInfo == 13 && goToSearch == true)
        {
                return true;
        }
        else if (keyInfo == 13 && goToSearch == false)
        {
                return false;
        }
}

 function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

 function setMessage(theText) {
         if ( theText.value == "" ) {
              theText.value = theText.defaultValue 
         }
 } 

 function suggest(inputString,state,script){
                 if(inputString.length == 0) {
                        $('#suggestions').fadeOut();
                 } else {
                 $('#name').addClass('load');
                         $.post(script, {city: ""+inputString+"", state: ""+state+""}, function(data){
                                if(data.length >0) {
                                        $('#suggestions').fadeIn();
                                        $('#suggestionsList').html(data);
                                        $('#name').removeClass('load');
                                }
                        });
                }
        }

function fill(thisValue) {
                $('#venue_city').val(thisValue);
                setTimeout("$('#suggestions').fadeOut();", 200);
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

