$(document).ready(function() {
	
	$('table.sortable').tablesorter();
	$('a.lightbox').lightBox();

});


// Old Scripts from Old Power Profiler tool

if (document.images) {
	
//top nav

	emissionsover = new Image
	emissionsover.src = "http://www.epa.gov/cleanrgy/powpro/myemissions_over.gif"
	emissionsup = new Image
	emissionsup.src = "http://www.epa.gov/cleanrgy/powpro/myemissions_up.gif"
	
	moreover = new Image
	moreover.src="http://www.epa.gov/cleanrgy/powpro/bemore_over.gif"
	moreup = new Image
	moreup.src = "http://www.epa.gov/cleanrgy/powpro/bemore_up.gif"
	
	buyover = new Image
	buyover.src = "http://www.epa.gov/cleanrgy/powpro/buygreen_over.gif"
	buyup = new Image
	buyup.src = "http://www.epa.gov/cleanrgy/powpro/buygreen_up.gif"
	
}
else {
	document.emissions = " "
	emissionsover = " "
	emissionsup = " "
	
	document.more = " "
	moreover = " "
	moreup = " "

	document.buy = " "
	buyover = " "
	buyup = " "
	
}
function definitionWindow(v_newurl) {

	defineWindow = window.open (v_newurl, 'definitions', 'height=200,width=360,scrollbars=1,resizeable=0,toolbar=0,location=0');

	}
function subregionWindow(v_url) {

defineWindow = window.open (v_url,'subregionmap','height=400,width=525,scrollbars=0,resizeable=0,toolbar=0,location=0');
}

function zip_validator(textfield)
{
  var checkOK = "0123456789";
  var checkStr = textfield.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }

  }

  if (!allValid)
  {
    alert("Please enter numbers only in the ZIP Code.");
    textfield.focus();
    textfield.blur();
    textfield.select();

	 return (false);
  }


  if (textfield.value.length < 5)
  {
    alert("Please enter 5-digit Zip Code.");
    textfield.focus();
    textfield.blur();
    textfield.select();

     return (false);
  }

return true;


}

 function main_validator(theForm)
{
  if (theForm.p_zip.value == "")
  {
    alert("Please enter your 5-digit Zip Code.");
    theForm.p_zip.focus();
    theForm.p_zip.blur();
    theForm.p_zip.select();

     return (false);
  }

  if (theForm.p_zip.value.length < 5)
  {
    alert("Please enter 5-digit Zip Code.");
    theForm.p_zip.focus();
    theForm.p_zip.blur();
    theForm.p_zip.select();

     return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theForm.p_zip.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }

  }
  if (!allValid)
  {
    alert("Please enter numbers only in the ZIP Code box.");
    theForm.p_zip.focus();
    theForm1.p_zip.blur();
    theForm.p_zip.select();

	 return (false);
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in this field.");
    theForm.p_zip.focus();
    theForm.p_zip.blur();
    theForm.p_zip.select();

    return (false);
  }
  
  return true;
}
