var objRezalt={};
function send(u,t)
{
	var all=document.getElementsByTagName('input');
	var answers='';
	var athers ='';
	var index = 0;
	var obj = [];

	for(i=0;i<all.length;i++)
	{
		if(all[i].name==u)
		{
			if(all[i].checked)
			{
				answer=all[i].value;

				if(document.getElementById('text_'+all[i].value)!=null)
				{
					var athers = document.getElementById('text_'+all[i].value).value;
				}
				if(document.getElementById('text_'+all[i].value)!=null && t=="select")
				{
				var w=0;
				selects=document.getElementById('text_'+all[i].value);
					for(r=0;r<selects.length;r++)
					{
						if(selects[r].selected)
						{
							obj[index] = {};
							obj[index].answer_id=selects[r].value;
							index++;
							var w=1;
						}
					}
				}
				if(w!=1){
					obj[index] = {};
					obj[index].answer_id = all[i].value;

					obj[index].text = athers;

				index++;
				}
			}
		}
	}
	if(index>0)
	{
	objRezalt.user_id = getCookie("user_id");
	objRezalt.quest_id = u;
	objRezalt.answers = obj;

	//alert(string_array());
	//jx.load(return_url+'=2&string='+ string_array() ,function(data){},"POST");
	//jx.load(return_url+'string='+ string_array() ,function(data){},"POST");
	showQuestion(u,answer);
	}
}
function buildQuestion()
{
	if (getCookie("user_id") == undefined && getCookie("polls_id")== undefined)
	{
		setCookie("polls_id" ,start_poll, null , "/");
		setCookie("user_id" ,Math.floor ( Math.random ( ) * 10000000000 + 1 )  , null , "/");
		document.getElementById(start_poll).style.display='block';
	}
	if (getCookie("user_id") == undefined )
	{
		setCookie("user_id" ,Math.floor ( Math.random ( ) * 10000000000 + 1 )  , null , "/");
		document.getElementById(start_poll).style.display='block';
	}
	if(getCookie("polls_id") == undefined)
	{
		document.getElementById(start_poll).style.display='block';
	}
	if( getCookie("polls_id") == 100000)
	{
	}
	if(getCookie("polls_id")!= undefined)
	{
		showQuestion(getCookie("polls_id"),null);
	}
}
function showQuestion(quest_id,answer)
{
	if(answer==null)
	{
		next_quest(quest_id);
	}
	else if(answer!=null)
	{
		var question=questObj[quest_id][answer];
		document.getElementById(quest_id).style.display='none';
		next_quest(question);
	}
}
function next_quest(question)
{
	if(document.getElementById(question)!=null)
	{
		jx.load(return_url+'string='+ string_array() ,function(data){},"POST");
		document.getElementById(question).style.display='block';
		setCookie("polls_id" ,question , null , "/");
	}
	else if(question==100000)
	{
	}
	else
	{
		jx.load(return_url+'lang='+lang_new+'&strings='+getCookie("user_id")+'&answer='+ string_array() ,function(data){document.getElementById('answer_rezalt').innerHTML=data;},"POST");
		setCookie("polls_id" ,100000, null , "/");
	}
}
function getCookie( check_name ) {
     var a_all_cookies = document.cookie.split( ';' );
     var a_temp_cookie = '';
     var cookie_name = '';
     var cookie_value = '';
     var b_cookie_found = false;

     for ( i = 0; i < a_all_cookies.length; i++ )
     {
          a_temp_cookie = a_all_cookies[i].split( '=' );
          cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

          if ( cookie_name == check_name )
          {
               b_cookie_found = true;
               if ( a_temp_cookie.length > 1 )
               {
                    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
               }
               return cookie_value;
               break;
          }
          a_temp_cookie = null;
          cookie_name = '';
     }
     if ( !b_cookie_found )
     {
          return null;
     }
}
function setCookie( name, value, expires, path, domain, secure )
{
     var today = new Date();
     today.setTime( today.getTime() );

     expires = 1000 * 1000 * 60 * 60 * 24;

     var expires_date = new Date( today.getTime() + (expires) );

     document.cookie = name + "=" +escape( value ) +
     ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
     ( ( path ) ? ";path=" + path : "" ) +
     ( ( domain ) ? "omain=" + domain : "" ) +
     ( ( secure ) ? ";secure" : "" );
}
function string_array()
{
var myJSONText = JSON.stringify(objRezalt, function (key, value) {

   return value;

});
 return myJSONText;
}
function enable_input(t)
{
	document.getElementById(t).checked=true;
}