reloadUrl  = '';
stopReload = false;

function sum_all(ar)
{
    var cnt = ar.length;

    var res = 0;
    for (var i in ar)
    {
        res += ar[i];
    }

    return res;
}

function getcookie(name) 
{
    var cookie = ' ' + document.cookie;
    var search = ' ' + name + '=';
    var setStr = null;
    var offset = 0;
    var end    = 0;
    if (0 < cookie.length) 
    {
        offset = cookie.indexOf(search);
        if (-1 != offset) 
        {
            offset += search.length;
            end = cookie.indexOf(';', offset)
            
            if (-1 == end)
                end = cookie.length;

            setStr = unescape(cookie.substring(offset, end));
        }
    }

    return(setStr);
}

function setcookie(name, value, expires, path, domain, secure) 
{
    document.cookie = name + '=' + escape(value) +
        ((expires) ? '; expires=' + expires : '') +
        ((path) ? '; path=' + path : '') +
        ((domain) ? '; domain=' + domain : '') +
        ((secure) ? '; secure' : '');
}

function DisableEnableForm(obj, val)
{
    if (null == val)
        var val = true;

    var arr = obj.elements;
    var cnt = arr.length;
    for (var i = 0; i < cnt; i++)
    {
       arr[i].disabled = val;
    }
}

function StartReload(url)
{
    reloadUrl = url;
    setTimeout('GoReloadUrl()', 200000);
}

function GoReloadUrl()
{
    if (stopReload)
        return;

    self.location = reloadUrl;
}

function clearSelect(obj)
{
    var cnt = obj.options.length;

    for (var i = cnt - 1; i >= 0; i--)
    {
        obj.options[i] = null;
    }
}

function clearSelect2(obj, gr1)
{
    var cnt = obj.options.length;

    for (var i = cnt - 1; i >= gr1; i--)
    {
        obj.options[i] = null;
    }
}

function objDump(d, l) 
{
    if (6 < l)
        return '';

    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == 'object') 
    {
        s += typeof(d) + " {\n";
        for (var k in d) 
        {
            for (var i=0; i<l; i++) 
                s += "  ";

            s += k+": " + objDump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) 
            s += "  ";

        s += "}\n"
    } 
    else 
        s += '' + d + "\n";

    return s;
}

function findInSelect(obj, val, type)
{
    var cnt = obj.options.length;

    if (2 == type)
    {
        for (var i = 0; i < cnt; i++)
        {
            if (obj.options[i].text == val)
            {
                obj.options[i].selected = true;
                break;
            }
        }
    }
    else
    {
        for (var i = 0; i < cnt; i++)
        {
            if (obj.options[i].value == val)
            {
                obj.options[i].selected = true;
                break;
            }
        }
    }
}

function adiv(res)
{
    return res ? 'block':'none';
}

function _v(id)
{
    return document.getElementById(id);
}

function _vstl(id, param, val)
{
    if (null == val)
    {
        switch(param)
        {
            case 'bg':
                return document.getElementById(id).style.backgroundColor;
                break;
            case 'c':
                return document.getElementById(id).style.color;
                break;
        }
    }
    else
    {
        switch(param)
        {
            case 'bg':
                document.getElementById(id).style.backgroundColor = val;
                break;
            case 'c':
                document.getElementById(id).style.color = val;
                break;
        }
    }
}

function del_from_array(arr, index, type)
{
    var new_arr = new Array();
    var len     = arr.length;

    if (null == type || 1 == type)
    {
        if (index >= len)
            return arr;

        for (var i = 0; i < index; i++)
        {
            new_arr[new_arr.length] = arr[i];
        }

        for (var i = index + 1; i < len; i++)
        {
            new_arr[new_arr.length] = arr[i];
        }
    }
    else
    {
        for (var i = 0; i < len; i++)
        {
            if (index != arr[i])
                new_arr[new_arr.length] = arr[i];
        }
    }

    return new_arr;
}

function in_array(needle, haystack)
{
    var len = haystack.length;
    for (var i = 0; i < len; i++)
    {
        if (needle == haystack[i])
            return true;
    }

    return false;
}

function in_arrayi(needle, haystack)
{
    var len = haystack.length;
    needle = needle.toLowerCase();
    for (var i = 0; i < len; i++)
    {
        if (needle == haystack[i].toLowerCase())
            return true;
    }

    return false;
}

function make_hidden(idnum)
{
   if (_v(idnum).style.display == 'none')
       _v(idnum).style.display = 'block';
   else
       _v(idnum).style.display = 'none';
}

function mhidden(idnum1,idnum2)
{
    _v(idnum1).style.display = 'none';
    _v(idnum2).style.display = 'block';
}

function spisokChange(klausel,spisok,nospisok)
{
    if (klausel.checked)
    {
        nospisok.disabled='';
        spisok.disabled='1';
    }
    else
    {
        nospisok.disabled='1';
        spisok.disabled='';
    }
}

function verify_url(url)
{
    var urlReg1 = /^http:\/\/([\w-]+\.)+([\w-]{2,4})$/;
    var urlReg2 = /^([\w-]+\.)+([\w-]{2,4})$/;
    return urlReg1.test(url) || urlReg2.test(url);
}

function verify_email(email)
{
    if (7 > email.length)
       return false;

    var zones = new Array(
            'ac','ad','ae','af','ag','ai','al','am','an','ao','aq','ar','as','at','au','aw','az',
            'ax','ba','bb','bd','be','bf','bg','bh','bi','bj','bm','bn','bo','br','bs','bt','bv',
            'bw','by','bz','ca','cc','cd','cf','cg','ch','ci','ck','cl','cm','cn','co','cr','cs',
            'cu','cv','cx','cy','cz','de','dj','dk','dm','do','dz','ec','ee','eg','eh','er','es',
            'et','eu','fi','fj','fk','fm','fo','fr','ga','gb','gd','ge','gf','gg','gh','gi','gl',
            'gm','gn','gp','gq','gr','gs','gt','gu','gw','gy','hk','hm','hn','hr','ht','hu','id',
            'ie','il','im','in','io','iq','ir','is','it','je','jm','jo','jp','ke','kg','kh','ki',
            'km','kn','kp','kr','kw','ky','kz','la','lb','lc','li','lk','lr','ls','lt','lu','lv',
            'ly','ma','mc','md','mg','mh','mk','ml','mm','mn','mo','mp','mq','mr','ms','mt','mu',
            'mv','mw','mx','my','mz','na','nc','ne','nf','ng','ni','nl','no','np','nr','nu','nz',
            'om','pa','pe','pf','pg','ph','pk','pl','pm','pn','pr','ps','pt','pw','py','qa','re',
            'ro','ru','rw','sa','sb','sc','sd','se','sg','sh','si','sj','sk','sl','sm','sn','so',
            'sr','st','sv','sy','sz','tc','td','tf','tg','th','tj','tk','tl','tm','tn','to','tp',
            'tr','tt','tv','tw','tz','ua','ug','uk','um','us','uy','uz','va','vc','ve','vg','vi',
            'vn','vu','wf','ws','ye','yt','yu','za','zm','zw', 'su',
            'aero','biz','cat','com','coop','info','jobs','mobi','museum','name','net',
            'org','pro','travel','gov','edu','mil','int'
            );

    var regEmail = /^[\w-\.]+@([\w-]+\.)+([\w-]{2,4})$/;

    var myArr = regEmail.exec(email);

    if (null == myArr)
       return false;

    if (!in_arrayi(myArr[2], zones))
       return false;

    return true;
}

function isDigit(charCode) { return (charCode >= 48 && charCode <= 57) }
function isLat(charCode)   { return ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)) }
function isRus(charCode)   { return (charCode >= 1040 && charCode <= 1103) }
function filter(evt,set,exc,x) 
{ //set= 1 - digit 2 - lat 4 - rus; x=êðîìå set
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt) 
    {
        var charCode = (evt.charCode || evt.charCode == 0) ? evt.charCode :
            ((evt.keyCode) ? evt.keyCode : evt.which);

        if (charCode > 13 && !x^(!(set&1 && isDigit(charCode)) && !(set&2 && isLat(charCode)) && !(set&4 && isRus(charCode)) && exc.indexOf(String.fromCharCode(charCode))==-1)) 
        {
            if (evt.preventDefault) { evt.preventDefault(); } else { evt.returnValue = false; return false; }
        }
    }
}

function isNumeric(str)
{
   if (str.length == 0) return false;
   for (var i = 0; i < str.length; i++)
   {
      var ch = str.substring(i, i+1);
      if ( ch < '0' || ch>'9' || str.length == null)  return false;
   }
   return true;
}


function selControl(obj)
{
    var i;
    var reg = /^check/;
    var result;
    for (i = 0; i < obj.form.elements.length; i++)
    {
        if (reg.test(obj.form.elements[i].name))
            obj.form.elements[i].checked = obj.checked;
    }
}

function wopen(url,name,w,h,r,s,st)
{
    var w = window.open(url,name,"width="+w+",height="+h+",resizable="+r+",toolbar=0,location=0,status="+st+",menubar=0,directories=0,scrollbars="+s);
}

function SimpleCheckForm(obj)
{
    obj.elements.submit.value    = 'Æäèòå...';
    obj.elements.submit.disabled = true;
    return true;
}

function check_code(code, type)
{
}

function auto_session()
{
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {}
    
    req.caching = false;
    req.open('GET', '/', true);
    req.send({gate: 'ajax', mod: 'auto_session'});
}

function dec(code,encrypted) 
{	
    var strCodes = new Array('!','"','#','$','%','&',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','',']','^','_','`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    
    var num = encrypted[0] - 0x41;
    var encrypted_email = encrypted.slice(1,encrypted.length - num);	
    var email = '';
    for (var i = 0; i < encrypted_email.length; i++) 
    {		
	email += strCodes[(encrypted_email[i] ^ code) - 0x21];
    }
    return email;
}

var esomestr = dec(36,[85,80,65,69,73,100,82,77,87,81,69,72,84,76,69,86,73,10,71,75,73,215,53,236,223,111,76,50,217,239,4,39,66,40,12,18,244,22,212,177,210]);
var esomestr_ivan = dec(13,[72,100,123,108,99,77,123,100,126,120,108,97,125,101,108,127,96,35,110,98,96,12,51,255,159,122,249,118]); 
function _alert(action)
{
    if (!_v('js_console'))
       document.body.innerHTML += '<div id="js_console">' + '<a href="javascript:void(0);" onclick="_v(\'js_console_inner\').innerHTML = \'\';">Clear</a><br />' + '<div id="js_console_inner"></div></div>';

    _v('js_console_inner').innerHTML = action + '<br />' + _v('js_console_inner').innerHTML;
}

function tp_action(direction, state_index, action)
{
    if ('prev' == direction)
    {
        if (state[state_index] == 0) return;

        if ('over' == action)
        {
           _v('w_' + state_index + '_c_l').src = '/i2/index/l_on_mo.gif';
           _v('w_' + state_index + '_c_c').src = '/i2/index/splitter.gif';
        }
        else if ('out' == action)
        {
           _v('w_' + state_index + '_c_l').src  = '/i2/index/l_active.gif'
           _v('w_' + state_index + '_c_c').src = '/i2/index/splitter_disable.gif';
        }
        else if ('down' == action)
          _v('w_' + state_index + '_c_l').src  = '/i2/index/l_on_mc.gif';
        else if ('up' == action)
          _v('w_' + state_index + '_c_l').src  = '/i2/index/l_on_mo.gif';
        else if ('click' == action)
            tp_change(state_index, state[state_index] - 1, direction);
    }
    else
    {
        if (state[state_index] == maxstate[state_index] - 1) return;

        if ('over' == action)
        {
           _v('w_' + state_index + '_c_r').src = '/i2/index/r_on_mo.gif';
           _v('w_' + state_index + '_c_c').src = '/i2/index/splitter.gif';
        }
        else if ('out' == action)
        {
           _v('w_' + state_index + '_c_r').src  = '/i2/index/r_active.gif'
           _v('w_' + state_index + '_c_c').src = '/i2/index/splitter_disable.gif';
        }
        else if ('down' == action)
          _v('w_' + state_index + '_c_r').src  = '/i2/index/r_on_mc.gif';
        else if ('up' == action)
          _v('w_' + state_index + '_c_r').src  = '/i2/index/r_on_mo.gif';
        else if ('click' == action)
            tp_change(state_index, state[state_index] + 1, direction);
    }
}

function tp_change(state_index, new_state, direction)
{
    if (state[state_index] == new_state)
        return;        

    if (new_state == 0)
    {
        _v('w_' + state_index + '_c_l').src = '/i2/index/l_disable.gif';
        _v('w_' + state_index + '_c_c').src = '/i2/index/splitter_disable.gif';
        _v('w_' + state_index + '_c_r').src  = '/i2/index/r_active.gif'
    }
    else if (new_state == maxstate[state_index] - 1)
    {
        _v('w_' + state_index + '_c_r').src = '/i2/index/r_disable.gif';
        _v('w_' + state_index + '_c_c').src = '/i2/index/splitter_disable.gif';
        _v('w_' + state_index + '_c_l').src  = '/i2/index/l_active.gif'
    }
    else
    {
        if (null == direction || 'next' == direction)
            _v('w_' + state_index + '_c_l').src  = '/i2/index/l_active.gif'

        if (null == direction || 'prev' == direction)
            _v('w_' + state_index + '_c_r').src  = '/i2/index/r_active.gif'
    }

	$(':image').attr('disabled', true);

    _v('i_' + state_index + '_' + state[state_index]).src = '/i2/index/dot.gif';
    _v('i_' + state_index + '_' + state[state_index]).className = 'hd';
    _v('i_' + state_index + '_' + new_state).src = '/i2/index/dot_selected.gif';
    _v('i_' + state_index + '_' + new_state).className = '';

    var h = '';
    var h_temp;

	if (state[state_index] < new_state)
	{
        for (var i = state[state_index]; i <= new_state; i++)
        {
            h += $('#w_' + state_index + '_' + i).html();
        }

		h_temp  = $('#w_' + state_index + '_' + new_state).html();
		
		$('#container_' + state_index).css('width', 210*(1 + new_state-state[state_index]));
        $('#container_' + state_index).html(h);
		$('#container_' + state_index).animate({left:'-' + 210*(new_state-state[state_index]) + 'px'}, 200, 'swing', function()
		{
			$('#container_' + state_index).html(h_temp);
			$('#container_' + state_index).css('left', '0px');
			$(':image').attr('disabled', false);
		});
	}
	else
	{
        for (var i = new_state; i <= state[state_index]; i++)
        {
            h += $('#w_' + state_index + '_' + i).html();
        }

		h_temp  = $('#w_' + state_index + '_' + new_state).html();
		
    	$('#container_' + state_index).css('width', 210*(1 - new_state + state[state_index]));
		$('#container_' + state_index).html(h);
		$('#container_' + state_index).css('left','-' + 210*(state[state_index] - new_state) + 'px');
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
		$('#container_' + state_index).animate({left:'0px'}, 200, 'swing', function()
		{
			$('#container_' + state_index).html(h_temp);
			$('#container_' + state_index).css('left', '0px');
			$(':image').attr('disabled', false);
		});
	}

    state[state_index] = new_state;
   
    var tmp ;
    if (0 == state_index)
       tmp = DA;
    else if (1 == state_index)
       tmp = IA;
    else if (2 == state_index)
       tmp = PA;
    else if (3 == state_index)
       tmp = OA;
   
   // _v('is_' + state_index).innerHTML = '<a href="/' + tmp[new_state].u +'"><img src="' + tmp[new_state].i + '" alt="' + _v('i_' + state_index + '_' + new_state).alt  + '" width="210" height="210" /></a>';
    _v('is_' + state_index + '2').innerHTML = '<a href="/' + tmp[new_state].u +'">' + tmp[new_state].t  + '</a>';
}
