var prevReport;

function show_first_report()
{
	prevReport = document.getElementById("report1");
	
	if (prevReport != undefined)
        prevReport.style.display = "block";
    
    leftSpace();
}

function showHideReport(id, btnId)
{
	var report = document.getElementById(id);
	var button = document.getElementById(btnId);
	
	if(button.className=="btnMinusGeneral")
	{	
		button.className = "btnPlusGeneral";
		report.style.display = "block";
	}
	else
	{
		button.className = "btnMinusGeneral";
		report.style.display = "none";
    }

    leftSpace();
}

function ChangeOkecOrName(isCodeOrName)
{
    var okecNameDropDownList=document.getElementById("ctl00_ContentPlaceHolder1_OkecNameDropDownList");
    var okecCodeDropDownList=document.getElementById("ctl00_ContentPlaceHolder1_OkecCodeDropDownList");
    var textBox = document.getElementById("ctl00_ContentPlaceHolder1_OkecNameTextBox");
    if (isCodeOrName=="code")        
	{				
		//okecNameDropDownList.value=okecCodeDropDownList.value; fortify fix 
		eval('okecNameDro'+'pDownList.value=okecCodeDrop'+'DownList.value');
	}
               
    else 
    {       
	    //okecCodeDropDownList.value=okecNameDropDownList.value; fortify fix 
	     eval('okecCodeDrop'+'DownList.value=okecNameDrop'+'DownList.value');
	}
	
            //okecCodeDropDownList.value=okecNameDropDownList.value;
    var dropDownListIndex=okecNameDropDownList.selectedIndex;
    textBox.value = okecNameDropDownList.options[dropDownListIndex].text;                 
}
			
				
function showHideReportCM(id, btnId)
{
    var report = document.getElementById(id);
    var button = document.getElementById(btnId);
					
	if(button.className=="btnMinus")
	{	
	    button.className = "btnPlus";
		report.style.display = "block";
	}
	else
	{
		button.className = "btnMinus";
		report.style.display = "none";
    }

	leftSpace();
}

function showHideReportGR(id, btnId)
{
	var report = document.getElementById(id);
	var button = document.getElementById(btnId);
	
	if(button.className=="btnMinusGR")
	{
	    button.className = "btnPlusGR";
	    report.style.display = "none";
	}
	else
	{
	    button.className = "btnMinusGR";
	    report.style.display = "block";
	}

    leftSpace();	
}

function showHideReportGR_sk(id, btnId)
{
	var report = document.getElementById(id);
	var button = document.getElementById(btnId);
	
	if(button.className=="btnMinusGR_sk")
	{
	    button.className = "btnPlusGR_sk";
	    report.style.display = "none";
	}
	else
	{
	    button.className = "btnMinusGR_sk";
	    report.style.display = "block";
    }

    leftSpace();	
}

function showHideAll(reportCount, perform)
{
	var i = 1;
	var report;
	var btn;
	
	for (i = 1; i <= reportCount; i++)
	{
		var id = "report" + i;
		report = document.getElementById(id);
		
		var btnId = "button" + i;						
		btn = document.getElementById(btnId);						
		
		if(perform=="show")
		{	
			report.style.display = "block";								
			btn.className = "btnPlusGeneral";						
		}
		else
		{
			report.style.display = "none";							
			btn.className = "btnMinusGeneral";
		}
	}
	leftSpace();
}

function onlyNumbers(e)
{
	var keynum;
	var keychar;
	var numcheck;
						
	if(window.event) // IE
	{
	    keynum = e.keyCode;
	}
	
	else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which;
	}
	
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return numcheck.test(keychar);
}

function onlyNumbersWithEnter(e)
{
	var keynum;
	var keychar;
	var numcheck;
						
	if(window.event) // IE
	{
	    keynum = e.keyCode;
	}
	
	else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which;
	}
	
	if (keynum == 13)
	{
	    checkTextInput();
	    return false;
	}
	else
	{
		keychar = String.fromCharCode(keynum);
	    numcheck = /\d/;
	    return numcheck.test(keychar);
	}
}
						
function checkTextInput()
{
    var textBox = document.getElementById('textInput');
	var max = document.getElementById('maxPage');
	var currentPage = document.getElementById('pageNumber');
	var oldPageNumber = "pagenumber=" + currentPage.value;
	var urlString = removeCheckedQuery(document.location.href);
	
	//var myregexp = new RegExp("/d")
	//myString.replace(myregexp, "replacement").urlString
	var checked = resolveChecked();
	if(checked != "") urlString += checked;
								
	if (Number(textBox.value) > Number(max.value))
	{								    
	    var page = max.value - 1;
	    var newPageNumber = "pagenumber=" + page;
		var newUrl = urlString.replace(oldPageNumber, newPageNumber);
		eval('document.location = newUrl');   //fortify fix 
	}
	
	else if (textBox.value == "" || Number(textBox.value) == 0)
	{									    
	    location.reload(true);
	}
	
	else
	{	
	    var page = textBox.value-1;
	    var newPageNumber = "pagenumber=" + page;
		var newUrl = urlString.replace(oldPageNumber, newPageNumber);
		eval('document.location = newUrl');  //fortify fix 
	}		
	return false;					
}


function CheckAddress(query)
{
    var returnQuery = "";
    var params = query.split("&");
    for (i=1; i<params.length;i++) 
    {
        returnQuery += params[i];
    } 
    
    var patt1=new RegExp(".*");
	var tmpstr = patt1.exec(returnQuery);
    return tmpstr;
}


function addInputToTheLinkInCompanyList(pages)
{
   var textBox = document.getElementById('textInputCompanyList');
   var urlString = document.location.href;
   var params = urlString.split("?");
   var param = CheckAddress(params[0]);
   if(Number(textBox.value) < Number(pages) && Number(textBox.value) != 0)
        document.location = param +"?page=" + Number(textBox.value);
   else if (textBox.value == "" || Number(textBox.value) == 0)										    
	       location.reload(true);
   else
      document.location = param +"?page="+pages;
}

function  checkedHidenCheckBox(checkBoxId)
{
    var checkBox = document.getElementById(checkBoxId);    
    checkBox.checked = !checkBox.checked;
}

function removeCheckedQuery(query)
{
        var returnQuery = "";
    var params = query.split("&");
    for (i=0; i<params.length;i++) 
    {
        if(params[i].substring(0, 8) != "checked=")
            returnQuery += params[i] + "&";
    } 
    
    var patt1=new RegExp(".*");
	var tmpstr = patt1.exec(returnQuery);
    return tmpstr;
}

function addCheckedToHref(e)
{
	if (!e) var e = window.event;

	var sender;
		
	if (e.target)
		sender = e.target;
	else if (e.srcElement)
	    sender = e.srcElement;

	if (sender.nodeType == 3)
	    sender = sender.parentNode;
		
	var checked = resolveChecked();
	if(checked!="")
	{
		var hrefAttr = removeCheckedQuery(sender.getAttribute("href")) + checked;
		sender.setAttribute("href", hrefAttr);						
	}
}


function resolveChecked()
{
    var queryParam = "";
	inputs = document.getElementsByTagName("input");
    	
	for(n=0; n < inputs.length; n++)
		if(inputs[n].getAttribute("type") == "checkbox")
		{
		    var attr = inputs[n].checked;
		        
			if(attr == true || attr == "true")
			{
				if(queryParam!="") queryParam += "_";
				queryParam += "1" + inputs[n].getAttribute("id");
			}
			if(attr == null || attr == false || attr == "false")
			{
				if(queryParam!="") queryParam += "_";
				queryParam += "0" + inputs[n].getAttribute("id");
			}
		}
			
   	if(queryParam!="") queryParam = "checked=" + queryParam;
    			
	return queryParam;
}


function leftSpace() {
    if (document.getElementById("simplifiedReportRow") == null)
        {
            $('#body_left_box_space').css('padding-bottom', "0px");

            if ($('#body_right').height() - $('#body_left').height() >= 0) {
            $('#body_left_box_space').css('padding-bottom', $('#body_right').height() - $('#body_left').height() + "px");
            $('#btnLeft').css('height', $('#body_right').height());
        }
    }
}

/* start Relation Chards*/


function MaximizeWidth(id) {
  var img = document.getElementById(id);
  if (img != null) {
    var w = window.innerWidth;
    if (!w) w = document.body.scrollWidth;
    if (!w) w = document.width;
    w -= 20;
    if (w < 100) w = 100;
    goSize(w, img.height, id);
    img.width = w;
  }
}

function GetWidowHeight()
{
//get window size
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  
  return myHeight;
}

function GetWidowWidth()
{
//get window size
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
  return myWidth;
}

function ResizeAll()
{
//get window size
  var myWidth = 0, myHeight = 0;
  
    myWidth = GetWidowWidth();
    myHeight = GetWidowHeight();
//window.alert( 'Width = ' + myWidth );
//window.alert( 'Height = ' + myHeight );
  
SetWidth("tableTitle", myWidth - 20);
SetWidth("tableWarning", myWidth - 20);
SetWidth("tableChart", myWidth - 29);
SetWidth("tableInfo", myWidth - 20);

SetHeight("tableChart", myHeight - 70);
}

function SetWidth(id, width) {
var element = document.getElementById(id);
if (element != null) element.width = width;
}

function FitGraph(reload)
{
    var elviewMode = document.getElementById('viewMode');
    
    if(elviewMode.value == '0')
    {
        document.getElementById('biViewWidth').value = GetWidowWidth()-49;
        document.getElementById('biViewHeight').value = GetWidowHeight()-100;
        
        if(reload)
            __doPostBack('','');
    }
}

function SetViewMode(viewMode)
{
    var elviewMode = document.getElementById('ctl00_ContentPlaceHolder1_viewMode');
    
    if(viewMode != elviewMode.value)
    {
        elviewMode.value = viewMode;
        __doPostBack('','');
    }
}

function SetWidth(id, width) {
var element = document.getElementById(id);
if (element != null) element.width = width;
}

function SetHeight(id, height) {
var element = document.getElementById(id);
if (element != null) element.height = height;
}

function FitOnLoad()
{
    window.alert('FitOnLoad');
    var elviewMode = document.getElementById('ctl00_ContentPlaceHolder1_viewMode');
    
    if(elviewMode.value == '0')
    {
        goZoom('fit','BIView1');
    }
}

function ExportToPDF()
{
    document.forms['ToPdf'].WindowWidth.value = GetWidowWidth();
    document.forms['ToPdf'].ImgSource.value = document.forms['form1'].BIView1.src;
    document.forms['ToPdf'].SORGENTE.value = '<HTML><BODY>' + document.forms['form1'].innerHTML + '</BODY></HTML>';
    window.open('about:blank','FINESTRAPDF','top=20,left=20,width=' + (screen.width / 2) + ',height=' + (screen.height - 150) + ', resizable' );
    document.forms['ToPdf'].target='FINESTRAPDF';
    document.forms['ToPdf'].submit();    
    return false;
}

function GetSRC()
{
    var img = document.getElementById('ctl00$ContentPlaceHolder1$BIView1');
    var link = document.getElementById('WordExport');
    var imgCompanies = document.getElementById('ctl00_ContentPlaceHolder1_imgCompanies');
    var imgPersons = document.getElementById('ctl00_ContentPlaceHolder1_imgPersons');
    var qStringC = '';
    var qStringP = '';
    
    if (imgCompanies.src.indexOf("expand_blue.jpg") != -1)
        qStringC = '&checked=0imgCompanies';
    else
        qStringC = '&checked=1imgCompanies';
        
    if (imgPersons.src.indexOf("expand_blue.jpg") != -1)
        qStringP = '_0imgPersons';
    else
        qStringP = '_1imgPersons';
        
    link.href = '/WordReport.aspx?type=RC'+qStringC+qStringP+'&img='+img.src;
}

function PrintPage()
{
    print();
}

function GetPdfSRC()
{
    var img = document.getElementById('ctl00$ContentPlaceHolder1$BIView1');
    var link = document.getElementById('PdfExport');
    var imgCompanies = document.getElementById('ctl00_ContentPlaceHolder1_imgCompanies');
    var imgPersons = document.getElementById('ctl00_ContentPlaceHolder1_imgPersons');
    var qStringC = '';
    var qStringP = '';
    
    if (imgCompanies.src.indexOf("expand_blue.jpg") != -1)
        qStringC = '&checked=0imgCompanies';
    else
        qStringC = '&checked=1imgCompanies';
        
    if (imgPersons.src.indexOf("expand_blue.jpg") != -1)
        qStringP = '_0imgPersons';
    else
        qStringP = '_1imgPersons';
    
    link.href = '/PdfReport.aspx?type=RC'+qStringC+qStringP+'&img='+img.src;
    //alert(img.src);
}

/* end Relation Chards*/
/* start general report phonebook link functions */
function zoznam(company,city)
{
    var str2=company.replace(/ /g,"+");
    var str3=escape(str2);
    var str5=city.replace(/ /g,"+");
    var str6=escape(str5);
    document.getElementById("zoznam").href="http://telefonny.zoznam.sk/hladaj.fcgi?co=telzoznam&s=" + str3 + "&mesto=" + str6 + "&ulica=&amp;psc=&amp;uto=&amp;net_fixed=1&amp;net_mobile=1&amp;net_alt=1";
    };
/* end general report phonebook link functions */


    
function showHideSection(sectionId, buttonId, openClass, closedClass) {
    var report = document.getElementById(sectionId);
    var button = document.getElementById(buttonId);

    if (button.className == closedClass) {
        button.className = openClass;
        report.style.display = "block";
    }
    else {
        button.className = closedClass;
        report.style.display = "none";
    }
}

function showHideCadastreReport(id, btnId)
{
    showHideSection(id, btnId, "cadastreBtnPlus", "cadastreBtnMinus");
    //leftSpace();
}

function showHideOwnershipDocSection(tableId, buttonId) {
    showHideSection(tableId, buttonId, "ownershipBtnPlus", "ownershipBtnMinus");
    leftSpace();
}

function showHideOwnershipDocMajorSection(tableId, buttonId) {
    showHideSection(tableId, buttonId, "ownershipMajorBtnPlus", "ownershipMajorBtnMinus");
    leftSpace();
}

function showHideReportPP(id, btnId, checkBoxId)
{
	var report = document.getElementById(id);
	var button = document.getElementById(btnId);
	var checkBox = document.getElementById(checkBoxId);
	
	if(button.className=="btnMinusPP")
	{	
		button.className = "btnPlusPP";
		report.style.display = "block";
		checkBox.checked = true;
	}
	else
	{
		button.className = "btnMinusPP";
		report.style.display = "none";
		checkBox.checked = false;
	}

    leftSpace();
}

function submitOnEnterCadastre(e)
{	   
	var keynum;
					
	if(window.event) // IE
	    keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
	    keynum = e.which;

	if (keynum == 13)
	{
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ContentPlaceHolder1$SearchButton', '', true, '', '', false, true));
    }
}

function hideOrShowComponentInCadastre()
{
    var textBoxIco=document.getElementById('ctl00_ContentPlaceHolder1_IcoTextBox');
    var textBoxBirthDate=document.getElementById('ctl00_ContentPlaceHolder1_BirthDateTextBox');
    var radioButtonList=document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonList1_0');
    var image=document.getElementById('ctl00_ContentPlaceHolder1_DateFromImageButton');    
    if (radioButtonList.checked)
        {
            textBoxIco.disabled=false;
            textBoxBirthDate.disabled=true;
            image.disabled=true;            
        }
    else
        {
            textBoxIco.disabled=true;
            textBoxBirthDate.disabled=false;
            image.disabled=false;   
         }
}


function resetComponentInCadastre()
{
    document.getElementById('ctl00_ContentPlaceHolder1_IcoTextBox').disabled=false;
    document.getElementById('ctl00_ContentPlaceHolder1_BirthDateTextBox').disabled=true;
    document.getElementById('ctl00_ContentPlaceHolder1_DateFromImageButton').disabled=true;
}


