
var js_ad_target_qs='';
for (var targetid in js_ad_targets) {
	js_ad_target_qs += 'targets['+targetid+']='+js_ad_targets[targetid]+'&';
}

if (typeof js_ad_keyword == 'undefined') {
	var js_ad_keyword = '';
}
if (typeof js_ad_keyword_field != 'undefined') {
	js_ad_alt_keyword = getQueryVariable(js_ad_keyword_field);
	if (js_ad_alt_keyword) {
		js_ad_keyword = js_ad_alt_keyword;
	}
}

/*
if (!js_ad_alt_keyword) {
	// Get from the referring search
}
*/
	
if (typeof js_ad_language == 'undefined') {
	var js_ad_language = '';
}
if (typeof js_ad_start == 'undefined') {
	var js_ad_start = 1;
}
js_ad_start--;
if (typeof js_ad_count == 'undefined') {
	var js_ad_count = 5;
}
if (typeof js_ad_charlimit == 'undefined') {
	var js_ad_charlimit = '';
}
if (typeof js_ad_feedid == 'undefined') {
	var js_ad_feedid = '';
}
if (typeof js_ad_feedprovider == 'undefined') {
	var js_ad_feedprovider = '';
}
if (typeof js_ad_feedtype == 'undefined') {
	var js_ad_feedtype = '';
}
if (typeof js_ad_go_image == 'undefined') {
	var js_ad_go_image = '';
}
if (typeof js_ad_go_image_top == 'undefined') {
	var js_ad_go_image_top = '';
}
if (typeof js_ad_images == 'undefined') {
	var js_ad_images = '';
}
if (typeof js_ad_image_format == 'undefined') {
	var js_ad_image_format = '';
}
if (typeof js_ad_first_ad_different == 'undefined') {
	var js_ad_first_ad_different = 1;
}
if (typeof js_ad_stylesheet == 'undefined') {
	var js_ad_stylesheet = '';
}
if (js_ad_images > 0) {
	cellheight = 100;
} else {
	cellheight = 71;
}
if (typeof js_ad_format == 'undefined') {
	var js_ad_format = 'leaderboard';
}
switch (js_ad_format) {
case 'leaderboard':
	if (typeof js_ad_width == 'undefined') js_ad_width=768;
	if (typeof js_ad_height == 'undefined') js_ad_height=cellheight + 20;
	break;
case 'skyscraper':
	if (typeof js_ad_width == 'undefined') js_ad_width=180;
	if (typeof js_ad_height == 'undefined') js_ad_height=50 + cellheight * js_ad_count;
	break;
case 'wideskyscraper':
	if (typeof js_ad_width == 'undefined') js_ad_width=600;
	if (typeof js_ad_height == 'undefined') js_ad_height=50 + cellheight * js_ad_count;
	break;
case 'pic_unit':
	if (typeof js_ad_width == 'undefined') js_ad_width=150;
	if (typeof js_ad_height == 'undefined') js_ad_height=50 + cellheight * js_ad_count;
	break;
}

if (typeof uniqid == 'undefined') {
	var uniqid = 0;
}
uniqid++;
var js_ad_onload = '';
if (typeof js_ad_requests == 'undefined') {
	var js_ad_requests = new Array();
}
if (typeof js_ad_statuses == 'undefined') {
	var js_ad_statuses = new Array();
}
if (typeof js_ad_pageload == 'undefined') {
	var d = new Date();
	var js_ad_pageload = 'page' + d.getTime();
}

var iframesrc = '/ads/show_js_ads.php?'
		+ js_ad_target_qs
		+ 'keyword='+escape(js_ad_keyword)
		+ '&request='+escape(window.location.search.substring(1))
		+ '&unique='+js_ad_pageload
		+ '&url='+escape(location.href)
		+ '&referer='+escape(document.referrer)
		+ '&language='+js_ad_language
		+ '&count='+js_ad_count
		+ '&start='+js_ad_start
		+ '&charlimit='+js_ad_charlimit
		+ '&first_ad_different='+js_ad_first_ad_different
		+ '&feedid='+js_ad_feedid
		+ '&feedprovider='+js_ad_feedprovider
		+ '&feedtype='+js_ad_feedtype
		+ '&kid='+getQueryVariable('kid')
		+ '&uid='+getQueryVariable('uid')
		+ '&go_image='+js_ad_go_image
		+ '&go_image_top='+js_ad_go_image_top
		+ '&images='+js_ad_images
		+ '&image_format='+js_ad_image_format
		+ '&format='+js_ad_format
		+ '&width='+js_ad_width
		+ '&height='+js_ad_height
		+ '&stylesheet='+js_ad_stylesheet
		+ '&frameid='+uniqid
		+ '';
//alert(iframesrc);
js_ad_load(js_ad_targets,iframesrc,false);

js_ad_keyword = undefined;
js_ad_language = undefined;
js_ad_count = undefined;
js_ad_start = undefined;
js_ad_charlimit = undefined;
js_ad_first_ad_different = undefined;
js_ad_feedid = undefined;
js_ad_go_image = undefined;
js_ad_go_image_top = undefined;
js_ad_images = undefined;
js_ad_image_format = undefined;
js_ad_format = undefined;
js_ad_width = undefined;
js_ad_height = undefined;
js_ad_stylesheet = undefined;
js_ad_onload = undefined;
//document.write(iframe);



function js_ad_getXmlHttpRequestObject() {
	if (document.all) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function js_ad_load(divids,url,post) {
	var method = post ? 'POST':'GET';
	var xmlhttp = js_ad_getXmlHttpRequestObject();
	xmlhttp.open(method, url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//getChatRequest();

			// deal with response
			var statustxt = '';
			if(xmlhttp.status == 200) {
				statustxt = xmlhttp.responseText;
			} else if(xmlhttp.status ==500) {
				//statustxt = 'Error ';
			} else {
				//statustxt = 'Unknown Response Code '+xmlhttp.status;
			}
			var statustxts = statustxt.split("&iexcl;");
			var i=0;
			for (var divid in divids) {
				// Spit out the content into this div
				var divel = document.getElementById(divid);
				if (!divel) {
					//alert('No such DIV '+divid);
					continue;
				}
				if (statustxts[i]) {
					divel.innerHTML = statustxts[i];
				}
				divel.style.height = "auto";
				i++;
			}
		}
	}
	if (post) {
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(post);
	} else {
		xmlhttp.send(null);
	}
}

function updateAdBlock(uniq,position,keyword) {
	/* Run the ad block at the specified position in the list, specifying the keyword to use */
	var requests = js_ad_requests[uniq];
	var i = 0;
	//alert('updateAdBlock('+uniq+','+position+','+keyword+') '+requests);
	for (var iframeid in requests) {
		i++;
		if (i < position) {
			continue;
		}
		var src = requests[iframeid];
		src += '&force_keyword='+escape(keyword);
		var ifr = document.getElementById(iframeid);
		if (ifr && (!ifr.src || ifr.src==document.location)) {
			ifr.src = src;
			//alert('Update Iframe #'+iframeid+' - '+src);
		}
		break;
	}
}

function updateAdBlocks(uniq) {
	var requests = js_ad_requests[uniq];
	for (var iframeid in requests) {
		var src = requests[iframeid];
		var ifr = document.getElementById(iframeid);
		if (ifr && (!ifr.src || ifr.src==document.location)) {
			ifr.src = src;
		}
	}
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	//alert('Query Variable ' + variable + ' not found');
	return '';
}

function documentHeight(d) {
	var height = 0, sh, oh;
	if (d.height) height = d.height;
	else if (d.body) {
		if (d.body.scrollHeight) height = sh = d.body.scrollHeight;
		//if (d.body.offsetHeight) height = oh = d.body.offsetHeight;
		//if (sh && oh) height = Math.max(sh, oh);
	}
	return height;
}

function autofitIFrame(num) {
	if (!num) {
		return;
	}
	var name = 'jsad'+num;
  	var iframeWin = window.frames[name];
	//var ife = document.getElementById? document.getElementById(name): document.all? document.all[name]: null;
	var ife = document.getElementById(name);
	var doc = iframeWin ? iframeWin.document : ife.contentDocument;
	if (ife) {
		ife.style.height = "auto";
		var height = documentHeight(doc);
		if (height) ife.style.height = height + "px";
		//alert(num+' - '+ife.style.height + ' - ' + height);
	}
}

