/**
 * jQuery Maxlength plugin
 * @version		$Id: jquery.maxlength.js 18 2009-05-16 15:37:08Z emil@anon-design.se $
 * @package		jQuery maxlength 1.0.5
 * @copyright	Copyright (C) 2009 Emil Stjerneman / http://www.anon-design.se
 * @license		GNU/GPL, see LICENSE.txt
 */
 (function(A){A.fn.maxlength=function(B){var C=jQuery.extend({events:[],maxCharacters:10,status:true,statusClass:"status",statusText:"character left",notificationClass:"notification",showAlert:false,alertText:"You have typed too many characters.",slider:false},B);A.merge(C.events,["keyup"]);return this.each(function(){var G=A(this);var J=A(this).val().length;function D(){var K=C.maxCharacters-J;if(K<0){K=0}G.next("div").html(K+" "+C.statusText)}function E(){var K=true;if(J>=C.maxCharacters){K=false;G.addClass(C.notificationClass);G.val(G.val().substr(0,C.maxCharacters));I()}else{if(G.hasClass(C.notificationClass)){G.removeClass(C.notificationClass)}}if(C.status){D()}}function I(){if(C.showAlert){alert(C.alertText)}}function F(){var K=false;if(G.is("textarea")){K=true}else{if(G.filter("input[type=text]")){K=true}else{if(G.filter("input[type=password]")){K=true}}}return K}if(!F()){return false}A.each(C.events,function(K,L){G.bind(L,function(M){J=G.val().length;E()})});if(C.status){G.after(A("<div/>").addClass(C.statusClass).html("-"));D()}if(!C.status){var H=G.next("div."+C.statusClass);if(H){H.remove()}}if(C.slider){G.next().hide();G.focus(function(){G.next().slideDown("fast")});G.blur(function(){G.next().slideUp("fast")})}})}})(jQuery);

 
 
 
 var offsetx = 12;
	var offsety =  -25;

function newelement(newid)
{ 
  if(document.createElement)
  { 
      var el = document.createElement('div'); 
      el.id = newid;     
      with(el.style)
      { 
          display = 'none';
          position = 'absolute';
      } 
      el.innerHTML = '&nbsp;'; 
      document.body.appendChild(el); 
  } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
  if(document.getElementById)
  {
      var iebody=(document.compatMode && 
      	document.compatMode != 'BackCompat') ? 
      		document.documentElement : document.body;
      pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
      pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
      mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
      mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

      var lixlpixel_tooltip = document.getElementById('tooltip');
      lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
      lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
  }
}
function tooltip(tip)
{
  if(!document.getElementById('tooltip')) newelement('tooltip');
  var lixlpixel_tooltip = document.getElementById('tooltip');
  lixlpixel_tooltip.innerHTML = tip;
  lixlpixel_tooltip.style.display = 'block';
  document.onmousemove = getmouseposition;
}
function exit()
{
  document.getElementById('tooltip').style.display = 'none';
}


$(document).ready(function(){
 	$('#mySearches').change(function() {
	  this.form.submit();
	});

 	$('.paymenttypeOffer').click(function() {
		if(this.id=="paymenttype_9") {
			if(this.checked==true) {
				$('.paymenttypeOffer').css('opacity','0.5');
				$('.paymenttypeOffer').attr('disabled','disabled');
				$('#paymenttype_9').css('opacity','1');
				$('#paymenttype_9').removeAttr('disabled');
				$('.paymentOfferLabel').css('opacity','0.5');
				$('#paymentOfferLabel_9').css('opacity','1');
			} else {
				$('.paymenttypeOffer').css('opacity','1');
				$('.paymenttypeOffer').removeAttr('disabled');
				$('.paymentOfferLabel').css('opacity','1');
			}
				
		} else {
			var isChecked = false;
			$('.paymenttypeOffer').each(function(index,item) {
				if(item.checked==true && isChecked == false && item.id !="paymenttype_9") {
					isChecked = true;
				}	
			});	
			if(isChecked) {
				$('#paymenttype_9').css('opacity','0.5');
				$('#paymenttype_9').attr('disabled','disabled');
				$('#paymentOfferLabel_9').css('opacity','0.5');
			} else {
				$('#paymenttype_9').css('opacity','1');
				$('#paymenttype_9').removeAttr('disabled');
				$('#paymentOfferLabel_9').css('opacity','1');
			}
 	 	 }		  	  
 	});
 	
 	if  ($('#paymenttype_9').attr('checked') == true){
 		$('.paymenttypeOffer').attr('checked',false);
		$('.paymenttypeOffer').css('opacity','0.5');
		$('.paymenttypeOffer').attr('disabled','disabled');
		$('#paymenttype_9').css('opacity','1');
		$('#paymenttype_9').removeAttr('disabled');
		$('.paymentOfferLabel').css('opacity','0.5');
		$('#paymentOfferLabel_9').css('opacity','1');
		$('#paymenttype_9').attr('checked',true);

 	} else {
 		var isChecked = false;
		$('.paymenttypeOffer').each(function(index,item) {
			if(item.checked==true && isChecked == false && item.id !="paymenttype_9") {
				isChecked = true;
			}	
		});	
		if(isChecked){
 			$('#paymenttype_9').css('opacity','0.5');
 			$('#paymenttype_9').attr('disabled','disabled');
			$('#paymenttype_9').attr('checked',false);
 		}
 	}
 	
 	$('.method1').click(function() {
			if(this.checked==true) {
				$('#method_item2').attr('opacity','0.5');
				$('#methodsofinvestment_2').attr('disabled','disabled');
				$('#actingpartner_1').attr('checked',false);
				$('#acting_item').css('opacity','0.5');
				$('#actingpartner_1').attr('disabled','disabled');
				$('#actingpartner_2').attr('checked','checked');	
				$('#method_item2').css('opacity','0.5');		
				
	 	 	} else {
	 	 			$('#methodsofinvestment_2').attr('disabled','');
	 	 			$('#method_item2').css('opacity','1');
	 	 			$('#actingpartner_1').removeAttr('disabled');
	 	 			$('#acting_item').css('opacity','1');
	 	 	 }		  	  
	 	});
 		$('.method2').click(function() {
		if(this.checked==true) {
			$('#method_item1').attr('opacity','0.5');
			$('#methodsofinvestment_1').attr('disabled','disabled');
			$('#actingpartner_2').attr('checked',false);
			$('#acting_item2').css('opacity','0.5');
			$('#actingpartner_2').attr('disabled','disabled');
			$('#actingpartner_1').attr('checked','checked');	
			$('#method_item1').css('opacity','0.5');		
			
 	 		} else {
 	 			$('#methodsofinvestment_1').removeAttr('disabled');
 	 			$('#method_item1').css('opacity','1');
 	 			$('#actingpartner_2').removeAttr('disabled');
 	 			$('#acting_item2').css('opacity','1');
 	 	 	}		  	  
 	});
	$('.acting1').click(function() {
	  		$('#methodsofinvestment_1').attr('checked',false);
			$('#method_item1').css('opacity','0.5');
			$('#method_item2').css('opacity','1');
			$('#methodsofinvestment_1').attr('disabled','disabled');
			$('#methodsofinvestment_2').removeAttr('disabled');
	
 	});
	$('.acting2').click(function() {
	  		$('#method_item1').css('opacity','1');
	  		$('#method_item2').css('opacity','0.5');
		$('#methodsofinvestment_2').attr('checked',false);
		$('#methodsofinvestment_2').attr('disabled','disabled');
		$('#methodsofinvestment_1').removeAttr('disabled');
		$('#methodsofinvestment_1').css('opacity','1');

	});
	
	$('.acting2').click(function() {
  		$('#method_item1').css('opacity','1');
  		$('#method_item2').css('opacity','0.5');
	$('#methodsofinvestment_2').attr('checked',false);
	$('#methodsofinvestment_2').attr('disabled','disabled');
	$('#methodsofinvestment_1').removeAttr('disabled');
	$('#methodsofinvestment_1').css('opacity','1');
	});
});
function removeVita(that) 
{
	var counter = 10;
	var position = false;
	var posClass
	while (position == false) {
		that = that.parentNode;
		posClass = that.getAttribute("class");
		if(posClass != null) {
			if(that.getAttribute("class").match(/vita_point/) == 'vita_point')
			{
				position = true;
			}
		}
		counter = counter -1;
		if(counter == 0){position = true;}
	}
	that.parentNode.removeChild(that);
}

function removeContact(that) 
{
	var counter = 10;
	var position = false;
	var posClass
	while (position == false) {
		that = that.parentNode;
		posClass = that.getAttribute("class");
		if(posClass != null) {
			if(that.getAttribute("class").match(/contact_point/) == 'contact_point')
			{
				position = true;
			}
		}
		counter = counter -1;
		if(counter == 0){position = true;}
	}
	that.parentNode.removeChild(that);
	updateContacts();
}


function removeStudy(that) 
{
	var counter = 10;
	var position = false;
	var posClass
	while (position == false) {
		that = that.parentNode;
		posClass = that.getAttribute("class");
		if(posClass != null) {
			if(that.getAttribute("class").match(/study_point/) == 'study_point')
			{
				position = true;
			}
		}
		counter = counter -1;
		if(counter == 0){position = true;}
	}
	that.parentNode.removeChild(that);
}

function removeLanguage(that) 
{
	var counter = 10;
	var position = false;
	var posClass
	while (position == false) {
		that = that.parentNode;
		posClass = that.getAttribute("class");
		if(posClass != null) {
			if(that.getAttribute("class").match(/language_point/) == 'language_point')
			{
				position = true;
			}
		}
		counter = counter -1;
		if(counter == 0){position = true;}
	}
	that.parentNode.removeChild(that);
}


function openContact(src)
{
	$.modal('<iframe src="' + src + '&box=1" height="560" width="830" scrolling="no" style="border:0;">', {
	closeHTML:"",
	containerCss:{
		backgroundColor:"#fff",
		borderColor:"#fff",
		height:580,
		padding:0,
		width:830
	},
	overlayCss: {
		backgroundColor:"#000"
	},
	overlayClose:true,
	closeHTML: "zu"
});
}


$(document).ready(function(){
	$('#moreStudy').click(function() {
		$('#hidden_study_table').clone().appendTo('#study_container');
	});
	$('#moreLanguages').click(function() {
		$('#hidden_language_table').clone().appendTo('#language_container');
	});
	$('#moreVitas').click(function() {
		$('#hidden_vita_table').clone().appendTo('#vita_container');
	});
	$('#moreContacts').click(function() {
		currentCounter++;
		var newobject = $('#hidden_contact_div').clone();
		newobject.addClass('contact'+currentCounter);
		newobject.attr('id', 'contact'+currentCounter)
		newobject.appendTo('#contact_container');
		$('.contact'+currentCounter +' input.contactcounter').val(currentCounter);
		updateContacts();
	});
	$('#branchFocusSelector').click(function() {
		if($('#branchFocusSelector').attr('checked') == true) {
			$('#sectorSelector').css('visibility','collapse');
		} else{
			$('#sectorSelector').css('visibility','visible');
		}
	});
	$('#removesplashbutton a').click(function() {
		confirmVal = confirm('Kopfbild löschen'); 
		if(confirmVal){
			$('#hiddensplashimage').val('');
			$('#splashpreview').remove();
		}
	});
	$('#removelogobutton a').click(function() {
		confirmVal = confirm('Logo löschen');
		if(confirmVal){
			$('#hiddenlogo').val('');
			$('#logopreview').remove();
		}
	});
	$('#removepresentationbutton a').click(function() {
		confirmVal = confirm('Präsentation löschen'); 
		if(confirmVal){
			$('#hiddenpresentation').val('');
			$('#presentationpreview').remove();
		}
	});
	$value = $('#url').val();
	if($value == ''){$('#url').val('http://');}
});	

  $(document).ready(function() {
    $("input[name='check_all']").click(function(){
      if($(this).val()==0){
        $(this).parents("table")
               .find("input:checkbox")
               .attr("checked","checked");
              $(this).attr("value",1)
               $(this).attr("checked","checked");
      }
      else{
        $(this).parents("table")
               .find("input:checkbox")
               .attr("checked","");
              $(this).attr("value",0)
               $(this).attr("checked","");
      }
    });
  }); 
  
 // add hb-abos to links
 function addHB( adlink , ischeck )
 {
 	if( typeof(document.getElementById(adlink)) !="undefined" )
 	{
 		var srcStr = "hBAbo";
 		var elm = document.getElementById(adlink);
 		var a = elm.href.split( '?' );
		var hasParam = 0;
		var newlink = a[0];
		var newval = ischeck ? 1 : 0;
 		if( a[1] )
 		{
 			var b = a[1].split( '&' );
 			for(i=0;i<b.length;i++)
 			{
 				var sp = (i==0) ? '?' : '&';
 				c = b[i].split('=');
 				if( c[0] )
 				{
 					if( c[0].indexOf( srcStr ) > 0 )
 					{
 						hasParam = 1;
 						newlink += sp + c[0] + "=" + newval;
 					}
 					else
 					{
 						newlink += sp + c[0] + "=" + c[1];
 					}
 				}
 			}
 			if( !hasParam ) newlink += sp + srcStr + "=" + newval;
 			elm.href = newlink;
 		}
 	}
 }

 function updateContacts(translationText){
	 var contacts = new Array();
	 var currentClass = '';
	 var matched = '';
	 $('div.contact_point').each(function(index) {
		 currentClass = $(this).attr('class');
		 matched = currentClass.match('contact[0-9]+');
		 if(matched){
			 matched = String(matched);
			 contacts.push(String(matched.replace('contact','')));
		 }
	  });
	updateContactsSelect(contacts,translationText);
 }
 
 function updateContactsSelect(contacts,translationText){
	 var number;
	 var text = translationText;
	 var selects = $('.contactsselect');
	 var options = '';
	/*if(selects.prop) {
		var options = selects.prop('options');
	}
	else {
		var options = selects.attr('options');
	}*/
	$('option', selects).remove();
	$.each(contacts, function(contact,value) {
		number = Number(value) +1;
		options = options + '<option value="'+value+'">'+text+' '+number+'</option>';// new Option(text+' '+number, value);
	});
	selects.html(options);
 }
 
 function removeContactImage(id){
	confirmVal = confirm('Kontaktbild löschen'); 
	if(confirmVal){
		$('#contactimage' + id).val('');
		$('#previewimage' + id).remove();
	}
 }
 
 function removeImageFile(filename,userid,pageurl,refreshUrl){
	 check = confirm('Datei wirklich löschen');
	 if (check){
		 $.get(pageurl+'&userid='+userid+'&filename='+filename, {},function(response){ 
			    	reloadProfileFileList( 'multifiles' , refreshUrl);
		 });
 	 }
 }
 


