﻿/* MAILTO
------------------------------------------------------------------------------*/

function mailTo(name){
	location.href = "mailto:" + name + "@roteraupe.de";
}

/* OPEN DIV
------------------------------------------------------------------------------*/

function slideDiv(id){
	if($(id).style.display == 'none'){
  	new Effect.SlideDown(id, {duration: 0.3 });
	}else{
  	new Effect.SlideUp(id, {duration: 0.3 });
	}
}

function toggleDiv(id){
	if($(id).style.display == 'none'){
    $(id).appear({ duration: 0.3, from: 0, to: 1 });
	}else{
    $(id).fade({ duration: 0.3, from: 1, to: 0 });
	}
}

function changeRow(id,col){
  var col;
	if(col == '1'){
		$(id).setStyle({background: '#e0eaf5'});
  }else{
		$(id).setStyle({background: '#ffffff'});
  }

}


/* LINKTRACKER
------------------------------------------------------------------------------*/

function trackLink(what,id){
  var url = '/inc/ajax/req_linktracker.php';
  new Ajax.Request(url, {
  parameters: "what=" + what + "&id=" + id + ",",
  method: 'POST'});
}





/* SET CHECKBOX
------------------------------------------------------------------------------*/

function setCB(id){
	//alert ($(id).checked);
  if($(id).checked == false){
  	$(id).checked = true;
		$(id+'_img').style.background = "url(/images/layout/checkbox_on.gif) no-repeat center left";
  }else{
    $(id).checked = false;
		$(id+'_img').style.background = "url(/images/layout/checkbox_off.gif) no-repeat center left";
  }

}

/* SHOW LOADER
------------------------------------------------------------------------------*/

function showLoader(loader, btn){
	$(btn).hide();
	$(loader).show();
}

/* GALLERY INFO
------------------------------------------------------------------------------*/

function fadeImageInfo(type){
	if(type == 'over'){
		new Effect.Appear('teaser_note', { from: 0.0, to: 0.7, duration: 0.2 });
	}else{
		if ( Prototype.Browser.IE6 ){
      $('teaser_note').hide();
		}else{
    	new Effect.Appear('teaser_note', { from: 0.7, to: 0.0, duration: 0.2 });
		}
	}
}


/* INSERT TAG
/* http://aktuell.de.selfhtml.org/artikel/javascript/bbcode/
------------------------------------------------------------------------------*/

function insertTag(aTag, eTag){

 var input = $('text');
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined'){

    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var selection = input.value.substring(start, end);

		if(aTag == '[img]'){
	   	var insImg = prompt("bitte eine url zum bild eingeben:\n\nzB: http://www.domain.de/der/pfad/zum/bild.jpg", "http://");
			insText = "[img]"+insImg+"[/img]";
			var after = input.value.substr(end);
      input.value = input.value.substr(0, start) + insText + after;
		}else if(aTag == '[vid]'){
	   	insVid = prompt("bitte die youtube url eingeben:\n\nzB: http://www.youtube.com/watch?v=hiErDeRcOdE", "http://");
      insTxt = "video ansehen";
	    insText = (insTxt != null && insVid != null) ? "[vid="+insVid+"]"+insTxt+"[/vid]" : "";
      input.value = input.value.substr(0, start) + insText + input.value.substr(end);
		}else if(aTag == '[url]'){
	   	insUrl = prompt("bitte eine url eingeben:\n\nzB: http://www.google.de", "http://");
	    if (selection == ""){
	      insTxt = prompt("bitte einen linktext eingeben:", "");
	    } else {
	      insTxt = selection;
	    }
	    insText = (insTxt != null && insUrl != null) ? "[url="+insUrl+"]"+insTxt+"[/url]" : "";
      input.value = input.value.substr(0, start) + insText + input.value.substr(end);
		}else{
			var insText = input.value.substring(start, end);
      input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
		}
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

/* RGS
------------------------------------------------------------------------------*/

  function loadCode(id){
    if(!id){
      $('rgs1').hide();
      $('rgs2').hide();
      $('rgs3').hide();
      $('rgs4').hide();
      $('rgs5').hide();
      $('rgs6').hide();
    }else{
      $('rgs1').hide();
      $('rgs2').hide();
      $('rgs3').hide();
      $('rgs4').hide();
      $('rgs5').hide();
      $('rgs6').hide();
      $('rgs'+id).show();
    }
  }


/* SOFTSCROLL
------------------------------------------------------------------------------*/

window.onload = function ()
{
    loadSoftScroll ();
}
function loadSoftScroll ()
{
    if (!document.getElementsByClassName('softscroll')) {
        return false;
    }
    var links = document.getElementsByClassName('softscroll');
    for (var i = 0; i < links.length; i++) {
        links[i].onclick = function ()
        {
            var parts = this.href.split('#');
            new Effect.ScrollTo(parts[1]);
            return false;
        }
    }
}



/* BLANKWIN
/* written by Alen Grakalic, provided by Css Globe (cssglobe.com)
/* http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically/
------------------------------------------------------------------------------*/

this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
		//obj.className = "";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};



// script initiates on page load.

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",blankwin);


/* FORUM */

function openThemeForm(cat_id){
	var cat_id;
  $('id_cat').value = cat_id;
	Lightview.show({ href: "#form_theme_new", rel: 'inline', options: { width: 860, height: 520 }});
}


