//Pool Zone JavaScript functions

/*#######################################################

This function creates an array of all HTML elements that are an <input> tag
It then determines which are checked, and then ads the checked checkbox value to an array.
This is then passed to the product compare PHP function to pull information from the database.

##########################################################*/

function getCheckboxValues()
{
var checkedArray = new Array();
var inputTagArray = new Array();
var arrayString;
inputTagArray = document.getElementById("centerarea").getElementsByTagName("input");
    for (var i=0; i<inputTagArray.length; i++)
    {
      if(inputTagArray[i].type=='checkbox' && inputTagArray[i].checked)
      {
        checkedArray.push(inputTagArray[i].value);
      }
    }
    arrayString = checkedArray.toString();
    document.getElementById('prodCompareInput').value = arrayString;
    document.getElementById('prodCompare').submit();
}


/*#######################################################
//Tab switching function
##########################################################*/

function setActiveTab(e) {

//If IE source = event.srcElement, if other, source = e.target.
//Different browsers have different javascript stuff.
//Since the tag being clicked is the <a> tag, that is the "source", we need to make changes to the <li> tag CSS
var source = window.event?event.srcElement:e.target;
var ulList = document.getElementById(source.parentNode.parentNode.id);
var tabBody = document.getElementById(source.parentNode.id + "Body");
var tabContent = document.getElementById(tabBody.parentNode.id);


//Set the Active Tab.  Need both lines for Firefox AND stupid IE 6
source.parentNode.setAttribute("class", "activeTab");
source.parentNode.setAttribute("className", "activeTab");

//Change previously active tab
for (i=0; i<ulList.childNodes.length; i++)
{
    if ((ulList.childNodes[i].nodeName=="LI") && (ulList.childNodes[i].id!=source.parentNode.id))
      {
         ulList.childNodes[i].setAttribute("class", "");
         ulList.childNodes[i].setAttribute("className", "");
      }
}

//Set the Active Tab Body.  Need both lines for Firefox AND stupid IE 6
tabBody.setAttribute("class", "activeInfo");
tabBody.setAttribute("className", "activeInfo");

//Hide previously active body
for (i=0; i<tabContent.childNodes.length; i++)
{
    //window.alert("in loop");
    if ((tabContent.childNodes[i].className=="activeInfo") && (tabContent.childNodes[i].id!=tabBody.id))
      {
         tabContent.childNodes[i].setAttribute("class", "inactiveInfo");
         tabContent.childNodes[i].setAttribute("className", "inactiveInfo");
      }
}

return;
}

/*#######################################################
//Check to make sure that if options are needed that they are selected.

##########################################################*/
function checkExtOps(frmname)
{
 //go through each element to see if any are dropdowns, check to see if something is selected.
 for(i=0; i < frmname.length; i++)
 {  
  if(frmname.elements[i].type == 'select-one' || frmname.elements[i].type == 'select-multiple')
  {
   if(frmname.elements[i].selectedIndex==0)
   {
    alert("Please select an option.");
    frmname.elements[i].focus();
    return false;
   }
  }
 } 
 return true;
}


/*#######################################################
//Popup fade function

##########################################################*/

var globalID;
var counter = 0;

	function popUp(elementID)
	{
                 globalID = elementID;
                 document.getElementById(globalID).style.visibility = "visible";
                 counter = 0;
                 fadeTimer = window.setInterval("fadeIn()", 20);
	}
	
	function hideElement(e)
	{
                 var source = window.event?event.srcElement:e.target;
                 globalID = source.parentNode.id;
                 counter = 1;
                 fadeTimer = window.setInterval("fadeOut()", 20);
	}
	
	function fadeIn()
	{
                 counter = counter + .1;
                 document.getElementById(globalID).style.opacity = counter;
                 if (counter > 1)
                    {
                      window.clearInterval(fadeTimer);
                    }
	}
	
	function fadeOut()
	{
                 counter = counter - .1;
                 document.getElementById(globalID).style.opacity = counter;
                 if (counter <= 0)
                    {
                      window.clearInterval(fadeTimer);
                      document.getElementById(globalID).style.visibility = "hidden";
                      counter=0;
                    }
	}


//******************************************************************************
//End Image Popup Functions


/*#######################################################
//Script to verify that all necessary information has been added

##########################################################*/
function Verify(myForm)
{

        if (myForm.fname.value.length < 1)
	{
                alert("Please enter a First Name.");
		myForm.fname.focus();
		return (false);
	}
	if (myForm.lname.value.length < 1)
	{
		alert("Please enter a Last Name.");
		myForm.lname.focus();
		return (false);
	}
	if (myForm.comp.value.length < 1)
	{
		alert("Please enter your Company Name.");
		myForm.comp.focus();
		return (false);
	}
	if (myForm.position.value.length < 1)
	{
		alert("Please enter your position in the company");
		myForm.position.focus();
		return (false);
	}
	if (myForm.add1.value.length < 1)
	{
		alert("Please enter an address.");
		myForm.add1.focus();
		return (false);
	}
	if (myForm.city.value.length < 1)
	{
		alert("Please enter your City.");
		myForm.city.focus();
		return (false);
	}
	if (myForm.zip.value.length < 1)
	{
		alert("Please enter your Zip/Postal Code.");
		myForm.zip.focus();
		return (false);
	}
	if (myForm.state.value == "None")
	{
		alert("Please enter your state.");
		myForm.state.focus();
		return (false);
	}
	if (myForm.email.value.length < 1)
	{
		alert("Please enter your email address.");
		myForm.email.focus();
		return (false);
	}
	if (myForm.phone.value.length < 1)
	{
		alert("Please enter your phone number.");
		myForm.phone.focus();
		return (false);
	}
	if (myForm.products.value.length < 1)
	{
		alert("Please list your product lines.");
		myForm.products.focus();
		return (false);
	}

 }
 
/*#######################################################
//Script for hover effect in OS Commerce checkout area.  This should be converted to 
CSS hover attributes when we have the time.

##########################################################*/

var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

/*#######################################################

image Change function for larger images page.

##########################################################*/

function ChangeImage(newImageName)
{
	document.getElementById('ImageName').src = "images/" + newImageName + ".jpg";
}
