var xmlHttp
var currentSystem = '';
var currentBrand = '';
var mouseHeight = 0;



function displayPopup(elem)
{
    document.getElementById("terrain_flash_section").style.display = "none";
    document.getElementById("installer_flash_section").style.display = "none";
    document.getElementById("terrain_flash_holding").style.display = "block";
    document.getElementById("installer_flash_holding").style.display = "block";
    Effect.Appear($('windowblind'), {to:0.5});
    Effect.Appear($(elem));
}
function closePopUp(elem)
{
    Effect.Fade($('windowblind'));
    Effect.Fade($(elem));
    document.getElementById("terrain_flash_holding").style.display = "none";
    document.getElementById("installer_flash_holding").style.display = "none";
    document.getElementById("terrain_flash_section").style.display = "block";
    document.getElementById("installer_flash_section").style.display = "block";
}
function showSystemSearch()
{  
    Effect.Appear($('system_search'));
}
function showBrandSearch()
{
    Effect.Appear($('brand_search'));
}
function cancelForm(div_name)
{
    Effect.Fade($('windowblind'));
    Effect.Fade($(div_name));
}
function clearProductCode()
{
    document.getElementById("product_code_results").innerHTML="";
}
function showProductCodeSearchResults()
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }


    var searchTerm = document.getElementById('product_code_input').value;
    var url="/polypipe/controller?action=PP-ProductCodeSearchResults&searchterm="
    url=url+searchTerm
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangeShowProductCodeSearchResults
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)

}

function stateChangeShowProductCodeSearchResults()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("product_code_results").innerHTML=xmlHttp.responseText
    }
}

function stateChangeShowSystemSearchResults()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {

        document.getElementById("search_all_systems_result").innerHTML=xmlHttp.responseText
    }
}
function showSystemSearchResults(str, count)
{ 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

    if(currentSystem != '')
        document.getElementById('system_' + currentSystem).style.color = '#5687C0';

    document.getElementById('system_' + count).style.color = '#fff';
    var url="/polypipe/controller?action=PP-SystemSearchResults&type=1&system_brand="
    url=url+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangeShowSystemSearchResults
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    currentSystem = count;

}

function stateChangeShowSystemSearchResults() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("search_all_systems_result").innerHTML=xmlHttp.responseText
    }
}

function clearSearchResults() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("search_all_systems_result").innerHTML=''
    }
}

function showBrandSearchResults(str, count)
{ 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    if(currentBrand != '')
        document.getElementById('brand_' + currentBrand).style.color = '#5687C0';

    document.getElementById('brand_' + count).style.color = '#fff';
    var url="/polypipe/controller?action=PP-SystemSearchResults&type=2&system_brand="
    url=url+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangeShowBrandSearchResults
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    currentBrand = count;
     
}
function show_coordsBrands(event, str, count)
{
mouseHeight=event.clientY + document.documentElement.scrollTop;
document.getElementById('search_all_brands_result').style.top = (mouseHeight - 60) + "px";
//Effect.Appear(document.getElementById('search_all_brands_result'));
document.getElementById('search_all_brands_result').style.display = 'block';
showBrandSearchResults(str, count);
}

function show_coordsSystems(event, str, count)
{
mouseHeight=event.clientY + document.documentElement.scrollTop;
document.getElementById('search_all_systems_result').style.top = (mouseHeight - 60) + "px";
//Effect.Appear(document.getElementById('search_all_systems_result'));
document.getElementById('search_all_systems_result').style.display = 'block';
showSystemSearchResults(str, count);
}
 function hideBrandResults()
 {
   //Effect.Fade(document.getElementById('search_all_systems_result'));
   document.getElementById('search_all_systems_result').style.display = 'none';
 }


 function hideSystemResults()
 {
   //Effect.Fade(document.getElementById('search_all_brands_result'));
   document.getElementById('search_all_brands_result').style.display = 'none';
 }
function stateChangeShowBrandSearchResults() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("search_all_brands_result").innerHTML=xmlHttp.responseText
    }
}

function getDetails(){
mousex=event.clientX+document.body.scrollLeft;
alert(mousex);
}

function clearBrandSearchResults() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("brand_search_results").innerHTML=''
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        //Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function toggleElem(elementName, elementNumber, numberElements)
{
    activeElem = $(elementName + elementNumber);
    activeElem.setAttribute("class", "active");
    activeElem.className = "active";

    for(i = 1; i < numberElements +1; i++)
    {
        if(i != elementNumber)
        {
            currElem = $(elementName + i);
            currElem.setAttribute("class", "inactive");
            currElem.className = "inactive";
        }
    }

}

function toggleImage(elementName, elementNumber, numberElements)
{
    for(i = 1; i < numberElements + 1; i++)
    {
        if(i != elementNumber)
        {
            currElem = $(elementName + i);
            currElem.style.display = "none";
        }
    }
    activeElem = $(elementName + elementNumber);
    $(activeElem).style.display = "block";

}

function toggleAbout(elementName, elementNumber)
{
    for(i = 1; i < 5; i++)
    {
        currElem = $(elementName + i);
        currElem.style.display = "none";
    }
    activeElem = $(elementName + elementNumber);
    //activeElem = $('about2')[0];
    Effect.Appear(activeElem);
    activeElementNumber = elementNumber;
}
function displayCompaniesHome()
{

        //document.getElementById("flashcontent").style.display = "none";
        //document.getElementById("terrain_flash_holding").style.display = "block";
        
        element = document.getElementById('search_all');
        selectCompany = document.getElementById('select_company');
        Effect.Appear(element);
        

}
function displayCompanies()
{
        element = document.getElementById('search_all');
        selectCompany = document.getElementById('select_company');
        
        Effect.toggle(element);
}

  function hideSearchAllHome()
 {
   Effect.Fade(document.getElementById('search_all'));
   //document.getElementById("terrain_flash_holding").style.display = "none";
   //document.getElementById("flashcontent").style.display = "block";

 }

  function hideSearchAll()
 {
   Effect.Fade(document.getElementById('search_all'));
   if(null != document.getElementById("terrain_flash_holding"))
   {
       document.getElementById("terrain_flash_holding").style.display = "none";
       document.getElementById("terrain_flash_section").style.display = "block";
      
   }

 }

var activeElementNumber = 1;
function switchAbout()
{
    for(i = 1; i < 5; i++)
    {
        currElem = $("about" + i);

        currElem.style.display = "none"

    }
    if(activeElementNumber == 4)
        activeElementNumber = 1

    else
        activeElementNumber = activeElementNumber + 1


    elementId = "about" + activeElementNumber;
    elementToActivate = $(elementId);
    Effect.Appear(elementToActivate);


}

var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 25
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false


}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        switchAbout();
        InitializeTimer()
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

