function clearField(fieldName){
	if (fieldName.defaultValue == fieldName.value) {
		fieldName.value = "";
	}
}

function revertField(fieldName){
	if (fieldName.value == "") {
		fieldName.value = fieldName.defaultValue;
	}
}

	String.prototype.trim = function(){
      return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
    }

function voltage(varname)
{
  var voltArray = new Array("1","1.5","2","2.5","3","3.3","4","5","6","7","8","9","10","11","12","13","13.8","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","30","32","34","35","36","37","38","40","41","42","44","45","48","50","52","55","60","62","65","67","70","75","80","85","90","95","100","105","110","115","120","125","130","135","140","150","165","170","180","185","200","250","275","300","325","340","360","370","400","420","475","500","550","580","600","750","800","900","1000");
  var bFound = new Boolean(false);
  var negAlert = '';
  var sInput;
  if (varname != '') { //This is a temp statement to allow old forms and new ones to work.
	sInput = varname;
  } else {
	if (varname == '') {
		sInput = 0;
	} else {
		sInput = document.voltform.term.value;
	}
  }
  if (varname != '') {
	sInput = sInput.trim();
  }
  sInput = sInput.replace(/\s*|\s*/g,'');
  
  
// Added by Don Rea 2009-3-12 to invoke the negative message alert if a negative value is searched on
// All references to negAlert in this function are part of this
//----------------------------------------------------------------------------------------------------
  if (sInput.substring (0, 1) == '-')
  {
		sInput = sInput.replace (/-/, '');
		negAlert = '&popup=negVoltModal';
  }
  if (sInput.substring (0, 8) == 'negative')
  {
		sInput = sInput.replace (/negative/, '');
		negAlert = '&popup=negVoltModal';
  }
  if (sInput.substring (0, 3) == 'neg')
  {
		sInput = sInput.replace (/neg/, '');
		negAlert = '&popup=negVoltModal';
  }
//----------------------------------------------------------------------------------------------------
  
  
  var locToGoto
  if (!isNaN(sInput))	{
	  // make volt positive
	  sInput = Math.abs(sInput);
  }

	searchSuffix = "?search=" + sInput;
	
  for (var i = 0; i < voltArray.length; i++) {
	if(voltArray[i] == sInput) {
	  location.href = "/power-supply-voltages/" + String(voltArray[i]) + "-volt-power-supplies.htm" + searchSuffix + negAlert;  
	  bFound = true;
	  break;
	  }
  }
  if (bFound == false) {	

	if (isNaN(sInput))	{
		rangePattern = /^([0-9])+\s*([\-]|to)?\s*([0-9])*$/;
		if (rangePattern.test(sInput)) //regEx for range
		{
			locToGoto="wide-adjust";
		}
		else
		{
		    location.href = "/noresult.htm?search=" + sInput;
			// alert("Please enter a numerical voltage or voltage range (e.g. 10-50).");
			return;
		}
	} 
	else // it is a number
	{
		if (sInput>=0&&sInput<1) 				locToGoto="novoltage.html";
		else if (sInput>=1&&sInput<=3.3) 		locToGoto="1to3.3-volt-power-supplies.htm";
		else if (sInput>3.3&&sInput<=8) 		locToGoto="3.4to8-volt-power-supplies.htm";
		else if (sInput>8&&sInput<=13.5) 		locToGoto="8.1to13.5-volt-power-supplies.htm";
		else if (sInput>13.5&&sInput<=19.5) 	locToGoto="13.6to19.5-volt-power-supplies.htm";
		else if (sInput>19.5&&sInput<=26)	 	locToGoto="19.6to26-volt-power-supplies.htm";
		else if (sInput>26&&sInput<=35)	 		locToGoto="27to35-volt-power-supplies.htm";
		else if (sInput>35&&sInput<=52)	 		locToGoto="36to52-volt-power-supplies.htm";
		else if (sInput>52&&sInput<=90)	 		locToGoto="53to90-volt-power-supplies.htm";
		else if (sInput>90&&sInput<=123)		locToGoto="91to123-volt-power-supplies.htm";
		else if (sInput>123&&sInput<=150)		locToGoto="124to150-volt-power-supplies.htm";
		else if (sInput>150&&sInput<=200)		locToGoto="151to200-volt-power-supplies.htm";
		else if (sInput>200&&sInput<=1000)		locToGoto="201to1000-volt-power-supplies.htm";
		else if (sInput>1000&&sInput<=30000)	locToGoto="hv-details.html";
		else									{ alert("We do not make any power supplies above 30,000 volts."); return; }
	}
	
	if (locToGoto == "novoltage.html") {
		location.href = "/nonStandardvoltage/novoltage.html" + searchSuffix + negAlert;
	}
	else if (locToGoto == "hv-details.html") {
		location.href = "/hv-details.html" + searchSuffix + negAlert;
		}
	else if (locToGoto == "wide-adjust") {
		location.href = "/power-supply-voltages/wide-adjust-output-power-supplies.htm" + searchSuffix + negAlert;
		}
	else {
		location.href = "/power-supply-voltages/" + locToGoto + searchSuffix + negAlert;
	}
  }
}

function numOutputs(varname)
{
  var sInput;
  if (varname != '') { //This is a temp statement to allow old forms and new ones to work.
	sInput = varname;
  } else {
	if (varname == '') {
		sInput = 0;
	} else {
		sInput = document.voltform.term.value;
	}
  }
  if (varname != '') {
	sInput = sInput.trim();
  }
  var locToGoto;
  
  // make volt positive
  sInput = Math.abs(sInput);

	if (sInput>=1&&sInput<=30) {
		return true;
	}
	else {
		alert("Please Enter a Value Between 1 and 30."); 
		return false; 
	}
	
}

function findModel(model) 
{
	if (model.value == model.defaultValue) {
		location.href = "/store/search.aspx";
	} else {
		location.href = "/store/search.aspx?model=" + model.value;
	}
}