function validateCurrency(strValue)
	{
	//var objRegExp = /^-?\d+(\.\d\d)?$/
	var objRegExp = /^-?\d{1,3}(,?\d{3})*(\.\d{1,2})?$/;
	//check to see if in correct format
	  if(!objRegExp.test(strValue))
		return false;
	  else
	  	{return true;}	
	}
function addCurrency( strValue ) 
	{
  	var objRegExp = /-?[0-9]*\.[0-9]{2}$/;

    if( objRegExp.test(strValue)) 
		{
      	objRegExp.compile('^-');
      	strValue = addCommas(strValue);
      	if (objRegExp.test(strValue))
			{strValue = '(' + strValue.replace(objRegExp,'') + ')';}
      	return strValue;
    	}
    else
		{return strValue;}
	}
function validateInteger( strValue ) 
	{
  	var objRegExp  = /(^-?\d\d*$)/;

  	//check for integer characters
  	return objRegExp.test(strValue);
	}
	
function addCommas(nStr)
	{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
	}

function removeCurrency( strValue ) 
	{
  	var objRegExp = /\(/;
  	var strMinus = '';

  	//check if negative
  	if(objRegExp.test(strValue)){
    	strMinus = '-';
  	}

  	objRegExp = /\)|\(|[,]/g;
  	strValue = strValue.replace(objRegExp,'');
  	if(strValue.indexOf('$') >= 0){
  	  strValue = strValue.substring(1, strValue.length);
  	}
  	return strMinus + strValue;
	}
		
function validateUSDate( strValue ) 
	{
	  //var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/
	  var objRegExp = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/
	  
	  //check to see if in correct format
	  if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	  else{
		if(isNaN(strValue.substring(1,2)))
			{var strSeparator = strValue.substring(1,2)} //find date separator
		else
			{var strSeparator = strValue.substring(2,3)}
		var arrayDate = strValue.split(strSeparator); //split date into month, day, year
		//create a lookup for months not equal to Feb.
		var arrayLookup = {'1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,'8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}
		var intDay = parseInt(arrayDate[1],10); 
		
		//check if month value and day value agree
		if(arrayLookup[parseInt(arrayDate[0],10)] != null) 
		{
		  if(intDay <= arrayLookup[parseInt(arrayDate[0],10)] && intDay != 0)
			return true; //found in lookup table, good date
		}
		
		var intMonth = parseInt(arrayDate[0],10);
		if (intMonth == 2) 
		{ 
		   var intYear = parseInt(arrayDate[2]);
		   if (intDay > 0 && intDay < 29) 
		   	{return true;}
		   else if (intDay == 29) {
			 if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
				 (intYear % 400 == 0)) {
				  // year div by 4 and ((not div by 100) or div by 400) ->ok
				 return true;
			 }   
		   }
		}
	  }  
	  return false; //any other values, bad date
	}
function validatePOBoxes(strValue)
	{
	myRE = new RegExp("P.O. Box", 'i');
	myRE2 = new RegExp("PO Box", 'i');
	myRE3 = new RegExp("P O Box", 'i');
	myRE4 = new RegExp("P. O. Box", 'i');
	myRE5 = new RegExp("P.O Box", 'i');
	myRE6 = new RegExp("PO. Box", 'i');
	
	if(strValue.match(myRE) || strValue.match(myRE2) || strValue.match(myRE3) || strValue.match(myRE4) || strValue.match(myRE5) || strValue.match(myRE6))
		{return false;}
	else
		{return true;}
	}
function validateEmail(strValue) 
	{
	var objRegExp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/i;
	//check for valid email
	return objRegExp.test(strValue);
	}	

function mod10( cardNumber ) 
	{ // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;

	for(i = 0; i < cardNumber.length; ++i ) 
		{ar[i] = parseInt(cardNumber.charAt(i));}
	for(i = ar.length -2; i >= 0; i-=2) { // you have to start from the right, and work back.
		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
 	}										 // if the double digit is > 9, ADD those individual digits together 

	for( i = 0; i < ar.length; ++i ) {
			sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
		}
		return (((sum%10)==0)?true:false);	 	
	}


function expired( month, year ) 
	{
	var now = new Date();							// this function is designed to be Y2K compliant.
	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
	if( now.getTime() < expiresIn.getTime() ) return false;
	return true;									// then we get the miliseconds, and do a long integer comparison
	}


function validateCard(cardNumber,cardType,cardMonth,cardYear) 
	{
	
	switch( cardType ) {		
		case 'MC':
			if( cardNumber.length != 16 ) 
				{
				alert("Please enter a valid MasterCard number.");
				document.getElementById('order_CardNumber').focus();
				return false;
				}
			var prefix = parseInt( cardNumber.substring(0,2));
	
			if( prefix < 51 || prefix > 55) 
				{
				alert("Please enter a valid MasterCard Card number.");
				document.getElementById('order_CardNumber').focus();
				return false;
				}
			break;
		case 'Visa':
			if( cardNumber.length != 16 && cardNumber.length != 13 ) 
				{
				alert("Please enter a valid Visa Card number.");
				document.getElementById('order_CardNumber').focus();
				return false;
				}
			var prefix = parseInt( cardNumber.substring(0,1));

			if( prefix != 4 ) 
				{
				alert("Please enter a valid Visa Card number.");
				document.getElementById('order_CardNumber').focus();
				return false;
				}
			break;
		}
										
	return true; // at this point card has not been proven to be invalid
	}

function disableButton(thebutton,tf)
	{
	thebutton.style.visibility = (tf)?'hidden':'visible';	
	}
	
function alignDistributor()
	{
	var thiszip = "";
	var thiscity = "";
	var thisstate = "";
	var thiszip = document.getElementById('customer_Zip').value;
	var thiscusttype = document.getElementById('customer_CustomerType')[document.getElementById('customer_CustomerType').selectedIndex].value;
	var thiscity = document.getElementById('customer_City').value;
	var thisstate = document.getElementById('customer_State')[document.getElementById('customer_State').selectedIndex].value;
		
	if (thiscusttype == 1 && thiszip != "" && thiscity != "" && thisstate != "")
		{
		var thisfile = "align_distributor.cfm?zipcode="+thiszip+"&city="+thiscity+"&state="+thisstate;
		popupWindow(thisfile,'440','325','AlignDistributor','yes');
		}
	else if(thiscusttype == 1 && (thiszip == "" || thiscity == "" || thisstate == ""))
		{
		alert("Please provide your city, state and zipcode so we can find your closest Distributor(s).");
		document.getElementById('customer_CustomerType')[0].selected = true;
		document.getElementById('customer_City').focus();
		}
	}
function zoomTile(itemID)
	{
	popupWindow('zoomtile.cfm?itemID='+itemID,570,555,'zmTile','yes');
	}
function DWTilePopup(ptID)
	{
	popupWindow('DWTilePopup.cfm?ptID='+ptID,600,613,'DWTile','no');
	}
function popupWindow(fileToOpen,width,height,winName,scrollbars)
	{
	features = "location=no,toolbar=no,menubar=no,resizeable=no,scrollbars="+scrollbars+",height="+height+",width="+width;
	if (navigator.appName == "Netscape") features += ",screenX=150,screenY=150"
	else features += ",left=150,top=150"
	window.open(fileToOpen,winName,features);	
	}
function RoomRendering_Popup()
	{
	features = "location=no,toolbar=no,menubar=no,resizeable=no,scrollbars=no,height=560,width=780"
	if (navigator.appName == "Netscape") features += ",screenX=300,screenY=65"
	else features += ",left=300,top=97"
	window.open("http://americanolean.com/roomrendering/index.cfm","roomrendering",features);
	}
/*
function TileTabulator_Popup()
	{
	features = "location=no,toolbar=no,menubar=no,resizeable=no,scrollbars=no,height=450,width=600"
	if (navigator.appName == "Netscape") features += ",screenX=300,screenY=75"
	else features += ",left=300,top=107"
		window.open("floortile/tile_tabulator.htm","pop",features);
	}	
*/
function TileTabulator_Popup()
	{
	features = "location=no,toolbar=no,menubar=no,resizeable=no,scrollbars=no"
	if (navigator.appName == "Netscape") features += ",screenX=300,screenY=75"
	else features += ",left=300,top=107"
		window.open("http://www.americanolean.com/tileestimator/tileEstimator.html","pop",features);
	}
function SelectSKU(itemID)
	{
	features = "location=no,toolbar=no,menubar=no,resizeable=yes,scrollbars=yes,height=292,width=565"
	if (navigator.appName == "Netscape") features += ",screenX=225,screenY=178"
	else features += ",left=225,top=210"
	window.open("selecttilesku.cfm?itemID="+itemID,"ItemSKUPop",features);
	}
	