var PreloadFlag = false;
var expDays = 90;
var exp = new Date(); 
var tmp = '';
var tmp_counter = 0;
var tmp_open = 0;

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function SetCookie(name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1)
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	} 
	return null;
}

function ShowHide(id1, id2, id3) 
{
	var res = expMenu(id1);
	if (id2 != '') expMenu(id2);
	if (id3 != '') SetCookie(id3, res, exp);
}
	
function expMenu(id) 
{
	var itm = null;
	if (document.getElementById) 
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	} 
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm) 
	{
		// do nothing
	}
	else if (itm.style) 
	{
		if (itm.style.display == "none")
		{ 
			itm.style.display = ""; 
			return 1;
		}
		else
		{
			itm.style.display = "none"; 
			return 2;
		}
	}
	else 
	{
		itm.visibility = "show"; 
		return 1;
	}
}

function showMenu(id)
{
	var itm = null;
	if (document.getElementById) 
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	} 
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm) 
	{
		// do nothing
	}
	else if (itm.style) 
	{
		if (itm.style.display == "none")
		{ 
			itm.style.display = ""; 
			return true;
		}
		else
		{
//			itm.style.display = "none"; 
			return true;
		}
	}
	else 
	{
		itm.visibility = "show"; 
		return true;
	}
}

function hideMenu(id)
{
	var itm = null;
	if (document.getElementById) 
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	} 
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	if (!itm) 
	{
		// do nothing
	}
	else if (itm.style) 
	{
		if (itm.style.display == "none")
		{ 
//			itm.style.display = ""; 
			return true;
		}
		else
		{
			itm.style.display = "none"; 
			return true;
		}
	}
	else 
	{
		itm.visibility = "hide"; 
		return true;
	}
}

function showStatus(id)
{
	var itm = null;
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	
	if(!itm)
	{
		// do nowt
	}
	else if (itm.style)
	{
		if (itm.style.display == "none")
		{
			window.status = 'Click to Expand';
			return true;
		}
		else
		{
			window.status = 'Click to Collapse';
			return true;
		}
	}
	else
	{
		window.status = 'Help';
		return true;
	}
}




function imgFit (img, maxImgWidth) 
{ 
  if (typeof img.naturalWidth == 'undefined') { 
    img.naturalHeight = img.height; 
    img.naturalWidth = img.width; 
  } 
  if (img.width > maxImgWidth) { 
    img.height = Math.round(((maxImgWidth)/img.width)*img.height); 
    img.width = maxImgWidth; 
    img.title = 'Click image to view full size'; 
    img.style.cursor = 'move'; 
  } else if (img.width == maxImgWidth && img.width < img.naturalWidth) { 
    img.height = img.naturalHeight; 
    img.width = img.naturalWidth; 
    img.title = 'Click to fit in the browser window'; 
  } 
} 

function xtoggle_block (block_id) {
	displaystyle = document.getElementById(block_id).style;
	if (displaystyle.display == 'none') {
		displaystyle.display = 'block';
	} else {
		displaystyle.display = 'none';
	}
	return false;
}

function xtoggle_TR (tr_id) {
	var tr = document.getElementById(tr_id);
	if (tr.className == 'hiddenRow') {
		tr.className = '';
	} else {
		tr.className = 'hiddenRow';
	}
	return false;
}

// Flashing Links START (from http://www.dynamicdrive.com/dynamicindex5/flashlink.htm)
var flashlinks=new Array()

function changelinkcolor(){
for (i=0; i< flashlinks.length; i++){
var flashtype=document.getElementById? flashlinks[i].getAttribute("flashtype")*1 : flashlinks[i].flashtype*1
var flashcolor=document.getElementById? flashlinks[i].getAttribute("flashcolor") : flashlinks[i].flashcolor
if (flashtype==0){
if (flashlinks[i].style.color!=flashcolor)
flashlinks[i].style.color=flashcolor
else
flashlinks[i].style.color=''
}
else if (flashtype==1){
if (flashlinks[i].style.backgroundColor!=flashcolor)
flashlinks[i].style.backgroundColor=flashcolor
else
flashlinks[i].style.backgroundColor=''
}
}
}

function init(){
var i=0
if (document.all){
while (eval("document.all.flashlink"+i)!=null){
flashlinks[i]= eval("document.all.flashlink"+i)
i++
}
}
else if (document.getElementById){
while (document.getElementById("flashlink"+i)!=null){
flashlinks[i]= document.getElementById("flashlink"+i)
i++
}
}
setInterval("changelinkcolor()", 1000)
}

if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.all)
window.onload=init
// Flashing Links END



function ajax_do (url) {
        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

function nodeClick(element){
  element.previousSibling.click();
}


$(document).ready(function(){
			$('div.spoiler-body').each( function() {
				var code = $(this).find('textarea').text();
				if(code) $(this).html(code);
			});
			var context = context || 'body';
        $('div.spoiler-head', $(context))
                .click(function(){
					var code = $(this).next('div.spoiler-body').find('textarea').text();
					if(code) $(this).next('div.spoiler-body').html(code);
					$(this).toggleClass('unfolded');
					$(this).next('div.spoiler-body').slideToggle('fast');
					fix_linked_image_sizes();
                });
});
function show_hide(the_layer)
{
  if(document.getElementById(the_layer))
  {
    if(document.getElementById(the_layer).style.display == 'none')
    {
      document.getElementById(the_layer).style.display = 'inline';
    }
    else
    {
      document.getElementById(the_layer).style.display = 'none';
    }
  }
}



function set_hid_cbox (cb_id, post_id, tr1_id, tr2_id)
{
        document.getElementById('del_split_row').className = 'row1';
        var cb  = document.getElementById(cb_id);
        var tr1 = document.getElementById(tr1_id);
        var tr2 = document.getElementById(tr2_id);
        cb.value        = (cb.value == post_id) ? 0 : post_id;
        if (cb.value == post_id) {
                tr1.className = tr2.className = 'sel';
        }
        else {
                tr1.className = tr2.className = ( !(tr1_id % 2) ) ? 'row1' : 'row2';
        }
        return false;
}
function toggle_disabled (id, val) {
        var el = document.getElementById(id);
        if (val == 1) {
                el.disabled = 0;
        }
        if (val == 0) {
                el.disabled = 1;
        }
        return false;
}




function unveil_spoiler(id)
{
	var element = document.getElementById(id);

}









$().ready(function() {
  
  var triggers = $('a.ex3bTrigger')[0];
  $('#ex3b').jqm({
    trigger: triggers,
    ajax: '/misc/ajax/simpletpl/return_password.tpl',
    target: 'div.jqmPassbackContent',
    overlay: 0
    });
  
  if($.browser.msie) {
  $('div.jqmPassback .jqmClose')
  .hover(
    function(){ $(this).addClass('jqmCloseHover'); }, 
    function(){ $(this).removeClass('jqmCloseHover'); });
  }
});





function usercp_register()
{


var profile_login = document.getElementById('profile_login');
var profile_login_error = document.getElementById('profile_login_error');


var profile_mail = document.getElementById('profile_mail');
var profile_mail_error = document.getElementById('profile_mail_error');


var profile_pass1 = document.getElementById('profile_pass1');
var profile_pass1_error = document.getElementById('profile_pass1_error');

var profile_pass2 = document.getElementById('profile_pass2');
var profile_pass2_error = document.getElementById('profile_pass2_error');


var return_error="";
if (!profile_login.value) {return_error=+"Имя не указано\n"; profile_login.style.border='1px solid red'; profile_login_error.innerHTML="Не указано Имя";}
else {profile_login.style.border='1px solid green'; profile_login_error.innerHTML="";}

if (!profile_mail.value) {return_error=+"email не указано\n"; profile_mail.style.border='1px solid red'; profile_mail_error.innerHTML="Не указан email";}
else 
{
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(profile_mail.value)) { profile_mail.style.border='1px solid green'; profile_mail_error.innerHTML="";}
else { return_error=+"email не верен\n"; profile_mail.style.border='1px solid red'; profile_mail_error.innerHTML="Не верный email"; }
	

}


if (!profile_pass1.value) {return_error=+"пароль не указано\n"; profile_pass1.style.border='1px solid red'; profile_pass1_error.innerHTML="Не указан пароль";}
else {profile_pass1.style.border='1px solid green'; profile_pass1_error.innerHTML="";}

if (!profile_pass2.value) {return_error=+"пароль2 не указано\n"; profile_pass2.style.border='1px solid red'; profile_pass2_error.innerHTML="Не указано подтверждение пароля";}
else {profile_pass2.style.border='1px solid green'; profile_pass2_error.innerHTML="";}

if (profile_pass1.value || profile_pass2.value)
{
if (profile_pass1.value!= profile_pass2.value) {return_error=+"Подтверждение пароля не верно\n"; profile_pass2.style.border='1px solid red'; profile_pass1.style.border='1px solid red';  profile_pass2_error.innerHTML="Подтверждение пароля не верно";}
else {profile_pass2.style.border='1px solid green'; profile_pass1.style.border='1px solid green';  profile_pass2_error.innerHTML="";} 
}

if (return_error=='') { return true; }
else 
{
return false;
}

}





var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(id)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
	$.ajax({
url: siteurl+'ajax.php?mode=medalinfo&id='+id,
type: 'GET',
complete: function (xhr) {if (xhr.responseText!='') {
body = document.getElementById('popchieldbody');
lixlpixel_tooltip.innerHTML=xhr.responseText; }}	
});

    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}