            function strltrim() {
                return this.replace(/^\s+/,'');
            }

            function strrtrim() {
                return this.replace(/\s+$/,'');
            }
            function strtrim() {
                return this.replace(/^\s+/,'').replace(/\s+$/,'');
            }

            String.prototype.ltrim = strltrim;
            String.prototype.rtrim = strrtrim;
            String.prototype.trim = strtrim;

function goback1()
{
		if (document.referrer.indexOf("showcart.asp") != -1)
		{
			window.location = "/asp/showcart.asp";
		}
		else
		{
			history.back();
		}
}

function closewin()
{
		if (self.parent.frames.length != 0) 
		{
			self.parent.close()
		} 
		else 
		{
			window.close()
		}
}



/* work on this later */
def_nosecurityrole = 17

function gomain(twait)
{
	setTimeout("window.location='gcmmain.asp'",twait);
}

function gostart()
{
	setTimeout("window.location='default.asp'",5000);
}

function validqty(s)
{
	if ( isblank(s) == true )
	{
		return false;
	}

	if ( isIntNum(s) == false )
	{
		return false;
	}

	if ( parseInt(s) < 1 )
	{
		return false;
	}

	return true;
}

function isblank(s)
{
	if (s == null )
	{
		return true;
	}

	if (s.length == 0 )
	{
		return true;
	}
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function isIntNum(s)
{
	if (isNaN(parseInt(s)))
	{
		return false;
	}
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (( c < '0') || (c > '9'))
		{
			return false;
		}
	}
	return true;
}

function isFloatNum(s)
{
	if (isNaN(parseFloat(s)))
	{
		return false;
	}
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((( c < '0') || (c > '9')) && (c != '.'))
		{
				return false;
		}
	}

	return true;
}

function isCurrency(s)
{
	if (isNaN(parseFloat(s)))
	{
		return false;
	}
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((( c < '0') || (c > '9')) && (c != '.'))
		{
			return false;
		}
	}

	return true;
}

function isInRange(s,low,high)
{
	if ((s >= low) && (s <= high))
	{
		return true;
	}
	return false
}

/* append % to make wildcard query if not already so */
function makeqwildcard(s)
{
	if (isblank(s))
	{
		return (s);
	}

	var wildcardchk = s.lastIndexOf("%");
	
	if ( wildcardchk != (s.length - 1) )
	{
		s = s + '%';
	}
		
	return (s);
}


function getqfldval(e)
{
	if (e.quotes)
	{
		var quotestr = "'"
	}
	else
	{
		var quotestr = ""
	}

	/* check for wildcards at the end only for now */
	if (e.valtype == 'text')
	{
		/* force wildcard here */
		if (e.makewild == true )
		{
			e.value = makeqwildcard(e.value);
		}
		var wildcheck = e.value;
         	var wildlen = e.value.length - 1;
         	var wildcardchk = wildcheck.lastIndexOf("%");
            if ( wildcardchk == wildlen )
           	{
           		var qop = " LIKE ";
			return( e.name + " " + qop + "" + quotestr + e.value + quotestr);
           	}                                      
	}

	if (e.numcomp == true)
	{
		if (isNaN(parseInt(e.value)))
		{
			var errstring = "__Err " + " Error: " + e.showname + " value is not valid: " + e.value
			return(errstring);
		}

		/* look for first operator  */
		var regexp1 = /^(\s*)(!=|<=|>=|<|>)(\s*)(\w+)/;
		var matchres = e.value.match(regexp1);
		if (matchres != null )
		{
			var numop = matchres[2];
			var numval = matchres[4];
			return(e.name + " " + numop + " " + quotestr + numval + quotestr);
		}
	}
	else if (e.datecomp == true)
	{
		quotestr = '#';
		/* look for first operator and mm/dd/yy or mm/dd/yyyy format only */
		var regexp2 = /^(\s*)(!=|<=|>=|<|>)?(\s*)(\d+)\/(\d+)\/(\d+)/;
		var matchres = e.value.match(regexp2);
		if (matchres != null)
		{
			var dateop = matchres[2];
			var datemm = matchres[4];
			var datedd = matchres[5];
			var dateyy = matchres[6];

			/* now verify the date is valid */
			if (verifydate(datemm + "/" + datedd + "/" + dateyy) != true )
			{
				var errstring = "__Err " + " Error: " + e.showname + " value is not valid: " + e.value;
				return(errstring);
			}

			if (( dateop == null) || (dateop.length == 0))
			{
				dateop = "=";
			}

			return(e.name + " " + dateop + " " + quotestr + datemm + "/" + datedd + "/" + dateyy + quotestr);
		}
		else
		{
			var errstring = "__Err " + " Error: " + e.showname + " value is not valid: " + e.value
			return(errstring);
		}
	}
	return(e.name + " = " + quotestr + e.value + quotestr);
}


function buildquery(finp)
{
	var msg;
	var qstr;
	var qcount;
	
	qcount = 0;
	qstr = '';
	for ( var i = 0; i < finp.length; i++ )
	{
		var e = finp.elements[i];
		if ((e.query) && (e.value != null) && (e.value.length > 0))
		{
			if (e.value == e.nullquery)
			{
				continue;
			}
			else
			{
				var qfldval = getqfldval(e);
			
				if ( qfldval.search(/^__Err/) != -1 )
				{
					var errstring = qfldval.substring(5,qfldval.length);
					alert(errstring);
					e.focus();
					e.select();
					return false;
				}
				
				if ( qcount == 0 )
				{
					qstr = qfldval;
				}
				else
				{
					qstr = qstr + ' AND ' + qfldval;
				}
				qcount++;
			}
		}
	}
	finp.wherequery.value = qstr;
	return true;
}

/* ssno verification ######### no spaces, dashes always 9 digits 0-9 */
function verifyssno(argssno)
{
	if ( argssno.length != 9)
	{
		return false;
	}

	var regexp = /^(\d+)/;
	var matchres = argssno.match(regexp);
	if ( matchres != null)
	{
		return true;
	}
	
	return false;
}

function verifydate(argdt)
{
	monlength = new Array(12);
	monlength[0] = 31; monlength[1] = 28; monlength[2] = 31;
	monlength[3] = 30; monlength[4] = 31; monlength[5] = 30;
	monlength[6] = 31; monlength[7] = 31; monlength[8] = 30;
	monlength[9] = 31; monlength[10] = 30; monlength[11] = 31;

	var regexp = /^(\d+)\/(\d+)\/(\d+)$/;
	var matchres = argdt.match(regexp);
	if (matchres != null)
	{
		var matchparts = argdt.split("\/");
		/* mm test */
		/* because of peculiar parseInt("08") bug which returns 0 strip the leading 0 */
		var mmtest = matchparts[0];
		var c = matchparts[0].charAt(0);
		if ( c == '0' )
		{
			/* get the last character of the month because should be single digit */
			mmtest = matchparts[0].charAt(matchparts[0].length - 1);
		}
		else
		{
			/* get the whole month expression ie. 10,11,12 */
			mmtest = matchparts[0];
		}

		if ((parseInt(mmtest) < 1 ) || (parseInt(mmtest) > 12))
		{
			return false;
		}
		/* yyyy  AND dd test */
		if ((parseInt(mmtest) == 2) && (parseInt(matchparts[1]) == 29))
		{
			/* leapyear check */
			if (((parseInt(matchparts[2]) % 4 ) != 0 ) || (((parseInt(matchparts[2]) % 100) == 0) && ((parseInt(matchparts[2]) % 400) != 0)))
			{	
				return false;
			}
		}
		else
		{
			var ddtest = matchparts[1];
			var c = matchparts[1].charAt(0);
			if ( c == '0' )
			{
				/* get the last character of the dd because should be single digit */
				ddtest = matchparts[1].charAt(matchparts[1].length - 1);
			}
			else
			{
				/* get the whole dd expression ie. 10,21,30 */
				ddtest = matchparts[1];
			}


			/* dd test */
			if ((parseInt(ddtest) < 1) || (parseInt(ddtest) > monlength[parseInt(mmtest) - 1]))
			{
				return false;
			}
		}

		return true;
	}
	else
	{
		return false;
	}
}

function formverify(finp)
{
	var msg;
	var empty_fields, error_fields;
	var errors;
	empty_fields = "";
	error_fields = "";

	for ( var i = 0; i < finp.elements.length; i++ )
	{
		var e = finp.elements[i];
		if (((e.type == "text") || (e.type == "textarea") || (e.type == "password") || (e.type == "file")) && (e.optional == false))
		{
			if ((e.value == null) || (e.value == "") || isblank(e.value))
			{
				empty_fields += "\n         "  + e.showname;
				continue;
			}
			
			/* check minimum length requirement */
			if (e.minlen != null)
			{
				e.value = e.value.trim();
				if ( e.value.length < e.minlen )
				{
					error_fields += "\n       " + e.showname + " minimum length is " + e.minlen;
				}
			}
		}
		
		if (( e.type == "select-one") && (e.optional == false))
		{
				var k = false;
				for ( j = 0; j < e.options.length; j++ )
				{
					if ( e.options[j].selected == true )
					{
						k = true;
					}
				}
				if ( k == false )
				{
					empty_fields += "\n        "  + e.showname;
					continue;
				}
		}

		if ((e.valtype == "int") && (e.value != "") && !isblank(e.value))
		{
			if (isIntNum(e.value) != true)
			{
				error_fields += "\n    " + e.showname + " has invalid value! ";
				continue;
			}
		}

		if ((e.valtype == "float") && (e.value != "") && !isblank(e.value))
		{
			if (isFloatNum(e.value) != true)
			{
				error_fields += "\n    " + e.showname + " has invalid value! ";
				continue;
			}
		}	
		
		if ((e.valtype == "currency") && (e.value != "") && !isblank(e.value))
		{
			if (isCurrency(e.value) != true)
			{
				error_fields += "\n    " + e.showname + " has invalid value! ";
				continue;
			}
		}


		if ((e.valtype == "date") && (e.value != "") && !isblank(e.value))
		{
			if (verifydate(e.value) != true)
			{
				error_fields += "\n    " + e.showname + " has invalid value! ";
				continue;
			}
		}
	
		/* ssno check */
		if ((e.valtype == "ssno") && (e.value != "") && !isblank(e.value))
		{
			if (verifyssno(e.value) != true)
			{
				error_fields += "\n   " + e.showname + " has invalid value! No space or dashes allowed, digits only, format: ######### ";
				continue;
			}
		}	
		
		if ((e.valtype == "email") && (e.value != "") && !isblank(e.value))
		{
			if (verifyemail(e.value) != true)
			{
				error_fields += "\n	  " + e.showname + " is invalid. Please try again. It should be in the format: name@host.domain.";
				continue;
			}
		}
	}


	msg = "";
	
	if (empty_fields)
	{
		msg += " The following field(s) are empty: " + empty_fields + "\n";
		alert(msg);
		return false;
	}

	if (error_fields)
	{
		msg += " The following fields have invalid values: " + error_fields + "\n";
		alert(msg);
		return false;
	}

	return true;
}

function get_payrate(num_sold)
{
	if (num_sold < 10)
	{
		return(2.0);
	}
	else if (num_sold < 20)
	{
		return(2.5);
	}
	else
	{
		return(3.0);
	}	
}

function verifyemail(stremail)
{
	if ( stremail.search(/[\w-_]+@[\w-_]+\.[\w-_]+/) == -1 )
	{
		return false;
	}
	return true;
}

function deletecheck(strurl)
{
	if (confirm("Are you sure you want to delete this record?") == true)
	{
		window.location=strurl;
		return true;
	}
	return false;
}

function gendeletecheck(strcheck)
{
	if (confirm(strcheck) == true)
	{
		return true;
	}
	return false;
}

	/* verify that filename ext is .jpg or .gif */
	function extverify(strfiletype,strfilename)
	{
		var intperiod;
		var strext;
		
		if (strfilename.length == 0)
		{
			alert(strfiletype + ' File is required for upload!');
			return false;
		}
		
		intperiod = strfilename.lastIndexOf('.',strfilename.length - 2);
		
		if (intperiod == -1)
		{
			alert(strfiletype + ' System only accepts files with .jpg or .gif extensions');
			return false;
		}
		
		strext = strfilename.substring(intperiod);
		
		if ((strext.toLowerCase() != '.jpg') && (strext.toLowerCase() != '.gif'))
		{	
			alert(strfiletype + ' System only accepts files with .jpg or .gif extensions.');
			return false;
		}		
		return true;
	}

 function openadminpicpopup(strwin,strname,lwidth,lheight)
{
	window.open(strwin,strname,'width=' + lwidth + ',height=' + lheight + ',status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,directories=no');
	return true;
}


function toggleTermsPrivacy(show)
{
	termsButton = document.getElementById('spanTerms');
	privacyButton = document.getElementById('spanPrivacy');
	termsContent = document.getElementById('spanTermsContent');
	privacyContent = document.getElementById('spanPrivacyContent');
	
	if(show == 'terms')
	{
		termsContent.style.display='block';
		privacyContent.style.display='none';
		
		termsButton.className = 'black2class';
		privacyButton.className = 'gray2class';	
		
	}
	else
	{
		termsContent.style.display='none';
		privacyContent.style.display='block';
		
		termsButton.className = 'gray2class';
		privacyButton.className = 'black2class';																
	}
}
	
