var NS4DOM = document.layers ? true:false;
var IEDOM = document.all ? true:false;
var W3CDOM = document.getElementById ? true:false;

function getObject (id) 
{
	if (W3CDOM) return document.getElementById(id);
	else if (IEDOM) return document.all[id];
	else if (NS4DOM) return document[id];
	return false;
}

function _eml(o){return o.email.value.match(/^([\w-~_]+\.)*[\w-~_]+@([\w-_]+\.){1,3}\w{2,4}$/i)?'':'E-mail: неверный формат адреса электронной почты;\n';}
function _dt(o){return(o.birthdate_yy.selectedIndex>0&&o.birthdate_mm.selectedIndex>0&&o.birthdate_dd.selectedIndex>0)?'':'Дата рождения: необходимо заполнить число, месяц и год;\n';}

function _reg0(o)
{
	var s='';

	if(!o.name.value)s+='Имя: поле необходимо заполнить;\n';
	if(!o.surname.value)s+='Фамилия: поле необходимо заполнить;\n';

	s+=_dt(o);

	if(!o.sex[0].checked&&!o.sex[1].checked)s+='Пол: поле необходимо заполнить;\n';

	if(o.zipcode.value&&!o.zipcode.value.match(/^\d+$/))s+='Индекс: поле должно быть числовым;\n';

	if(!o.region.selectedIndex)s+='Обл./Край/АО/Респ.: поле необходимо заполнить;\n';
	if(!o.city.value)s+='Город: поле необходимо заполнить;\n';
	if(!o.street.value)s+='Улица: поле необходимо заполнить;\n';
	if(!o.numh.value)s+='Дом: поле необходимо заполнить;\n';
	if(!o.numf.value)s+='Квартира: поле необходимо заполнить;\n';

	if((!o.telcode.value||!o.tel.value)&&(!o.mobtelcode.value||!o.mobtel.value))s+='Требуется указать, по крайней мере, один номер телефона;\n';

	if(o.telcode.value&&!o.telcode.value.match(/^\d+$/))s+='Тел. код: поле должно быть числовым;\n';
	if(o.mobtelcode.value&&!o.mobtelcode.value.match(/^\d+$/))s+='Тел. код мобильный: поле должно быть числовым;\n';
	if(o.sms.checked&&(!o.mobtel.value||!o.mobtelcode.value)) s+='Пароль по SMS: должно быть заполнено поле мобильного телефона;\n';

	if(!o.email.value)s+='E-mail: поле необходимо заполнить;\n';

	if(!s)return true;

	alert(s);
	return false;
}

function _reg1(o)
{
//	if (o.back.value) return true;

	var s='';
	
	if(!o.smoke[0].checked&&!o.smoke[1].checked)s+='Вы курите?: поле необходимо заполнить;\n';
	if(!o.smoke[0].checked&&o.smoke[1].checked)s+='Регистрация может быть завершена только при условии того, что вы курите.';
	
//	s+=_eml(o);
	
	if(!s)return true;
	
	alert(s);
	return false;
}

function _reg2(o)
{
	return true;
}




function _remind(o)
{
	var s='';
	if(!o.name.value)s+='Имя: поле необходимо заполнить;\n';
	if(!o.surname.value)s+='Фамилия: поле необходимо заполнить;\n';

	s+=_dt(o);

	if(!o.address.value)s+='Адрес: поле необходимо заполнить;\n';

	s+=_eml(o);
	
	if(!s) return true;
	
	alert(s);
	
	return false;

}


function openWin(filename)
{
	var height = 560;
	var width = 650;

	if (filename == '/conditions/') height = 600;
	if (filename == '/nb/remind/') height = 400;
	if (filename == '/nb/teaser/') { width = 1000; height = 646; window.open(filename,'','height=' + height + ',width=' + width + ',scrollbars=no,resizable=no,menubar=no'); return; }
	if (filename == '/br/kmag/') { width = 1003; height = 661; window.open(filename,'','height=' + height + ',width=' + width + ',scrollbars=no,resizable=no,menubar=no'); return; }
	
	window.open(filename,'','height=' + height + ',width=' + width + ',scrollbars=yes,resizable=no,menubar=no');
	void{};
}


/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($q)
{
	$q.fn.hint = function (blurClass)
	{
    if (!blurClass) blurClass = 'blur';
    
    return this.each(function () {
        var $input = $q(this),
            title = $input.attr('title'),
            $form = $q(this.form),
            $win = $q(window);

        function remove() {
            if (this.value === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) { 
            // on blur, set value to title attr if text is blank
            $input.blur(function () {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title
            
            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);

$q(document).ready(function(){

	$q('input[title!=""]').hint();

    	$q('li.closed').click(function(){ 
		 if ($q(this).find('ul').is(":hidden")) 
		 {
	    		$q(this).find('ul').slideDown("fast");
		 }
		 else
		 {
			$q(this).find('ul').slideUp('fast');
		 }
	});
    
	$q('.block .item .item_title').click(function(){ 
		 if ($q(this).parent().find('.item_image').is(":hidden")) 
	    		$q(this).parent().find('.item_image').slideDown("fast");
		 else
			$q(this).parent().find('.item_image').slideUp("fast");
	});

	/*$q('#avatar_upload').upload({
    	
		name: 'avatar_id_file',
		action: '/proc/profile_avatar',
		onSubmit: function() {
			$q('#avatar_upload_status').text('Загрузка файла');
		},
		onComplete: function(data) {
			//data contains the response from the action url
			$q('#avatar_upload_status').text('аватар загружен');
			window.location.href=window.location.href;
		}
	});*/

	$q('#addtofavorites').click(function()
	{
		if ($q(this).attr('title') == 'Убрать из избранного')
		{
			$q(this).text('Добавить в избранное');
			$q(this).attr('title', 'Добавить в избранное');
		}
		else
		{
			$q(this).text('Убрать из избранного');
			$q(this).attr('title', 'Убрать из избранного');
		}
		
		this.parentNode.getElementsByTagName('form')[0].submit();
	});
	
	if(!$q('#horoscope ul.top li').length) return;
	
	$q('#horoscope ul.top li').click(function(){
		id = $q(this).attr('id').replace('sign', '');

		$q(".horoscope .text").removeClass ('show');
		$q(".horoscope .text").addClass ('hide');
		$q(".horoscope #text" + id).removeClass ('hide');
		$q(".horoscope #text" + id).addClass ('show');
		
		$q(".horoscope .sign").css("background-image", "url(/@/horoskope/" + id + ".gif)");
	});
	
});


function _chdt(o){e=o.form.elements;f=o.name.split('_')[0];
dd=e[f+'_dd'].options[e[f+'_dd'].selectedIndex].value;
mm=e[f+'_mm'].options[e[f+'_mm'].selectedIndex].value;
//alert(e[f+'_yy']?1:0);
yy=e[f+'_yy'].options?e[f+'_yy'].options[e[f+'_yy'].selectedIndex].value:1970;
if((mm==4||mm==6||mm==9||mm==11)&&dd>30){e[f+'_dd'].options.selectedIndex=29;return;}
if(mm==2&&dd>28)e[f+'_dd'].options.selectedIndex=(Math.floor(yy/4)==yy/4)?28:27;}

function _lt10(n){return n>9?n:'0'+n}

function _ctl_dtm(n,t,d,m,y,h,mi,s)
{
var mn=['','Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],w = '',z='<select name="'+n+'_dd"  class="day" onchange="_chdt(this)"'+w+'>'
for(var i=1;i<32;i++) z+='<option value="'+i+'"'+(i==d?' selected="selected"':'')+'>'+_lt10(i)+'</option>'
z+='</select><select name="'+n+'_mm" class="month"  onchange="_chdt(this)"'+w+'>'
for(i=1;i<mn.length;i++) z+='<option value="'+i+'"'+(i==m?' selected="selected"':'')+'>'+mn[i]+'</option>'
z+='</select><select name="'+n+'_yy" class="year" onchange="_chdt(this)"'+w+'>'
for(i=1970;i<2030;i++) z+='<option value="'+i+'"'+(i==y?' selected="selected"':'')+'>'+i+'</option>'
z+='</select>'
if(t){
z+='&nbsp;<select name="'+n+'_hh" onchange="_chdt(this)"'+w+'>'
for(i=0;i<23;i++) z+='<option value="'+i+'"'+(i==h?' selected="selected"':'')+'>'+_lt10(i)+'</option>'
z+='</select>:<select name="'+n+'_mi" onchange="_chdt(this)"'+w+'>'
for(i=0;i<60;i++) z+='<option value="'+i+'"'+(i==mi?' selected="selected"':'')+'>'+_lt10(i)+'</option>'
z+='</select>:<select name="'+n+'_mi" onchange="_chdt(this)"'+w+'>'
for(i=0;i<60;i++) z+='<option value="'+i+'"'+(i==s?' selected="selected"':'')+'>'+_lt10(i)+'</option>'
z+='</select>'
}
return z
}

function _private_del(n)
{
	document.forms.private_del.msg_id.value = n;
	document.forms.private_del.submit();

return false;
}

function private_reply(msgid, msg) {
	
	document.private_add.login.value = document.getElementById("authorid"+msgid).innerHTML;
	rExp = /<br>/gi;
	var htmln = document.getElementById("msg"+msgid).innerHTML.replace(rExp, " ");
	document.private_add.message.value = "// --\r\n"+htmln+"\r\n// --\r\n\r\n";
	document.private_add.c_id.disabled=true;

	
	
}
