function validate_email(field, alert_str)
{
	var str = field.value;
//	alert(str);
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(str) && reg2.test(str)) {
			return true;
		}
		if(alert_str.length>0)
			alert(alert_str);
		field.select();
		return false;
	} else {
		if(str.indexOf("@") >= 0)
		{
			return true;
		}
		if(alert_str.length>0)
			alert(alert_str);
		field.select();
		return false;
	}
}

function check_username_pass(username, password, re_password)
{
	if((username.value.length < 5 || username.value.length > 70))
	{
		alert("Please fill in the username(5-7 characters)");
		//username.focus();
		return false;
	}
	if((password.value.length < 5 || password.value.length > 7))
	{
		alert("Please fill in the password(5-7 characters)");
		//password.focus();
		return false;
	}
	if(password.value != re_password.value)
	{
		alert("You must retype the same password");
		//re_password.focus();
		return false;
	}
	return true;
		
}

function check_subscribe_individual()
{
	f = document.form_subscribe_individual;

	if (f.subscription[0].checked==false) 
	{

		if(!check_username_pass(f.username, f.password, f.re_password)) return false;

		if(!f.tos.checked)
		{
			alert("Please accept terms and conditions");
	//		f.first_name.focus();
			return false;
		}
	}


	if(!f.first_name.value)
	{
		alert("Please fill in the first name");
		f.first_name.focus();
		return false;
	}

	if(!f.last_name.value)
	{
		alert("Please fill in the last name");
		f.last_name.focus();
		return false;
	}

	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}

	if(!f.address.value)
	{
		alert("Please fill in the address");
		f.address.focus();
		return false;
	}

	if(!f.city.value)
	{
		alert("Please fill in the city");
		f.city.focus();
		return false;
	}

	if(!f.state_province.value)
	{
		alert("Please fill in the state/province");
		f.state_province.focus();
		return false;
	}

	if(!f.zip_code.value)
	{
		alert("Please fill in the zip code");
		f.zip_code.focus();
		return false;
	}

	if(!f.country.value)
	{
		alert("Please fill in the country");
		f.country.focus();
		return false;
	}


	

	return true;
}

function check_subscribe_single_africa()
{
	f = document.form_subscribe_single_africa;

	if(!f.tos.checked)
	{
		alert("Please accept terms and conditions");
//		f.first_name.focus();
		return false;
	}

	if(!f.library_name.value)
	{
		alert("Please fill in the Library Name");
		f.library_name.focus();
		return false;
	}

	if(!f.address.value)
	{
		alert("Please fill in the address");
		f.address.focus();
		return false;
	}

	if(!f.city.value)
	{
		alert("Please fill in the city");
		f.city.focus();
		return false;
	}

	if(!f.state_province.value)
	{
		alert("Please fill in the state/province");
		f.state_province.focus();
		return false;
	}

	if(!f.zip_code.value)
	{
		alert("Please fill in the zip code");
		f.zip_code.focus();
		return false;
	}

	if(!f.country.value)
	{
		alert("Please fill in the country");
		f.country.focus();
		return false;
	}

	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}

	if(!check_username_pass(f.username, f.password, f.re_password)) return false;
		
	return true;
}

function check_subscribe_single_cont()
{
	f = document.form_subscribe_single_cont;

	if(!f.tos.checked)
	{
		alert("Please accept terms and conditions");
//		f.first_name.focus();
		return false;
	}

	if(!f.library_name.value)
	{
		alert("Please fill in the Library Name");
		f.library_name.focus();
		return false;
	}

	if(!f.address.value)
	{
		alert("Please fill in the address");
		f.address.focus();
		return false;
	}

	if(!f.city.value)
	{
		alert("Please fill in the city");
		f.city.focus();
		return false;
	}

	if(!f.state_province.value)
	{
		alert("Please fill in the state/province");
		f.state_province.focus();
		return false;
	}

	if(!f.zip_code.value)
	{
		alert("Please fill in the zip code");
		f.zip_code.focus();
		return false;
	}

	if(!f.country.value)
	{
		alert("Please fill in the country");
		f.country.focus();
		return false;
	}

	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}

	if(f.billing_address.checked == false)
	{
		if(!f.bill_address.value)
		{
			alert("Please fill in the billing address");
			f.bill_address.focus();
			return false;
		}

		if(!f.bill_city.value)
		{
			alert("Please fill in the billing city");
			f.bill_city.focus();
			return false;
		}

		if(!f.bill_state_province.value)
		{
			alert("Please fill in the billing state/province");
			f.bill_state_province.focus();
			return false;
		}

		if(!f.bill_zip_code.value)
		{
			alert("Please fill in the billing zip code");
			f.bill_zip_code.focus();
			return false;
		}

		if(!f.bill_country.value)
		{
			alert("Please fill in the billing country");
			f.bill_country.focus();
			return false;
		}
		if(!validate_email(f.bill_email, "Please insert a valid billing email(ex: company@yahoo.com)"))
		{
			return false;
		}
		
	}

	if(!check_username_pass(f.username, f.password, f.re_password)) return false;
		
	return true;
}

function check_subscribe_multiple()
{
	f = document.form_subscribe_multiple;

	if(!f.tos.checked)
	{
		alert("Please accept terms and conditions");
//		f.first_name.focus();
		return false;
	}

	for(i = 1; i <= 2; i++)
	{
		institution = document.getElementById("institution_"+i);
		library_name = document.getElementById("library_name_"+i);
		address = document.getElementById("address_"+i);
		city = document.getElementById("city_"+i);
		state_province = document.getElementById("state_province_"+i);
		zip_code = document.getElementById("zip_code_"+i);
		country = document.getElementById("country_"+i);
		email = document.getElementById("email_"+i);

		if(!institution.value)
		{
			alert("Please fill in the institution name");
			institution.focus();
			return false;
		}

		if(!library_name.value)
		{
			alert("Please fill in the Library Name");
			library_name.focus();
			return false;
		}

		if(!address.value)
		{
			alert("Please fill in the address");
			address.focus();
			return false;
		}

		if(!city.value)
		{
			alert("Please fill in the city");
			city.focus();
			return false;
		}

		if(!state_province.value)
		{
			alert("Please fill in the state/province");
			state_province.focus();
			return false;
		}

		if(!zip_code.value)
		{
			alert("Please fill in the zip code");
			zip_code.focus();
			return false;
		}

		if(!country.value)
		{
			alert("Please fill in the country");
			country.focus();
			return false;
		}

		if(!validate_email(email, "Please insert a valid email(ex: company@yahoo.com)"))
		{
			return false;
		}
	}
	if(!f.bill_address.value)
	{
		alert("Please fill in the billing address");
		f.bill_address.focus();
		return false;
	}

	if(!f.bill_city.value)
	{
		alert("Please fill in the billing city");
		f.bill_city.focus();
		return false;
	}

	if(!f.bill_state_province.value)
	{
		alert("Please fill in the billing state/province");
		f.bill_state_province.focus();
		return false;
	}

	if(!f.bill_zip_code.value)
	{
		alert("Please fill in the billing zip code");
		f.bill_zip_code.focus();
		return false;
	}

	if(!f.bill_country.value)
	{
		alert("Please fill in the billing country");
		f.bill_country.focus();
		return false;
	}
	if(!validate_email(f.bill_email, "Please insert a valid billing email(ex: company@yahoo.com)"))
	{
		return false;
	}
	if(!check_username_pass(f.username, f.password, f.re_password)) return false;
	return true;
	
}

function check_contact()
{
	f = document.form_contact;
	if(!f.request.value)
	{
		alert("You must fill in the request");
		f.request.focus();
		return false;
	}
	if(!f.name.value)
	{
		alert("You must fill in the name");
		f.name.focus();
		return false;
	}
	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}
	return true;
}

function check_monograph_order()
{
	f = document.form_monograph_order;

	total = f.total.value;
	for(i=0; i<total; i++)
	{
		
		var ck_mono = document.getElementById("monographorder_"+i);
		
		if(ck_mono.checked==true)
		{
			var quantity = document.getElementById("quantity_"+i).value;
			var val = parseInt(quantity);
			
			if ((val != quantity)||(val == 0)||(val == '')) 
			{
				alert("You must fill in the quantity(positive number)");
				return false;
			}
		}
	}


	if(!f.first_name.value)
	{
		alert("You must fill in the first name");
		f.first_name.focus();
		return false;
	}
	if(!f.name.value)
	{
		alert("You must fill in the name");
		f.name.focus();
		return false;
	}
	if(!f.address.value)
	{
		alert("You must fill in the address");
		f.address.focus();
		return false;
	}
	if(!f.zip_code.value)
	{
		alert("You must fill in the zip code");
		f.zip_code.focus();
		return false;
	}
	if(!f.country.value)
	{
		alert("You must fill in the country");
		f.country.focus();
		return false;
	}
	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}
	return true;
}

function check_order_form()
{
	f = document.form_order;

	if(!f.first_name.value)
	{
		alert("You must fill in the first name");
		f.first_name.focus();
		return false;
	}
	if(!f.name.value)
	{
		alert("You must fill in the name");
		f.name.focus();
		return false;
	}
	if(!f.address.value)
	{
		alert("You must fill in the address");
		f.address.focus();
		return false;
	}
	if(!f.zip_code.value)
	{
		alert("You must fill in the zip code");
		f.zip_code.focus();
		return false;
	}
	if(!f.country.value)
	{
		alert("You must fill in the country");
		f.country.focus();
		return false;
	}
	if(!validate_email(f.email, "Please insert a valid email(ex: company@yahoo.com)"))
	{
		return false;
	}
	return true;
}

function check_forgotten()
{
	f = document.form_forgotten;
	if(!f.username.value)
	{
		alert("Please insert your username");
		f.username.focus();
		return false;
	}
	if(!validate_email(f.email, "Please insert your email address on this site"))
	{
		return false;
	}
	return true;
}

function window_open(url, title, scrol, tool, w, h )
{
	f=window.open(url, title, "scrollbars="+scrol+",toolbar="+tool+",width="+w+",height="+h); 
	f.focus(); 
	return false;
}

function type_sub_change()
{
	f = document.form_subscribe_individual;
	
				
	if(f.subscription[0].checked==true)
	{
		document.getElementById("online_subscription_div").style.display='none';
	}
	else
	{
		document.getElementById("online_subscription_div").style.display='block';
	}
		
}


function type_sub_change_2()
{
	f = document.form_subscribe_single_cont;
	
				
	if(f.subscription[0].checked==true)
	{
		document.getElementById("online_subscription_div").style.display='none';
	}
	else
	{
		document.getElementById("online_subscription_div").style.display='block';
	}
		
}