/* ########################################################################################
									IMAGE MANIPULATION
######################################################################################## */

// Init Vars
var originalImg;


function returnEvent(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);	
	return evt;
}
// Dynamically get the images' ID
function getTargetId(evt) {
	var evt = returnEvent(evt);
	var objId = (evt.target) ? evt.target.id : ((evt.srcElement) ? evt.srcElement.id : null);
	return objId;
}
// Return a swapped image to its original
function swapImageReturn(evt) {
	document.getElementById(getTargetId(evt)).src = originalImg;	
}
// Swap an Image
function swapImage(evt, newImg) {
	originalImg = document.getElementById(getTargetId(evt)).src;
	document.getElementById(getTargetId(evt)).src = newImg;
}


/* ########################################################################################
									DIV MANIPULATION
######################################################################################## */

// Init Vars
var userType = new Array("user_login", "user_register");

function hideShow_userType(name) {
	var objId = name;
	for (var i=0; i<userType.length; i++) {
		if (objId == userType[i]) {
			document.getElementById(userType[i]).style.display = "block";	
		} else {
			document.getElementById(userType[i]).style.display = "none";
		}
	}
}

/* Function used to expand/collapse blocks of code */
function expandCollapse(imgID, divID)
{
	if(imgID.length > 0)
	{
		objImage = document.getElementById(imgID);
	}
	objDiv = document.getElementById(divID);
	if(objDiv.style.display == 'none')
	{
		objDiv.style.display = 'block';
		if(imgID.length > 0)
		{
			objImage.src = '/resource/images/minusSign.gif';
		}
	}
	else
	{
		objDiv.style.display = 'none';
		if(imgID.length > 0)
		{
			objImage.src = '/resource/images/plusSign.gif';
		}
	}
}

function displayFullSizedImage(strImageURL, intWidth, intHeight)
{
	intBorderPadding = 5;
	intWidth += intBorderPadding;
	intHeight += intBorderPadding;
	intLeft =  (window.screen.width - intWidth)/2;
	intTop =  (window.screen.height - intHeight)/2;
	window.open(strImageURL, '_blank', 'width=' + intWidth + ',height=' + intHeight + ',left=' + intLeft + ',top=' + intTop + ',resizable=yes');
}


/* Check to see if a number is an integer */
function isInt(theValue)
{
	var result = true;
	var myExp = /^(\-)?\d+$/;  //Accept an optional "-" at the beginning of the value and at least 1 digit at the end.
	if(!myExp.test(theValue) || isNaN(theValue))
	{
		result = false;
	}
	return result;
}

/* Checks to see if one value is between two other values [Accepts integers, floats, and strings] */
function isBetween(theValue, low, high)
{
	var result = false;
	if(theValue >= low && theValue <= high)
	{
		result = true;
	}
	return result;
}

/*Check if the value of the field is in the range between the low and high integer value*/
function inRange(txtField, intLow, intHigh)
{
	if(txtField.value.length > 0)
	{	
		if((!isBetween(txtField.value, intLow, intHigh) || !isInt(txtField.value)))
		{
			alert('This field should be between ' + intLow + ' and ' + intHigh + ' inclusive, with no decimals.');
			txtField.focus();
			txtField.select();
			return false;
		}
	}
	return true; // Means that there were no problems...
}
