function go (url)
{
    if (url == '') return false;
    location.href=url;
    return true;
}
var rowShow=(document.all?'block':'table-row');

function decrypt_asymmetric(encrypted_value, encrypted_secret_key_value, private_key_value)
{
    return encrypted_value;
}

function setValue(element_id, value, b_parent)
{
    //default value
    b_parent = typeof(b_parent) != 'undefined' ? b_parent : false;
    if(b_parent == true)
    {
        el = parent.document.getElementById(element_id);
    } 
    else
    {
        el =        document.getElementById(element_id);
    }

    //"text
    //"td"
    //"select-one"
    if(el.type == "TD")
    {
        el.innerHTML = value;
         //TD
    }
    else if(el.type == "text")
    {
        el.value = value;
         //<input type="text">
    }
    else if(el.type == "select-one")
    {
        el.selectedIndex = value;
        if(el.onchange)
        {
            el.onchange();
        }
    }
}

/**
 * Отправить зашифрованные данные на расшифровку.
 */
function decryptGroupJavascript(group_id, form_id, form_action_id, encrypted_data_index_id, form_target)
{
    //Поменять action формы (перенаправить на модуль Crypto), сделать сабмит.
    el = document.getElementById(encrypted_data_index_id);
    el.value = group_id;

    el = document.getElementById(form_action_id);
    old_form_action = el.value;
    el.value = 'DecryptRsaBlowfishJavascript';

    el = document.getElementById(form_id);
    old_form_target = el.target;
    el.target = form_target;
    el.submit();

    setTimeout('restoreFormParams("'+form_id+'","'+old_form_target+'","'+form_action_id+'","'+old_form_action+'");', 500); //0.5 s - wait a little; form.submit and other function calls may be asynchronious.
}

function restoreFormParams(form_id, old_form_target, form_action_id, old_form_action)
{
    el = document.getElementById(form_id);
    el.target = old_form_target;

    el = document.getElementById(form_action_id);
    el.value = old_form_action;
}

function toggleRows(prefix) {
    var el,i,state;
    rows = document.getElementsByTagName("tr");
    for (var i=0; i<rows.length; i++) {
        row = rows[i];
        if (row.id.indexOf(prefix) == -1) continue;
        state=('none'==row.style.display?1:0);
        row.style.display=(state?rowShow:'none');
    }
    img = document.getElementById("img_" + prefix);
    if (img) {
        if (state) {
            img.src = "images/minus.gif";
        } else {
            img.src = "images/plus.gif";
        }
    }
    SetCookie('rowShowState'+prefix, state);
}

function setFromState(prefix) {
    var el,i,state=GetCookie('rowShowState'+prefix)*1;
    rows = document.getElementsByTagName("tr");
    for (var i=0; i<rows.length; i++) {
        row = rows[i];
        if (row.id.indexOf(prefix) == -1) continue;
        row.style.display=(state?rowShow:'none');
    }
    img = document.getElementById("img_" + prefix);
    if (img) {
        if (state) {
            img.src = "images/minus.gif";
        } else {
            img.src = "images/plus.gif";
        }
    }
}

function setVisible(prefix) {
    var el=document.getElementById(prefix);
    rows = document.getElementsByTagName("tr");
    for (var i=0; i<rows.length; i++) {
        row = rows[i];
        if (row.id.indexOf(prefix) == -1) continue;
        row.style.display=(rowShow);
    }
    img = document.getElementById("img_" + prefix);
    if (img) {
        img.src = "images/minus.gif";
    }
}

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 SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (2 < argc) ? argv[2] : null;
    var path = (3 < argc) ? argv[3] : null;
    var domain = (4 < argc) ? argv[4] : null;
    var secure = (5 < argc) ? 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 getAttrHelp(type_id, view_tag, attr_of_obj, WindowWidth, WindowHeight) {
	if (!WindowHeight)
	{
		WindowHeight = '220';
	}
	if (!WindowWidth)
	{
		WindowWidth = '352';
	}
	if (!attr_of_obj)
	{
		attr_of_obj='prod_attr';
	}
	var file_prefix = "";
	if (attr_of_obj=="custsl_attr"||attr_of_obj=="custbt_attr")
	{
		file_prefix = "cust_"
	}
    var bars_width = 47;
    var winl = (screen.width - WindowWidth) / 2;
    var wint = ((screen.height - WindowHeight) - bars_width) / 2;
    helpWnd = window.open(file_prefix+'attr_help.php?type_id='+type_id+'&view_tag='+view_tag+'&attr_of_obj='+attr_of_obj, 'help', 'top='+wint+',left='+winl+',width='+WindowWidth+',height='+WindowHeight+',toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,resizable=yes');
    helpWnd.focus();
}

function openURLinNewMinimizedWindow(url, windowName) {
    //starting width and height
    var w = 100;
    var h = 100;
    var bars_width = 47;

    var winl = (screen.width - w) / 2;
    var wint = ((screen.height - h) - bars_width) / 2;
    
    var params = 'top='+wint+',left='+winl+',width='+w+',height='+h+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes';

    helpWnd = window.open(url, windowName, params);
    helpWnd.focus();
    return helpWnd;
}

function openURLinNewWindow(url, windowName) {
    var w = 740;
    var h = 600;
    var bars_width = 47;

    var winl = (screen.width - w) / 2;
    var wint = ((screen.height - h) - bars_width) / 2;
    
    var params = 'top='+wint+',left='+winl+',width='+w+',height='+h+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes';

    helpWnd = window.open(url, windowName, params);
    helpWnd.focus();
    return helpWnd;
}

function closeAndFocusParent()
{
    if(!(!window.opener || window.opener.closed))
    {
        window.opener.focus();
    }
    window.close();
}

function closeAndReloadParent()
{
    if(!(!window.opener || window.opener.closed))
    {
        window.opener.location.reload();
        window.opener.focus();
    }
    window.close();
}

function disableButtons(buttonsArray)
{
	for (i=0; i<buttonsArray.length; i++)
	{
		var button = document.getElementById(buttonsArray[i]);
		if (button!=null)
		{
			button.onclick = "";
		}
	}
}

var DOM = (typeof(document.getElementById) != 'undefined');
function selectItems (formId)
{
    if (!DOM) return;
    var form = document.forms[formId];
    var selectAll = document.getElementById('SelectAll');
    var checked = selectAll.checked;
    var elements = form.elements;
    for(i = 0; i < elements.length; i++) {
        elem = elements[i];
        if (elem.id.indexOf('select_') != -1) {
            elem.checked = checked;
            selectRow(elem);
        }
    }
    return true;
}

function selectRow (Element, css_class_name) {
    if (!DOM) return;
    //default value
    css_class_name = typeof(css_class_name) != 'undefined' ? css_class_name : 'selected';

    var selectedTableRow = Element.parentNode.parentNode;
    if (Element.checked) {
        selectedTableRow.className = css_class_name;
    } else {
        selectedTableRow.className = '';
    }
}

function selectRowAlways (Element, css_class_name) {
    if (!DOM) return;
    //default value
    css_class_name = typeof(css_class_name) != 'undefined' ? css_class_name : 'selected';

    var selectedTableRow = Element.parentNode.parentNode;
    selectedTableRow.className = css_class_name;
}

function selectRowDeselectOther (Element) {
    if (!DOM) return;
    var buttons_with_the_same_name = document.getElementsByName(Element.name); 
    
    for(var i=0; i<buttons_with_the_same_name.length; i++) 
    {
        if (Element != buttons_with_the_same_name[i]) 
        {
            buttons_with_the_same_name[i].checked = false;
        }
        buttons_with_the_same_name[i].parentNode.parentNode.className = '';
    }

    var selectedTableRow = Element.parentNode.parentNode;
    if (Element.checked) {
        selectedTableRow.className = 'selected';
    } else {
        selectedTableRow.className = '';
    }
}

function UncheckAll(formId)
{
    var form = document.forms[formId];
    if (document.getElementById)
    {
        var selectAll = document.getElementById('SelectAll');
        selectAll.checked = false;
    }
    return true;
}

function number_format(num, digits, dec_point, thousands_sep)
{
    nStr = num.toFixed(digits);
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? dec_point + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    if (thousands_sep)
    {
        while (rgx.test(x1))
        {
            x1 = x1.replace(rgx, '$1' + thousands_sep + '$2');
        }
    }
    return x1 + x2;
}

function ShowHint(URL, WindowWidth, WindowHeight)
{
	if (!WindowHeight)
	{
		WindowHeight = '320';
	}
	if (!WindowWidth)
	{
		WindowWidth = '400';
	}
    var bars_width = 47;
    var winl = (screen.width - WindowWidth) / 2;
    var wint = ((screen.height - WindowHeight) - bars_width) / 2;
    hintWnd = window.open(URL, 'hint', 'top='+wint+',left='+winl+',width='+WindowWidth+',height='+WindowHeight+',toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,resizable=yes,scrollbars=yes');
    hintWnd.focus();
}
function setFocusOnFirstElement()
{
    var i=0;
    while (document.forms[i])
    {
        form = document.forms[i];
        var j = 0;
        while (form.elements.item(j))
        {
            switch (form.elements.item(j).tagName)
            {
                case "INPUT":
                            if(form.elements.item(j).type == "text" && form.elements.item(j).clientHeight!=0 && form.elements.item(j).clientWidth!=0)
                            {
                                if (!form.elements.item(j).disabled)
                                {
                                    form.elements.item(j).focus();
                                    return;
                                }
                            }
                            break;
                case "TEXTAREA":
                            if(form.elements.item(j).clientHeight!=0 && form.elements.item(j).clientWidth!=0)
                            {
                                if (!form.elements.item(j).disabled)
                                {
                                    form.elements.item(j).focus();
                                    return;
                                }
                            }
                            break;
            }
            j++;
        }
        i++;
    }
}


function array_unshift(var_array)
{
    var A_u = 0;
    for (A_u = var_array.length-1; A_u >= 0; A_u--)
    {
        var_array[A_u + (arguments.length-1)] = var_array[A_u];
    }
    for (A_u = 0; A_u < (arguments.length-1); A_u++)
    {
        var_array[A_u] = arguments[A_u+1];
    }
    return var_array;
}

function is_array(variable)
{
   var source = variable.toSource();
   return (source.search(/^\[([^,]*,)+[^,]*\]/) != -1);
}

/*
Execute javascript function.
Each parameter from params array will be surrounded by quotes, 
so all parameters must be simple strings.
*/
function asc_exec_ellipsis_args_only_strings(function_name, params)
{
    command = function_name+"(";
    if(params.length >0)
    {
        command = command+"'"+params[0]+"'";
        for(i=1; i< params.length; i++)
        {
            command = command+", '" + params[i] + "'";
        }
    }
    command = command+")";
    return eval(command);
}

function disableBlock(block_id, z_index)
{
	var _element = document.getElementById(block_id);

    if(!_element.offsetParent)
        return;
	
	var _width  = _element.offsetWidth;
	var _height = _element.offsetHeight;
	var _left = _element.offsetLeft;
	var _top = _element.offsetTop;
	obj = _element;
	while(obj.offsetParent)
	{
		_left+=obj.offsetParent.offsetLeft;
		_top+=obj.offsetParent.offsetTop;
		obj=obj.offsetParent;
	};

    var d = document.getElementById('hd_'+block_id);
	if (!d) {
		d = document.createElement('DIV');
		d.id = 'hd_'+block_id;
		document.body.appendChild(d);
	};

    _width-=2;
    _height-=2;
    if(_width < 0) _width = 0;
    if(_height < 0) _height = 0;
    
    d.style.display = 'none';
    d.style.position = 'absolute';
    d.style.width = _width + 'px';
    d.style.height = _height + 'px';
    d.style.left = _left + 'px';
    d.style.top = _top + 'px';
    d.style.zIndex = z_index;
    d.style.border = 'solid 1px black';
    d.style.display = '';

	// фюсрты хь яюыєяЁючЁрўэюёЄ№
	if(navigator.userAgent.indexOf("MSIE 6")!=-1)
	{
	  d.style.backgroundImage='none';
	  d.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/halftranspixel.png', sizingMethod='scale')";
	}
	else
	{
	  d.style.backgroundImage='url("images/halftranspixel.png")';
	}
};
function enableBlock(block_id)
{
    var _element = document.getElementById('hd_'+block_id);
    if(!_element)
        return;
        
    _element.style.display = 'none';
};
function showBlock(block_id, z_index)
{
    document.getElementById(block_id).style.zIndex = z_index;
    document.getElementById(block_id).style.display = '';
};
function hideBlock(block_id)
{
    document.getElementById(block_id).style.display = 'none';
};

function disableButton(button_id)
{
    if(document.getElementById(button_id).className.indexOf('button_disabled')==-1)
    {
        document.getElementById(button_id).className += ' button_disabled';
        document.getElementById(button_id).onclick = function() {};
    };
};

function enableButton(button_id,onclick_function)
{
    document.getElementById(button_id).className = document.getElementById(button_id).className.replace(' button_disabled','');
    document.getElementById(button_id).onclick = onclick_function;
};


function NavCellMouseOver(id)
{
	document.getElementById(id).className            = 'ActiveNavCellBorder';
	document.getElementById(id+'_content').className = 'ActiveNavCellContent';
	document.getElementById(id+'_header').className  = 'ActiveNavCellHeader';
};

function NavCellMouseOut(id)
{
	document.getElementById(id).className            = 'InactiveNavCellBorder';
	document.getElementById(id+'_content').className = 'InactiveNavCellContent';
	document.getElementById(id+'_header').className  = 'InactiveNavCellHeader';
};

