function quoted(str){	return (str != null) ? '"' + str + '"' : '""';}
function aatv_encodeURIComponent(str){
	if (typeof(encodeURIComponent) == 'function')	return encodeURIComponent(str);
	else	return escape(str);
}
function aatv_add2_url(param, value){	if (value)	window.aatv_ad_url += ';' + param + '=' + value;}
function aatv_add2_url_esc(param, value){
	if (value)	aatv_add2_url(param, aatv_encodeURIComponent(value));
}
function aatv_add_color(param, value, rand){
	if(value && typeof(value) == 'object')	value = value[rand % value.length];
	aatv_add2_url('color_' + param, value);
}
function aatv_get_user_data(w, date){
var s=w.screen;var n=navigator;var javEnab=navigator.javaEnabled();var tz=-date.getTimezoneOffset();

if(s){
	aatv_add2_url("u_h", s.height);aatv_add2_url("u_w", s.width);aatv_add2_url("u_cd", s.colorDepth);
	aatv_add2_url("u_ah", s.availHeight);aatv_add2_url("u_aw", s.availWidth);
}

aatv_add2_url("u_tz", tz);aatv_add2_url("u_his", history.length);aatv_add2_url("u_java", javEnab);

if(n.plugins)	aatv_add2_url("u_nplug", n.plugins.length);

if(n.mimeTypes)	aatv_add2_url("u_nmime", n.mimeTypes.length);

}

function aatv_write_iframe(w, d, ad_url){
ad_url=ad_url.substring(0, 1000);ad_url=ad_url.replace(/%\w?$/, '');

/* invalid iframe stuff
' marginwidth="0"' +
' marginheight="0"' +
' vspace="0"' +
' hspace="0"' +
' allowtransparency="true"' + */

//d.write('--<div style="width:600px;">'+ad_url+'</div>---');
d.write('<if'+'rame' +
' name="aatv_ads_frame"' +
' width=' + quoted(w.aatv_ad_wid) +
' height=' + quoted(w.aatv_ad_hei) +
' frameborder="0"' +
' src=' + quoted(ad_url)  +
' scrolling="no"></if'+'rame>');

/*d.write('<div style="width:'+w.aatv_ad_wid+'px;"><a href="mail:info@artsandtv.com" style="float:left">Feedback</a><a href="http://ArtsandTV.com" style="float:right">Ads.by.ArtsandTV.com</a></div>');
*/
}
/*
if(document.all){
	aatv_wid=parent.document.all['aatv_ads_frame'].width;
	aatv_hei=parent.document.all['aatv_ads_frame'].height;
}else if(document.getElementById){
	aatv_wid=parent.document.getElementById['aatv_ads_frame'].width;
	aatv_hei=parent.document.getElementById['aatv_ads_frame'].height;
}
*/
function aatv_show_ad() {
var nullval=null; var w=window; var d=document; var date=new Date(); var rand=date.getTime().toString().substring(0,10);

w.aatv_ad_url='http://2.go.globaladsales.com/?n='+ rand;
//w.aatv_ad_url='http://2.go.aaotv.com/?n='+ rand;

/* TESTING STUFF */
aatv_add2_url_esc('ip', w.ip);

/*ArtsandTV stuff*/
aatv_add2_url_esc('zoneid', w.aatv_zoneid);
aatv_add2_url('ct0', w.aatv_ct0);
aatv_add2_url('aatv_wid', w.aatv_ad_wid);
aatv_add2_url('aatv_hei', w.aatv_ad_hei);

aatv_add2_url('lmt', w.aatv_last_modified_time);
aatv_add2_url('hl', w.aatv_language);

if(w.aatv_country)
	aatv_add2_url('gl', w.aatv_country);
else
	aatv_add2_url('gl', w.aatv_gl);

aatv_add2_url('gr', w.aatv_region);
aatv_add2_url_esc('gcs', w.aatv_city);
aatv_add2_url('region', w.aatv_ad_region);
aatv_add2_url('feedback_link', w.aatv_feedback);
//aatv_add2_url_esc('referer', w.aatv_ref_url);
//aatv_add2_url_esc('loc', w.aatv_page_loc);
//aatv_add2_url_esc('url', w.aatv_page_url);

if (w.aatv_ad_channel) {
	var chnl=w.aatv_ad_channel.toLowerCase();aatv_add2_url_esc('channel', chnl);
	var pv_ch='';var arr=chnl.split('+');

	for (var i=0; i < arr.length; i++){
		var ch=arr[i];	pv_ch += ch + '+';
	}
	aatv_add2_url_esc('pv_ch', pv_ch);
}

aatv_add2_url_esc('alternate_ad_url', w.aatv_alternate_ad_url);
aatv_add2_url('num_ads', w.aatv_max_num_ads);
aatv_add_color('bg', w.aatv_color_bg, rand);
aatv_add_color('text', w.aatv_color_text, rand);
aatv_add_color('link', w.aatv_color_link, rand);
aatv_add_color('url', w.aatv_color_url, rand);
aatv_add_color('border', w.aatv_color_border, rand);
aatv_add_color('line', w.aatv_color_line, rand);
aatv_add2_url('kw_type', w.aatv_kw_type);
aatv_add2_url_esc('kw', w.aatv_kw);
aatv_add2_url_esc('contents', w.aatv_contents);



if (aatv_onpage(w, d) && d.body) {
	var scr_h=d.body.scrollHeight;	var clt_h=d.body.clientHeight;
	if (clt_h && scr_h)	aatv_add2_url_esc('cc', Math.round(clt_h * 100 / scr_h));
}

aatv_get_user_data(w, date);
aatv_write_iframe(w, d, w.aatv_ad_url);

/* TESTING */
w.ip=nullval;

w.aatv_ct0=nullval;
w.aatv_zoneid=nullval;

w.aatv_ad_wid=nullval;
w.aatv_ad_hei=nullval;

w.aatv_feedback=nullval;
w.aatv_page_loc=nullval;
w.aatv_ref_url=nullval;
w.aatv_ad_region=nullval;

w.aatv_page_url=nullval;
w.aatv_language=nullval;
w.aatv_gl=nullval;
w.aatv_country=nullval;
w.aatv_region=nullval;
w.aatv_city=nullval;

w.aatv_max_num_ads=nullval;
w.aatv_ad_channel=nullval;
w.aatv_contents=nullval;
w.aatv_alternate_ad_url=nullval;

w.aatv_color_bg=nullval;
w.aatv_color_text=nullval;
w.aatv_color_link=nullval;
w.aatv_color_url=nullval;
w.aatv_color_border=nullval;
w.aatv_color_line=nullval;

w.aatv_kw_type=nullval;
w.aatv_kw=nullval;
}

function aatv_onpage(w, d) {	return w.top.location == d.location;}

function aatv_in_adframe(w, d) {
var documentElement=d.documentElement;

if(aatv_onpage(w, d)) return false;

if(w.aatv_ad_wid && w.aatv_ad_hei){
	var wd=1;var ht=1;
	if(w.innerHeight){
		wd=w.innerWidth;	ht=w.innerHeight;
	}else if(documentElement && documentElement.clientHeight){
		wd=documentElement.clientWidth;	ht=documentElement.clientHeight;
	}else if (d.body){
		wd=d.body.clientWidth;	ht=d.body.clientHeight;
	}

	if(ht > 2 * w.aatv_ad_hei || wd > 2 * w.aatv_ad_wid)	return false;

}

return true;

}

function aatv_init_globals(){
var w=window;var d=document;var loc=d.location;var ref=d.referrer;var nullval=null;

if(w.aatv_page_url == nullval){
	w.aatv_page_url=ref;
	if(!aatv_in_adframe(w, d)){
		w.aatv_page_url=loc;
		w.aatv_last_modified_time=Date.parse(d.lastModified) / 1000;
		w.aatv_ref_url=ref;
	}
}else{
	w.aatv_page_loc=ref;
	if(!aatv_in_adframe(w, d))	w.aatv_page_loc=loc;
}

}

aatv_init_globals();
aatv_show_ad();
