p=777;
WMTT=null;
button="right";
document.onmousemove=updateToolTip;
document.onmousedown=mousebutton_clicked;

function showDetails(i)
{
	document.getElementById('details'+i).style.display="";
	document.getElementById('details'+i).style.backgroundColor="#CCCCCC";
}

function hideAllDetails()
{
	for(i=1;i<500;i++)
	{
		document.getElementById('details'+i).style.display="none";
		document.getElementById('details'+i).style.backgroundColor="#FFFFFF";
	}
}

function checkUrl(url)
{
	var pos=url.indexOf("http://");
	
	if(pos!=0) alert("Achtung! Die eingegebene Adresse ist nicht gültig! Sie muss(!) mit http:// beginnen.");
}

function gotostartpage()
{
	window.location.href="index.php";
}

function mousebutton_clicked(mouseevent)
{
	if(!mouseevent) mouseevent = window.event;
	
	if(mouseevent.button) 
	{
		if(mouseevent.button == 1) 
		{
			button="left";
		} 
		else 
		{
			button="right";
		}
	}
}

function showAdultHint()
{
	alert("Eine Kampagne erfüllt die Ab18-Voraussetzungen, wenn das angezeigte Banner oder die verlinkte Website folgenden Inhalt darstellen:\n"+
	"\n"+
	"» Text mit erotischem oder pornografischen Inhalten\n"+
	"» Bilder mit erotischem oder pornografischen Inhalten\n"+
	"\n"+
	"Beachten Sie bitte, dass diese Kampagnen nur bei den Benutzern angezeigt wird, die in Ihrem Profil die Option 'Adult-Werbung erlauben' aktiviert haben.\n"+
	"\n"+
	"\n"+
	"Wenn Sie eine Ab18-Kampagne nicht als eine solche kennzeichen, wird Sie gesperrt!");
}

function setStandardDateFormat(sdf)
{
	document.getElementById('ondate').value=sdf;
	document.getElementById('span_checkformat').innerHTML='';
}

function showMoreSettings()
{
	document.getElementById('moreoptions').style.display="block";
	document.getElementById('moreoptions2').style.display="none";
}

function switchAdultText()
{
	if(document.getElementById('cb_adult').checked)
	{
		document.getElementById('adulttext').style.display="block";
	}
	else
	{
		document.getElementById('adulttext').style.display="none";
	}
}

function setPaymentMethodColors(type)
{
	if(type=="gwp")
	{
		document.getElementById('div_pay_with_account').className="paymentmethod_no";
		document.getElementById('div_pay_with_gwp').className="paymentmethod_yes";
	}
	else
	{
		document.getElementById('div_pay_with_account').className="paymentmethod_yes";
		document.getElementById('div_pay_with_gwp').className="paymentmethod_no";
	}
}

function showBookings(month)
{
	hideBookings();
	
	document.getElementById('div_bookings_'+month).style.display="block";
}

function setOffset(o)
{
	document.getElementById('offset').value=o;
}

function createToolTip(created,user_id,html)
{
	document.getElementById('span_tooltip_date').innerHTML=created;
	document.getElementById('span_tooltip_user_id').innerHTML=user_id;
	document.getElementById('span_tooltip_preview').innerHTML=html;
}

function isIE()
{
	var browser = navigator.appName;	
	if ( browser.indexOf("icrosoft")>=0 ) return true;
	if ( browser.indexOf("xplorer")>=0 ) return true;
	return false;
}

function gotourl(to)
{
	if(!isIE() || (isIE() && button=="left") )
	{
		location.href=to;
		document.getElementById('loadingnewbanners').style.display="block";
	}
}

function writeClickCountError(type,clicks,price)
{
	if(type=="account")
	{
		document.getElementById('span_hint_account').innerHTML="<img src='img/cross.gif' alt='error'> <font color='#CC0000'>Diese <span id='span_clicks2'>"+clicks+"</span> Klicks würden Sie <b><span id='span_pay_preview'>"+price+"</span></b> &euro; (Euro) kosten. Sie haben aber nicht so viel Guthaben auf Ihrem OTR-Konto!</font><br />";
	}
	
	if(type=="gwp")
	{
		document.getElementById('span_hint_gwp').innerHTML="<img src='img/cross.gif' alt='error' /> <font color='#CC0000'>Diese</font><font color='#CC0000'> <span id='span_clicks2'>"+clicks+"</span> Klicks w&uuml;rden Sie <b><span id='span_pay_with_gwp_preview'>"+clicks+"</span></b> GWP kosten. So viele GWP haben Sie aber nicht zur Verfügung!</font><br />";
	}
	
	document.getElementById('radio_pay_with_account').checked=true;
}

function writeClickCountOk(type,clicks,price)
{
	if(type=="account")
	{
		document.getElementById('span_hint_account').innerHTML="<img src='img/check.gif' alt='error'> <font color='#009900'>Diese <span id='span_clicks2'>"+clicks+"</span> Klicks würden Sie <b><span id='span_pay_preview'>"+price+"</span></b> &euro; (Euro) kosten.</font><br />";
	}
	
	if(type=="gwp")
	{
		document.getElementById('span_hint_gwp').innerHTML="<img src='img/check.gif' alt='error'> <font color='#009900'>Diese <span id='span_clicks2'>"+clicks+"</span> Klicks würden Sie <b><span id='span_pay_with_gwp_preview'>"+clicks+"</span></b> GWP kosten.</font><br />";
	}
}

function showPaymentMethods(c,p)
{
	var a=false;
	var b=false;
	
	if(p>max_price)
	{
		document.getElementById('div_pay_with_account').style.display="none";
		document.getElementById('pay_with_account_possible').value="0";
		
		setPaymentMethodColors("gwp");
	}
	else
	{
		a=true;
		document.getElementById('div_pay_with_account').style.display="block";
		document.getElementById('pay_with_account_possible').value="1";
	}
	
	if(c>max_gwp)
	{
		document.getElementById('div_pay_with_gwp').style.display="none";
		document.getElementById('pay_with_gwp_possible').value="0";
		
		setPaymentMethodColors("account");
	}
	else
	{
		b=true;
		document.getElementById('div_pay_with_gwp').style.display="block";
		document.getElementById('pay_with_gwp_possible').value="0";
	}
	
	if(a || b)
	{
		document.getElementById('div_pay_nomethod').style.display="none";
		document.getElementById('btn_pay').style.display="";	
		document.getElementById('pay_with_account_possible').value="1";
		document.getElementById('pay_with_gwp_possible').value="1";		
	}
	else
	{
		document.getElementById('div_pay_nomethod').style.display="block";
		document.getElementById('btn_pay').style.display="none";
		document.getElementById('pay_with_account_possible').value="0";
		document.getElementById('pay_with_gwp_possible').value="0";		
	}
	
	if(a && !b)
	{
		document.getElementById('radio_pay_with_gwp').checked=false;
		document.getElementById('radio_pay_with_account').checked=true;
	}
	
	if(!a && b)
	{
		document.getElementById('radio_pay_with_account').checked=false;
		document.getElementById('radio_pay_with_gwp').checked=true;
	}
	
	if(!a && !b)
	{
		document.getElementById('pay_with_account_possible').value="0";
		document.getElementById('pay_with_gwp_possible').value="0";	
		document.getElementById('radio_pay_with_account').checked=false;
		document.getElementById('radio_pay_with_gwp').checked=false;
	}
	
}

function incClicks(value)
{
	c+=value;	
	if(c<1000)  c=1000;
	if(c>200000) c=200000;
	
	price=/*Math.round*/(c/500);
	price=price.toFixed(2);
	
	gwp=Math.round(c/5);
	
	if(price>max_price)
	{
		writeClickCountError("account",c,price);
	}
	else
	{
		writeClickCountOk("account",c,price);
	}
	
	if(gwp>max_gwp)
	{
		writeClickCountError("gwp",c,price);
	}
	else
	{
		writeClickCountOk("gwp",c,price);
	}
	
	showPaymentMethods(gwp,price);

	document.getElementById('clicks').value=c;
	document.getElementById('span_clicks').innerHTML=c;
	document.getElementById('price').value=price;
	document.getElementById('span_pay').innerHTML=price;
	document.getElementById('span_pay_with_gwp').innerHTML=gwp;
	document.getElementById('span_pay_preview').innerHTML=price;
	document.getElementById('span_pay_with_gwp_preview').innerHTML=gwp;
	document.getElementById('span_clicks_to_buy').value=c;
	document.getElementById('span_clicks_to_buy_with_gwp').value=c;
}

function decClicks(value)
{
	c-=value;
	if(c<1000)  c=1000;
	if(c>200000) c=200000;
	
	price=/*Math.round*/(c/500);
	price=price.toFixed(2);
	
	gwp=Math.round(c/5);

	if(price>max_price)
	{
		writeClickCountError("account",c,price);
	}
	else
	{
		writeClickCountOk("account",c,price);
	}
	
	if(gwp>max_gwp)
	{
		writeClickCountError("gwp",c,price);
	}
	else
	{
		writeClickCountOk("gwp",c,price);
	}
	
	showPaymentMethods(gwp,price);

	document.getElementById('clicks').value=c;
	document.getElementById('span_clicks').innerHTML=c;
	document.getElementById('price').value=price;
	document.getElementById('span_pay').innerHTML=price;
	document.getElementById('span_pay_with_gwp').innerHTML=gwp;
	document.getElementById('span_pay_preview').innerHTML=price;
	document.getElementById('span_pay_with_gwp_preview').innerHTML=gwp;
}

function showStep(s)
{
	document.getElementById('step1').style.display="none";
	document.getElementById('step2').style.display="none";
	document.getElementById('step3').style.display="none";
	document.getElementById('step4').style.display="none";
	
	document.getElementById('step'+s).style.display="block";
}

function checkcurrency()
{
	var str=document.getElementById('price').value;
	
	if(str.search(",")>=0)
	{
		document.getElementById('price').value=str.replace(",",".");
		alert("Bitte trennen Sie Dezimalstellen mit einem Punkt (.)!");
	}
	
	document.getElementById('span_pay').innerHTML=document.getElementById('price').value;
}

function makePreview()
{
	linktarget=document.getElementById('linktarget').value;
	imageurl=document.getElementById('imageurl').value;
	
	html="<a href='"+linktarget+"' target='_blank'><img border='0' src='"+imageurl+"'></a>";
	
	document.getElementById('div_preview').innerHTML=html;
	
	x_get('checkcode.php?linktarget='+linktarget+"&imageurl="+imageurl,'span_checkcode');
}

function checkFormat()
{
	f=document.getElementById('ondate').value;
	
	x_get('checkformat.php?f='+f,'span_checkformat');
}

function switchSection(input)
{
	section=document.getElementById(input);
	if(section.style.display=="none")
	{
		section.style.display="block";
	}
	else
	{
		section.style.display="none";
	}
}

function updateToolTip(e) 
{
	x=(document.all)?window.event.x+document.body.scrollLeft:e.pageX;
	y=(document.all)?window.event.y+document.body.scrollTop:e.pageY;
	
	if (WMTT!=null) 
	{		
		versetzungX=-160;
		versetzungY=20;
		
		var WMTTID = WMTT.id;
		var ersterTeilDerID = WMTTID.substr(0,6);
		
		WMTT.style.left=(x+versetzungX)+"px";
		WMTT.style.top=(y+versetzungY)+"px";
	}
}

function showToolTip(id,inputposition) 
{
	try
	{
		updateToolTip;
		position=inputposition;
		WMTT=top.frames['mainFrame'].getElementById(id);
		WMTT.style.display="block";
	}
	catch(e){}
}

function hideToolTip() 
{
	if (WMTT!=null)	WMTT.style.display="none";
}

function setCSession()
{
	x_get('setclicksession.php','hiddendiv');
}