var imgWindow = "";

function openPopup(img, width, height) {
   if (img && width && height) {
      width = Math.min(width + 36, 640);
      height = Math.min(height + 30, 480);
      if (imgWindow.location && !imgWindow.closed)
         imgWindow.close();
      imgWindow = window.open(img, "imgWindow" + width + height, "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
      // imgWindow.focus();
   }
}

function randomString() {
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZ";
	var string_length = 1;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	document.randform.randomfield.value = randomstring;
}

var NumberOfWords = 216

var words = new BuildArray(NumberOfWords)

words[1] = "Bremsen"
words[2] = "Fallschirm"
words[3] = "Strassenschild"
words[4] = "Lächeln"
words[5] = "Wolke"
words[6] = "Zahn"
words[7] = "Abstimmung"
words[8] = "Eimer"
words[9] = "Sprung"
words[10] = "Zeitung"
words[11] = "Frosch"
words[12] = "Meer"
words[13] = "Eis"
words[14] = "Pferd"
words[15] = "Prüfung"
words[16] = "Roboter"
words[17] = "Fernsehen"
words[18] = "Tasse"
words[19] = "Gras"
words[20] = "Schlange"
words[21] = "Tanzsaal"
words[22] = "Schlüssel"
words[23] = "Bleistift"
words[24] = "Hof"
words[25] = "Buch"
words[26] = "Gefängnis"
words[27] = "Tanz"
words[28] = "Essen"
words[29] = "Geschäft"
words[30] = "Turm"
words[31] = "Blatt"
words[32] = "Bild"
words[33] = "Rose"
words[34] = "Kaktus"
words[35] = "Wüste"
words[36] = "Fisch"
words[37] = "Hai"
words[38] = "Brunnen"
words[39] = "Bombe"
words[40] = "Zunge"
words[41] = "Ohren"
words[42] = "Radio"
words[43] = "Messer"
words[44] = "Suppe"
words[45] = "Eiscreme"
words[46] = "Telefon"
words[47] = "Ruf"
words[48] = "Anwalt"
words[49] = "Brücke"
words[50] = "Taucher"
words[51] = "Stab"
words[52] = "Zucker"
words[53] = "Maus"
words[54] = "Floh"
words[55] = "König"
words[56] = "Teppich"
words[57] = "Trompete"
words[58] = "Lampe"
words[59] = "Kabel"
words[60] = "Hammer"
words[61] = "Tür"
words[62] = "Dach"
words[63] = "Treppen"
words[64] = "Garten"
words[65] = "Sessel"
words[66] = "Zirkus"
words[67] = "Clown"
words[68] = "Politiker"
words[69] = "Schreibtisch"
words[70] = "Bestechung"
words[71] = "Polizist"
words[72] = "Statue"
words[73] = "Schnecke"
words[74] = "Seife"
words[75] = "Bad"
words[76] = "Trophäe"
words[77] = "Rennen"
words[78] = "Energie"
words[79] = "Zehen"
words[80] = "Massage"
words[81] = "Füllfeder"
words[82] = "Fahne"
words[83] = "Sardine"
words[84] = "Sauce"
words[85] = "Brief"
words[86] = "Computer"
words[87] = "Begräbnis"
words[88] = "Parade"
words[89] = "Band"
words[90] = "Trommel"
words[91] = "Barriere"
words[92] = "Picnic"
words[93] = "Bier"
words[94] = "Bettler"
words[95] = "Krücke"
words[96] = "Bart"
words[97] = "Headline"
words[98] = "Sack"
words[99] = "Kartoffel"
words[100] = "Gänseblümchen"
words[101] = "Zigarette"
words[102] = "Lippenstift"
words[103] = "Nase"
words[104] = "Schuhe"
words[105] = "Kordel"
words[106] = "Gefangener"
words[107] = "Dusche"
words[108] = "Salz"
words[109] = "Insel"
words[110] = "Zahnstocher"
words[111] = "Bakterien"
words[112] = "Kopfschmerzen"
words[113] = "Ebene"
words[114] = "Fenster"
words[115] = "Tennis"
words[116] = "Ball"
words[117] = "Fell"
words[118] = "Rauch"
words[119] = "Brillen"
words[120] = "Whisky"
words[121] = "Jazz"
words[122] = "Oper"
words[123] = "Kerzenständer"
words[124] = "Geist"
words[125] = "Kirche"
words[126] = "Heiliger"
words[127] = "Tischler"
words[128] = "Säge"
words[129] = "Schraubenzieher"
words[130] = "Sand"
words[131] = "Vulkan"
words[132] = "Strand"
words[133] = "Bikini"
words[134] = "Baby"
words[135] = "Mond"
words[136] = "Wein"
words[137] = "Brot"
words[138] = "Haar"
words[139] = "Käse"
words[140] = "Katze"
words[141] = "Dinosaurier"
words[142] = "Kanguruh"
words[143] = "Feuer"
words[144] = "Wind"
words[145] = "Handy"
words[146] = "Werbung"
words[147] = "Bar"
words[148] = "Lenkrad"
words[149] = "Rollstuhl"
words[150] = "Spital"
words[151] = "Pille"
words[152] = "Hebamme"
words[153] = "Magazin"
words[154] = "Pin-Up"
words[155] = "Ratte"
words[156] = "Kaffee"
words[157] = "Rasse"
words[158] = "Leiter"
words[159] = "Krieg"
words[160] = "Curry"
words[161] = "Pilz"
words[162] = "Make-Up"
words[163] = "Zoo"
words[164] = "Ecke"
words[165] = "Würfel"
words[166] = "Glückspiel"
words[167] = "Weihnachten"
words[168] = "Ferien"
words[169] = "Kaugummi"
words[170] = "Glocke"
words[171] = "Tisch"
words[172] = "Kaffeehaus"
words[173] = "Fasching"
words[174] = "Kreuzfahrt"
words[175] = "Schokolade"
words[176] = "Hochzeit"
words[177] = "Schnarchen"
words[178] = "Vogel"
words[179] = "Golf"
words[180] = "Gabel"
words[181] = "Manieren"
words[182] = "Drohung"
words[183] = "Beleidigung"
words[184] = "U-Boot"
words[185] = "Strauss"
words[186] = "Giraffe"
words[187] = "Universität"
words[188] = "Apotheke"
words[189] = "Nacken"
words[190] = "Kuss"
words[191] = "Elefant"
words[192] = "Theater"
words[193] = "Soldat"
words[194] = "Hochhaus"
words[195] = "Zug"
words[196] = "Lift"
words[197] = "Trauben"
words[198] = "Magen"
words[199] = "Ausschlag"
words[200] = "Trapez"
words[201] = "Gesetz"
words[202] = "Scherz"
words[203] = "Gelse"
words[204] = "Feuerwerk"
words[205] = "Schatten"
words[206] = "Schmerz"
words[207] = "Lachen"
words[208] = "Sarg"
words[209] = "Schaum"
words[210] = "Welle"
words[211] = "Boxen"
words[212] = "Krone"
words[213] = "Schule"
words[214] = "Wörterbuch"
words[215] = "Bank"
words[216] = "Fächer"

function BuildArray(size){
    this.length = size
    for (var i = 1; i <= size; i++){
        this[i] = null}
    return this
}

function PickRandomWord(frm) {
    // Generate a random number between 1 and NumberOfWords
    var rnd = Math.ceil(Math.random() * NumberOfWords)

    // Display the word inside the text box
    frm.WordBox.value = words[rnd]
}
Antville = {};
Antville.prefix = "Antville_";

Antville.pixel = new Image();
Antville.pixel.src = "/static/pixel.gif";

Antville.colors = {"aliceblue": true, "antiquewhite": true, "aqua": true,  "aquamarine": true, "azure": true, "beige": true, "bisque": true,  "black": true, "blanchedalmond": true, "blue": true, "blueviolet": true,  "brown": true, "burlywood": true, "cadetblue": true, "chartreuse": true,  "chocolate": true, "coral": true, "cornflowerblue": true,  "cornsilk": true, "crimson": true, "cyan": true, "darkblue": true,  "darkcyan": true, "darkgoldenrod": true, "darkgray": true,  "darkgreen": true, "darkkhaki": true, "darkmagenta": true,  "darkolivegreen": true, "darkorange": true, "darkorchid": true,  "darkred": true, "darksalmon": true, "darkseagreen": true,  "darkslateblue": true, "darkslategray": true, "darkturquoise": true,  "darkviolet": true, "deeppink": true, "deepskyblue": true, "dimgray": true,  "dodgerblue": true, "firebrick": true, "floralwhite": true, "forestgreen": true, "fuchsia": true, "gainsboro": true, "ghostwhite": true, "gold": true, "goldenrod": true, "gray": true, "green": true, "greenyellow": true, "honeydew": true, "hotpink": true, "indianred ": true, "indigo ": true, "ivory": true, "khaki": true, "lavender": true, "lavenderblush": true, "lawngreen": true, "lemonchiffon": true, "lightblue": true, "lightcoral": true, "lightcyan": true, "lightgoldenrodyellow": true, "lightgrey": true, "lightgreen": true, "lightpink": true, "lightsalmon": true, "lightseagreen": true, "lightskyblue": true, "lightslateblue": true, "lightslategray": true, "lightsteelblue": true, "lightyellow": true, "lime": true, "limegreen": true, "linen": true, "magenta": true, "maroon": true, "mediumaquamarine": true, "mediumblue": true, "mediumorchid": true, "mediumpurple": true, "mediumseagreen": true, "mediumslateblue": true, "mediumspringgreen": true, "mediumturquoise": true, "mediumvioletred": true, "midnightblue": true, "mintcream": true, "mistyrose": true, "moccasin": true, "navajowhite": true, "navy": true, "oldlace": true, "olive": true, "olivedrab": true, "orange": true, "orangered": true, "orchid": true, "palegoldenrod": true, "palegreen": true, "paleturquoise": true, "palevioletred": true, "papayawhip": true, "peachpuff": true, "peru": true, "pink": true, "plum": true, "powderblue": true, "purple": true, "red": true, "rosybrown": true, "royalblue": true, "saddlebrown": true, "salmon": true, "sandybrown": true, "seagreen": true, "seashell": true, "sienna": true, "silver": true, "skyblue": true, "slateblue": true, "slategray": true, "snow": true, "springgreen": true, "steelblue": true, "tan": true, "teal": true, "thistle": true, "tomato": true, "turquoise": true, "violet": true, "violetred": true, "wheat": true, "white": true, "whitesmoke": true, "yellow": true, "yellowgreen": true};

Antville.ColorPickerFactory = function() {
   this.prefix = Antville.prefix + "ColorPicker_";
   this.valuePrefix = Antville.prefix + "ColorValue_";

   this.open = function(name, text, skin) {
      if (skin == "colorpickerExt")
         var cpWindow = window.open("http://www.rahmenhandlung.at/denkbar/colorpicker?name=" + name + "&text=" + text + "&skin=" + skin, Antville.ColorPicker.prefix, "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=480,height=360");
      else
         var cpWindow = window.open("http://www.rahmenhandlung.at/denkbar/colorpicker?name=" + name + "&text=" + text + "&skin=" + skin, Antville.ColorPicker.prefix, "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=350,height=320");
   }

   this.set = function(name, color) {
      var prefix = Antville.ColorPicker.prefix;
      var valuePrefix = Antville.ColorPicker.valuePrefix;
      var color = Antville.parseColor(color);
      if (color)
         document.getElementById(prefix + name).style.backgroundColor = color;
      else
         color = Antville.parseColor(document.getElementById(prefix + name).style.backgroundColor);
      if (color.indexOf("#") == 0)
         color = color.substr(1,color.length-1);
      document.getElementById(valuePrefix + name).value = color;
      return;
   }

   return this;
}

Antville.ColorPicker = new Antville.ColorPickerFactory();

Antville.encode = function(str) {
   var chars = ["&", "<", ">", '"'];
   for (var i in chars) {
      var c = chars[i];
      var re = new RegExp(c, "g");
      str = str.replace(re, "&#" + c.charCodeAt() + ";");
   }
   return str;
}

Antville.decode = function(str) {
   return str.replace(/&amp;/g, "&");
}

Antville.parseColor = function(color) {
   var c = color.toLowerCase();
   if (Antville.colors[c])
      return c;
   var rgb = new RegExp("rgb ?\\( ?([0-9^,]*), ?([0-9^,]*), ?([0-9^ \\)]*) ?\\)");
   var result = color.match(rgb);
   if (result) {
      var R = parseInt(result[1]).toString(16);
      var G = parseInt(result[2]).toString(16);
      var B = parseInt(result[3]).toString(16);
      if (R.length == 1) R="0"+R;
      if (G.length == 1) G="0"+G;
      if (B.length == 1) B="0"+B;
      return "#"+R+G+B;
   }
   if (c.indexOf("#") == 0)
      c = c.substr(1,c.length-1);
   if (c.length == 6) {
      var nonhex = new RegExp("[^0-9,a-f]");
      nonhex.ignoreCase = true;
      var found = c.match(nonhex);
      if (!found)
         return "#" + c;
   }
   return;
}

Antville.Referrer = function(url, text, count) {
   this.url = url;
   this.text = text;
   this.count = count;
   this.compose = function(key, prefix) {
      var query = new Antville.Query(this.url);
      if (query[key]) {
         if (prefix == null)
            prefix = "";
         return prefix + Antville.encode(query[key]);
      }
      return this.text;
   }
   return this;
}

Antville.Query = function(str) {
   if (str == undefined)
      var str = location.search.substring(1);
   else if (str.indexOf("?") > -1)
      var str = str.split("?")[1];
   if (str == "")
      return this;
   var parts = Antville.decode(unescape(str)).split("&");
   for (var i in parts) {
      var pair = parts[i].split("=");
      var key = pair[0];
      if (key) {
         key = key.replace(/\+/g, " ");
         var value = pair[1];
         if (value)
            value = value.replace(/\+/g, " ");
         this[key] = value;
      }
   }
   return this;
}

Antville.Filter = function(def, key) {
   this.key = key;
   if (def == null)
      this.items = [];
   else if (def instanceof Array)
      this.items = def;
   else
      this.items = def.replace(/\r/g, "\n").split("\n");
   this.test = function(str) {
      if (!str)
         return false;
      for (var n in this.items) {
         var re = new RegExp(this.items[n], "i");
         if (re.test(str))
            return true;
      }
      return false;
   }
   return this;
}
