//*****************************************************************************

var bValid, sError;

function validateForm(oForm) {
	if (oForm.name=="frmSearch")
		return validateForm_frmSearch(oForm);
	else if (oForm.name=="frmSendArticle")
		return validateForm_frmSendArticle(oForm);
	else if (oForm.name=="frmRegister")
		return validateForm_frmRegister(oForm);
	else if (oForm.name=="frmMailingList")
		return validateForm_frmMailingList(oForm);
	else if (oForm.name=="frmTaibRegistration")
		return validateForm_frmTaibRegistration(oForm);
	else if (oForm.name=="frmTaibLogin")
		return validateForm_frmTaibLogin(oForm);
}

function validateForm_frmSearch(oForm) {
	bValid=true;
	sError="";
	
	notEmpty(oForm.frmSearchString);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function validateForm_frmSendArticle(oForm) {
	bValid=true;
	sError="";
	
	notEmpty(oForm.frmTName);
	isEmail(oForm.frmTEmail);
	notEmpty(oForm.frmRName);
	isEmail(oForm.frmREmail);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function validateForm_frmRegister(oForm) {
	bValid=true;
	sError="";
	
	notEmpty(oForm.frmFullName);
	isEmail(oForm.frmEmail);
	notEmpty(oForm.frmCity);
	notEmpty(oForm.frmCountry);
	notEmpty(oForm.frmHomeContact);
	notEmpty(oForm.frmOfficeContact);
	notEmpty(oForm.frmMobileContact);
	notEmpty(oForm.frmBusiness1);
	isNumberInRange(oForm.frmTemplateNumber,1,10);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function validateForm_frmMailingList(oForm) {
	bValid=true;
	sError="";
	
	isEmail(oForm.frmEmail);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function validateForm_frmTaibRegistration(oForm) {
	bValid=true;
	sError="";
	
	notEmpty(oForm.frmEmailAddress);
	isEmail(oForm.frmEmailAddress);
	notEmpty(oForm.frmFirstName);
	notEmpty(oForm.frmLastName);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function validateForm_frmTaibLogin(oForm) {
	bValid=true;
	sError="";
	
	notEmpty(oForm.frmEmailAddress);
	isEmail(oForm.frmEmailAddress);
	
	if (!bValid) {
		alert(sError);
		return false;
	}
	else {
		return true
	}
}

function notEmpty(oIn) {
	if (oIn.value.length==0) {
		bValid=false;
		sError+=oIn.title+" must not be empty\n";
		oIn.focus();
	}
}

function isEmail(oIn) {
	if (oIn.value.indexOf("@")<0) {
		bValid=false;
		sError+=oIn.title+" must be a valid email address (name@domain.com)\n";
		oIn.focus();
	}
}

function inputsMatch(oIn1,oIn2) {
	if (oIn1.value!=oIn2.value) {
		bValid=false;
		sError+=oIn1.title+" and "+oIn2.title+" must match\n";
		oIn2.focus();
	}
}

function isNumber(oIn) {
	if (parseInt(oIn.value)!=oIn.value) {
		bValid=false;
		sError+=oIn.title+" must be numeric\n";
		oIn.focus();
	}
}

function isNumberInRange(oIn,lower,upper) {
	if (parseInt(oIn.value)!=oIn.value) {
		bValid=false;
		sError+=oIn.title+" must be numeric\n";
		oIn.focus();
	}
	else if (parseInt(oIn.value)<lower||parseInt(oIn.value)>upper) {
		bValid=false;
		sError+=oIn.title+" must be in the range "+lower+" to "+upper+"\n";
		oIn.focus();
	}
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

//*****************************************************************************

function postLoad() {
	var i;
	
	for (i=0; i<document.images.length; i++)
		if (document.images[i].getAttribute('xsrc')!=null)
			document.images[i].setAttribute('src',document.images[i].getAttribute('xsrc'));
		else if (!document.images[i].complete) {
			document.images[i].width=55;
			document.images[i].height=61;
			document.images[i].src='gif/wglogopart.html';
		}
	
	if (document.getElementById('iframePoll'))
		document.getElementById('iframePoll').src='psq/displaypsq7e10.html?psqid=-1';

	if (document.getElementById('iframeSPoll'))
		document.getElementById('iframeSPoll').src='spsq/displaypsq7e10.html?psqid=-1';
	

}
