
function newsStyleChanger () {
	var $cnt = 0;
	// adding the extra class to the first news element for use more space on the homepage
	if (jQuery('#homeNews')){
		jQuery('#homeNews .newsItem:first').attr('class', 'newsItemImportant');
	}
	//disable the picture from the other news elements
	if (jQuery('#homeNews')){
		jQuery('#homeNews .newsItem img').each(function () {
			jQuery(this).css('display', 'none');

		});
		// truncate news text
		jQuery('#homeNews .newsContent .newsText').each(function () {
			if($cnt > 0){
			var $str = jQuery(this).find("b");
			var $str2 = jQuery(this).find("p");
			//remember link before truncating
			var $morelink = $str2.find("span.morelink");
			var $charcount = $str.text().length;
			if ($charcount > 72){
			$str.html($str.html().substring(0,70)+"...");
			}
			$str2.html($str2.html().substring(0,79)+"... ");
			// add link again
			$str2.append($morelink);
			}
			$cnt += 1;
		});
		//truncate news text different for health news
		jQuery('.healthNews .healthNewsText').each(function () {
			var browser=navigator.appName;
			var $morelink = jQuery(this).find("a");
			var $string = jQuery(this);

			if (browser == "Microsoft Internet Explorer"){
			$string.html($string.html().substring(0,50)+"... ");
			} else {
				$string.html($string.html().substring(0,59)+"... ");
			}
			$string.append($morelink);
		});
		// changing the morelink according to the categories
	}
}

function toggleOthersField(prefix, name) {

    if (jQuery("input[name='"+prefix+"']:checked").val() == name) {
    	jQuery("input[name='"+prefix+"_" +name+"']").attr('disabled','');
    } else {
    	jQuery("input[name='"+prefix+"_" +name+"']").attr('disabled', 'disabled');
    }
}

function handleOthersField(prefix, name) {
	jQuery("input[name='"+prefix+"']").change(function(){
		toggleOthersField(prefix, name);
	});
	toggleOthersField(prefix, name);
}


jQuery(document).ready(function(){
	newsStyleChanger();
	jQuery('#competitionSelect').change(function(){
		var url = jQuery(this).val();
		if (url.length>0) {
			window.location = url;
		}
	});

	jQuery('#competitionYears select').change(function(){
		jQuery('#competitionYears').submit();
	});

	jQuery('#cipButton').click(function(){
		jQuery('#cipInfo').toggle('fast');
	});
	jQuery('#cipButton2').click(function(){
		jQuery('#cipInfo2').toggle('fast');
	});

	jQuery('#cipInfo').click(function(){
		jQuery('#cipInfo').hide();
	});

	jQuery(".datepicker").datepicker($.extend({
			dateFormat: 'dd/mm/yy',
			changeYear: true,
			yearRange: '1900:2010',
			buttonImage: 'typo3conf/ext/csg/img/datepicker.png',
			showOn: 'both'
		},
		$.datepicker.regional[globalLanguage]
	));

	jQuery("#contact_birthdate_day,#contact_birthdate_month,#contact_birthdate_year").datepicker(
		$.extend({
			dateFormat: 'dd/mm/yy',
			changeYear: true,
			yearRange: '1900:2010',
			onSelect: function(dateText, inst) {

				jQuery('#contact_birthdate_day').val(
					dateText.substr(3,2)
				);
				jQuery('#contact_birthdate_month').val(
						dateText.substr(0,2)
				);
				jQuery('#contact_birthdate_year').val(
						dateText.substr(6,4)
				);
			}
		},
		$.datepicker.regional[globalLanguage]
	));

	handleOthersField('scheme', 'others');
	handleOthersField('submitted_by', 'others');
	handleOthersField('educacion_1_titulacio', 'si');
	handleOthersField('educacion_2_titulacio', 'si');


	jQuery('.tx-indexedsearch .tx-indexedsearch-browsebox:first').hide();

	jQuery('.topimage a:empty').remove();

	if (jQuery('.topimage').children().length > 1) {
		jQuery('.topimage').innerfade({
			speed: 'slow',
			timeout: 4000,
			type: 'sequence',
			containerheight: jQuery('.topimage img:first').height()+'px'
		});
	}

	jQuery('.aa').fontResize({
		defaultLabels:        '',
		//defaultSize:          "15px",
		defaultChangePercent: 20
	});
});

