$(document).ready(function(){

	if (document.getElementById("cal1Container")) {
		var loader = new YAHOO.util.YUILoader({
			require: ["calendar", "json", "utilities","animation"],
			loadOptional: true,
			allowRollup: true,
			base: 'jslibs/yui251/build/',
			skin: {
				defaultSkin: 'sam',
				base: 'assets/skins/',
				overrides: {
					calendar: ['myCalSkin']
				}
			},
			
			onProgress: function(o){
			
			},
			
			// The function to call when all script/css resources have been loaded
			onSuccess: function(){
				// do a ajax request
				var request = YAHOO.util.Connect.asyncRequest('POST', '/de/article/getdates/', {
					failure: function(o){
						alert('Error');
					},
					success: function(o){
						var json = YAHOO.lang.JSON.parse(o.responseText);
						var cal1 = new YAHOO.widget.Calendar("cal1Container");
						
						var renderCellDefault = function(workingDate, cell){
							var Jahr = workingDate.getYear();
							var month = workingDate.getMonth() + 1;
							if (Jahr < 2000) 
								Jahr = Jahr + 1900;
							YAHOO.util.Dom.addClass(cell, "highlight1");
							
							cell.innerHTML = '<a href="/de/blog/' + Jahr + '/' + month + '/' + this.buildDayLabel(workingDate) + '" >' + this.buildDayLabel(workingDate) + "</a>";
							return YAHOO.widget.Calendar.STOP_RENDER; // to force the new behavior
						}
						for (bla in json) {
							var date = json[bla].article_month + '/' + json[bla].article_day + '/' + json[bla].article_year
							cal1.addRenderer(date, renderCellDefault)
						}
						
						$('#cal1Container').hide();
						cal1.render();
						$('#cal1Container').slideDown();
						
					}
				}, "");
				
				
				
			} // on success
		});
		loader.insert();
	}
	
	if ($('#ll').length > 0) {
		$('#ll').click(function(){
			$('#loginForm').slideDown();
			return false;
		})	
	}
	
	if($('#clist').length > 0){
				
		// jetzt noch display = inline stellen
		$('#form').fadeIn();
		$('#indicator').fadeOut();
				
		var v = jQuery("#form1").validate({
			highlight: function(element, errorClass) {
				$(element).fadeOut(function() {
					$(element).fadeIn()
     			})
  			},
		    submitHandler: function(form) {
		    	jQuery(form).ajaxSubmit({
		    		target: "#result",
		    		beforeSubmit:function(){
		    			//$('.submit').attr('disabled','true');
		    		},
		    		success: function(res){
		    			
		    			//check if we have error
		    			if(res.Results.status != 'successfully inserted'){
		    				$('pre').fadeOut(200,function(){$(this).fadeIn(200)});
		    				//$('.submit').attr('disabled','false');
		    			}else{
		    				var el = $('<div class="commentrow" $>'+res.Results.data+'</div><div class="arrow">'+res.Results.message+'</div>').hide();
		    				$('#clist').append(el);
		    				$(el).slideDown(1000);
		    				
		    				$('#form').slideUp(1000);
		    				
		    				$('.submit').attr('disabled','false');
		    				$('form :input').val("");
		    				$('form :input.submit').val("Submit");
		    				$('form :textarea').val("");
		    			}
		    		},
		    		failure: function(res){
		    			alert('shit');
		    		},
		    		
		    		dataType:'json'
		    	});
		    }
		});

	}
	
	if($('#formii').length > 0){
	
		var v = jQuery("#formii").validate();
		
		/*
		var check = function(id){
			// doing a post ajax request
			var lang = document.getElementById('lang').value;
			$.post('/'+lang+'/contact/process/',{id : decodeURIComponent($('#'+id).val())},function(res){
				//response success
				// new ul error
				var ul = $('<ul />').attr('class','errors').attr('id',id + '_e');
			},'json');
		}
		
		$('#mail_name').bind('blur',function(e){
			check('mail_name');
		});
		$('#mail_email').bind('blur',function(e){
			check('mail_email');
		});
		$('#mail_text').bind('blur',function(e){
			check('mail_text');
		});
		
		$('#mail_url').bind('blur',function(e){
			// http raushauen
			var val = $(this).val();
			val = val.toLowerCase();
			
			if(val.indexOf('https://') >= 0){
				$(this).val() = val.substr(val.indexOf('https://')+8);
			}
			
			if(val.indexOf('ftp://') >= 0){
				$(this).val() = val.substr(val.indexOf('ftp://')+6);
			}
			
			if(val.indexOf('http://') >= 0){
				$(this).val() = val.substr(val.indexOf('http://')+7);
			}
			check('mail_url');
		});
		
		*/
	}
});

/*
success:function(o){
	if(o.responseText != "true"){
		var oJson = YAHOO.lang.JSON.parse(o.responseText);
		
		// create a new ul list an append it at the input element
		var ul = document.createElement('ul');
		ul.setAttribute('class','errors');
		ul.setAttribute('id',id +'_e');
		for(i in oJson[id]){
			var li = document.createElement('li');
			li.innerHTML = oJson[id][i];
			ul.appendChild(li);	
		}
		if (document.getElementById(id + '_e')) {
			document.getElementById('style_' + id).removeChild(document.getElementById(id + '_e'));
		}
			
		document.getElementById('style_' + id).appendChild(ul);	
	}else{
		if (document.getElementById(id + '_e')) {
			document.getElementById('style_' + id).removeChild(document.getElementById(id + '_e'));
		}
	}
	
	
},
failure:function(o){
	//alert('error');
}
*/

