$(function(){

	
	$('span.information').qtip({
		content: {
	    	text: '<img src="tl_files/codeprofiler/images/close-qtip.gif" class="close_qtip"><strong>More know how – more security</strong><br><br>The CodeProfiler Team actively researches how to make ABAP programs more secure. This includes inspections of the ABAP standard and changes in the ABAP programming language.<br><br>One of the results is that we regularly identify “Zero Day” vulnerabilities in the standard. Zero Day means that a protective measure has not yet been defined for the vulnerability.<br><br>We are aware of our responsibility and report these vulnerabilities to SAP in accordance with our <a href="http://www.virtualforge.com/vf_vdp/VDP.pdf">Vulnerability Disclosure Policy</a>.<br><br>	On this page you can request our latest findings.'
	   },
		position: {
	   		my: 'top center',  // Position my top left...
	      	at: 'bottom center', // at the bottom right of...
	      	target: $('span.information') // my target
	   },
	   	hide: {
			fixed: true,
			event: 'click mouseleave',
			target: $('.close_qtip')
	   }
	});
	
	$('.dataprotection').qtip({
	   content: {
	      text: 'The protection of your personal data is important to us. Below, we would like to explain how we protect your privacy when handling the data in this form: We want to emphasize that the entry of any personal data takes place explicitly on a voluntary basis. By clicking on the “submit request” button, the user agrees to the provided data being stored and used for marketing purposes such as invitations to events, other marketing activities and the newsletter mailing list. This permission can be revoked any time. We will not sell or hand over your data to other third parties. Your data is stored and protected from external intrusion to the best of our knowledge.'
	   },
	   position: {
	      my: 'top center',  // Position my top left...
	      at: 'bottom center', // at the bottom right of...
	      target: $('.dataprotection') // my target
	   }
	});
	
	$('.dataprotection').click(function(event){
		event.preventDefault();
	});
	
	$("#ctrl_11").show('fast');
	
	jQuery.fn.center = function () {
	    this.css("position","absolute");
	    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()/2 + "px");
	    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
	    return this;
	}
	
	// Via http://css-tricks.com/snippets/jquery/append-site-overlay-div/
	
	$("body").prepend("<div id='overlay'></div><div id='ajaxadvisoryform'></div>");
	var docHeight = $(document).height();
	$("#overlay")
		.height(docHeight)
		.css({
			'opacity' : 0.4,
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'background-color': 'black',
			'width': '100%',
			'z-index': 5
		}).click(function(){ 
			$(this).fadeOut('fast');  
			$('#ajaxadvisoryform').fadeOut('fast');
		});
//	$('#ajaxadvisoryform').center();
	
	
	$("#advisoriesformlink").click(function(event){
		event.preventDefault();
		
		var advisory_ids = '';
		var amount_checked = $('input[name|="advisory"]:checked').length;
		$('input[name|="advisory"]:checked').each(function(i){
			advisory_ids += $(this).parent().next().text();
			if(i != amount_checked-1) { advisory_ids += ', '; }
		});
		
		//log(advisory_ids);
		//log(amount_checked);
		
		if(advisory_ids == '') {
			alert("Please choose the advisories you want to request by checking them off on the left of the list.")
			return false; 
		}
		
		
		$('#ajaxadvisoryform').center();
		//$("#ajaxadvisoryform").load("/index.php/advisories-anfordern.html #advisories-anfordern-form" , function(response, status, xhr) {
		$("#ajaxadvisoryform").load("http://codeprofilers.com/index.php/advisories-anfordern.html #advisories-anfordern-form" , function(response, status, xhr) {
		

		  //alert(xhr.statusText);
		  log(response);
		  
			if (status == "error") {
		    	var msg = "Sorry but there was an error: ";
		    	log(msg + xhr.status + " " + xhr.statusText);
		  	}
		  	else
		  	{
				$('input[name|="Angeforderte_Advisories"]').val(advisory_ids);
				$("#overlay").fadeIn();
				$("#ajaxadvisoryform").fadeIn();
				$('input.text').each(function() {
					$(this).data('default', $(this).val())
			    	.addClass('inactive')
			    	.focus(function(){
			      		$(this).removeClass('inactive');
			      		if ($(this).val() == $(this).data('default') || ''){
			        		$(this).val('');
			      		}
			    	})
			    	.blur(function(){
			      		if ($(this).val() == '') {
			        		$(this).addClass('inactive');
			        		$(this).val($(this).data('default'));
			      		}
			    	});
			  	});
				
				
				$('.dataprotection').qtip({
				   content: {
				      text: 'The protection of your personal data is important to us. In the following we inform you how all data entered in this form will be handled: We want to emphasize that the entry of any personal data takes place explicitly on a voluntary basis. By clicking on the “submit request” button the user agrees that the provided data is stored and used for marketing purposes such as invitations to events, other marketing activities and the newsletter mailing list. This permission can be revoked any time.<br><br>We will not sell or hand over your data to other third parties. Your data is stored and protected from external intrusion to the best of our knowledge.'
				   },
				   position: {
				      my: 'top center',  // Position my top left...
				      at: 'bottom center', // at the bottom right of...
				      target: $('.dataprotection') // my target
				   }
				});
				
				
				$("#advisories-anfordern").validate({
			    rules: {
			    	name: "required defaultInvalid",
			    	company: "required defaultInvalid",
			    	telephone: {
						required: true,
						minlength: 5, 
						defaultInvalid: true,
						digits: true
					},
			    	email: {
			    		required: true,
			    		email: true,
			    	},
					dataprot: "required"
			    },
			    errorPlacement: function(error, element) {
			      error.remove();
			    }
			  });
				
				$('.dataprotection').click(function(event){
					event.preventDefault();
				});
			}
		});	
	});
	
	
	
	
	
	
});




 









