

//functions returns false if invalid email address
function checkEmail(address) {
	while(address.charCodeAt(0)==32) {
		address=address.substr(1);
		}
	while(address.charCodeAt(address.length-1)==32) {
		address=address.substring(0,address.length-1);
		}
	for(i=0;i<address.length;i++) {
		s = address.charCodeAt(i);
		if (!(((s >= 65) && (s <= 90)) || ((s >= 48) && (s <= 57)) || ((s >= 97) && (s <= 122))||(s==64)||(s==45)||(s==46)||(s==95)) ) return false;
	}
  	addressSplit = address.split('@');
  	if(addressSplit.length==2) {
  		name   = addressSplit[0];
  		domain = addressSplit[1];
	  	if((name.substr(name.length-1,1)=='.')||(name.substr(0,1)=='.')||(domain.substr(domain.length-1,1)=='.')||(domain.substr(0,1)=='.')) {  //no improperly placed periods
			return false;
		} else {
		  	domainSplit = domain.split('.');
		  	if(domainSplit.length<2) return false;  // no period in domain
		}
	} else {
		return false;
	}
	return true;
}

// following function disallows numeric, accented or special entries into fields

function checkText(theField) {
	var theString = document.Form.elements[theField].value;
	var theLength = theString.length;
	for (i = 0; i < theLength; i++) {
		s = theString.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || (s == 32) || ((s >= 97) && (s <= 122))) ;
		else {
			return false;
			}
		}
	return true;
	}

// following function disallows accented or special entries into fields

function checkNumTextSpace(theField) {
	var theString = document.Form.elements[theField].value;
	var theLength = theString.length;
	for (i = 0; i < theLength; i++) {
		s = theString.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || ((s >= 48) && (s <= 57)) || (s == 32) || ((s >= 97) && (s <= 122)));
		else {
			return false;
			}
		}
	return true
	}

// following function disallows spaces, accented or special entries into fields

function checkNumText(theField) {
	var theString = document.Form.elements[theField].value;
	var theLength = theString.length;
	for (i = 0; i < theLength; i++) {
		s = theString.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || ((s >= 48) && (s <= 57)) || ((s >= 97) && (s <= 122)));
		else {
			return false;
			}
		}
	return true
	}

// following function only allow numeric entry into certain fields

function checkNum(theField) {
	var s = document.Form.elements[theField].value;
	if (isNaN(s) == true) {
		document.Form.elements[theField].focus();
		if (isNaN(parseInt(s)) == true )
			document.Form.elements[theField].value = '';
		else
			document.Form.elements[theField].value = parseInt(s);

		}
	}

//following function adds century prefix to date of birth 'year' field if only two digits

function fixYear(dob_year,thisField) {
	if ((dob_year <  100) && (dob_year > 9)) {
		dob_year = 19 + dob_year;
		document.Form.elements[thisField].value = dob_year;
		}
		}

//following function creates new popup window

function goPopupExt(myUrl,myWidth,myHeight, scrollbars) {
	if (navigator.userAgent.indexOf("MSIE") && (navigator.appVersion.substring(0,1) == '2')) {
   	popup = window.open(myUrl,'thenewWin','top=50,left=50,toolbar=no,location=no,directories=no,status=no,resizable=yes,copyhistory=no,width=' + myWidth + ',height=' + myHeight + ',scrollbars=' + scrollbars);
	} else {
		popup = window.open(myUrl,'thenewWin','top=50,left=50,toolbar=no,location=no,directories=no,status=no,resizable=yes,copyhistory=no,width=' + myWidth + ',height=' + myHeight + ',scrollbars=' + scrollbars);
		popup.focus();
	}
	}

//sets path variables
 var pathFile = "/";



function setCookie(cookieName,cookieVal) {
	nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	document.cookie = cookieName+"="+cookieVal+"; expires="+nextyear.toGMTString()+"; path=/";
}

function prodLine(code,theText, theTop) {
	this.code = code;
	this.text = theText;
	this.theTop = theTop;
}



//var productDesc = new Array();





function writeProducts(code,category,isCatalog, theHeight) {

	if(isCatalog) document.write("<table border=0 cellpadding=0 cellspacing=0>");
	else document.write("<table border=0 cellpadding=2 cellspacing=0>");
	for(i=0;i<productLine.length;i++) {
		if(isCatalog) {
			theInfo = '';
			document.write("<tr><td bgcolor=#FFFFFF valign=top align=left height="+theHeight+"><a href='#' onClick=\"javascript:showProduct('"+productLine[i].code+"')\"><img src='/images/resampled.php?w=36&h=36&x=140&y=0&x2=453&y2=313&source_im=products/"+code+"_jpgfiles/"+productLine[i].code+code+"_w.jpg' border=0></a></td><td>&nbsp;</td></tr>");

		}
		else {
			document.write("<tr><td bgcolor=#FFFFFF><a href='/Scripts/t4cgi.exe/products.taf?design="+code+"&prodLine="+productLine[i].code+"&category="+category+"'><img src='/images/resampled.php?w=36&h=36&x=140&y=0&x2=453&y2=313&source_im=products/"+code+"_jpgfiles/"+productLine[i].code+code+"_w.jpg' border=0></a></td>");
			document.write("<td bgcolor=#FFFFFF><a href='/Scripts/t4cgi.exe/products.taf?design="+code+"&prodLine="+productLine[i].code+"&category="+category+"'><img src='/images/thumbs/"+productLine[i].code+".gif' border=0></a></td></tr>");


		}
	}
	//if(isCatalog) document.write("<tr><td bgcolor=#FFFFFF><img src='/images/blank.gif' height=9></td></tr>");
	document.write("</table>");

}

// function clears radio button choices
function clearChoices(theField) {
	for(i=0;i<document.Form.elements[theField].length;i++) document.Form.elements[theField][i].checked=false;
}	
