function AdminLogin(){

	
	var frm = document.loginForm;
	var frmFields = new Array('username', 'pword');

	for (var i in frmFields) {
		
		// Check each required field in the array.
		if (Trim(frm.elements[frmFields[i]].value) == '') {
			NotValid( frm, frmFields[i], GetDisplayName( frmFields[i] ) + ' Field is not Valid' );
			return false;
		}

		// Check each required field in the array.
		if (Trim(frm.elements[frmFields[i]].value).length < 5 ) {
			NotValid( frm, frmFields[i], GetDisplayName( frmFields[i] ) + ' Value Must Contain At Least 5 Characters' );
			return false;
		}

		// Check each required field in the array.
		if (Trim(frm.elements[frmFields[i]].value).length > 16 ) {
			NotValid( frm, frmFields[i], GetDisplayName( frmFields[i] ) + ' Value Must Not Contain More than 16 Characters' );
			return false;
		}

	}

	frm.action = "?action=logonrequired";
	frm.submit();
}


function NotValid(frm, strFieldName, strErrorMessage) {
	frm.elements[strFieldName].focus();
	frm.elements[strFieldName].select();
	alert(strErrorMessage);
}

function GetDisplayName(strFieldName) {
	switch (strFieldName) {
		case 'username':			return 'Username';
		case 'pword':			return 'Password';
		default:					return 'Selected';
	}
}

function Trim(strInput) {
	return strInput.replace(/\s/g, '');
}

function ChangeMyZone( url, zone ) {
	
	window.location.href = url + "?zone=" + zone;
}

function changePage( action, page, query, string, value ){

	var url = "";
	page--;
	
	if ( query != "" ) {
		url = "?action="+action+"&page="+page+"&"+q+"="+s;
	}
	else{
		url = "?action="+action+"&page="+page;
	}
	window.location.href = url;
}

function redirect( url ){
		window.location.href = url;
}

function Trim(strInput) {
	return strInput.replace(/\s/g, '');
}

function PhotoViewer( popupLocation, id  ){
	
		popupLocation = "http://" + document.domain + "/model/multimedia/image/view.php" + "?id=" + id;
		var popupWidth = 1080;
		var popupHeight = 850;
		var statusBarOn = true;
	
		var heightspeed = 20; 	// vertical speed
		var widthspeed 	= 20;  	// horizontal speed
		var leftdist 	= (screen.width - popupWidth) / 2;    	// distance to left edge of window
		var topdist 	= (screen.height - popupHeight) / 2;   	// distance to top edge of window
		if (document.all)
		{
			if (statusBarOn) 
			{
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			} 
			else
			{ 
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			}
	
			for (sizeheight = 1; sizeheight < popupHeight; sizeheight += heightspeed) 
			{
				popup.resizeTo("1", sizeheight);
			}
			for (sizewidth = 1; sizewidth < popupWidth; sizewidth += widthspeed) 
			{
				popup.resizeTo(sizewidth, sizeheight);
			}
			
			popup.resizeTo(popupWidth, popupHeight);
			popup.location = popupLocation;
		}
		else
		{
			var popup = window.open(popupLocation,"","left=" + leftdist + ",top=" + topdist + ",width=" + popupWidth + ",height=" + popupHeight + ",scrollbars=yes");
		}
	
}

function PopUp( popupLocation  ){
	
		var popupWidth = 1200;
		var popupHeight = 950;
		var statusBarOn = true;
	
		var heightspeed = 20; 	// vertical speed
		var widthspeed 	= 20;  	// horizontal speed
		var leftdist 	= (screen.width - popupWidth) / 2;    	// distance to left edge of window
		var topdist 	= (screen.height - popupHeight) / 2;   	// distance to top edge of window
		if (document.all)
		{
			if (statusBarOn) 
			{
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			} 
			else
			{ 
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			}
	
			for (sizeheight = 1; sizeheight < popupHeight; sizeheight += heightspeed) 
			{
				popup.resizeTo("1", sizeheight);
			}
			for (sizewidth = 1; sizewidth < popupWidth; sizewidth += widthspeed) 
			{
				popup.resizeTo(sizewidth, sizeheight);
			}
			
			popup.resizeTo(popupWidth, popupHeight);
			popup.location = popupLocation;
		}
		else
		{
			var popup = window.open(popupLocation,"","left=" + leftdist + ",top=" + topdist + ",width=" + popupWidth + ",height=" + popupHeight + ",scrollbars=yes");
		}
	
}


function Selector( file, type, field ){
		
	
		var popupWidth = 1040;
		var popupHeight = 800;
		var statusBarOn = true;
	
		var heightspeed = 20; 	// vertical speed
		var widthspeed 	= 20;  	// horizontal speed
		var leftdist 	= (screen.width - popupWidth) / 2;    	// distance to left edge of window
		var topdist 	= (screen.height - popupHeight) / 2;   	// distance to top edge of window
		if (document.all)
		{
			if (statusBarOn) 
			{
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			} 
			else
			{ 
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			}
	
			for (sizeheight = 1; sizeheight < popupHeight; sizeheight += heightspeed) 
			{
				popup.resizeTo("1", sizeheight);
			}
			for (sizewidth = 1; sizewidth < popupWidth; sizewidth += widthspeed) 
			{
				popup.resizeTo(sizewidth, sizeheight);
			}
			
			popup.resizeTo(popupWidth, popupHeight);
			popup.location = file + "?action=" + type + "&field=" + field;
		}
		else
		{

			var popup = window.open(file + "?action=" + type + "&field=" + field,"","left=" + leftdist + ",top=" + topdist + ",width=" + popupWidth + ",height=" + popupHeight + ",scrollbars=yes");
		}
}

function DatePicker( calendar, field ){
		
		var popupWidth = 400;
		var popupHeight = 400;
		var statusBarOn = true;
	
		var heightspeed = 20; 	// vertical speed
		var widthspeed 	= 20;  	// horizontal speed
		var leftdist 	= (screen.width - popupWidth) / 2;    	// distance to left edge of window
		var topdist 	= (screen.height - popupHeight) / 2;   	// distance to top edge of window
		if (document.all)
		{
			if (statusBarOn) 
			{
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			} 
			else
			{ 
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			}
	
			for (sizeheight = 1; sizeheight < popupHeight; sizeheight += heightspeed) 
			{
				popup.resizeTo("1", sizeheight);
			}
			for (sizewidth = 1; sizewidth < popupWidth; sizewidth += widthspeed) 
			{
				popup.resizeTo(sizewidth, sizeheight);
			}
			
			popup.resizeTo(popupWidth, popupHeight);
			popup.location = calendar + "?field=" + field;
		}
		else
		{
			var popup = window.open(calendar + "?field=" + field,"","left=" + leftdist + ",top=" + topdist + ",width=" + popupWidth + ",height=" + popupHeight + ",scrollbars=yes");
		}
}

function returnDate(date, field){

	if (window.opener && !window.opener.closed) {
		
    	window.opener.insertDate(date, field);
	}
    
	window.close();
}


function ChangeMonth(year, field) {

	var frm = document.calendar;
	changeMonth = frm.month.value;

	window.location.href = "calendar.php?month=" + changeMonth + "&year=" + year + "&field=" +field;

}

function Month(month, year, field ){

	if ( month < 1 ) {
		window.location.href = "calendar.php?month=" + 12 + "&year=" + (year-1) + "&field=" +field;
	}
	else if ( month > 12 ) {
		window.location.href = "calendar.php?month=" + 1 + "&year=" + (year+1) + "&field=" +field;
	}
	else {
		window.location.href = "calendar.php?month=" + month + "&year=" + year + "&field=" +field;
	}

	
}

function ChangeYear( month, field ) {
	var frm = document.calendar;
	window.location.href = "calendar.php?month=" + month + "&year=" + frm.year.value + "&field=" +field;
}

function Help( topic  ){
	
		popupLocation = "http://" + document.domain + "/help/" + "?topic="+ topic;
		
		var popupWidth = 1050;
		var popupHeight = 750;
		var statusBarOn = true;
	
		var heightspeed = 20; 	// vertical speed
		var widthspeed 	= 20;  	// horizontal speed
		var leftdist 	= (screen.width - popupWidth) / 2;    	// distance to left edge of window
		var topdist 	= (screen.height - popupHeight) / 2;   	// distance to top edge of window
		if (document.all)
		{
			if (statusBarOn) 
			{
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			} 
			else
			{ 
				var popup = window.open("","","left=" + leftdist + ",top=" + topdist + ",width=4,height=4,scrollbars=yes,resizable=yes,status=yes");
			}
	
			for (sizeheight = 1; sizeheight < popupHeight; sizeheight += heightspeed) 
			{
				popup.resizeTo("1", sizeheight);
			}
			for (sizewidth = 1; sizewidth < popupWidth; sizewidth += widthspeed) 
			{
				popup.resizeTo(sizewidth, sizeheight);
			}
			
			popup.resizeTo(popupWidth, popupHeight);
			popup.location = popupLocation;
		}
		else
		{
			var popup = window.open(popupLocation,"","left=" + leftdist + ",top=" + topdist + ",width=" + popupWidth + ",height=" + popupHeight + ",scrollbars=yes");
		}
	
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
