
function isText(a,b){
	if (a == "" || a == "null" || a == "NULL"){
		alert("Missing " + b);
		return false;
	}
	return true;
}

function isUsername(a,b){
	if (a == ""){
		alert("Missing " + b);
		return false;
	}
	return true;
}

function isPassword(a,b){
	if (a == ""){
		alert("Missing " + b);
		return false;
	}
	return true;
}

function isSameAs(a,b,msg){
	if (a != b){
		alert(msg);
		return false;
	}
	return true;
}

function isSelected(a,b){
	if (a == ""){
		alert("Please select " + b);
		return false;
	}
	return true;
}

function isChecked(a,b){

	if (a.checked == true){
		return true;
	}
	else {
		alert(b);
		return false;
	}

}

function isEmail(a,b) {
	
	var x = a;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (filter.test(x)) {
		return true;
	}
	else {
		alert("Invalid or missing " + b);
		return false;
	}
}


function openWindow(url, w, h) {
    var options = "width=" + w + ",height=" + h + ",";
    options += "resizable=1,scrollbars=1,status=0,";
    options += "menubar=0,toolbar=0,location=0,directories=0";
    var newWin = window.open(url, 'newWin', options);
	newWin.moveTo(0,0);
    newWin.focus();
}
function selectAll(f){
	var elms = f.elements;
	var elms_len = elms.length;
	for(var i=0;i<elms.length;i++){
		if (elms[i].type == "checkbox"){
			elms[i].checked = true;
		}
	}
}
function unselectAll(f){
	var elms = f.elements;
	var elms_len = elms.length;
	for(var i=0;i<elms.length;i++){
		if (elms[i].type == "checkbox"){
			elms[i].checked = false;
		}
	}
}
function checkWithSelectedForm(f){

	var elms = f.elements;
	var elms_len = elms.length;
	for(var i=0;i<elms.length;i++){
		if (elms[i].type == "checkbox"){
			if (elms[i].checked == true){
				if (f.task){
					var new_task = f.with_selected.value;
					if (new_task == "delete"){
						if (!confirm("Are you sure you want to delete these?")) { return false; }
					}
					f.task.value = new_task;
				}
				return true;
			}
		}
	}
	alert("Please select at least one item to continue");
	return false;

}
function setBlockHeight(){

	var LH = 0; var RH = 0; var CH = 0;var pad = 0;
	if (document.getElementById('lblock_c')){
		var LH = document.getElementById('lblock_c').offsetHeight;
	}
	if (document.getElementById('rblock_c')){
		var RH = document.getElementById('rblock_c').offsetHeight;
	}
	if (document.getElementById('cblock_c')){
		var CH = document.getElementById('cblock_c').offsetHeight;
	}
	
	var A = [LH,RH,CH];
	highest = -1;

	for(i=0;i<A.length;i++){
    	if (A[i] > highest){
        	highest = A[i];
		}
	}

	if (document.getElementById('lblock_c')) document.getElementById('lblock_c').style.height = highest;
	if (document.getElementById('rblock_c')) document.getElementById('rblock_c').style.height = highest;
	if (document.getElementById('cblock_c')) document.getElementById('cblock_c').style.height = highest;


}
function addTotals(a){
	var total = 0;

	for(i=0;i<a.length;i++){
		var b = parseInt(a[i]);

		total += b;
	}
	return total;
}

function new_captcha(){

	if(document.getElementById)	{
	
		thesrc = document.getElementById("captcha").src;
		
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		
		document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
	} 
	else {
		alert("Sorry, cannot autoreload verification image\nSubmit the form and a new image will be loaded");
	}
}

function textCounter(field, countfield, maxlimit) {

	if (field.value.length > maxlimit) {
	
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		countfield.value = maxlimit - field.value.length;
	}
}


