/** $Id: javascript.js,v1.3 2006/05/23 advocat Exp $ */
if(self!=top){top.location.href=window.location.href;}function goURL(url){top.location.href=url;}if(typeof(thisURL)=='string'){var domain=document.domain;setTimeout("goURL((domain?'http://'+domain:'')+thisURL)",600000);}
var q_domain,q_text_show,q_text_hide;

function timezone(tz_global,text){
    var class_date=new Date();
    var tz_local=-(class_date.getTimezoneOffset()/60);
    
    if(tz_local&&tz_local!=tz_global){
        document.write('<img src="http://img.'+q_domain+'/icons/ltime.gif" alt="'+text+'" border="0" class="absmiddle"> <a href="/apply/?timezone='+tz_local+'">'+text+'<'+'/a>');
        //document.location="/apply/?timezone="+tz_local;
    }
}

var u_menu = new Array();
u_menu['top'] = 1;
u_menu['cat'] = 1;
u_menu['reg'] = 1;
u_menu['src'] = 1;
function initMenu(id) {
    var od = document.getElementById('d_'+id);/*td menu div*/
    if(od) {
        od.style.overflow = 'hidden';
    }
    u_menu[id] = 0;
}
function useMenu(id)
{
    if (u_menu[id] == 1) {
        return ;
    }
	var ob = document.getElementById('b_'+id);/*td box*/
	var od = document.getElementById('d_'+id);/*td menu div*/
	var ot = document.getElementById('t_'+id);/*td menu div table*/
	var bs = 'box-s';/*css class box show*/
	var bh = 'box-i';/*css class box hide*/
	
	if (ob.className == bs) {
		/*show*/
		u_menu[id] = 1;
		useMenuShow(id, 1, 0);
	} else {
		/*hide*/
		u_menu[id] = 1;
		useMenuShow(id, 0, 0);
	}
} function useMenuShow(id,c,j)
{
	var ob = document.getElementById('b_'+id);/*td box*/
	var od = document.getElementById('d_'+id);/*td menu div*/
	var ot = document.getElementById('t_'+id);/*td menu div table*/
	var bs = 'box-s';/*css class box show*/
	var bh = 'box-i';/*css class box hide*/
	
	var step = 10;
	
	var hd = parseInt(od.offsetHeight);
	var ht = parseInt(ot.offsetHeight);
	
	if (c) {
		/*hide*/
		if (j) {
			od.style.height = '0px';
		} else {
			if (hd > step + 1) {
				od.style.height = (hd - step)+'px';
				setTimeout("useMenuShow('"+id+"',1,0)", 1);
			} else {
				od.style.height = '0px';
				ob.className = bh;
				u_menu[id] = 0;
			}
		}
	} else {
		/*show*/
		if (hd < (ht + step + 1)) {
			od.style.height = (hd + step)+'px';
			setTimeout("useMenuShow('"+id+"',0,0)", 1);
		} else {
			od.style.height = '';
			ob.className = bs;
			u_menu[id] = 0;
		}
	}
}
var q_show = true;
function qMenuShow ()
{
	var et = document.getElementById('qtable');
	var ed = document.getElementById('qdiv');
	var eb = document.getElementById('qbox');
	var ht = parseInt(et.offsetHeight);
	var hd = parseInt(ed.offsetHeight);
	if (q_show) {
		if (hd>10) {
			ed.style.height = (hd-10)+'px';
			setTimeout("qMenuShow()", 1);
		} else {
			ed.style.height='0px';
			eb.innerHTML = '<img src="http://img.'+q_domain+'/icons/qshow.gif" alt="" class="absmiddle" /><a href="javascript:qMenuShow()">'+q_text_show+'</a>';
			q_show = false;
		}
	} else {
		if (hd<(ht-10)){
			ed.style.height=(hd+10)+'px';
			setTimeout("qMenuShow()", 1);
		} else {
			ed.style.height='';
			eb.innerHTML = '<img src="http://img.'+q_domain+'/icons/qhide.gif" alt="" class="absmiddle" /><a href="javascript:qMenuShow()">'+q_text_hide+'</a>';
			q_show = true;
		}
	}
}

// name - имя cookie
// value - значение cookie
// [expires] - дата окончания действия cookie (по умолчанию - до конца сессии)
// [path] - путь, для которого cookie действительно (по умолчанию - документ, в котором значение было установлено)
// [domain] - домен, для которого cookie действительно (по умолчанию - домен, в котором значение было установлено)
// [secure] - логическое значение, показывающее требуется ли защищенная передача значения cookie

var caution = false;

function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie превышает 4KB и будет вырезан !"))
                        document.cookie = curCookie
}
// name - имя считываемого cookie

function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
// name - имя cookie
// [path] - путь, для которого cookie действительно
// [domain] - домен, для которого cookie действительно
function deleteCookie(name, path, domain) {
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
        }
}

function printSkypeStatusIcon(skypename)
{
	document.write('<a href="skype:' + skypename + '?chat" style="text-decoration:none"><scr' + 'ipt type="text/javas' + 'cript">\n' +
	'<!--\n' +
	'document.write(\'<img src="http://mystatus.skype.com/smallicon/' + skypename + '?\'+Math.random()+\'" style="border:none;vertical-align:middle;" alt="' + skypename + '" />\')\n' +
	'//-->\n' +
	'</scr' + 'ipt>\n' + '</a>');
}

function set_client_timezone()
{
    var d=new Date();
    var gmtHours = -d.getTimezoneOffset()/60;

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            window.location.href=window.location.href;
        }
    }
    xmlhttp.open("GET","/apply/?timezone="+gmtHours, true);
    xmlhttp.send();
}
function RTsetCookie( name, value, path, domain, time ) {
    var secure = '';
    var today = new Date();
    today.setTime( today.getTime() );
    if (time == ''){
        expires = 1 * 1000 * 60 * 60 * 6;
    } else expires = 1 * 1000 * 60 * 60 * time;

    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" : "" );
}
function RTgetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;      } else {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end));
}


