<!--
// These scripts unless otherwise notes are copyrighted to MadeRight Technology Group
// © 2002-2010 All Rights Reserved

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) 
// if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

function winBRopen(theURL, Name, popW, popH, scroll, resize) { // V 1.0
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resize+'';
	Win = window.open(theURL, Name, winProp);
	Win.window.focus();
}

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function DelDocument(DocumentID){
	msg = confirm("Delete this document ?")
  	if (msg) 
   		{window.navigate("admin_DocList.asp?action=del&DocumentID="+DocumentID);}
}

function DelDocument2(DocumentID){
	msg = confirm("Delete this document ?")
  	if (msg) 
   		{window.navigate("admin_DocList2.asp?action=del&DocumentID="+DocumentID);}
}

function DelArticle(ArticleID){
	msg = confirm("Delete this document ?")
  	if (msg) 
   		{window.navigate("admin_DocList.asp?action=del&ArticleID="+ArticleID);}
}

function MR_promptOpen(alstr,url,name,props) { 
	msg2 = confirm(alstr)
  	if (msg2)
		{
		window.open(url,name,props);
		}
}

//Append text to input element
function jQ_append(id_of_input, text){   
	$(id_of_input).val($(id_of_input).val() + text);

}

// Opens New Widow - Compliments of MacroMedia
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Closes window and refreshes parent when passed Close=True in QS Param
function MR_closeWin(x) {
if (x == 'true') {
	opener.location.href = opener.location;
	self.close()
	}
	else
		{}
}

function EAG_comparePassSimple(x1,x2)
{
//vx1 = x1.toString();
//vx2 = x2.toString();
str1 = x1.value;
str2 = x2.value;
if (str1 != str2) {
	alert('The Passwords you entered do not match one another, please re-enter them now.');
	x1.value = ''
	x2.value = ''
	}
	else
		{
		return true;
		}
}

function EAG_comparePass(x1,x2)
{
//vx1 = x1.toString();
//vx2 = x2.toString();
var invalid = " "; // Invalid character is a space
str1 = x1.value;
str2 = x2.value;
if (x1.value.length < 8) {
	alert('The password you entered is less than 8 characters and is not complex enough, please try again.');
	x1.value = ''
	x2.value = ''
	}
if (x1.value.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed.");
	x1.value = ''
	x2.value = ''
	}
if (str1 != str2) {
	alert('The Passwords you entered do not match one another, please re-enter them now.');
	x1.value = ''
	x2.value = ''
	}
	else
		{
		return true;
		}
}

// © Copyright 2002. All Rights Reserved - BICUS Services Corp.
// Unless otherwise noted, All Scripts written by Andrew Gscheidle, 2002-2003.
// Error handling

function BSC_blockError(msg,url,linenumber)
	{
		vW=screen.width;
		vH=screen.height;
		vRes = (vW + " X " + vH);
		vD=screen.colorDepth + "-bit";
		var agt=navigator.userAgent.toLowerCase();
		var strAgt = agt.toString();
		var strOS = strAgt.split(';');
		var strOStxt = strOS[2];
		var ref = document.referrer;
	
		document.location.href = "/report_errors.asp?Page=" + url + '&Msg=' + msg + '&Line=' + linenumber + '&Referrer=' + ref + '&uRes=' + vRes + '&uDepth=' +vD + '&uOS=' + strOStxt + '&SendMail=True';
	}
//window.onerror = BSC_blockError;

function BSC_convertUpper(vfld) {
var str = vfld.value;
var xstr = str.toUpperCase();
vfld.value = xstr;
}

function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
} 

function windowOpen(URL,WINNAME,PROPS)
{
window.open(URL,WINNAME,PROPS);
}


function BSC_count(x,fldname)
{
	var countfld = document.forms[x].cntr
	var ii = fldname.value.length;
	return countfld.value=ii
}


function BSC_checkLength(fld,allowed)
{
	//BSC_count(fld)
  var i = fld.value.length;
	var x = parseInt(allowed);
	if (i >= x) 
	{
	alert('Character Limit Exceeded! You may only enter in ' + allowed + ' characters.\nYou have entered ' + i + ' characters.\nPlease remove ' + (parseInt(i-x)) + ' characters.')
	return false;
	}
		else
		{
		return true
		}
}

// evaluates string to remove non-desired characters such as data masks, etc.
	// returns pure value back to page or calling function.
	function BSC_stripCharsNotInBag (s)
	{   
		var bag = "1234567890";
		var i;
			var returnString = "";
			for (i = 0; i < s.length; i++)
			{   
					// Check that current character isn't whitespace.
					var c = s.charAt(i);
					if (bag.indexOf(c) != -1) returnString += c;
			}
			return returnString;
	}
	
	function BSC_returnCharsNotInBag (s,fld2)
	{   
		var bag = "1234567890";
		var i;
			var returnString = "";
			for (i = 0; i < s.length; i++)
			{   
					// Check that current character isn't whitespace.
					var c = s.charAt(i);
					if (bag.indexOf(c) != -1) returnString += c;
			}
			//alert(returnString)
			eval(fld2.value = returnString)
			//return returnString;
	}
	
	function BSC_stripCharsNotInBag2 (s2)
	{   
		var bag2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*+<>,.?/;:[]{}=";
		var i2;
			var returnString2 = "";
			for (i2 = 0; i2 < s2.length; i2++)
			{   
					// Check that current character isn't whitespace.
					var c2 = s2.charAt(i2);
					if (bag2.indexOf(c2) != -1) returnString2 += c2;
			}
			return returnString2;
	}

	//Returns Error message with up to one parameter in the error msg.
	function BSC_onError(eIndex, addparam)
	{
	 var defaultmsg = "Your Date is Invalid.\n";
	 errormsg = new Array()
	 errormsg[0] = defaultmsg+"Date Too SHORT, please enter an 8 DIGIT date. (HELP: You should use a MM/DD/YYYY format, pad single digit days & months with 0.)";
	 errormsg[1] = defaultmsg+"Invalid MONTH entered. You must enter a number between 01 and 12. Please re-enter your MONTH";
	 errormsg[2] = defaultmsg+"Invalid DAY entered. Please enter a number between 1-31. Please re-enter your DAY";
	 errormsg[3] = defaultmsg+"Invalid DAY entered. The month you entered only has 30 days. Please re-enter your DAY";
	 errormsg[4] = defaultmsg+"February only has 28 days in " + addparam + ". Please re-enter your DAY.";
	 errormsg[5] = defaultmsg+"Date Too LONG, please enter no more than 8 digits. You should use a MM/DD/YYYY format.";
	 errormsg[6] = "The phone number has TOO MANY digits. Please enter 10 digits.";
	 errormsg[7] = "The phone number has TOO LITTLE digits. Please only enter 10 digits.";
	 errormsg[8] = "You have not entered a valid email address, please re-enter a valid email address";
	 errormsg[9] = "The email address you entered contains blank spaces. Email addresses cannot have blank spaces, please re-enter.";
	 errormsg[10] = "The phone number you entered contains invalid symbols and/or letters, please re-enter.";
	 errormsg[11] = "You have not entered a Weis Markets email address, please re-enter a valid weismarkets.com address.";
	 
	 return alert(errormsg[eIndex]);
	}

	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	function BSC_daysInFebruary (year)
	{   
			return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
	}
	
	// Evaluates field for vaild date and reformats string to MM/DD/YYYY format
	function BSC_checkDate(dField,dValue)
	{	
		var fldDate = dValue;
		var strDate = BSC_stripCharsNotInBag(new String(fldDate));
		var lenDate = strDate.length;
		var txtYYYY = strDate.substring(4,8);
		var iYYYY = parseInt(txtYYYY);	
		
		if (lenDate > 8)
			{
			BSC_onError(5);
			dField.focus();
			return false;
			}
		
		if ((lenDate > 0) && (lenDate < 8))
			{	 
			BSC_onError(0);
			dField.focus();
			return false;
			}
		
		if (lenDate == 8)
			{
			var txtMM = strDate.substring(0,2);
				//alert(txtMM)
			var txtDD = strDate.substring(2,4);
			var iMM = parseInt(txtMM);
				//alert(iMM)
			var iDD = parseInt(txtDD)
			
			if ((txtMM < 1) || (txtMM >12))
				{
				BSC_onError(1);
				dField.focus();
				return false;
				}
	
			if ((txtDD < 1) || (txtDD > 31))
				{
				BSC_onError(2);
				dField.focus();
				return false;
				}
				
			if (((txtMM == 4) || (txtMM == 6) || (txtMM == 9) || (txtMM == 11)) && (txtDD > 30))
				{
				BSC_onError(3);
				dField.focus();
				return false;
				}
				
				if ((txtMM == 2) && (txtDD > BSC_daysInFebruary(iYYYY)))
					{
					BSC_onError(4,txtYYYY);
					dField.focus();
					return false;
					}
			var strDate = new String(txtMM + "/" + txtDD +"/" + txtYYYY);
			dField.value = strDate;
			return true;
			}
	}	
	
	// Checks field for valid US Phone format and format the string for (999) 999-9999 format.
	function BSC_checkPhone(phField,phValue)
	{
		var strPhone = new String(phValue);
		var fxdPhone = BSC_stripCharsNotInBag(strPhone);
		var fxdAlphaChars = BSC_stripCharsNotInBag2(strPhone);
		
		if (fxdAlphaChars.length >= 1)
			{
				BSC_onError(10);
			}
	
		if (fxdPhone.length > 10)
			{
				BSC_onError(6);
				phField.focus();
			}
		
		if ((fxdPhone.length > 0) && (fxdPhone.length < 10))
			{
				BSC_onError(7);
				phField.focus();
			}
		
		if (fxdPhone.length == 10)
			{
				var rtrnPhone = "(" + fxdPhone.substring(0,3) + ") " + fxdPhone.substring(3,6)+ "-" + fxdPhone.substring(6,10);
				phField.value = rtrnPhone;
				return true;
			}	
	}

	//Checks form field for email address (checks for @, and also . with at least one character after the .
	function BSC_checkEmail(emField,emValue)
	{
			var i = 1;
			var sLength = emValue.length;
		
		if (sLength > 0 )
		{
		if (emValue.indexOf(".") == -1)
			BSC_onError(8);
			
		if (emValue.indexOf(" ") == 1)
			BSC_onError(9);
			
		// look for @
			while ((i < sLength) && (emValue.charAt(i) != "@"))
			{ i++
			}
	
			if ((i >= sLength) || (emValue.charAt(i) != "@")) 
			BSC_onError(8);
			else i += 2;
	
	
			// look for .
			while ((i < sLength) && (emValue.charAt(i) != "."))
			{ i++
			}
	
			// there must be at least one character after the .
			if ((i >= sLength - 1) || (emValue.charAt(i) != ".")) 
			BSC_onError(8);
			else 
			return true;
		}
	}

	//Checks form field for Weis email address (checks for @weismarkets.com)
	function BSC_checkWeisEmail(emField,emValue)
	{
			var i = 1;
			var sLength = emValue.length;
		
		if (sLength > 0 )
		{
		if (emValue.indexOf("@weismarkets.com") == -1)
			BSC_onError(11);
						
		if (emValue.indexOf(" ") >= 1)
			BSC_onError(9);
			
		// look for @
			while ((i < sLength) && (emValue.charAt(i) != "@"))
			{ i++
			}
	
			if ((i >= sLength) || (emValue.charAt(i) != "@")) 
			BSC_onError(8);
			else i += 2;
	
	
			// look for .
			while ((i < sLength) && (emValue.charAt(i) != "."))
			{ i++
			}
	
			// there must be at least one character after the .
			if ((i >= sLength - 1) || (emValue.charAt(i) != ".")) 
			BSC_onError(8);
			else 
			return true;
		}
	}


function BSC_checkPassLength(fld,minlen)
{
	var i = fld.value.length;
	var x = parseInt(i);
	var y = parseInt(minlen);
	if (x < y) 
		{
		alert('PASSWORDS must contain at least '+ minlen + ' characters.\nPlease re-enter a PASSWORD that is at least ' + minlen + ' characters long.')
		//fld.focus();
		//return false;
		}
		else 
			{
			return true;
			}
}

function BSC_checkUserLength(fld,maxlen)
{
	var i = fld.value.length;
	var x = parseInt(i);
	var y = parseInt(maxlen);
	if ((x == 0) || (x > y))
		{
		alert('USER NAMES must be between 1 and '+ maxlen + ' characters.\nPlease re-enter a USER name that is between 1 and ' + maxlen + ' characters long.')
		//fld.focus();
		//return false;
		}
		else 
			{
			return true;
			}
}

function BSC_checkPassNum(fld)
{
 var alphanum = new Array('0','1','2','3','4','5','6','7','8','9','A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','Q','q','R','r','S','s','T','t','U','u','V','v','W','w','X','x','Y','y','Z','z')

}


function BSC_comparePass(fld1,fld2)
{
	BSC_checkPassLength(fld1,6)
	BSC_checkPassLength(fld2,6)
	var strA = fld1.value;
	var strB = fld2.value;
	if (strA != strB)
	{
	alert('The PASSWORDS you entered do not match one another.\nIt is advised that you re-enter both PASSWORDS')
	return false;
	}
	else
		{
		//alert('Match')
		return document.forms[0].submit();
		}
}

function BSC_showOnOver(fld)
{
 alert(fld.value)	
}

function BSC_userConfirm(fld,fld1,fld2)
{
	BSC_checkUserLength(fld,8)
	BSC_checkPassLength(fld1,6)
	BSC_checkPassLength(fld2,6)
	var strA = fld1.value;
	var strB = fld2.value;
	if (strA != strB)
	{
	alert('The PASSWORDS you entered do not match one another.\nIt is advised that you re-enter both PASSWORDS')
	return false;
	}
	else
		{
		//alert('Match')
		return document.forms[0].submit();
		}
}

function BSC_toUpper(fld,str)
{
var fldname = fld;
var xx = str;
return fldname.value = xx.toUpperCase();
}
//-->

function ShowTimeoutWarning () 
{ 
    
window.alert( "You will be automatically logged out in five minutes unless you do something!" ); 
}

function SJK_CHECK_NUM(sjkField,sjkValue)
	{
		var strNUM = new String(sjkValue);
		var decimalTest=strNUM.split('.');

		if (isNaN(strNUM))
			{
				alert("The amount field must contain a number without symbols!");
			}
		
		if (document.form1.flat_price.checked == true)
			{	
				if(decimalTest.length!=2||decimalTest[1].length!=2)
					{
						alert("The amount field must contain two decimal places!");
					}
			}
				
	}
