var ara_mainurl="http://reklam.ara.com.tr/reklam/";
var ara_defurl="http://reklam.ara.com.tr/reklam/default/";
var sizes=window.ara_format;
var size=sizes.split("x"); 
var rescount=0;


function updateUrl(id,val)
{
    if(id)
    {
        window.ara_show_url+="&"+id+"="+val;
    }
}

function chkAds(win,doc)
{
    var root=doc.documentElement;
    
    if(isFr(win,doc))
        return false;
    if(size[0]&&size[1]){
        var width=1;
        var height=1;
        if(win.innerHeight){
            width=win.innerWidth;
            height=win.innerHeight;
        }else if(root&&root.clientHeight){
            width=root.clientWidth;
            height=root.clientHeight;
        }else if(doc.body)
        {
            width=doc.body.clientWidth;
            height=doc.body.clientHeight;
        }
        
        if(width>2*win.size[0] || height>2*win.size[1])
        {
            return false;
        }
    }
    return true;
}

function isFr(win,doc){
    return win.top.location==doc.location;
}

function createAds() 
{
    var win = window;
    var doc = document;
    var ref=doc.referrer;
    var loc=doc.location;
    chkAds(win,doc);
    
    
    if(win.ara_page_url==null)
    {
        win.ara_page_url=ref;
        if(!chkAds(win,doc)){
            win.ara_page_url=loc;
            win.ara_last_modified_time=Date.parse(doc.lastModified)/1000;
            win.ara_referrer_url=ref;
        }
    } else
    {
        win.ara_page_location=ref;
        if(!chkAds(win,doc)){
            win.ara_page_location=loc;
        }
    }
    
    win.ara_page_location = loc;
    if(win.ara_num_ads==null){
        win.ara_num_ads=new Array();
    }
    win.ara_num_ads.push(1);
    
    var regeX = new RegExp('#','gi');
    win.ara_show_url = ara_mainurl+"reklam_show.php?ara=2";
    updateUrl("uid",win.ara_userid);
    updateUrl("tp",win.ara_type);
    updateUrl("fr",win.ara_format);
    updateUrl("ws",window.screen.width+"x"+window.screen.height);
    updateUrl("pl",win.ara_page_location);
    updateUrl("qr",win.ara_query);
    if (win.ara_format!="1x1") {
    updateUrl("bg",win.ara_bg.replace(regeX,''));
    updateUrl("tt",win.ara_title.replace(regeX,''));
    updateUrl("tx",win.ara_text.replace(regeX,''));
    updateUrl("lk",win.ara_link.replace(regeX,''));
    updateUrl("br",win.ara_border.replace(regeX,''));
    }
    
    if (win.ara_type==10) {
		size[0]="100%";
		size[1]="150";

		//updateUrl("rc",rescount);
	} 
	
	if (win.ara_type==11) {
		size[0]="100%";
	}
	

    
    if(window.ara_num_ads != null)
	{	
		if( window.ara_num_ads.length < 16 )
		{
			showAds(win,doc,ara_show_url);
		}
		else
		{
		  	showDefAds(win,doc,ara_show_url);
		}
	}
	else
	{
		showAds(win,doc,ara_show_url);
	}

}


/*
var xmlhttp;
function getResCount(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Opera, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    //document.getElementById('A1').innerHTML=xmlhttp.status;
    //document.getElementById('A2').innerHTML=xmlhttp.statusText;
    rescount=xmlhttp.responseText;
    }
  else
    {
    alert("Problem retrieving XML data:" + xmlhttp.statusText);
    }
  }
}

//getResCount("http://reklam.ara.com.tr/reklam/reklam_count.php");
*/
function showAds(win,doc,url){
    url=url.substring(0,1000);
    //url=url.replace(/%\w?$/,"");
    //document.write('<script>function changeframe(){document.getElementById(\'ara_reklam_10\').height = "50";}</script>');
    document.write('<iframe name="ara_reklam_'+win.ara_type+'" id="ara_reklam_'+win.ara_type+'" width="'+size[0]+'" height="'+size[1]+'" frameborder="0" src="'+url+'" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no">');
	document.write("</iframe>");
}

function showDefAds(win,doc,url){
    document.write('<iframe name="ara_reklam" width="'+size[0]+'" height="'+size[1]+'" frameborder="0" src="'+ara_defurl+'default.php" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no">');
	document.write("</iframe>");
}



createAds();




