if(window.HTMLElement){
	HTMLElement.prototype.removeNode = function(removeChildren) {
	  if (Boolean(removeChildren))
	    return this.parentNode.removeChild(this);
	  else {
	    var r=document.createRange();
	    r.selectNodeContents(this);
	    return this.parentNode.replaceChild(r.extractContents(),this);
	  }
	}
}
var cSelect;

function get_region(country_id)
{
//alert(country_id);
if (document.getElementById("select_cities")){var toDelete=document.getElementById("select_cities");toDelete.removeNode(true);}
if (document.getElementById("select_regions")){var toDelete=document.getElementById("select_regions");toDelete.removeNode(true);}
if (document.getElementById("select_agencies")){var toDelete=document.getElementById("select_agencies");toDelete.removeNode(true);}
url="generator.php?ajax_action=get_region&country_id="+country_id;
sendRequest(url);
}

function get_city(region_id,selector)
{
	if (document.getElementById("select_cities")){var toDelete=document.getElementById("select_cities");toDelete.removeNode(true);}
	if (document.getElementById("select_agencies")){var toDelete=document.getElementById("select_agencies");toDelete.removeNode(true);}
	if (selector==1) {} else {region_id=cSelect.value;}
	url="generator.php?ajax_action=get_city&region_id="+region_id;
	sendRequest(url);
}

function sendRequest(url)
{
		if(window.XMLHttpRequest)
		{
		    //alert('t1');
			req = new XMLHttpRequest();
		    req.open("GET", url, true);
			req.onreadystatechange=processReqChange;
		    req.send(null);	  
			
		 } 
		  else if(window.ActiveXObject)
		 {
		   
			req = new ActiveXObject("Microsoft.XMLHTTP");
		    if(req)
			{ 
			//alert('t2');
		      req.open("GET", url, true); 
     	      req.onreadystatechange=processReqChange;
		      req.send(); 
		  	}
		  }   
//alert(req.status); 
}

function processReqChange() 
{
	if ((req.readyState==4) && (req.status==200)) 
  
	{  	
		var response;
		if (req.responseXML.documentElement) 
		{
		//alert('1');
	 	response = req.responseXML.documentElement;
	 	} 
		else 
		{
		//alert('2');
	  	response=req.responseXML.loadXML(req.responseText);
	 	}	
		//if (read_action==1) {showTaskDetailp(response4);}
		showTaskDetailp(response);
	}	//else alert(req4.readyState); 
	//else alert("Идет загрузка");
}

function showTaskDetailp(response)
{
	var receivedTag = req.responseXML; 
	var action = receivedTag.getElementsByTagName("data").item(0).getAttribute("action");
	//alert(action);
	if (action=="get_regions")
	{
		var itemList = receivedTag.getElementsByTagName("data");
		var nodeList = itemList.item(0).childNodes;
		var cDiv,oData,oText,oID,oExecutor,cIns;
		
		if (nodeList.length>=1)
		{
			
			cIns=document.getElementById('region');
			//создание элемента SELECT
			cSelect=document.createElement('select');
			cSelect.id='select_regions';
			cSelect.name='region_id';
			cSelect.onchange=get_city;
			cIns.appendChild(cSelect);
			
			///////// OPTION ////////////////
			option=document.createElement('option'); ///создание элемента OPTION	
			//option.document.createAttribute("value");	///добавление атрибута элемента option	
			//option.setAttribute("value",0); ///присвоение атрибуту значения
			//option.setAttribute("selected","yes"); 
			option.value=0;
			cSelect.appendChild(option);
			var oText=document.createTextNode("регион");	
			option.appendChild(oText);
			//alert(oText);
			//alert("tt");
		}
		
		for (i=0;i<nodeList.length;i++)
		{
			var node = nodeList.item(i); 
			if (node.nodeName == "region") 
			{
				
				gData = node.firstChild.nodeValue;
				var oID = node.getAttribute("id");
				///////// OPTION ////////////////
				option=document.createElement('option'); ///создание элемента OPTION	
				//option.document.createAttribute("value");	///добавление атрибута элемента option	
				//option.setAttribute("value",oID); ///присвоение атрибуту значения
				option.value=oID;
				//option.setAttribute("selected","yes");
				cSelect.appendChild(option);
				var oText=document.createTextNode(gData);	
				option.appendChild(oText); 
				//option.id="every_days";
				
			}
		}
	}
	////CITIES
	if (action=="get_cities")
	{
		var itemList = receivedTag.getElementsByTagName("data");
		var nodeList = itemList.item(0).childNodes;
		var cDiv,oData,oText,oID,oExecutor,cIns;
		
		if (nodeList.length>=1)
		{
			cIns=document.getElementById('city');
			//создание элемента SELECT
			cSelect2=document.createElement('select');
			cSelect2.id='select_cities';
			cSelect2.name='city_id';
			cIns.appendChild(cSelect2);
			
			///////// OPTION ////////////////
			option=document.createElement('option'); ///создание элемента OPTION	
			//option.document.createAttribute("value");	///добавление атрибута элемента option	
			//option.setAttribute("value",0); ///присвоение атрибуту значения
			//option.setAttribute("selected","yes");
			option.value=0;
			cSelect2.appendChild(option);
			var oText=document.createTextNode("город");	
			option.appendChild(oText);
		}
		
		for (i=0;i<nodeList.length;i++)
		{
			var node = nodeList.item(i); 
			if (node.nodeName == "city") 
			{
				
				gData = node.firstChild.nodeValue;
				var oID = node.getAttribute("id");
				//alert (gData);
				
				///////// OPTION ////////////////
				option=document.createElement('option'); ///создание элемента OPTION	
				//option.document.createAttribute("value");	///добавление атрибута элемента option	
				//option.setAttribute("value",oID); ///присвоение атрибуту значения
				option.value=oID;
				//option.setAttribute("selected","yes");
				cSelect2.appendChild(option);
				var oText=document.createTextNode(gData);	
				option.appendChild(oText); 
				//option.id="every_days";
				
			}
		}
	}
} 

function prompting_show(select)
{
tp=event.y+document.body.scrollTop;
lf=event.x+document.body.scrollLeft;

switch(select)
{
	case 1: text="Укажите Ваш e-mail и пароль для последующей корректировки Вашего отзыва."; break;
	case 2: text="Подсказка номер 2"; break;
	case 3: text="Подсказка номер 3"; break;
	case 4: text="Подсказка номер 4"; break;
	case 5: text="Подсказка номер 5"; break;
	case 6: text="Подсказка номер 6"; break;
	default: text="Подсказка по умолчанию";
}

cDiv=document.getElementById('prompt');
cDiv.style.left=lf+15;
cDiv.style.top=tp-30;
cDiv.style.visibility='visible';
//var oText=document.createTextNode(text);	
//cDiv.appendChild(oText); 
cDiv.childNodes[0].nodeValue=text;
}

function prompting_hide(select)
{
cDiv=document.getElementById('prompt');
cDiv.style.visibility='hidden';
}


		
var ns6=document.getElementById&&!document.all
function restrictinput(maxlength,e,placeholder)
{
	if (window.event&&event.srcElement.value.length>=maxlength)
	return false
	else if (e.target&&e.target==eval(placeholder)
	&&e.target.value.length>=maxlength)
	{
	var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
	if (pressedkey.test(String.fromCharCode(e.which)))
	e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder)
{
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : 
	document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder))
	{
		if (lengthleft<0)
		theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}
function displaylimit(theform,thelimit)
{
	var limit_text='Осталось <b><span id="'+theform.toString()+'">'+thelimit+'</span></b> символов'
	if (document.all||ns6)
	document.write(limit_text)
	if (document.all)
	{
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6)
	{
		document.body.addEventListener('keypress', function(event) 
		{ restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) 
		{ countlimit(thelimit,event,theform) }, true); 
	}
}
//displaylimit("document.add_agency.description",100) 

////функция очистки поля поиска
var subscribe=0;
var search=0;
function clearinput(id)
{
	if ((subscribe==0)||(search==0))
	{
		var oInput=document.getElementById(id);
		oInput.setAttribute("value","");
		if (id=="search") {search=1;}
		if (id=="subscribe") {subscribe=1;}
	}
}