// ajax stuff
function header_hide(getstr) {
	dojo.io.bind({
		url: "?s=2nd_ajax_call&bv="+getstr,
	  load: function(type, data, evt) { 	
	  }, 
	  mimetype: "text/plain"
	});	
}


//content einsetzen
function setNewsDetailContent(elementID, uri, getVars) {

 $.ajax({
   
  type: "GET",
  url: uri,
  data: getVars,
	cache: false,

  beforeSend: function(){
    // Handle the beforeSend event
	  $("#newsdetail_content").fadeOut(1500);
  },
  
  success: function(data){
    // Handle the complete event
	document.getElementById(elementID).innerHTML = data;
    $("#newsdetail_content").fadeIn(2000);
    var dump = sIFR();
	$("#newsdetail_content").find('a.twitter-share-button').each(function(i) 
	{
		jQuery('head').append('<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>');
		var loadedTweetButton = new twttr.TweetButton($(this).get(0));
		loadedTweetButton.render();
	});
  }

 });
	
}

// content ersetzen
function setGetContent(elementID, uri, getVars) {

 $.ajax({
   
  type: "GET",
  url: uri,
  data: getVars,
	cache: false,

  beforeSend: function(){
    // Handle the beforeSend event
	  $("#"+elementID).fadeOut(1500);
  },
  
  success: function(data){
    // Handle the complete event
	$("#"+elementID).replaceWith(data);
    $("#"+elementID).fadeIn(2000);
    var dump = sIFR();
  }

 });
	
}

// div element - html content befüllen/ersetzen
function setGetHTMLContent(elementID, uri, getVars, singleImport) {

	if(singleImport == 'undefined') singleImport = false;
 $.ajax({
   
  type: "GET",
  url: uri,
  data: getVars,
	cache: false,

  beforeSend: function(){
    // Handle the beforeSend event
	if(document.getElementById(elementID).innerHTML.length > 0 &&  singleImport == true) return false;
  },
  
  success: function(data){
    // Handle the complete event
	document.getElementById(elementID).innerHTML = data;
    var dump = sIFR();
  }

 });
	
}

// div elemente - html content befüllen/ersetzen - rückgabe elemente + content per json
function setGetJSONHTMLContent(uri, getVars) {

 $.ajax({
   
  type: "GET",
  url: uri,
  data: getVars,
  dataType: "json",
  cache: false,

  beforeSend: function(){
    // Handle the beforeSend event
  },
  
  success: function(data){
    // Handle the complete event
	if(data.returnData) 
	{
		for(x =0;x<=data.returnData.length;x++)
		{
			arrCurData = data.returnData[x];
			if(arrCurData)
			{
				elementID = arrCurData.strCSSId;
				elementData = arrCurData.description;
				$("#"+elementID).html(elementData);
			}
		}
	}
	
    var dump = sIFR();
  }

 });
	
}

// umleiten
function setRedirect(uri, getVars) {

	 $.ajax({
	   
	  type: "GET",
	  url: uri,
	  data: getVars,
		cache: false,

	  beforeSend: function(){
	    // Handle the beforeSend event
	  },
	  
	  success: function(data){
	    // Handle the complete event
		if ( data ) {
		  window.location.href = data;
		}
	  }

	 });
		
}

//project selection
function updateProjectBranche( intElementId ) {

	var domain = location.host;

	$.ajax({
	   
		type: "GET",
		url: 'http://' + domain +'/cms/?p=244&mode=aj_updateprojects&mode2=1&sel=' + intElementId ,
		data: '',
		cache: false,

		beforeSend: function(){
		// Handle the beforeSend event
		//$("#ajax_projektliste").fadeOut(1500);
	},

	success: function(data){
		// Handle the complete event
		$("#ajax_projektliste").html(data);
		//$("#ajax_projektliste").fadeIn(2000);
		$('dl.accordion').accordion({ 
		    event: 'click', 
		    active: '.selected', 
			duration: 1500, 
		    selectedClass: 'active', 
			autoHeight: false,
			collapsible: true,
		    header: "dt" 
		});
	}

	});

}
function updateProjectBereich( intElementId ) {

	var domain = location.host;

	$.ajax({

		type: "GET",
		url: 'http://' + domain + '/cms/?p=244&mode=aj_updateprojects&mode2=2&sel=' + intElementId,
		data: '',
		cache: false,

		beforeSend: function(){
		// Handle the beforeSend event
		//$("#ajax_projektliste").fadeOut(1500);
	},

	success: function(data){
		// Handle the complete event
		$("#ajax_projektliste").html(data);
		//$("#ajax_projektliste").fadeIn(2000);
		$('dl.accordion').accordion({ 
		    event: 'click', 
		    active: '.selected', 
			duration: 1500, 
		    selectedClass: 'active', 
			autoHeight: false,
			collapsible: true,
		    header: "dt" 
		});
	}

	});

}


// content ersetzen
function sendPostTEData(elementID, uri) {

 $.ajax({
  type: "POST",
  data: $("#"+elementID).serialize(),
  url: uri,
	cache: false,
  success: function(data){
  	eval(data);
  }
 });
 
}
 
// content ersetzen
function sendPostData(elementID, uri) {

 $.ajax({
  type: "POST",
  data: $("#"+elementID).serialize(),
  url: uri,
	cache: false,

  beforeSend: function(){
    // Handle the beforeSend event
	  $("#"+elementID).fadeOut(1500);
  },
  
  success: function(data){
    // Handle the complete event
    $("#"+elementID).replaceWith(data);
    $("#"+elementID).fadeIn(2000);
    var dump = sIFR();
  }
 });
 
}
  
