<?php

if ($post == "") {
    $nume = $_GET['nume'];
	$indexed = false;
} else {
    $nume = $post;
	$indexed = true;
}

include 'config.php';

$_GET = str_replace($interzis, $replace, $_GET);

    $link = mysql_connect($baza['host'], $baza['user'], $baza['pass'])
        or die("Could not connect : " . mysql_error());
    mysql_select_db($baza['nume']) or die("Erorr!, DtaBase Name Incorect!");
$table = $baza['table'];
$a = mysql_fetch_assoc(mysql_query("SELECT * FROM $table  WHERE nume = '$nume'"));

$intrebare = $a['intrebare'];
$nume = $a['nume'];
$oponent1 = $a['oponent1'];
$oponent2 = $a['oponent2'];
$img1 = $a['img1'];
$img2 = $a['img2'];
$com1 = $a['com1'];
$com2 = $a['com2'];
$email = $a['email'];
$pass = $a['pass'];
$vote1 = $a['votes1'];
$vote2 = $a['votes2'];
$id = $a['id'];
$date = $a['date'];
$ips = $a['ips'];

$ar1 = explode('|-|', $img1);
$ar2 = explode('|-|', $img2);

$img1 = $ar1[0];
$img2 = $ar2[0];

$html1 = $ar1[1];
$html2 = $ar2[1];
$ipc =  $_SERVER['REMOTE_ADDR'];
$w = mysql_fetch_assoc(mysql_query("SELECT * FROM votes  WHERE id = '$id' AND ip = '$ipc'"));

if ((isset($_COOKIE["v_$id"])) or ($w['time'] > time())) {
$votat_pe = $_COOKIE["v_$id"];
$votat = "true";   
} else { $votat = "false"; }
include 'sus.php';
if ($vote1 == "") { die("Page Not Found!");}
?>


<script>
var intrebare = "<?php echo $intrebare; ?>";
var oponent1 = "<?php echo $oponent1; ?>";
var oponent2 = "<?php echo $oponent2; ?>";
var img1 = "<?php echo $img1; ?>";
var img2 = "<?php echo $img2; ?>";
var com1 = "<?php echo $com1; ?>";
var com2 = "<?php echo $com2; ?>";
var adresa = "http://<?=$_SERVER['HTTP_HOST']?>/view_<?php echo $nume; ?>";
var title = oponent1+" vs "+oponent2+" | "+intrebare;

function getVote(int)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("poll").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","/vote.php?id=<?=$id; ?>&ips=<?=$_SERVER['REMOTE_ADDR']; ?>&vote="+int,true);
xmlhttp.send();

}

function pause(n){
  today=new Date()
   today2=today
   while((today2-today)<=n){
   today2=new Date()
   }
}


function godd()
{



pause(3000);
window.location=adresa;

}

var id_brand = 0;
var iterations = 0;

var total_count = new Array();
total_count[1] = 0;
total_count[2] = 0;

var texts = new Object();
texts.facebook = new Array();
texts.facebook[1] = new Object();
texts.facebook[1].summary = com1;
texts.facebook[1].title=title;
texts.facebook[1].url = adresa;
texts.facebook[1].image = img1;

texts.facebook[2] = new Object();
texts.facebook[2].summary= com2;
texts.facebook[2].title=title;
texts.facebook[2].url = adresa;
texts.facebook[2].image = img2;


texts.twitter = new Array();
texts.twitter[1] = new Object();
texts.twitter[1].title = com1;
texts.twitter[1].url = adresa;

texts.twitter[2] = new Object();
texts.twitter[2].title = com2;
texts.twitter[2].url = adresa;

texts.odnoklassniki = new Array();
texts.odnoklassniki[1] = new Object();
texts.odnoklassniki[1].title = com1;
texts.odnoklassniki[1].url = adresa;

texts.odnoklassniki[2] = new Object();
texts.odnoklassniki[2].title = com2;
texts.odnoklassniki[2].url = adresa;



function voteFacebook(){
	var url = "http://www.facebook.com/sharer.php?s=100&p[title]="+encodeURIComponent(texts.facebook[id_brand].title)+"&p[summary]="+encodeURIComponent(texts.facebook[id_brand].summary)+"&p[url]="+encodeURIComponent(texts.facebook[id_brand].url)+"&p[images][0]="+encodeURIComponent(texts.facebook[id_brand].image);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
}

function voteOdnoklassniki(){
    var url = " http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl="+encodeURIComponent(texts.odnoklassniki[id_brand].url)+"&st.comments="+encodeURIComponent(texts.odnoklassniki[id_brand].title);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
}

function voteTwitter(){
	var url = "http://twitter.com/share?text="+encodeURIComponent(texts.twitter[id_brand].title)+"&url="+encodeURIComponent(texts.twitter[id_brand].url)+"&counturl="+encodeURIComponent(texts.twitter[id_brand].url);
	window.open(url,'','toolbar=0,status=0,width=626,height=436');
	$.modal.close();
}


function calculateFB(idbrand){
		var facebook = 'https://api.facebook.com/method/fql.query?query=select total_count from link_stat where url="' +encodeURIComponent(texts.facebook[idbrand].url)  + '"&format=json&callback=?';
		 $.getJSON(facebook, function(data) {			
				upCounter([idbrand],data[0].total_count);
				
	     });		

}

function calculateTwitter(idbrand){
		var twitter = 'http://urls.api.twitter.com/1/urls/count.json?url=' +encodeURIComponent(texts.twitter[idbrand].url)  + '&callback=?';
			$.getJSON(twitter, function(data) {			
				upCounter([idbrand],data.count);
				
	     });	
}

function calculateodnoklassniki(idbrand){
		var odnoklassniki = 'http://odnoklassniki.ru/share.php?act=count&index='+idbrand+'&url=' +encodeURIComponent(texts.odnoklassniki[idbrand].url)  + '&callback=?';
		VK = new Object();
		VK.Share = {};
		VK.Share.count = function(index, count) {
			upCounter([index],count);
		}
		$.getJSON(odnoklassniki, function(data) {	    });	
}

function calculateStart(){
		calculateFB(1);
		calculateFB(2);
		calculateTwitter(1);
		calculateTwitter(2);
		calculateodnoklassniki(1);
		calculateodnoklassniki(2);
}

function upCounter(id,count){
	total_count[id]+=count;
	$('#counter-'+id).html(total_count[id]);
	iterations++;
	if(iterations == 12){
		//$.post("/en/ajax",{action:"update-points",id_battle:10,points_1:total_count[15], points_2:total_count[16]});
		//$.post("/en/ajax",{action:"update-points",id_battle:17,points_1:total_count[30], points_2:total_count[29]});
	}
}

var lang = {
		years:   ['an', 'ani'],
		months:  ['luna', 'luni'],
		days:    ['zi', 'zile'],
		hours:   ['ora', 'ore'],
		minutes: ['minut', 'minute'],
		seconds: ['secunda', 'secunde'],
		plurar:  function(n) {
			return (n == 1 ? 0 : 1);
		}
	}
$(document).ready(function(){
	$("#countdown").countdown(new Date(2011, 3, 3, 23, 59, 59), {suffix:'',prefix:'A ramas:', finish: '',lang:lang});
	calculateStart();
});

function iwant(){
			$.post("/en/ajax",{action:"iwant",brand_1: $('#br_1').val(), brand_2:$('#br_2').val()});
			$('#submit').html('Thank you!');
}

function showLogin1(b){
	id_brand = b;
	$('#login-window').modal({});
}

function showLogin2(b){
	id_brand = b;
	$('#login-window2').modal({});
}

</script>
<div style="text-align:center">
<div id="question">
		<?php echo $intrebare; ?>
</div>


<table width="100%" border="0">

<tr>
<td width="4%">&nbsp;</td>
<td align="center"><center><img class="imgvs" height="200" src="<?php echo $img1; ?>" /></center></td>
<td align="center">	<center>		<span id="vs"><img src="/static/img/vs.gif" /></span>
			
		&nbsp;&nbsp;<br><button class="gbtn" onclick="window.location = '/browse'; return false"><?=$lng['browse']?></button></br>
			

			
			
			</center></td>
<td align="center"><center><img class="imgvsac" height="200" src="<?php echo $img2; ?>" /></center></td>
<td width="4%">&nbsp;</td>
</tr>

<tr>
<td width="4%">&nbsp;</td>
<td><center><?php echo $html1; ?><br /><h3><?php echo $oponent1; ?></h3></center></td>
<td></td>
<td><center><?php echo $html2; ?><br /><h3><?php echo $oponent2; ?></h3></center></td>
<td width="4%">&nbsp;</td>
</tr>

<tr>
<td width="4%">&nbsp;</td>
<td align="center">
				<center><div class="brand-votes"><font color="#0040eb"><b id="counter-15">
<?php echo $vote1; ?>
				</b></font></div></center>
</td>
<td></td>
<td align="center">				<center><div class="brand-votes">
                <font color="#ff0000"><b id="counter-16">
<?php echo $vote2; ?>
				</b></font></div></center>
</td>
<td width="4%">&nbsp;</td>
</tr>

<tr>
<td width="4%">&nbsp;</td>
<td align="center">
<?php if ($votat == "false") {
?>				
			<center> <a class="green" href="#" onclick="showLogin1(1)"><?=$lng['vote1']?><a></center>
<?php
}
?>	
</td>
<td align="center">
<?php 
if ($votat == "true") {
?>
<span style="font-size: 14pt"><font color="#36B500"><?=$lng['ms']?></font></span>
<?php
}
?>	
</td>


<td align="center">
<?php 
if ($votat == "false") {
?>		
			<center> <a class="orange" href="#" onclick="showLogin2(2)"><?=$lng['vote1']?><a></center>
<?php
}
?>	
</td>
<td width="4%">&nbsp;</td>
</tr>
</table>



<?php
if (!$indexed) {
$r = mysql_query("SELECT * FROM sondaje ORDER BY (votes1+votes2) DESC");

$i=0;
while ($x = mysql_fetch_assoc($r)) {
$i=$i+1;
$m[$i]=$x;
}
?>

<center>
<table width="100%"><tr><td width="20%" align="center">&nbsp;</td>
<td align="center">
	<div align="center" class="battle-slideshow clr">
	<center>
	<a class="battle-slideshow-container" href="/view_<?php echo $m[1]['id']; ?>">
		<div class="padding clr">
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[1]['img1']; ?>\" />"); </script></noindex>
					<div><?php echo $m[1]['oponent1']; ?></div>
				</div>
				<div class="vs">
					VS				
				</div>
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[1]['img2']; ?>\" />"); </script></noindex>
					<div><?php echo $m[1]['oponent2']; ?></div>
				</div>
		</div>
	</a>
	</center><center>
		<a class="battle-slideshow-container" href="/view_<?php echo $m[2]['id']; ?>">
		<div class="padding clr">
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[2]['img1']; ?>\" />"); </script></noindex>
					<div><?php echo $m[2]['oponent1']; ?></div>
				</div>
				<div class="vs">
					VS				
				</div>
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[2]['img2']; ?>\" />"); </script></noindex>
					<div><?php echo $m[2]['oponent2']; ?></div>
				</div>
		</div>
	</a>
	</center><center>
		<a class="battle-slideshow-container" href="/view_<?php echo $m[3]['id']; ?>">
		<div class="padding clr">
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[3]['img1']; ?>\" />"); </script></noindex>
					<div><?php echo $m[3]['oponent1']; ?></div>
				</div>
				<div class="vs">
					VS				
				</div>
				<div class="pic">
					<noindex><script> document.write("<img width=\"60\" height=\"60\" src=\"<?php echo $m[3]['img2']; ?>\" />"); </script></noindex>
					<div><?php echo $m[3]['oponent2']; ?></div>
				</div>
		</div>
	</a>
</center>
			</div>

			</td><td >&nbsp;</td></tr></table>
</center>
<?php 
}
?>


	<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  
  <script>
  $(document).ready(function() {
    $("#tabs").tabs();
  });
  </script>
	
			<script type="text/javascript">
				new BackCounter([$('countdown')]).addEvent('completed', function(){
					$('battle-ended').setStyle('display','block');
					$('battle-timer').setStyle('display','none');
				}).start();
			</script>
	
	
<div id="tabs">
    <ul>
        <li><a href="#fragment-1"><span>Вконтакте.</span></a></li>
        <li><a href="#fragment-2"><span>Facebook.</span></a></li>
		<li><a href="#fragment-3"><span><?=$lng['contactreclama']?>. </span></a></li>
		<li><a href="#fragment-4"><span>Гипер форум</span></a></li>
    </ul>
    <div id="fragment-1"><center>
				<script type="text/javascript" src="http://userapi.com/js/api/openapi.js?29"></script>
				<script type="text/javascript">
				  VK.init({apiId: 2759889,  onlyWidgets: true});
				</script>
				<div id="vk_comments"></div>
				<script type="text/javascript">
				VK.Widgets.Comments("vk_comments", {limit: 20, width: "550", attach: "*"}, 'dsafsd<?php echo $id; ?>');
				</script></center>
    </div>
    <div id="fragment-2">
				<div id="fb-root"></div>
				<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
				<fb:comments href="http://100vs500.ru/view_<?php echo $id; ?>" num_posts="20" width="550"></fb:comments>
    </div>
	
	    <div id="fragment-3">
<center><script type="text/javascript"><!--
google_ad_client = "ca-pub-1136166278066060";
/* giperbaner */
google_ad_slot = "0289388443";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>
    </div>
	<div id="fragment-4"><center><p><a href="http://giper-forum.ru"><img src="http://100vs500.ru/img/giper.jpg"  alt="Гипер форум ру.нета giper-forum.ru" ></a></p></center>
	
</div>	
	
	
<hr />

<a href="/browse" ><center><h2>Список Батлов</h2><center></a>






	</div>
	<div align="center" class="clear"></div>
	<div id="countdown"></div>

<div align="center" style="margin-top:40px; margin-bottom:50px">

		<div align="center" class="clear"></div>
	</div>
<div align="center" class="clear"></div>


<div align="center" id="login-window" style="display:none">
<center>
<?php if ($votat == "true") {
echo "Ati votat deja...";
} else {
?>

<h1><?=$lng['select']?></h1><br/>
<img src="/img/facebook.png" onclick="voteFacebook();getVote(1);godd()">
<img src="/img/twitter.png" onclick="voteTwitter();getVote(1);godd()">
<img src="/img/odnoklassniki.png" onclick="voteOdnoklassniki();getVote(1);godd()">
<img src="/img/vk.png" onclick="window.open('http://vkontakte.ru/share.php?url=http://<?=$_SERVER['HTTP_HOST']?>/view_<?php echo $nume; ?>&title=<?php echo $intrebare; ?>&description=<?php echo $oponent1; ?> vs <?php echo $oponent2; ?>&image=<?php echo $img1; ?>&noparse=true','mywindow','width=600,height=500');getVote(1);godd()">

<hr>
<img width="150" src="<?php echo $img1; ?>" /><br />
<h2><?php echo $oponent1; ?></h2>
<br/>

<?php } ?>
</center>
</div>

<div id="login-window2" style="display:none">
<center>
<?php if ($votat == "true") {
echo "Ati votat deja...";
} else {
?>
<h1><?=$lng['select']?></h1><br>
<img src="/img/facebook.png" onclick="voteFacebook();getVote(2);godd()">
<img src="/img/twitter.png" onclick="voteTwitter();getVote(2);godd()">
<img src="/img/odnoklassniki.png" onclick="voteOdnoklassniki();getVote(2);godd()">
<img src="/img/vk.png" onclick="window.open('http://vkontakte.ru/share.php?url=http://<?=$_SERVER['HTTP_HOST']?>/view_<?php echo $nume; ?>&title=<?php echo $intrebare; ?>&description=<?php echo $oponent1; ?> vs <?php echo $oponent2; ?>&image=<?php echo $img2; ?>&noparse=true','mywindow','width=600,height=500');getVote(2);godd()">

<hr>
<img width="150" src="<?php echo $img2; ?>" /><br />
<h2><?php echo $oponent2; ?></h2>
<br/>

<?php } ?>
</center>
</div>


<?php
if ($indexed) {
?>

<ul class="battle-list">
<?php
$result = mysql_query("SELECT * FROM sondaje ORDER BY (votes1+votes2) DESC");
$i=0;		
while($a = mysql_fetch_assoc($result))
{
$i=$i+1;	
$intrebare = $a['intrebare'];
$nume = $a['nume'];
$oponent1 = $a['oponent1'];
$oponent2 = $a['oponent2'];
$img1 = $a['img1'];
$img2 = $a['img2'];
$com1 = $a['com1'];
$com2 = $a['com2'];
$email = $a['email'];
$pass = $a['pass'];
$vote1 = $a['votes1'];
$vote2 = $a['votes2'];
$id = $a['id'];
$date = $a['date'];

$ar1 = explode('|-|', $img1);
$ar2 = explode('|-|', $img2);

$img1 = $ar1[0];
$img2 = $ar2[0];

echo <<<HTML
	
		<li id="battle62" class="clr ">

	<div class="pics">
		<div class="pic1">
			
							<img width='40' height='40' src="$img1" />
						
			<div class="vote-1">
				$vote1			</div>

		</div>
		<div class="vs">
			vs		</div>

		<div class="pic2">
			
							<img width='40' height='40' src="$img2" />
							
			<div class="vote-2">
				$vote2			</div>
		</div>

	</div>
	
	<div class="title">
		<h2>

			<a href="/view_$id">
				$intrebare		</a>
		</h2>
		

				<small>$oponent1 vs $oponent2</small>

			
	</div>
	

<br><br><br>	
</li>

HTML;
if ($i == $index_sondaje) { break; }	
		}
?>
</ul>


<?php
}
include 'jos.php'; ?>