/**
 * Function returns JS for normal banner
 */
function banner_get_normal(zoneid) {
	var awrz_rnd = Math.floor(Math.random()*99999999999);

	if (!document.phpAds_used) document.phpAds_used = ',';
	var awrz_protocol = location.protocol.indexOf('https')>-1?'https:':'http:';

	banner  = "<" + "script language='JavaScript' type='text/javascript' src='";
	banner += awrz_protocol+"//"+awrz_adserver+"/adjs.php?n=" + zoneid;
	banner += "&zoneid=" + zoneid + "&target=_blank";
	banner += "&exclude=" + document.phpAds_used;
	banner += "&loc=" + escape(window.location);
	if (document.referrer)
		banner += "&referer=" + escape(document.referrer);
	banner += '&r=' + awrz_rnd;
	banner += "&ct0=" + escape(document.phpAds_ct0);

	banner += "'><" + "/script>\n";

	return banner;
}

/**
 * Function loads MAX page for banner text
 */
function banner_video_flash() {
        var zoneid = "99955";
        var banner = "";

        connected_banner = banner_zone_is_connected( zoneid );

        if ( connected_banner )
                search_str = "&bannerid=" + connected_banner;
        else
                search_str = "&zoneid=" + zoneid;

        var awrz_rnd = Math.floor(Math.random()*99999999999);

        banner  = "<" + "script language='JavaScript' type='text/javascript' src='";
        banner += "http://"+awrz_adserver+"/adjs_flash.php?n=" + zoneid;
        banner += search_str + "&target=_blank";
        banner += "&exclude=" + document.phpAds_used;
        banner += "&loc=" + escape(window.location);
        if (document.referrer)
                banner += "&referer=" + escape(document.referrer);
        banner += '&r=' + awrz_rnd;
        banner += "&ct0=" + escape(document.phpAds_ct0);
        banner += "'><" + "/script>";

        document.write( banner );
}

/**
 * Returns bannerid if some other banner has connected this zone with a certain banner
 */
function banner_zone_is_connected( zoneid ) {
        if ( !connect_zone || !connect_banner )
                return false;

        if ( connect_zone == zoneid )
                return connect_banner;

	connect_zone = connect_zone + '';

        if ( connect_zone.indexOf(',') != -1 ) {
                var tmp = ',' + connect_zone + ',';
                if ( tmp.indexOf(',' + zoneid + ',') >= 0 )
                        return connect_banner;
        }

        return false;
}


/**
 * Function returns JS for normal banner. JS does not document.write this banner, it is left only in 'phpadsbanner' variable.
 */
function banner_get_normal_variable(zoneid) {
        var awrz_rnd = Math.floor(Math.random()*99999999999);

        if (!document.phpAds_used) document.phpAds_used = ',';
        var awrz_protocol = location.protocol.indexOf('https')>-1?'https:':'http:';

        banner  = "<" + "script language='JavaScript' type='text/javascript' src='";
        banner += awrz_protocol+"//"+awrz_adserver+"/adjs_var.php?n=" + zoneid;
        banner += "&zoneid=" + zoneid + "&target=_blank";
        banner += "&exclude=" + document.phpAds_used;
        banner += "&loc=" + escape(window.location);
        if (document.referrer)
                banner += "&referer=" + escape(document.referrer);
        banner += '&r=' + awrz_rnd;
        banner += "&ct0=" + escape(document.phpAds_ct0);

        // is this zone connected?
        connected_banner = banner_zone_is_connected(zoneid);
        if ( connected_banner )
                banner += "&bannerid=" + connected_banner;

        banner += "'><" + "/script>\n";

        return banner;
}
