function checkRegistrationForm() {
  var part = $('.part');
  var part_cb = $('.part_cb');
  var part_text = "You participate to following events:\n";
  var part_checked = false;
  for(var i = 0; i < part_cb.length; i++) {
    if(part_cb[i].checked) {
      part_text += part[i].innerHTML + "\n";
      part_checked = true;
    }
  }
  part_text += "\n(confirm with 'ok' or go back with 'cancel')";
  if(part_checked) {
    return confirm(part_text);
  } else {
    return true;
  }
}

function flash(name,width,w_unit,height,h_unit,loop,wmode) {
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + w_unit + '" height="' + height + h_unit + '" id="' + name + '" align="middle">\n');
  document.write('  <param name="allowScriptAccess" value="sameDomain" />\n');
  document.write('  <param name="movie" value="' + ROOT + 'flash/' + name + '" />\n');
  document.write('  <param name="loop" value="' + loop + '" />\n');
  document.write('  <param name="menu" value="false" />\n');
  document.write('  <param name="quality" value="high" />\n');
  document.write('  <param name="wmode" value="' + wmode + '" />\n');
  document.write('  <param name="scale" value="exactfit" />\n');
  document.write('  <param name="salign" value="rt" />\n');
  document.write('  <param name="bgcolor" value="#ffffff" />\n');
  document.write('  <embed src="' + ROOT + 'flash/' + name + '" loop="' + loop + '" menu="false" quality="high" wmode="' + wmode + '" scale="exactfit" salign="rt" bgcolor="#ffffff" width="' + width + w_unit + '" height="' + height + h_unit + '" name="' + name + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
  document.write('</object>\n');
}

function testimonial() {
//  if(navigator.appName == "Microsoft Internet Explorer") {
//    var string = ((document.body.clientWidth - 1000) / 2) + 1;
//    if(string < 0) {
//      string = 0;
//    }
//    document.write('<div class="testimonials" style="right:' + string + 'px">');
//    flash("testimonials.swf","600","px","400","px",true,"transparent");
//    document.write('</div>');
//  }
}

function module_over(module,color) {
  for(var i = 0; i < 5; i++) {
    if(module.childNodes[i].firstChild.nodeValue == "x" || module.childNodes[i].firstChild.nodeValue == "(x)") {
      module.childNodes[i].style.backgroundColor = color;
    }
  }
  module.childNodes[5].style.backgroundColor = color;
}

function modules_over(module,color,rows) {
  for(var i = 0; i < rows; i++) {
    module_over(module,color);
    if(module.nextSibling.nodeName != "#text") {
      module = module.nextSibling;
    } else {
      module = module.nextSibling.nextSibling;
    }
  }
}


function module_out(module) {
  for(var i = 0; i < 6; i++) {
    module.childNodes[i].style.backgroundColor = "#ffffff";
  }
}

function modules_out(module,rows) {
  for(var i = 0; i < rows; i++) {
    module_out(module);
    if(module.nextSibling.nodeName != "#text") {
      module = module.nextSibling;
    } else {
      module = module.nextSibling.nextSibling;
    }
  }
}

function popup(width,height,src,title) {
  height += 15;
  x = screen.availWidth / 2 - width / 2;
  y = screen.availHeight / 2 - height / 2;
  var popup= window.open("", "popup", "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y);
  html  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
  html += '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">\n';
  html += '<head>\n';
  html += '  <title>' + title + '</title>\n';
  html += '  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />\n';
  html += '  <meta http-equiv="content-language" content="en-US" />\n';
  html += '  <meta http-equiv="content-style-type" content="text/css" />\n';
  html += '  <meta http-equiv="content-script-type" content="text/javascript" />\n';
  html += '  <link rel="stylesheet" type="text/css" href="' + ROOT + 'css/popup.css" />\n';
  html += '</style>\n';
  html += '</head>\n';
  html += '<body>\n';
  html += '<center>\n';
  html += '<a href="javascript:self.close()"><img src="' + ROOT + 'img/' + src + '" alt="' + title + '" /></a><br />\n';
  html += 'Click in the picture to close\n';
  html += '</center>\n';
  html += '</body>\n';
  html += '</html>';
  popup.document.write(html);
}

var bbtags = new Array();
var prompt_tag = "Geben Sie einen Text ein:";
var prompt_link_text = "Geben Sie einen Linknamen ein (optional):";
var prompt_link_url = "Geben Sie die volle Adresse des Links ein:";
var prompt_img = "Bitte geben Sie die volle Bildadresse ein:";
var prompt_list_type = "Was für eine Liste möchten Sie? Geben Sie '1' ein für eine nummerierte Liste, 'a' für ein alphabetische, oder gar nichts für eine einfache Punktliste.";
var prompt_list_item = "Geben Sie einen Listenpunkt ein.\nGeben Sie nichts ein oder drücken 'Abbrechen' um die Liste fertigzustellen.";

var myAgent = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);
var is_ie = ((myAgent.indexOf("msie") != -1) && (myAgent.indexOf("opera") == -1));
var is_win = ((myAgent.indexOf("win") != -1) || (myAgent.indexOf("16bit") != -1));

function getArraySize(theArray) {
  for(i = 0; i < theArray.length; i++) {
    if((theArray[i] == "undefined") || (theArray[i] == "") || (theArray[i] == null)) {
      return i;
    }
  }
  return theArray.length;
}

function pushArray(theArray,value) {
  theArraySize = getArraySize(theArray);
  theArray[theArraySize] = value;
}

function popArray(theArray) {
  theArraySize = getArraySize(theArray);
  retVal = theArray[theArraySize - 1];
  delete theArray[theArraySize - 1];
  return retVal;
}

function addText(theTag,theClsTag,isSingle,theForm) {
  var isClose = false;
  var content = theForm.content;
  var set=false;
  var old=false;
  var selected = "";
  if(content.textLength >= 0) { // Mozilla, Firebird, Netscape
    if(theClsTag != "" && content.selectionStart != content.selectionEnd) {
      selected = content.value.substring(content.selectionStart,content.selectionEnd);
      str = theTag + selected + theClsTag;
      old = true;
      isClose = true;
    } else {
      str = theTag;
    }
    content.focus();
    start = content.selectionStart;
    end = content.textLength;
    endtext = content.value.substring(content.selectionEnd,end);
    starttext = content.value.substring(0,start);
    content.value = starttext + str + endtext;
    content.selectionStart = start;
    content.selectionEnd = start;
    content.selectionStart = content.selectionStart + str.length;
    if(old) {
      return false;
    }
    set = true;
    if(isSingle) {
      isClose = false;
    }
  }
  if((myVersion >= 4) && is_ie && is_win) {  // Internet Explorer
    if(content.isTextEdit) {
      content.focus();
      var sel = document.selection;
      var rng = sel.createRange();
      rng.colapse;
      if((sel.type == "Text" || sel.type == "None") && rng != null){
        if(theClsTag != "" && rng.text.length > 0) {
          theTag += rng.text + theClsTag;
        } else if(isSingle) {
          isClose = true;
        }
        rng.text = theTag;
      }
    } else {
      if(isSingle) {
        isClose = true;
      }
      if(!set) {
        content.value += theTag;
      }
    }
  } else {
    if(isSingle) {
      isClose = true;
    }
    if(!set) {
      content.value += theTag;
    }
  }
  content.focus();
  return isClose;
}

function getSelectedText(theForm) {
  var content = theForm.content;
  var selected = '';
  if(navigator.appName == "Netscape" && content.textLength >= 0 && content.selectionStart != content.selectionEnd ) {
    selected = content.value.substring(content.selectionStart,content.selectionEnd);
  } else if((myVersion >= 4) && is_ie && is_win ) {
    if(content.isTextEdit) {
      content.focus();
      var sel = document.selection;
      var rng = sel.createRange();
      rng.colapse;
      if((sel.type == "Text" || sel.type == "None") && rng != null) {
        if(rng.text.length > 0) {
          selected = rng.text;
        }
      }
    }
  }
  return selected;
}

function add_tag(theForm,theTag) {
  var donotinsert = false;
  for (i = 0; i < bbtags.length; i++) {
    if(bbtags[i] == theTag) {
      donotinsert = true;
    }
  }
  if(!donotinsert) {
    if(addText("<" + theTag + ">","</" + theTag + ">",true,theForm)) {
      pushArray(bbtags,theTag);
    }
  } else {
    var lastindex = 0;
    for(i = 0; i < bbtags.length; i++) {
      if(bbtags[i] == theTag) {
        lastindex = i;
      }
    }
    while(bbtags[lastindex]) {
      tagRemove = popArray(bbtags);
      addText("</" + tagRemove + ">","",false,theForm);
    }
  }
}

function add_link(theForm) {
  var selected = getSelectedText(theForm);
  var linkText = prompt(prompt_link_text,selected);
  var linkURL = prompt(prompt_link_url,"http://");
  if((linkURL != null) && (linkURL != "")) {
    if((linkText != null) && (linkText != "")) {
      var theText = "<a href=\"" + linkURL + "\" title=\"external link\" target=\"_blank\">" + linkText + "</a>";
    } else {
      var theText = "<a href=\"" + linkURL + "\" title=\"external link\" target=\"_blank\">[Link]</a>";
    }
    addText(theText,"",false,theForm);
  } else {
    add_link(theForm);
  }
}

function add_img(theForm) {
  var linkImg = prompt(prompt_img,"http://");
  if((linkImg != null) && (linkImg != "") ) {
    addText("\n<img src=\"" + linkImg + "\" alt=\"\">","",true,theForm);
  } else {
    add_img(theForm);
  }
}

function add_list(theForm) {
  listType = prompt(prompt_list_type,"");
  if((listType == "a") || (listType == "1")) {
    theList = "<ul class=\"list_" + listType + "\">";
    listEend = "</ul>";
  } else {
    theList = "<ul class=\"list_hyphen\">";
    listEend = "</ul>";
  }
  listEntry = "initial";
  while((listEntry != "") && (listEntry != null)) {
    listEntry = prompt(prompt_list_item,"");
    if((listEntry != "") && (listEntry != null)) {
      theList = theList + "<li>" + listEntry + "</li>";
    }
  }
  addText(theList + listEend,"",false,theForm);
}

var initXMLHttpRequest = function() {
	if(typeof XMLHttpRequest != 'undefined') {
		xmlHttpObject = new XMLHttpRequest();
		return;
	}
	try {
		xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e) {
		try {
			xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e) {
			xmlHttpObject = null;
		}
	}
	return;
}
