// version of Flash required
var requiredMinorVersion = 0;
var requiredRevision = 0;
//browser
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

//MAIN MENU ITEMS
var menuArray = new Array('','plants','about-us','buy','shipping','contact');
var numMenus = 5;

document.onmouseover = hideAllMenus;
document.onclick = hideAllMenus;

var images = new Array()
images[0] = '/graphics/gradient-blue-27px.gif';

var currentSection;

function headerForm()
{
	var objForm = document.getElementById('headerForm');
	objForm.User_Id.email = true;
	if(verify(objForm))
	{
		objForm.submit();
	}
}

function contactForm(formType)
{
	var objForm = document.getElementById('contactForm');
	if(formType == 'avail'){objForm.Question_or_Comment.optional=true;}
	objForm.Email.email = true;
	if(verify(objForm))
	{
		objForm.action = self.location.href;
		objForm.submit();
	}
}

function getStyleObject(objectId) 
{
  if(document.getElementById && document.getElementById(objectId)) 
	{
		// W3C DOM
		return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM
		return document.layers[objectId];
  } else {
		return false;
  }
} 

function changeObjectVisibility(objectId, newVisibility, newZindex)
{
  var styleObject = getStyleObject(objectId);
  if(styleObject) 
	{
		
		styleObject.visibility = newVisibility;
		styleObject.zIndex = newZindex;
		return true;
	} 
	else 
	{
		//couldn't find the object, can't change its visibility
		return false;
  }
}	

function showMenu(menuNumber, eventObj, labelID, parentMenu) 
{
	hideAllMenus(parentMenu);
	eventObj.cancelBubble = true;
	var menuId = 'submenu' + menuNumber;
	if(changeObjectVisibility(menuId, 'visible', 100))
	{
		return true;
  } 
	else 
	{
		return false;
  }
}

function hideAllMenus(parentMenu) 
{
	for(counter = 1; counter <= numMenus; counter++) 
	{
		if(counter != parentMenu)
		{
			changeObjectVisibility('submenu' + counter, 'hidden', 1);
		}
	}
}

function hideOtherMenus()
{
	for(counter = 1; counter <= numMenus; counter++) 
	{
		if(counter != currentSection || currentSection == '')
		{
			changeObjectVisibility('submenu' + counter, 'hidden', 1);
		}
		else if(counter == currentSection)
		{
			changeObjectVisibility('submenu' + counter, 'visible', 1);
		}
	}
}

var liveButton = '';
function drawMenu()
{
	var sectionName = unescape(parsedSection());
	sectionName = replaceChars(sectionName,'-','');
	if(sectionName == 'order'){sectionName = 'buy';}
	liveButton = sectionName + 'Button';
	var pageName = unescape(parsedName());
	var spacer = '<span class="menuSpacer"></span>';
	var liveMenu = ' style="background-position:0px -27px; color:#fff;"';
	var mainMenu = '';

	mainMenu = '<a href="/contact/" class="mainMenuLink"';
	if(sectionName == 'contact'){mainMenu += liveMenu;}
	mainMenu += ' id="contactButton">CONTACT</a>';
	mainMenu += spacer;
	mainMenu += '<a href="/shipping/" class="mainMenuLink"';
	if(sectionName == 'shipping'){mainMenu += liveMenu;}
	mainMenu += ' id="shippingButton">SHIPPING</a>';
	mainMenu += spacer;
	mainMenu += '<a href="/order/" class="mainMenuLink"';
	if(sectionName == 'buy'){mainMenu += liveMenu;}
	mainMenu += ' id="buyButton">BUY</a>';
	mainMenu += spacer;
	mainMenu += '<a href="/about-us/" class="mainMenuLink"';
	if(sectionName == 'aboutus'){mainMenu += liveMenu;}
	mainMenu += ' id="aboutusButton">ABOUT US</a>';
	mainMenu += spacer;
	mainMenu += '<a href="/plants/" class="mainMenuLink"';
	if(sectionName == 'plants'){mainMenu += liveMenu;}
	mainMenu += ' id="plantsButton">PLANTS</a>';
	mainMenu += spacer;
	mainMenu += '<a href="/" class="mainMenuLink"';
	if(sectionName == 'home'){mainMenu += liveMenu;}
	mainMenu += ' id="homeButton">HOME</a>';
	document.write(mainMenu);
}

function parsedSection()
{
	var urlString = location.toString();
	var urlArray = urlString.split('/');
	var rootDir = urlArray[2];
	var sectionName = urlArray[urlArray.length-2];
	if(rootDir == sectionName){sectionName = 'home';}
	return sectionName;
}

function parsedName()
{
	var urlString = location.toString();
	var urlArray = urlString.split('/');
	var sectionPage = urlArray[urlArray.length-1];
	if((sectionPage == null) || (sectionPage == '')){sectionPage = 'index.asp';}
	sectionPage = sectionPage.substr(0,sectionPage.indexOf('.'));
	return sectionPage
}

function movieIsLoaded(theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}

var imageArray = new Array();
function grabImages(images)
{
	for(i=0;i<images.length;i++)
	{
		var whatImage = images[i];
		var n = imageArray.length;
		imageArray[n] = new Image();
		imageArray[n].src = whatImage;
	}
}
			
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function returnVars(whatVars)
{
     var flashMovie=getFlashMovieObject("controls");
     flashMovie.responseVars(whatVars);
}

function getWidth()
{
	var frameWidth = '';
  if (self.innerWidth)
  {
	frameWidth = self.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth)
  {
	frameWidth = document.documentElement.clientWidth;
  }
  else if (document.body)
  {
	frameWidth = document.body.clientWidth;
  }
  return frameWidth;
}

function getHeight()
{
	var frameHeight = '';
  if (self.innerHeight)
  {
	frameHeight = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  {
	frameHeight = document.documentElement.clientHeight;
  }
  else if (document.body)
  {
	frameHeight = document.body.clientHeight;
  }
  return frameHeight;
}

function findPos(styleObject) {
	var curleft = 0;
	var curtop = 0;
	if (styleObject.offsetParent) {
		curleft = styleObject.offsetLeft
		curtop = styleObject.offsetTop
		while (styleObject = styleObject.offsetParent) {
			curleft += styleObject.offsetLeft
			curtop += styleObject.offsetTop
		}
	}
	return [curleft,curtop];
}

function getArgs()
{
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split(',');
	for(var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if(pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}

//jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i)
{
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) 
		{ 
			//alert('no version');
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	return (reqVer ? false : 0.0);
}

function showFlash(whatMovie,paramString,movieName,W,H,BG,Win,Alignment,whatScale,whatVersion,alternateContent)
{
	var requiredMajorVersion = whatVersion;
	if(whatScale == null || whatScale == '')
	{
		whatScale = 'showAll';
	}
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion)
	{  // if we've detected an acceptable version
		var downloadAddress = 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab';
    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + ' width="'+W+'" height="'+H+'" id="'+movieName+'"'
    + ' codebase="'+downloadAddress+'">'
    + '<param name="movie" value="'+whatMovie+paramString+'" />'
    + '<param name="menu" value="false" />'
    + '<param name="quality" value="high" />'
    + '<param name="wmode" value="'+Win+'" />'
    + '<param name="bgcolor" value="#'+BG+'" />'
    + '<param name="scale" value="'+whatScale+'" />'
    + '<embed src="'+whatMovie+paramString+'" menu="false" quality="high"'
    + ' wmode="'+Win+'" bgcolor="#'+BG+'" '
    + ' scale="'+whatScale+'"'
    + ' width="'+W+'" height="'+H+'" name="'+movieName+'" align="'+Alignment+'"'
    + 'play="true"'
    + 'loop="false"'
    + 'quality="high"'
    + 'allowScriptAccess="sameDomain"'
		+ 'swliveconnect="true"'
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="https://www.macromedia.com/go/getflashplayer">'
    + '<\/embed>'
    + '<\/object>';
		//alert(oeTags);
    document.write(oeTags);   // embed the flash movie
  } 
	else 
	{
			document.write(alternateContent);
  }
}

function clearField(whatField,defaultVal)
{
	if(whatField.value == defaultVal){whatField.value = '';}
}


function verify(f)
{
  var empty_fields = "";
  var fCount = 0;
  var empty_options = "";
  var oCount = 0;
	var empty_checks = '';
	var cCount = 0;
  var errors = "";
  var eCount = 0;
  var msg = "";
	var checkedSets = new Array();

  for(var i = 0; i < f.length; i++)
  {
    var e = f.elements[i];
		var fieldTitle = e.name;
		if((e.fTitle != '') && (e.fTitle != null)){fieldTitle = e.fTitle;}
		e.style.borderColor='#EBEBEB';
		e.style.borderBottomColor='#000';
    if(((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && !e.optional)
    {
      if (((e.value == null) || (e.value == "") || isblank(e.value)) && !e.conditional)
      {
        empty_fields += "\n" + replaceChars(fieldTitle,"_"," ") + " is required";
				e.style.borderColor='#f00';
        fCount += 1
        continue;
      }
		}

		//CHECKBOXES
		/*
		if((e.type == 'checkbox') && !e.optional && !e.conditional)
		{
			var setName = fieldTitle;
			var setChecked = false;
			if(!Array.indexOf)
			{
					for(var cs=0; cs<checkedSets.length; cs++)
					{
						if(checkedSets[cs]==setName)
						{
							setChecked = true;
							break;
						}
					}
			}
			if(Array.indexOf)
			{
				if(checkedSets.indexOf(setName) > -1)
				{
					setChecked = true;
				}
			}
			if(!setChecked)
			{
				var checkVal = false;
				var currentSet = f[setName];
				for(zz=0;zz<currentSet.length;zz++)
				{
					if(currentSet[zz].checked)
					{
						checkVal = true;
						break;
					}
				}
				if(!checkVal)
				{
	        empty_checks += "\n" + replaceChars(fieldTitle,"_"," ") + " selection is required";
	        cCount = cCount + 1;
				}
				checkedSets.push(setName);
			}
		}	//END OF CHECKBOXES
		*/

		//RADIOS
		if(e.type == 'radio' && (!e.optional || !e.conditional))
		{
			var setName = fieldTitle;
			var setChecked = false;
			if(!Array.indexOf)
			{
					for(var cs=0; cs<checkedSets.length; cs++)
					{
						if(checkedSets[cs]==setName)
						{
							setChecked = true;
							break;
						}
					}
			}
			if(Array.indexOf)
			{
				if(checkedSets.indexOf(setName) > -1)
				{
					setChecked = true;
				}
			}
			if(!setChecked)
			{
				var checkVal = false;
				var currentSet = f[setName];
				for(zz=0;zz<currentSet.length;zz++)
				{
					if(currentSet[zz].checked || currentSet[zz].optional)
					{
						checkVal = true;
						break;
					}
				}
				if(!checkVal)
				{
		      empty_checks += "\n" + replaceChars(fieldTitle,"_"," ") + " selection is required";
					//alert(fieldTitle);
					document.getElementById(e.id).style.borderColor='#f00';  //NAME IS ID OF PARENT CONTAINER
		      cCount = cCount + 1;
				}
				else
				{
					//alert('0'+e.name);
					document.getElementById(e.id).style.borderColor='#fff';
				}
				checkedSets.push(setName);
			}
		}	//END OF RADIOS
		
		//CONDITONAL FIELDS
    if(e.conditional)
    {
			var triggered = false;
			var failed = false;
			//FIRST CHECK IF THE CONDITONAL FIELD IS REQUIRING THIS TO HAVE A VALUE
			var conditionField = e.condition;
			if(regExTest(conditionField,/[\d]/))
			{
				var whatField = f.elements[conditionField];
			}
			else
			{
				var whatField = f[conditionField];
			}
			var fieldType = whatField.type;
			var fieldName = whatField.id;
				//WHAT VALUE TO TRIGGER THIS
			var conditionalValue = e.conValue;
			//alert(e.name+','+e.type+','+e.condition+','+conditionalValue+','+e.optional);
			//WHAT TYPE OF FIELD WAS SELECTED TO TRIGGER THIS
			if(fieldType == 'hidden' && whatField.value == 'true')
			{
				triggered = true;
			}
			if(fieldType == 'checkbox' && whatField.checked)
			{
				triggered = true;
			}
			if(fieldType == 'radio' && whatField.checked)
			{
				triggered = true;
			}
			if(fieldType == 'text')
			{
				if((conditionalValue == 'notNull') && (whatField.value != ''))
				{
					triggered = true;
				}
				else if(whatField.value == conditionalValue)
				{
					triggered = true;
				}
			}
			if(whatField.options)
	    {
      	//if (whatField.selectedIndex == (whatField.length-1))
				if(whatField.value == conditionalValue)
      	{
					triggered = true;
				}
			}
			if(triggered == true)
			{
				//alert('triggered');
				//CHECK THAT THE CONDITION IS MET
				if((e.options || (e.type == 'select-one')) && !e.optional)
    		{
      		var which = e.options.selectedIndex;
					if(which < 0)
					{
						failed = true;
					}else{
						var choice = e.options[which].value;
						if ((choice == null) || (choice == ""))
						{
							failed = true;
						}
					}
				}
				if((e.type == "text") || (e.type == "textarea"))
				{
					if((e.value == null) || (e.value == "") || isblank(e.value))
					{
						failed = true;
					}
				}
				if((e.type == 'checkbox') || (e.type == 'radio'))
				{
					var setName = fieldTitle;
					var setChecked = false;
					if(!Array.indexOf)
					{
							for(var cs=0; cs<checkedSets.length; cs++)
							{
								if(checkedSets[cs]==setName)
								{
									setChecked = true;
									break;
								}
							}
					}
					if(Array.indexOf)
					{
						if(checkedSets.indexOf(setName) > -1)
						{
							setChecked = true;
						}
					}
					if(!setChecked)
					{
						var checkVal = false;
						var currentSet = f[setName];
						for(zz=0;zz<currentSet.length;zz++)
						{
							if(currentSet[zz].checked == true)
							{
								checkVal = true;
								break;
							}
						}
						if(!checkVal)
						{
							failed = true;
						}
						checkedSets.push(setName);
					}
				}
				if(failed == true)
				{
					//alert("failed");
        	empty_fields += "\n" + replaceChars(fieldTitle,"_"," ") + " is required;";
					document.getElementById(e.name).style.borderColor='#f00';  //NAME IS ID OF PARENT CONTAINER
          fCount += 1
					e.style.borderColor='#f00';
				}
				else
				{
					document.getElementById(e.name).style.borderColor='#fff';  //NAME IS ID OF PARENT CONTAINER
				}
			}
    }
		
		if(e.time)
		{
			if(regExTest(e.value,"[^0-9:]") == true)
			{
			  errors += "\nA valid " + replaceChars(fieldTitle,"_"," ") + " is required. Format as: xx:xx";
			  eCount += 1;
				e.style.borderColor='#f00';
			}
    }
		
    if(e.phone)
    {
			var rangePattern = /[^0-9-]/;
			if(regExTest(e.value,rangePattern) == true)
			{
         errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be numeric. Format as: xxx-xxx-xxxx";
         eCount = eCount + 1;
				e.style.borderColor='#f00';
			}
    }
		
    if(e.money)
    {
			var moneyPattern = /[^0-9\$\.\,]/;
			if(regExTest(e.value,"[^0-9\.\$,]") == true)
			{
         errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be dollars and cents";
         eCount = eCount + 1;
				e.style.borderColor='#f00';
			}
    }
		
    if(e.numeric)
    {
			var numPattern = /[^0-9\.\,]/;
			if(regExTest(e.value,numPattern) == true)
			{
         errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be numeric";
         eCount = eCount + 1;
				e.style.borderColor='#f00';
			}
    }
		
    if(e.numericRange)
    {
			var rangePattern = /[^0-9\s\$\.\,-]/;
			if(regExTest(e.value,rangePattern) == true)
			{
         errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be numeric";
         eCount = eCount + 1;
				e.style.borderColor='#f00';
			}
    }
		
		if(e.date && !e.conditional)
		{
			var datePattern = /\d{1,2}\/\d{1,2}\/\d{4}/;
			if(regExTest(e.value,datePattern) == false)
			{
			  errors += "\nA valid " + replaceChars(fieldTitle,"_"," ") + " is required. Format as: xx/xx/xxxx";
			  eCount += 1;
				e.style.borderColor='#f00';
			}
    }
			
    if(e.count != null)
    {
	    if (e.value.length < e.count)
      {	  
  	    errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be at least " + e.count + " characters in length";
        eCount = eCount + 1;
				e.style.borderColor='#f00';
      }
    }
    if(e.minValue != null)
    {
		  var v = parseFloat(e.value);
      if (isNaN(v) || ((e.minValue != null) && (v < e.minValue)))
      {	  
        errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be greater than " + e.minValue;
        eCount = eCount + 1;
				e.style.borderColor='#f00';
      }
    }
    if(e.maxValue != null)
    {
		  var v = parseFloat(e.value);
      if (isNaN(v) || ((e.maxValue != null) && ( v > e.maxValue)))
      {	  
        errors += "\n" + replaceChars(fieldTitle,"_"," ") + " must be less than " + e.maxValue;
        eCount = eCount + 1;
				e.style.borderColor='#f00';
      }
    }
    if(e.email)
    {
			if(regExTest(e.value,"^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$") == false)
			{
			  errors += "\nA valid email address is required";
			  eCount += 1;
				e.style.borderColor='#f00';
			}
    }
		
		if(e.creditcard)
		{
			var ccType = document.getElementById('Credit_Card_Type').value;
			if(ccType != null && ccType != '')
			{
				if(!isValidCC (ccType, e.value))
				{
					errors += "\nInvalid Credit Card Number";
					eCount += 1;
					e.style.borderColor='#f00';
				}
			}
			else
			{
					eCount += 1;
			}
		}
		
		if(e.rx && (e.value != null) && (e.value != "") && !isblank(e.value))
		{
			if(regExTest(e.value,e.pattern) == true)
			{
				errors += "\nInvalid Characters Entered for " + replaceChars(fieldTitle,"_"," ");
				eCount += 1;
				e.style.borderColor='#f00';
			}
		}
		
    if (e.options && !e.optional && !e.conditional)
    {
      var which = e.options.selectedIndex;
			if(which < 0)
			{
        empty_options += "\n" + replaceChars(fieldTitle,"_"," ") + " selection is required";
        oCount = oCount + 1;
				e.style.borderColor='#f00';
			}else{
				var choice = e.options[which].value;
				if ((choice == null) || (choice == "") && !e.conditional)
				{
					empty_options += "\n" + replaceChars(fieldTitle,"_"," ") + " selection is required";
					oCount = oCount + 1;
					e.style.borderColor='#f00';
					//continue;
				}
			}
    }
  }

  if ((!empty_fields) && (!empty_options) && (!empty_checks) && !errors)
  {
    return true;
  }
  else
  {
		msg = "Please correct the following entries.\n"
    if (empty_fields)
    {
      fieldsVar = "field"
      if(fCount > 1){fieldsVar += "s"}
      msg += "\n" + fCount + " required " + fieldsVar + " left blank.";
      msg += empty_fields += "\n";
    }
    if (errors)
    {
      fieldsVar = "field"
      if(eCount > 1){fieldsVar += "s"}
      msg += "\n" + eCount + " " + fieldsVar + " with invalid entries.";
      msg += errors += "\n";
    }
    if (empty_options)
    {
      choicesVar = "drop-down selection"
      if (oCount > 1)
        {choicesVar += "s"}
      msg += "\n" + oCount + " required " + choicesVar + " not completed.";
      msg += empty_options += "\n";
    }
    if (empty_checks)
    {
      choicesVar = "checkbox\/radio option"
      if (cCount > 1)
        {choicesVar += "s"}
      msg += "\n" + cCount + " required " + choicesVar + " not chosen.";
      msg += empty_checks += "\n";
    }
    alert(msg);
    return false;
  }
}

function isblank(s)
{
  for(var i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}

function replaceChars(string,text,by) 
{
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceChars(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function regExTest(whatString,whatPattern)
{
	var regX = new RegExp(whatPattern);
	return regX.test(whatString);
}

function luhn (cc) {
   var sum = 0;
   var i;
 
   for (i = cc.length - 2; i >= 0; i -= 2) {
      sum += Array (0, 2, 4, 6, 8, 1, 3, 5, 7, 9) [parseInt (cc.charAt (i), 10)];
   }
   for (i = cc.length - 1; i >= 0; i -= 2) {
      sum += parseInt (cc.charAt (i), 10);
   }
   return (sum % 10) == 0;
}

var creditCardList = [
   ["1",      "4",    16],
   ["1",      "4",    13],
   ["visa",    "4",     13],
   ["visa",    "4",     16],
   ["2",      "51",    16],
   ["mc",      "51",    16],
   ["mc",      "52",    16],
   ["mc",      "53",    16],
   ["mc",      "54",    16],
   ["mc",      "55",    16]
											/*
   ,["amex",    "34",    15],
   ["amex",    "37",    15],
   ["disc",    "6011",  16]
	 */
];

function isValidCC (cctype, ccnumber)
{
   var cc = getdigits (ccnumber);
   if (luhn (cc)) {
      for (var i in creditCardList) {
         if (creditCardList [i][0] == (cctype.toLowerCase ())) {
            if (cc.indexOf (creditCardList [i][1]) == 0) {
               if (creditCardList [i][2] == cc.length) {
                  return true;
               }
            }
         }
      }
   }
   return false;
}

function getdigits (s) {
   return s.replace (/[^\d]/g,'');
}

function autoTab(input,len, e)
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(input.value.length >= len && !containsElement(filter,keyCode)) 
	{
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
}

function containsElement(arr, ele)
{
	var found = false
	var index = 0;
	while(!found && index < arr.length)
	{
		if(arr[index] == ele)
		{
			found = true;
		}
		else
		{
			index++;
		}
	}
	return found;
}

function getIndex(input) 
{
	var index = -1
	var i = 0
	var found = false;
	while (i < input.form.length && index == -1)
	{
		if (input.form[i] == input)
		{
			index = i;
		}
		else 
		{
			i++;
		}
	}
	return index;
}

function submitForm(formName,whereTo)
{
	var whatForm = document.getElementById(formName);
	if(formName == 'contactForm')
	{
		whatForm.Address.optional=true;
		whatForm.City.optional=true;
		whatForm.State.optional=true;
		whatForm.ZIP.optional=true;
		whatForm.Email.email=true;
		whatForm.Area_Code.numeric=true;
		whatForm.Phone_Prefix.numeric=true;
		whatForm.Phone_Number.numeric=true;
	}
	if(formName == 'headerForm')
	{
		whatForm.Sign_In_User_Name.email=true;
	}
	if(formName == 'signupForm')
	{
		whatForm.Email_Address.email=true;
		whatForm.Phone.optional=true;
		whatForm.Address.optional=true;
		whatForm.Address_2.optional=true;
		whatForm.City.optional=true;
		whatForm.State.optional=true;
		whatForm.Zip.optional=true;
	}
	var whatReturn = verify(whatForm); 
	if(whatReturn != false)
	{
		whatForm.action = whereTo;
		whatForm.submit();
	}
}

//AJAX STUFF
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function printWin(whatFile)
{
  var printWindow = open(whatFile,'printWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=760,height='+screen.availHeight+',top=0,left=0');
  printWindow.focus();
}