var qstop = 0;
var sq    = 0;

function ShowDelay(id, str, strb, block, hblock, wait_id, num, wmode) {
	sq = 1;
	num = (null != num) ? num : 0;
	setTimeout("Search('"+id+"', '"+str+"', '"+strb+"', '"+block+"', '"+hblock+"', '"+wait_id+"', '"+num+"', '"+wmode+"')", 500);
}

function Search(id, str, strb, block, hblock, wait_id, num, wmode) {   
	if ( !qstop && _v(strb).value == str && sq ) {	
	    qstop = 1;
		sq    = 0;
		_v(wait_id).style.display = 'block';
	    var req = new JsHttpRequest();
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
		        _v(hblock).style.display  = 'none';   
		        _v(block).innerHTML       =  req.responseJS.q;
			    _v(block).style.display   = 'block';
			    _v(wait_id).style.display = 'none';
				qstop = 0;
            }
        }
		num = (null != num) ? num : 0;
        req.open(null, siteAdr+'pajax.php', true);
	if (wmode>0)
	{
	    req.send( { action: 'search', id: id, str: str, num: num, wmode: wmode } );
	}else
	{
	    req.send( { action: 'search', id: id, str: str, num: num } );
	}
	}	
}

function ShowLoad(t)
{
    if (_v('load'))
	{
	    _v('load').style.display = (t == 1) ? 'block' : 'none';
	}
}

//**************************************************************//
//           Top blocks 
//**************************************************************//
/** for ideas */
function ShowBlock( num, cur, id, block, wait, is_out )
{
    _v(wait).style.display = 'block';
	_v('bl'+cur).className = '';  
	_v('bl'+num).className = 'active';
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		    _v(block).innerHTML =  req.responseJS.q;
			_v(wait).style.display = 'none';
        }
    }
	var out = (null != is_out) ? 1 : 0;
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'getmainblock', id: id, num: num, out: out } );	
}

/** for projects */
function ShowBlockP( num, cur, block, wait )
{
    _v(wait).style.display = 'block';
	_v('bl'+cur).className = '';  
    _v('bl'+num).className = 'active';
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            _v(block).innerHTML =  req.responseJS.q;
			_v(wait).style.display = 'none';
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
    req.send( { action: 'getmainprojblock', num: num } );   
}
//**************************************************************//
//           Vote 
//**************************************************************//
function Vote( id, block, sout, loginb , pid) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		    _v(block).innerHTML =  req.responseJS.q;
			if (null != loginb) {
			    //_v(loginb).style.display = 'block';
			}
        }
    }
	sout = (null == sout || 0 == sout) ? 0 : sout;
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'vote', id: id, block: block, sout: sout, pid: pid } );
}

function CancelVote( id, block, sout, loginb , pid) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		    _v(block).innerHTML =  req.responseJS.q;
			if (null != loginb) {
			    //_v(loginb).style.display = 'block';
			}
        }
    }
	sout = (null == sout || 0 == sout) ? 0 : sout;
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'cancelvote', id: id, block: block, sout: sout, pid: pid } );
}
//**************************************************************//
//           Favorites
//**************************************************************//
function Fav( pid, id, block, wait ) {   
	_v(wait).style.display = 'block';
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		    _v(block).innerHTML =  req.responseJS.q;
		    _v(wait).style.display = 'none';
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'fav', pid: pid, id: id, block: block } );
}

function CancelFav( pid, id, block, wait ) {   
	_v(wait).style.display = 'block';
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		    _v(block).innerHTML =  req.responseJS.q;
		    _v(wait).style.display = 'none';
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'cancelfav', pid: pid, id: id, block: block } );
}

//**************************************************************//
//          Ban && Dublicate
//**************************************************************//
function SetModer( act, id, block ) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4 && req.responseJS.q) {
		    _v(block).innerHTML =  req.responseJS.q;
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: act, id: id } );
}

function SetStatus( id, status, block, stsblock ) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
			status = status * 1;
		    if (null !=  _v(stsblock)) {
			    switch (status) {
			        case 1: _v(stsblock).className = 'status_status4';_v('a'+stsblock).innerHTML = 'выполнено';break;
				    case 2: _v(stsblock).className = 'status_status3';_v('a'+stsblock).innerHTML = 'запланировано';break;
				    case 3: _v(stsblock).className = 'status_status2';_v('a'+stsblock).innerHTML = 'делается';break;
				    case 4: _v(stsblock).className = 'status_status1';_v('a'+stsblock).innerHTML = 'отклонено';break;
			    }
            }			
			if (req.responseJS.q && 0 < req.responseJS.q) {
			    var v = req.responseJS.q; 
			    _v(block+'_'+v).className = 'actv'; 
				_v(block+'_'+v).href  = 'javascript:SetStatus(\''+id+'\', \''+req.responseJS.q+'\', \'sta_'+id+'\', \'sts_'+id+'\')';
		    }
			if (status) {
			    _v(block+'_'+status).className = 'actm'; 
			    _v(block+'_'+status).href  = 'javascript:void(0);';
			}
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'setstatus', id: id, status: status } );
}

function BanIp( pid, ip, login, block ) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4 && req.responseJS.q) {
		    _v(block).innerHTML =  req.responseJS.q;
			//_v(block).className = (1 == req.responseJS.q) ? 'grey' : 'blue';
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'banip', pid: pid, ip: ip, login: login } );
}

function NoTop( id, block ) {   
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4 && req.responseJS.q) {
		    _v(block).innerHTML =  req.responseJS.q;
			_v(block).style.color = ('1' == req.responseJS.eq) ? '#105895' : '#A3A3A2';
        }
    }
    req.open(null, siteAdr+'pajax.php', true);
	req.send( { action: 'notop', id: id } );
}

//**************************************************************//
//           Check Emails
//**************************************************************//
function CheckEmails(private_emails, res, what, actb) {
    if ( private_emails ) {
        _v(res).innerHTML = '';
        var req = new JsHttpRequest();
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                if ( req.responseJS.q ) {
                    _v(res).innerHTML = req.responseJS.q;
                } 
				if (null != _v(actb)) {
				    _v( actb ).className =( req.responseJS.rq ) ? 'add_idea_link' : 'button_disabled';
				}
            }
        }
        req.open(null, siteAdr+'ajax.php', true);
        req.send( { action: 'checkuserlist', private_emails: private_emails, what: what } );                  
    }
}

function DelProjUser( uid, pid, res ) {
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if ( req.responseJS.q ) {
                _v(res).innerHTML = req.responseJS.q;
            } 
        }
    }
    req.open(null, siteAdr+'ajax.php', true);
    req.send( { action: 'delprojuser', uid: uid, pid: pid } );                  
}

function GetWidget3( res, link, title, ltitle, color, bcolor, tcolor, align, cr, waction, lfont, lsize, project_title, domain, regime, vcolor, cmline,glcolor,tbcolor, w, h) {
    _v(res).innerHTML = '';
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if ( req.responseJS.q ) {
                title = req.responseJS.q;
            } 
                       
                 p = "<script type=\"text/javascript\"><!--\nreformal_wdg_w    = \""+w+"\";\nreformal_wdg_h    = \""+h+"\";\nreformal_wdg_domain    = \""+domain+"\";\nreformal_wdg_mode    = "+regime+";\nreformal_wdg_title   = \""+project_title+"\";\nreformal_wdg_ltitle  = \""+ltitle+"\";\nreformal_wdg_lfont   = \""+lfont+"\";\nreformal_wdg_lsize   = \""+lsize+"\";\nreformal_wdg_color   = \""+color+"\";\nreformal_wdg_bcolor  = \""+bcolor+"\";\nreformal_wdg_tcolor  = \""+tcolor+"\";\nreformal_wdg_align   = \""+align+"\";\nreformal_wdg_charset = \""+(cr==2?'utf-8':'windows-1251')+"\";\nreformal_wdg_waction = "+waction+";\nreformal_wdg_vcolor  = \""+vcolor+"\";\nreformal_wdg_cmline  = \""+cmline+"\";\nreformal_wdg_glcolor  = \""+glcolor+"\";\nreformal_wdg_tbcolor  = \""+tbcolor+"\";\n//-->\n</script>\n";

		_v(res).value = p+"\n"+'<div id="ref_wdg_box"><div id="x_ot37"><div id="x_ne37"><script type="text/javascript" language="JavaScript" src="'+link+'"></script><div class="tgdw_mottob"><div class="dewopyb"> на платформе <a href="http://reformal.ru" target="_blank"><img src="http://widget.reformal.ru/i/wd/reformal.png" width="62" height="9" alt="Reformal.ru" /></a></div></div></div></div></div>';
        }
    }
    req.open(null, siteAdr+'ajax.php', true);
    req.send( { action: 'gettitle', title: title } );                  
}



function GetWidget( res, link, title, ltitle, color, bcolor, tcolor, align, cr, waction, lfont, lsize, project_title, domain, regime, vcolor, cmline,glcolor,tbcolor, ext_domain, img_url, ext_mode, our_img, dis) {
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if ( req.responseJS.q ) {
                ltitle = req.responseJS.q;
            } 
			var ext_image_param = '';
			if (ext_mode==1 && jQuery.trim(ltitle)!='') // закладка с изм текстом
			{
				ext_image_param = ' \nreformal_wdg_bimage = "'+our_img+'";\n ';
			}else
			{
				ext_image_param = ' \nreformal_wdg_bimage = "'+img_url+'";\n ';
			}
			/*if (!dis || dis==1)
			{
				ext_image_param = '';
			}*/	
	ps = "<script type=\"text/javascript\"><!--\n"+(ext_domain?"reformal_wdg_vlink    = \""+ext_domain+"\";\n":"")+"reformal_wdg_domain    = \""+domain+"\";\nreformal_wdg_mode    = "+regime+";\nreformal_wdg_title   = \""+project_title+"\";\nreformal_wdg_ltitle  = \""+ltitle+"\";\nreformal_wdg_lfont   = \""+lfont+"\";\nreformal_wdg_lsize   = \""+lsize+"\";\nreformal_wdg_color   = \""+color+"\";\nreformal_wdg_bcolor  = \""+bcolor+"\";\nreformal_wdg_tcolor  = \""+tcolor+"\";\nreformal_wdg_align   = \""+align+"\";\nreformal_wdg_charset = \""+(cr==2?'utf-8':'windows-1251')+"\";\nreformal_wdg_waction = "+waction+";\nreformal_wdg_vcolor  = \""+vcolor+"\";\nreformal_wdg_cmline  = \""+cmline+"\";\nreformal_wdg_glcolor  = \""+glcolor+"\";\nreformal_wdg_tbcolor  = \""+tbcolor+"\";\n"+ext_image_param+"//-->\n</script>\n";

			_v(res).value = ps+"\n"+'<script type="text/javascript" language="JavaScript" src="'+link + '"></script><noscript><a href="http://'+domain+'.reformal.ru">'+project_title+' feedback </a> <a href="http://reformal.ru"><img src="http://reformal.ru/i/logo.gif" /></a></noscript>';
        }
    }
    req.open(null, siteAdr+'ajax.php', true);
    req.send( { action: 'gettitle', title: ltitle } );  	
}


function GetWidgetAdi( res, link, title, ltitle, color, bcolor, tcolor, align, cr, waction, lfont, lsize, project_title, domain, regime, vcolor, cmline,glcolor,tbcolor, w, h, img_url, ext_mode, our_img, dis, aw4_tcolor) {
    
    
    _v(res).innerHTML = '';
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if ( req.responseJS.q ) {
                title = req.responseJS.q;
            } 
			var ext_image_param = '';
			if (ext_mode==1 && jQuery.trim(ltitle)!='') // закладка с изм текстом
			{
				ext_image_param = ' \nreformal_wdg_bimage = "'+our_img+'";\n ';
			}else
			{
				ext_image_param = ' \nreformal_wdg_bimage = "'+img_url+'";\n ';
			}	
			/*if (!dis || dis==1)
			{
				ext_image_param = '';
			}*/
			p = "<script type=\"text/javascript\"><!--\nreformal_wdg_w    = \""+w+"\";\nreformal_wdg_h    = \""+h+"\";\nreformal_wdg_domain    = \""+domain+"\";\nreformal_wdg_mode    = "+regime+";\nreformal_wdg_title   = \""+project_title+"\";\nreformal_wdg_ltitle  = \""+ltitle+"\";\nreformal_wdg_lfont   = \""+lfont+"\";\nreformal_wdg_lsize   = \""+lsize+"\";\nreformal_wdg_color   = \""+color+"\";\nreformal_wdg_bcolor  = \""+bcolor+"\";\nreformal_wdg_tcolor  = \""+tcolor+"\";\nreformal_wdg_align   = \""+align+"\";\nreformal_wdg_charset = \""+(cr==2?'utf-8':'windows-1251')+"\";\nreformal_wdg_waction = "+waction+";\nreformal_wdg_vcolor  = \""+vcolor+"\";\nreformal_wdg_cmline  = \""+cmline+"\";\nreformal_wdg_glcolor  = \""+glcolor+"\";\nreformal_wdg_tbcolor  = \""+tbcolor+"\";\nreformal_wdg_tcolor_aw4  = \""+aw4_tcolor+"\";\n"+ext_image_param+"//-->\n</script>\n";

			_v(res).value = p+"\n"+'<script type="text/javascript" language="JavaScript" src="'+link+'"></script><noscript><a href="http://'+domain+'.reformal.ru">'+project_title+' feedback</a> <a href="http://reformal.ru">на платформе <img src="http://widget.reformal.ru/i/reformal_ru.png" /></a></noscript>';
        }
    }
    req.open(null, siteAdr+'ajax.php', true);
    req.send( { action: 'gettitle', title: title } );                  
}

function CheckDomain(err_id, iid1, iid2, domain, id) {
    var req = new JsHttpRequest();
    //_v( err_id ).style.display = 'none';
	
	req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.responseJS.q) {
                _v(iid1).style.display = (0 == req.responseJS.eq) ? 'none' : 'block';
                _v(iid2).style.display = (0 == req.responseJS.eq) ? 'block' : 'none';    
                _v(err_id).className   = (0 == req.responseJS.eq) ? 'red' : 'green';
			    _v( err_id ).innerHTML     = req.responseJS.q;
                _v( err_id ).style.display = 'block';
            }
        }
    }
    
    req.open(null, siteAdr + 'ajax.php', true);
    req.send( { action: "checkdomain", fm: {domain: domain, id: id}} );  
}

var cur_mnu = 0;
function ShowMenuTab( id ) {
    var oi = 0;
	if ( 0 < cur_mnu) {
	    _v('mnu_'+cur_mnu).style.display = 'none';
		oi = cur_mnu;
		cur_mnu = 0;
	}
	if ( id != oi ) {
        _v('mnu_'+id).style.display = 'block';
        cur_mnu = id;		
	}
}

function SHBl( id ) {
    _v( id ).style.display = ('none' == _v( id ).style.display) ? 'block' : 'none';
}

function Subm( id ) {
    _v( id ).submit();
}

function RegInlShb( num ) {
    if (inl_act == num) {
	    //return true;
	} else {
        _v('ib'+inl_act).className = '';
		_v('ib'+inl_act+'na').style.display = 'none';
		_v('ib'+inl_act+'a').style.display  = 'block';
		
		_v('ib'+num).className = 'active';
		_v('ib'+num+'na').style.display = 'block';
		_v('ib'+num+'a').style.display  = 'none';
        inl_act = num;  
        if (null != _v('no_registration'))
		{
		    _v('no_registration').style.display = (1 == num) ? 'block' : 'none';
        }
		_v('verify_auth').style.display = (2 == num) ? 'block' : 'none';
        _v('registration').style.display = (3 == num) ? 'block' : 'none';
	}
}


function ChangeDis(id, dis) { 
    var req = new JsHttpRequest();
	req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.responseJS.q) {
                _v('dis_1').style.display = _v('dis_1').style.display == 'none' ? 'block' : 'none';
                _v('dis_2').style.display = _v('dis_2').style.display == 'none' ? 'block' : 'none';
            }
        }
    }
    
    req.open(null, siteAdr + 'ajax.php', true);
    req.send( { action: "changedisign", id: id, dis: dis} );  
}



function SetFilters(filter)
{
	if (filter == 'idea')
		_v('show_idea').value = _v('show_idea').value==1 ? 0 : 1;

	if (filter == 'ques')
		_v('show_ques').value = _v('show_ques').value==1 ? 0 : 1;
	if (filter == 'error')
		_v('show_error').value = _v('show_error').value==1 ? 0 : 1;
	if (filter == 'thanks')
		_v('show_thanks').value = _v('show_thanks').value==1 ? 0 : 1;

}
