﻿function checkAction(param, action)
{
	var actionText = "Подтверждаете действие: " + action + " ?";
	if (window.confirm(actionText))
	{
		location.href = param;
	}
	else
	{
		return false;
	}
}
function refreshCheckcode()
{
	$('#checkcode').attr('src', pb_url+'checkcode.php?' + '&random=' + Math.random());
}
function digg(id, param, type)
{
	var digg_count = $('#'+param+'_'+type+'_'+id);
	var digg_do = $('#'+param+'_'+type+'_do_'+id);
	$.ajax({
		type: 'GET',
		url: pb_url+'ajax.php',
		dataType: 'json',
		data: 'action=' + param + '&type=' + type + '&id=' + id + '&verifyhash=' + verifyhash + '&random=' + Math.random(),
		error: function(var1,var2,var3)
		{
			pb_tip(param+'_'+type+'_do_'+id, ajax_response_failed);
		},
		success: function(data)
		{
			if (data[0]=='1')
			{
	            pb_tip(param+'_'+type+'_do_'+id,data[1]);
	            digg_count.html(data[2]);
	            if (param == 'comment')
	            {
		            digg_do.removeAttr('onclick').html('['+(type=='digg'? digged : buried)+']');
	            }
	            else
	            {
	            	digg_do.html('<span class=\"'+type+'ed\">'+digg_do.find('a').text()+'</span>');
	            }
			}
		}
	});
	return;
}
function pb_pop(url,title,width,height)
{
    var w = 1024;
    var h = 768;
    if (document.all || document.layers)
    {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    var leftPos = (w/2-width/2);
    var topPos = (h/2.3-height/2.3);
    window.open(url,title,"width="+width+",height="+height+",top="+topPos+",left="+leftPos+",scrollbars=no,resizable=no,status=no");
}
function show_menu(obj,id)
{
	$('#'+obj+id).slideToggle("slow",menu_icon(obj,id)); 
}
function menu_icon(obj,id)
{
	var src = $('#'+obj+'icon_'+id).attr("src");
	if ($('#'+obj+id).css('display') == 'none')
	{
		var re = /expand\.gif/g;
		src = src.replace(re, 'collapse.gif');
		$('#'+obj+'icon_'+id).attr("src", src);
		$('#'+obj+'icon_'+id).attr("alt", 'Закрыть');
	}
	else
	{
		var re = /collapse\.gif/g;
		src = src.replace(re, 'expand.gif');
		$('#'+obj+'icon_'+id).attr("src", src);
		$('#'+obj+'icon_'+id).attr("alt", 'Открыть');
	}
}
function changeAvatar(obj)
{
	var avatar = $('#avatar_'+obj);
	var oldavatar = $('#savatar').val();
	if (oldavatar)
	{
		var avatarid = oldavatar.split('|');
		$('#avatar_'+avatarid[1]).removeClass("onavatar");
		if (obj == avatarid[1])
		{
			$('#savatar').val('');
			return;
		}
	}
	$('#avatar_'+obj).addClass("onavatar");
	$('#savatar').val(avatar.attr('name')+'|'+obj);
}
var gocheck = true;
function PBchoseAll(form)
{
	for(var i = 0; i < form.elements.length; i ++)
	{
		var e = form.elements[i];
		if (e.type == 'checkbox')
		{
			e.checked = gocheck;
		}
	}
	gocheck = (gocheck == true) ? false : true;
}
var curattaid = 1;
function addattachment()
{
	var clonenode = $("p[name='attachbody']");
	if (clonenode.length < attachnum)
	{
		curattaid++;
		$('#upload').append('<p name="attachbody"><input type="file" name="attachments_'+curattaid+'"></p>');
	}
}
function delattachment()
{
	var clonenode = $("p[name='attachbody']");
	if (clonenode.length > 1)
	{
		curattaid--;
		$("p[name='attachbody']:last").remove();
	}
}
function checktitle()
{
	var title = $('#title').val();
	if (title.length < title_min || title.length > title_max)
	{
		$('#cktitle').text(title_tip);
	}
	else
	{
		$('#cktitle').text('');
	}
}
function checksource()
{
	var url = $('#source').val();
	if (!url) return;
	var reg = /^(https?|ftp|gopher|news|telnet|mms|rtsp):\/\/[^\s]*$/i;
	if (!reg.test(url))
	{
		$('#cksource').text(sourcelink_tip);
	}
	else
	{
		$('#cksource').text('');
	}
}

var tagnum = 0;
function addTag(tagName)
{
	if (tagnum < 5)
	{
		var tagObj = $('#tag');
		var tags = tagObj.val();
		if (tags.length > 0)
		{
			tagdata = tags.split(",")
			for (i=0; i < tagdata.length; i++)
			{
				if (tagdata[i].toLowerCase() == tagName.toLowerCase())
				{
					return false;
				}
			}
			tagObj.val(tags+"," + tagName);
		}
		else
		{
			tagObj.val(tagName);
		}
		tagnum++;
	}
	return false;
}
function toggleLogin()
{
	$('#login').animate({opacity:'toggle'},'slow',function(){if ($('#login').css('display')!='none') $('#username').focus();});
}
function keysubmit(event, post)
{
	if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83))
	{
		if (post)
		{
			$('#submit').click();return;
		}
		$('#send_comment').click();
	}
}
function postForm()
{
	var title = $('#title').val();
	if (title.length < title_min || title.length > title_max)
	{
		$('#cktitle').text(title_tip);return false;
	}
	var url = $('#source').val();
	var reg = /^(https?|ftp|gopher|news|telnet|mms|rtsp):\/\/[^\s]*$/i;
	if (url && !reg.test(url))
	{
		$('#cksource').text(sourcelink_tip);return false;
	}
	var content = document.getElementsByName('content')[0].value;
	if (content.length < content_min || content.length > content_max)
	{
		$('#ckcontent').text(content_tip);return false;
	}
	return true;
}
function FullWin(tag) {
   var newWinObj = window.open(tag,'newWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width=950,height=680')
}
function addNetscapePanel() {
   if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
   {
       window.sidebar.addPanel ("$insert[site_name]", "$insert[site_url]/sidebar.php","");
   }
   }

function bookmark() {
window.external.AddFavorite("http://corsairs.hclan.org", "Corsairs Clan")
}

function SetCookie(cookie, str) {
	document.cookie = cookie+"="+escape(str)+"; path=/; expires=Fri, 01-Jan-2010 00:00:00 GMT";
}

function GetCookie(cookie) {
	var i1 = document.cookie.indexOf(cookie+"=");
	if(i1<0) return "";
	i1 += cookie.length+1;
	var i2 = document.cookie.indexOf(";", i1);
	if(i2<0) i2 = document.cookie.length;
	return unescape(document.cookie.substring(i1, i2));
}

function GetNick () {
	var n=GetCookie("selected_nick")||GetCookie("detected_nick")||"";
	return n;
}

var nick="";
nick=GetNick();

function detect_DoFSCommand(command, args) {
	if (command == "OK")  {
		var oldnick = GetCookie("detected_nick");
		var t = args.split("\t");
		SetCookie("detected_nick",t[0]);
		nick=GetNick();
		if(GetCookie("selected_nick")=="" && oldnick!="" && oldnick!=t[0]){
			AskSelectPers(oldnick,t[0]);
		}
	}
}
if (navigator.appName.indexOf("Microsoft") != -1) {// Hook for Internet Explorer.
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub detect_FSCommand(ByVal command, ByVal args)\n');
	document.write('Call detect_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

var domain = 'timezero.de';
var domain_http = 'www.timezero.de';
var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var set_on = false;
var IE = navigator.appName.indexOf("Microsoft") != -1;
var nIE = (IE && parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ") + 5))>=6);
var smile_n=1;
var mouseX=0,mouseY=0;
var isSelected = false;

function Inf(login, e){
	if (!login.length) { Out(); return; }
	var obj = document.getElementById("hint");
	var lang = top.current_lang || 'de';
	if (e) {
		mouseX = e.clientX;
		mouseY = e.clientY;
	}
	obj.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="334" height="335" id="info"><param name="movie" value="http://game.'+domain+'/info.swf?language='+lang+'" /><param name="allowScriptAccess" value="always" /><param name="quality" value="high" /><param name="base" value="http://game.'+domain+'/" /><param name="bgcolor" value="#43454F" /><param name="flashvars" value="login='+login+'" /><embed src="http://game.'+domain+'/info.swf?language='+lang+'" base="http://game.'+domain+'/" quality="high" width="334" height="335" id="info" name="info" swLiveConnect="true" bgcolor="#43454F" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="login='+login+'" /></object>';
	obj.style.visibility = "visible";
	obj.style.left = document.body.scrollLeft + (mouseX < document.body.clientWidth/2 ? mouseX : mouseX - 300);
	obj.style.top = document.body.scrollTop + (mouseY+335 > document.body.clientHeight ? document.body.clientHeight-350 : mouseY + 5);;
}

function Out(){
	var obj = document.getElementById("hint");
	if (obj) {
		obj.innerHTML = '';
		set_on=false;
	}
}

function navigation(id, th) {
     th.style.cursor='pointer'; 
     document.getElementById('nav1').style.display = 'none';
     document.getElementById('nav2').style.display = 'none';
     document.getElementById('nav3').style.display = 'none';
     document.getElementById('nav4').style.display = 'none';
     document.getElementById('nav5').style.display = 'none';
     document.getElementById('nav6').style.display = 'none';

     document.getElementById('menu1').style.color = '#c0c0c0';
     document.getElementById('menu2').style.color = '#c0c0c0';
     document.getElementById('menu3').style.color = '#c0c0c0';
     document.getElementById('menu4').style.color = '#c0c0c0';
     document.getElementById('menu5').style.color = '#c0c0c0';
     document.getElementById('menu6').style.color = '#c0c0c0';


     if(id == '1') {
        document.getElementById('nav1').style.display = '';
        document.getElementById('menu1').style.color = '#ffffff';
     }
     if(id == '2') {
        document.getElementById('nav2').style.display = '';
        document.getElementById('menu2').style.color = '#ffffff';
     }
     if(id == '3') {
        document.getElementById('nav3').style.display = '';
        document.getElementById('menu3').style.color = '#ffffff';
     }
     if(id == '4') {
        document.getElementById('nav4').style.display = '';
        document.getElementById('menu4').style.color = '#ffffff';
     }
     if(id == '5') {
        document.getElementById('nav5').style.display = '';
        document.getElementById('menu5').style.color = '#ffffff';
     }
     if(id == '6') {
        document.getElementById('nav6').style.display = '';
        document.getElementById('menu6').style.color = '#ffffff';
     }
}

function menuover(th) {
     th.style.cursor='pointer'; 
}

function mefe(id) {
     document.getElementById('k').style.display = 'none';
     document.getElementById('p').style.display = 'none';
     document.getElementById('v').style.display = 'none';
     document.getElementById('w').style.display = 'none';
     document.getElementById('e').style.display = 'none';
     document.getElementById('a').style.display = 'none';
	 document.getElementById('g').style.display = 'none';
	 document.getElementById('i').style.display = 'none';
	 document.getElementById('m').style.display = 'none';
	 document.getElementById('s').style.display = 'none';
	 document.getElementById('h').style.display = 'none';
	 document.getElementById('c').style.display = 'none';
	 document.getElementById('l').style.display = 'none';
	 document.getElementById('t').style.display = 'none';
	 document.getElementById('b').style.display = 'none';
	 document.getElementById('f').style.display = 'none';
	 document.getElementById('u').style.display = 'none';
	 document.getElementById('j').style.display = 'none';
	 document.getElementById('d').style.display = 'none';
	 document.getElementById('r').style.display = 'none';
	 
     document.getElementById(id).style.display = '';
}

function quest(id) {
     document.getElementById('f').style.display = 'none';
     document.getElementById('h').style.display = 'none';
     document.getElementById('i').style.display = 'none';
     document.getElementById('m').style.display = 'none';
     document.getElementById('p').style.display = 'none';
     document.getElementById('l').style.display = 'none';
	 
     document.getElementById(id).style.display = '';
}
