//****************************************
// IW/QS FUNCTIONS
//****************************************
function addToLightbox(imageIDs) {
	window.open(GL_SITE_ROOT + "lightbox_popup.php?Lightbox_Unique_ID=" + imageIDs, "", "height=600,width=570,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,left=0,top=0,directories=no");
}

//****************************************
// GENERAL FUNCTIONS
//****************************************
function FormatNumber(expr, decplaces) {
	var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
	
	while (str.length <= decplaces) {
		str = "0" + str;
	}
	
	var decpoint = str.length - decplaces;
	
	return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);
}

function trim (str) {
	while (str.charAt(0) == ' ') {
		str = str.substring(1);
	}
	
	while (str.charAt(str.length - 1) == ' ') {
		str = str.substring(0, str.length - 1);
	}
	
	return str;
}

function isValidDate(sDate) {
	//Check to make sure two slashes are present in the date provided
	if (sDate.lastIndexOf('/') <= sDate.indexOf('/')) {
		return false;
	}

	//Split on slash
	sDateArray = sDate.split('/');
	
	sMonth = sDateArray[0];
	sDay = sDateArray[1];
	sYear = sDateArray[2];
	
	//Validate year part
	if (isNaN(sYear)) {
		return false;
	}
	
	if (sYear.length == 2) {
		sYear = parseInt('20' + sYear);
	} else {
		if (sYear.length != 4) {
			return false;
		}
	}
	
	if (sDay <= daysInMonth(sMonth, sYear)) {
		return true;
	} else {
		return false;
	}
}
	
function isLeapYear(yr) {
	if      (yr % 4 != 0)   return false;
	else if (yr % 400 == 0) return true;
	else if (yr % 100 == 0) return false;
	else                    return true;
}

function daysInMonth(mn, yr) {
	var mDay;
	
	if ((mn == 4) || (mn == 6) || (mn == 9) || (mn == 11)) { 
		mDay = 30;
	} else if (mn == 2) {
		//calling leap year function 
		mDay = isLeapYear(yr) ? 29 : 28;    
	} else {
		mDay = 31;
	}
	
	return mDay; 
}

function reloadCaptcha(root) {
	var captchaImage = document.getElementById('captcha');
	var captchaInput = document.getElementById('captchaCode');
	
	captchaImage.src = root + 'inc/securimage/show.php?t=' + Math.random();
	captchaInput.value = '';
	captchaInput.focus();
	
	return false;
}