function initAjax() {

//	addHelper("where_country_field", null);

	addHelper('otheruserpostingfield', null, 'otherusers');
	addHelper('tagsfield', null, 'tags');
	addHelper('registration_user_country', null, 'country');
	addHelper('registration_user_city', 'registration_user_country_hidden', 'city');


//  addHelper('registration_user_city', null, 'city');
		
//	addHelper("where_location_field", "where_country_field");


		
}

function removeHelper(stepRH) {
	if (stepRH=="1") {
		document.getElementById('helperOut').style.display='none'
	}
	else
	{
		var t=setTimeout("removeHelper(1)",500);
	}
}


function addHelper(elemID1, elemID2, ttype) {
		
	if (document.getElementById(elemID1)) {				
		document.getElementById(elemID1).onkeypress=function(){helper(elemID1, elemID2, ttype)};
		document.getElementById(elemID1).onblur=function(){removeHelper(0)};
	}		
}

function helper(elemID1, elemID2, ttype) {
		
	var t=setTimeout("helperAJAX('"+elemID1+"', '"+elemID2+"', '"+ttype+"')",50);
}

function getAbsY(inputObj)
{
	  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
	    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	      return returnValue;
}

function getAbsX(inputObj)
{
	  var returnValue = inputObj.offsetLeft;
	    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	      return returnValue;
}

function helperAJAX(elemID1, elemID2, ttype) {
		
	fromCity=0;
	var req = new Subsys_JsHttpRequest_Js(); 
	req.onreadystatechange = function() { 
			
		if (req.readyState == 4) {
																										 
			if (req.responseJS) { 
				
				resultResonseArray=req.responseJS["region"];

				if (resultResonseArray["resultCount"]!=0) {
																		
					document.getElementById('helperOut').style.top="1px";
					document.getElementById('helperOut').style.left="1px";
					switch(elemID1)
					{						
						case "otheruserpostingfield":	
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top=getAbsY(obj)+0+"px";
							document.getElementById('helperOut').style.left=getAbsX(obj)+0+"px";																	
							document.getElementById('helperOut').style.display="inline";
							break;    

						case "registration_user_country":
						case "registration_user_city":
						
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top=getAbsY(obj)+0+"px";
							document.getElementById('helperOut').style.left=getAbsX(obj)+0+"px";																	
							document.getElementById('helperOut').style.display="inline";
//							document.getElementById('helperOut').style.width="250px";						
						
						
							break;


						default:
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top=getAbsY(obj)+0+"px";
							document.getElementById('helperOut').style.left=getAbsX(obj)+0+"px";																	
							document.getElementById('helperOut').style.display="inline";
							fromCity=1;
							break;
					}

					htmlResult='<div class="helperListAll">';
					for (i=1;i<=resultResonseArray["resultCount"];i++)
					{	
						
						switch(ttype)
						{
							
							case "tags":
							
								htmlResult=htmlResult+"<div class=\"helperListItem\" OnClick=\"document.getElementById('" + elemID1 + "').value='" + resultResonseArray["resultName"+i] + "'; document.getElementById('" + elemID1 + "_hidden').value='" + resultResonseArray["resultId"+i] + "'; document.getElementById('helperOut').style.display='none';\"><a>"+resultResonseArray["resultNameHL"+i]+"</a></div>";
							
								break;
								
							case "otherusers":
							
								htmlResult=htmlResult+"<div class=\"helperListItem\" OnClick=\"document.getElementById('" + elemID1 + "').value='" + resultResonseArray["resultName"+i] + "'; document.getElementById('" + elemID1 + "_show').innerHTML='" + resultResonseArray["resultName"+i] + "'; document.getElementById('" + elemID1 + "_hidden').value='" + resultResonseArray["resultId"+i] + "'; document.getElementById('helperOut').style.display='none';\"><a>"+resultResonseArray["resultNameHL"+i]+"</a></div>";
							
								break;
								
							case "country":
							case "city":

								htmlResult=htmlResult+"<div class=\"helperListItem\" OnClick=\"document.getElementById('" + elemID1 + "').value='" + resultResonseArray["resultName"+i] + "'; document.getElementById('" + elemID1 + "_hidden').value='" + resultResonseArray["resultId"+i] + "'; document.getElementById('helperOut').style.display='none';\"><a>"+resultResonseArray["resultNameHL"+i]+"</a></div>";
																					
								break;
														
						}
						
					}

					document.getElementById('helperOut').innerHTML=htmlResult + '</div>';

				}
				else
				{
					document.getElementById('helperOut').style.display="none";
					document.getElementById('helperOut').innerHTML="";
				}
			} 
		} 
        } 

	req.caching = false; 


	paramName1=document.getElementById(elemID1).value;
	
		var che = '';
		var	chereq = '';
		for (var qu=1; qu<=7; qu++) {	
			
			
			if( document.getElementById('rubrik' + qu) ) {
				if (document.getElementById('rubrik' + qu).checked) {	
					che = che + document.getElementById('rubrik' + qu).value + '|';	
				}	
			}
		}		

		// проверка на изменение имени

		if (ttype=='otherusers') {
			if( document.getElementById(elemID1 + '_show') ) {
				
				var inzlo = document.getElementById(elemID1 + '_show').innerHTML;
				var outzlo = document.getElementById(elemID1).value;
				
				if( inzlo!=outzlo ) {
					
					document.getElementById(elemID1 + '_show').innerHTML='';
					document.getElementById(elemID1 + '_hidden').value='';
					
				}
			}
		}
		
		if (elemID2!="null") {
			if (document.getElementById(elemID2)) {
				paramName2=document.getElementById(elemID2).value;
												
			} else {
				
				paramName2='';
				
			}
		} else {
			
			paramName2='';
			
		}
	
		req.open('POST', '/ajax/' + ttype + '.php', true); 		
		req.send({text: paramName1, checked: che, exttext: paramName2}); 

}