function OpenFens(link,height,width)
{
 slidewin=open(link,"slide","toolbar=no,location=no,status=no,scrollbars=yes,width="+width+",height="+height+",left=10,top=10,resizable=yes");
  if (!slidewin.opener) slidewin.opener=self; 
  if (!slidewin.opener != null) slidewin.focus();
}

function ZoomInS(aImage, aTitle, aWidth, aHeight) {
  h = 10;
  w = 20;
  x =   open("","","toolbar=0,location=0,directories=0,status=0,menubar=0,width="+aWidth+",height="+aHeight+",left=50,top=50");
  x.document.write('<HTML><HEAD><TITLE>'+aTitle+'</TITLE></HEAD>');
  x.document.write('<BODY TOPMARGIN="0" LEFTMARGIN="0">');
  x.document.write('<TABLE width="100%" height="100%"><tr><td align="center"><img src="'+aImage+'"></td></tr></table>');
  x.document.write('</BODY></HTML>');

  if (!x.opener)
    x.opener=self; 
  if (!x.opener != null)
    x.focus();
}

function ZoomIn(aImage, aTitle) {
  ZoomInS(aImage, aTitle, 640, 480) 
}

function DownloadCounter(FileURL) {
  GetCounter = new Image(1,1);
  GetCounter.src = "http://www.DownloadCounter.de/counter.pl?file="+FileURL+"&user=SebastianKeseling&img";
}

function IsEMail(EMail){ 
  if(EMail != "")
  {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return filter.test(EMail);
  }
  else
    return false;
}

function Mail(){
  bs = 'ling';
  vs = '.'; // 
  ls = '@'; // hm@test.xyz
  ls = 'info'+ls;
  xs = 'mai';
  ls = ':'+ls; // .invalid
  ls = ls + 'kese'+bs; // @
  ls = ls + vs + 'de'; // .xyz
   
  window.location.replace(xs+'lto'+ls);
}

function TextCounter(field, countFieldId, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		document.getElementById(countFieldId).innerHTML = maxlimit - field.value.length;
	}
}

function getRadioValue(feld){
for (i=0; i < feld.length; i++){
if(feld[i].checked == true){
return feld[i].value;
}
}
} 

function getVoteCaption(rating, name){
  var caption = '';
  switch (rating){
  case 4:
     caption = 'Sehr gut';
    break;  
  case 3:
    caption = 'Gut';
    break;
  case 2:
     caption = 'Durschnittlich';
    break;
  case 1:
    caption = 'Schlecht';
    break;
  case 0:
     caption = 'Sehr Schlecht';
    break;
  default:
    caption = 'Ohne Wertung'
    break;
  }

  window.document.getElementById(name+'caption').innerHTML = caption;
}

function starToSchool(starRating, max, school){
  if (starRating <= 0)
    return starRating
  else
    return max-starRating+1;
}

(function(a) {
	a.fn.displRating = function(p) {
		var p = p || {};
		var b = p && p.rating_star_length ? p.rating_star_length : 5;
		var c = p && p.rating_function_name ? p.rating_function_name : "";
		var e = p && p.rating_initial_value ? p.rating_initial_value : -1;
		var d = p && p.directory ? p.directory : "img";
		var sm = p && p.school_marks ? p.school_marks : true;
		var f = "";
		var g = a(this);
		
		var lastRating = e;
		var nm = g.attr('name');
		
		b = parseInt(b);
		init();
		g.next("ul").children("li").hover(function() {
		    $(this).parent().children("li").css('background-image', 'url(' + d + '/rtstar_e.png)');
			var a = $(this).parent().children("li").index($(this));
			$(this).parent().children("li").slice(0,a+1).css('background-image', 'url(' + d + '/rtstar_h.png)');
			
			getVoteCaption(a, nm);
		}, function() {
		});
		g.next("ul").children("li").click(function() {
			var a = $(this).parent().children("li").index($(this));
			lastRating = a;
			f = a + 1;
			g.val(starToSchool(f, b, sm));
			if(c != "") {
			  eval(c + "(" + g.val() + ")")
			}
			getVoteCaption(a, nm);
		});
		g.next("ul").hover(function() { 
		}, function() {
			if(f == "") {
			  $(this).children("li").css('background-image', 'url(' + d + '/rtstar_e.png)')}
  		    else {
			  $(this).children("li").css('background-image', 'url(' + d + '/rtstar_e.png)');
			  $(this).children("li").slice(0,f).css('background-image', 'url(' + d + '/rtstar_n.png)')
			}
            
			getVoteCaption(lastRating, nm);			
		});
		function init() {$('<span style="vertical-align: bottom; margin-left:8px" id="'+nm+'caption"></span>').insertAfter(g);
			g.css("float", "left");
			var a = $("<ul>");
			a.attr("class", "rating");
			for(var i = 1; i <= b; i++) {a.append('<li style="background-image:url(' + d + '/rtstar_e.png)"><span>' + i + '</span></li>')
			}
			a.insertAfter(g);
			if(e != -1) {
				f = e;
				g.val(starToSchool(f, b, sm));
				g.next("ul").children("li").slice(0,f).css('background-image', 'url(' + d + '/rtstar_n.png)')
			}
			getVoteCaption(-1, nm);
		}

	}
})(jQuery);

