function isIE()
{
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function _onmouseout(_scr, _Img)
{
	eval ("document.images." + _Img + ".src = '" + _scr + "'" );
}

function checkAutoInfill()
{
	var isChecked = false;
	for ( i = 0; i < 4; i++ )
	{
		if ( document.infill_price_form.infill_price_radio[i].checked )
		{
			isChecked = true;
		}
	}

	if ( !isChecked )
	{
		alert("Please, select sum.");
		return false;
	}

	if ( document.infill_price_form.infill_price_radio[3].checked )
	{
		var re = new RegExp("^(\\d)+(\\.(\\d)+)?$");
		var ares = re.exec(document.infill_price_form.infill_price_edit.value);
		if ( null == ares )
		{
			alert("Incorrect sum number! Please, enter correct number.");
			return false;
		}
	}

	var cartItemsNumber = parseInt(document.infill_price_form.cart_items_number.value);

	if ( cartItemsNumber > 0 )
	{
		if ( confirm("Do you want to replace products in the cart?\n\"OK\" - replace products in the cart.\n\"Cancel\" - add products to the cart.") )
		{
			document.infill_price_form.clear.value = "1";
		}
		else
		{
			document.infill_price_form.clear.value = "0";
		}
	}

	return true;
}

function checkIsIntNumberCorrect(sNumber)
{
	var re = new RegExp("^(\\d)+$");
	var ares = re.exec(sNumber);
	if ( null == ares )
	{
		return false;
	}

	return true;
}

function checkIsDoubleNumberCorrect(sNumber)
{
	var re = new RegExp("^(\\d)+(\\.(\\d)+)?$");
	var ares = re.exec(sNumber);
	if ( null == ares )
	{
		return false;
	}

	return true;
}

function checkIsDateCorrect(nDay, nMonth, nYear)
{
	var day = parseInt(nDay);
	var month = parseInt(nMonth);
	var year = parseInt(nYear);

	var isLeapYear = false;
	if ( 0 == (year%4) )
	{
		isLeapYear = true;
	}

	if ( 2 == month )
	{
		if ( !isLeapYear && day > 28 )
		{
			return false;
		}
		if ( isLeapYear && day > 29 )
		{
			return false;
		}
	}
	else if ( day > 30 && (4 == month || 6 == month || 9 == month || 11 == month) )
	{
		return false;
	}

	return true;
}

function showBirthDateField(){

	if( document.data )
	{
		if( document.data.bill_country )
		{
			var billCountry = document.data.bill_country;

			var selectedCountry = billCountry.options[billCountry.selectedIndex].value;
			var birth_date = document.getElementById('birth_date');

			if( birth_date )
			{
				for ( var i=0; i < countriesEng.length; i++ )
				{
					if( countriesEng[i] == selectedCountry )
					{
						birth_date.style.display = '';
						break;
					}
					else
					{
						birth_date.style.display = 'none';
						continue;
					}
				}
			}
		}
	}
}

function validateSugnUpForm(theForm)
{
	if ( theForm )
	{
		if ( theForm.bill_country )
		{
			var billCountry = theForm.bill_country;
			var selectedCountry = billCountry.options[billCountry.selectedIndex].value;

			for ( var i = 0; i < countriesEng.length; i++ )
			{
				if(countriesEng[i] == selectedCountry)
				{
					var engCountry = true;
					break;
				}
				else
				{
					var engCountry = false;
					continue;
				}
			}

			if ( theForm.user_account_type[1].checked && !theForm.company_name.value )
			{
				alert("Please, enter company name for the corporate account.");
				theForm.company_name.focus();
				return (false);
			}

			if (!theForm.username.value)
			{
				alert("Please, enter user name.");
				theForm.username.focus();
				return (false);
			}

			if (!theForm.pass1.value)
			{
				alert("Please, enter password.");
				theForm.pass1.focus();
				return (false);
			}

			if (theForm.pass1.value != theForm.pass2.value)
			{
				alert("Please, repeat the same password two times.");
				theForm.pass2.focus();
				return (false);
			}

			if ( theForm.user_account_type[1].checked && !theForm.company_name.value )
			{
				alert("Please, enter company name for the corporate account.");
				theForm.company_name.focus();
				return (false);
			}

			if (!theForm.bill_firstname.value)
			{
				alert("Please, enter first name.");
				theForm.bill_firstname.focus();
				return (false);
			}

			if (!theForm.bill_lastname.value)
			{
				alert("Please, enter last name.");
				theForm.bill_lastname.focus();
				return (false);
			}

			if (!theForm.code_word.value)
			{
				alert("Please, enter security word.");
				theForm.code_word.focus();
				return (false);
			}

			if (!theForm.bill_address.value)
			{
				alert("Please, enter address.");
				theForm.bill_address.focus();
				return (false);
			}

			if (!theForm.bill_city.value)
			{
				alert("Please, enter city.");
				theForm.bill_city.focus();
				return (false);
			}

			if (!theForm.bill_postal_code.value)
			{
				alert("Please, enter postal code.");
				theForm.bill_postal_code.focus();
				return (false);
			}

			if (!theForm.bill_country.value)
			{
				alert("Please, enter country.");
				theForm.bill_country.focus();
				return (false);
			}

			if ( true == engCountry )
			{
				if ( 0 == theForm.birth_date_day.selectedIndex )
				{
					alert("Please, select Your birth date day.");
					theForm.birth_date_day.focus();
					return (false);
				}

				if ( 0 == theForm.birth_date_month.selectedIndex )
				{
					alert("Please, select Your birth date month.");
					theForm.birth_date_month.focus();
					return (false);
				}

				if ( 0 == theForm.birth_date_year.selectedIndex )
				{
					alert("Please, select Your birth date year.");
					theForm.birth_date_year.focus();
					return (false);
				}

				if ( !checkIsDateCorrect(theForm.birth_date_day.value, theForm.birth_date_month.value, theForm.birth_date_year.value) )
				{
					alert("Please, select correct Your birth date.");
					theForm.birth_date_day.focus();
					return (false);
				}
			}

			if ( 0 == theForm.bill_phone_prefix.selectedIndex )
			{
				alert("Please, select phone country code.");
				theForm.bill_phone_prefix.focus();
				return (false);
			}

			if (!theForm.bill_phone.value)
			{
				alert("Please, enter phone.");
				theForm.bill_phone.focus();
				return (false);
			}

			if ( (theForm.bill_fax.value.length > 0) && (0 == theForm.bill_fax_prefix.selectedIndex) )
			{
				alert("Please, select fax country code.");
				theForm.bill_fax_prefix.focus();
				return (false);
			}

			if (!theForm.bill_email.value)
			{
				alert("Please, enter email.");
				theForm.bill_email.focus();
				return (false);
			}

			if( !checkEmail(theForm.bill_email.value) )
			{
				alert("Please, enter valid email address.");
				theForm.bill_email.focus();
				return (false);
			}

			if ( theForm.bill_email2 )
			{
				if (theForm.bill_email.value != theForm.bill_email2.value)
				{
					alert("Please verify your email address - the email address you entered in both fields does not match.");
					theForm.bill_email2.focus();
					return (false);
				}
			}

			if ( theForm.how_know_type )
			{
				if( 0 == theForm.how_know_type.selectedIndex )
				{
					alert("Dear user, It is important for us to know where you heard about CoinInvestDirect. Please give us your feedback. Thank you.");
					theForm.how_know_type.focus();
					return (false);
				}

				if ( document.getElementById('which_text_tr').style.display != 'none' )
				{
					if ( !theForm.how_know_which_text.value )
					{
						alert("Dear user, It is important for us to know where you heard about CoinInvestDirect. Please give us your feedback. Thank you.");
						theForm.how_know_which_text.focus();
						return (false);
					}
				}
			}
		}
	}

	return true;
}

function validateCheckoutLoginForm(theForm)
{
	if (!theForm.user_name.value)
	{
		alert("Please, enter login name.");
		theForm.user_name.focus();
		return (false);
	}

	if (!theForm.user_password.value)
	{
		alert("Please, enter password.");
		theForm.user_password.focus();
		return (false);
	}

	return true;
}

function validateCheckoutForm(theForm)
{
	if (!theForm.bill_firstname.value)
	{
		alert("Please, enter \"Bill To\" first name.");
		theForm.bill_firstname.focus();
		return (false);
	}

	if (!theForm.bill_lastname.value)
	{
		alert("Please, enter \"Bill To\" last name.");
		theForm.bill_lastname.focus();
		return (false);
	}

	if (!theForm.bill_address.value)
	{
		alert("Please, enter \"Bill To\" address.");
		theForm.bill_address.focus();
		return (false);
	}

	if (!theForm.bill_city.value)
	{
		alert("Please, enter \"Bill To\" city.");
		theForm.bill_city.focus();
		return (false);
	}

	if (!theForm.bill_postal_code.value)
	{
		alert("Please, enter \"Bill To\" postal code.");
		theForm.bill_postal_code.focus();
		return (false);
	}

	if (!theForm.bill_country.value)
	{
		alert("Please, enter \"Bill To\" country.");
		theForm.bill_country.focus();
		return (false);
	}

	if ( 0 == theForm.phone_prefix.selectedIndex )
	{
		alert("Please, select \"Bill To\" phone country code.");
		theForm.phone_prefix.focus();
		return (false);
	}

	if (!theForm.bill_phone.value)
	{
		alert("Please, enter \"Bill To\" phone.");
		theForm.bill_phone.focus();
		return (false);
	}

	if ( (theForm.bill_fax.value.length > 0) && (0 == theForm.fax_prefix.selectedIndex) )
	{
		alert("Please, select \"Bill To\" fax country code.");
		theForm.fax_prefix.focus();
		return (false);
	}

	if (!theForm.bill_email.value)
	{
		alert("Please, enter \"Bill To\" email.");
		theForm.bill_email.focus();
		return (false);
	}

	if( !checkEmail(theForm.bill_email.value) )
	{
		alert("Please, enter \"Bill To\" valid email address.");
		theForm.bill_email.focus();
		return (false);
	}

	if ( (theForm.shipto_mobile.value.length > 0) && (0 == theForm.mobile_prefix.selectedIndex) )
	{
		alert("Please, select \"Ship To\" mobile country code.");
		theForm.mobile_prefix.focus();
		return (false);
	}

	if ( !theForm.billme_by_email.checked && !theForm.billme_by_fax.checked && !theForm.billme_by_mail.checked )
	{
		alert("Please, select type of billing \"Bill Me\".");
		return (false);
	}

	return true;
}


if( document.data )
{
	if( document.data.bill_country )
	{
		var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
		if (root)
		{
			if (root.addEventListener)
			{
				root.addEventListener("load", showBirthDateField,false);
			}
			else if (root.attachEvent)
			{
				root.attachEvent("onload", showBirthDateField);
			}
		}
	}
}

function goTo(where)
{
	var where;

	if(where.value != '')
	{
		window.location.href= 'main.php?a=' + where.value;
	}
}