
function openReminderWindow() {
	rwin = window.open('email_reminder.php','eWindow','toolbar=0,status=0,scrollbars=1,resizable=1,width=480,height=300');
	rwin.focus();
}

function checkDeleteForm(frm) {
	if(checkGenericForm(frm)) {
		return confirm("Are you sure you want to delete this entry?");
	}
	return false;
}

function showStatebox(fld) {
	frm = fld.form;
	if(fld.value == "Canada") {
		if(frm.retailersstateca) camenu = frm.retailersstateca;
		if(frm.storestate_ca_req) camenu = frm.storestate_ca_req;
		
		if(frm.storestate_req) usmenu = frm.storestate_req;
		if(frm.retailersstate) usmenu = frm.retailersstate;
		
		camenu.style.visibility = "visible";
		usmenu.style.visibility = "hidden";
	}
	if(fld.value == "US") {
		if(frm.storestate_ca_req) camenu = frm.storestate_ca_req;
		if(frm.retailersstateca) camenu = frm.retailersstateca;
		if(frm.storestate_req) usmenu = frm.storestate_req;
		if(frm.retailersstate) usmenu = frm.retailersstate;
		
		usmenu.style.visibility = "visible";
		camenu.style.visibility = "hidden";
	}

}

function checkForm(frm) {
	for (var i=0;i<frm.length;i++) {
		current = frm.elements[i];
		if(current.name.indexOf("_req") > -1) {
			if(current.value.replace(/^\s+|\s+$/, '') == "" && current.type=="text") {
				alert("You need to enter text in all required fields.");
				return false;
			}
			if(current.value.replace(/^\s+|\s+$/, '') == "" && current.type=="password") {
				alert("You need to enter text in all password fields.");
				return false;
			}
			if(current.style.visibility == "visible" && current.value == "#" && current.type != "text") {
				alert("You have to make a selection in all drop down menus.");
				return false;
			}
			if(current.value.replace(/^\s+|\s+$/, '') == "" && current.type=="textarea") {
				alert("You need to enter text in all required text areas.");
				return false;
			}
			if(current.name == "spam_req") {
				if(current.checked != true) {
					alert("You have not checked the spam verification box. Please do so and try again.");
					return false;
				}
			}
		}
	}
	return true;
}

function checkCouponForm(frm) {
	if(frm.zip_req.value.replace(/^\s+|\s+$/, '') == "") {
		alert("You need to fill in all required fields.");
		return false;
	}
	
	return true;
}

function checkFinderForm(frm) {
	if(frm.ziponly.value.replace(/^\s+|\s+$/, '') != "" && frm.radiusonly.value.replace(/^\s+|\s+$/, '') != "") {
		return true;
	}
	alert("Please fill in all fields - zip and distance.");
	return false;
}

function checkCityForm(frm) {
	if(frm.city.value.replace(/^\s+|\s+$/, '') != "" && frm.state.value != "#" && frm.radiusonly.value.replace(/^\s+|\s+$/, '') != "") {
		return true;
	}
	else {
		alert("Please fill in all fields - city, state and distance.");
		return false;
	}
}

function checkDistance(fld) {
	if(!isNumeric(fld.value)) {
		alert("Distance can only be an integer value.");
		fld.value = "";
		fld.focus();
	}
}

function checkZipCode(fld) {
	if(fld.value.replace(/^\s+|\s+$/, '') != "" && fld.value.length < 5) {
		alert("Zip codes are 5 digit numbers for US and 7 letter codes for Canada.");
		fld.value = "";
		fld.focus();	
	}
}

function checkRetailersForm(frm) {
	if(frm.name.value.replace(/^\s+|\s+$/, '') != "" && frm.email.value.replace(/^\s+|\s+$/, '') != "") {
		return true;
	}
	alert("Please fill in all fields or at least name and email.");
	return false;
}

function isNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function checkGenericForm(frm) {
	message = "";
	for (var i=0;i<frm.length;i++)
	{
		current = frm.elements[i];
		if(current.name=="rightemployee" || current.name.indexOf("sel") > -1) {}
		else if(current.name == "hwebedit" || current.name == "newhweb") {}
		else if(frm.payperiod != null) {
			if(frm.payperiod.value == "#" && frm.payperiod_m.value == "#") {
				alert("You have to make a selection in all drop down menus.");
				return false;
			}
			if(frm.payperiod.value != "#" || frm.payperiod_m.value != "#") 
				return true;
		}
		else if(current.value.replace(/^\s+|\s+$/, '') == "" && current.type=="text") {
			alert("You need to enter text in all required fields.");
			return false;
		}
		else if(current.value.replace(/^\s+|\s+$/, '') == "" && current.type=="password") {
			alert("You need to enter text in all password fields.");
			return false;
		}
		else if(current.style.visibility == "visible" && current.value == "#" && current.type!="text") {
			alert("You have to make a selection in all drop down menus.");
			return false;
		}
	}
	return true;
}

function checkInfoForm(frm) {
	mes = "";
	if(frm.rname.value.replace(/^\s+|\s+$/, '') == "") mes += "Please enter your name.\n";
	if(frm.remail.value.replace(/^\s+|\s+$/, '') == "") mes += "Please enter your email address.\n";
	if(mes != "") { alert(mes); return false; }
	return true;
}

function showUserDetails(sel) {
	document.useradd.selname.value=sel.options[sel.selectedIndex].text;
	document.useradd.selemail.value=sel.options[sel.selectedIndex].value;
	document.useradd.seluser.value=sel.options[sel.selectedIndex].id;
}

function showHospitalDetails(sel) {
	document.hospitaladd.selname.value=sel.options[sel.selectedIndex].text;
	document.hospitaladd.selweb.value=sel.options[sel.selectedIndex].value;
}

function showRemoveUserDetails(sel) {
	_name=sel.options[sel.selectedIndex].text;
	_email=sel.options[sel.selectedIndex].title;
	_user=sel.options[sel.selectedIndex].id;
	if(_name == "Select user") {
		_name = ""; _email = ""; _user = "";
	}
	document.userremove.selname.value=_name;
	document.userremove.selemail.value=_email;
	document.userremove.seluser.value=_user;
}

function showRemoveHospitalDetails(sel) {
	_name=sel.options[sel.selectedIndex].text;
	_web=sel.options[sel.selectedIndex].id;
	if(_name == "Select user") {
		_name = ""; _web = "";
	}
	document.hospitalremove.selname.value=_name;
	document.hospitalremove.selemail.value=_web;
}

function clearBut() {
	document.useradd.selname.value="";
	document.useradd.selemail.value="";
	document.useradd.seluser.value="";
}

function movetolist(from, to, tempfrom, tempto) {
  fromList = eval('document.usereditdo.' + from);
  toList = eval('document.usereditdo.' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp') {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0; i < fromList.options.length; i++) {
    var current = fromList.options[i];
    if (current.selected) {
      sel = true;
      if (current.value == 'temp') {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      populateTemp(tempfrom, tempto, txt, val);
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any employees!');
}

function moveSelToText(from, to) {
  fromList = eval('document.emailform.' + from);
  toText = eval('document.emailform.' + to);
  var sel = false;
  for (i=0; i < fromList.options.length; i++) {
    var current = fromList.options[i];
    if (current.selected) {
      sel = true;
      txt = current.text;
      val = current.value;
	  currenttext = toText.value;
	  if(currenttext == "") delim = "";
	  else delim = ",\n";
      currenttext += delim + "\"" + txt + "\" " + "<" + val + ">";
      toText.value = currenttext;
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any employees!');
}

function moveAll(from, to) {
	_a = eval('document.emailform.' + from);
	for (a=0; a < _a.options.length; a++) {
    	_a.options[a].selected = "true";
    }
    moveSelToText(from, to);
}

function populateTemp(tmfr, tmto, intext, invalue) {
	if(tmfr == "_inact[]") {
		_from = document.getElementById('_inact');
		_to = document.getElementById('_act');
	}
	if(tmfr == "_act[]") {
		_from = document.getElementById('_act');
		_to = document.getElementById('_inact');
	}
	
	found = false;
    	for (a=0; a < _to.options.length; a++) {
    		if(_to.options[a].text == intext && _to.options[a].value == invalue) {
    			_to.options[a]=null;
    			found = true;
    		}
    	}

	if(!found) {
		_from.options[_from.length] = new Option(intext, invalue);	
	}
}

function passAll(frm) {
	if(checkGenericForm(frm)) {
		_a = document.getElementById('_act');
		for (a=0; a < _a.options.length; a++) {
    		_a.options[a].selected = "true";
    	}
    	_i = document.getElementById('_inact');
		for(i=0; i< _i.options.length; i++){ 		
    		_i.options[i].selected = "true";
    	}
    	return true;
	}
	else {
		return false;
	}
}

function checkPass(fld) {
	if(fld.value.length < 6 && fld.value.length > 0) {
		fld.value="";
		fld.focus();
		alert("Your password cannot be shorter than 6 characters.\nPlease choose another password.");
	}
}	

function checkIfOther(el) {
	if(el.value=="other") {
		el.form.addtlprog.style.visibility = "visible";
	}
	else {
		el.form.addtlprog.style.visibility = "hidden";
	}
}

function checkIfOthers(el, nm) {
	otherfld = eval('el.form.' + nm);
	if(el.value=="other") {	
		otherfld.style.visibility = "visible";
	}
	else {
		otherfld.style.visibility = "hidden";
	}
}

function checkNumKits(frm) {
	chewingGumKit = parseInt(frm.cg_kit.value, 10);
	chocolateKit = parseInt(frm.ch_kit.value, 10);
	gummiesKit = parseInt(frm.gu_kit.value, 10); 
	sum = chewingGumKit + chocolateKit + gummiesKit; 
	
	if(isNaN(sum)) {
		alert("Please enter numeric values only! Type 0 in the box if you don't want any kits from that type.");
		return false;
	}
	else if(sum != 12) {
		alert("This offer is only valid for Make Your Own Candy Kits.\nPlease adjust the numbers of the items you want and try again!");
		return false;
	}
	
	frm.item_name.value = "Make-Your-Own Kit Special: 12 for $78 (" + chewingGumKit + " Chewing Gum Kits, " + chocolateKit  + " Chocolate Kits, " + gummiesKit + " Gummies Kits)";
	return true;

}

function swapImage(imgname, newimg) {
	imgtoswap = eval("document." + imgname);
	imgtoswap.src = "images/" + newimg;
}

