	// name - name of the cookie
	// value - value of the cookie
	// [expires] - expiration date of the cookie (defaults to end of current session)
	// [path] - path for which the cookie is valid (defaults to path of calling document)
	// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
	// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
	// * an argument defaults when it is assigned null as a placeholder
	// * a null placeholder is not required for trailing omitted arguments
	function setCookie(name, value, path, expires, domain, secure) {
		var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
		
		document.cookie = curCookie;
	}
	
	// name - name of the desired cookie
	// * return 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));
	}
	
	function GetCookieNonNull(cookieName) 
	{
		var cookieval = getCookie(cookieName);
		if (("" + cookieval) == null || cookieval == null)
		{
			cookieval="";
		}
		return cookieval;
	}
	
	function GetExpireDate(daystoexpire)
	{
		var date = new Date();
		date.setTime(date.getTime() + (daystoexpire*24*60*60*1000));
		return date;
	}
	
	function openNewWindow(win) 
	{
		openNewWindowSized(win, '375', '500')
	}
	
	function openNewWindowSized(win, hgt, wdt)
	{
		if (hgt=='')
			hgt = '375';
		
		if (wdt=='')
			wdt = '500';
		
		hgt = (parseInt(hgt) + 20) + '';
		wdt = (parseInt(wdt) + 10) + '';
		
		newWindow = window.open("", win,"width=" + wdt + ",height=" + hgt + ",menubar=no,toolbar=no,scrollbars=yes,directories=no,location=no,resizable=yes");
	}
	
	function openPrintableWindow(win) 
	{
		newWindow = window.open("", win,"width=500,height=375,menubar=yes,toolbar=no,scrollbars=yes,directories=no,location=no,resizable=yes");
	}
	
	function openBigWindow(win) 
	{
		newWindow = window.open("", win,"width=500,height=525,menubar=no,toolbar=no,scrollbars=yes,directories=no,location=no,resizable=yes");
	}
	
	function getRadioValue(radio) 
	{
		for (var i=0; i<radio.length; i++) {
			if (radio[i].checked) return radio[i].value;
		} 
		return "";
	}

	
	function IsNumberType(strtocheck, numtype) 
	{
		var rtn = false;
		
		if (numtype == "INT") {
			s = parseInt(strtocheck,10);
		} else {
			s = parseFloat(strtocheck,10);
		}
		if (s == strtocheck) {
			rtn = true;
		}
		return rtn;
	}
	
	function CheckNumLength(nmbr,lngth)	
	{
		var i = Number(nmbr);
		var x = nmbr.length;
		
		if ( x == lngth) 
		{
			if (isNaN(i) == true) 
			{
				return false;
			}
			else 
			{
				return true;
			}
		}			
		else 
		{
			return false;				
		}
	}


	function isNumeric(StrChkVal)
	{
		var RetVal = true;
		var NumberOfPoints = 0;
		for (i = 0 ; i < StrChkVal.length ; i++)
		{
			if (mid(StrChkVal, i + 1, 1) == ".")
			{
				if (NumberOfPoints == 0)
				{
					NumberOfPoints = 1;
				}
				else
				{
					RetVal = false
				}
			}
			else
			{
				if (isNaN(parseInt(mid(StrChkVal, i + 1, 1), 10)))
				{
					RetVal = false;
				}
			}
		}
	
		return RetVal;
	}

	function StrTrim(StrVar)
	{
		for (I = 0 ; I < StrVar.length ; I++)
		{
			if ((StrVar.substring(0,1)) == " ")
			{
				StrVar = StrVar.substring(1,StrVar.length);
				I = I - 1;
			}
		}
	
		for (I = 0 ; I < StrVar.length ; I++)
		{
			if ((StrVar.substring(StrVar.length - 1,StrVar.length - 0)) == " ")
			{
				StrVar = StrVar.substring(0,StrVar.length - 1);
				I = I - 1;
			}
		}
		return StrVar;
	}

	function mid(str,start,n)
	{
		var strlen = str.length;
		var jj = str.substring(start-1,strlen);
		jj = jj.substring(0,n);
		return jj;
	}

	function Checkdate(datestr)
	{
		flag = false
	    if (datestr.length == 10)   
		{
			firstsl = datestr.indexOf("/")
			secondsl = datestr.indexOf("/", firstsl + 1)
		var dd = (mid(datestr, 1 , firstsl)).valueOf()
		var mm = (mid(datestr, firstsl + 2, secondsl - (firstsl + 1))).valueOf()
		var yy = (mid(datestr, secondsl + 2, datestr.length - secondsl)).valueOf()
	
			if ((firstsl != -1) && (secondsl != -1))
			 {
	
				if ((firstsl == 2) || (firstsl == 1))
				{
	
					if ((secondsl == 4) || (secondsl == 5) || (secondsl ==3) && ((secondsl - firstsl) > 1))
					{
	
						if (((datestr.length - secondsl) == 3) || ((datestr.length - secondsl) == 5))	
						{	
	
				if (!(isNumeric(mm) && isNumeric(dd) && isNumeric(yy)))
				{
				  return flag
				}
				else
				{
				    if (parseInt(mm, 10) < 1 || parseInt(mm, 10) > 12)
				    {
					mm = Number.NaN
					return flag
				    }
				    if (parseInt(dd, 10) < 1 || (parseInt(dd, 10) > getDays((parseInt(mm, 10) - 1 ),parseInt(yy, 10))))
				    {
					dd = Number.NaN
					return flag
				    }
				    flag = true
				    return flag
				}
			    }
			}
				}
			}
		}
		else
		{
	//        alert("Invalid Date.")
		}
		return flag
	}
	
	function Checkdate1(datestr)
	{
		flag = false
	    if ((datestr.length >= 6) &&(datestr.length <= 10))   
		{
			firstsl = datestr.indexOf("/")
			secondsl = datestr.indexOf("/", firstsl + 1)
		var dd = (mid(datestr, 1 , firstsl)).valueOf()
		var mm = (mid(datestr, firstsl + 2, secondsl - (firstsl + 1))).valueOf()
		var yy = (mid(datestr, secondsl + 2, datestr.length - secondsl)).valueOf()
	
			if ((firstsl != -1) && (secondsl != -1))
			 {
	
				if ((firstsl == 2) || (firstsl == 1))
				{
	
					if ((secondsl == 4) || (secondsl == 5) || (secondsl ==3) && ((secondsl - firstsl) > 1))
					{
	
						if (((datestr.length - secondsl) == 3) || ((datestr.length - secondsl) == 5))	
						{	
	
				if (!(isNumeric(mm) && isNumeric(dd) && isNumeric(yy)))
				{
				  return flag
				}
				else
				{
				    if (parseInt(mm, 10) < 1 || parseInt(mm, 10) > 12)
				    {
					mm = Number.NaN
					return flag
				    }
				    if (parseInt(dd, 10) < 1 || (parseInt(dd, 10) > getDays((parseInt(mm, 10) - 1 ),parseInt(yy, 10))))
				    {
					dd = Number.NaN
					return flag
				    }
				    flag = true
				    return flag
				}
			    }
			}
				}
			}
		}
		else
		{
	//        alert("Invalid Date.")
		}
		return flag
	}
	
	
	// 4/12/2004 Const added these two functions to validate zip/postal codes in shippingaddress.asp and to distinguish between the two
//Canadian Postal Code Validation
		function validate_Canadian_Postal_code(post_val)
		{
		post_val = StrTrim(post_val);
		
		while (post_val.indexOf(" ") > -1)
			post_val = post_val.replace(" ","");
			
		if (post_val == "")
			{
				alert("Please enter your Postal Code!");
				return false;
			}        
		
		if (post_val.search(/^([a-zA-Z]{1}\d{1}){3}$/) == -1)
			{
				alert("You have entered an invalid postal code! Please verify and correct your postal code.");
				return false;
			}	

		}
	

//US Zip Code Validation

	function validate_US_Zip_code(zip_val)
	{
		zip_val = StrTrim(zip_val);
		if (zip_val == "")
		{
			alert("Please enter your Zip Code!");
			return false;
		}        
		
		if (zip_val.search(/^\d{5}(-\d{4})?$/) == -1)
		{
			alert("You have entered an invalid zip code! Please verify and correct your zip code. Examples: 11788 or 11788-2624");
			return false;
		}		
		return true;	
	}
	
	//this is used in the cart to make sure people don't press the button more than once
	var multiclick_flag = 0;
	//var imgTopNew = new Image();
	//imgTopNew.src = "/images/cart/processing.gif";
	var imgBottomNew = new Image();
	imgBottomNew.src = "/images/cart/processing.gif";
	
	function prevent_multiclick()
	{
		if (multiclick_flag == 0) 
		{
			//change button images to indicate processing
			//document.imgTop.src = imgTopNew.src;
			document.imgBottom.src = imgBottomNew.src;
			 
			// allow the first submit only
			multiclick_flag++ ;
			return true ;
		} 
		else 
			return false ;	// kill the subsequent submits
	}
	
	function replacemultiple(str, find, repl)
	{
		while (str.indexOf(find) > -1)
			str = str.replace(find, repl);
		
		return str;
	}

        function submitLogin()
        {
	        if(StrTrim(document.frmLogin.username.value) == "")
	        {
		        alert("Please enter your username.");
		        document.frmLogin.username.focus();
		        return false;
	        }
        		
	        if(StrTrim(document.frmLogin.password.value) == "")
	        {
		        alert("Please enter your password.");
		        document.frmLogin.password.focus();
		        return false;
	        }
        			
	        document.frmLogin.submit();
        }

        function submitLoginEnter(myfield, e)
        {
	        var keycode;
	        if (window.event) keycode = window.event.keyCode;
	        else if (e) keycode = e.which;
	        else return true;

	        if (keycode == 13)
	        {
		        //myfield.form.submit();
		        submitLogin();
		        return false;
	        }
	        else
		        return true;
        }
	
	function submit_form(frm)
{	
		eval(frm + '.keyword.value = "' + StrTrim(replacemultiple(replacemultiple(replacemultiple(eval(frm + '.keyword.value'), "/", " "), "#", " "), "%", "") + '"'));
		
		var reg = new RegExp("^-+$"); 
		
		if (eval(frm + '.keyword.value') == "" || reg.exec(eval(frm + '.keyword.value')))
		{
			alert("Please enter search text.");
			eval(frm + ".keyword.value= ''");
			eval(frm + '.keyword.focus()');
			return false;
		}
		else
			eval(frm + '.submit()');
}

function testkeyword(frm)
{
		if(StrTrim(eval(frm + '.keyword.value')) == "" || eval(frm + '.keyword.value') == "keyword or item " || eval(frm + '.keyword.value') == "keyword or item #")
			return false;
		else
			eval(frm + '.submit()');
}

function replacemultiple(str, find, repl)
{
	while (str.indexOf(find) > -1)
		str = str.replace(find, repl);
		
	return str;
}

function submitenter(myfield,e,frm)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
	   submit_form(frm);
	   return false;
	}
	else
	   return true;
}
