abc_ad_url = '';
abc_org_error_handler = window.onerror;

function quoted(str) 
{
	return (str != null) ? '"' + str + '"' : '""';
}

function abc_encodeURIComponent(str) 
{
	if (typeof(encodeURIComponent) == 'function') 
	{
		return encodeURIComponent(str);
	} 
	else 
	{
		return escape(str);
	}
}

function abc_write_tracker(tracker_event)
{
	var qloc = window.abc_ad_url.indexOf('?');
	var img_src = 'http://www.abcsearch.com/af/imp.gif?event=';
	img_src += tracker_event;
	if (qloc != -1 && qloc+1 < window.abc_ad_url.length)
	{
		img_src += '&' + window.abc_ad_url.substring(qloc+1);
	}
	var img_tag = '<i' + 'mg height="1" width="1" border="0" ' +
			'src=' + quoted(img_src) +
			' />';
	document.write(img_tag);
}

function abc_append_url(param, value)
{
	if (value || value == 0)
	{
		window.abc_ad_url += '&' + param + '=' + value;
	}
}

function abc_append_url_esc(param, value)
{
	if (value)
	{
		abc_append_url(param, abc_encodeURIComponent(value));
	}
}

function abc_show_ad()
{
	var w = window;
	w.onerror = w.abc_org_error_handler;
	w.abc_ad_url = 'http://www.abcsearch.com/adntfy/?';
	urlpath = (w.backfil) ? w.abc_referrer : (new String(w.abc_page_url));
	if(urlpath.search(/http:\/\//i)==0)
	{
		w.abc_ad_url+='url='+abc_encodeURIComponent(urlpath);
	}
	else
	{
		w.abc_ad_url+='url=local';
	}

	abc_append_url_esc('abc_host_name', w.abc_host_name);
	abc_append_url_esc('abc_ad_user', w.abc_ad_user);
	abc_append_url_esc('abc_subid', w.abc_subid); 
	abc_append_url_esc('abc_kws', w.abc_kws);
	abc_append_url_esc('abc_banner_width', w.abc_banner_width );
	abc_append_url_esc('abc_banner_height', w.abc_banner_height);
	abc_append_url('abc_v_ad_count', w.abc_v_ad_count);
	abc_append_url('abc_h_ad_count', w.abc_h_ad_count);
	abc_append_url('abc_size_title', w.abc_size_title);
	abc_append_url('abc_size_text', w.abc_size_text);
	abc_append_url('abc_size_url', w.abc_size_url);
	abc_append_url('abc_size_border_text', w.abc_size_border_text);
	abc_append_url('abc_size_border_outer', w.abc_size_border_outer);
        abc_append_url('abc_size_border_inner', w.abc_size_border_inner);
	abc_append_url('abc_ad_line_space', w.abc_ad_line_space);

	abc_append_url_esc('abc_color_bg', w.abc_color_bg);
	abc_append_url_esc('abc_color_text', w.abc_color_text);
	abc_append_url_esc('abc_color_title', w.abc_color_title);
	abc_append_url_esc('abc_color_url', w.abc_color_url);
	abc_append_url_esc('abc_color_border', w.abc_color_border);
	abc_append_url_esc('abc_color_border_text', w.abc_color_border_text);
	
	//Font-weight, Text alignment changes - Sreedhar - 25 June 2007  - Start
	abc_append_url_esc('abc_font_weight', w.abc_font_weight);
	abc_append_url_esc('abc_text_alignment', w.abc_text_alignment);
	//Font-weight, Text alignment changes - Sreedhar - 25 June 2007  - End
	abc_append_url_esc('abc_scroll_title', w.abc_scroll_title);	//OptionalTitleScrolling - Sreedhar - 02 August 2007
	abc_append_url_esc('abc_underline_title', w.abc_underline_title);	//OptionalTitleUnderline - Sreedhar - 14 August 2007
	abc_append_url_esc('abc_new_window', w.abc_new_window);	//Optional Open In New Window  - Arun Dhwaj - 13 Nov'07
	abc_append_url_esc('abc_banner_heading', w.abc_banner_heading);
	abc_append_url_esc('abc_adult_filter', w.abc_adult_filter);
	abc_append_url_esc('abc_adult_content_host', w.abc_adult_content_host);
	abc_append_url_esc('abc_banner_heading_alignment', w.abc_banner_heading_alignment);
	abc_append_url_esc('abc_trunc_text', w.abc_trunc_text);
	abc_append_url_esc('abc_crawl_content', w.abc_crawl_content);

	abc_append_url_esc('loc', w.abc_page_location);
	if (w.abc_noframe)
	{
		abc_append_url('nloc', document.location);
	}
	if (w.abc_onpage && document.body)
	{
		var scr_h = document.body.scrollHeight;
		var clt_h = document.body.clientHeight;
		if (clt_h && scr_h)
		{
			abc_append_url_esc('cc', Math.round(clt_h*100/scr_h));
		}	
	}
	w.abc_ad_url = w.abc_ad_url.substring(0, 1000);
	w.abc_ad_url = w.abc_ad_url.replace(/%\w?$/, '');	
	if (abc_ad_output == 'html')
	{
		if (w.name == 'abc_ads_frame')
		{
			abc_write_tracker('reboundredirect');
		}
		else
		{
			document.write('<ifr' + 'ame' +' name="abc_ads_frame"' +' width=' + quoted(w.abc_banner_width) +' height=' + quoted(w.abc_banner_height) +' frameborder=' + quoted(w.abc_ad_frameborder) +' src=' + quoted(w.abc_ad_url) +' marginwidth="0"' +' marginheight="0"' +' vspace="0"' +' hspace="0"' +' allowtransparency="true"' +' scrolling="no">');
			abc_write_tracker('noiframe');
			document.write('</ifr' + 'ame>');
		}
	}
	w.abc_page_location = null;
	w.abc_referrer_url = null;
	w.abc_host_name = null;
}

function abc_error_handler(message, url, line) 
{
  abc_show_ad();
  return true;
}

function abc_in_adframe()
{
	var w = window;
	var d = document;
	if (w.top.location == d.location)
	{
		w.abc_onpage = 1;
		return false;
	}
	if (w.abc_ad_width && w.abc_ad_height)
	{
		var wd = 1;
		var ht = 1;
		if (w.innerHeight)
		{
			wd = w.innerWidth;
			ht = w.innerHeight;
		}
		else if (d.documentElement && d.documentElement.clientHeight)
		{
			wd = d.documentElement.clientWidth;
			ht = d.documentElement.clientHeight;
		}
		else if (d.body)
		{
			wd = d.body.clientWidth;
			ht = d.body.clientHeight;
		}
		if (ht > 2 * w.abc_ad_height || wd > 2 * w.abc_ad_width)
		{
			w.abc_noframe = 1;
		}
	}
	return true;
}


window.onerror = abc_error_handler;
if (window.abc_ad_frameborder == null)
{
	abc_ad_frameborder = 0;
}
if (window.abc_ad_output == null)
{
	abc_ad_output = 'html';
}
if (window.abc_page_url == null)
{
	abc_page_url = document.referrer;		//if frame is present we have to get the referrer not the location
	abc_host_name=document.location.hostname;
	if (!abc_in_adframe())
	{
		abc_page_url = document.location;		//if page is not framed one get the location of the document
		abc_host_name=document.location.hostname;
		abc_last_modified_time = Date.parse(document.lastModified) / 1000;
		abc_referrer_url = document.referrer;
	}
}
else
{
	abc_page_location = document.referrer;
	if (!abc_in_adframe())
	{
		abc_page_location = document.location;
		abc_host_name=location.hostname;
	}
}
abc_show_ad();
