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

function add_word(arg){
    var str = document.getElementById("formdatum_qtext");
    str.value += " " + arg;
} 

function add_andword_to_text(arg){
    var str = document.getElementById("formdatum_qtext");
    str.value += " ::+" + arg;
} 

function add_notword_to_text(arg){
    var str = document.getElementById("formdatum_qtext");
    str.value += " ::-" + arg;
} 

function add_patent(arg){
    var str = document.getElementById("formdatum_publication_number");
    str.value += " " + arg;
    var a = str.value.split(/\s+/);
    str.value = a.join(' ');
} 

function add_andword_to_patent(arg){
    var str = document.getElementById("formdatum_publication_number");
    str.value += " ::+" + arg;
    var a = str.value.split(/\s+/);
    str.value = a.join(' ');
} 

function add_notword_to_patent(arg){
    var str = document.getElementById("formdatum_publication_number");
    str.value += " ::-" + arg;
    var a = str.value.split(/\s+/);
    str.value = a.join(' ');
} 


function reset_word() {
    var str = document.getElementById("formdatum_qtext");
    str.value = "";
} 

function reset_patent(arg){
    var str = document.getElementById("formdatum_publication_number");
    str.value = " ";
} 

function show_all(n, use_makemap){
    show_all_ex(n, use_makemap);
}

function show_all_ex(n, use_makemap, options){
    var i;
    for (i = 0; i < n; i++) {
        if(typeof options == 'undefined') {
            new Effect.Appear('item' + i);
        } else if(options == false) {
            Element.show('item' + i);
        } else {
            new Effect.Appear('item' + i, options);
        }
    }
    if(typeof options == 'undefined') {
        new Effect.SwitchOff('showallbutton');
        if(use_makemap) {
            new Effect.Appear('makemap');
        }
    } else if(options == false) {
        Element.hide('showallbutton');
        if(use_makemap) {
          Element.show('makemap');
        }
    } else {
        new Effect.SwitchOff('showallbutton', options);
        if(use_makemap) {
          new Effect.Appear('makemap', options);
        }
    }
}

function show_item_only(arg, n){
    show_item_only_ex(arg, n);
}

function show_item_only_ex(arg, n, options){
    var a, i, j, fade;

    if(typeof options == 'undefined') {
        new Effect.Appear('showallbutton');
        new Effect.Fade('makemap');
    } else if(options == false) {
        Element.show('showallbutton');
        Element.hide('makemap');
    } else {
        new Effect.Appear('showallbutton', options);
        new Effect.Fade('makemap', options);
    }

    a = arg.split(/\|/);
    for (i = 0; i < n; i++) {
        fade = true;
        for (j = 0; j < a.length; j++) {
            if (a[j].length < 1) continue;
            if (i == a[j]) {
                fade = false;
                break;
            }
        }
        if (fade) {
            if(typeof options == 'undefined') {
                new Effect.Fade('item' + i);
            } else if(options == false) {
                Element.hide('item' + i);
            } else {
                new Effect.Fade('item' + i, options);
            }
        } else {
            if(typeof options == 'undefined') {
                new Effect.Appear('item' + i);
            } else if(options == false) {
                Element.show('item' + i);
            } else {
                new Effect.Appear('item' + i, options);
            }
        }
    }
} 

function set_cookie(name,value) {
    var exp=new Date();
    exp.setTime(exp.getTime()+1000*3600*24*365);
    document.cookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString();
}

function get_cookie(name) {
  var results = document.cookie.match(name + '=(.*?)(;|$)');
  return (results) ? unescape(results[1]) : null;
}
