var locked;
var old_modcat = old_id = false;
var position = 0;
if(navigator.userAgent.indexOf('Safari')!==-1)
	browser = 'Safari';
else if(navigator.userAgent.indexOf('MSIE')!==-1)
	browser = 'IE';
else
	browser = 'FFox';

function showInfo()
{
	document.getElementById('addInfo').style.display = "block";
}

function hideInfo()
{
	document.getElementById('addInfo').style.display = "none";
}

function doOnload()
{
        var mwin = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
        if (typeof(mwin.onbeforeunload) != "undefined")
    		mwin.onbeforeunload = check_rb_state;
                
	var layer;
	if(layer = document.getElementById('GridScalex_layer'))
	{
		var total_width,right,left = getLeft(1)-1,padding=4;
		left -= padding;
		layer.style.left = left;
		layer.style.top = 0;
		document.getElementById('GridScalex_table').left = left;

		// set the total width of the table
		for(i=2;column = document.getElementById('GO_column'+(i-1));i++)
		{}
		total_width = getLeft(i-1) - getLeft(1) + padding + 1;
		document.getElementById('GridScalex_table').width = total_width;

		total_width = 0;
		for(i=2;column = document.getElementById('GO_column'+(i));i++)
		{
			right = getLeft(i);
			if(i==2)
				subtract = padding*3 + 1;
			else
				subtract = padding*2;

			//if(browser!='Safari')
			//fixed for moodle need 1 integral 2 need to check
				subtract += 2;

			document.getElementById('GO_column'+(i-1)).width = right - left - subtract;
            if(layer_header = document.getElementById('GO_column_layer_header'+(i-1)))
                layer_header.width = right - left - subtract;
            if(layer_header = document.getElementById('GO_column_layer_header2_'+(i-1)))
                layer_header.width = right - left - subtract;

			left = right;
		}
		i++;

		//if(browser!='Safari')
			subtract = 2;
		//else
		//	subtract = 0;

		document.getElementById('GO_column'+(i-2)).width = getLeft(i-1) - getLeft(i-2) - padding - subtract;
        if(layer_header = document.getElementById('GO_column_layer_header'+(i-1)))
            layer_header.width = getLeft(i-1) - getLeft(i-2) - padding - subtract;
        if(layer_header = document.getElementById('GO_column_layer_header2_'+(i-1)))
            layer_header.width = getLeft(i-1) - getLeft(i-2) - padding - subtract;
	}

	if(layer = document.getElementById('GridScaley_layer'))
	{
		var bottom,top = getTop(1)+1;
		var left = getLeft(1);
		layer.style.left = left;
		layer.style.top = top;
		document.getElementById('GridScaley_table').left = left;
		document.getElementById('GridScaley_table').top = top;

		for(i=1;row = document.getElementById('GridScaley_row'+i);i++)
		{
			bottom = getTop(i);
			maxHeight = row.cells[1].offsetHeight;
			for(j=1;j<row.cells.length;j++)
			{
				if(maxHeight<row.cells[j].offsetHeight)
					maxHeight = row.cells[j].offsetHeight;
			}
			//document.getElementById('LO_row'+(i-1)).height = bottom-top-2;
			document.getElementById('GridScaley_floatingrow'+i).height = maxHeight;
			top = bottom;
		}
                for(i=1;row = document.getElementById('ltr1_'+i);i++)
                {
                    jQuery('#ltr1_'+i).css('width', jQuery('#thead'+i).css('width'));
                    jQuery('#GO_column_layer_header1').css('width', jQuery('#thead1').css('width'));
                }
            //ltr
		document.getElementById('GridScaley_table').width = getLeft(2)-getLeft(1);
	}
    if(layer = document.getElementById('GridScaley_layer_header'))
	{
        //ShowProps(document.getElementById('GridOutput_header_row').style,"style");
    		var bounds = getBounds(document.getElementById('GridOutput_header_row'));
		var bottom,top = bounds.top-1;
		var left = getLeft(1)
		layer.style.left = left;
		layer.style.top = top;
        //layer.firstChild.height = bounds.height; //
	        document.getElementById('GridScaley_layer_header_table').style.height = bounds.height;
		document.getElementById('GridScaley_table').left = left;
		document.getElementById('GridScaley_table').top = top;

/*		for(i=1;row = document.getElementById('GridScaley_row'+i);i++)
		{
			bottom = getTop(i);
			maxHeight = row.cells[1].offsetHeight;
			for(j=1;j<row.cells.length;j++)
			{
				if(maxHeight<row.cells[j].offsetHeight)
					maxHeight = row.cells[j].offsetHeight;
			}
			//document.getElementById('LO_row'+(i-1)).height = bottom-top-2;
			document.getElementById('GridScaley_floatingrow'+i).height = maxHeight;
			top = bottom;
		}
*/
		var width_y = jQuery('#GridScaley_layer_header').css('width');
		jQuery('#GridScaley_table').css('width', width_y);
		jQuery('#GridScaley_layer_header_table').css('width', width_y);
		jQuery('#GridScaley_layer_header2_table').css('width', width_y);


		//document.getElementById('GridScaley_table').width = document.getElementById('GridScaley_layer_header_table').width = document.getElementById('GridScaley_layer_header2_table').width = getLeft(2)-getLeft(1);
	}

	if(layer = document.getElementById('GridScaley_layer_header2'))
	{
    		var bounds = getBounds(document.getElementById('GridScalex_table'));
	        var total_width,right,left = getLeft(1)-1,padding=4;
		left -= padding;
		layer.style.left = left;
		layer.style.top = 0;
		document.getElementById('GridScaley_layer_header2_table').left = left;
    		document.getElementById('GridScaley_layer_header2_table').style.height = bounds.height;
	}
    
	window.onresize = doOnresize;
    window.setInterval('doOnscroll()',50);
    window.onscroll = doOnscroll;

  if(typeof positionMenus == "function")
        positionMenus();
	putFocus();
        startPolling();
//        start_slide_menu();

}
/*my*/

function start_slide_menu()
{
    slide_menu();
    //setInterval("slide_menu()",250);
}

/*test*/
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function slide_menu()
{
    if (navigator.appName == "Microsoft Internet Explorer")
        {var position = document.body.scrollLeft;}
    else
        {var position = window.pageXOffset;}
    ScreenWidth = document.body.clientWidth;

    var menu_line = document.getElementById('menu_container');
    menu_line.style.width = ScreenWidth ;
    var width_button = 20;

    var btn_left = document.getElementById('l_btn');

    if(findPosX(btn_left)<200)
        {
            btn_left.style.display = "none";
        }
    else
        btn_left.style.display = "block";
    var btn_right = document.getElementById("r_btn");
//    alert(findPosX(btn_right)+"<=>"+(ScreenWidth-16));
    if(findPosX(btn_right)<(ScreenWidth-16))
        btn_right.style.display = "none";
    else
    {

        btn_right.style.postition = "absolute";
//        alert(findPosY(menu_line));
        btn_right.style.top = findPosY(menu_line)+16;
        menu_line.style.width = ScreenWidth -16 ;
        btn_right.style.left = ScreenWidth-16;
        btn_right.style.display = "block";
    }
    
}

function startPolling(){
    setInterval("poll()",100);
}
function scroll_menu_to_right()
{
    
}
function scroll_menu_to_left()
{
    
    
    alert(findPosY(btn_left));
}


function scrollbarWidth() {
    var div = jQuery('<div style="width:50px; height:50px; overflow:hidden; position:absolute; top:-200px; left:-200px;"><div style="height:100px;"></div></div>').appendTo('body');
    var w1 = jQuery('div', div).innerWidth();
    div.css('overflow-y', 'scroll');
    var w2 = jQuery('div', div).innerWidth();
    jQuery(div).remove();
    return (w1 - w2);
}

function poll(){
    if (navigator.appName == "Microsoft Internet Explorer")
        {var position = document.body.scrollLeft;}
    else
        {var position = window.pageXOffset;}
    ScreenWidth = document.body.clientWidth;
    var newWidth = (ScreenWidth+position);
    var w = jQuery('#GridOutput_header_row_table').innerWidth()
    var p = jQuery('#GridOutput_header_row_table');
    var offset = p.offset();
    var l = (offset!==null)?(offset.left!==null)?offset.left:'':'';
    //Logme(newWidth);
    jQuery('#GridScalex_layer').css('width',w+"px");
    jQuery('#GridScalex_table').css('width',w+"px");
    jQuery('#GridScalex_layer').css('left',l);
    jQuery('#GridScalex_table').css('left',l);
    jQuery('#head_table').css('width',newWidth+"px");
    jQuery('#head_table2').css('width',newWidth+"px");
    jQuery('.right_both').css('width',newWidth+"px");
    jQuery('.right_both2').css('width',newWidth-10+"px");
    
//    document.getElementById('head_table').style.width = newWidth;
//    document.getElementById('head_table2').style.width = newWidth;

    return true;
    }
/*my  end*/
function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

rb_changed = false;
rb_submit = false;
function run_rb_submit()
{
	if(rb_changed==false)
	{
		rb_changed = true;
    		if(document.getElementById('top_submit'))
	        {
	                document.getElementById('top_submit').style.backgroundColor='red';
		        document.getElementById('top_submit').style.color='white';
	                document.getElementById('top_submit').style.fontWeight='bold';
	        }
	        if(document.getElementById('bottom_submit'))
	        {
	                document.getElementById('bottom_submit').style.backgroundColor='red';
	                document.getElementById('bottom_submit').style.color='white';
	                document.getElementById('bottom_submit').style.fontWeight='bold';
	        }
	}
}


function doOnresize()
{
	doOnload();
	doOnscroll();
}

var unlocking = false;
function dOr()
{
	if(unlocking==false)
		doOnresize();
}

var old_modcat = false;
var opened = false;
function doOnBodyClick()
{
	if(old_modcat!=false && opened==false && currentMod != old_modcat)
	{
		document.getElementById('menu_hidden'+old_modcat).style.visibility = "hidden";
		document.getElementById('button_'+old_modcat).style.backgroundPosition = 'top';
		old_modcat = false;
		openedMenu = false;
	}

	if(old_modcat != false && opened==false && currentMod!=false && openedMenu == true && currentMod == old_modcat)
	{
		document.getElementById('menu_hidden'+old_modcat).style.visibility = "hidden";
		openedMenu = false;
		old_modcat = false;
	}

	opened = false;
}

function doOnscroll()
{
	var layer;
	// ltable need to fix bug in IE 8x
        var xtable;	
	if(layer = document.getElementById('GridScalex_layer'))
	{
		xtable = document.getElementById('GridScalex_table');
		var pY = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset);
		if(pY > getListTop())
		{
                        layer.style.visibility = "visible";
                        xtable.style.visibility = "visible";
                }
                else
                {
                        layer.style.visibility = "hidden";
                        xtable.style.visibility = "hidden";
                }
		if(pY)
			layer.style.top = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset);
	}

	if(layer = document.getElementById('GridScaley_layer_header2'))
	{
        var pX = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
		var pY = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset);
		if(pY > getListTop() && pX > 25)
			layer.style.visibility = "visible";
		else
			layer.style.visibility = "hidden";
		if(pY)
			layer.style.top = (window.document.body.scrollTop ? window.document.body.scrollTop : window.pageYOffset);
        if(pX)
            layer.style.left = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
	}

	if(layer = document.getElementById('GridScaley_layer'))
	{
		var pX = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
		if(pX > 25)
			layer.style.visibility = "visible";
		else
			layer.style.visibility = "hidden";
		if(pX)
			layer.style.left = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
	}

    if(layer = document.getElementById('GridScaley_layer_header'))
	{
		var pX = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
		if(pX > 25)
			layer.style.visibility = "visible";
		else
			layer.style.visibility = "hidden";
		if(pX)
			layer.style.left = (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.pageXOffset);
	}
}

function getLeft(column_number)
{
	var x = 0;
	if(document.layers)
		x = document.layers['GridScalex'+column_number].pageX;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all['GridScalex'+column_number] : document.getElementById('GridScalex'+column_number);
		while(cell)
		{
			x += cell.offsetLeft;
			cell = cell.offsetParent;
		}
	}
	return x;
}

function getTop(row_number)
{
	var y = 0;
	if(document.layers)
		y = document.layers['GridScaley'+row_number].pageY;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all['GridScaley'+row_number] : document.getElementById('GridScaley'+row_number);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y-6;
}

function getListTop()
{
	var y = 0;
	if(document.layers)
		y = document.layers['GridScalex1'].pageY;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all['GridScalex1'] : document.getElementById('GridScalex1');
		while(cell)
		{
		  y += cell.offsetTop;
		  cell = cell.offsetParent;
		}
	}
	return y;
}

function getListBottom(column_number)
{
	var y = 0;
	if(document.layers)
		y = document.layers['GridScalex'+column_number].pageY;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all['GridScalex'+column_number] : document.getElementById('GridScalex'+column_number);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y-6;
}

var runPutFocus = true;
function putFocus()
{
	var i,o,y=0;
	if(document.forms.length > 0 && runPutFocus==true)
	{
		// disable second call of the function
		runPutFocus = false;
		if(document.getElementById('red_button_form'))
		{
//			with(document.getElementById('red_button_form'))
//			{
//				onchange = function() {run_rb_submit();}
//			}
//			if(browser=='IE')
			{
				with(document.getElementById('red_button_form'))
				{
					for(i=0;i<length;i++)
					{
						var element = elements[i];
						if(!element.attributes['ignorered'] || element.attributes['ignorered'].value != 'ignorered')
						{

							if(element.type == "checkbox" || element.type == "radio")
							{
							element.prioronclick = element.onclick;
							element.onclick = function()
							{
								var ret = true;
								if(this.prioronclick)
									ret = this.prioronclick();

								run_rb_submit();
								return ret;
							}
							element.prioronkeypress = element.onkeypress;
							element.onkeypress = function()
							{
								var ret = true;
								if(this.prioronkeypress)
								{
									ret = this.prioronkeypress();
								}
								run_rb_submit();
								return ret;
							}
							}
							else
							{
							element.prioronchange = element.onchange;
							element.onchange = function()
							{
								var ret = true;
								if(this.prioronchange)
								{
									ret = this.prioronchange();
								}
								run_rb_submit();
								return ret;
							}
							}
						}
					}
				}
			}
		}

		for(o=0;o<document.forms.length;o++)
		{
			for(i=0;i<document.forms[o].elements.length;i++)
			{
				if(document.forms[o].elements[i].type=='text' && document.forms[o].elements[i].name!='GridSearchIn')
				{
					try
					{
						var cell = document.forms[o].elements[i];
						while(cell)
						{
							y += cell.offsetTop;
							cell = cell.offsetParent;
						}

						if(y<getWindowHeight())
							document.forms[o].elements[i].focus();
						return;
					}
					catch(err)
					{}
				}
			}
		}
	}
}

function getWindowHeight()
{
	if(window.innerHeight)
		return window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		 return document.documentElement.clientHeight;
	else if(document.body)
		 return document.body.clientHeight;
}

function getWindowWidth()
{
	if(window.innerWidth)
		return window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		 return document.documentElement.clientWidth;
	else if(document.body)
		return document.body.clientWidth;
}

function addHTML(html,id,replace)
{
	if(locked!=false)
	{
		if(replace==true)
			document.getElementById(id).innerHTML = html;
		else
			document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + html;
	}
}

function changeHTML(show,hide)
{
	for(key in show)
		document.getElementById(key).innerHTML = document.getElementById(show[key]).innerHTML;
	for(i=0;i<hide.length;i++)
		document.getElementById(hide[i]).innerHTML = '';
}

function checkAll(form,value,name_like)
{
	if(value==true)
		checked = true;
	else
		checked = false;

	for(i=0;i<form.elements.length;i++)
	{
		if(form.elements[i].type=='checkbox' && form.elements[i].name!='controller' && form.elements[i].name.substr(0,name_like.length)==name_like)
			form.elements[i].checked = checked;
	}
}

function openMenu(modcat)
{
	document.getElementById('menu_'+modcat).display = 'block';
	if(old_modcat!=false)
		document.getElementById('menu_'+old_modcat).display = 'none';
	//document.getElementById('modcat_input').value=modcat;
	if(old_modcat==modcat)
		old_modcat = false;
	else
		old_modcat = modcat;
}

function getXPos(id)
{
	var x = 0;
	if(document.layers)
		x = document.layers[id].pageX;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all[id] : document.getElementById(id);
		while(cell)
		{
			x += cell.offsetLeft;
			cell = cell.offsetParent;
		}
	}
	return x;
}

function getYPos(id)
{
	var y = 0;
	if(document.layers)
		y = document.layers[id].pageY;
	else if(document.all || document.getElementById)
	{
		var cell = document.all ? document.all[id] : document.getElementById(id);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y;
}


function replaceAll(haystack,needle,replacement)
{
	haystack = haystack.replace(needle,replacement);
	if(haystack.match(needle))
		haystack = replaceAll(haystack,needle,replacement);
	return haystack;
}

function switchMenu(id)
{
	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display = 'block';
		if(arrow = document.getElementById(id+'_arrow'))
			arrow.src = 'images/arrow_down.gif';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
		if(arrow = document.getElementById(id+'_arrow'))
			arrow.src = 'images/arrow_right.gif';
	}
        jQuery('#'+id).trigger('click');
	positionMenus();
}

function setSI(id,value)
{
	if(value)
	{
		for(i=0;i<=document.getElementById(id).options.length;i++)
		{
			if(document.getElementById(id).options[i].value==value)
			{
				document.getElementById(id).options[i].selected=true;
				return true;
			}
		}
	}
}

var single_quote = "'";
var double_quote = '``';

function hl_cb(cb)
{
    if(browser!="IE")
    {
        cb.checked=!cb.checked;
        hilite_checked(cb);
    }
}

function hilite_checked(cb, row)
{
    if(browser!="IE")
    {
        if(!row || row.tagName.toLowerCase()!='tr')
        {
            var i = 0;
            row = cb;
            do
            {
                row = row.parentNode;
                i++;
            } while (row.tagName.toLowerCase() != "tr" && i<5);
        }
        if(cb.checked)
        {
            row.className+=' hilite';
//            checkbox_selected += cb.name;
        }
        else
        {
//            checkbox_selected = checkbox_selected.replace(cb.name,'');
            row.className=row.className.replace(/hilite/g,'');
        }
    }
}

//function restoreCheckbox(cb)
//{
//    alert(checkbox_selected);
//}


function check_clicked(row)
{
    if(browser!="IE")
    {
        var cb=row,i=0;
        do
        {
            cb=cb.firstChild;
            i++;
        }
        while(cb.type!="checkbox" && i<5);
        cb.checked = !cb.checked;
        hilite_checked(cb, row);
    }
}

function CheckAll_hilite(form,value,name_like)
{
    for(i=0;i<form.elements.length;i++)
    {
        if(form.elements[i].type=='checkbox' && form.elements[i].name!='controller' && form.elements[i].name.substr(0,name_like.length)==name_like)
        {
            hilite_checked(form.elements[i]);
        }
    }
}

function enable_input(input, cb)
{
    document.getElementById(input).disabled = cb.checked;
}

function enable_all_inputs(form, name_like, enable)
{
    for(i=0;i<form.elements.length;i++)
    {
        if((form.elements[i].type=='select-one' || form.elements[i].type=='checkbox' || form.elements[i].type=='text' || form.elements[i].type=='radio' ) && form.elements[i].name.substr(0,name_like.length)==name_like)
        {
            form.elements[i].disabled = !enable;
        }
    }
}

function add_benchmark_card_longer_comments(form, name_like, value, replace)
{
     for(i=0;i<form.elements.length;i++)
    {
        if((form.elements[i].type=='textarea') && form.elements[i].name!='controller' && form.elements[i].name.indexOf(name_like)!=-1)//substr(0,name_like.length)==name_like)
        {
            if(replace)
            {
                 form.elements[i].value = value;
            }
            else
            {
                 form.elements[i].value+=value;
            }
        }
    }
}
/*
function Delete_file(Upload_file_field_id,FileID)
{
	if(confirm('Do you want to delete file?'))
	{
		if(document.student)
		{
	 		document.student.action = document.student.action + '&DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id;
	 		document.student.submit();
	  	};
		if(document.user)
		{
			document.user.action = document.user.action + '&DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id;
			document.user.submit();
		};
	}
}
*/

function Delete_file(Upload_file_field_id,FileID,Rand,subfolder,lang)
{

        if(lang!='')
        {
            switch(lang)
            {
                case 'ru':
                    DeleteConfirm = 'Вы хотите удалить этот файл?';
                break;
                case 'en':
                    DeleteConfirm = 'Do you want to delete this file?';
                break;
                default:
                    DeleteConfirm = 'Do you want to delete this file?';
                break;
            }
        }
        if(confirm(DeleteConfirm))
        {
                if(document.student)
                {
	                //jQuery.post(document.student.action + '&DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id);
                        var link = subfolder + 'functions/extra/ManageFiles.fnc.php?DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id + '&table=students';
                        jQuery.post(link, function(data) {jQuery("#note").val(data);});
                        jQuery('#afterUP'+Rand).hide();
                        jQuery('#FileInput'+Rand).html('').hide();
                        jQuery('#buttonUpload'+Rand).show();
                        jQuery('#fileToUpload'+Rand).show();
                        jQuery('#fileToUpload'+Rand).val('');
                        jQuery('#InputButton'+Rand).show();
                        var new_var = "<input type='hidden' id='inputstudents["+Upload_file_field_id+"]' name='students["+Upload_file_field_id+"]' value=''>";
                        jQuery('#afterUP'+Rand).html(new_var).hide();

                        
                        //document.student.action = document.student.action + '&DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id;
                        //document.student.submit();
                };
                if(document.user)
	        {
	                var link = subfolder + 'functions/extra/ManageFiles.fnc.php?DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id + '&table=users';
	                jQuery.post(link, function(data) {jQuery("#note").val(data);});
                        jQuery('#afterUP'+Rand).hide();
		        jQuery('#FileInput'+Rand).html('').hide();
                        jQuery('#buttonUpload'+Rand).show();
                        jQuery('#fileToUpload'+Rand).show();
                        jQuery('#fileToUpload'+Rand).val('');
                        jQuery('#InputButton'+Rand).show();
                        var new_var = "<input type='hidden' id='inputusers["+Upload_file_field_id+"]' name='users["+Upload_file_field_id+"]' value=''>";
                        jQuery('#afterUP'+Rand).html(new_var).hide();
                        //document.user.action = document.user.action + '&DeleteFileOK=1&FileID=' + FileID + '&Upload_file_field_id=' + Upload_file_field_id;
            	        //document.user.submit();
                };
	}
}

function delete_confirm(from, what) {
    var conf = document.getElementById("conf");
    conf.innerHTML = "<input type=\"hidden\" value=\""+from+"\" name=\"what\">\n\
                              <input type=\"hidden\" value=\""+what+"\" name=\"from\">\n\
                              <input type=\"button\" value=\"Yes\" onclick=\"delete_merge('"+from+"','"+what+"'); return false;\">\n\
                              <input type=\"button\" value=\"No\" onclick=\"hide_conf_menu(); return false;\">\n\
                              <div id=\"status\"></div>";
            conf.style.display = "block";

}

function hide_conf_menu()
{
    form = document.getElementById("conf");
    form.style.display = "none";
}
var ShowedForms = new Array();
function DelileForms(ShowedForms)
{
    for (var key in ShowedForms)
    {
        var val = ShowedForms[key];
        jQuery('#FileInput'+key).html('');
    }


}
function FileInputShow(temp,form)
{
    jQuery('#FileInput'+temp).html(form).show();
    jQuery('#InputButton'+temp).hide();
    return null;
}

function ajaxFileUpload(field,rand,subfolder,lang)
{
        if(lang!='')
        {
            switch(lang)
            {
                case 'ru':
                    Download = 'Скачать ';
                    Delete = 'Удалить файл'
                break;
                case 'en':
                    Download = 'Download ';
                    Delete = 'Delete this file';
                break;
                default:
                    Download = 'Download ';
                    Delete = 'Delete this file';
                break;
            }
        }
            if(document.student)
                    link = subfolder + 'functions/extra/ManageFiles.fnc.php?servicefunction=upload_file&field_id='+field+'&path='+subfolder+'&rand='+rand+'&table=students';
            if(document.user)
                    link = subfolder + 'functions/extra/ManageFiles.fnc.php?servicefunction=upload_file&field_id='+field+'&path='+subfolder+'&rand='+rand+'&table=users';
                    jQuery.ajaxFileUpload
                    (
                        {
                            url: link,
                            secureuri:false,
                            fileElementId:'fileToUpload'+rand,
                            dataType: 'json',
                            beforeSend:function()
                            {
                                jQuery("#loading").show();
                            },
                            complete:function()
                            {
                                jQuery("#loading").hide();
                            },
                            success: function (data, status)
                            {
                                if(typeof(data.error) != 'undefined')
                                {
                                    if(data.error != '')
                                    {
                                        jQuery('#upload_status'+rand).val(data.error);
	                            }
                                    else
                                    {
                                        jQuery('#buttonUpload'+rand).hide();
    	                                jQuery('#fileToUpload'+rand).hide();
                                        jQuery('#FileInput'+rand).html('');
                                        jQuery('#afterUP'+rand).show();
				        var links = "<a href=\"JavaScript:Delete_file('"+field+"','"+data.id+"','"+rand+"','"+ subfolder +"','" + lang + "');\">" + Delete + "</a>\n";
                                        links += "<a href='index.php?download="+data.id+"'><img width='15' vspace='0' border='0' class='GridOutput_fieldint' src='images/file_download_button.gif'>&nbsp;" + Download + " " + data.name +" </a>\n";
                                        links += "<input type='hidden' id='inputstudents["+field+"]' name='students["+field+"]' value='"+data.id+"'>\n";

				        jQuery('#afterUP'+rand).html(links);
				        jQuery('#InputButton'+rand).hide();
		                    }
			        }
		    	    },
	                    error: function (data, status, e)
	                    {
	                        jQuery('#upload_status'+field).val("error:"+ data + status + e);
	                    }
	        	}
                    )
    return false;
}
function killfirstquot(element)
{
    if(element.value.substring(0,1)=="'")
        element.value = element.value.substring(1);
}