var _captcha_post;
function processCaptcha(key,url,uid){
if (!uid){
return false;
}
var _captcha_img = $("#captcha_img"+uid);
var _captcha_key = $("#captcha_key"+uid);
if (_captcha_img.length < 1 || _captcha_key.length < 1){
return false;
}
if ($(_captcha_img).is("img")){
$(_captcha_img).attr("src",url);
}else{
$(_captcha_img).replaceWith('
');
}
$(_captcha_key).val(key);
$("#captcha_value"+uid).val("");
}
$(document).ready(function(){
function _make_gallery(){
$("div.b-photo-informer").each(function(){
var _block = this;
$("table.pager a, td.listing a",this).each(function(){
$(this).unbind('click').click(function(){
var _href = $(this).attr('href');
var _uid = _href.match(/uid=(\d*)/i)[1];
var _page = _href.match(/page=(\d*)/i)[1];
var _return = true;
$(_block).height($(_block).height());
$.ajax({
url:"/inc/fotki/"+_uid+".html",
data:{'uid':_uid,'page':_page},
async:false,
success:function(msg){
var _html = $(msg).html();
$(_block).html(_html);
window.setTimeout(function(){
$(_block).css({'height':'auto'});
_make_gallery();
},50);
_return = false;
}
});
return _return;
});
});
});
}
_make_gallery();
function _make_feedback(){
var imgIndicator = new Object();
var imgCount = 6;
var imgRepeat = 2;
var counts = 0;
var img_need = false;
for (var j = 0; j < imgRepeat; j++ ){
for (var i = 1; i <= imgCount; i++ ){
imgIndicator['img' + (i + j * imgCount)] = new Image(16,16);
imgIndicator['img' + (i + j * imgCount)].src = 'http://passport.yandex.ru/i/next' + i + '.gif';
}
}
imgIndicator['img' + (imgRepeat * imgCount + 1)] = new Image(16,16);
imgIndicator['img' + (imgRepeat * imgCount + 1)].src = 'http://passport.yandex.ru/i/next1.gif';
var _rotate_timeout;
function rotate(){
if (img_need && document.images['img_reloading']){
counts++;
document.images['img_reloading'].src = imgIndicator['img' + ((counts % imgCount)+1)].src;
window.clearTimeout(_rotate_timeout);
_rotate_timeout = window.setTimeout(rotate,70);
}
}
$("div.b-feedback").each(function(){
var _uid = $(this).attr("id")||"";
_uid = _uid.replace("e_","")||"";
if (_uid){
$("#captcha_rotate"+_uid).unbind('click').click(function(){
_getCaptcha(_uid);
return false;
});
$("#feedback_form"+_uid).unbind('submit').submit(function(){
var _this = this;
$("input,textarea",_this).attr("disabled","disabled");
$(_this).attr("action","/feedback/");
$("#captcha_error"+_uid+",#captcha_success"+_uid+",#internal_error"+_uid+",#name_error"+_uid+",#text_error"+_uid+",#email_error"+_uid).hide();
var params = {};
$("input",_this).each(function(){
var name = $(this).attr("name");
var val = $(this).val();
params[name]=val;
});
params["text"]=$("#b-feedback__input_comment").val()||"";
params["action"]="send";
params["id"]=_uid;
var _errors = {
'INVALID_USER_NAME':'name_error',
'INVALID_USER_EMAIL':'email_error',
'INVALID_MESSAGE':'text_error',
'INVALID_CAPTCHA_VALUE':'captcha_error'
};
$.ajax({
url:"/feedback/",
data:params,
type:"POST",
dataType:"xml",
success:function(msg){
msg = $("response",msg);
if (!$(msg).is("response")){
$("#internal_error"+_uid).show();
}else{
if ($(msg).attr("status") == "SUCCESS" ){
$("#captcha_success"+_uid).show();
}else{
$("errors",msg).each(function(){
var _err = $(this).text();
if (_errors[_err]){
$("#"+_errors[_err]+_uid).show();
}else{
$("#internal_error"+_uid).show();
}
});
}
}
$("input,textarea",_this).removeAttr("disabled");
_getCaptcha(_uid);
},
error:function(){
$("#internal_error"+_uid).show();
$("input,textarea",_this).removeAttr("disabled");
_getCaptcha(_uid);
}
});
return false;
});
function _getCaptcha(_uid){
if (img_need){
return false;
}
if (_captcha_post){
_captcha_post.abort();
}
img_need = true;
rotate();
var rnd = Math.floor ( Math.random ( 777) * 777 );
_captcha_post = $.ajax({
url:"/feedback/",
type:"POST",
data:{'action':'get_captcha','uid':_uid,'rnd':rnd},
success:function(msg){
img_need = false;
$("head").append('');
},
error:function(){
window.setTimeout(function(){
img_need = false;
_getCaptcha(_uid);
},300);
}
});
}
_getCaptcha(_uid);
}
});
}
_make_feedback();