
function GoByRadio(where) {
    for (var i=0; i<4; i++) {
        if (where.GoTo[i].checked == true)
            location.href = where.GoTo[i].value;
    }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
 

// CALENDAR


function startCalendar(month, year) {
		new Ajax.Updater('calendarInternal', '../calendar/rpc.php', {method: 'post', postBody: 'action=startCalendar&month='+month+'&year='+year+''});
}

function highlightCalendarCell(element) {
		$(element).style.border = '1px solid #575757';
}

function resetCalendarCell(element) {
		$(element).style.border = '1px solid #333';
}
	
function showEventForm(day) {
		$('evtDay').value = day;
		$('evtMonth').value = $F('ccMonth');
		$('evtYear').value = $F('ccYear');
		
		displayEvents(day, $F('ccMonth'), $F('ccYear'));
		
		if(Element.visible('addEventForm')) {
			// do nothing.
		} else {
			Element.show('addEventForm');
		}
}
	
function displayEvents(day, month, year) {
		new Ajax.Updater('eventList', '../calendar/rpc.php', {method: 'post', postBody: 'action=listEvents&&d='+day+'&m='+month+'&y='+year+''});
		if(Element.visible('eventList')) {
			// do nothing, its already visble.
		} else {
			setTimeout("Element.show('eventList')", 300);
		}
}
	
function addEvent(day, month, year, body) {
		if(day && month && year && body) {
			// alert('Add Event\nDay: '+day+'\nMonth: '+month+'\nYear: '+year+'\nBody: '+body);
			new Ajax.Request('rpc.php', {method: 'post', postBody: 'action=addEvent&d='+day+'&m='+month+'&y='+year+'&body='+body+'', onSuccess: highlightEvent(day)});
			$('evtBody').value = '';
		} else {
			alert('There was an unexpected script error.\nPlease ensure that you have not altered parts of it.');
}
		
// highlightEvent(day);
} 
	
function highlightEvent(day) {
		Element.hide('addEventForm');
		$('calendarDay_'+day+'').style.background = '#<?= $eventColor ?>';
}
	

	
function deleteEvent(eid) {
		confirmation = confirm('Are you sure you wish to delete this event?\n\nOnce the event is deleted, it is gone forever!');
		if(confirmation == true) {
			new Ajax.Request('rpc.php', {method: 'post', postBody: 'action=deleteEvent&eid='+eid+'', onSuccess: Element.hide('event_'+eid+'')});
		} else {
			// Do not delete it!.
		}
}


function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function SwapTo(id,txt){
	 var zxcobj=document.getElementById(id);
	 if (!zxcobj.oldtxt){ zxcobj.oldtxt=zxcobj.innerHTML; }
	 zxcobj.innerHTML=txt||zxcobj.oldtxt;
}


// NEWSLETTER INPUT CHECK
 
var myVar = null;

function AJAX_CHECK_INIT(){
	if (window.XMLHttpRequest) {
	  myVar = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	  try {
		myVar = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (ex) {
		try {
		  myVar = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (ex) {
		}
	  }
	}
}

function myVarStatus() {
  if (myVar.readyState == 4) {
    var ToRespond = document.getElementById("myVarInit");
    ToRespond .innerHTML = myVar.responseText;
  }
}

function myVarInit() {

  var ajaxemail 	= document.getElementById("email").value; 
  var ToRespond  	= document.getElementById("myVarInit");
  
  ToRespond .innerHTML = '<img src="/_images.fix/newsletter_loading.gif" alt="Bitte warten" />'; // Lade Grafik
	// myVar.open("GET", "/news/newslettercheck.php?uname=" + uname+"&emailcheck="+ajaxemail+""); 
	myVar.open("GET", "/news/newslettercheck.php?emailcheck="+ajaxemail+"");
	myVar.onreadystatechange = myVarStatus;
	myVar.send(null);
}
var ToRespond = AJAX_CHECK_INIT();


//EOF

// POLL FUNCS

function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML="Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	ahah(name,div);
	return false;
}


var http_request = false;


function makeRequest(url, parameters) 
{
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
}

function alertContents()
{
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
}
   
function get(obj)
{
      
      var getstr = "?";
      
      for (i=0; i<obj.childNodes.length; i++)
      {
		//INPUT-TYPES
		if (obj.childNodes[i].tagName == "INPUT")
		{
			// TYPE=TEXT
			if (obj.childNodes[i].type == "text")
			{
			getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
			}
			
			// TYPE=HIDDEN
			if (obj.childNodes[i].type == "hidden")
			{
			getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
			}
			
			// TYPE=CHECKBOX
			if (obj.childNodes[i].type == "checkbox") 
			{
				if (obj.childNodes[i].checked)
				{
				getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				} 
				else 
				{
				getstr += obj.childNodes[i].name + "=&";
				}
			}
			
			// TYPE=RADIO
			if (obj.childNodes[i].type == "radio")
			{
				if (obj.childNodes[i].checked)
				{
				getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				}
			}
			
		}  // END INPUT-TYPES
         
		 if (obj.childNodes[i].tagName == "SELECT")
		 {
		 var sel = obj.childNodes[i];
		 getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		 }
         
      } // END FOR
      
      makeRequest('../umfrage/umfrage.php', getstr);
}

//EOF

