function GetICode()
{
	  var community_id = (document.getElementById("community_id") ? document.getElementById("community_id").value : null);
    var query = (community_id ? 'community_id=' + community_id : '');
    xmlhttpPost(getProtocol() + '//' + document.location.host + '/get_icode.php', query, 'displayICode', '');	
}

function displayICode(strIn)
{
    if(strIn)
       setInnerHTML('icode_result', strIn);
}

function BrowserDetect() 
{
   var ua = navigator.userAgent.toLowerCase();	 	 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirefox     = (ua.indexOf('firefox') != -1);
	 this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}

var browser = new BrowserDetect();

//alert(browser.isFirefox);

function toggle(id)
{
         var ide = document.getElementById(id);
         if(ide != null)
         {
            if(ide.style.display == "none")
            {
               if(browser.isFirefox)
               {
                 if(ide.tagName == "TABLE" || ide.tagName == "SELECT")
                    ide.style.display = "inline";
                 else if(ide.tagName == "TR")
                    ide.style.display = "table-row";
                 else if(ide.tagName == "TR")
                    ide.style.display = "table-cell";                                        
                 else
                    ide.style.display = "block";
               }
               else {
                 if(ide.tagName == "SELECT")
                    ide.style.display = "inline";
  							 else													 
                 		ide.style.display = "block";
							 }
            }
            else
               ide.style.display = "none";
            //ide.style.display = ide.style.display == "none" ? "block" : "none";
         }
}

function check_toggle(id)
{
         var ide = document.getElementById(id);
         if(ide != null)
            return (ide.style.display == "none") ? 0 : 1;
}

function show_element(id)
{
         if(!check_toggle(id))
            toggle(id);
}

function hide_element(id)
{
         if(check_toggle(id))
            toggle(id);    
}

function setInnerHTML(id, innerHTML)
{
         element = document.getElementById(id);
         if(typeof(element) != "undefined")
            element.innerHTML = innerHTML;
}

function getInnerHTML(id)
{
         return document.getElementById(id).innerHTML;
}

function go_by_link(_link)
{
         document.location.href = _link;
}

function emotion(value, forum_id)
{ 
 document.getElementById('new_'+forum_id+'_thread_text').value += value;
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function get_active_layer(id)
{
 				 for (i=1; i<=3; i++)
				 {
				 	if (document.getElementById('layer_'+id+"_"+i).style.display=="block")
						 return i;
				 }
				 
				 return 0;
}

function Do(forum_id, action)
{
 				 var active_layer = 0;
				 var new_layer    = 0;							 
				 
				 active_layer = get_active_layer(forum_id);
				 
		if (active_layer)
	  {	 
				if (active_layer == 1 && action == "threads")
				{
				 document.getElementById('layer_'+forum_id+"_1").style.display="none";
				 Delete_Cookie('state['+forum_id+']', '/', '');
				}
				else
				{ 		
						
						switch (action)
				 		{
				  	 case "threads":    new_layer = 1; break;
						 case "new_thread": new_layer = 2; break;
						 case "preview":    new_layer = 3; break;
				 		}
						
						 document.getElementById('layer_'+forum_id+"_"+active_layer).style.display="none";
						 document.getElementById('layer_'+forum_id+"_"+new_layer).style.display="block";
						 //document.getElementById('layer_'+forum_id+'_'+new_layer).className='board_text_over';
						 Set_Cookie( 'state['+forum_id+']', '1', '', '/', '', '' );
				 }
		 }
		 else
		 {
				 		 document.getElementById('layer_'+forum_id+"_1").style.display="block";
						 //document.getElementById('layer_'+forum_id+'_1').className='board_text_over';						 
						 Set_Cookie( 'state['+forum_id+']', '1', '', '/', '', '' );
		 }
		 
		 
}

function DoPage(forum_id, page)
{
 Set_Cookie( 'page['+forum_id+']', page, '', '/', '', '' );
}

function DoCPage(post_id, page)
{
 Set_Cookie( 'cpage['+post_id+']', page, '', '/', '', '' );
}

function Fill(forum_id)
{
 document.getElementById('preview_'+forum_id+'_thread_title').innerHTML=document.getElementById('new_'+forum_id+'_thread_title').value;
 document.getElementById('preview_'+forum_id+'_thread_text').innerHTML =document.getElementById('new_'+forum_id+'_thread_text').value;
 document.getElementById('preview_'+forum_id+'_thread_title_hidden').value=document.getElementById('new_'+forum_id+'_thread_title').value;
 document.getElementById('preview_'+forum_id+'_thread_text_hidden').value =document.getElementById('new_'+forum_id+'_thread_text').value;
}

function Clear(forum_id)
{
 document.getElementById('new_'+forum_id+'_thread_title').value="";
 document.getElementById('new_'+forum_id+'_thread_text').value="";
}

function xmlhttpPost(strURL, strSubmit, strResultFunc, waitFunc, extra_param) {

        var xmlHttpReq = false;
        
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
                xmlHttpReq = new XMLHttpRequest();
                xmlHttpReq.overrideMimeType('text/xml');
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if(waitFunc)
           eval(waitFunc + '()');
        xmlHttpReq.open('POST', strURL, true);
        xmlHttpReq.setRequestHeader('Content-Type', 
		     'application/x-www-form-urlencoded');
        xmlHttpReq.onreadystatechange = function() {
                if (xmlHttpReq.readyState == 4) {
                   eval(strResultFunc + '(xmlHttpReq.responseText' + (extra_param ? ', extra_param' : '') + ');');
                }
        }
        xmlHttpReq.send(strSubmit);
}

function switchMailSource(_source)
{
         _form = document.forms['yahoo_contacts'];
         _source_old = _form.elements['source'].value;
         if(_source != _source_old)
         {
					 hide_element('yahoo_wait');              
           hide_element('yahoo_empty');
           hide_element('yahoo_error');
           hide_element('yahoo_success');
					 setInnerHTML('contacts_login_name', eval('mail_sources.' + _source + '.email_fld'));
					 if (_source == 'mailru')
					 		 show_element('mailru_domains');
					 else
					 		 hide_element('mailru_domains');					 
           document.getElementById(_source + '_button').src = 'images/button_mail_' + _source + '_s.gif'
           if(_source_old)
              document.getElementById(_source_old + '_button').src = 'images/button_mail_' + _source_old + '.gif'           
           _form.elements['source'].value = _source;
           _form.style.padding = eval('mail_sources.' + _source + '.padding');
         }
         show_element('mail_suck_form');
}

function suckYahoo(_form)
{
         _source = _form.elements['source'].value;
				 if (typeof(eval('mail_sources.' + _source)) != 'undefined') {
    				 if(_form.elements['data[e]'].value == '' || _form.elements['data[p]'].value == '')
                return false;
              if(check_toggle('yahoo_success'))
                 toggle('yahoo_success');
              if(check_toggle('yahoo_empty'))
                 toggle('yahoo_empty');
              if(check_toggle('yahoo_error'))
                 toggle('yahoo_error');
             //setInnerHTML('_wait_msg_source', _form.elements['source'].value);
    				 setInnerHTML('_wait_msg_source', eval('mail_sources.' + _source + '.name'));					
             if(!check_toggle('yahoo_wait'))
                toggle('yahoo_wait');
             var query = 'data%5Be%5D=' + escape(_form.elements['data[e]'].value + (_source == 'mailru' ? '@' + _form['data[d]'].value : '')) + '&data%5Bp%5D=' + escape(_form.elements['data[p]'].value);
             query += "&source=" + _form.elements['source'].value;
             xmlhttpPost(getProtocol() + '//' + document.location.host + '/suck_contacts.php', query, 'displaySuckYahooResult', '');
				 }
}

function displaySuckYahooResult(strIn) {
        var strContent;
        var strResponseArray;
				
        if(check_toggle('yahoo_wait'))
           toggle('yahoo_wait');
        if(strIn)
        {
           strResponseArray = strIn.split('|');
           if(strResponseArray[0] == 1)
           {
              //setInnerHTML('_success_msg_source', strResponseArray[1]);
							setInnerHTML('_success_msg_source', eval('mail_sources.' + strResponseArray[1] + '.name'));
              setInnerHTML('_success_msg_num', strResponseArray[2]);              
              if(check_toggle('yahoo_empty'))
                 toggle('yahoo_empty');
              if(check_toggle('yahoo_error'))
                 toggle('yahoo_error');
              if(!check_toggle('yahoo_success'))
                 toggle('yahoo_success');
              document.forms['yahoo_contacts'].elements['data[e]'].value = '';
              document.forms['yahoo_contacts'].elements['data[p]'].value = '';
              show_element('view_contacts_link');
           }
           else if(strResponseArray[0] == 0)
           {
              if(check_toggle('yahoo_success'))
                 toggle('yahoo_success');
              if(check_toggle('yahoo_error'))
                 toggle('yahoo_error');
              if(!check_toggle('yahoo_empty'))
                 toggle('yahoo_empty');
              document.forms['yahoo_contacts'].elements['data[e]'].value = '';
              document.forms['yahoo_contacts'].elements['data[p]'].value = '';
           }
           else if(strResponseArray[0] == -1)
           {
              //setInnerHTML('_error_msg_source', strResponseArray[1]);
							setInnerHTML('_error_msg_source', eval('mail_sources.' + strResponseArray[1] + '.name'));							 
              if(check_toggle('yahoo_success'))
                 toggle('yahoo_success');
              if(check_toggle('yahoo_empty'))
                 toggle('yahoo_empty');
              if(!check_toggle('yahoo_error'))
                 toggle('yahoo_error');
           }
        }
}

function getProtocol()
{
         return document.location.protocol;
}

function _check_all(checkbox_name, checked, field_name, form_name)
{
        var i;
        if(!form_name)
           form_name = "select";
				for(i=0; ; i++)
				{
              checkbox = document.forms[form_name].elements[checkbox_name + '[' + i + ']' + (field_name ? '[' + field_name + ']' : '')];
						if(typeof(checkbox) == "undefined")
						   return true;
						checkbox.checked = checked;		 
				}
}

function show_banning()
{
				var i;
        var id_c;
        var id_l;
			  show_element('ban_button');        
        for(i=0; ; i++)
				{
            id_c = 'ban_checkbox_' + i;
            id_l = 'ban_link_' + i;            
						if(!document.getElementById(id_c))
						   return true;
						show_element(id_c);
						show_element(id_l);
				}
}

function show_banning_m()
{
				var i;
        var id_l;
			  show_element('ban_button_top');
			  show_element('ban_button_bottom');
        for(i=0; i < 10; i++)
				{
            id_l = 'ban_link_' + i;            
						if(document.getElementById(id_l))
						   show_element(id_l);
				}
}

function ban_m_check(i, checked)
{
        setDisabled('ban_checkbox_' + i, checked ? false : true);
}

function ban_m_submit(form)
{
         form.action = form.elements['ban_url'].value;
         form.submit();
}

function setDisabled(id, disabled)
{
         var obj = document.getElementById(id);
         if(obj)
            obj.disabled = disabled;
}

    function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
       return evt.clientX + (document.documentElement.scrollLeft ?
       document.documentElement.scrollLeft :
       document.body.scrollLeft);
    else return null;
    }
    
    function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
       return evt.clientY + (document.documentElement.scrollTop ?
       document.documentElement.scrollTop :
       document.body.scrollTop);
    else return null;
    }
    
    function bookmarksite(title, url){
    if (document.all)
    window.external.AddFavorite(url, title);
    else if (window.sidebar)
    window.sidebar.addPanel(title, url, "")
    }
    
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}    