/* Author: Datapix: K.Barklem
	 Last Modified: 12-Jun-2006 */

	var win = null;

function newWindow(pagelink,pagetitle,w,h,features) {
	// setup window position for centre of screen
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? ((screen.height-h)/2) -20 : 0;

	// set window properties
	settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',' + features;

	// show window
	win = window.open(pagelink,pagetitle,settings);
	return;
}


function checkError() {
	var errValue = '';	
	var errCtrl = window.parent.mainbody.document.getElementById('profileError');
	
	errValue = errCtrl.value;
	errCtrl.value = '';

	if (errValue != '')	{
		alert('There were errors saving profile');
		editProfile(errValue);
		//window.parent.mainbody.document.forms['frmMyProfile'].cmdManage.click();
	}
	return;
}


function read_param(pname) {
  // get URL
	var docloc = document.URL.toString();

	// check that parameters were passed
	if (docloc.indexOf("?") == -1) { return ''; }
	
	// get parameters
	var paramstr = docloc.substr(docloc.indexOf("?") + 1, docloc.length);
	var params = paramstr.split("&");
	
	// loop until we find the parameter were looking for
	for(myEnum=0; myEnum < params.length; myEnum++)
	{
		var param = params[myEnum].split("=");
		if ((param[0] == pname) && (param[1].length != 0)) { return(param[1]);	}	//we found the parameter, return the value
  }
	
	// no parameter was found, return nothing
	return '';
}


//process for preloading images
function preloadImages(images) {
	for(loop = 0; loop < images.length; loop++)
	{
		var image = new Image();
		image.src = images[loop];
	}
	return;
}

function check_err() {

	var errtype = read_param('err');

	switch (errtype) {
		case 'vname':
			self.document.write('You must supply your first and last name! &nbsp; Please try again.');
			break;
		case 'oname':
			self.document.write('You must supply an organization and contact name! &nbsp; Please try again.');
			break;
		case 'len':
			self.document.write('Password length must be 6 to 12 characters long! &nbsp; Please try again.');
			break;
		case 'match': 
			self.document.write('Passwords don\'t match! &nbsp; Please try again.');
			break;
		case 'log': 
			self.document.write('Incorrect email address or password! &nbsp; Please try again.');
			break;
		case 'used':
			output = 'That user name is already registered! &nbsp; If you have forgotten ';
			output += 'your password <a href="resetpwd.html">click here</a>, or try again.';
			self.document.write(output);
			break;
		case 'acct': 
			self.document.write('Login failed! &nbsp; Incorrect email address or password. &nbsp; Please try again.');
			break;
		case 'sys': 
			self.document.write('System Error! &nbsp; Login failed! &nbsp; Please try again.');
			break;
		case 'reg': 
			self.document.write('System Error! &nbsp; Registration failed! &nbsp; Please try again later.');
			break;
		case 'chg': 
			self.document.write('System Error! &nbsp; Account change failed! &nbsp; Please try again later.');
			break;
		case 'usedchg':
			self.document.write('That account is already setup in our database! &nbsp; Please try again.');
			break;
		case 'nochg':
			self.document.write('No changes have been made! &nbsp; Please try again.');
			break;
		case 'nouser':
			self.document.write('User account could not be found! &nbsp; Please try again.');
			break;
		case 'noagree':
			self.document.write('Agreement to "Terms of Use" required to create account! &nbsp; Account not created!');
			break;
		case 'nomail':
			self.document.write('Confirmation e-mail could not be sent! &nbsp; Account not created!');
			break;
		default:
			self.document.write('&nbsp;');
			break;
	}
	return;
}

function showProfile(target,id) {
	
	switch (target)	{
		case 'org':
			var linkstr = '../_php/profile/summary_org.php?id=' + id;
			break;
		case 'vol':
			var linkstr = '../_php/profile/summary_vol.php?id=' + id;
			break;
		case 'opp':
			var linkstr = '../_php/profile/summary_opp.php?id=' + id;
			break;
	}
	newWindow(linkstr, '', 640, 540, '');
	return;
}


function editProfile(target,id) {
	var linkstr = 'profile.html?profile=' + target + '&id=' + id;
	newWindow(linkstr, '', 640, 540, '');
	return;
}


function adminEditProfile(target,id) {
	var linkstr = '../profile.html?profile=' + target + '&id=' + id;
	newWindow(linkstr, '', 640, 540, '');
	return;
}


function showSaveConfirm(target,id) {
	alert('show');
	var linkstr = '_php/sav_confirm.php?profile=' + target + '&id=' + id;
	newWindow(linkstr, '', 580, 454, '');
	return;
}


function cal(ctrl, month, year) {
	var linkstr = '../calendar.php?ctrl=' + ctrl + '&month=' + month + '&year=' + year;
	newWindow(linkstr, '', 170, 200, '');
	return;
}


function showVolReq(volid, oppid) {
	var linkstr = '_php/profile/summary_req.php?id=' + volid + '&opp=' + oppid;
	newWindow(linkstr, '', 640, 540, '');
	return;
}


function showAcctNotes(acctid) {
	var linkstr = 'acct_note.php?ac=' + acctid;
	newWindow(linkstr, '', 600, 450, '');
	return;
}


function volRequest() {
	var linkstr = '../../vol/volunteer.php';
	newWindow(linkstr, '', 530, 430, '');
	return;
}


function editDox(target) {
	var linkstr = 'sitecontent_edit.php?id=' + target;
	newWindow(linkstr, '', 500, 400, '');
	return;
}


function printDocument(target) {
	//var linkstr = target;
	newWindow(target, '', 600, 450, 'scrollbars');
	return;
}


function manageVolunteers() {
	var linkstr = 'vol_manage.php';
	newWindow(linkstr, '', 780, 580, 'scrollbars');
	return;
}