function newCenterWin(w,h,url){
	// width of the new window
	var wWidth = w;
	// height of the new window
	var wHeight = h;
	// window left position
	var posL = (window.screen.availWidth - wWidth) / 2;
	// window top position
	var posT = (window.screen.availHeight - wHeight) / 2;
	// see if extra param has passed in
	if(arguments.length==4){
		var extra = ',' + arguments[3];
	}else{
		var extra = "";
	}
	var newWin = window.open(url,"centreWindow",'width=' + wWidth + ',height=' + wHeight + ',top=' + posT + ',left=' + posL + extra);
	newWin.focus();
}




function f2gInfo(wForm){
	wForm.address.value = "210 - 1807 Maritime Mews";
	wForm.city.value = "Vancouver";
	wForm.province.selectedIndex = 2;
	wForm.country.selectedIndex = 1;
	wForm.postal.value = "V6H 3W7";
	wForm.phone.value = "604-736-0525";
}

function noInfo(wForm){
	wForm.address.value = "";
	wForm.city.value = "";
	wForm.province.selectedIndex = 0;
	wForm.country.selectedIndex = 0;
	wForm.postal.value = "";
	wForm.phone.value = "";
}


function checkSwitch(checkbox,objs){
	if(checkbox.checked == false){
	//alert('uncheck')
		uncheckServ(checkbox,objs);
	}else{
	//alert('check')
		checkServ(checkbox,objs)
	}
}

function checkServ(checkbox,objs){
	checkMe(eval(checkbox));
	if(objs.length > 0){
		textBoxArray = objs.split(",");
			for(i=0;i<textBoxArray.length;i++){
				x = eval('document.editServ.' + textBoxArray[i])
				x.disabled = false;
				x.className = '';
			}
	}
}

function uncheckServ(checkbox,objs){
	if(objs.length > 0){
		textBoxArray = objs.split(",");
			if(textBoxArray.length > 0){
				for(i=0;i<textBoxArray.length;i++){
					x = eval('document.editServ.' + textBoxArray[i])
					x.disabled = true;
					x.className = 'disableText';
				}
			}
	}
}

function checkMe(checkbox){
	checkbox.checked = true;
}


function chkServ(){
// @ error check, before submit
// @ formEle[x][0] is check box name
// @ formEle[x][1] is text boxes name
// @ formEle[x][2] is error message
formEle = new Array()
	formEle[0] = new Array(2)
		formEle[0][0] = "servCart";
		formEle[0][1] = "cartUn,cartPw,cartUrl";
		formEle[0][2] = "Shopping Cart info is incomplete";
	formEle[1] = new Array(2)
		formEle[1][0] = "servStat";
		formEle[1][1] = "statUn,statPw,statUrl";
		formEle[1][2] = "Statisitc info is incomplete";

	var f = "document.editServ.";
	var errMsg = "";
	// loop thought above array
	for(var i = 0; i < formEle.length; i++){
		// if check box is checked
		if(eval(f + formEle[i][0] + ".checked")){
			// make an array of text boxes
			txtBoxesArr = formEle[i][1].split(",");
				// loop thought text boxes array
				for(var j = 0; j < txtBoxesArr.length; j++){
					// if text box is empty
					if(!eval(f + txtBoxesArr[j] + ".value.length")){
						// set messages
						errMsg = errMsg + formEle[i][2];
						return throwErr(errMsg);
					}
				}
		}
	}
	document.editServ.target = "_self";
	document.editServ.action = "service.cfm";
	document.editServ.submit();
}

// test user's service logins
function testLogin(un,pw,lk,serv,act){
errMsg = ""
	if(!un.value.length){
		errMsg = "Please enter the username for " + serv;
		return throwErr(errMsg);
	}
	if(!pw.value.length){
		errMsg = "Please enter the password for " + serv;
		return throwErr(errMsg);
	}
	if(lk.value.indexOf("http://") != 0){
		errMsg = "Please enter the link for " + serv;
		return throwErr(errMsg);
	}
	document.editServ.act.value = act;
	document.editServ.username.value = un.value;
	document.editServ.password.value = pw.value;
	document.editServ.serviceUrl.value = lk.value;
	document.editServ.target = "_blank";
	document.editServ.action = "../inc/quickLoginDisplay.cfm?mode=admin&act=" + act;
	document.editServ.submit();
}

// check user 
function chkUser(f){
errMsg = ""
	// chk fullname
	if(!f.fullname.value.length){
		errMsg = "Please enter the user\'s fullname";
		return throwErr(errMsg)
	}
	// chk email
	if(!isValidEmail(f.email.value)){
		errMsg = "Invalid email address";
		return throwErr(errMsg)
	}
	// chk address
	if(!f.address.value.length){
		errMsg = "Please enter the user\'s address";
		return throwErr(errMsg)
	}
	// chk city
	if(!f.city.value.length){
		errMsg = "Please enter the user\'s city";
		return throwErr(errMsg)
	}
	// chk province
	if(!f.province.value.length){
		errMsg = "Please enter the user\'s province";
		return throwErr(errMsg)
	}
	// chk phone
	if(!f.phone.value.length){
		errMsg = "Please enter the user\'s phone";
		return throwErr(errMsg)
	}
	// chk website
	if(f.website.value.indexOf("http://")!=-1 || f.website.value.indexOf("www.")!=-1){
		errMsg = "Website should be \"mydomain.com\" without \"http://\" or \"www.\"";
		return throwErr(errMsg)
	}
	// chk username
	if(f.username.value.length < 3){
		errMsg = "Login username must be 3 or more characters long";
		return throwErr(errMsg)
	}
	// chk password length
	if(f.password.value.length < 3){
		errMsg = "Password must be 3 or more characters long";
		return throwErr(errMsg)
	}
	// chk password and re-password
	if(f.password.value != f.repassword.value){
		errMsg = "Passwords don\'t match";
		return throwErr(errMsg)
	}
	
}

// if errMsg has value, alert, and abort
function throwErr(msg){
		alert(msg);
		return false;	
}

// confirmation dialog box
function confirmBox(msg){
	var dummy = confirm(msg)
		if(dummy){
			return true;
		}else{
			return false;
		}
}

// send email form checking
function chkSendSetting(f){
	msg = "";
		
		/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		if individual is selected
		@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
		if(f.mto[0].checked){
			// chk send to address
			if(!isValidEmail(f.mtoaddr.value)){
				errMsg = "Please provide a valid email on \"Send To\" field";
				return throwErr(errMsg);
			}
		/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		if group is selected
		@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
		}else if(f.mto[1].checked){
			// assume no group is selected
			hasSelected = false;
			// see if only 1 group exists
			if(!f.groupId.length){
				// see if that 1 group has selected
				hasSelected = f.groupId.checked;
			// if multi-group
			}else{
				// loop though x number of groups
				for(var i=0;i<f.groupId.length;i++){
					// hasSelected will be true if at least 1 group is checked
					if(f.groupId[i].checked){
						hasSelected = true;
					}
				}
			}
			// if not even 1 group has selected
			if(!hasSelected){
				errMsg = "Please select at least 1 group to send to";
				return throwErr(errMsg);
			}
		}
		/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		check email format
		@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
		var hasSelected = false;
		// loop through the selection
		for(var i=0;i<f.mformat.length;i++){
			if(f.mformat[i].checked){
				hasSelected = true;
			}
		}
		// if no format has selected
		if(!hasSelected){
			errMsg = "Please select the format of your email campaign";
			return throwErr(errMsg);
		}
		// chk reply to address
		if(!isValidEmail(f.mfrom.value)){
			errMsg = "Please provide a valid email on \"Send From\" field";
			return throwErr(errMsg);
		}
		// chk mail subject
		if(!f.msubject.value.length){
			errMsg = "Mail subject cannot be blank";
			return throwErr(errMsg);
		}
		// chk mail subject not too long
		if(f.msubject.value.length > 60){
		errMsg = "Subject cannot be longer than 60 characters";
		return throwErr(errMsg)
		}
	return true;
}

// if preview button is clicked
function emailPreview(wForm){
	if(chkCampiagn(wForm)){
		wForm.action = "mlPreview.cfm";
		wForm.target = "childWin";
		newCenterWin('', 70, 60, 'true', 'toolbar=0,menubar=0,status=1');
		wForm.submit();
	}
}

// if send button is clicked
function emailSend(wForm){
	if(chkCampiagn(wForm)){
		wForm.action = "mlSend.cfm";
		wForm.target = "_self";
		wForm.submit();
	}
}

// return ture is email address is valid
function isValidEmail(email){
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
		if (index > 0){
			var pindex = theStr.indexOf(".",index);
				if ((pindex > index+1) && (theStr.length > pindex+1))
					result = true;
				}
	return result;
}

// this is for CF validate email
function validateEmail(form, ctrl, value) {
  if (value == "" || value.indexOf ('@', 1) == -1 || 
value.indexOf ('.', 3) == -1) 
  {
    return (false);
  } 
  else
  {
    return (true);
  } 
}

// check/uncheck all checkbox(es)
function checkBoxSwtich(checkbox,targetCheckbox,rc){
	if(rc > 1){
		if(!checkbox.checked){
			for(i=0;i<targetCheckbox.length;i++){
				targetCheckbox[i].checked = false;
			}
		}else{
			for(i=0;i<targetCheckbox.length;i++){
				targetCheckbox[i].checked = true;
			}
		}
	}else if(rc == 1){
		if(!checkbox.checked){
			targetCheckbox.checked = false;
		}else{
			targetCheckbox.checked = true;
		}
	}
}

function navMouseOver(element){
	element.className = 'navover';
}

function navMouseOut(element){
	element.className = 'nav';
}

function navGoTo(lk){
	self.location = lk;
}

function hasCheck(obj,rc){
	// default is nothing checked
	var isCheck = false;
	// if record count is zero, return false anyway
	if(rc == 0){
		isCheck = false;
	}
	// if record count is 1, see if that 1 has checked
	else if(rc == 1){
		if(obj.checked){
			isCheck = true;
		}
	}
	// loop thu the element if there are more than 1
	else if(rc > 1){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				isCheck = true;
			}
		}
	}
	// return result
	return isCheck;
}

function jumpToPageNumber(page,st,srt,ascdesc,groupId){
	window.location = page + "?st=" + st + "&srt=" + srt + "&ascdesc=" + ascdesc + "&groupId=" + groupId
}