﻿var OldMenu, OldParent;
var OldMenu1, OldParent1;
var OldMenu2, OldParent2;
var OldMenu3, OldParent3;
 
var OldCard, OldParentCard;
var OldCard2, OldParentCard2;
 
function DisplayOrNoneCards(element, parentelement, n)
{
	if(!n && OldCard != null)
	{
		OldCard.style.display="none";
		OldParentCard.style.display="block";
	}
	
	if(n==2 && OldCard2 != null)
	{
		OldCard2.style.display="none";
		OldParentCard2.style.display="block";
	}	
	
	var DivElement = document.getElementById(element);
	var ParentElement = document.getElementById(parentelement);	
	DivElement.style.display = "block";
	ParentElement.style.display = "none";
		
	if(!n)	
	{
		OldCard = DivElement;
		OldParentCard = ParentElement;
	}
	
	if(n == 2)
	{
		OldCard2 = DivElement;
		OldParentCard2 = ParentElement;
	}

	
	return false;
} 
 
var n;
function BrendGetImage (CurrentN, url, div)
{
	if( CurrentN!= n )
	{
		n = CurrentN;
		document.getElementById(div).style.display = 'block';
		
		LoadPage(url, div);
	}
	
} 
 
function ChangeImg( img, newImg) 
{
	img.style.background = 'url( ' + newImg + ')';
}
 
function HideBrendGetImage(div)  
{
//	$get(div).style.display = 'none';
//	n = 0;
}
 
function SetChecked(Div, AllChecked, ParentDiv)
{
	var Frm = document.getElementById( Div );
	var Elements = Frm.elements;

	var Input = document.getElementById( 'i' + AllChecked );
	var Status = !Input.checked
	
	var Element;

	for( var i=0;i<Elements.length;i++)
	{
		Element = Frm[i];
		//alert( Element.id + '||' +Element.parentNode.parentNode.id + '||' + ParentDiv );
		if(Element.type == 'checkbox' && Element.parentNode.parentNode.id == ParentDiv)
		{
			var ElementId = Element.id;
			ElementId = ElementId.substr(1);
			checkButton( ElementId, 'i'+ElementId, 1, Status);
		}
	}
}
 
function AddLanguageItem (TopDiv, InpetCount)
{
	var InpetCount2 = document.getElementById( InpetCount );
	var TopDiv2 = document.getElementById( TopDiv + InpetCount2.value );
	
	InpetCount2.value = Number( InpetCount2.value ) + 1;
	
	var newForm = "<div class=\"floatleft\">" +
            "<input type=\"text\" onblur=\"formTxtBlur(this,' Язык')\" onfocus=\"formTxtFocus(this,' Язык')\" value=\" Язык\" size=\"200\" id=\"input_ptn_a1\" class=\"sminp300 inpborder\" name=\"a1_"+InpetCount2.value+"\"/>" +
            "<input type=\"text\" onblur=\"formTxtBlur(this,' 5-1')\" onfocus=\"formTxtFocus(this,' 5-1')\" value=\" 5-1\" size=\"2\" id=\"input_ptn_a2\" class=\"sminp30 inpborder\" name=\"a2_"+InpetCount2.value+"\"/>"+
            "</div>"+
			"<div class=\"csp_p\">&nbsp;</div>"+
			"<div id=\"addFormlanguage" + InpetCount2.value + "\"></div>";
	
	TopDiv2.innerHTML = newForm;
	
	
	return false;
}
 
function DisplayOrNone(element, parentelement, n)
{
	if(!n && OldMenu != null)
	{
		OldMenu.style.display="none";
		OldParent.className = "dwnldnocheck";
	}
	
	if(n == 1 && OldMenu1 != null)
	{
		OldMenu1.style.display="none";
		OldParent1.className = "dwnldnocheck";
	}
	
	if(n == 2 && OldMenu2 != null)
	{
		OldMenu2.style.display="none";
		OldParent2.className = "dwnldnocheck";
	}		

	if(n == 3 && OldMenu2 != null)
	{
		OldMenu3.style.display="none";
		OldParent3.className = "dwnldnocheck";
	}	
	
	var DivElement = document.getElementById(element);
	var ParentElement = document.getElementById(parentelement);	
	DivElement.style.display = "block";
	ParentElement.className = "dwnldcheck";
		
	if(!n)
	{
		OldMenu = DivElement;
		OldParent = ParentElement;
	}
	
	if(n == 1)
	{
		OldMenu1 = DivElement;
		OldParent1 = ParentElement;
	}
	
	if(n == 2)
	{
		OldMenu2 = DivElement;
		OldParent2 = ParentElement;
	}	
	
	if(n == 3)
	{
		OldMenu3 = DivElement;
		OldParent3 = ParentElement;
	}			
	
	
	return false;
}

function trim(s) {
	return rtrim(ltrim(s));
} // end function

function ltrim(s) {
	return s.replace(/^\s+/, ''); 
} // end function

function rtrim(s) {
	return s.replace(/\s+$/, ''); 
} // end function

function makeDate( input_month, input_day, input_year) {
    var month = parseInt(input_month.options[input_month.selectedIndex].value);
    var day = parseInt(input_day.options[input_day.selectedIndex].value);
    var year = parseInt(input_year.options[input_year.selectedIndex].value);
    switch (month) {
        case 4: case 6: case 9: case 11:
            if (day == 31) { day = 30; input_day.selectedIndex = 29+1; }
            break;
        case 2:
            if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) {
                if (day > 29) { day = 29; input_day.selectedIndex = 28+1; }
            }
            else {
                if (day > 28) { day = 28; input_day.selectedIndex = 27+1; }
            }
            break;
    }
    if ((month==0)||(day==0)||(year==0)) {
        month=0;
        day=0;
        year=0;
    }
    if (month < 10) {month = '0' + month; }
    if (day < 10) {day = '0' + day; }
    var nn = year + '-' + month + '-' + day;
    if (nn=='0-00-00') {nn='0';}
    return nn;
}

function ChangeQA(id){
	if (id == 'FullQA'){
		document.getElementById('FullQA').style.display = 'none';
		document.getElementById('AnnouncementQA').style.display = 'block';
	} else if (id == 'AnnouncementQA'){
		document.getElementById('FullQA').style.display = 'block';
		document.getElementById('AnnouncementQA').style.display = 'none';
	}
	return false;
}

function SwithTagParam()
{
	this.hideBrief = false;
	this.briefId = "";
	this.detailedId = "";
	this.activeClass = "";
	this.inactiveClass = "";
}

function $get(id)
{
	return document.getElementById(id);
}

function SwitchTag(briefId, detailedId, prm)
{
	if (briefId == prm.briefId) return;

	$get(detailedId).style.display = "block";
	
	if (prm.hideBrief)
	{
		$get(briefId).style.display = "none";
	}
	else
	{
		$get(briefId).className = prm.activeClass;
	}

	var oldBrief = $get(prm.briefId);
	oldBrief.className = prm.inactiveClass;
	oldBrief.style.display = "block";
	
	$get(prm.detailedId).style.display = "none";

	
	prm.briefId = briefId;
	prm.detailedId = detailedId;
}

function openRecForm(id)
{
	var form = "recpismoform";
	var url = "ajax/guideitenes.aspx?id=" + id;
	LoadPage(url, form);
	openForm(form);
	$get(form).style.visibility = "visible";
}
