﻿

jQuery(document).ready(function () {
    
    $("#ctl00_search_searchString").select();  
    bindClick($("a[type='link']"));
    bindClick($("#ctl00_sans_injan"));
    $(".textbox-auto-clear").each(function () {
        var origValue = $(this).val(); // Store the original value
        $(this).focus(function () {
            if ($(this).val() == origValue) {
                $(this).val('');  
                $(this).removeClass("txt_placeholder");
               
            }
        });
        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val(origValue);
               $(this).addClass("txt_placeholder");
            }
        });
    });

    $('#password-clear').focus(function () {
        $('#password-clear').hide();
        $('#ctl00_pswrd').show();
        $('#ctl00_pswrd').focus();
    });
    $('#ctl00_pswrd').blur(function () {
        if ($('#ctl00_pswrd').val() == '') {
            $('#password-clear').show();
            $('#ctl00_pswrd').hide();
        }
    }); 
    setHeight();
});



jQuery(window).resize(function () { 
    setHeight();
});

function setHeight() {
    if (jQuery('#vertical').height() != null) { 
             var old_height = jQuery("#vertical").height();
                var new_height = (getWindowInnerHeight());
                var documentHeigth = jQuery("form").height();
             //   alert(old_height + " --> " + new_height + "  win:" + jQuery(window).height());
                if (old_height < new_height) {
                    jQuery('#vertical').height(new_height);     
                }
                else {
                    //jQuery('#vertical').height('auto');                   
                }
    }
}

function getWindowInnerHeight() {
    var myHeight = 0;
    var notCount = 182;
    myHeight = jQuery(window).height() - notCount;  
    return myHeight;
   
}

function bindClick(obj) {
    if ($("#ctl00_search_searchString").length != 0) {
        obj.bind("click", function () {         
            this.href = addSearchString(this.href);

        });
    }
}


function addSearchString(url) {  
    if ($("#ctl00_search_searchString").val().length != 0) {
        if (url.search(/.aspx?/) == 0) url = url + "?"
        url = url + "&q=" + encodeURI(parseString($("#ctl00_search_searchString").val()));
    }   
    return url;
}

function go(url) {

    window.location = addSearchString(url);
}

function bindGoClick(r) {
    $("a[type='el']").bind("click", function() {
        document.location = "default.aspx?r=" + r + "&cid=" + $(this).attr("id");
    })
}
function bindGoClickFP() {
    $("a[type='el']").bind("click", function() {
        document.location = "groups/default.aspx?id=" + $(this).attr("id");
    })
}

function appendAction(action) {
    if (window.location.search == "") {
        window.location = window.location + '?action=' + action;
    }
    else {
        var hash = window.location.hash;
        window.location = window.location.toString().replace(hash, '') + '&action=' + action + hash;
    }
}

function parseString(str) {
    return str.replace('#', '__')
}

function goDic(url) {
    try {
        window.location = encodeURI(url + "&!r=" + document.getElementById("ctl00_sans_resID").value)
    } catch (err) {
        window.location = url
    }
}

//priekš autorizācijas

var resTitle;
var xmlHttp;

function check() {
    var obj1 = document.getElementById("ctl00_checked");
    if (obj1 == null) {
        obj1 = document.getElementById("ctl00_ctl00_checked");
    }

    var obj2 = document.getElementById("ctl00_remember");
    if (obj2 == null) {
        obj2 = document.getElementById("ctl00_ctl00_remember");
    } 

    if (obj1.src.search(/unchecked.PNG/i) > 0) {
        obj1.src = obj1.src.replace("unchecked", "checked"); 
        obj2.value = true;
    }
    else {
        obj1.src = obj1.src.replace("checked", "unchecked"); 
        obj2.value = false;
    }
}

function remember() {
    document.getElementById("ctl00_augsa_remember").value = false;
}

var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1799085-1']); _gaq.push(['_trackPageview']); (function () { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
