// <![CDATA[
			
function trim(varString){

	var strTemp = varString.toString();
		
	if(strTemp.indexOf(" ") >= 0){
	
		// Left Trim
		for (i=0; i < strTemp.length; i++) {
			if(strTemp.charAt(i) == " "){
				strTemp = strTemp.substring(i + 1);
			}
			else{
				break
			}
		}
		
		// Right Trim
		for (i=strTemp.length - 1;  i >= 0; i--) {
			if(strTemp.charAt(i) == " "){
				strTemp = strTemp.substring(0, i);
			}
			else{
				break
			}
		}
	}
	
	return strTemp
}

function IsValidEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
	return false
	}

	for (i=0; i<invalidChars.length; i++) {
	badChar = invalidChars.charAt(i)
	if (email.indexOf(badChar,0) > -1) {
	return false
	}
}	
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
	return false
	}

	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
	return false
	}

	if (periodPos+3 > email.length) {
	return false
	}

	return true
}

function SQLInjection(strText) {

	var	arrBadChars = new Array("&", "'", "\"", "+", ",", "(", ")");

	for (i=0; i < arrBadChars.length; i++) {
		if (strText.indexOf(arrBadChars[i], 0) > -1) {
			return true
			break;
		}
	}
	return false
}

/* 
	IsNumeric() Function
	Imitates the VB function of the same name by returning true if the value is numeric
	and false if it is not.
	This function is more user friendly than the JavaScript isNan() function because it allows for 
	decimal points. 
*/
function IsNumeric(varValue) {
	
	varValue = varValue.toString();

	if (varValue.length == 0){
		return false;
	}
	
	for (var n = 0; n < varValue.length; n++){
	
		if (isNaN(varValue.substring(n, n+1)) && (varValue.substring(n, n+1) != "."))
			return false;
		}
		
	return true;
}

/*
 CheckValidDate Procedure
 This function determines if the date is valid and has been entered in dd/mm/yy
 form. This ensures that the date can be converted to Medium Date
 format on the server without any problems.
*/

function IsDate(strDate){

	var blnResult = true;

	// check that the string is at least 6 characters long ie. 1/1/03.		
	if (strDate.length < 6){ 
		blnResult = false;
	}
	else{
		// check that there are 3 values separated by forward slashes.
		var arrDate = strDate.split("/")
	
		if(arrDate.length != 3){ 
			blnResult = false;
		}
		else{
			// check that each of the 3 values are numeric
			for (i = 0; i <= 2; i++){
				if(isNaN(arrDate[i])){
					blnResult = false;
				}
				else{
					/*
					 check that the month (array element 1) is between 1 and 12
					 and the days (array element 0) do not exceed the number of days in the month
					 */
					if (i == 1) {	// Jan, Mar, May, July, Aug, Oct, Dec
						if (arrDate[i] == 1 || arrDate[i] == 3 || arrDate[i] == 5 || arrDate[i] == 7 ||
							arrDate[i] == 8 || arrDate[i] == 10 || arrDate[i] == 12){
							if(arrDate[0] < 1 || arrDate[0] > 31){
								blnResult = false;
							}
						}			// Apr, Jun, Sep, Nov
						else if(arrDate[i] == 4 || arrDate[i] == 6 || arrDate[i] == 9 || arrDate[i] == 11){
								if(arrDate[0] < 1 || arrDate[0] > 30){
									blnResult = false;
								}
						}
						else if (arrDate[i] == 2){ 		// Feb
							
							if (arrDate[2] % 4 == 0){ 	// leap year
								if(arrDate[0] < 1 || arrDate[0] > 29){
									blnResult = false;
								}
							}
							else{ 						// non leap year
								if(arrDate[0] < 1 || arrDate[0] > 28){
									blnResult = false;
								}
							}
						}
						else{
							blnResult = false;
						}
					}
				}
			}
		}
	}
	return blnResult;
}

function ClearLoginField(objField){
	if(objField.name == "txtLoginEmail" && objField.value == "email address"){
		 objField.value = "";
	} else if (objField.name == "txtLoginPassword" && objField.value == "password"){
		 objField.value = "";
	}
}

function SubscriberLogin(){
	
	var intErrors = 0;
	var strErrors = "Sorry, your login could not be processed for the following reasons:\n\n";
	
	if(!IsValidEmail(trim(document.frmLogin.txtLoginEmail.value))){
		intErrors++;
		strErrors+= intErrors +") The email address entered appears to be invalid.\n";
	}
	
	if(0 == trim(document.frmLogin.txtLoginPassword.value).length){
		intErrors++;
		strErrors+= intErrors +") Please enter your first name.\n";
	}
	
	if(0 == intErrors){
		return true;
	} else {
		alert(strErrors);
		return false;
	}
}

var blnIsSafari = false;

if(navigator.vendor){
	if (navigator.vendor.indexOf("Apple") != -1){
		blnIsSafari = true;
	}
}

function AbsolutePosition(strObjectName, strAxis){
	
	if (document.getElementById) {	//  IE 5+, NS6+, Mozilla
		obj = document.getElementById(strObjectName);
	} else if(document.all) { 
		obj = document.all.item(strObjectName);
	}
	
	var objOriginal = obj;
	
	var intTempPos = 0;
	
	if (strAxis.toUpperCase() == 'Y'){
		
		if (obj.offsetParent) {
			intTempPos = obj.offsetTop
			while (obj = obj.offsetParent) {
				intTempPos += obj.offsetTop;
			}
		}
		
	} else if (strAxis.toUpperCase() == 'X'){
		
		if (obj.offsetParent) {
			intTempPos = obj.offsetLeft
			while (obj = obj.offsetParent) {
				intTempPos += obj.offsetLeft;
			}
		}
		
	} 
	
	return intTempPos;

}

function ShowSubMenu(MenuID, intOffsetX, intOffsetY){
		
	var objMenu = document.getElementById("SubMenu"+ MenuID);
	
	/* Since Firefox can't calculate the position of a dynamically positioned object
	We have to use the parent object as the starting point for the sub menus
	Hence we trim off the first integer ( which represents the parent object)
	NOTE: This limits this script to 10 parent items (starting from 0)
	*/
	
	var strMenuID = MenuID.toString();
	var ParentMenuID = strMenuID.substr(0, 1);
	var	intPosY = AbsolutePosition("Menu" + ParentMenuID , "Y");
	var	intPosX = AbsolutePosition("Menu" + ParentMenuID , "X");
	
	/* Safari has a weird positioning problem which requires manual vertical adjustments */
	if(blnIsSafari){
		
		strURL = document.URL;
		strPage = strURL.substring(strURL.lastIndexOf('/') + 1, strURL.length);
		arrFolders = strURL.split('/');
		
		if(arrFolders.length < 5 && strPage == "index.php"){ // Main Home Page 
			intPosY += 50;
		} 
		
	} 
	
	objMenu.style.left = (intPosX + intOffsetX) + "px";
	objMenu.style.top  = (intPosY + intOffsetY) + "px";
	objMenu.style.display = "block";
		
	objMenu = null;
	
}

function HideSubMenu(MenuID){
	
	var objMenu = document.getElementById("SubMenu"+ MenuID);
	objMenu.style.display = "none";
	objMenu = null;
	
}

// Pop Up Window function for the REUNCUT player
function popup(URL,w,h,scrollbars) {
	eval("page = window.open(URL, 'reuncutplayer', 'toolbar=0,scrollbars=' + scrollbars + ',location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + "');");
}

// ]]>