function color_stars(object, href) {
	 var id_prefix = "rate_"
	 var curr_id = object.name.replace(id_prefix, "")

	 for(var i=1; i <= curr_id; i++) {
	     var temp = id_prefix+i
	     document.images[temp].src=href
	 }
}
function uncolor_stars(href) {
   document.images['rate_1'].src=href
   document.images['rate_2'].src=href
   document.images['rate_3'].src=href
   document.images['rate_4'].src=href
   document.images['rate_5'].src=href
}
function go_rate(object) {
	 var id_prefix = "rate_"
	 var curr_id = object.name.replace(id_prefix, "")
	 document.forms['rate_form'].elements['rating'].value = curr_id
	 document.forms['rate_form'].submit()
}

function change_pwd(a_obj)
{
    var form = document.forms["user_settings"];
    var flag = form.elements["pwd"].value;
    a_obj.innerText = flag == 1 ? "Хотите изменить пароль?" : "Передумал менять пароль!";
    form.elements["pwd"].value = flag == 1 ? 0 : 1;
    document.getElementById("tr_pwd").style.display = flag == 1 ? "none" : "";
    document.getElementById("tr_pwd2").style.display = flag == 1 ? "none" : "";
}


var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function show_diller_form(is_checked)
{
    if(is_checked) {
        document.getElementById("diller_form").style.display = "";
        document.getElementById("is_diller_id").value = 1;
    } else {
        document.getElementById("diller_form").style.display = "none";
        document.getElementById("is_diller_id").value = 0;
    }
}

function comparedCollapseExpand(domain, expired, collapse)
{

//   var d = new Date(new Date().getTime() + (30*24*60*60*1000))
//   alert(d)
    if(collapse) {
        document.getElementById('compared_list').style.display="none";
        setCookie('compared', 'collapse', expired, '/', domain, false)
    } else {
        document.getElementById('compared_list').style.display="";
        setCookie('compared', 'expand', expired, '/', domain, false)
    }

}
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration in days
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    var d = new Date(new Date().getTime() + (expires*24*60*60*1000))
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + d : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(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));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create 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 showLogin(referer)
{
	var f = document.forms['login'];
	var login_field = f.elements["register[login]"];
	var password_field = f.elements["register[password]"];

	if (document.getElementById && f) {
		var login = getCookie('brok_login');
		islogin = (login && login.length > 1);
		if (islogin) {
			if (login_field.value != login) {
				login_field.value = login;
				password_field.value = '';
			}
		}
		document.getElementById('login-form').style.display = 'block';
		f.referer.value = referer == "" ? document.location.href : referer;
		islogin ? password_field.focus() : login_field.focus();
		return false;
	}

	return true;
}

function hideLogin()
{
	if(document.getElementById('login-form')) document.getElementById('login-form').style.display = 'none';
	return false;
}

function load_banners(area_id)
{
//    jsphp_shtml('top_board','./init_bn.php','board=top&area_id=' + area_id);
//
//    if(document.getElementById("left_top_board")) jsphp_shtml('left_top_board','./init_bn.php','board=left_top&area_id=' + area_id);
//    if(document.getElementById("left_bottom_board")) jsphp_shtml('left_bottom_board','./init_bn.php','board=left_bottom&area_id=' + area_id);
//    if(document.getElementById("right_top_board")) jsphp_shtml('right_top_board','./init_bn.php','board=right_top&area_id=' + area_id);
//    if(document.getElementById("right_bottom_board")) jsphp_shtml('right_bottom_board','./init_bn.php','board=right_bottom&area_id=' + area_id);
}

function draw_submit_button (is_checked)
{
    var im = document.getElementById("sbm_vote_image");
    if (im.style.display == "none" && is_checked) {
        im.style.display = ""
    }
    return false;
}

function m2s(m){return m+'s';}
function s2m(s){return s.replace('s','');}
function id2int(id){return id.replace('s','').replace('m','');}

//Event.observe(window, 'load', function() {
//    $$('td.main').each(function(e)
//    {
//        Event.observe(e.id, 'mouseover', function(event) {
//            $$('div.sub').invoke('hide');
//        	this.up().addClassName('selected');
//        	this.addClassName('selected');
//            var offset = this.positionedOffset();
//            var style={
//                    top: (offset.top+40)+'px',
//                    left: offset.left+'px',
//                    position: 'absolute'
//                  };
//            var subId = m2s(this.id);
//            $(subId).setStyle(style).show();
//         });
//        Event.observe(e.id, 'mouseout', function(event) {
//            var relatedTarget = $(event.relatedTarget || event.target);
//            if(relatedTarget && relatedTarget.descendantOf(this)) {
//                return;
//            }
//        	this.up().removeClassName('selected');
//        	this.removeClassName('selected');
//        	$(m2s(this.id)).hide();
//        });
//    });
//});

