//----------------------------------------------------------------------------------------------
//			validationTools.js							Validation tools
//		 	Created by Johan van Niekerk				SSPF-Dundee
//			3 November 2005
//
//			This javascript file contains methods for cleaning and checking input
//----------------------------------------------------------------------------------------------

/* Duplicate function name - now uses isValidHyperlink in pims.js
function validHyperlink(string) {
	var reg = new RegExp("http://\\S+");
	if (reg.test(string)) {
		return true;
	} else {
		return false;
	}	
}
*/

function validEmail(string) {	//If the regular expression matches the email, the email is OK
	var reg = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
	if (reg.test(string)) {
		return true;
	} else {
		return false;
	}	
}
function validNumber(string) {	//If the regular expression finds anything that is not a number, return false
	var reg = new RegExp("[^0-9]");
	if (reg.test(string)) {
		return false;
	} else {
		return true;
	}	
}


function validPrimer(theSeq) { //as for validDNASequence but with an alert
	var reg = new RegExp("[^ACGTURYMKSWBDHVN]");//Allow all IUPAC characters
	theSeq=cleanSequence(theSeq);
	if (reg.test(theSeq)) {
		alert('Sequence '+theSeq+' contains non-DNA characters');
	}
	return theSeq;
}
function validEnd(theSeq) { //as for validProteinSequence but with an alert
	var reg = new RegExp("[^ABCDEFGHIKLMNPQRSTVWXYZ]");//Allow all IUPAC characters
	theSeq=cleanSequence(theSeq);
	if (reg.test(theSeq)) {
		alert('Sequence '+theSeq+' contains non-Protein characters');
	}
	return theSeq;
}

function cleanSequence(string){
	string=string.toUpperCase();
	string=removeSpaces(string);
	string = string.replace(/[^A-Z]/g, "");
	return string;
}
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
function confirmDelete()
{
var agree=confirm("Are you sure you want to delete this record?");
if (agree)
	return true ;
else
	return false ;
}
function confirmEmptyRecycleBin()
{
var agree=confirm("Are you sure you want to permanently delete these records?");
if (agree)
	return true ;
else
	return false ;
}
