

window.onload = function() {
	/* ************ all pages ************************************************** */
	/* .bottomlink */
	var elA = document.getElementsByTagName('a');
	for(var i = 0; i < elA.length; i++) {
		if(elA[i].className == 'bottomLink') {
			elA[i].onclick = function() {
				window.open(this.href, '', 'width=400,height=500,resizable');
				return false;
			}
		}
	}

	/* #customer_login */
	if(el_customer_login = document.getElementById('customer_login')) {
		el_customer_login.onsubmit = function() {
			var el_customer_username = document.getElementById('customer_username');
			var checks = [
				[el_customer_username, 'non_blank', error_900],
				[el_customer_username, 'email', error_910]
			];
			return validate(checks);
		}
	}

	/* ************ contact.php **************************************************** */
	$("#contact form").submit(function() {
		var checks = [
			[$("#realname").get(0), 'non_blank', 'Venligst udfyld »Navn«'],
			[$("#reply_to").get(0), 'non_blank', 'Venligst udfyld »Email«'],
			[$("#reply_to").get(0), 'email', 'Ups! »Email« er ugyldig'],
			[$("#subject").get(0), 'non_blank', 'Venligst udfyld »Emne«'],
			[$("#message").get(0), 'non_blank', 'Venligst udfyld »Besked«']
		];
		return validate(checks);
	});
	
	/* ************ business-sign-up.php **************************************************** */
	/* #business-sign-up #registration */
	if(document.getElementById('business-sign-up')) {
		if(document.getElementById('registration')) {
			var input_company = document.getElementById('company');
			var input_regNo = document.getElementById('regNo');
			var input_regNo2 = document.getElementById('regNo2');
			var input_description = document.getElementById('description');
			var input_postalcode = document.getElementById('postalcode');
			var input_city = document.getElementById('city');
			var input_addr1 = document.getElementById('addr1');
			var input_phone = document.getElementById('phone');
			var input_email = document.getElementById('email');
			var input_bankaccount = document.getElementById('bankaccount');
			var input_bankaccount2 = document.getElementById('bankaccount2');
			var input_bic = document.getElementById('bic');
			var input_bank = document.getElementById('bank');
			var input_d_lastname = document.getElementById('d_lastname');
			var input_d_middlename = document.getElementById('d_middlename');
			var input_d_firstname = document.getElementById('d_firstname');
			var input_d_title = document.getElementById('d_title');
			var input_a_lastname = document.getElementById('a_lastname');
			var input_a_middlename = document.getElementById('a_middlename');
			var input_a_firstname = document.getElementById('a_firstname');
			var input_pw = document.getElementById('pw');
			var input_pw_repeat = document.getElementById('pw_repeat');
			var input_terms = document.getElementById('terms');

			var form_registration = document.getElementById('registration');
			form_registration.onsubmit = function () {
				var checks = [
					[input_company, 'non_blank', '«Полное название организации» отсутствует'],
					[input_regNo, 'non_blank', '«ИНН» отсутствует'],
					[input_regNo2, 'non_blank', '«КПП» отсутствует'],
					[input_description, 'non_blank', '«Описание деятельности компании» отсутствует'],
					[input_postalcode, 'non_blank', '«Юридический адрес: Индекс» отсутствует'],
					[input_city, 'non_blank', '«Юридический адрес: Город» отсутствует'],
					[input_addr1, 'non_blank', '«Юридический адрес: улица, дом» отсутствует'],
					[input_phone, 'non_blank', '«Телефон» отсутствует'],
					[input_email, 'non_blank', '«Электронная почта» отсутствует'],
					[input_email, 'email', '«Электронная почта» недействительна'],
					[input_bankaccount, 'non_blank', '«Расчетный счет» отсутствует'],
					[input_bankaccount2, 'non_blank', '«Корреспондентский счет» отсутствует'],
					[input_bic, 'non_blank', '«БИК» отсутствует'],
					[input_bank, 'non_blank', '«Название банка» отсутствует'],
					[input_d_lastname, 'non_blank', '«Информация о руководителе: Фамилия» отсутствует'],
					[input_d_firstname, 'non_blank', '«Информация о руководителе: Имя» отсутствует'],
					[input_d_middlename, 'non_blank', '«Информация о руководителе: Отчество» отсутствует'],
					[input_d_title, 'non_blank', '«Информация о руководителе: Должность» отсутствует'],
					[input_a_lastname, 'non_blank', '«Информация о Контактном лице: Фамилия» отсутствует'],
					[input_a_firstname, 'non_blank', '«Информация о Контактном лице: Имя» отсутствует'],
					[input_a_middlename, 'non_blank', '«Информация о Контактном лице: Отчество» отсутствует'],
					[input_pw, 'password', 'Пароль и должен быть не менее 8 и не более 15 знаков'],
					[[input_pw, input_pw_repeat], 'identity', 'Пароли не были идентичны'],
					//[input_terms, 'checkbox', 'Вы должны принять условия']
				];
				return validate(checks);
			}
		}
	}
	
	/* ************ private-sign-up.php **************************************************** */
	/* #private-sign-up #registration */
	
	/* ************ forgotten.php **************************************************** */
	/* #forgotten #forgotten_password_form */
	if(document.getElementById('forgotten')) {
		if(document.getElementById('forgotten_password_form')) {
			var el_forgotten_password_form = document.getElementById('forgotten_password_form');
			el_forgotten_password_form.onsubmit = function() {
				var inputEmail = document.getElementById('email');
				var checks = [
					[inputEmail, 'non_blank', error_message_101],
					[inputEmail, 'email', error_message_102]
				];
				return validate(checks);
			}
		}
	}

	/* ************ account-password.php **************************************************** */
	/* #account-password #change_password_form */
	if(document.getElementById('account-password')) {
		if(document.getElementById('change_password_form')) {
			var el_change_password_form = document.getElementById('change_password_form');
			el_change_password_form.onsubmit = function() {
				var input_pw_new = document.getElementById('pw_new');
				var input_pw_repeat = document.getElementById('pw_repeat');
				var checks = [
					[input_pw_new, 'password', error_message_2],
					[[input_pw_new, input_pw_repeat], 'identity', error_message_3]
				];
				return validate(checks);
			}
		}
	}

	/* ************ account-email.php **************************************************** */
	/* #account-email #change_email_form */
	if(document.getElementById('account-email')) {
		if(document.getElementById('change_email_form')) {
			var el_change_email_form = document.getElementById('change_email_form');
			el_change_email_form.onsubmit = function() {
				var input_email_new = document.getElementById('email_new');
				var checks = [
					[input_email_new, 'non_blank', error_message_270],
					[input_email_new, 'email', error_message_271]
				];
				return validate(checks);
			}
		}
	}
	
	/* ************ account-recreate-password.php **************************************************** */
	/* #account-recreate-password #recreate_password_form */
	/*
	if(document.getElementById('account-recreate-password')) {
		if(document.getElementById('recreate_password_form')) {
			var el_recreate_password_form = document.getElementById('recreate_password_form');
			el_recreate_password_form.onsubmit = function() {
				var input_newPassword = document.getElementById('newPassword');
				var input_newPasswordAgain = document.getElementById('newPasswordAgain');
				var checks = [
					[input_newPassword, 'password', 'Ny adgangskode skal være mellem 8 og 15 tegn langt'],
					[[input_newPassword, input_newPasswordAgain], 'identity', 'Adgangskoder er ikke ens']
				];
				return validate(checks);
			}
		}
	}
	*/
	$("#account-recreate-password form").submit(function() {
		var checks = [
			[$("#newPassword").get(0), 'password', 'Ny adgangskode skal være mellem 8 og 15 tegn langt'],
			[[$("#newPassword").get(0), $("#newPasswordAgain").get(0)], 'identity', 'Adgangskoder er ikke ens']
		];
		return validate(checks);
	});

	
	/* ************ checkout-sign-in.php **************************************************** */
	/* #checkout-signin #checkout_sign_in_form */
	if(document.getElementById('checkout-signin')) {
		var el_checkout_sign_in_form = document.getElementById('checkout_sign_in_form');
		el_checkout_sign_in_form.onsubmit = function() {
			var el_email = document.getElementById('email');
			var checks = [];
			checks[0] = [el_email, 'email', 'Invalid email address'];
			return validate(checks);
		}
	}

	/* ************ delivery.php **************************************************** */
	/* #delivery #delivery_address_form */
	if(document.getElementById('delivery')) {
		var el_delivery_address_form = document.getElementById('delivery_address_form');
		el_delivery_address_form.onsubmit = function() {
			var el_use_different = document.getElementById('use_different');
			if(el_use_different.checked) {
				var el_att = document.getElementById('att');
				var el_addr1 = document.getElementById('addr1');
				var el_city = document.getElementById('city');
				var el_postalcode = document.getElementById('postalcode');
				var el_country = document.getElementById('country');
				checks = [
					[el_att, 'non_blank', 'Please fill in Name'],
					[el_addr1, 'non_blank', 'Please fill in Address'],
					[el_city, 'non_blank', 'Please fill in City'],
					[el_postalcode, 'non_blank', 'Please fill in Postal code'],
					[el_country, 'non_blank', 'Please fill in Country']
				];
			}
			return validate(checks);
		}
	}

	/* ************ product.php ************************************************** */
	
	/* ************ productcat.php ************************************************** */
	/* #num_selector */
	var elNumSelector;
	if(elNumSelector = document.getElementById('num_selector')) {
		elNumSelector.onchange = function() {
			location.href = this.value;
		}
	}

	if ($("#productFlicker").get(0)) {
		if(typeof(slides) != 'undefined') {
			slideShow();
		}
	}
}











