//form validation functions

function quicksearch_validator(theForm)
{
if (theForm.companyname.value == "")
{ 
alert("SCoRe quick search:\n\nPlease enter the name of a company (or part of it)."); 
theForm.companyname.focus();
return (false); 
}
return (true);
}

function scoresearch_validator(theForm)
{
if (theForm.name.value == "" && theForm.startdate.value == "" && theForm.coll.selectedIndex == 0 && theForm.doctype.selectedIndex == 0 && theForm.country.selectedIndex == 0 && theForm.ft.selectedIndex == 0) 
{ 
alert("Search SCoRe catalogue:\n\nPlease specify at least one search criterion."); 
return (false); 
}
	
var checkOK = "0123456789";
var checkStr = theForm.startdate.value;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}

if (!allValid && theForm.startdate.value !== "")
{
alert("Year of report (YYYY)\n\nPlease enter the year as 4 digits, e.g. 1957.");
theForm.startdate.focus();
return (false);
}
	
	
if (theForm.startdate.value.length > 0 && theForm.startdate.value.length < 4)
{
alert("Year of report (YYYY)\n\nPlease enter the year as 4 digits, e.g. 1957.");
theForm.startdate.focus();
return (false);
}
	
return (true);
}

function validEmail(email) {
invalidChars = " /:,;"
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1)
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) != -1) {
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) {
return false
}
if (periodPos+3 > email.length)	{
return false
}
return true
}

function validatefeedback(theForm) {

if (theForm.name.value == "")
{
alert("SCoRe feedback:\n\nPlease enter your name.");
theForm.name.focus();
return (false);
}

if (theForm.email.value == "")
{
alert("SCoRe feedback:\n\nPlease enter your email address.");
theForm.email.focus();
return (false);
}

if (!validEmail(theForm.email.value))
{
alert("SCoRe feedback:\n\nPlease enter a valid email address.");
theForm.email.focus();
return (false);
}

if (theForm.subject.value == "")
{
alert("SCoRe feedback:\n\nPlease enter your subject.");
theForm.subject.focus();
return (false);
}

if (theForm.message.value == "")
{
alert("SCoRe feedback:\n\nPlease enter your message.");
theForm.message.focus();
return (false);
}

return (true);
}

function openWin(url) {
newWindow = window.open(url,'_blank');
return false;
}

function homesearch_validator(theForm)
{
if (theForm.name.value == "" && theForm.coll.selectedIndex == 0) 
{ 
alert("Search SCoRe catalogue:\n\nPlease enter a company name or select a collection."); 
return (false); 
}

return (true);
}

//google maps functions

function addLoadEvent(func) { 
var oldonload = window.onload; 
if (typeof window.onload != 'function'){ 
window.onload = func
} else { 
window.onload = function() {
oldonload();
func();
}
}
}

function createMarker(point, icon, popuphtml) {
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(popuphtml);
});
return marker;
}
