function init(){
	var els = document.getElementsByTagName("*");
	for(i=0;i<els.length;i++){
		if(els[i].type=='text'){
			els[i].focus()
			break
		}
	}
}

function btnaction(action){
	switch(action){
	case 'logout':
		document.location="admin-login.asp"
		break
	case 'menu':
		document.location="admin-index.asp"
		break
	}
}

	function validate_events(){
		var isValid = 1;
		var msgStr =''
		var re
		
		if(document.getElementById('ContactNumber').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a contact phone number\n';
		}
				
		if(document.getElementById('Title').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the event title\n';
		}

		if(document.getElementById('StartDate').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a start date\n';
		}

		if(document.getElementById('EndDate').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter an end date\n';
		}
		
		list = document.getElementById('scope')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the scope of the event\n';
		}
		
		list = document.getElementById('TypeofEvent')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the type of event\n';
		}

		if(document.getElementById('City').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the city that the event takes place in \n';
		}
		
		list = document.getElementById('State')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the state that the event takes place in\n';
		}		
		
		
		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
			}
	} 
	
	
function validate_announcement(){
		var isValid = 1;
		var msgStr =''
		var re
		
		if(document.getElementById('Title').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a title\n';
		}
		
		if(document.getElementById('Url').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a URL\n';
		}
		
		if(document.getElementById('Details').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter details of the announcement\n';
		}	
		
		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
			}
}	
	
function validate_signup(){
		var isValid = 1;
		var msgStr =''
		var re
	
		if(document.getElementById('name').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your full first and last names\n';
		}
		
		if(document.getElementById('email').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your email address\n';
		}
		else{
			re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	        if (!re.test(document.getElementById('email').value) == true){
				isValid = 0;
				msgStr = msgStr + 'Your email address does not appear to be valid.\n';
			}
		}
		
		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
			}
}	


	
function validate_staff(){
		var isValid = 1;
		var msgStr =''
		var re
		
		if(document.getElementById('fname').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a first name\n';
		}

		if(document.getElementById('lname').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a last name\n';
		}
		
		if(document.getElementById('position').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the staff members position\n';
		}
		
		if(document.getElementById('phone').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a phone number\n';
		}	
		
		if(document.getElementById('email').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter an email address\n';
		}	
		else{
			re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	        if (!re.test(document.getElementById('email').value) == true){
				isValid = 0;
				msgStr = msgStr + 'Your email address does not appear to be valid please double check it.\n';
			}
		}

		if(document.getElementById('username').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a username\n';
		}			
		if(document.getElementById('password').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a password\n';
		}					

		list = document.getElementById('access')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the access level\n';
		}		

		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
		}
}		

function validate_login(){
		var isValid = 1;
		var msgStr =''
		var re
		
		if(document.getElementById('username').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a username\n';
		}
		
		if(document.getElementById('password').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter a password\n';
		}
		
		
		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
			}
}	


function validate_request(){
		var isValid = 1;
		var msgStr =''
		var re
		
		if(document.getElementById('fname').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your first name\n';
		}
				
		if(document.getElementById('lname').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your last name\n';
		}

		if(document.getElementById('email').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your email address\n';
		}

		if(document.getElementById('phone').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your phone number\n';
		}
		
		list = document.getElementById('state')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your State or Jurisdiction \n';
		}
		
		list = document.getElementById('role')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your primary role in relation to this request.\n';
		}

		if(document.getElementById('needs').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your information needs\n';
		}
		
		list = document.getElementById('delivery')
		if(list[list.selectedIndex].value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter your desired delivery format\n';
		}		
		
		if(document.getElementById('dateneeded').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter the date you need the information by\n';
		}
		if(document.getElementById('whydeadline').value == ''){
			isValid = 0;
			msgStr = msgStr + 'Please enter why you need the information by the date specified\n';
		}
		
		
		if(isValid == 0){
			alert(msgStr);
			return false
		}
		else{
			return true
			}
	} 
	

var popupWin
var prompted = false
function offsitelink(url){
	maxW = self.screen.availWidth-10 
	maxH = self.screen.availHeight-25
	if(popupWin && popupWin.open && !popupWin.closed){
		popupWin.close();
	}
	if(!getCookie('surveyPrompt')==1&&prompted==false){
		prompted = true
		liRet = confirm("Would you like to conduct our usability survey?");
		if(liRet){
			popupWin = window.open('http://studies.web-surveys.net/NCRRCUsability/?url=' +url,"","width="+ maxW +",scrollbars=yes,height="+maxH+",status=yes,toolbar=yes,menubar=yes,location=yes")
			}
		else{
			popupWin = window.open(url,"","width="+ maxW +",scrollbars=yes,height="+maxH+",status=yes,toolbar=yes,menubar=yes,location=yes")
			}
		}
	else{
		popupWin = window.open(url,"","width="+ maxW +",scrollbars=yes,height="+maxH+",status=yes,toolbar=yes,menubar=yes,location=yes")
	}
	var ExpireDate = new Date()
	ExpireDate.setMonth(ExpireDate.getMonth()+3)
	setCookie('surveyPrompt',1,ExpireDate)
}
	
	

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}