﻿

var prm;
var timeoutId;
var dLoading;

function SelectText(sender) {
    // var content = eval("document.myform.field");
    sender.focus();
    sender.select();
}



window.onload = function initPageSyska() {

    // setup page stuff, as this will only run one time on the client, and not on async
    prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(initializeRequest);
    prm.add_beginRequest(beginRequest);
    prm.add_endRequest(endRequest);
    prm.add_pageLoaded(pageLoaded);

    // var form = Sys.WebForms.PageRequestManager.getInstance()._form;
    //form._initialAction = form.action = window.location.href;

    setLoadingDivPlacement();
}

// Here we add some event handlers for three critical phases of the asynchronous postback life-cycle
function pageLoaded(sender, args)
{
    // javascript to make sure client side crap runs after an async callback
}

function EnableInput(x, y, z) {
    $get(x).disabled = false;
    $get(y).disabled = false;
    $get(z).disabled = false;
}

function DisableInput(x, y, z) {
    $get(x).disabled = true;
    $get(y).disabled = true;
    $get(z).disabled = true;
}

function ToggleWholeMap(x) {
    var e = $get(x);
    if (e.disabled) {
        e.disabled = false;
    }
    else {
        e.disabled = true;
    }
    
    
//    var ele = $get(x);
//    ToggleDisabled(ele);

//    ele = $get(y);
//    ToggleDisabled(ele);

//    ele = $get(r);
//    ToggleDisabled(ele);
}

function ToggleDisabled(ele) {
    ele.disabled = !ele.disabled;
}

function SetRadioButtons(name, value) {

    var table = document.getElementById(name);

    if (table == null) {
        return;
    }
    
    var radios = table.getElementsByTagName("input");
    if (radios == null)
        return;
    
    var str = '';
    for (var i = 0; i < radios.length; i++) {
        if (radios[i].type == 'checkbox')
            radios[i].checked = value;
    }
}

// This is the first event fired by the PageRequestManager when an asynchronous postback begins
function initializeRequest(sender,args) {
	// If an async postback is already in progress its best to cancel 
	// any new requests until the current postback completes
	if (prm.get_isInAsyncPostBack())
		args.set_cancel(true);
}

function setLoadingDivPlacement()
{
    dLoading = $get('loading');
	var dMain = $get('main');
	var mainBounds = Sys.UI.DomElement.getBounds(dMain);
	Sys.UI.DomElement.setLocation(dLoading, (mainBounds.width / 2) - 126, 10);
}

// This is the second event fired by the prm
// This is where the UpdateProgress control does it work to display your progress control
// By writing your own javascript here you will gain superior control over when your progress indicator is shown
function beginRequest(sender,args) {
	timeoutId = setTimeout('display()', 1);
}

function display()
{
    Sys.UI.DomElement.removeCssClass(dLoading,'hidden');
}

// This event is fired after the async postback completes
// This is where the UpdateProgress control does its work to hide your progress control
function endRequest(sender,args) {		
    clearTimeout(timeoutId);
    Sys.UI.DomElement.addCssClass(dLoading,'hidden');
    
    thumbnailviewer.init();
    standardistaTableSortingInit();
}

function OnSelect(obj, text)
{
    if(obj.value == text)
        obj.value = '';
}

function OnBlur(obj, text)
{
    if(obj.value == '')
        obj.value = text;
}

//function Over(obj)
//{
//    Sys.UI.DomElement.addCssClass(obj, "ho-light");
//}

//function Out(obj)
//{
//    Sys.UI.DomElement.removeCssClass(obj, "ho-light");
//}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    
    // top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight - 2 + 'px';
        top.style.width = bottom.offsetWidth - 2 + 'px';
    }
}
