//a MUST before : <script language='JavaScript' src='/cookies.js'></script>

//-------------------------

//<p><a href="javascript:E_Me('a','s','k','','','','','','','Ask');"><img src="./images/mail_ask.gif" /></a></p>
function E_Me(c1,c2,c3,c4,c5,c6,subj) 	
{
	strAdds = new Array(c1,c2,c3,c4,c5,c6);
	strUser = "";
	strMailTo = "";
	for (x=0;x<strAdds.length;x++) {
		if (strAdds[x]!=null)
			strUser += strAdds[x];
	}
	//alert("mai"+"lto:"+strUser+"@"+"inbox"+"."+ "ru");
	strMailTo = "mai"+"lto:"+strUser+"@"+"mail"+"."+ "ru?subject=" + subj;
	document.location = strMailTo;
}

function popup(wndName, url, width, height) 
{
// <a href="javascript:popup('','/demo/flash_demo.html','770','580');" >On-line демо ролик (flash)</a>
   var position='left='+(window.screen.availWidth-width)/2+',top='+(window.screen.availHeight-height)/2+',width='+width+',height='+height;
   var thewnd=window.open(url,'',position + ',resizable=1,scrollbars=1,status=1');
   thewnd.focus();
}


function RecallSearch()
{
//alert(GetCookieValueByName(document.forms[0].elements['productname'].value));

if (CookieValueByNameExists("region")) { 
  document.forms['search'].elements['region'].value=GetCookieValueByName("region");
  }
else document.forms['search'].elements['region'].value=1;

if (CookieValueByNameExists("productname")) { 
//  alert(GetCookieValueByName("productname"));
  document.forms['search'].elements['productname'].value=decodeURI(GetCookieValueByName("productname"));
  var s=document.forms['search'].elements['productname'].value;
  s=s.replace(/[+]/g,' ');
  document.forms['search'].elements['productname'].value=s;
}
if (CookieValueByNameExists("country")) { 
  document.forms['search'].elements['country'].value=GetCookieValueByName("country");
}
if (CookieValueByNameExists("metro")) { 
  document.forms['search'].elements['metro'].value=GetCookieValueByName("metro");
}
if (CookieValueByNameExists("district")) { 
  document.forms['search'].elements['district'].value=GetCookieValueByName("district");
}
if (CookieValueByNameExists("searchtype")) { 
  if (GetCookieValueByName("searchtype")=="1") document.forms['search'].elements['searchtype'].checked=true;
}
 
  Set_region(document.forms['search'].elements['region'].value);
  SetUnsetAptSearch(document.forms['search'].elements['searchtype'].checked);
  document.forms['search'].elements['map'].value='';
  document.forms['search'].elements['productname'].focus();

}

// --- ---

function MetroKeyPress()
{
if (window.event.keyCode==27)
  document.forms['search'].elements['metro'].value=0;
}

function Set_metro(value)
{
if (value!=0) 
   document.forms['search'].elements['district'].value=0;
}

function Set_district(value)
{
if (value!='0') 
  document.forms['search'].elements['metro'].value=0;
}

function Submit()
{
if (!document.forms['search'].elements['searchtype'].checked && 
    document.forms['search'].elements['productname'].value.length<3)
{
  alert("Поле ввода 'Названия' должно иметь не менее 3-х символов !");
  document.forms['search'].elements['productname'].focus();  
  return false; 
}                                               
if (document.forms['search'].elements['country'].value.length>0 &&
    document.forms['search'].elements['country'].value.length<3)
{
    alert("Поле ввода 'Страны' должно иметь не менее 3-х символов или быть пустым !");
    document.forms['search'].elements['country'].focus();
    return false;                                                       
}
   
return true;
}

function Set_region(value, point)
{
  var arr = getElementsByNameIE('span','idmoscow');
          
  for(var i = 0; i < arr.length; i++)
  {
     //alert(arr[i]);
	 if (value!=1)
	   arr[i].style.visibility='hidden';
	 else 
	   arr[i].style.visibility='visible';
  }
  if (point!='profile')
    SetCookieForNDays('region', value, '', '/', '', '');
  
}

function SetModURI(value)
{
  value=encodeURI(value); 
  value=value.replace(/[%]/g,'@');
  return value;
}

function SetModURI0(elem)
{
  var s=elem.value;
  s=encodeURI(s); 
  s=s.replace(/[%]/g,'@');
  elem.value=s;
  return true;
}  
// ---  ---


function getElementsByNameIE(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


function SetUnsetAptSearch(value) 
{
  if (value) document.getElementById('idcountryname').innerHTML='Адрес (фрагмент)';//   .style.visibility='hidden';
  else document.getElementById('idcountryname').innerHTML='Страна пр-ва';//  .style.visibility='visible';
   
}
