﻿
jQuery(function() {
	clearOnFocus('searchinput');
	jQuery('#login .tx-felogin-pi1 form').attr('action', 'index.php?id=43&no_cache=1');
	
	var fe_user_team = jQuery('#fe_user_team').html();
	if(fe_user_team != null)
	{
		jQuery('#mailformTeam').attr('value', fe_user_team);
	}
	
	var register_country = jQuery('#tx-srfeuserregister-pi1-country');
	if(jQuery(register_country).attr('type') == 'text')
	{
		value = jQuery(register_country).attr('value');
		var radioForm  = '<input type="hidden" name="FE[fe_users][country]" title="Gib hier Dein Land ein." maxlength="60" size="20" class="tx-srfeuserregister-pi1-text" id="tx-srfeuserregister-pi1-country">';
		radioForm  += '<input type="checkbox" id="temp_community_facebook" value="Facebook" name="temp_community[]" /><label for="temp_community_facebook">Facebook</label><br/>';
		radioForm += '<input type="checkbox" id="temp_community_myspace" value="MySpace" name="temp_community[]" /><label for="temp_community_myspace">MySpace</label><br/>';
		radioForm += '<input type="checkbox" id="temp_community_studivz" value="StudiVZ" name="temp_community[]" /><label for="temp_community_studivz">StudiVZ</label><br/>';
		radioForm += '<input type="checkbox" id="temp_community_xing" value="Xing" name="temp_community[]" /><label for="temp_community_xing">Xing</label><br/>';
		radioForm += '<input type="checkbox" id="temp_community_linkedin" value="LinkedIn" name="temp_community[]" /><label for="temp_community_linkedin">LinkedIn</label><br/>';
		
		var regForm = document.getElementById('tx-srfeuserregister-pi1-fe_users_form');
		regForm.onsubmit = function() {
			var values = getCheckboxValue(this.elements['temp_community[]']);
			this.elements['FE[fe_users][country]'].value = values;
		};
		
		// set hidden
		jQuery(register_country).after(radioForm);
		jQuery(register_country).detach();
		
		// set values checked		
		if(value)
		{
			setCheckboxValue(regForm.elements['temp_community[]'], value);
		}
	}
});

function setCheckboxValue(checkboxes, values)
{
	for (var i = 0; i < checkboxes.length; i++)
	{
		if (values.indexOf(checkboxes[i].value) >= 0)
		{
			checkboxes[i].checked = true;
		}
	}
}

function getCheckboxValue(checkboxes)
{
	var c_value = "";
	for (var i = 0; i < checkboxes.length; i++)
	{
		if (checkboxes[i].checked)
		{
			c_value = c_value + ',' + checkboxes[i].value;
		}
	}
	return c_value.substr(1);
}


function setPageTitle(elSelector)
{
	el = document.getElementById(elSelector);
	el.value = document.URL;
}

function clearOnFocus(elSelector)
{
	el = document.getElementById(elSelector);
	if(el)
	{
		jQuery (el).data('initialValue', el.value);
		jQuery (el).focus(function() {
			if(this.value == jQuery (this).data('initialValue'))
				this.value = '';
		});
		jQuery (el).blur(function() {
			if(this.value == '')
				this.value = jQuery (this).data('initialValue');
		});
	}
}
