﻿function PostBackOnEnter(event, button) {
    if (button) {        
        if (!event) var event = window.event;        
        if (event.keyCode && event.keyCode == 13) {           
            __doPostBack(button, '');
        }
    }    
}
function JSNavigate(elm) {
    //alert(elm);
    if (elm && elm.tagName == "A" && elm.href) {
        //alert('redirecting to: ' + elm.href);
        if (parent && parent.frames.length > 0) {
            parent.window.location = elm.href;
        }
        else {
            window.location = elm.href;
        }
        return false;
    }
}
//JS Tabs ****************
function showTab(contId, elmId, tab) {
    if (!contId || !elmId || !tab)
        return;
    var cont = document.getElementById(contId);
    if (cont) {
        var elms = cont.getElementsByTagName("div");
        if (elms) {
            for (var i = 0; i < elms.length; i++) {
                if (elms[i].id == elmId) {
                    elms[i].className = elms[i].className.replace('hiddenTab', 'visibleTab');
                }
                else {
                    if (elms[i].className.indexOf('visibleTab') > -1) {
                        elms[i].className = elms[i].className.replace('visibleTab', 'hiddenTab');
                    }
                }
            }
        }
    }
    //switch tab
    var li = tab.parentNode;
    while (li && li.tagName != "LI") {
        li = li.parentNode;
    }
    if (li) {
        li.className = "current " + li.className;
    }
    var ul = li.parentNode;
    if (ul) {
        var lis = ul.getElementsByTagName("LI");
        if (lis) {
            for (var j = 0; j < lis.length; j++) {
                if (lis[j] != li) {
                    lis[j].className = lis[j].className.replace("current ", "").replace(" current", "").replace("current", "");
                }
            }
        }       
    }
}
//JS Tabs END****************
function f_getXY(el){
    if (el.parentNode === null || el.offsetParent === null ||
            el.style.display == 'none') {
        return false;
    }
    var ua = navigator.userAgent.toLowerCase();
    var isSafari = (ua.indexOf('safari') > -1);
    
    var parentNode = null;
    var pos = [];
    var box;
    

    if (el.getBoundingClientRect) { // IE
        box = el.getBoundingClientRect();
        var doc = document;
        if ( parent.document != document) {// might be in a frame, need to get its scroll
            doc = parent.document;
        }

        var scroll_Top = f_scrollTop();
        var scroll_Left = f_scrollLeft();
		
        return [box.left + scroll_Left, box.top + scroll_Top];
    }
    else { // safari, opera, & gecko
        pos = [el.offsetLeft, el.offsetTop];
        parentNode = el.offsetParent;
        if (parentNode != el) {
            while (parentNode) {
                pos[0] += parentNode.offsetLeft;
                pos[1] += parentNode.offsetTop;
                parentNode = parentNode.offsetParent;
            }
        }
        if (isSafari && el.style.position == 'absolute' ) { // safari doubles in some cases
            pos[0] -= document.body.offsetLeft;
            pos[1] -= document.body.offsetTop;
        }
    }

    if (el.parentNode) { parentNode = el.parentNode; }
    else { parentNode = null; }

    while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML')
    { // account for any scrolled ancestors
        if (parentNode.style.display != 'inline') { // work around opera inline scrollLeft/Top bug
            pos[0] -= parentNode.scrollLeft;
            pos[1] -= parentNode.scrollTop;
        }

        if (parentNode.parentNode) {
            parentNode = parentNode.parentNode;
        } else { parentNode = null; }
    }


    return pos;
}


function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}


function doTableSelectRow(source, hiddenId, rowIndex)
{
    if (typeof(hiddenId) != "undefined")
    {
	    var rowObj = source.parentNode;
	    var hiddenObj = document.getElementById(hiddenId);

	    if (hiddenObj)
	    {
		    hiddenObj.value = rowIndex;
	    }
	}
	
	if (typeof(source) == 'string')
	{
	    source = document.getElementById(source);
	}

	while(rowObj != null && rowObj.tagName != "TR")
	{
		rowObj = rowObj.parentNode;
	}

	if (rowObj)
	{
		for(var rowInd = 0; rowInd <  rowObj.parentNode.childNodes.length; rowInd++)
		{
		    var currentRow = rowObj.parentNode.childNodes[rowInd];
			if (currentRow.tagName == "TR")
			{
				currentRow.className = currentRow.className.replace("selected ", "").replace("selected","");
			}
		}

		rowObj.className = "selected " + rowObj.className;
	}
}

function isDate(dtStr)
{
    return isDate(dtStr, false);
}

function isDate(dtStr, allowAllDates, allowEmptyDate){
    return isDate(dtStr, allowAllDates, true);
}

function isDate(dtStr, allowAllDates, allowEmptyDate) {
    // ja datums ir tuks
    if (dtStr.length==0)
    {
        return allowEmptyDate;
    }

    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf('.')
    var pos2=dtStr.indexOf('.',pos1+1)
    var pos3=dtStr.indexOf(' ',pos2+1)
    var pos4=dtStr.indexOf(':',pos3+1)
    
    if (pos1 != 2 || pos2 != 5)
    {
        return false;
    }
    var hasTime=false;
    if (dtStr.length>10)
    {
        if (pos3!=10 || pos4!=13 || dtStr.length>16)
        {
            return false;
        }
        hasTime=true;
    }
    
    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1,10)
    var strHour=dtStr.substring(pos3+1,pos4)
    var strMinute=dtStr.substring(pos4+1,pos4+3)

    strYr=strYear
    
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) 
            strYr=strYr.substring(1)
    }
    
    if(hasTime){
        if (strHour.charAt(0)=="0" && strHour.length>1) strHour=strHour.substring(1)
        if (strMinute.charAt(0)=="0" && strMinute.length>1) strMinute=strMinute.substring(1)
    }

    month=parseInt(strMonth, 10)
    day=parseInt(strDay, 10)
    year=parseInt(strYr, 10)
    
    if (pos1==-1 || pos2==-1)
    {
        return false;
    }

    if (strMonth.length<1 || month<1 || month>12)
    {
        return false;
    }

    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
    {
        return false;
    }

    if (strYear.length != 4 || year==0 )
    {
        return false;
    }
    
    if(hasTime){
        hour=parseInt(strHour, 10)
        minute=parseInt(strMinute, 10)
        if (hour<0||hour>23||minute<0||minute>59){
            return false;
        }
    }

    if (dtStr.indexOf('.',pos2+1)!=-1 || isInteger(stripCharsInBag(stripCharsInBag(stripCharsInBag(dtStr, '.'),':'),' '))==false)
    {
        return false;
    }

    if (!allowAllDates && ((year<1800) || (year>2200 || (year==2200 && (month > 1 || day>1)))))
    {
        return false;
    }

    return true;
}
function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is integer.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }

    return true;
}
/*
    Apraksts: Funkcija atjauno klasifikatora drop-down kontroles stāvokli, mainoties vērtībai koda teksta laukā
    Autors: Antons Ulasevičs
*/
function updateClassifierDropDown(textBoxName, dropDownName, forceOnChange)
{
    var textBox = document.getElementById(textBoxName);
    var dropDown = document.getElementById(dropDownName);
    var skipCodeReplace = false;
    var justCursorMove = false;
    if (window.event && window.event.keyCode)
    {
        // Izlaižam koda aizvietošanu, ja tika nospiesta Backspace, Delete, Left vai Right poga
        skipCodeReplace = ((event.keyCode == 8) || (event.keyCode == 46) || (event.keyCode == 37) || (event.keyCode == 39));
        // Uzstādam flagu, ja tika nospiesta Left vai Right poga
        justCursorMove = (event.keyCode == 37) || (event.keyCode == 39);
    }
    
    if (textBox == null || dropDown == null)
	    return;

    if (!skipCodeReplace)    
        textBox.value = textBox.value.toUpperCase();
    var codeStart = textBox.value.toUpperCase();
    
    var matched_entries = 0;
    var last_option_index = -1;
    var entry;
    var full_match_index = -1;
    var code_replace;
    
    // Meklējam elementus drop-down sarakstā, kuru kodiem ievadītais kods ir sākums
    for (i = 0; i < dropDown.options.length; i++)
    {
        entry = dropDown.options[i].value.toUpperCase();
        if (entry.indexOf(codeStart) == 0)
        {
            // Ir atrasts kods, kas sākas ar ievadīto kodu
            matched_entries++;
            last_option_index = i;
            code_replace = entry;
        }
        
        if (entry == codeStart)
        {
            // Ir atrasts tāds kods, kas ir vienāds ar ievadīto kodu
            full_match_index = i;
        }
    }
    
    if (matched_entries == 1)
    {
        // Ja tika atrasts tikai viens kods, kas sākas ar ievadīto kodu,
        // aizvietojam ievadīto kodu ar pilno klasifikatora vērtības kodu
        dropDown.options[last_option_index].selected = true;
            
        textBox.style.color = 'Black';
        
        if (!skipCodeReplace)
            textBox.value = code_replace;

        if (forceOnChange && !justCursorMove)
        {
            // Izsaucam OnChange notikumu drop-down sarakstam
            var backup_value = textBox.value;
            _fireEvent(dropDown, 'change'); 
            if (skipCodeReplace)
                textBox.value = backup_value;
        }
    }
    else if (full_match_index != -1)
    {
        // Ja ievadītais kods ir vienāds ar kādu no klasifikatora vērtības kodiem,
        // ieselektējam vērtību drop-down sarakstā un izsaucam OnChange notikumu
        dropDown.options[full_match_index].selected = true;
        textBox.style.color = 'Black';

        if (forceOnChange && !justCursorMove)
        {
            _fireEvent(dropDown, 'change'); 
            
        }
    }
    else
    {
        // Citādi ieselektējam pirmo ierakstu drop-down sarakstā un izsaucam OnChange
        // notikumu
        dropDown.options[0].selected = true;
        
        if (!justCursorMove)
        {
            var backup_value = textBox.value;
            _fireEvent(dropDown, 'change'); 
            textBox.value = backup_value;
        }
        
        textBox.style.color = 'Red';
    }
}





/*
    Apraksts: Funkcija nosaka, vai ievadītais kods ir sākums kādam no klasifikatora vērtības kodiem
    Autors: Antons Ulasevičs
*/
function isCodeStartValid(codeStart, dropDown)
{
    for (i = 0; i < dropDown.options.length; i++)
    {
        var entry = dropDown.options[i].value;
        
        if (entry.indexOf(codeStart) == 0)
        {
            return true;
        }
    }
    
    return false;
}

function stripCharsInBag(s, bag)
{
    var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function daysInFebruary (year)
{
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
    } 

    return this
}
/*
    Apraksts: Funkcija atgriež Date tipa objektu, kas satur datumu padoto teksta mainīgajā
    Autors: Antons Ulasevičs
*/
function parseDate(dtStr){
    // ja datums ir tuks
    if (dtStr.length==0)
    {
        return true;
    }

    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf('.')
    var pos2=dtStr.indexOf('.',pos1+1)
    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)

    strYr=strYear

    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) 
        strYr=strYr.substring(1)
    }

    month=parseInt(strMonth, 10)
    day=parseInt(strDay, 10)
    year=parseInt(strYr, 10)

    if (pos1==-1 || pos2==-1)
    {
        return false;
    }

    if (strMonth.length<1 || month<1 || month>12)
    {
        return false;
    }

    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
    {
        return false;
    }

    if (strYear.length != 4 || year==0 )
    {
        return false;
    }

    if (dtStr.indexOf('.',pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, '.'))==false)
    {
        return false;
    }

    return new Date(year, month - 1, day);
}

/*
    Apraksts: Funkcija atgriež atrāk nekā "parseDate" Date tipa objektu (neveic validacijus), kas satur datumu padoto teksta mainīgajā 
    Autors: Sergey Denisov
*/
function quickParseDate(dtStr)
{
    //var pos1=dtStr.indexOf('.')
    //var pos2=dtStr.indexOf('.',pos1+1)
    //var strDay=dtStr.substring(0,2)
    //var strMonth=dtStr.substring(3,5)
    //var strYear=dtStr.substring(6)
    return new Date(dtStr.substring(6), dtStr.substring(3,5) - 1, dtStr.substring(0,2));
    //return new Date(parseInt(dtStr.substring(6), 10), parseInt(dtStr.substring(3,5), 10) - 1, parseInt(dtStr.substring(0,2), 10));
}

/*
    Apraksts: Funkcija ievieto punktus teksta mainīgajā, ja tas ir formātā DDMMYYYY un ir korekts datums
    Autors: Antons Ulasevičs
*/
function CheckCalendarContents(dtStr, allowAllDates)
{
	if (dtStr.length==8)
	{
		var strDayOrig=dtStr.substring(0,2)
		var strMonthOrig=dtStr.substring(2,4)
		var strYearOrig=dtStr.substring(4,8)

		var newDate = strDayOrig + '.' + strMonthOrig + '.' + strYearOrig;

		if (isDate(newDate, allowAllDates))
		{
			return newDate;	
		}
		
	}
	return dtStr;
}
/*
    Apraksts: Funkcija pievieno doto JavaScript kodu kontroles OnChange notikumam
    Autors: Antons Ulasevičs
*/
function add2onchange(elem_name,jscode)
{
	if (elem_name&&jscode)
	{
	    var elem = document.getElementById(elem_name);
	    
	    if (!elem)
	        return;
	        
		if (elem.tagName == 'SPAN' || elem.tagName == 'TABLE')
		{
		    // Ja padotā kontrole ir ASP.NET RadioButtonList vai CheckBoxList kontrole, tad pievienojam JavaScript kodu tās OnClick notikumam
		    add2onclick(elem_name, jscode);
		}
		else
		{
		    if (document.getElementById(elem_name).onchange != undefined)
		    {
		        var oldJsCode = new String(document.getElementById(elem_name).onchange);
			    // eval("document.getElementById('" + elem_name + "').onchange=function() {" + jscode + "}");
		        eval("document.getElementById('" + elem_name + "').onchange = function(event) {" + oldJsCode.replace(/(.*)}[^}]*$/, "$1" + jscode).replace(/^[^{]*{(.*)/, "$1") + "}");
		        //alert(document.getElementById(elem_name).onchange);
		    }
		    else
		    {
			    eval("document.getElementById('" + elem_name + "').onchange=function() {" + jscode + "}");
		    }
		}
	}
}
/*
    Apraksts: Funkcija pievieno doto JavaScript kodu kontroles OnClick notikumam
    Autors: Antons Ulasevičs
*/
function add2onclick(elem_name,jscode)
{
    if (elem_name&&jscode)
	{
	    var ctl;
	    eval('ctl = document.' + document.forms[0].name + '.' + elem_name + '_0');

        if (ctl && ctl.type == 'checkbox')
        {
            // ASP.NET CheckBoxList kontroles gadījums
            var i = 0;
            
            do {
                eval('ctl = document.' + document.forms[0].name + '.' + elem_name + '_' + i);
                
                if (!ctl)
                    return;
            
                if (ctl.onclick != undefined)
	            {
	                eval("ctl.onclick = function() {" + ctl.onclick.toString().replace(/(.*)}[^}]*$/, "$1" + jscode).replace(/^[^{]*{(.*)/, "$1") + "}");
	                
		            if (i == 0)
                        document.getElementById(elem_name).onchange = ctl.onclick.toString().replace(/(.*)}[^}]*$/, "$1" + jscode).replace(/^[^{]*{(.*)/, "$1");
	            }
	            else
	            {
		            eval("ctl.onclick = function() {" + jscode + "}");
		            
		            if (i == 0)
                        document.getElementById(elem_name).onchange = jscode;
	            }
	            
                i++;
            } while (true);
        }
        else
        {
            // ASP.NET RadioButtonList kontroles gadījums
            eval('ctl = document.' + document.forms[0].name + '.' + elem_name);
            
            if (ctl != undefined && ctl.length != undefined)
            {
                for (ctr = 0; ctr < ctl.length; ctr++)
                {
		            if (document.getElementById(ctl[ctr].id).onclick != undefined)
		            {
		                eval("document.getElementById('" + ctl[ctr].id + "').onclick = function() {" + document.getElementById(ctl[ctr].id).onclick.toString().replace(/(.*)}[^}]*$/, "$1" + jscode).replace(/^[^{]*{(.*)/, "$1") + "}");
		            }
		            else
		            {
			            eval("document.getElementById('" + ctl[ctr].id + "').onclick = function() {" + jscode + "}");
		            }
                }
                
                if (document.getElementById(elem_name).onchange != undefined)
	            {
	                document.getElementById(elem_name).onchange = document.getElementById(elem_name).onchange.toString().replace(/(.*)}[^}]*$/, "$1" + jscode).replace(/^[^{]*{(.*)/, "$1");
	            }
	            else
	            {
		            document.getElementById(elem_name).onchange = jscode;
	            }
            }
        }
	}
}
/*
    Apraksts: Funkcija ieselektē doto vērtību RadioButtonList kontrolē
    Autors: Antons Ulasevičs
*/
function selectValueInRadioList(control, selectValue)
{
    if (control[0])
    {
        for (i = 0; i < control.length; i++)
        {
            control[i].checked = (control[i].value == selectValue);
            control[i].disabled = (control[i].value != selectValue);
        }
    }
    else
    {
        if (control.value == selectValue)
        {
           control.checked = true;
           control.disabled = false;
        }
    }
}
/*
    Apraksts: Funkcija padara pieejamu doto vērtību RadioButtonList kontrolē
    Autors: Antons Ulasevičs
*/
function enableValueInRadioList(form, control, selectValue)
{
    var ctl;
    eval('ctl = document.' + form + '.' + control);

    if (ctl.length != undefined)
    {
        for (ctr = 0; ctr < ctl.length; ctr++)
        {
            if (ctl[ctr].value == selectValue)
                ctl[ctr].disabled = false;
        }
    }
}
/*
    Apraksts: Funkcija padara nepieejamu doto vērtību RadioButtonList kontrolē
    Autors: Antons Ulasevičs
*/
function disableValueInRadioList(form, control, selectValue)
{
    var ctl;
    eval('ctl = document.' + form + '.' + control);

    if (ctl.length != undefined)
    {
        for (ctr = 0; ctr < ctl.length; ctr++)
        {
            if (ctl[ctr].value == selectValue)
            {
                ctl[ctr].checked = false;
                ctl[ctr].disabled = true;
            }
        }
    }
}
/*
    Apraksts: Funkcija padara pieejamu doto vērtību CheckBoxList kontrolē
    Autors: Antons Ulasevičs
*/
function enableValueInCheckList(form, control, i)
{
    var ctl;
    eval('ctl = document.' + form + '.' + control + '_' + i);
    if (ctl.parentNode.tagName != 'SPAN')
        eval('document.' + form + '.' + control + '_' + i + '.disabled = false');
}
/*
    Apraksts: Funkcija padara nepieejamu doto vērtību CheckBoxList kontrolē
    Autors: Antons Ulasevičs
*/
function disableValueInCheckList(form, control, i)
{
    var ctl;
    eval('ctl = document.' + form + '.' + control + '_' + i);
    if (ctl.parentNode.tagName != 'SPAN')
    {
        eval('document.' + form + '.' + control + '_' + i + '.checked = false');
        eval('document.' + form + '.' + control + '_' + i + '.disabled = true');
    }
}
/*
    Apraksts: Funkcija padara nepieejamas visas vērtības RadioButtonList kontrolē
    Autors: Antons Ulasevičs
*/
function disableButtonsInRadioList(form, control)
{
    var ctl;
    eval('ctl = document.' + form + '.' + control);

    if (ctl.length != undefined)
    {
        for (ctr = 0; ctr < ctl.length; ctr++)
        {
            ctl[ctr].checked = false;
            ctl[ctr].disabled = true;
        }
    }
}
/*
    Apraksts: Funkcija padara nepieejamas visas vērtības CheckBoxList kontrolē
    Autors: Antons Ulasevičs
*/
function disableButtonsInCheckList(form, control)
{
    var ctl;
    
    var i = 0;
    do {
        eval('ctl = document.' + form + '.' + control + '_' + i);
 
        if (!ctl)
            return;
        
        ctl.checked = false;
        ctl.disabled = true;

        i++;
    } while (true);
}
/*
    Apraksts: Funkcija padara nepieejamas CheckBoxList vērtības, kam piesaistītās datuma kontroles datums neietilpst datumu intervālā
    Autors: Antons Ulasevičs
*/
function alterCheckBoxList(formId, listId, dateControl, entriesArrName)
{
    var strSelectedDate = document.getElementById(dateControl).value;
    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    
    if (strSelectedDate == '')
    {
        // Ja piesaistītā datuma kontrolē nav ievadīts datums, atslēdz visas vērtības
        for (i = 0; i < entriesArr.length; i++)
            disableValueInCheckList(formId, listId, entriesArr[i][2]);    
    }
    else if (strSelectedDate != '' && isDate(strSelectedDate)) {
        // Ja ir ievadīts korekts datums, tad atslēdz tas vērtības, kam datums nav aktivitātes intervālā
        var selectedDate = parseDate(strSelectedDate);

        for (i = 0; i < entriesArr.length; i++) {
            var strStartDate = entriesArr[i][3];
            var strEndDate = entriesArr[i][4];
            
            if (!isDate(strStartDate) || !isDate(strEndDate)) continue;
                
            var startDate = parseDate(strStartDate);
            var endDate = parseDate(strEndDate);

            if (selectedDate >= startDate && selectedDate <= endDate) {
                // Ieslēdzam vērtību
                enableValueInCheckList(formId, listId, entriesArr[i][2]);
            }
            else {
                // Atslēdzam vērtību
                disableValueInCheckList(formId, listId, entriesArr[i][2]);
            }
        }
    }
}
/*
    Apraksts: Funkcija padara nepieejamas RadioButtonList vērtības, kam piesaistītās datuma kontroles datums neietilpst datumu intervālā
    Autors: Antons Ulasevičs
*/
function alterRadioButtonList(formId, listId, dateControl, entriesArrName)
{
    var strSelectedDate = document.getElementById(dateControl).value;
    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    
    if (strSelectedDate == '')
    {
        // Ja piesaistītā datuma kontrolē nav ievadīts datums, atslēdz visas vērtības
        for (i = 0; i < entriesArr.length; i++)
            disableValueInRadioList(formId, listId, entriesArr[i][0]);    
    }
    else if (strSelectedDate != '' && isDate(strSelectedDate)) {
        // Ja ir ievadīts korekts datums, tad atslēdz tas vērtības, kam datums nav aktivitātes intervālā
        var selectedDate = parseDate(strSelectedDate);

        for (i = 0; i < entriesArr.length; i++) {
            var strStartDate = entriesArr[i][2];
            var strEndDate = entriesArr[i][3];
            if (!isDate(strStartDate) || !isDate(strEndDate)) continue;
            
            var startDate = parseDate(strStartDate);
            var endDate = parseDate(strEndDate);
            
            if (selectedDate >= startDate && selectedDate <= endDate) {
                // Ieslēdzam vērtību
                enableValueInRadioList(formId, listId, entriesArr[i][0]);
            }
            else {
                // Atslēdzam vērtību
                disableValueInRadioList(formId, listId, entriesArr[i][0]);
            }
        }
    }
}
/*
    Apraksts: Funkcija padara nepieejamas DropDownList vērtības, kam piesaistītās datuma kontroles datums neietilpst datumu intervālā
    Autors: Antons Ulasevičs
*/
function alterDropDownList(textBoxId, listId, dateControl, entriesArrName)
{
    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    var dropDown = document.getElementById(listId);
    
    var strSelectedDate = document.getElementById(dateControl).value;
    
    if (strSelectedDate == '' || !isDate(strSelectedDate)) {
        // Ja piesaistītā datuma kontrolē nav ievadīts datums, slēpj visas vērtības
        dropDown.options.length = 1;
        var txtCC = document.getElementById(textBoxId);
        if (txtCC.value != '') txtCC.style.color = 'Red'; else txtCC.style.color = 'Black';
    } else {

        // Ja ir ievadīts korekts datums, tad slēpj tas vērtības, kam datums nav aktivitātes intervālā
    
        // Izņem visas vērtības
        var selectedDate = parseDate(strSelectedDate);
        var j = 1;
        dropDown.options.length = 1;

        for (i = 0; i < entriesArr.length; i++) {
    
            //var strStartDate = entriesArr[i][2];
            //var strEndDate = entriesArr[i][3];
            
            //if (!isDate(strStartDate) || !isDate(strEndDate)) continue;
            
            //var startDate = quickParseDate(entriesArr[i][2]);
            //var endDate = quickParseDate(entriesArr[i][3]);
            //document.write(quickParseDate(entriesArr[i][2]));
            if (selectedDate <= quickParseDate(entriesArr[i][3]) && selectedDate >= quickParseDate(entriesArr[i][2])) 
            {
            
                // Ja datums ir aktivitātes intervālā, tad ievieto vērtību sarakstā
                //j++;
                //dropDown.add(entriesArr[i][1],entriesArr[i][0]);
                //dropDown.options.length = j;
                //dropDown.options[j-1] = new Option(entriesArr[i][1], entriesArr[i][0]);
                dropDown.options.add(new Option(entriesArr[i][1], entriesArr[i][0]));
                //op.add(new Option(entriesArr[i][1], entriesArr[i][0]));
                //dropDown.options[j-1].text = entriesArr[i][1];
                //dropDown.options[j-1].value = entriesArr[i][0];
            }
            //dropDown.options = op;
            
        }

        var txtCC = document.getElementById(textBoxId);
        var ddlCV = document.getElementById(listId);
        if (txtCC.value == '' && ddlCV.options.length != 1)
            // Ierakstam izvēlētās vērtības kodu koda laukā
            txtCC.value = ddlCV.options[ddlCV.selectedIndex].value;
        else if (txtCC.value != '' && ddlCV.options.length == 1)
            // Ja kods nav tukšs, bet sarakstā nav elementu, atzīmējam kodu kā nederīgu
            txtCC.style.color = 'Red';
        else if (!isCodeStartValid(txtCC.value, ddlCV))
            // Ja kods nav sākums nevienam saraksta elementa kodam, tad atzīmējam kodu kā nederīgu
            txtCC.style.color = 'Red';
        else if (isCodeStartValid(txtCC.value, ddlCV))
            // Ja kods ir sākums kādam saraksta elementa kodam, tad atjaunojam drop-down sarakstu
            updateClassifierDropDown(textBoxId, listId, false);
    }
}
/*
    Apraksts: Funkcija filtrē DropDownList kontroles elementus atkārībā no virskontrolē izvēlētās vērtības
    Autors: Antons Ulasevičs
*/
function filterDropDownListByParent(textBoxId, listId, entriesArrName, parentClassifierArrayName, parentControlId)
{

    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    
    var dropDown = document.getElementById(listId);
    var textBox = document.getElementById(textBoxId);
    var parentControl = document.getElementById(parentControlId);
 
    if (dropDown && textBox && parentControl)
    {
        // Nosakam virskontrolē izvēlēto vērtību identifikatorus
        var parentValueCode = getSelectedValue(parentControl);
        var parentValueIdArray = getClassifierValueIdByCode(parentClassifierArrayName, parentValueCode);


        if (parentValueIdArray != undefined)
        {
            var j = 1;

            // Nolasam iepriekš saglabāto backup-masīvu ar elementiem
            var backupArr;
            eval('if (window.' + listId + '_backup) { backupArr = window.' + listId + '_backup; }');
            
            if (backupArr == undefined)
            {
                // Ja neeksistē backup-masīvs ar elementiem, tad izveidojam to
                eval('window.' + listId + '_backup = new Array(document.getElementById("' + listId + '").options.length);');
                eval('for (var k = 0; k < document.getElementById("' + listId + '").options.length; k++) {' + 
                    'window.' + listId + '_backup[k] = document.getElementById("' + listId + '").options[k].value + ";" + ' +
                    'document.getElementById("' + listId + '").options[k].text; }');
            }
            else
            {
                // Ja eksistē backup-masīvs ar elementiem, tad atjaunojam DropDownList elementus no backup-masīva
                eval('document.getElementById("' + listId + '").options.length = backupArr.length; ' +
                    'for (var l = 0; l < backupArr.length; l++) { ' +
                    ' document.getElementById("' + listId + '").options[l].value = backupArr[l].substring(0, backupArr[l].indexOf(";")); ' +
                    ' document.getElementById("' + listId + '").options[l].text = backupArr[l].substring(backupArr[l].indexOf(";") + 1, backupArr[l].length); ' +
                    '}' + 
                    'document.getElementById("' + listId + '").selectedIndex = 0;');
            }
          
          
           
            if (parentValueIdArray.length == 0)
            {
                // Ja virskontrolē nav izvēlētās vērtības, tad izņemam visus elementus
                dropDown.options.length = 1;
            }
            else
            {
                for (var j = 1; j < dropDown.options.length; j++) {
                    // Ejām cauri DropDownList elementiem
                    
                    var lookingForValue = dropDown.options[j].value;
                    for (var i = 0; i < entriesArr.length; i++)
                    {
                        // Meklējām klasifikatora masīvā tekošo DropDownList elementu
                        if (entriesArr[i][0] == lookingForValue)
                        {
                            if (!in_array(parentValueIdArray, entriesArr[i][entriesArr[i].length - 1]))
                            {
                            
                                // Ja tekošā DropDownList elementa virsvērtība nav izvēlēta virskontrolē, tad
                                // nobīdam visus nākamos elementus, tādējādi izņemot tekošo no saraksta
                                
                                dropDown.remove(j);
                                /*
                                for (var k = j; k < dropDown.options.length - 1; k++)
                                {
                                    dropDown.options[k].value = dropDown.options[k + 1].value;
                                    dropDown.options[k].text = dropDown.options[k + 1].text;
                                }
                                dropDown.options.length = dropDown.options.length - 1;
                                */
                                j--;
                            }
                        }
                    }
                }

            }
            //alert(dropDown.onchange);
            // Izsaucam OnChange notikumu
            try
            {
                //textBox.fireEvent('onkeyup');
                updateClassifierDropDown(textBoxId, listId, false)
                //_fireEvent(textBox, 'keyup'); 
                
                //dropDown.onchange();
            }
            catch (error) {}
        }
    }
}
/*
    Apraksts: Funkcija filtrē RadioButtonList kontroles elementus atkārībā no virskontrolē izvēlētās vērtības
    Autors: Antons Ulasevičs
*/
function filterRadioButtonsByParent(formId, radioControl, entriesArrName, parentClassifierArrayName, parentControlId)
{
    var radioList;
    eval('radioList = document.' + formId + '.' + radioControl);
    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    
    var parentControl = document.getElementById(parentControlId);
    
    if (radioList && parentControl)
    {
        // Nosakam virskontrolē izvēlēto vērtību identifikatorus
        var parentValueCode = getSelectedValue(parentControl);
        var parentValueIdArray = getClassifierValueIdByCode(parentClassifierArrayName, parentValueCode);

        if (parentValueIdArray != undefined)
        {
            if (parentValueIdArray.length == 0)
            {
                // Ja virskontrolē nav izvēlētās vērtības, tad atslēdzam visus elementus
                disableButtonsInRadioList(formId, radioControl);
            }
            else
            {
                for (var j = 0; j < radioList.length; j++)
                {
                    // Ejām cauri RadioButtonList elementiem
                    var lookingForValue = radioList[j].value;
                    
                    for (var i = 0; i < entriesArr.length; i++)
                    {
                        // Meklējām klasifikatora masīvā tekošo RadioButtonList elementu
                        if (entriesArr[i][0] == lookingForValue)
                        {
                            if (!in_array(parentValueIdArray, entriesArr[i][entriesArr[i].length - 1]))
                            {
                                // Ja tekošā RadioButtonList elementa virsvērtība nav izvēlēta virskontrolē, tad
                                // atslēdzam to
                                radioList[j].checked = false;
                                radioList[j].disabled = true;
                            }
                            else
                            {
                                radioList[j].disabled = false;
                            }
                        }
                    }
                }
            }

            // Izsaucam OnChange notikumu
            eval(document.getElementById(radioControl).onchange);
        }
    }
}
/*
    Apraksts: Funkcija filtrē CheckBoxList kontroles elementus atkārībā no virskontrolē izvēlētās vērtības
    Autors: Antons Ulasevičs
*/
function filterCheckBoxListByParent(formId, checkBoxControl, entriesArrName, parentClassifierArrayName, parentControlId)
{
    var entriesArr;
    eval('entriesArr = ' + entriesArrName);
    
    var parentControl = document.getElementById(parentControlId);
    
    if (parentControl)
    {
        // Nosakam virskontrolē izvēlēto vērtību identifikatorus
        var parentValueCode = getSelectedValue(parentControl);
        var parentValueIdArray = getClassifierValueIdByCode(parentClassifierArrayName, parentValueCode);

        if (parentValueIdArray != undefined)
        {
            if (parentValueIdArray.length == 0)
            {
                // Ja virskontrolē nav izvēlētās vērtības, tad izņemam visus elementus
                disableButtonsInCheckList(formId, checkBoxControl);
                enableValueInCheckList(formId, checkBoxControl, entriesArr[0][2]);
            }
            else
            {
                enableValueInCheckList(formId, checkBoxControl, entriesArr[0][2]);

                for (var j = 1; j < entriesArr.length; j++)
                {
                    // Ejām cauri CheckBoxList elementiem
                    var currentParentId = entriesArr[j][entriesArr[j].length - 1];

                    if (!in_array(parentValueIdArray, currentParentId))
                    {
                        // Ja tekošā CheckBoxList elementa virsvērtība nav izvēlēta virskontrolē, tad
                        // atslēdzam to
                        disableValueInCheckList(formId, checkBoxControl, entriesArr[j][2]);
                    }
                    else
                    {
                        enableValueInCheckList(formId, checkBoxControl, entriesArr[j][2]);
                    }
                }
            }
            
            // Izsaucam OnChange notikumu
            eval(document.getElementById(checkBoxControl).onchange);
        }
    }
}
/*
    Apraksts: Funkcija atgriež izvēlētās vērtības klasifikatora kontrolē
    Autors: Antons Ulasevičs
*/
function getSelectedValue(parentControl)
{
    var elem_type = parentControl.type;
    
    if (elem_type == 'select-one' && parentControl.selectedIndex >= 0)
    {
        // ASP.NET DropDownList kontroles gadījums
        return new Array(parentControl.options[parentControl.selectedIndex].value);
    }
    else if (parentControl.tagName == 'SPAN' || parentControl.tagName == 'TABLE')
    {
        var ctl;
        eval('ctl = document.' + document.forms[0].name + '.' + parentControl.id + '_0');

        if (ctl && ctl.type == 'checkbox')
        {
            // ASP.NET CheckBoxList kontroles gadījums
            var retArr = new Array();
            
            var i = 0;
            var found = 0;
            
            do {
                eval('ctl = document.' + document.forms[0].name + '.' + parentControl.id + '_' + i);
         
                if (!ctl)
                    break;
            
                if (ctl.checked)
                {
                    try
                    {
                        var entriesArr;
                        eval('entriesArr = ' + parentControl.id.substring(0, parentControl.id.lastIndexOf('_cblClassifierValues')) + '_array;');
                        
                        if (entriesArr)
                        {
                            var currentCode = entriesArr[i][0];
                            retArr[found] = currentCode;
                            found++;
                        }
                    } catch (error) {  }
                }    

                i++;
            } while (true);
            
            return retArr;
        }
        else
        {
            // ASP.NET RadioButtonList kontroles gadījums
            eval('ctl = document.' + document.forms[0].name + '.' + parentControl.id);

            if (ctl != undefined && ctl.length != undefined)
            {
                for (ctr = 0; ctr < ctl.length; ctr++)
                {
                    if (ctl[ctr].checked)
                        return new Array(ctl[ctr].value);
                }
            }    
        }
    }
}
/*
    Apraksts: Funkcija nosaka klasifikatora vērtības identifikatoru pēc klasifikatora vērtības koda
    Autors: Antons Ulasevičs
*/
function getClassifierValueIdByCode(parentClassifierArrayName, valueCode)
{
    var parentEntriesArr;

    if (valueCode)
    {
        eval ('parentEntriesArr = ' + parentClassifierArrayName);
        
        var retArr = new Array();
        var found = 0;
        
        for (var j = 0; j < valueCode.length; j++)
        {
            for (var i = 0; i < parentEntriesArr.length; i++)
            {
                if (parentEntriesArr[i][0] == valueCode[j])
                {
                    retArr[found] = parentEntriesArr[i][parentEntriesArr[i].length - 2];
                    found++;
                }
            }
        }
        
        return retArr;
    }
    else
        return new Array();
}
/*
    Apraksts: Funkcija nosaka, vai dotais elements ir attēlots ar dotās CSS klases lietošanu
    Autors: Antons Ulasevičs
*/
function checkClass(oElm, strClassName)
{
    strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	return oRegExp.test(oElm.className);
}
/*
    Apraksts: Funkcija pievieno dotā elementa CSS klasēm jauno klases nosaukumu
    Autors: Antons Ulasevičs
*/
function addClass(oElm, strClassName)
{
    if(!checkClass(oElm, strClassName))
    {
        oElm.className += oElm.className ? ' ' + strClassName : strClassName;
    }
}
/*
    Apraksts: Funkcija izņem no dotā elementa CSS klasēm doto klases nosaukumu
    Autors: Antons Ulasevičs
*/
function removeClass(oElm, strClassName)
{
    if (oElm != null)
    {
        var rep = oElm.className.match(' '+strClassName) ? ' ' + strClassName : strClassName;
        oElm.className = oElm.className.replace(rep, '');
        oElm.className.replace(/^\s./, '');
    }
}
/*
    Apraksts: Funkcija ieselektē doto elementu
    Autors: Antons Ulasevičs
*/
function setChecked(elementId)
{
    document.getElementById(elementId).checked=true;
}
/*
    Apraksts: Funkcija nosaka, vai dotā vērtība ir masīvā
    Autors: Antons Ulasevičs
*/
function in_array(array,value)
{
    if (array.constructor.toString().indexOf("Array") == -1)
        return false;
    
    for (var i = 0; i < array.length; i++)
    {
        if (array[i] == value)
            return true;
    }
    
    return false;
}


// ctl00_MainContent_uxClassifierRadioButtonList_rblClassifierValues_5
/*
    Apraksts: Funkcija atgriež ClassifierCheckBoxList kontroles izvēlētā elementa kodus
    Autors: Alexander Popov
*/
function getClassifierCheckBoxListSelectedValuesCSL( elem_name )
{
    var elemPrefix = elem_name + "_cblClassifierValues_";
    
    var array;
    
    eval( "array = " + elem_name + "_array" )
   
    var result = "";
    
    var index = 0;
    var ctr;
    var addAll = false;
    
    do
    {
        eval( "ctr = document.getElementById('" + elemPrefix + index + "')" );
        
        if ( !ctr ) 
        {
            break;
        }
        
        if ( ctr.checked || addAll )
        {            
            if ( index == 0 )
            {
                addAll = true;
            }   
            else
            {
                if ( result.length > 0 )
                {
                    result += ",";
                }
                
                result += array[index][0];
            }
        }
        
        index++;
        
        
        
    }while(true)
    
    
    return result;
}
/*
    Apraksts: Funkcija atgriež ClassifierRadioButtonList kontroles SELECT elementu
    Autors: Alexander Popov
*/
function getClassifierRadioButtonListObjects(elem_name)
{
    return document.getElementsByName(elem_name + '_rblClassifierValues');     
}
/*
    Apraksts: Funkcija atgriež ClassifierRadioButtonList kontroles izvēlētā elementa kodu
    Autors: Alexander Popov
*/
function getClassifierRadioButtonListSelectedValue( elem_name )
{
    var elems = getClassifierRadioButtonListObjects( elem_name );
    
   
    
    for( var index = 0; index < elems.length; index ++ )
    {       
        if ( elems[ index ].checked )
        {
            return elems[ index ].value;
        }   
    }
    
    return "";
}
/*
    Apraksts: Funkcija atgriež ClassifierDropDown kontroles SELECT elementu
    Autors: Antons Ulasevičs
*/
function getClassifierDropDownObject(elem_name)
{
    return document.getElementById(elem_name + '_ddlClassifierValues');
}
/*
    Apraksts: Funkcija atgriež ClassifierDropDown kontroles izvēlētā elementa kodu
    Autors: Antons Ulasevičs
*/
function getClassifierDropDownValueCode(elem_name)
{
    var elem = getClassifierDropDownObject(elem_name);
    
    if (!elem)
        return;
        
    return elem.options[elem.selectedIndex].value;
}
/*
    Apraksts: Funkcija atgriež ClassifierDropDown kontroles izvēlētā elementa vērtību
    Autors: Antons Ulasevičs
*/
function getClassifierDropDownValueTextValue(elem_name)
{
    var elem = getClassifierDropDownObject(elem_name);
    
    if (!elem)
        return;
        
    return elem.options[elem.selectedIndex].text;
}
/*
    Apraksts: Funkcija atgriež ClassifierDropDown kontroles izvēlētās vērtības identifikatoru
    Autors: Antons Ulasevičs
*/
function getClassifierDropDownValueId(elem_name)
{
    var valueCode = getClassifierDropDownValueCode(elem_name);
    
    if (!valueCode)
        return;
        
    return getClassifierValueIdByCode(elem_name + '_array', valueCode);
}


function isSet(name)
{
    try
    {
	    if (typeof document.all[name] == "undefined") 
	    {
		    return false;
	    }
	    return true;
	}
	catch (error)
	{
	    if (document.getElementById(name) != null)
	    {
	        return true;
	    }
	    return false;
	}
}


function setRadioValue(name,value)
{
	if (isSet(name)) 
	{
		
		switch (document.all[name][0].type)
		{
			case "radio": 
				for(var j = 0 ; j < document.all[name].length ; ++j) {
					document.all[name][j].checked = document.all[name][j].value == value;
			   }
			break;
			
		}
	}
}

function setValue(name,value) {
    setValueNoEvent(name, value);    
    DoFireEvent(name, 'change');
}

function DoFireEvent(name, event) {    
    if (isSet(name)) {
        var elem = null;
        try {
            elem = document.all[name];
        }
        catch (error) {
            elem = document.getElementById(name);
        }

        if (elem != null) {            
            _fireEvent(elem, event)
        }
    }
}

function setValueNoEvent(name, value) {    
    if (isSet(name)) {
        var elem = null;
        try {
            elem = document.all[name];
        }
        catch (error) {
            elem = document.getElementById(name);
        }

        if (typeof elem.type == "undefined") {
            setRadioValue(name, value);
        }
        else {
            switch (elem.type) {
                case "checkbox":
                    if (value == 1) {
                        elem.checked = true;
                    }
                    else {
                        elem.checked = false;
                    }
                    break;

                case "select-one":
                default:
                    elem.value = value;
            }
        }
    }
}

function isEmptyField(name)
{
	if (isSet(name))
	{
		switch (document.all[name].type)
		{
			case 'checkbox':
				if (document.all[name].checked) 
				{
					return false;
				}
				break;
			default:
				if (document.all[name].value!='') 
				{
					return false;
				}
				break;
		}
	}
	return true;
}


function getValue(name)
{
        if (isSet(name))
        {
		switch (document.all[name].type)
		{
			case "checkbox": 
				if (document.all[name].checked)
				{
					return 1;
				}
				else
				{
					return '';
				}
				break;
			case "select-one": 
			default: 
				return document.all[name].value;
				break;
		 }
	}
}


function textDateToTimeStamp(dtStr)
{
	var pos1=dtStr.indexOf('.')
	var pos2=dtStr.indexOf('.',pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var d = new Date(parseInt(strYear, 10), parseInt(strMonth, 10)-1, parseInt(strDay, 10));
	var timestamp=d.getTime();
	return timestamp;
}


/*
    Apraksts: Funkcija ieselektē vai atselektē visas aktīvas CheckBoxList vērtības atkarībā no "Izvēlēties visas" vērtības stāvokļa
    Autors: Antons Ulasevičs
*/
function setCheckBoxesState(toggler, form, control)
{
    var ctl;

    var i = 0;
    do {
        eval('ctl = document.' + form + '.' + control + '_' + i);
 
        if (!ctl)
            return;
        
        if (toggler != ctl && !ctl.disabled)
        {
            try
            {
                if (ctl.parentNode.tagName != 'SPAN')
                    ctl.checked = toggler.checked;
            }
            catch (error)
            {
                ctl.checked = toggler.checked;
            }
        }

        i++;
    } while (true);
}


var tmpimg = new Image();
var ImageControlName;

function LoadingImage()
{
	if( tmpimg.readyState=="complete" )
	{
		var image = document.getElementById(ImageControlName);
		image.src = tmpimg.src;
	}
	else
	{
		window.document.forms[0].reset();
    	SetEmptyImage();
	}
}

function LoadingEmptyImage()
{
	if( tmpimg.readyState=="complete" )
	{
		var image = document.getElementById(ImageControlName);
		image.src = tmpimg.src;
	}
}
function SetEmptyImage()
{	
    tmpimg.src = '../i/1pix.png';
	tmpimg.onreadystatechange = LoadingEmptyImage;
}

function checkFormat( fileName )
{
	var ext = fileName.substr(fileName.length - 4).toLowerCase();
	return (ext == '.jpg');
}

function UpdateImage(uploadName, imageName)
{		
    tmpimg = new Image();
	var imageFile = document.getElementById(uploadName);
	ImageControlName = imageName;
	if ( checkFormat( imageFile.value ) )
	{
	     tmpimg.onreadystatechange = LoadingImage;
	     tmpimg.src = imageFile.value;			
	}
	else
    {
	    window.document.forms[0].reset();
		SetEmptyImage();
		alert('Iespējami tikai JPEG failu formāts!');
	}
}

function SetClassifierDropDownValueCode(elem_code, value_code)
{
    var dropdown_object = getClassifierDropDownObject(elem_code);
	if (dropdown_object != undefined)
		setValue(dropdown_object.name,value_code);
}


// useg in classifier form to ampty all clssifier input fields
function ClearAllClassifierInputFields(form)
{
   for(i=0; i<form.elements.length; i++)
	{
		if(form.elements[i].type == 'checkbox')
		{
			form.elements[i].checked = false;
			form.elements[i].disabled = false;
		}
		else 
		{
			if (form.elements[i].type == 'text')
			{
				form.elements[i].value = "";
				form.elements[i].disabled = false;
			}
			else
			{
				if (form.elements[i].type == 'select-one')
			    {
				    form.elements[i].selectedIndex = "-1";
				    form.elements[i].disabled = false;
			    }
			}
        }	
	}
}



var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

/*
function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
*/
function ShowHideDiv(DivId)
{
    var el = document.getElementById(DivId); 
    if (el!=null)
    {
        el.style.display=(el.style.display=='none'?'block':'none');
    }
    return false;
}

function ShowHideInlineElement(ElementId) {
    var el = document.getElementById(ElementId);
    if (el != null) {        
        el.style.display = (el.style.display == 'none' ? 'inline' : 'none');        
    }
    return false;
}

function ShowSingleInlineElement(ElementId) {    
    var el = document.getElementById(ElementId);
    if (el != null) {
        el.style.display = (el.style.display == 'none' ? 'inline' : el.style.display);
    }

    var hdnId = '__lastShownElement';
    EnsureHiddenField(hdnId);
    var hdn = document.getElementById(hdnId);
    if (hdn != null) {
        var lastId = hdn.value ? hdn.value : "notset";
        if (lastId != ElementId) {
            var last = document.getElementById(lastId);
            if (last) {
                last.style.display = 'none';
            }
        }
        hdn.value = ElementId;
    }
    
    return true;
}

function ShowInlineElement(ElementId) {
    var el = document.getElementById(ElementId);
    if (el != null) {
        el.style.display = (el.style.display == 'none' ? 'inline' : el.style.display);
    }
    return true;
}

function EnsureHiddenField(Id) {
    var el = document.getElementById(Id);
    if (el == null) {
        try {
            var input = document.createElement("input");
            input.setAttribute("type", "hidden");
            input.setAttribute("id", Id);
            input.setAttribute("value", "");
            document.forms[0].appendChild(input);
        } catch (e) { }
    }
    return true;
}

/*
Raise event (work with FX, IE)
*/
function _fireEvent(element, event)
{
    try
    {
        var e = document.createEvent('HTMLEvents');
        e.initEvent(event, false, false);
        element.dispatchEvent(e);
    }
    catch (error)
    {
   
        switch(event)
        {
            case "change":
                element.fireEvent('onchange');
                break;
            case "keyup":
                element.fireEvent('onkeyup');
                break;
        }
    }

}

function CopyLastTableRow(tableId, rowcountId) {
    /* Declare variables */
    var table, templateRow, newRow, rowCounter;
    var i, s, t;

    table = document.getElementById(tableId);
    templateRow = table.rows[table.rows.length-1];
    

    /* Make a copy of the template row */
    newRow = templateRow.cloneNode(true);
    /* Add the newly-created row to the table */
    templateRow.parentNode.appendChild(newRow);

    rowCounter = document.getElementById(rowcountId)
    //try 
    //{
    var originalRowCount = parseInt(rowCounter.value);
    originalRowCount = originalRowCount + 1;
    rowCounter.value = originalRowCount;
    //}
    //catch (error) { }
    return true;

}

function IncrementCounter(counterId) 
{
    rowCounter = document.getElementById(counterId);
    var originalRowCount = rowCounter ? parseInt(rowCounter.value) : 0;    
    rowCounter.value = originalRowCount + 1;    
    return true;
}

function foozzz() {
   // return RegisterFormulaChange('[TXTL]+[SUM(TXTL)]-[AVG(TXTA)]/[MIN(TXTL)]+[MAX(TXTL)]', 'ctl00_MainContent_Calendar1_uxHelpTooltip');
    // return RegisterFormulaChange('[SUM(TXTL)]', 'ctl00_MainContent_uxSection_ctl06_warning');

    var ul = document.getElementById('ctl00_MainContent_tst_uxTree_UL');
    alertInfo(ul);
    var li1 = ul.firstChild;
    while (!isListItem(li1)) {
        li1 = li1.nextSibling;
    }
    alertInfo(li1);
    var li2 = li1.nextSibling;
    while (!isListItem(li2)) {
        li2 = li2.nextSibling;
    }
    alertInfo(li2);
    var cb = FindCheckBoxInsideElement(li2);
    alert("found check box: " + cb.id);
}
function alertInfo(el){
    alert("info: element id = " + el.id + "; class = " + el.className + "; tag=" + el.tagName);
}

/*
Apraksts: Funkcija analīzē padoto formulu, atrod lauku kodus, tad pēc tiem atrod atbilstošus HTML elementus.
Atrastiem elementiem funkcija piereģistrē papildus "onchange" notikumu - norādītā elementa (elementId) parādīšanu
Autors: Ilja Nevdahs
*/
function RegisterFormulaChange(formula, elementId) {
    var regex = '\\[([A-Z0-9]+)\\]|\\(([A-Z0-9]+)\\)';
    //alert(regex);
    var val = formula;

    var count = 0;
    var codes = [];
    var str = "";
    //only 2 regex groups supported!!!
    while (val.match(regex)) {
        if (RegExp.$1.length != 0) {
            if (str.indexOf(RegExp.$1) < 0) {
                codes[codes.length] = RegExp.$1;
            }
            str = str + RegExp.$1 + '\n';
            val = val.replace(RegExp.$1, "");
        }
        if (RegExp.$2.length != 0) {
            if (str.indexOf(RegExp.$2) < 0) {
                codes[codes.length] = RegExp.$2;
            }
            str = str + RegExp.$2 + '\n';
            val = val.replace(RegExp.$2, "");
        }
        count++;
        if (count > 10) { break; }
    }

    for (var i = 0; i < codes.length; i++) {
        //alert(codes[i]);
        var els = document.getElementsByName(codes[i]);
        //alert(els.length);
        if ((els != null) && (els.length > 0)) {
            for (var j = 0; j < els.length; j++) {
                var container = els[j];
                var control = container.firstChild;                
                while (control != null) {
                    if (control.id != undefined) {
                        if ((control.tagName == 'INPUT')||(control.tagName == 'TEXTAREA')) {
                            addListener(control, "change", function() { ShowInlineElement(elementId); });                            
                        }
                    }
                    control = control.nextSibling;
                }
            }
        }
    }
}
/*
Apraksts: Funkcija pievieno doto JavaScript funkciju kontroles norādītamm notikumam
Autors: Ilja Nevdahs
Piemērs: addListener(control, "change", function() { alert("value changed!"); });
*/
function addListener(element, event, listener, bubble) {
    if (element.addEventListener) {
        if (typeof (bubble) == "undefined") bubble = false;
        element.addEventListener(event, listener, bubble);
    } else if (element.attachEvent) {
        element.attachEvent("on" + event, listener);
    }
}



/*
Apraksts: funkciju kopa darbam ar adaptēto TreeView
*/
// TreeView Begin ********************************

function ConfirmTreeSelection(id, text){
    if (!ValidateTreeSelection(id)) {
        return confirm(text);
    }
    else return true;
}

function ValidateTreeSelection(id) {
    //alert(id);
    if (!isNull(id)) {        
        var types = document.getElementsByName(id + '_isType');
        if (types != null && types.length > 0) {
            for (var i = 0; i < types.length; i++) {
                var chk = types[i].nextSibling;
                while (!isNull(chk)) {
                    if (isCheckBox(chk)) {
                        if (chk.checked)
                        { return true; }
                    }                    
                    chk = chk.nextSibling;                    
                }
            }
        }

        var stypes = document.getElementsByName(id + '_isSubType');
        if (stypes != null && stypes.length > 0) {
            for (var i = 0; i < stypes.length; i++) {
                var chk = stypes[i].nextSibling;
                while (!isNull(chk)) {
                    if (isCheckBox(chk)) {
                        if (chk.checked)
                        { return true; }
                    }
                    chk = chk.nextSibling;
                }
            }
        }
    }
    return false;
}

function FindTreeViewRoot(element) {
    var result = null;
    while (!isNull(element)) {
        if (isDiv(element) && element.id) {
            result = element;
            break;
        }
        element = element.parentNode;
    }
    return result;
}
function CascadeCheckmarks(e, id) {
     // obj gives us the node on which check or uncheck operation has performed          
    var element = e.srcElement || e.target;
    var parentState = true; //default true;

    //checking whether obj consists of checkbox to avoid exception
    if (isCheckBox(element)) {
        var checkedState = element.checked;        
        //find root element
        var root = FindTreeViewRoot(element);
        if (isNull(root)) return false;

        if (isSectorCheckBox(element)) {
            //show button            
            if (id != null && id != "") {
                var button = document.getElementById(id);
                if (!isNull(button)) {
                    if (checkedState) {
                        ShowElementRememberSyle(button);
                    }
                    else {
                        HideElementRememberSyle(button);
                    }
                }
            }            
            //find all sector elements
            var sectors = document.getElementsByName(root.id + '_isSector');
            if (sectors != null && sectors.length > 0) {
                for (var i = 0; i < sectors.length; i++) {
                    //get first element, expect a checkbox
                    var chk = sectors[i].nextSibling;
                    while (!isNull(chk)) {
                        if (isCheckBox(chk)) {
                            //disable other sectors
                            if (element != chk) {
                                chk.checked = false;
                                CascadeEnableSector(root.id, chk.parentNode.id, false);
                            }
                            //enable/disable this sector
                            else {
                                CascadeEnableSector(root.id, chk.parentNode.id, checkedState);
                            }
                            break;
                        }
                        //search for checkbox
                        chk = chk.nextSibling;
                    }
                }
            }
        }
        else if (isTypeCheckBox(element)) {
            CascadeEnableType(root.id, element.parentNode.id, checkedState);
        }
    }
}
function CascadeCheckmarks2(e, id) {
    // obj gives us the node on which check or uncheck operation has performed          
    var element = e.srcElement || e.target;
    var parentState = true; //default true;

    //checking whether obj consists of checkbox to avoid exception
    if (isCheckBox(element)) {
        var checkedState = element.checked;
        //find root element
        var root = FindTreeViewRoot(element);
        if (isNull(root)) return false;

        if (isSectorCheckBox(element)) {
            //show button            
            if (id != null && id != "") {
                var button = document.getElementById(id);
                if (!isNull(button)) {
                    if (checkedState) {
                        ShowElementRememberSyle(button);
                    }
                    else {
                        HideElementRememberSyle(button);
                    }
                }
            }
            //find all sector elements
            var sectors = document.getElementsByName(root.id + '_isSector');
            if (sectors != null && sectors.length > 0) {
                for (var i = 0; i < sectors.length; i++) {
                    //get first element, expect a checkbox
                    var chk = sectors[i].nextSibling;
                    while (!isNull(chk)) {
                        if (isCheckBox(chk)) {
                            //enable/disable this sector
                            CascadeEnableSector(root.id, chk.parentNode.id, chk.checked);
                        }
                        //search for checkbox
                        chk = chk.nextSibling;
                    }
                }
            }
        }
        else if (isTypeCheckBox(element)) {
            CascadeEnableType(root.id, element.parentNode.id, checkedState);
        }
    }
}
function isSectorCheckBox(chk) {
    return (chk.previousSibling.id.lastIndexOf("_isSector") > -1);
}
function isTypeCheckBox(chk) {
    return (chk.previousSibling.id.lastIndexOf("_isType") > -1);
}
function isSubTypeCheckBox(chk) {
    return (chk.previousSibling.id.lastIndexOf("_isSubType") > -1);
}
function CascadeEnableSector(rootId, sectorId, enable) {
    var types = document.getElementsByName(rootId + '_isType');
    if (types != null && types.length > 0) {
        for (var i = 0; i < types.length; i++) {
            //check sector id
            if (types[i].parentNode.id.indexOf(sectorId) > -1) {
                var chk = types[i].nextSibling;
                while (!isNull(chk)) {
                    if (isCheckBox(chk)) {
                        chk.disabled = !enable;
                        if (!enable) {
                            chk.checked = false;
                            CascadeEnableType(rootId, chk.parentNode.id, enable);
                        }
                        break;
                    }
                    chk = chk.nextSibling;
                }
            }
        }
    }
}
function CascadeEnableType(rootId, typeId, enable) {
    var subtypes = document.getElementsByName(rootId + '_isSubType');
    if (subtypes != null && subtypes.length > 0) {
        for (var i = 0; i < subtypes.length; i++) {
            //check type id
            if (subtypes[i].parentNode.id.indexOf(typeId) > -1) {            
                var chk = subtypes[i].nextSibling;
                while (!isNull(chk)) {
                    if (isCheckBox(chk)) {
                        chk.disabled = !enable;
                        if (!enable) {
                            chk.checked = false;                         
                        }
                        break;
                    }
                    chk = chk.nextSibling;
                }
            }
        }
    }
}

function HideElementRememberSyle(el) {
    if (!isNull(el)){
        var hdnId = el.id + '__lastStyle';
        EnsureHiddenField(hdnId);
        var hdn = document.getElementById(hdnId);
        if (hdn != null) {
            if (el.style.display != 'none') {
                hdn.value = el.style.display;
            }
        }
        el.style.display = 'none';        
   }
}
function ShowElementRememberSyle(el) {
    if (!isNull(el)) {
        if (el.style.display == 'none') {
            var hdnId = el.id + '__lastStyle';
            var hdn = document.getElementById(hdnId);
            var lastStyle = "inline-block";
            if (hdn != null) {
                var lastStyle = hdn.value ? hdn.value : "inline-block";
            }
            el.style.display = lastStyle;
        }
    }
}

function FindExpandableElement(element) {
    if (isNull(element)) return null;
    //go up the tree
    while (!isNull(element)) {
        if (isListItem(element))
            break;
        element = element.parentNode;
    }
    if (!isNull(element)) {
        element = element.firstChild;
        //go down the tree
        while (!isNull(element)) {
            if (element.className == "AspNet-TreeView-Expand")
                return element;                
            element = element.nextSibling;
        }
    }
    
}

//return the first checkbox inside given element, going down the hierarchy, but ignoring nested UL's
function FindCheckBoxInsideElement(el) {
    var ret = null;
    if (el != null) {        
        var child = el.firstChild;
        while (!isNull(child)) {
            //alert("element id = " + child.id + "; class = " + child.className);
            if (isCheckBox(child)) {
                return child;
            }
            if (!isList(child)) {
                if (child.childNodes.length > 0) {
                    ret = FindCheckBoxInsideElement(child);
                    if (isCheckBox(ret))
                    { break; }
                }
            }
            child = child.nextSibling;            
        }
    }
    return ret;
}


//helper functions
function isDiv(obj) {
    if (isNull(obj))
        return false;
    return (obj.tagName == 'DIV');
}
function isSpan(obj) {
    if (isNull(obj))
        return false;
    return (obj.tagName == 'SPAN');
}

function isCheckBox(obj) {
    if (isNull(obj))
        return false;
    return (obj.tagName == 'INPUT' && obj.type == 'checkbox');
}

function isList(obj) {
    if (isNull(obj))
        return false;
    return (obj.tagName == 'UL');
}

function isListItem(obj) {
    if (isNull(obj))
        return false;
    return (obj.tagName == 'LI');
}

function isNull(obj) {
    return (obj == null);
}

function isEmpty(obj) {    
    return (obj == null || obj == "");
}

// TreeView End ********************************

//Geo Coordinates Functions *****************

/*
Apraksts: funkcija pārbauda ievādlauku aizpildījumu.
Ievādlaukam jābūt ievietotām <span> elementā.
Funkcija pārbauda visus ievādlaukus, kuri ir ievietoti citos <span> elementus ar tādu pašu identifikatoru.
Piem:
<span id="a" name="a"><input id="id1" type="text" value="123" /><span>
<span id="a" name="a"><input id="id2" type="text" value="345" /><span>
Autors: ISoft, Ilja Nevdahs
*/
function ValidateRequireAllOrNothing(val, args) {
    var el = document.getElementById(val.controltovalidate);
    if (el) {
        //get parent span
        elValue = el.value;
        var isMpty = isEmpty(elValue);
        var span = el.parentNode;
        while (!isNull(span)) {
            if (isSpan(span)) {
                break;
            }
            span = span.parentNode;
        }
        if (!isNull(span)) {
            var els = document.getElementsByName(span.id);
            if ((els != null) && (els.length > 0)) {
                for (var j = 0; j < els.length; j++) {
                    var container = els[j];
                    if (container != span) //ignore current element
                    {
                        var control = container.firstChild;
                        while (control != null) {
                            if (control.id != undefined) {
                                if ((control.tagName == 'INPUT') || (control.tagName == 'TEXTAREA')) {
                                    if (isEmpty(control.value) != isMpty) {
                                        //only some values are empty
                                        args.IsValid = false;
                                        return false;
                                    }
                                    break;
                                }
                            }
                            control = control.nextSibling;
                        }
                    }
                }
            }
        }
    }
    return true;
}

/*
Apraksts: funkcija pārbauda ievādlauka unikalitāti.
Ievādlaukam jābūt ievietotām <span> elementā.
Funkcija pārbauda visus ievādlaukus, kuri ir ievietoti citos <span> elementus ar tādu pašu identifikatoru.
Piem:
<span id="a" name="a"><input id="id1" type="text" value="123" /><span>
<span id="a" name="a"><input id="id2" type="text" value="345" /><span>
Autors: ISoft, Ilja Nevdahs
*/
function ValidateUniqueValues(val, args) {
    var el = document.getElementById(val.controltovalidate);
    var isRequired = false;
    var elValue = null;
    if (val.isRequired == "true") isRequired = true;
    
    if (el) {
        //get parent span
        elValue = el.value;
        var span = el.parentNode;
        while (!isNull(span)) {
            if (isSpan(span)) {
                break;
            }
            span = span.parentNode;
        }
        if (!isNull(span)) {
            var els = document.getElementsByName(span.id);            
            if ((els != null) && (els.length > 0)) {
                for (var j = 0; j < els.length; j++) {
                    var container = els[j];
                    if (container != span) //ignore current element
                    {
                        var control = container.firstChild;
                        while (control != null) {
                            if (control.id != undefined) {
                                if ((control.tagName == 'INPUT') || (control.tagName == 'TEXTAREA')) {
                                    if (control.value == el.value) {
                                        //value is not unique
                                        args.IsValid = false;
                                        return false;
                                    }
                                    break;
                                }
                            }
                            control = control.nextSibling;
                        }
                    }
                }
            }
        }
    }
    if (isRequired && isEmpty(elValue)) {
        return false;
    }
    else return true;
}
//Geo Coordinates Functions END *****************

//Navigation functions **********
function goBack(elm) {
    if (elm) {
        elm.style.visibility = 'hidden';
    }
    if (history && history.length && history.length > 0) {
        history.back();
    }
    else {
        //reload page
        window.location = window.location;
    }
}
//Navigation functions END **********

//Defining click() event for links in browser that do not have it
function defineClickEvent(a) {
    if (a && typeof (a.click) == 'undefined') {
        a.click = function() {
            var result = true;
            if (a.onclick) result = a.onclick();
            if (typeof (result) == 'undefined' || result) {
                eval(a.getAttribute('href'));
            }
        }
    }
}
//

//Adding handler to asp.net postback
addToPostBack = function(func) {
    var old__doPostBack = __doPostBack;
    if (typeof __doPostBack != 'function') {
        __doPostBack = func;
    } else {
        __doPostBack = function(t, a) {
            if (func(t, a)) old__doPostBack(t, a);
        }
    }
};

wrapPostBack = function(func1, func2) {
    var old__doPostBack = __doPostBack;
    if (typeof __doPostBack != 'function') {
        __doPostBack = function(t, a) {
            if (func1(t, a)) {
                func2(t, a);
            }
        }
    } else {
        __doPostBack = function(t, a) {
            if (func1(t, a)) {
                old__doPostBack(t, a);
                var isValid = true;
                try {
                    isValid = Page_IsValid;
                }
                catch (error) { }
                if (!isValid) {                    
                    func2(t, a);
                }
            }
        }
    }
};

