function commentFocused(obj)
{
	document.getElementById("submitComment").style.display = "block";
	if (obj.value=='הכנס תגובתך כאן...'){obj.value='';}
	obj.style.color = "black";
}

function commentBlured(obj)
{
	if (obj.value=='')
	{
		obj.value='הכנס תגובתך כאן...';
		obj.style.color = "gray";
	}	
}

function makeAjaxRequest(url)
{
	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlhttp!=null)
    {
		xmlhttp.onreadystatechange=req_Complete;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null)
	}
	else
	{
		alert("הדפדפן שלך אינו תומך ב-AJAX")
	}
}

function req_Complete()
{
	jQuery.noConflict();
	if (xmlhttp.readyState==4)
	{
		if (xmlhttp.status==200)
		{
			response = xmlhttp.responseText;
			startIndex = response.indexOf("[AjaxResponse]") + 14;
			endIndex = response.indexOf("[/AjaxResponse]");
			msg = response.substring(startIndex,endIndex);	
			document.getElementById("ajaxMsg").innerHTML = msg;
			document.getElementById("ajaxState").src = "images/info.png";
			option = document.getElementById("option").value;
			if (msg == "הצבעתך נשמרה!")
			{
				// $("#count"+option).fadeOut("fast");
				document.getElementById("count"+option).innerHTML = parseInt(document.getElementById("count"+option).innerHTML) + 1 ;
				// $("#count"+option).fadeIn("slow");
				jQuery("#pie").fadeOut("fast");
				document.getElementById("pie").src = "pie/" + document.getElementById("count2").innerHTML + "-" + document.getElementById("count1").innerHTML  + "-" + document.getElementById("count0").innerHTML + ".png";
				jQuery("#pie").fadeIn("slow");
			}
		}
		else
		{
			alert("הצבעתך נכשלה, אנא נסה שנית! במידה והבעיה חוזרת אנא פנה למנהל האתר ודווח על הבעיה.")
		}
	}
}

function showComment(option)
{
	jQuery.noConflict();

	document.getElementById("voteOptions").style.display = "none";
	lawId = document.getElementById("LawId").value;//querySt("id");
	url = "vote.php?option="+option+"&lawid="+lawId ;
	makeAjaxRequest(url); //todo - make second request after timeout
	if (document.getElementById("option").value=="")
	{
		document.getElementById("option").value=option;
	}

	jQuery("#comment").show("slow");
	jQuery("#comment").fadeIn("slow");

	commentObj = document.getElementById("userComment");
	switch (option)
	{
		case 0:
			//$("#userComment").removeClass().addClass("against");
			//$("#userComment").attr('class', 'against');		 
			commentObj.className = "against";
			break;
		case 1:
			//$("#userComment").removeClass().addClass("nimna");
			//$("#userComment").attr('class', 'nimna');
			commentObj.className="nimna";
			break;
		case 2:
			//$("#userComment").removeClass().addClass("for");
			//$("#userComment").attr('class', 'for');
			commentObj.className = "for";
			break;
	}
}

function trim(str)
{
	return str.replace(/^\s\s*/,"").replace(/\s\s*$/,"");
}

function validateForm()
{
	if (trim(document.getElementById("commentContent").value)=="" || (document.getElementById("commentContent").value=="הכנס תגובתך כאן..."))
	{
		alert("חובה למלא תוכן בתגובה"); 
		return false;
	}
}

function setCommentsDivHeight()
{
	obj1 = document.getElementById("for");
	obj2 = document.getElementById("against");
	obj3 = document.getElementById("nimna");

	//make all divs in the same (maximum) height
	if (obj1.clientHeight != obj2.clientHeight || obj1.clientHeight != obj3.clientHeight || obj2.clientHeight != obj3.clientHeight)
	{
		maxHeight = Math.max(Math.max(obj1.clientHeight,obj2.clientHeight),obj3.clientHeight) + "px";
		obj1.style.height = maxHeight;
		obj2.style.height = maxHeight;
		obj3.style.height = maxHeight;
	}

	//min-height: 200px
	if (obj1.clientHeight < 200)
		obj1.style.height = "200px";
	if (obj2.clientHeight < 200)
		obj2.style.height = "200px";
	if (obj3.clientHeight < 200)
		obj3.style.height = "200px";
}
