/**
 * FILE DEPRECATED
 * Use http://opinion.peytz.dk/decide2.js
 */
if (typeof(pcoq_customername)=='undefined') {
    var pcoq_customername = 'undefined';
}
if (typeof(pcoq_hostname)=='undefined') {
    var pcoq_hostname = pcoq_customername + '.opinion.peytz.dk';
}

var pcoq_popupurl = '//'+pcoq_hostname+'/pop.js.php?id=';
var pcoq_dataurl = '//'+pcoq_hostname+'/js/data/surveys.js.php?loc='+escape(location.href);

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,''); };
Array.prototype.exists = function(v) {for(var i in this) if(v==this[i]) return true; return false;};
Array.prototype.intersect = function(a) {var r = new Array(); for(var i=0; i<this.length; i++) if(!a.exists(this[i])) r[r.length]=this[i]; return r;};

function pcoq_getCookie(name){
    var dc = document.cookie, begin=0, end=0;
    if ((begin=dc.indexOf(name+"=")) != -1) {
        if ((end=dc.indexOf(";", begin+name.length+1)) == -1) end = dc.length;
        return unescape(dc.substring(begin+name.length+1, end));
    }
    return null;
}

function pcoq_setCookie(name, value, expires) {
    document.cookie = name + "=" + escape(value) +
        ((expires == null) ? "" : "; expires=" + (new Date(expires).toGMTString()) ) + 
        "; path=/; domain=" + pcoq_cookiedomain;
}

function pcoq_popup(id) {
    document.write("<script type='text/javascript' src='"+pcoq_popupurl+id+"&time="+(new Date().getTime())+"'><\/script>");
}

function pcoq_decide() {
    pcoq_setCookie('pcoq_data', '456', new Date().getTime() + pcoq_datadelay*1000)
    var decided_ids = (pcoq_getCookie('pcoq_decided')!=null ? (''+pcoq_getCookie('pcoq_decided')).split("-") : new Array());
    var possible_ids = pcoq_active_ids.intersect(decided_ids);
    if(possible_ids.length == 0) return;
    var this_id = possible_ids[Math.floor(Math.random() * possible_ids.length)];
    if(Math.floor( Math.random() * eval('pcoq_frq.q'+this_id) ) == 0) {
        pcoq_popup(this_id);
        pcoq_setCookie('pcoq_annoy', this_id, new Date().getTime() + pcoq_annoydelay*1000);
    }    
    decided_ids[decided_ids.length] = this_id;
    pcoq_setCookie('pcoq_decided', decided_ids.join("-"), new Date().getTime() + 1000*60*60*24*365);
}

var pcoq_test = pcoq_getCookie('pcoq_test');
if(pcoq_test) pcoq_popup(pcoq_test);
else if(!pcoq_getCookie('pcoq_annoy') && !pcoq_getCookie('pcoq_data')) {
    document.write('<script type="text/javascript" src="'+pcoq_dataurl+'&time='+(new Date().getTime())+'"><\/script>');
}


