﻿function ajaxFunction(functionName, urlAddress, showLTD)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState == 4)
		{
		    if (functionName == "fill")
		    {
			document.all["groupsCenterTD"].innerHTML = xmlHttp.responseText;
			if (document.all["leftTD"] != null)
			{
				document.all["leftTD"].style.display = (showLTD == "1") ? "inline" : "none";
				if (showLTD == "1")
				{
				    if (document.all["groupsCenterTD"] != null) document.all["groupsCenterTD"].className="groupsCenterTD";
				}
				else
				{
				    if (document.all["groupsCenterTD"] != null) document.all["groupsCenterTD"].className="groupsMainBody";
				}
			}
			else
			{
				if (document.all["groupsCenterTD"] != null) document.all["groupsCenterTD"].className="groupsMainBody";
			}
		    }
		    else if (functionName == "FVote")
		    {
		        var responseText = xmlHttp.responseText;
    			if (responseText=="0") alert("مهلت ارسال نظر به اين نظرسنجی پايان يافته است");
    			else if (responseText=="1") alert("کد يا رمز را اشتباه وارد کرده ايد");
    			else if (responseText=="2") alert("شما اجازه شرکت در اين نظرسنجی را نداريد");
    			else if (responseText=="3") alert("شما قبلا به اين  موضوع نظرسنجی رای داده ايد");
    			else if (responseText=="4") alert("تبريک...رای شما با موفقيت ثبت شد");
    			else alert("متاسفانه مشکلی رخ داد. لطفا دوباره سعی کنيد");
		    }
		}
		else if (xmlHttp.readyState == 3)
		{
			if (functionName=="fill") document.all["groupsCenterTD"].innerHTML="<img src='http://www.webthinker.net/rayaportal/images/loading.gif'/>";
		}
	}

	xmlHttp.open("GET",urlAddress,true);
	xmlHttp.send(null);
}