gen_ads = true;
offset = 0;

function generate_ad_divs () {
	document.write("<div id=\"ads_container\"><div id=\"ads\"></div><div><div id=\"ad_caption\"></div><div id=\"ad_nav\"></div></div></div>");
}

function generate_ads (field,cur_offset,dir) {
	if (typeof(window["ad_auto_cycle"]) != "undefined") {clearTimeout(ad_auto_cycle);}
	if (dir != null) {
		document.getElementById("ad_"+dir).style.backgroundColor = "#000000";
		document.getElementById("ad_"+dir).style.color = "#FFFFFF";
	}
    var xmlHttpReq2 = false;
    var self2 = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self2.xmlHttpReq2 = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self2.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self2.xmlHttpReq2.open('GET', '/scripts/generate_ads.php'+(cur_offset != null ? '?cur_offset='+cur_offset+'&dir='+dir : ''), true);
    self2.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self2.xmlHttpReq2.onreadystatechange = function() {
        if (self2.xmlHttpReq2.readyState == 4) {
            return_ads(field, self2.xmlHttpReq2.responseText);
        }
    }
    self2.xmlHttpReq2.send(null);
}

function return_ads (field, ads) {
	var ad = ads.split("\n");
	var offset = ad[0];
	var ad_html = "";
	var ad_style = "";
	if (ad[3].length > 0) {
		ad_html += "<a href=\""+ad[1]+"\" onclick=\"window.open('"+ad[1]+"');return false;\" title=\""+ad[2]+"\"><img src=\""+ad[3]+"\" alt=\""+ad[2]+"\" /></a>";
		document.getElementById(field).style.border = "0";
		document.getElementById(field).style.padding = "0";
		document.getElementById(field).style.width = "468px";
		document.getElementById(field).style.height = "60px";
	} else {
		ad_html += "<a href=\""+ad[1]+"\" onclick=\"window.open('"+ad[1]+"');return false;\" title=\""+ad[1]+"\">"+ad[2]+"</a><br />"+ad[4];
		document.getElementById(field).style.border = "1px solid #C0C0C0";
		document.getElementById(field).style.padding = "4px";
		document.getElementById(field).style.width = "458px";
		document.getElementById(field).style.height = "50px";
	}
	document.getElementById(field).innerHTML = ad_html;
	document.getElementById("ad_caption").innerHTML = "non-profit ads for sites and services I &hearts;";
	document.getElementById("ad_nav").innerHTML = "<b onclick=\"generate_ads('ads',"+offset+",'prev');\" title=\"previous ad\" id=\"ad_prev\">&lt;</b> <span onclick=\"generate_ads('ads',"+offset+",'rand');\" title=\"random ad\" id=\"ad_rand\">random</span> <b onclick=\"generate_ads('ads',"+offset+",'next');\" title=\"next ad\" id=\"ad_next\">&gt;</b>";
	ad_auto_cycle = setTimeout("generate_ads('"+field+"',"+offset+",'next')",600000);
}