/*
 * SUNANAPA.RU: JavaScript data manipulation module.
 * Copyright 2008 by Robert Pirverdov, Russia, weberio (at) mail.ru
 * MD5-subscript 8ae5bea892d7b08a3432d1dcc10cba3d
 * Especially for http://www.sunanapa.ru
 * Illegal copying and distribution is pursued under the law of Russia Federation
 * Not for commercial use!
 * Do not remove this comment if you want to use script!
 * Незаконное копирование и распространение преследуется по закону РФ
 * Не для коммерческого использования!
 * Не удаляйте данный комментарий, если вы хотите использовать скрипт!
*/

Main=function(){
this.pattern={
name:/^[\d\wа-яёЁ &(),\.$\+-]+$/i,
town:/^[\d\wа-яёЁ &(),\.-]+$/i,
email:/^[a-z0-9\._-]+@[a-z0-9\.-]+\.[a-z]{2,4}$/i,
telbox:/^[a-z0-9\._@,; ()\+-]{4,}$/,
tel:/[0-9,; ()\+-]{4,}/,
msg:/^[\S\s]{10,5000}$/};
this.DOM=document.getElementById?true:false;
this.months=['','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];
this.seBlink=0;
this.GET={};var x,p=1,l=location.search;
if(l.length>2){if(l.charAt(l.length-1)!='&')l+='&';while((x=l.indexOf('=',p))!=-1){this.GET[l.substring(p,x)]=unescape(l.substring(x+1,p=l.indexOf('&',x+1)));if(p==-1)break;p++}}
}
Main.prototype.trim=function(s){
var whitespace=' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
while(s.length>0)if(whitespace.indexOf(s.charAt(0))!=-1)s=s.substring(1);else break;
while(s.length>0)if(whitespace.indexOf(s.charAt(s.length-1))!=-1)s=s.substring(0,s.length-1);else break;
return s;
}
Main.prototype.ById=function(id){
return this.DOM?document.getElementById(id):document.all[id];
}
Main.prototype.syntaxError=function(obj){
if(this.seBlink!=0)return;
this.seHandle=setInterval(function(){main.seBlink++;obj.style.color=(obj.style.color==''?'#fff':'');obj.style.backgroundColor=(obj.style.backgroundColor==''?'#f00':'');if(main.seBlink==6){clearInterval(main.seHandle);main.seBlink=0}},250);
}
Main.prototype.sfhover=function(idPrefix,t){
var e,i=1;
if(main.DOM)while(e=main.ById(idPrefix+i)){if(t!=''&&e.getElementsByTagName(t))e=e.getElementsByTagName(t)[0];i++;
e.onmouseover=function(){this.className+=' sfhover'}
e.onmouseout=function(){this.className=this.className.substring(0,this.className.length-8)}
}}
Main.prototype.flashLoad=function(id){
var o,p,f=(location.host=='localhost'?'':'http://www.sunanapa.ru/')+'media/flash/'+id.substring(6)+'.swf';
try{o=document.createElement('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">')}
catch(e){o=document.createElement('object');o.type='application/x-shockwave-flash'}
o.width=200;o.height=241;o.data=f;
p=document.createElement('param');
p.name='pluginspage';
p.value='http://get.adobe.com/flashplayer/';
o.appendChild(p);
p=document.createElement('param');
p.name='movie';
p.value=f;
o.appendChild(p);
p=document.createElement('param');
p.name='bgcolor';
p.value='#ffffff';
o.appendChild(p);
p=document.createElement('param');
p.name='play';
p.value='false';
o.appendChild(p);
if(this.ById(id).hasChildNodes())this.ById(id).removeChild(this.ById(id).firstChild);
this.ById(id).appendChild(o);
}
Main.prototype.dtlClick=function(obj,id){
main.ById('dtl'+id).style.display=main.ById('dtl'+id).style.display=='block'?'none':'block';
if(obj.innerHTML=='+'){obj.innerHTML='-';obj.style.paddingLeft='3px'}
else {obj.innerHTML='+';obj.style.paddingLeft='1px'}
}
Main.prototype.newWindow=function(name,f,w,h){
if(this['nw_'+name]&&!this['nw_'+name].closed)this['nw_'+name].focus();
else this['nw_'+name]=window.open('./js-window/'+f,name,'dependent=yes,left=285,top=160,screenx=285,screeny=160,toolbar=0,scrollbars=1,location=0,directories=0,menubar=0,status=0,resizable=0,width='+w+',height='+h,true);
}
Main.prototype.checkSendmailForm=function(obj){
var err='',v,i,i1,i2;
if(!obj.name.value.match(this.pattern.name))err='Ошибка: имя указано неверно!';
if(err==''&&!obj.town.value.match(this.pattern.town))err='Ошибка: местонахождения некорректно!';
if(err==''&&!obj.telbox.value.match(this.pattern.telbox))err='Ошибка: e-mail или телефон указан неверно!\r\nСтрока не должна содержать ничего, кроме e-mail и/или номера телефона.';
if(err==''&&!obj.msg.value.match(this.pattern.msg))err='Ошибка: длина текста сообщения некорректна!';
if(err==''&&obj.code.value=='')err='Ошибка: антиспам код не указан!';
if(err==''&&obj.subject.value.charAt(0)=='Р'){
v=obj.telbox.value;
while((i=v.lastIndexOf('@'))>0){
i1=i2=i-1;while(i1>=0&&!v.charAt(i1).match(/[ ,;]/))i1--;while(i2<v.length&&!v.charAt(i2).match(/[ ,;]/))i2++;
v=v.substring(0,i1+1)+v.substring(i2);
}if(!v.match(this.pattern.tel)&&!confirm('Вы не указали или некорректно указали телефон.\r\nНам важно знать Ваш телефонный номер для того, чтобы подтвердить Вашу заинтересованность перед владельцем объекта и быстро связаться с Вами.\r\nУверены, что не хотите указать номер своего телефона?')){obj.telbox.focus();return false}
}if(err!='')alert(err);
return err==''?true:false;
}
Main.prototype.answerForm=function(){
if(document.cookie.indexOf('answer=1')==-1)document.write('<img width="70" height="70" hspace="7" src="templates/weberio/images/anim_radar.gif" alt="" align="left" />'+
'<form name="UAF" action="" method="post">'+
'<input type="hidden" name="referer" value="'+document.referrer+'" />'+
'<table cellspacing="0" cellpadding="0" align="left">'+
'<tr><td><textarea class="inputbox" cols="70" rows="4" name="'+String.fromCharCode(117)+'ser'+String.fromCharCode(90*1+5)+'answer" style="width:410px;border:2px solid #f00;font-size:9pt;font-style:normal;background:#ffd"></textarea></td>'+
'<td style="padding-left:10px">'+
'<button type="submit" style="width:45px;height:42px;padding:0;background:#ccc" onmouseover="this.style.backgroundColor=document.UAF.user_answer.value.length<5?\'#eecccc\':\'#bbddbb\'" onmouseout="this.style.backgroundColor=\'#cccccc\'" onclick="if(document.UAF.user_answer.value.length<5){document.UAF.user_answer.style.backgroundColor=\'#ffdddd\';return false}"><img width="36" height="36" src="templates/weberio/images/anim_button24.gif" alt="OK" /></button>'+
'</td></tr>'+
'</table></form>');else document.write('Спасибо!');
}
Main.prototype.moveLogo=function(){
if(!this.DOM||!this.ById('hdr'))return;
var o=this.ById('hdr').getElementsByTagName('IMG');
o[1].style.marginTop='-50px';
o[1].style.display='block';
this.moveLogoH=setTimeout(function(){main.moveLogoH=setInterval(function(){var o=main.ById('hdr').getElementsByTagName('IMG');o[1].style.marginTop=(parseInt(o[1].style.marginTop)+1)+'px';if(parseInt(o[1].style.marginTop)>=5){clearInterval(main.moveLogoH);o[1].style.marginTop='5px'}},50)},3000);
}
Main.prototype.gradient=function(id){
if(!this.DOM||!this.ById(id))return;
var t=this.ById(id),p,c,i,z=0,g=[],rgb=[[0,0,0],[0,0,0],[0,0,0]];
if((i=t.className.indexOf('-'))==-1)return;
g=['',''];
p=i;while(p>0&&(c=t.className.charAt(p-1))!=' '){g[0]=c+g[0];p--}
p=i;while(p<t.className.length-1&&(c=t.className.charAt(p+1))!=' '){g[1]+=c;p++}
if(g[0].length!=6||g[1].length!=6)return;
for(x=0;x<g.length;x++)for(p=0;p<8;p=p+2)rgb[x][p/2]=parseInt(g[x].substring(p,p+2),16);
i=t.innerHTML.length;c='';rgb[2]=rgb[0];
for(p=0;p<i;p++){
c+='<span style="color:rgb('+rgb[2][0]+','+rgb[2][1]+','+rgb[2][2]+')">'+t.innerHTML.charAt(p)+'</span>';
for(x=0;x<3;x++){rgb[2][x]+=Math.round((rgb[1][x]-rgb[0][x])/(i-1));if(rgb[2][x]>255)rgb[2][x]=255}
}t.innerHTML=c;
}
Main.prototype.showMail=function(v){
var a,x,v=v.split(' '),s='';
a=parseInt(v[0],10);for(x=v.length-1;x>=0;x--)s+=String.fromCharCode(x==0?a:parseInt(v[x])+a);
document.write('<a href="mailto:'+s+'?subject=SUNANAPA.RU" style="color:#000">'+s+'</a>');
}
Main.prototype.onReady=function(){}

function doLoad()
{var x,i,o,e,g=new RegExp('(?:^.* |^)submenu(?: .*$|$)');
o=document.getElementsByTagName('UL');
for(x=0;x<o.length;x++)if(o[x].className&&o[x].className.match(g)){
try{
e=o[x].childNodes;
for(i=0;i<e.length;i++)if(e[i].nodeName&&e[i].nodeName=='LI'){
e[i].onmouseover=function(){this.className+=' sfhover'}
e[i].onmouseout=function(){this.className=this.className.replace(new RegExp(' sfhover\\b'),'')}
}}catch(e){}}
main.onReady();
}
var main=new Main();
window.addEventListener?window.addEventListener('load',doLoad,false):window.attachEvent('onload',doLoad);

