// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var searchProgressIntervall = false;
var isSearchInProgress = false;

function SearchProgressTimer() {
    $('search_progress_time').time = $('search_progress_time').time + 1;
    $('search_progress_time').innerHTML = $('search_progress_time').time;
}
	
function ResetSearchProgressTimer() {
    $('search_progress_time').time = 0;
    $('search_progress_time').innerHTML = 0;
}

function StartSearchProgressTimer() {
    isSearchInProgress = true;
    if(!searchProgressIntervall) {
        searchProgressIntervall = setInterval('SearchProgressTimer();',1000);
    }
}

function StopSearchProgressTimer() {
    isSearchInProgress = false;
    if(searchProgressIntervall) {
        clearInterval(searchProgressIntervall);
        searchProgressIntervall = false;
    }
}

function pushBackClassName(element, className) {
    if(Object.isString(element.className)) {
        element.className = element.className + ' ' + className;
    }
    else
    {
        element.className = className;
    }
}

function deleteClassName(element, className) {
    if(Object.isString(element.className)) {
        element.className = element.className.replace(' ' + className, '');
    }
}

function display_none_by_name(name) {
    elements = document.getElementsByName(name);
    for(var i=0; i<elements.length; ++i) {
        elements[i].style.display = "none";
    }
}

function display_block_by_name(name) {
    elements = document.getElementsByName(name);
    for(var i=0; i<elements.length; ++i) {
        elements[i].style.display = "block";
    }
}
         
function disable_expert_options_blat_oneoff() {
    if($('expert_options_blat_tilesize').selectedIndex == 0) {
        $('expert_options_blat_oneoff').selectedIndex = 0;
        $('expert_options_blat_oneoff').disabled = true;
        $('warn_expert_options_blat_oneoff').style.display = "inline";
    } else {
        $('expert_options_blat_oneoff').disabled = false;
        $('warn_expert_options_blat_oneoff').style.display = "none";
    }
}

function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
        deleteClassName(thisfield, "defaulttext");
    }
}

function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
        pushBackClassName(thisfield, "defaulttext");
    }
}

function fieldemtpy(field, defaulttext, alertdiv, alerttext) {
    var empty;
    if (field.value == defaulttext) {
        empty = true;
        alertdiv.innerHTML = alerttext;
    }
    else {
        empty = false;
        alertdiv.innerHTML = "";
    }
    return empty;
}


function getPageSizeWithScroll() {
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
    return arrayPageSizeWithScroll;
}

