var language 	= null;


function checkCountryStates() {
	if (document.applicationForm.country.value == 'US')
		document.applicationForm.state.disabled = false;
	else if (document.applicationForm.country.value == 'UK')
		document.applicationForm.state.disabled = false;
	else
		document.applicationForm.state.disabled = true;
}

function checkCountry() {
	if (document.applicationForm.country.value == 'UK')
		document.applicationForm.cityCode.disabled = false;
	else
		document.applicationForm.cityCode.disabled = true;
}

function changeRegion() {
	document.applicationForm.region.value = document.applicationForm.cityCode.value;
}

function toggleDateTime() {
	if (document.getElementById('tddAnytime').checked == true) {
		document.getElementById('tddMonth').disabled = true;
		document.getElementById('tddDay').disabled = true;
		document.getElementById('tddYear').disabled = true;
		document.getElementById('tddHour').disabled = true;
		document.getElementById('tddMinute').disabled = true;
	}
	else {
		document.getElementById('tddMonth').disabled = false;
		document.getElementById('tddDay').disabled = false;
		document.getElementById('tddYear').disabled = false;
		document.getElementById('tddHour').disabled = false;
		document.getElementById('tddMinute').disabled = false;
	}
}

function checkFormData(lang, form) {
	msg = null;
	
	/**
	 * STEP 1
	 */
	if (document.applicationForm.username && document.applicationForm.username.value == "") {
		toggleDiv('step1');
		
		document.applicationForm.username.focus();
		msg = getErrorMsg("e_nousername", lang);
		
		alert(msg);
		
		return false;
	}
	else if (verifyUsername(document.applicationForm.username.value) == true) {
		toggleDiv('step1');
		
		document.applicationForm.username.focus();
		msg = getErrorMsg("e_invalidusername", lang);
		
		alert(msg);
		
		return false;
	}
	else if (checkUsername(document.applicationForm.username.value) == true) {
		toggleDiv('step1');
		
		document.applicationForm.username.focus();
		msg = getErrorMsg("e_duplicateusername", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.firstname.value == "") {
		toggleDiv('step1');
		
		document.applicationForm.firstname.focus();
		msg = getErrorMsg("e_nofirstname", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.lastname.value == "") { 
		toggleDiv('step1');
		
		document.applicationForm.lastname.focus();
		msg = getErrorMsg("e_nolastname", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.email.value == "") {
		toggleDiv('step1');
		
		document.applicationForm.email.focus();
		msg = getErrorMsg("e_noemail", lang);
		
		alert(msg);
		
		return false;
	}
	else if (checkEmail(document.applicationForm.email.value) == false) {
		toggleDiv('step1');
		
		document.applicationForm.email.focus();
		
		return false;
	}
	
	
	/**
	 * STEP 2
	 */
	else if (document.applicationForm.dobDay.value == "0") { 
		toggleDiv('step2');
		
		document.applicationForm.dobDay.focus();
		msg = getErrorMsg("e_nodobday", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.dobMonth.value == "0") { 
		toggleDiv('step2');
		
		document.applicationForm.dobMonth.focus();
		msg = getErrorMsg("e_nodobmonth", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.dobYear.value == "0") { 
		toggleDiv('step2');
		
		document.applicationForm.dobYear.focus();
		msg = getErrorMsg("e_nodobyear", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.gender.value == "0") {  
		toggleDiv('step2');
		
		document.applicationForm.gender.focus();
		msg = getErrorMsg("e_nogender", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.street.value == "") {  
		toggleDiv('step2');
		
		document.applicationForm.street.focus();
		msg = getErrorMsg("e_noaddress", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.cityCode.value == "0") {  
		toggleDiv('step2');
		
		document.applicationForm.cityCode.focus();
		msg = getErrorMsg("e_nocityregion", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.zip.value == "") { 
		toggleDiv('step2');
		
		document.applicationForm.zip.focus();
		msg = getErrorMsg("e_nozip", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.city.value == "") { 
		toggleDiv('step2');
		
		document.applicationForm.city.focus();
		msg = getErrorMsg("e_nocity", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.cellular.value == "") {  
		toggleDiv('step2');
		
		document.applicationForm.cellular.focus();
		msg = getErrorMsg("e_nocellular", lang);
		
		alert(msg);
		
		return false;
	}
	
	
	/**
	 * STEP 3
	 */
	else if (document.applicationForm.category.value == "0") { 
		toggleDiv('step3');
		
		document.applicationForm.category.focus();
		msg = getErrorMsg("e_nocategory", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.tddLocation.value == "") { 
		toggleDiv('step3');
		
		document.applicationForm.tddLocation.focus();
		msg = getErrorMsg("e_nolocation", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.tddDescription.value == "") { 
		toggleDiv('step3');
		
		document.applicationForm.tddDescription.focus();
		msg = getErrorMsg("e_nodescription", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.tddDescription.value.length < 125) { 
		toggleDiv('step3');
		
		document.applicationForm.tddDescription.focus();
		msg = getErrorMsg("e_shortdescription", lang);
		
		alert(msg);
		
		return false;
	}
	//else if (document.applicationForm.tddAnytime.checked == false && document.applicationForm.tddMonth.value == 0) { // && selectedTab.id == 'tab3') {
	else if (document.applicationForm.tddMonth.value == 0) { 
		toggleDiv('step3');
		
		document.applicationForm.tddMonth.focus();
		msg = getErrorMsg("e_nomonth", lang);
		
		alert(msg);
		
		return false;
	}
	//else if (document.applicationForm.tddAnytime.checked == false && document.applicationForm.tddDay.value == 0) { // && selectedTab.id == 'tab3') {
	else if (document.applicationForm.tddDay.value == 0) { 
		toggleDiv('step3');
		
		document.applicationForm.tddDay.focus();
		msg = getErrorMsg("e_noday", lang);
		
		alert(msg);
		
		return false;
	}
	//else if (document.applicationForm.tddAnytime.checked == false && document.applicationForm.tddYear.value == 0) { // && selectedTab.id == 'tab3') {
	else if (document.applicationForm.tddYear.value == 0) { 
		toggleDiv('step3');
		
		document.applicationForm.tddYear.focus();
		msg = getErrorMsg("e_noyear", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.hairstyle.value == "0") { 
		toggleDiv('step3');
		
		document.applicationForm.hairstyle.focus();
		msg = getErrorMsg("e_nohairstyle", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.character.value == "0") { 
		toggleDiv('step3');
		
		document.applicationForm.character.focus();
		msg = getErrorMsg("e_nocharacter", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.dresscode.value == "0") {  
		toggleDiv('step3');
		
		document.applicationForm.dresscode.focus();
		msg = getErrorMsg("e_nodresscode", lang);
		
		alert(msg);
		
		return false;
	}
	
	
	/**
	 * STEP 4 
	 */
	else if (document.applicationForm.userPhoto.value == "") {  
		toggleDiv('step4');
		
		//document.applicationForm.userPhoto.focus();
		msg = getErrorMsg("e_nouserphoto", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.agree.checked == false) {  
		toggleDiv('step4');
		
		//document.applicationForm.agree.focus();
		msg = getErrorMsg("e_notagreed", lang);
		
		alert(msg);
		
		return false;
	}
	else if (document.applicationForm.security_string.value == "") {  
		toggleDiv('step4');
		
		document.applicationForm.security_string.focus();
		msg = getErrorMsg("e_nosecuritystring", lang);
		
		alert(msg);
		
		return false;
	}
	
	return true;
}

function updateUserPhoto(id, image) {
	document.applicationForm.userPhoto.value = id;
	document.applicationForm.userPhotoImg.src = image;
}

function checkUsername(username) {
	retVal = false;
	
	for (i = 0; i < usernames.length; i++) {
		if (usernames[i] == username)
			retVal = true;
	}
	
	return retVal;
}

function verifyUsername(username) {
	retVal = false;
	
	var Set='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ§1234567890_-';
	
	for (i=0; i<=username.length; i++) {
		character = username.charAt(i);
		
     	if (Set.indexOf(character) == -1) 
			retVal = true;
	}
		
	return retVal;
}

function nextStep() {
	//alert(selectedTab.id);
	
	if (checkFormDataBeforeNextStep(language, 'new')) {
		toggleTabContent(document.getElementById(nextTab), contentTab);	
		document.location.href = '#formBegin';
	}
	
	if (selectedTab.id == 'tab1') {
		nextTab		= 'tab2';
		contentTab	= 'userTab';
	}
	else if (selectedTab.id == 'tab2') {
		nextTab		= 'tab3';
		contentTab	= 'tddTab';
	}
	else if (selectedTab.id == 'tab3') {
		nextTab 	= 'tab4';
		contentTab	= 'imageTab';
	}		
}
