function $(obj) { return document.getElementById(obj); }

function clearCookie(cookieName, data) {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
    setcookie(cookieName, data, yesterday, '/');
}

function setcookie(cookieName, cookieValue, expires, path, domain, secure) {

    now = new Date();
    expires = new Date(now.getTime() + 60 * 60 * 24 * 365 * 5);

	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function getcookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}

var arr = new Array;
function cshow(id, cookies) {
    //if ($("n"+id)==null) return false;

    arr[id] = !arr[id];
    
    if (cookies == 'R') {
        //alert(getcookie("c"+id));
        if (getcookie("c"+id) == 'true') arr[id] = true;
        else arr[id] = false;
    }
        
    if (arr[id]) {
        //alert('my - true');
        if (($("n"+id)!=null)) $("n"+id).className = 'nodc';
        $("d"+id).style.display = 'block';

        if (cookies == 'W') {
            setcookie("c"+id, 'true', '', '/');
        }
    } else {
        if (($("n"+id)!=null)) $("n"+id).className = 'nodo';
        $("d"+id).style.display = 'none';

        if (cookies == 'W') {
            clearCookie("c"+id, 'false');
        }
    }
}

function radio2(radio, layer) {
    if ($(radio+'_S') == null) $(radio+'_N').checked = true;
    if ($(radio+'_S') != null && $(radio+'_S').checked) {
        $(layer+'_S').style.display = 'inline';
        $(layer+'_N').style.display = 'none';
    }
    if ($(radio+'_N').checked) {
        $(layer+'_N').style.display = 'inline';
        if ($(radio+'_S') != null) $(layer+'_S').style.display = 'none';
    }
}

function menu_rainbow(rainbow, position) {

    rainbow = rainbow.split(',');
    n = rainbow.length;
    //rainbow.reverse();

    if (position == 'T') {
        R = 204;
        G = 225;
        B = 209;
    }
    
    r = 0;
    g = 0;
    b = 0;

    for (i = 1; i < n; i++) {
        id = rainbow[i];

        R = R - r;
        G = G - g;
        B = B - b;
        //alert('RGB('+R+','+G+','+B+')');
        if (i == 1) { $("v"+id).className = 'save_tcell_hover'; }
        if (($("v"+id) != null)) {
            $("v"+id).style.backgroundColor = 'RGB('+R+','+G+','+B+')';
        }
    }

}

lh = 0;
timer = new Array;
function hshow(id) {
  arr[id] = !arr[id];
  if (timer[id]) clearTimeout(timer[id]);
  if (arr[id]) {
    lh = 0;
    timer[id] = setTimeout(function() {
      $(id).style.display = 'block';
    },300);
  } else {
     lh ++;
     timer[id] = setTimeout(function() {
      $(id).style.display = 'none';
      },400*lh);
  }
}

function refresh_image(id, img) {
    rand = Math.round(Math.random() * 10000);
    imgsrc = img + '?r=' + rand;
    timer[rand] = setTimeout(function() {
        $(id).src = imgsrc;
    }, 1000);
}

//sform.submit();

function chgSearchField(id) {
    blur(id); // only for FF (bug in IE)

    for (i = 1; i <= stabs; i++) {
        if (!$('search_tab'+i)) continue;
        
        if (id == i) {
            $('search_tab'+i).className = 'stab_act';
            $('search_form'+i).style.display = 'block';
        } else {
            $('search_tab'+i).className = 'unstab_act';
            $('search_form'+i).style.display = 'none';
        }
    }
}


function gallery(id, width_small, width_big) {
    if (!$(id)) return false;

    var imgs = $(id).getElementsByTagName('IMG');
    for (var gall_i in imgs) {
        if (imgs.hasOwnProperty(gall_i)) {
            url = imgs[gall_i].src;
            url = url.replace(width_small+'', width_big+'');
            imgs[gall_i].src         = url;
            imgs[gall_i].style.width = width_big+'px';
            imgs[gall_i].style.height = ''
        }
    }
}

function sync_search_fields(id) {
    for (i = 1; i <= stabs; i++) {
        $('search_field'+i).value = $('search_field'+id).value;
    }
}

function pshow(id, s) {

  if (s == 0) {
    $("d"+id).style.display = 'block';
  } else {
    $("d"+id).style.display = 'none';
  }
}
