var xmlhttp = false;
var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();

top_votes = 0;

if(window.XMLHttpRequest)
{
	// Firefox   
	xmlhttp = new XMLHttpRequest();   
}
else if(window.ActiveXObject)
{
	// Internet Explorer   
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
}
else
{
	// XMLHttpRequest non supporté par le navigateur
	alert("Your browser doesn't support XMLHTTPRequest Objects");
}

function myXMLHttpRequest ()
{
    
	var xmlhttplocal;
	if (window.XMLHttpRequest)
	{
	    try
	    {
		    xmlhttplocal = new XMLHttpRequest();

		    // Évite un bug du navigateur Safari :
		    if (xmlhttplocal.overrideMimeType)
		    {
			    xmlhttplocal.overrideMimeType("text/xml");
		    }
		}
		catch(e)
		{
		    //window.alert("Your browser doesn't support XMLHTTPRequest Objects");
		}
	}
	else
	{
		if (window.ActiveXObject)
		{

			try 
			{
				// essaie de charger l'objet pour IE
				xmlhttplocal = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					// essaie de charger l'objet pour une autre version IE
					xmlhttplocal = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					window.alert("Your browser doesn't support XMLHTTPRequest Objects");
				} // try-catch
			} // try-catch

		}
	} // if-else
	return (xmlhttplocal);
};

function top_getvote ()
{
    id = top_id;
  	if (xmlhttp)
	{
	    instpath = "http://www.topgradinite.ro/director";
	    
		url = instpath + "/getvote.php?id=" + id;
		
		strContent = new String();
		strContent = 'id=' + id;
		anonymous_vote = true;
		mnmxmlhttp[id] = myXMLHttpRequest ();
		
		if (mnmxmlhttp[id])
		{
		    try
		    {
			    mnmxmlhttp[id].open ("POST", url, true);
			    mnmxmlhttp[id].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');

			    mnmxmlhttp[id].send (strContent);
			    errormatch = new RegExp ("^ERROR:");

			    target1 = document.getElementById ('voted-1');

			    mnmPrevColor[id] = target1.style.backgroundColor;
    			
			    mnmxmlhttp[id].onreadystatechange = function () 
			    {
				    if (mnmxmlhttp[id].readyState == 4) 
				    {
    				    
					    mnmString[id] = mnmxmlhttp[id].responseText;
					    if (mnmString[id].match (errormatch)) 
					    {
						    mnmString[id] = mnmString[id].substring (6, mnmString[id].length);
						    changemnmvalues (id, true);
					    } else 
					    {
						    changemnmvalues (id, false);
					    }
				    }
			    }
			}
			catch(e)
			{
			    //alert(e);
			}
		}
	}
};

function changemnmvalues (id, error)
{
	split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('voted-1');
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = 'Voturi ' + b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
	}
	return false;
};






function top_vote ()
{
    id = top_id;
    instpath = "http://www.topgradinite.ro/director";
    
  	if (xmlhttp)
	{
	    url = instpath + "/vote2.php?id=" + id;
	    
	    window.open( url ); 
	    
//		strContent = new String();
//		strContent = 'id=' + id;
//		anonymous_vote = true;
//		mnmxmlhttp[id] = myXMLHttpRequest ();
//		
//		if (mnmxmlhttp[id])
//		{
//		    try
//		    {
//			    mnmxmlhttp[id].open ("POST", url, true);
//			    mnmxmlhttp[id].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
//			    mnmxmlhttp[id].send (strContent);
//			    errormatch = new RegExp ("^ERROR:");

//			    target1 = document.getElementById ('voted-1');

//			    mnmPrevColor[id] = target1.style.backgroundColor;
//    			
//			    mnmxmlhttp[id].onreadystatechange = function () 
//			    {
//				    if (mnmxmlhttp[id].readyState == 4) 
//				    {
//					    mnmString[id] = mnmxmlhttp[id].responseText;
//					    if (mnmString[id].match (errormatch)) 
//					    {
//						    mnmString[id] = mnmString[id].substring (6, mnmString[id].length);
//						    changemnmvalues (id, true);
//					    } else 
//					    {
//						    changemnmvalues (id, false);
//					    }
//				    }
//			    }
//			}
//			catch(e)
//			{
//			    //alert(e);
//			}
//		}
	}
	
	//window.open( instpath ); 
};

 
//document.write( '<table>'  );
//document.write( '<tr>' );
//document.write( '   <td align=center>' );
document.write( '       <a href="javascript:top_vote()" style="color: #F7560F;">' );
//document.write( '       <a href="http://www.topgradinite.ro/director/vote2.php?id=' + top_id + '" style="color: #F7560F;">' );
document.write( '           <img src="http://www.topgradinite.ro/director/favicon32.ico" alt="Top Gradinite Bucuresti" />' );
document.write( '       </a>' );
//document.write( '   </td>' );

//document.write( '   <td align=center>' );
document.write( '       <a href="javascript:top_vote()" id="voted-1" style="color: #F7560F;">' );
//document.write( '       <a id="voted-1" href="http://www.topgradinite.ro/director/vote2.php?id=' + top_id + '" style="color: #F7560F;">' );
document.write( '           <font size="2" face="Verdana">' );
document.write( '           Voteaza' );
document.write( '           </font>' );
document.write( '       </a>' );
//document.write( '   </td>' );

//document.write( '</tr>');

//document.write( '<tr>' );
//document.write( '   <td align=center colspan=2>' );
//document.write( '       <a href="javascript:top_vote()" style="color: #F7560F;">' );
//document.write( '           <font size="1" face="Verdana">' );
//document.write( '               Voteaza-ne in TopGradinite.ro' );
//document.write( '           </font>' );
//document.write( '       </a>' );
//document.write( '   </td>' );
//document.write( '</tr>');


//document.write( '</table>'  );




top_votes = top_getvote();


  
