function doPrint()
{
	window.print();
}

function doEmail()
{
	document.location = "/sendmail.php?doctitle="+escape(document.title)+"&docurl="+encodeURIComponent(document.location.href);
}
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function sendvote(voteid)
{
	var url = 'http://www.croasia.net/user_post.php?act=vote&id=' + voteid;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4)
		{
			viewResult();
		}
	}
	xmlhttp.send(null);
}
function sendvote2(ids)
{
	var url = 'http://www.croasia.net/user_post.php?act=votemulti&ids=' + ids;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4)
		{
			viewResult();
		}
	}
	xmlhttp.send(null);
}
function doVote()
{
	var f = document.cropoll;
	for (var i = 0 ; i < f.elements.length; i++)
	{
		var e = f.elements[i];
		
		if ( (e.name == 'question') && (e.type == 'radio') )
		{
			if(e.checked)
			{
				//alert(e.value);		
				for ( var j = 0; j < aVariantList.length; j++ )
				{
					if(aVoteIDList[j]==e.value)
						aVoteList[j]++;
				}
				
				// submit vote
				sendvote(e.value);
				return;
			}
		}
	}
	alert("Please select your choice first!");
}
function doMultiVote()
{
	var f = document.cropoll;
	var ids = "";
	for (var i = 0 ; i < f.elements.length; i++)
	{
		var e = f.elements[i];
		
		if ( (e.name == 'question') && (e.type == 'checkbox') )
		{
			if(e.checked)
			{
				//alert(e.value);		
				for ( var j = 0; j < aVariantList.length; j++ )
				{
					if(aVoteIDList[j]==e.value)
					{
						aVoteList[j]++;
						ids = ids+","+e.value;
					}
				}
			}
		}
	}
	if(ids=="")
		alert("Please select your choice first!");
	else
		// submit vote
		sendvote2(ids);
	
	return;
}
function viewResult()
{
	// get total votes num
	var iTotalVotes = 0;
	for ( var i = 0; i < aVariantList.length; i++ )
    {
		//aVoteList[i] = ;
		iTotalVotes += (+aVoteList[i]);
	}

	// generate percent values
	var aPercentList = new Array();
	for ( var i = 0; i < aVoteList.length; i++ )
    {
    	if ( 0 == iTotalVotes )
    		aPercentList[i] = 0;
    	else
			aPercentList[i] = Math.round((aVoteList[i]/iTotalVotes*100)*10)/10;
    }

	document.getElementById('poll_actions').style.display = 'none';
	document.getElementById('poll_line').style.display = 'none';
	container = document.getElementById('poll_content');
	container.innerHTML = '';
	
	for ( var i = 0; i < aVariantList.length; i++ )
	{
		sText = aVariantList[i];

		var newText = document.createTextNode(sText + ' ( ' + aVoteList[i] + ' votes ): ');

		var newDiv = document.createElement("div");
		newDiv.className = "pollTextBox";

		newDiv.id = 'r_' + i;
		newDiv.appendChild(newText);

		var newDiv2 = document.createElement("div");
		newDiv2.className = "pollTextBoxWrapperRes";
		newDiv2.appendChild(newDiv);

		var newDiv3 = document.createElement("div");
		newDiv3.className = "pollTextContainerRes";
		newDiv3.appendChild(newDiv2);

		var newDiv4 = document.createElement("div");
		newDiv4.id='p_' + i;
		newDiv4.className = "pollProgressBar";

		newText = document.createTextNode('0');
		newDiv4.appendChild( newText );
		
		container.appendChild( newDiv3 );
		container.appendChild( newDiv4 );

		drawBar(newDiv4.id,aPercentList[i]);
	}
}
function searchw_onsubmit()
{
	if(document.searchw.keyword.value!="")
	{
		document.searchw.submit();
		return true;
	}
	else
	{
		alert("Missing keyword for search!");
		return false;
	}
}

function createNamedElement( type, name )
{
	var element;
	try
	{
		element = document.createElement('<'+type+' name="'+name+'">');
	}catch(e){}
	if (!element || !element.name) // Cool, this is not IE !!
	{
		element = document.createElement(type)
		element.name = name;
	}
	return element;
}


function drawBar( item, size )
{
	var bar = document.getElementById(item);
	var widthLim = Math.floor( size * (bar.parentNode.offsetWidth / 100) );

	if ( widthLim > bar.offsetWidth )
	{

		bar.style.width = bar.offsetWidth + 2 + 'px';
// for correct final percent value,  offsetWidth mast be equal to widthLim
		if ( widthLim < bar.offsetWidth )
			bar.style.width = widthLim + 'px';

		var percentStep = Math.round(((size*bar.offsetWidth)/widthLim)*100)/100;
		bar.innerHTML = percentStep;

		setTimeout("drawBar('"+item+"',"+size+")", 50 );
	}
	else
	{
		//bar.innerHTML += '%';
		bar.innerHTML = size + '%';					
	}
}

