
function basicLength(label,strng,length) {
	var error = "";
	  if (strng.length < length) {
		 error = "Please provide a  "+label+".\n"
	  }
	return error;
}

function checkbox_checker(boxer,label)
{
	
	var error = "";
	// set var checkbox_choices to zero
	
	var checkbox_choices = 0;
	
	// Loop from zero to the one minus the number of checkbox button selections
	for (counter = 0; counter < boxer.length; counter++)
	{
	
	// If a checkbox has been selected it will return true
	// (If not it will return false)
		if (boxer[counter].checked)
		{ 
			checkbox_choices ++;
		}
		
	}
	//alert("num of cc is "+checkbox_choices);

	if (checkbox_choices < 1 )
	{
	// If there were less then selections made display an alert box
		
		error = "Please select at least one "+label+". \n"
		//alert(error);
		
	}

return error;
}



function checkEmail(str) {
	var error = "";
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))){
		error =("Invalid E-mail Address! Please re-enter.\n")
		
	}
	return (error)
}

function checkPasscode (strng) {
	//alert("checking username");
var error = "";
if (strng == "") {
   error = "You didn't enter a passcode.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 5) || (strng.length > 8)) {
       error = "Password must be between 5 and 8 characters.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The passcode contains illegal characters.\n";
    } 
return error;
}

function checkPhone(str) {
	var error = "";
	var stripped = str.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	   error = "The phone number contains illegal characters.";
	}
	
	if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
	}

	return error;

}

function removeCommas(aNum) {

//remove any commas

aNum=aNum.replace(/,/g,"");

//remove any spaces

aNum=aNum.replace(/\s/g,"");

return aNum;

}

function validateNumber(num) {
var error = "";
if (isNaN(num))
	{ 
	error = num+" is not a number.\n";
	}
return error;
}

// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; 
	if (z<0) 
		z--; 
		for(var i = z; i < 0; i++) 
		y.unshift('0');
		y.splice(z, 0, pnt); 
	while (z > 3) {
		z-=3; y.splice(z,0,thou);
		}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
	
	}


function submitenter(myfield,e,action)
{
	
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
    //do What?
	if(action=='addPlace') {
		//alert("yes hit");
		addPlace();
	}
	if(action=='savePlace') {
		save_Place();
	}	
	if(action=='addRoom') {
		addRoom();
	}	
	if(action=='saveRoom') {
		saveRoom();	
	}
	if(action=='addSpace') {
		addSpace();
	}	
	if(action=='saveSpace') {
		spaceQuickSave();
	}	
	if(action=='val_login') {
		valthedater();	
	}
	if(action=='searcher') {
		searcher();	
	}
	if(action=='saveThingBasics') {
		saveThingBasics();	
	}
	if(action=='saveThingSubj') {
		saveThingSubj();	
	}
	if(action=='newbie') {
	    valNew();	
	}	
	if(action=='reset_pass') {
	    resetPassword();	
	}
   
   return false;
   }
else
   return true;
}



    function toggle_visibility(id) {
       var e = $(id);
	   var p = $(id+"_Prompt");
       if(e.style.display == 'block') {
		  //alert('yes, block is');
          e.style.display = 'none';
		  p.innerHTML = "Show";
	   } else {
          e.style.display = 'block';
		  p.innerHTML = "Hide";
	   }
    }


function emptyDiv(id) {
	$(id).innerHTML = '';
	$(id).style.display='none'
}

