var url = document.getElementById('siteurl').value;

$(function()
{
  Date.format = 'yyyy-mm-dd';
	$('.date-pick').datePicker({startDate:'1996-01-01'});
});

//this function removes unwanted characters on typing
function removeSpecialChars(id)
{
	var field = document.getElementById(id);
	var maintainplus = '';
	var numval = field.value;
	if ( numval.charAt(0)=='+' ){ var maintainplus = '';}
	curphonevar = numval.replace(/[\\! \"£@$%^&*+={};:'()#~,¦\/<>?|`¬\]\[]/g,'');
	field.value = maintainplus + curphonevar;
	var maintainplus = '';
	field.focus;
}

function tabshow(id, no_of_tabs)
{
	if(id != '')
	{
		for(i = 1; i<= no_of_tabs; i++)
		{
			document.getElementById('tab'+i).style.display = 'none';
		}
		document.getElementById(id).style.display = 'block';
	}
}



function show_chart_div(value)
{
	document.getElementById('chart_articles').style.display = 'none';
	document.getElementById('chart_departments').style.display = 'none';
	if(value == 'A')
	{
		document.getElementById('chart_articles').style.display = 'block';
	}
	else if(value == 'D')
	{
		document.getElementById('chart_departments').style.display = 'block';
	}
}



//=======================================================


function checkAvailability(username, div)
{
	$.get(url+"users/check_username_availability/" + username, function(data){
			$('#' + div).html(data);
		});
}



function checkAvailabilityEdit(username, div, userid)
{
	$.get(url+"users/check_username_availability_edit/" + username + '/user_id:'+userid, function(data){
			$('#' + div).html(data);
		});
}



function copyAddress()
{
	if(document.getElementById('same_as_above').checked)
	{
		document.getElementById('UserYaddress').value = document.getElementById('UserGaddress').value;
	}
}



function checkUsernameAvailabilityOnRegistration(username)
{
	if(username != '')
	{
		$.get(url+"users/check_username_availability_on_registration/" + username, function(data) {
				$('#username_registration').html(data);
			});
	}
}

function checkPasswordStrengthOnRegistration(password)
{
	if(password != '')
	{
		$.get(url+"users/check_password_strength_on_registration/" + password, function(data) {
				$('#password_registration').html(data);
			});
	}
}


function checkQ1(value)
{
	if(document.getElementById('UserSecquestion2').value == value)
	{
		alert('The question already selected, please select another one');
		document.getElementById('UserSecquestion').value = '';
	}
}

function checkQ2(value)
{
	if(document.getElementById('UserSecquestion').value == value)
	{
		alert('The question already selected, please select another one');
		document.getElementById('UserSecquestion2').value = '';
	}
}


function divshowHear(value)
{
	if(value == 'Others')
	{
		document.getElementById('hear').style.display = 'block';
	}
	else
	{
		document.getElementById('hear').style.display = 'none';
		document.getElementById('UserHearAboutOthers').value = '';
	}
}



function divshowSurveyOptions(value)
{
	document.getElementById('SurveyQuestionOption1').value = '';
	document.getElementById('SurveyQuestionOption2').value = '';
	document.getElementById('SurveyQuestionOption3').value = '';
	document.getElementById('SurveyQuestionOption4').value = '';
	document.getElementById('SurveyQuestionOption5').value = '';
	document.getElementById('SurveyQuestionOption6').value = '';
	
	if(value == 'C')
	{
		document.getElementById('answer_options').style.display = 'block';
	}
	else
	{
		document.getElementById('answer_options').style.display = 'none';
	}
}
