function checkBrowserName(name){  
	var agent = navigator.userAgent.toLowerCase();  
	if (agent.indexOf(name.toLowerCase())>-1) {  
  	return true;  
	}  
 	return false;  
}  

function insert(aTag, eTag) {
	var input = document.forms['form'].elements['text'];
	input.focus();
	/* für den Internet Explorer */
	if(typeof document.selection != 'undefined') {
	  var range = document.selection.createRange();
	  var insText = range.text;
	  range.text = aTag + insText + eTag;
	  /* Anpassen der Cursorposition */
	  range = document.selection.createRange();
	  if(insText.length == 0) {
		  range.move('character', -eTag.lenght);
		}else{
		  range.moveStart('character', aTag.length + insText.length + eTag.length);
		}
		range.select();
	}
	/* für neuere auf Gecko basierende Browser */
	else if(typeof input.selectionStart != 'undefined'){
	  /* Einfügen des Formatierungscodes */
	  var start = input.selectionStart;
	  var end = input.selectionEnd;
	  var insText = input.value.substring(start,end);
	  input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
	  /* Anpassen der Cursorposition */
	  var pos;
	  if(insText.length == 0){
		  pos = start + aTag.length;
		}else{
		  pos = start + aTag.length + insText.length + eTag.length;
		}
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	/*für die übrigen Browser */
	else {
	  
	}
}

function format_byselect_size(sel)
	{
	  var index = sel.selectedIndex;
	  if (sel.options[index].value != '') {
	       insert('[size=' + sel.options[index].value + ']', '[/size]');    
	  }
	}	
function format_byselect_color(sel)
	{
	  var index = sel.selectedIndex;
	  if (sel.options[index].value != '') {
	       insert('[color=' + sel.options[index].value + ']', '[/color]');    
	  }
	}	
function format_byselect_font(sel)
	{
	  var index = sel.selectedIndex;
	  if (sel.options[index].value != '') {
	       insert('[font=' + sel.options[index].value + ']', '[/font]');    
	  }
	}
function set_link()
	{
	  var url = prompt("Bitte URL eigeben:");
	  var text = prompt("Bitte LINKTEXT eingeben:");
	  if (url.length > 0) {
		  insert('[url=' + url + ']' + text ,'[/url]')
		}
	}	
function set_image()
	{
	  var url = prompt("Bitte URL zum Bild eigeben:");
	  if (url.length > 0) {
		  insert('[img]' + url + '[/img]','')
		}
	}	
function set_color(color)
	{
	  if (color.length > 0) {
		  insert('[color=' + color + ']','[/color]')
		}
	}	
function hideit(id)
{
  var stat = document.getElementById(id).style.display;
 if( stat == "none"){
    document.getElementById(id).style.display="block";
	}else{
	  document.getElementById(id).style.display="none";
	}
}



function rand (min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

function  show_cat(me,user,cat,pg,alpha){	
	if(!alpha) var alpha = '';
  //die Daten Anlgen die per GET übertragen werden
  var data = 'me='+me+'&user='+user+'&cat='+cat+'&alpha='+alpha+'&pg='+pg;
  //Request abschicken
  $.ajax({
		url: "member/profil/show_card_cat.php",
		type: "GET",
		data: data,
		success: function(res) {
    if(pg > 1){ $('#'+cat+'_cards').css('min-height','411px'); }
    $('#'+cat+'_cards').html(res);
    }
	});
	return false;
}

function show_collection(me,user,limit,set){
  
  // request erstellen
  var req = null;
  try {
	  req = new XMLHttpRequest();
	}
	catch(ms){
		try{
		  req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(nonms){
		  try{
			  req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(failed){
			  req = null;
			}
		}
	}
	if(req == null)
		alert("Error creating request object!");
	
	// Anfrage erstellen
	req.open("GET",'member/profil/show_card_collection.php?me='+me+'&user='+user+'&limit='+limit+'&cardset='+set);

	// Beim abschließen diese Funktion
	req.onreadystatechange = function() {
	  switch(req.readyState) {
		  case 4:
		  	if(req.status != 200 && req.status !=0){
				  
				}else{
				  //schreibe antwort ins DIV
				  document.getElementById('collect_cards').innerHTML = req.responseText;
				  $('#collectionfield').fadeIn(1500,function(){ 
				   // nothing
					})
				}
				break;
				
			default:
				return false;
				break;
		}
	}
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	req.send(null);
}


function show_collection_edit(me,limit,set){
  
  // request erstellen
  var req = null;
  try {
	  req = new XMLHttpRequest();
	}
	catch(ms){
		try{
		  req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(nonms){
		  try{
			  req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(failed){
			  req = null;
			}
		}
	}
	if(req == null)
		alert("Error creating request object!");
	
	// Anfrage erstellen
	req.open("GET",'member/cardbox/edit_collection.php?me='+me+'&limit='+limit+'&cardset='+set);

	// Beim abschließen diese Funktion
	req.onreadystatechange = function() {
	  switch(req.readyState) {
		  case 4:
		  	if(req.status != 200 && req.status !=0){
				  
				}else{
				  //schreibe antwort ins DIV
				  document.getElementById('collection').innerHTML = req.responseText;
				}
				break;
				
			default:
				return false;
				break;
		}
	}
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	req.send(null);
}


function show_master(user,pg,order){
  
  // request erstellen
  var req = null;
  try {
	  req = new XMLHttpRequest();
	}
	catch(ms){
		try{
		  req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(nonms){
		  try{
			  req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(failed){
			  req = null;
			}
		}
	}
	if(req == null)
		alert("Error creating request object!");
	
	// Anfrage erstellen
	req.open("GET",'member/profil/show_master.php?user='+user+'&pg='+pg+'&order='+order);

	// Beim abschließen diese Funktion
	req.onreadystatechange = function() {
	  switch(req.readyState) {
		  case 4:
		  	if(req.status != 200){
				  
				}else{
				  //schreibe antwort ins DIV
				  document.getElementById('master_cards').innerHTML = req.responseText;
				}
				break;
				
			default:
				return false;
				break;
		}
	}
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	req.send(null);
}

//
function close_popup(){
	$('#default_popup').hide();
	$('#page_overlay').hide();
}
function show_popup(){
	$('#default_popup').show();
	$('#page_overlay').fadeIn('fast');
}

function cardpound(id){
 	$('.card').hide();
	var pound = $.post("games/ajax/cardpound.php", { card: id }, 
	function(data){
		$('#default_popup').css({height:'auto'}).html( data );
		show_popup();
	});
}

function badone(todo){
 	if(todo == 'play'){
	 	var badone_summe = $('#summe').val();
		var badone = $.post("games/ajax/badone.php", { summe: badone_summe, play: 'true' }, 
		function(data){
			$('#gamefield').html( data );
		});
	}
	if(todo == 'take'){
	 	var badone_summe = $('#summe').val();
		var badone = $.post("games/ajax/badone.php", { summe: badone_summe, take: 'true' }, 
		function(data){
			$('#gamefield').html( data );
		});
	}	
}
function show_news(this_id,direction){ 
 	if(direction == 'prev'){
 	 	var prev_news = (this_id-1);
 	 	if($('.news'+prev_news).length == 0){ $('#news').before('<div class="news'+prev_news+'"></div>');	}
 	 	$('.news'+prev_news).hide();
		$.post('news.php',{ id:prev_news },
				function(data){
				$('.news'+this_id).fadeOut(750);
				$('.news'+prev_news).html( data ).delay(750).fadeIn(750);
				location.href = '#news'+prev_news;
				$('.pollscript').each(function(index){
					var poll = $(this).attr('id');
					var poll_id = poll.substring(4);
					$(this).load('poll.php', { id:poll_id } );
				});
		});
	}else{
 	 	var next_news = (this_id+1);
 	 	if($('.news'+next_news).length == 0){ $('#news').after('<div class="news'+next_news+'"></div>'); }
		$.post('news.php',{ id:next_news },
				function(data){
				$('.news'+this_id).fadeOut(750);
				$('.news'+next_news).html( data ).delay(750).fadeIn(750);
				location.href = '#news'+next_news;
				$('.pollscript').each(function(index){
					var poll = $(this).attr('id');
					var poll_id = poll.substring(4);
					$(this).load('poll.php', { id:poll_id } );
				});	
		});
	}
}

function poll_show_result(poll){ 
	$('#poll'+poll+' .voting').hide();
	$('#poll'+poll+' .results').fadeIn(750);
}

function poll_vote(poll){ 
 	var voting = $('#poll'+poll+' input[name=poll_answer'+poll+']:checked').val();
 	$('#poll'+poll).css({cursor:'wait'});
 	if(typeof voting != 'undefined'){
		$.post('poll.php',{ action:'vote', value:voting, id:poll },
			function(data){
			$('#poll'+poll).html( data );
			$('#poll'+poll+' .voting').hide();
		 	$('#poll'+poll).css({cursor:'default'});
			$('#poll'+poll+' .results').fadeIn(750);
		});
	}else{
	 	$('#poll'+poll).css({cursor:'default'});
		alert('Du hast keine gültige Option gewählt!');
	}
}

$(document).ready(function(){
	// Umfragen laden!
	$('.pollscript').each(function(index){
		var poll = $(this).attr('id');
		var poll_id = poll.substring(4);
		$(this).load('poll.php', { id:poll_id } );
	});
	// Box mit vollständigen memberarealinks anzeigen
	$('#membernavi .linkbox_ico').mouseenter(function(){
		$(this).clearQueue();
		var offset = $(this).offset();
		var navi_width = $('#membernavi_full').width();
		var offset_left = navi_width -19;
		$('#membernavi_full').fadeIn('fast').offset({top: offset.top+21, left: offset.left-offset_left});
	});
	$('#membernavi .linkbox_ico').mouseleave(function(){
		$('#membernavi_full').delay(750).fadeOut('fast');
	});
	$('#membernavi_full').mouseenter(function(){
		$(this).clearQueue();
	});
	$('#membernavi_full').mouseleave(function(){
		$('#membernavi_full').delay(750).fadeOut('fast');
	});
});

/* imitation select feld	
 	$('.option').click(function(){
		var val = $(this).attr('id');
		show_collection_edit(<?php echo $my_ID; ?>,1,val);
	});
 	
	$('.select').mouseenter(function(){
 	 	var linked = $(this).attr('name');
	 	var offset = $(this).offset();
	 	var select_options_height = $('.select_options[name='+linked+']').height();
	 	var select_options_width = $(this).width();
	 	$('.select_options[name='+linked+']').css({position:'absolute', left:offset.left, top:offset.top-select_options_height, width:select_options_width}).show();
	});
	
 	$('.select_options').mouseleave(function(){ $(this).hide(); }); */
