//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 = ''
	}
}

$().ready(function() {
	$("#downloadToExcel").click(function(){
		$("#Export").val(1);
		$("#" +$(this).parents('form').attr('id')).submit();
	});
	$(".xButton").click(function(){
		$("#Export").val(0);
	});
});
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 = "";
}

var popupfeatures = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes";
function popUp(myurl) {var win = open(myurl,'popupwindow' + Math.floor(Math.random() * 100),popupfeatures + ',width=900,height=500');win.focus();}

function popupSized(myurl,height,width) {var win = open(myurl,'popupwindow',popupfeatures + ',width=' + width + ',height=' + height);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();
}*/

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 CheckString.match(/^[a-z]+$/i);
}

function IsNumeric(CheckString)
{
	return CheckString.match(/^[0-9]+$/);
}

//------------------------------- Test for amounts ---------------------------------------//

function AmountIsNumeric(CheckString)
{
	return CheckString.match(/^(\d*\.)?\d+$/);
}

//------------------------------- Test for email ---------------------------------------//

function IsEmail(email) {
	return email.match(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
}


//------------------------------- 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;
}

function Ellip(s, len) {
	s = s.replace(/<\/?[a-z]+[^>]*>/g, "");
	if(s.length > len) {
		s = s.slice(0, len) + "...";
	}
	return s;
}

