var popupfeatures = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=825,height=350";
function popUp(myurl) {var win = open(myurl,'popupwindow',popupfeatures);win.focus();}

function enlarge(pic,title,width,height)
{
	preview = window.open("", title, "resizable=yes,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+width+",height="+height+"");
	preview.document.write('<html><head><title>Picture<\/title><\/head>'+'<body onBlur="self.focus();" marginWidth="0" marginHeight="0" topmargin="0" leftmargin="0">'+'<center><img border="0" src="'+pic+'" width="'+width+'" height="'+height+'">'+'<\/center><\/body><\/html>');
	preview.document.close();
}
$().ready(function() {
   $('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
});


//check and uncheck checkboxes on a form
// onClick="checkAll(document.myform.list)
// onClick="uncheckAll(document.myform.list)"
function checkAll(field)
{
	if(field.length > 1){
		for (i = 0; i < field.length; i++)
			field[i].checked = true ;
	}else{
		field.checked = true ;		
	}
}

function uncheckAll(field)
{
if(field.length > 1){
		for (i = 0; i < field.length; i++)
			field[i].checked = false ;
	}else{
		field.checked = false ;		
	}
}
function showHide(item){
	itemID = document.getElementById(item);
	if(itemID.style.display == ''){
		itemID.style.display = 'none'
	}else{
		itemID.style.display = ''
	}
}
function popUp_help(url) {

if (document.all) {var xMax = screen.width, yMax = screen.height} 
else if (document.layers) {var xMax = window.outerWidth, yMax = window.outerHeight} 
else {var xMax = 640, yMax=480}; var xOffset = (xMax - 670)/2, yOffset = (yMax - 650)/2; 

sealWin=window.open(url,"",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=700,height=500,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
self.name = "";
}

/*function enlarge(pic,title,width,height)
{
	preview = window.open("", title, "resizable=yes,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+width+",height="+height+"");
	preview.document.write('<html><head><title>Picture<\/title><\/head>'+'<body onBlur="self.focus();" marginWidth="0" marginHeight="0" topmargin="0" leftmargin="0">'+'<center><img border="0" src="'+pic+'" width="'+width+'" height="'+height+'">'+'<\/center><\/body><\/html>');
	preview.document.close();
}*/

var counter = 0;
function count() 
{
	counter++;
	if(counter > 1) 
	{ 
		return false;
	}
	return true;
}
function ResetCounter() {
	counter = 0;
}
window.onunload = ResetCounter;






//------------------------------- Test for alphanumeric ---------------------------------------//

function IsAlpha(CheckString)
{
	return ValidAlphanumeric(CheckString,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
}

function IsNumeric(CheckString)
{
	return ValidAlphanumeric(CheckString,'0123456789');
}

function ValidAlphanumeric(CheckString, ValidString)
{
	var LegalCount=0;
	for (i=0; i<CheckString.length; i++)
	{
		if (ValidString.indexOf(CheckString.substring(i,i+1)) !== -1) {LegalCount=LegalCount+1;}
	}
	if (LegalCount !== 0) return true;
	else return false;
}	



//------------------------------- Test for amounts ---------------------------------------//

function AmountIsNumeric(CheckString)
{
	return ValidAmount(CheckString,'0123456789.');
}

function ValidAmount(CheckString, ValidString)
{
	var IllegalCount=0;
	var DotCount=0;
	for (i=0; i<CheckString.length; i++)
	{
		if (ValidString.indexOf(CheckString.substring(i,i+1)) == -1) {IllegalCount=IllegalCount+1;}
		if (CheckString.substring(i,i+1) == '.') {DotCount=DotCount+1;}
	}
	if (IllegalCount == 0 && DotCount<=1 && CheckString.length!==DotCount) return true;
	else return false;
}	

//------------------------------- Test for email ---------------------------------------//

function IsEmail(email) 
{
	invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
	
	// Check for null
	if (email == "") return false;

	// Check for invalid characters as defined above
	for (i=0; i<invalidChars.length; i++) 
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) return false;
	}
	
	lengthOfEmail = email.length;
	if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) return false;
	
	Pos = email.indexOf("@",1);
	if (email.charAt(Pos + 1) == ".") return false;
	
	while ((Pos < lengthOfEmail) && ( Pos != -1)) 
	{
		Pos = email.indexOf(".",Pos);
		if (email.charAt(Pos + 1) == ".") return false;
		if (Pos != -1) Pos++;
	}

	// There must be at least one @ symbol
	atPos = email.indexOf("@",1);
	if (atPos == -1) return false;

	// But only ONE @ symbol
	if (email.indexOf("@",atPos+1) != -1) return false;

	// Also check for at least one period after the @ symbol
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1) return false;

	if (periodPos+3 > email.length) return false;

	return true;
}


//------------------------------- Enlarge an image ---------------------------------------//

function enlarge(pic,title,width,height)
{
	
	if(typeof preview != 'undefined'){preview.close()};
	preview = window.open("", 'ImagePopup', "resizable=yes,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+width+",height="+height+"");
	preview.document.write('<html><head><title>Picture<\/title><\/head>'+'<body onBlur="self.focus();" marginWidth="0" marginHeight="0" topmargin="0" leftmargin="0">'+'<center><img border="0" src="'+pic+'" width="'+width+'" height="'+height+'">'+'<\/center><\/body><\/html>');
	preview.document.close();
}
	

function Sanitise(StringToClean) {
	var CleanString = StringToClean;
	CleanString = CleanString.toLowerCase().replace(/[^a-z0-9]+/g, '-');
	CleanString = CleanString.replace(/^[\-]+/, '');
	CleanString = CleanString.replace(/[\-]+$/, '');
	CleanString = CleanString.slice(0, 80);
	return CleanString;
}

var TitleLastEdit = "";
var ForceFillClean = 0;
function FillClean(TitleField, TitleCleanField) {
	if(Sanitise(TitleLastEdit) == TitleCleanField.value || ForceFillClean) {
		TitleCleanField.value = Sanitise(TitleField.value);
		ForceFillClean = 0;
	};
	TitleLastEdit = TitleField.value;
}
