function opencomments (id) {
 var div = document.getElementById('commentspopup');
 YAHOO.riot.container.popup.show();
 var handleSuccess = function(o){
  if(o.responseText !== undefined){
   div.innerHTML = o.responseText;
  }
 };
 var callback = {
   success:handleSuccess,
   failure:handleFailure
 };
 maske = 'comments';
 var postData = "ajax_"+maske+"&tmp_id="+id;
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

var handleFailure = function(o){
	if(o.responseText !== undefined){
		//div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
		//div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		//div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
	}
};


// Nicht in Benutzung


// liest die Mauskoordinaten aus und setzt sie im Hauptfenster als var...
var mcwx = 0;
var mcwy = 0;
var ie = (document.all) ? true : false;
if(!ie) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=koordinaten;

function koordinaten(e) {
 if(!e) e = window.event;
 if (ie) {
  mcwx = window.event.clientX + document.body.scrollLeft;
  mcwy = window.event.clientY + document.body.scrollTop;
 }
 else {
  mcwx = e.pageX;
  mcwy = e.pageY;
 }
 if(mcwx < 0) {mcwx = 0;}
 if(mcwy < 0) {mcwy = 0;} 
 return true;
}

function openlinkinfo (id) {
 var div = document.getElementById('wa_'+id);

 var handleSuccess = function(o){
  if(o.responseText !== undefined){
   div.innerHTML = o.responseText;
  }
 };
 var callback = {
   success:handleSuccess,
   failure:handleFailure
 };
 maske = 'linkinfo';
 var postData = "ajax_"+maske+"&tmp_linkid="+id;
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function linkvote (id,vote) {
 var div = document.getElementById('votepopout');
 YAHOO.votepopup.overlay.show();
 var handleSuccess = function(o){
  if(o.responseText !== undefined){
   div.innerHTML = o.responseText;
   setTimeout('YAHOO.votepopup.overlay.hide();', 3000);
  }
 };
 var callback = {
   success:handleSuccess,
   failure:handleFailure
 };
 maske = 'linkinfo';
 var postData = "ajax_"+maske+"&tmp_linkid="+id+"&tmp_linkvote="+vote;
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}


// ######################


function div_leeren(ldiv){
 var div = document.getElementById(ldiv);
 div.innerHTML = '';
}


function mget(maske,formdata,div){
 var div = document.getElementById(div);
 
 var handleSuccess = function(o){
  if(o.responseText !== undefined){
   div.innerHTML = o.responseText;
  }
 };
 var handleFailure = function(o){
	 if(o.responseText !== undefined){
	  div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
	  div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
	  div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
	 }
 };
 var callback = {
   success:handleSuccess,
   failure:handleFailure,
   argument:['foo','bar']
 };
 if (formdata) {
  formdata = serializeForm(formdata);
 }
 var postData = "ajax_"+maske+"&"+formdata;
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
 //setload(div);
}


function nget(maske, modulname, formdata){
 if (formdata) {
  formdata = serializeForm(formdata);
  //alert("Formdata:"+formdata);
 }
 var postData = "najax_"+maske+"&najaxmodul_"+modulname+"&"+formdata;
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function makeRequest(data){
 data = serializeForm(data);
 var postData = "btn_test&"+data;
 // alert("Bitte Ihren Wohnort eingeben!"+postData);
 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}





/**
 * Serialize a form into a format which can be sent as a GET string or a POST 
 * content.It correctly ignores disabled fields, maintains order of the fields 
 * as in the elements[] array. The 'file' input type is not supported, as 
 * its content is not available to javascript. This method is used internally
 * by the submit class method.
 */

function do_submit(form,action,maske,div) {
  // alert("In do_submit:"+form);
  form.action.name  = ("btn_"+action);
  form.action.value = action;
  mget(maske,form,div);
  return false;
  //form.submit();
}

function serializeForm(theform) {
	var els = theform.elements;
	var len = els.length;
	var queryString = "";
	this.addField = 
		function(name,value) { 
			if (queryString.length>0) { 
				queryString += "&";
			}
			queryString += encodeURIComponent(name) + "=" + encodeURIComponent(value);
		};
	for (var i=0; i<len; i++) {
		var el = els[i];
		if (!el.disabled) {
			switch(el.type) {
				case 'text': case 'password': case 'hidden': case 'textarea': 
					this.addField(el.name,el.value);
					break;
				case 'submit':
						this.addField(el.name,el.value);
					break;	
    case 'select-one':
					if (el.selectedIndex>=0) {
						this.addField(el.name,el.options[el.selectedIndex].value);
					}
					break;
				case 'select-multiple':
					for (var j=0; j<el.options.length; j++) {
						if (el.options[j].selected) {
							this.addField(el.name,el.options[j].value);
						}
					}
					break;
				case 'checkbox': case 'radio':
					if (el.checked) {
						this.addField(el.name,el.value);
					}
					break;
			}
		}
	}
	return queryString;
};




//// tools
function set_all_rights() {
 var konfiggid = document.getElementById("konfig_gid").value;
 document.getElementById("menugid").value = konfiggid;
 document.getElementById("topmenugid").value = konfiggid;
 document.getElementById("tabmenugid").value = konfiggid;
 document.getElementById("rueckschaugid").value = konfiggid;
 document.getElementById("editorgid").value = konfiggid;
}


function setload(div) {
 div.innerHTML = '<div align="center"><br /><br /><br /><img src="/base/cw/img/layout/load.gif" border="1"></div>'; 
}

function lb_progress(value)	{
	oLadebalken = document.getElementById("ladebalken").firstChild;
 if(value < 51)
  oLadebalken.style.background = 'rgb(255, ' + Math.floor(value / 50 * 255) + ', 0)';
 else
  oLadebalken.style.background = 'rgb(' + Math.floor(255 - ((value - 50) / 50 * 255)) + ', 255, 0)';

  //oLadebalken.firstChild.firstChild.nodeValue = 
  oLadebalken.style.width = value + "%";
}




// Colorpicker


	var hue;
	var picker;
	var gLogger = {debug: function(){}};
	var dd;
 var ret_colorinput;
  
	function update_return_input() {
	 document.getElementById(ret_colorinput).value =	'#'+document.getElementById('hexval').value;	 
 }
	
 function rgb_init(return_input_id) {
  ret_colorinput = return_input_id;
		hue = YAHOO.widget.Slider.getVertSlider("hueBg", "hueThumb", 0, 180);
		hue.onChange = function(newVal) { hueUpdate(newVal); };

		picker = YAHOO.widget.Slider.getSliderRegion("pickerDiv", "selector", 
				0, 180, 0, 180);
		picker.onChange = function(newX, newY) { pickerUpdate(newX, newY); };

		hueUpdate();

		dd = new YAHOO.util.DD("ddPicker");
		dd.setHandleElId("pickerHandle");
		dd.endDrag = function(e) {
			// picker.thumb.resetConstraints();
			// hue.thumb.resetConstraints(); 
        };
	}

	// window.onload = init;

	function pickerUpdate(newX, newY) {
		swatchUpdate();
	}

	function hueUpdate(newVal) {

		var h = (180 - hue.getValue()) / 180;
		if (h == 1) { h = 0; }

		gLogger.debug("hue " + hue.getValue());

		var a = YAHOO.util.Color.hsv2rgb( h, 1, 1);

		document.getElementById("pickerDiv").style.backgroundColor = 
			"rgb(" + a[0] + ", " + a[1] + ", " + a[2] + ")";

		swatchUpdate();
	}

	function swatchUpdate() {
		var h = (180 - hue.getValue());
		if (h == 180) { h = 0; }
		document.getElementById("hval").value = (h*2);

		h = h / 180;
		gLogger.debug("h " + hue.getValue());

		var s = picker.getXValue() / 180;
		document.getElementById("sval").value = Math.round(s * 100);

		gLogger.debug("s " + s);

		var v = (180 - picker.getYValue()) / 180;
		document.getElementById("vval").value = Math.round(v * 100);

		gLogger.debug("v " + v);

		var a = YAHOO.util.Color.hsv2rgb( h, s, v );

		document.getElementById("swatch").style.backgroundColor = 
			"rgb(" + a[0] + ", " + a[1] + ", " + a[2] + ")";

		document.getElementById("rval").value = a[0];
		document.getElementById("gval").value = a[1];
		document.getElementById("bval").value = a[2];
		document.getElementById("hexval").value =	YAHOO.util.Color.rgb2hex(a[0], a[1], a[2]);
 }

// Ende Colorpicker
