function bfLoad(container_id)
{
	replaceWith = '';
	
	switch (container_id)
	{
	case 'twitter':
		shorturl = 't' + document.URL.split('/')[4];
		if (shorturl == 'tundefined')
			shorturl = document.URL.split('/')[3];
		URL = "http://platform.twitter.com/widgets/tweet_button.html?"+
				"counturl=http://openpr.de/" + shorturl + "&" +  
				"url=http://openpr.de/" + shorturl + "&" +
				"count=horizontal&"+
				"text=" + document.TITLE + "&";
		break;

	case 'facebook':
		URL = "http://www.facebook.com/plugins/like.php?href=" + document.URL + "&layout=button_count&show_faces=false&width=140&action=recommend&font=verdana&colorscheme=light&height=21";
		break;
	}
	
	newContainer = document.createElement("DIV");
	newContainer.id = container_id;
	newContainer.style.cursor = "default";
	newContainer.style.backgroundImage = "none";
	
	replaceWith = document.createElement("IFRAME");
	replaceWith.setAttribute("src", URL);
	replaceWith.setAttribute("allowTransparency", true);
	replaceWith.setAttribute("scrolling", "no");
	replaceWith.setAttribute("frameBorder", 0);
	replaceWith.style.border 	= "none";
	replaceWith.style.overflow 	= "hidden";
	replaceWith.style.width 	= "140px";
	replaceWith.style.height 	= "21px";

	newContainer.appendChild( replaceWith );
	
	$('blindfold').replaceChild(newContainer, $(container_id));
}

function toggleDS(container_id)
{
	new Ajax.Request("/jstemp/twitter_facebook.php?type="+container_id, 
			{ 
				method: 'get',
				onSuccess: function(r){
					json = eval('(' + r.responseText + ')');
					(Object.keys(json)).each( 
											function (s){
												if (json[s] == true)
													bfLoad( s );
											});
				}
			});
}

function mailto(prid)
{
	w = window.open('/email2.php?prid='+prid,'','width=500,height=550,top=0,left=0;scrolling=auto,status=no,menubar=no,toolbar=no');
	w.focus();
}

function loadArchives(q)
{
	
	$('busy').style.visibility = "visible";
	$('archividfield').value = "";
			
	new Ajax.Request("/jstemp/archives.php?q="+encodeURIComponent(q), {
		  method: 'get',
		  onSuccess: function(r){
			$('busy').style.visibility = "hidden";
			
			$('complete').style.visibility = "visible";
			$('complete').innerHTML = r.responseText;
			
			if(!parseInt($('listcount').value))
				$('complete').style.visibility = "hidden";		  	
		  }
		});
}

function loadPM(){
	new Ajax.Request("/jstemp/pm.php", {
		  method: 'get',
		  
		  onSuccess: function(r){
			json = eval('(' + r.responseText + ')');
			if (json.prid != null)
			{
				/*$('pmloadergif').style.display = 'none';*/
				
				var n=json.prtxt.length;
				var l=0;
				var abs = 0;
				var buffer = '';
				var txt = '';
				
				//wenn bild, dann das als erstes
				//und auch nicht zum absatz zählen
				if (json.primg != null)
				{
					$('pmtxt' + abs).innerHTML = json.primg;
				}
				
				//ab 650 und 1100 zeichen wird aufgeteilt, der Rest wird in den buffer 
				//geladen und im letzten Absatz ausgegeben
				for (var i=0 ; i<n ; i++)
				{
					txt = json.prtxt[i];
					
					buffer = buffer + txt + '<br />';
					l = buffer.length;
					
					if ( (l >= 780 && abs==0) ||  l >= 480 && abs==1)
					{
						//alert(l + '::' + abs);
						$( 'pmtxt' + abs ).innerHTML += buffer;
						abs ++;
						buffer = '<br />';
					}
				
				}
				
				$( 'pmtxt' + abs ).innerHTML += buffer + 
					'<br/>' +
					'<i>Diese Pressemitteilung wurde auf openPR veröffentlicht.</i><br/><br/>'+
					json.youtube + "<br />" +
					json.contact + "<br /><br />" +
					json.portrait + "";

				//Ads_BA_preloaded.push('CAD');
				//Ads_BA_move['CAD']=true;
				//Ads_BA_moveAD('CAD');

				
			}else{
				txt = 	"<h1> Hinweis</h1><br />"+
	  					"<p style=\"font-size:14px;\">Die gewünschte Pressemitteilung kann zur Zeit nicht angezeigt werden.<br><br>"+
	  					"Bitte versuchen Sie es zu einem späteren Zeitpunkt noch einmal.</p><br><br>";
						
				$('pm').innerHTML = txt;
				
			}
		  },
		  
		  onFailure: function(){
		  	loadPM()
		  	/*	txt = 	"<h1>Hinweis</h1><br />"+
		  			"<p style=\"font-size:14px;\">Die gewünschte Pressemitteilung kann zur Zeit nicht angezeigt werden.<br><br>"+
		  			"<br>Bitte aktivieren Sie ggf. Cookies und Javascript in Ihrem Browser<br><br>und versuchen Sie es zu einem späteren Zeitpunkt noch einmal.</p><br><br>";
		  	$('pm').innerHTML = txt;
		  	*/
		  }
		});
}
function placeGoogleAd( place )
{
	$('google_ad_' + place ).innerHTML = $('google_ad_' + place + '_tmp').innerHTML;
	$('google_ad_' + place + '_tmp').innerHTML = '';

}

function loadPrint()
{
	
	new Ajax.Request("/jstemp/print.php", {
		  method: 'get',
		  onSuccess: function(r){
			$('pm').innerHTML = r.responseText;
		  }
		});
}

function ArchivList(){
	
	this.selected = -1;
	this.max = 0;
	
	this.timeout = 250;
	this.closetimer = 0;
	
	this.mclosetime = function(){
		this.closetimer = window.setTimeout(this.hideList, this.timeout);
	};
	
	this.mcancelclosetime = function(){
		if(this.closetimer)
		{
			window.clearTimeout(this.closetimer);
			this.closetimer = null;
		}
	};
	
	this.getSelected = function(){
		return this.selected;
	};
	
	this.setSelected = function(i){
		this.selected = parseInt(i);
	};
	
	this.setMax = function(max){
		this.max = parseInt(max);
	};
	
	this.getMax = function(){
		this.max = $('listcount') ? parseInt($('listcount').value) : 0;
		return this.max;
	};
	
	this.resetList = function(){
		this.selected = -1;
	};
	
	this.hideList = function(){
		$('complete').style.visibility = "hidden";
		$('complete').scrollTop = 0;
	};
	
	this.highLight = function(n,s){
		
		this.mcancelclosetime();
			
		for(i=0; i < this.getMax(); i++)
		{
			e = $('sr_'+i); 
			if(e)
			{
				e.style.background = "rgb(255,255,255)";
				e.style.color = "rgb(0,0,0)";
			}
		}
		
		if(n > -1)
		{
			e = $('sr_'+n); 
			e.style.background = "rgb(214,119,25)";
			e.style.color = "rgb(255,255,255)";
			this.setSelected(n);
			
			if(s)
			{
				$('complete').scrollTop = this.getSelected() > 2 ? (this.getSelected() * 18) - 32 : 0;
			}
		}
		else
		{
			this.resetList();
		}	
	};
	
	this.moveIndex = function(i){
		this.highLight(this.getSelected() + i, 1)
	};
	
	this.setChoice = function(){
		eid = $('sr_'+this.getSelected()+'_aid').value;
		enm = $('sr_'+this.getSelected()+'_anm').value;
						
		$('archividfield').value = eid;
		$('archivnmfield').value = enm;
		
		this.hideList();
	};
}
