// JavaScript Document

	function SubmitLoginForm(e) {

		if(CheckLoginForm())
			document.loginForm.submit();

		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();

		return false;

	}

	function CheckLoginForm() {

		if(blankStringRegExp.test(document.loginForm.username.value)) {
			alert(__lang_enter_your_username_email);
			document.loginForm.username.focus();
			return false;
		}

		if(!emailAddressRegExp.test(document.loginForm.username.value)) {
			alert(__lang_username_email_not_formated);
			document.loginForm.username.focus();
			return false;
		}

		if(document.loginForm.password.value == "") {
			alert(__lang_enter_password_for_account);
			document.loginForm.password.focus();
			return false;
		}

		return true;

	}

	function SubmitRegisterForm(e) {

		if(CheckRegisterForm())
			document.registerForm.submit();

		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();

		return false;

	}

	function CheckRegisterForm() {

		if(blankStringRegExp.test(document.registerForm.username.value)) {
			alert(__lang_enter_your_username_email);
			document.registerForm.username.focus();
			return false;
		}

		if(!emailAddressRegExp.test(document.registerForm.username.value)) {
			alert(__lang_username_email_not_formated);
			document.registerForm.username.focus();
			return false;
		}

		if(document.registerForm.password.value == "") {
			alert(__lang_enter_password_for_account);
			document.registerForm.password.focus();
			return false;
		}

		if(document.registerForm.password.value != document.registerForm.confirm_password.value) {
			alert(__lang_confirm_your_password);
			document.registerForm.confirm_password.focus();
			return false;
		}

		if(blankStringRegExp.test(document.registerForm.first_name.value)) {
			alert(__lang_enter_your_first_name);
			document.registerForm.first_name.focus();
			return false;
		}

		if(blankStringRegExp.test(document.registerForm.last_name.value)) {
			alert(__lang_enter_your_last_name);
			document.registerForm.last_name.focus();
			return false;
		}

		return true;

	}

	function SubmitSendPasswordForm(e) {

		if(CheckSendPasswordForm())
			document.forgotPasswordForm.submit();

		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();

		return false;

	}

	function CheckFullProfileForm(CheckForm) {

		if(CheckForm.iscompany[0] + "" != "undefined" && CheckForm.iscompany[1] + "" != "undefined")
			if(!CheckForm.iscompany[0].checked && !CheckForm.iscompany[1].checked) {
				alert(__lang_select_company_or_person);
				return false;
			}

		if(CheckForm.countrygroup.value == "") {
			alert(__lang_select_country_region);
			CheckForm.countrygroup.focus();
			return false;
		}

		if(CheckForm.first_name.value == "") {
			alert(__lang_enter_your_first_name);
			CheckForm.first_name.focus();
			return false;
		}

		if(CheckForm.last_name.value == "") {
			alert(__lang_enter_your_last_name);
			CheckForm.last_name.focus();
			return false;
		}

		if((CheckForm.iscompany[0] + "" != "undefined" && CheckForm.iscompany[0].checked) || CheckForm.iscompany.value == "0") {

			if(CheckForm.countrygroup.value == "ro") {

				//if(!validateCNP(CheckForm.ro_p_cnp.value)) {
				//	alert(__lang_enter_your_correct_cnp);
				//	CheckForm.ro_p_cnp.focus();
				//	return false;
				//}

				if(CheckForm.ro_p_address.value == "") {
					alert(__lang_enter_your_str_address);
					CheckForm.ro_p_address.focus();
					return false;
				}

				if(CheckForm.ro_p_city.value == "") {
					alert(__lang_enter_your_city);
					CheckForm.ro_p_city.focus();
					return false;
				}

				if(CheckForm.ro_p_state.value == "") {
					alert(__lang_enter_your_sector);
					CheckForm.ro_p_state.focus();
					return false;
				}

				if(CheckForm.ro_p_zip.value == "") {
					alert(__lang_enter_your_zip_code);
					CheckForm.ro_p_zip.focus();
					return false;
				}

			}

			if(CheckForm.countrygroup.value == "eu") {

				if(CheckForm.eu_p_address.value == "") {
					alert(__lang_enter_your_str_address);
					CheckForm.eu_p_address.focus();
					return false;
				}

				if(CheckForm.eu_p_city.value == "") {
					alert(__lang_enter_your_city);
					CheckForm.eu_p_city.focus();
					return false;
				}

				if(CheckForm.eu_p_country.value == "") {
					alert(__lang_select_your_country);
					CheckForm.eu_p_country.focus();
					return false;
				}

				if(CheckForm.eu_p_state.options.length > 0) {
					if(CheckForm.eu_p_state.value == "") {
						alert(__lang_select_your_state);
						CheckForm.eu_p_state.focus();
						return false;
					}
				}
				else
					if(CheckForm.eu_p_state_text.value == "") {
						alert(__lang_enter_your_state);
						CheckForm.eu_p_state_text.focus();
						return false;
					}

				if(CheckForm.eu_p_zip.value == "") {
					alert(__lang_enter_your_zip_code);
					CheckForm.eu_p_zip.focus();
					return false;
				}

			}

			if(CheckForm.countrygroup.value == "neu") {

				if(CheckForm.neu_p_address.value == "") {
					alert(__lang_enter_your_str_address);
					CheckForm.neu_p_address.focus();
					return false;
				}

				if(CheckForm.neu_p_city.value == "") {
					alert(__lang_enter_your_city);
					CheckForm.neu_p_city.focus();
					return false;
				}

				if(CheckForm.neu_p_country.value == "") {
					alert(__lang_select_your_country);
					CheckForm.neu_p_country.focus();
					return false;
				}

				if(CheckForm.neu_p_state.options.length > 0) {
					if(CheckForm.neu_p_state.value == "") {
						alert(__lang_select_your_state);
						CheckForm.neu_p_state.focus();
						return false;
					}
				}
				else
					if(CheckForm.neu_p_state_text.value == "") {
						alert(__lang_enter_your_state);
						CheckForm.neu_p_state_text.focus();
						return false;
					}

				if(CheckForm.neu_p_zip.value == "") {
					alert(__lang_enter_your_zip_code);
					CheckForm.neu_p_zip.focus();
					return false;
				}

			}

		}
		else {

			if(CheckForm.co_company.value == "") {
				alert(__lang_enter_your_company_name);
				CheckForm.co_company.focus();
				return false;
			}

			if(CheckForm.countrygroup.value == "ro") {

				if(CheckForm.ro_co_register.value == "") {
					alert(__lang_enter_your_company_reg_no);
					CheckForm.ro_co_register.focus();
					return false;
				}

				if(CheckForm.ro_co_cui.value == "") {
					alert(__lang_enter_your_company_cui);
					CheckForm.ro_co_cui.focus();
					return false;
				}

				if(CheckForm.ro_co_bank.value == "") {
					alert(__lang_enter_your_company_bank_name);
					CheckForm.ro_co_bank.focus();
					return false;
				}

				if(CheckForm.ro_co_account.value == "") {
					alert(__lang_enter_your_company_bank_acc);
					CheckForm.ro_co_account.focus();
					return false;
				}

				if(CheckForm.ro_co_address.value == "") {
					alert(__lang_enter_your_company_str_address);
					CheckForm.ro_co_address.focus();
					return false;
				}

				if(CheckForm.ro_co_city.value == "") {
					alert(__lang_enter_your_company_city);
					CheckForm.ro_co_city.focus();
					return false;

				}

				if(CheckForm.ro_co_state.value == "") {
					alert(__lang_enter_your_company_sector);
					CheckForm.ro_co_state.focus();
					return false;
				}

				if(CheckForm.ro_co_zip.value == "") {
					alert(__lang_enter_your_company_zip_code);
					CheckForm.ro_co_zip.focus();
					return false;
				}

			}

			if(CheckForm.countrygroup.value == "eu") {

				if(CheckForm.eu_co_vat.value == "") {
					alert(__lang_enter_your_company_vat_no);
					CheckForm.eu_co_vat.focus();
					return false;
				}

				if(CheckForm.eu_co_address.value == "") {
					alert(__lang_enter_your_company_str_address);
					CheckForm.eu_co_address.focus();
					return false;
				}

				if(CheckForm.eu_co_city.value == "") {
					alert(__lang_enter_your_company_city);
					CheckForm.eu_co_city.focus();
					return false;
				}

				if(CheckForm.eu_co_country.value == "") {
					alert(__lang_select_your_company_country);
					CheckForm.eu_co_country.focus();
					return false;
				}

				if(CheckForm.eu_co_state.options.length > 0) {
					if(CheckForm.eu_co_state.value == "") {
						alert(__lang_select_your_company_state);
						CheckForm.eu_co_state.focus();
						return false;
					}
				}
				else
					if(CheckForm.eu_co_state_text.value == "") {
						alert(__lang_enter_your_company_state);
						CheckForm.eu_co_state_text.focus();
						return false;
					}

				if(CheckForm.eu_co_zip.value == "") {
					alert(__lang_enter_your_company_zip_code);
					CheckForm.eu_co_zip.focus();
					return false;
				}

			}

			if(CheckForm.countrygroup.value == "neu") {

				if(CheckForm.neu_co_address.value == "") {
					alert(__lang_enter_your_company_str_address);
					CheckForm.neu_co_address.focus();
					return false;
				}

				if(CheckForm.neu_co_city.value == "") {
					alert(__lang_enter_your_company_city);
					CheckForm.neu_co_city.focus();
					return false;
				}

				if(CheckForm.neu_co_country.value == "") {
					alert(__lang_select_your_company_country);
					CheckForm.neu_co_country.focus();
					return false;
				}

				if(CheckForm.neu_co_state.options.length > 0) {
					if(CheckForm.neu_co_state.value == "") {
						alert(__lang_select_your_company_state);
						CheckForm.neu_co_state.focus();
						return false;
					}
				}
				else
					if(CheckForm.neu_co_state_text.value == "") {
						alert(__lang_enter_your_company_state);
						CheckForm.neu_co_state_text.focus();
						return false;
					}

				if(CheckForm.neu_co_zip.value == "") {
					alert(__lang_enter_your_company_zip_code);
					CheckForm.neu_co_zip.focus();
					return false;
				}

			}

		}

		if(CheckForm.phone.value == "") {
			alert(__lang_enter_your_phone_number);
			CheckForm.phone.focus();
			return false;
		}

		/*
		if(CheckForm.fax.value == "") {
			alert(__lang_enter_your_fax_number);
			CheckForm.fax.focus();
			return false;
		}
		*/

		return true;

	}

	function CheckSendPasswordForm() {

		if(blankStringRegExp.test(document.forgotPasswordForm.username.value)) {
			alert(__lang_enter_your_username_email);
			document.forgotPasswordForm.username.focus();
			return false;
		}

		if(!emailAddressRegExp.test(document.forgotPasswordForm.username.value)) {
			alert(__lang_username_email_not_formated);
			document.forgotPasswordForm.username.focus();
			return false;
		}

		return true;

	}

	function PersonCompanySelected() {

		ShowFieldPanels();

	}

	function CountrySelected() {
		ShowFieldPanels();
	}

	function ShowFieldPanels() {

		isPersonRadio = document.getElementById('iscompany_0');
		isCompanyRadio = document.getElementById('iscompany_1');
		isCompanyValue = document.getElementById('iscompany');
		countryGroupSelect = document.getElementById('countrygroup');

		// Hide the Personal Info panels if visible
		document.getElementById('divRoPersonalInfo').style.display = "none";
		document.getElementById('divEUPersonalInfo').style.display = "none";
		document.getElementById('divNonEUPersonalInfo').style.display = "none";

		// Hide the Company Info panels if visible
		document.getElementById('divRoCompanyInfo').style.display = "none";
		document.getElementById('divEUCompanyInfo').style.display = "none";
		document.getElementById('divNonEUCompanyInfo').style.display = "none";

		// Hide the General Info panels if visible
		document.getElementById('divSaveInfo').style.display = "none";
		document.getElementById('divNameInfo').style.display = "none";
		document.getElementById('divCompanyInfo').style.display = "none";
		document.getElementById('divPhoneFaxInfo').style.display = "none";

		if ((isPersonRadio && isPersonRadio.checked) ||
			(isCompanyValue && isCompanyValue.value == "0")) {

			if(countryGroupSelect.value != "") {

				document.getElementById('divNameInfo').style.display = "block";
				document.getElementById('divPhoneFaxInfo').style.display = "block";

				if(countryGroupSelect.value == "ro")
					document.getElementById('divRoPersonalInfo').style.display = "block";

				if(countryGroupSelect.value == "eu")
					document.getElementById('divEUPersonalInfo').style.display = "block";

				if(countryGroupSelect.value == "neu")
					document.getElementById('divNonEUPersonalInfo').style.display = "block";

				document.getElementById('divSaveInfo').style.display = "block";

			}

		}

		if ((isCompanyRadio && isCompanyRadio.checked) ||
			(isCompanyValue && isCompanyValue.value == "1")) {

			if(countryGroupSelect.value != "") {

				document.getElementById('divNameInfo').style.display = "block";
				document.getElementById('divCompanyInfo').style.display = "block";
				document.getElementById('divPhoneFaxInfo').style.display = "block";

				if(countryGroupSelect.value == "ro")
					document.getElementById('divRoCompanyInfo').style.display = "block";

				if(countryGroupSelect.value == "eu")
					document.getElementById('divEUCompanyInfo').style.display = "block";

				if(countryGroupSelect.value == "neu")
					document.getElementById('divNonEUCompanyInfo').style.display = "block";

				document.getElementById('divSaveInfo').style.display = "block";

			}

		}
		
	}

	function SubmitGeneralProfileForm(e) {
	
		if(CheckFullProfileForm(document.profileForm)) {

			document.profileForm.submit();
	
		}
	
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
		return false;
	
	}

	function SubmitUsernameProfileForm(e) {
	
		if(CheckUsernameProfileForm()) {

			document.profileForm.submit();
	
		}
	
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
		return false;
	
	}

	function CheckUsernameProfileForm() {

		if(blankStringRegExp.test(document.profileForm.username.value)) {
			alert(__lang_enter_your_username_email);
			document.profileForm.username.focus();
			return false;
		}

		if(!emailAddressRegExp.test(document.profileForm.username.value)) {
			alert(__lang_username_email_not_formated);
			document.profileForm.username.focus();
			return false;
		}

		return true;

	}

	function SubmitPasswordProfileForm(e) {
	
		if(CheckPasswordProfileForm()) {

			document.profileForm.submit();
	
		}
	
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
		return false;
	
	}

	function CheckPasswordProfileForm() {

		if(document.profileForm.password.value == "") {
			alert(__lang_enter_new_password_for_account);
			document.profileForm.password.focus();
			return false;
		}

		if(document.profileForm.password.value != document.profileForm.confirm_password.value) {
			alert(__lang_confirm_your_new_password);
			document.profileForm.confirm_password.focus();
			return false;
		}

		return true;

	}

	function changeCountryOption(obj, selectedState, focusState) {

		posIndex = 0;
		objName = obj.name;
		for (var j=0; j<2; j++) {
			posIndex = objName.indexOf("_", posIndex)+1;
		}

		prefix = objName.substring(0, posIndex);

		divZones = document.getElementById(prefix + "zones_div");
		divZonesText = document.getElementById(prefix + "zones_text_div");

		zoneList = zonesArray[obj.value];		
		if (zoneList != undefined) {

			zonesObject = document.getElementById(prefix + "state");
				
			zonesObject.length = 0;

			appendOptionLast(zonesObject, "", "--", false);

			for (element in zoneList ) {
				
				SelectThis = (selectedState == element);
				
				appendOptionLast(zonesObject, element, zoneList[element], SelectThis);
			}

			divZonesText.style.display = "none";
			divZones.style.display = "block";

			if (focusState) {
				zonesObject.focus();
			}

		} else {

			divZones.style.display = "none";
			divZonesText.style.display = "block";

		}
		
	}

	function updateStates(selectedState, focusState) {
		countryGroupSelect = document.getElementById('countrygroup');

		if(countryGroupSelect.value != "") {

			if(countryGroupSelect.value == "eu") {

				countrySelectName = "eu_p_country";
				countryObj = document.getElementById(countrySelectName);
				changeCountryOption(countryObj, selectedState, focusState);

				countrySelectName = "eu_co_country";
				countryObj = document.getElementById(countrySelectName);
				changeCountryOption(countryObj, selectedState, focusState);

			}

			if(countryGroupSelect.value == "neu") {

				countrySelectName = "neu_p_country";
				countryObj = document.getElementById(countrySelectName);
				changeCountryOption(countryObj, selectedState, focusState);

				countrySelectName = "neu_co_country";
				countryObj = document.getElementById(countrySelectName);
				changeCountryOption(countryObj, selectedState, focusState);

			}

		}

	}

	function appendOptionLast(elSel, valueString, textString, SelectThis) {
		
		var elOptNew = document.createElement('option');
		elOptNew.text =  textString;
		elOptNew.value = valueString;
		
		elOptNew.selected = SelectThis;
		
		try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			elSel.add(elOptNew); // IE only
		}
	}

	function validateCNP(s) {
		var suma=0;
		var mesaj="";

		if(s.length==13) {

			suma=parseInt(s.charAt(0))*2+parseInt(s.charAt(1))*7+parseInt(s.charAt(2))*9+
				 parseInt(s.charAt(3))*1+parseInt(s.charAt(4))*4+parseInt(s.charAt(5))*6+
				 parseInt(s.charAt(6))*3+parseInt(s.charAt(7))*5+parseInt(s.charAt(8))*8+
				 parseInt(s.charAt(9))*2+parseInt(s.charAt(10))*7+parseInt(s.charAt(11))*9;

			suma=suma%11;

			if(suma==10) suma=1;

			if(suma==parseInt(s.charAt(12)))
				return true;
			else
				return false;
		
		}
		else
			return false;

	}

	function SubmitPartnersForm(e) {
	
		if(CheckPartnersForm(document.partnersForm)) {

			document.partnersForm.submit();
	
		}
	
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
		return false;
	
	}

	function CheckPartnersForm(CheckForm) {

		if(blankStringRegExp.test(CheckForm.full_name.value)) {
			alert(__lang_enter_your_full_name);
			CheckForm.full_name.focus();
			return false;
		}

		if(blankStringRegExp.test(CheckForm.hotel.value)) {
			alert(__lang_enter_your_hotel);
			CheckForm.hotel.focus();
			return false;
		}

		if(blankStringRegExp.test(CheckForm.telephone.value)) {
			alert(__lang_enter_your_phone_number);
			CheckForm.telephone.focus();
			return false;
		}

		if(!phoneNumberRegExp.test(CheckForm.telephone.value)) {
			alert(__lang_phone_number_not_correct);
			CheckForm.telephone.focus();
			return false;
		}

		if(blankStringRegExp.test(CheckForm.email.value)) {
			alert(__lang_enter_your_email);
			CheckForm.email.focus();
			return false;
		}

		if(!emailAddressRegExp.test(CheckForm.email.value)) {
			alert(__lang_email_not_formated);
			CheckForm.email.focus();
			return false;
		}

		return true;

	}

	function CheckCreditCardInfo(form) {
		if (form.credit_card_type.value == "") {
			alert(__lang_enter_credit_card_type);
			form.credit_card_type.focus();
			return false;	
		}

		if (form.credit_card_name.value == "") {
			alert(__lang_enter_credit_card_name);
			form.credit_card_name.focus();
			return false;	
		}

		if (form.credit_card_number.value == "") {
			alert(__lang_enter_credit_card_number);
			form.credit_card_number.focus();
			return false;	
		}

		if (!checkCreditCard (form.credit_card_number.value,form.credit_card_type.value)) {
			alert(__lang_invalid_credit_card_number);
			form.credit_card_number.focus();
			return false;		
		}

		if (form.credit_card_month.value == "") {
			alert(__lang_enter_credit_card_month);
			form.credit_card_month.focus();
			return false;	
		}

		if (form.credit_card_year.value == "") {
			alert(__lang_enter_credit_card_year);
			form.credit_card_year.focus();
			return false;	
		}

		return true;
	}
