// (C) 2008 HeatSeek.com  All Rights Reserved
// Various utility functions

// Open a new window to download the given link:
function srsDownloadNewWin(link)
{
	window.open(link, 'download_window', 'toolbar=0,location=no,directories=0,status=0,scrollbars=0,resizeable=0,width=1,height=1,top=0,left=0');
	window.focus();
	
} // srsDownloadNewWin

// Open new window for a screenshot image:
function srsPopScreenshotWindow(imageURL)
{
    window.open(imageURL, "Screenshot", "resizable=yes,status=no,width=900,height=600,dependent=yes");
    return false;
} // srsPopScreenshotWindow

// Check a form radio button:
function srsCheckRadio( theForm, radioName, radioIndex )
{
    theForm[radioName][radioIndex].checked = true;
}

// Validate support request form submission
function srsValidateSupportForm( theForm )
{
	var reason = "";
	if ( theForm.os.value.length == 0 )
		reason += "Operating System is empty. ";
		
	if ( theForm.desc.value.length == 0 )
		reason += "Support request is empty. ";
		
	if ( reason.length > 0 )
		alert(reason);
		
	return reason.length == 0;

} // srsValidateSupportForm

// Validate download form submission:
function srsDoDownloadForm( dlForm, checkAge )
{
    var reason = "";
    if ( checkAge && (dlForm.agreement.checked != true) )
        reason += "- Box 1 Not Checked -\r\nYou must be an adult to download HeatSeek.";
    	
    if ( reason.length > 0 )
        alert(reason);
    else if (navigator.appVersion.indexOf('MSIE') != -1) // valid form submit and using IE
    {
        if ( dlForm['hslang'] )
            srsDownloadNewWin('/dlredir.php?lang=' + dlForm['hslang'][dlForm['hslang'].selectedIndex].value);
        else
            srsDownloadNewWin('/dlredir.php');
    }
    	
    return reason.length == 0;

} // srsValidateDownloadForm

// Translate current page to this new target language:
function srsSwitchLanguage( langForm )
{
    var sourceURL = langForm.u.value;
    var langSelection = langForm.langChoice;
    var targetLang = langSelection.options[langSelection.selectedIndex].value;

    // If destination is English, just navigate to original source page:
    if ( targetLang == "en" )
        window.location = sourceURL;
    else
    {
        // Build translation URL:
        var destURL = "http://www.google.com/translate_c?u=" + sourceURL + "&hl=en&ie=UTF8&langpair=en|" + targetLang;
        window.location = destURL;
    }

} // srsSwitchLanguage

function srsSwitchToTab( tabName )
{
    // The possible tabs buttons we have:
	var tabButtons = new Array(
		'tab_news',
		'tab_sponsors',
		'tab_contact',
		'tab_about',
		'tab_demo',
		'tab_private',
		'tab_download',
		'tab_burndvd',
		'tab_view'
	); // tabButtons

    var tabContentBoxSuffix = "-box"; // ASSUME: tab content box has an id which is: tabname + <suffix>

    // To switch to a tab, we have to de-activate other tabs,
    // then activate the given tab.
    var targetTab = document.getElementById( tabName );
    var targetContentBox = document.getElementById( tabName + tabContentBoxSuffix );
    if ( targetTab && targetContentBox )
    {
        // Deactivate other tabs:
        for ( var i=0; i < tabButtons.length; ++i )
        {
            if ( tabButtons[i] != tabName ) // is this a different tab?
            {
                var otherTabButton = document.getElementById( tabButtons[i] );
                var otherTabContentBox = document.getElementById( tabButtons[i] + tabContentBoxSuffix );
                if ( otherTabButton )
                    otherTabButton.className = '';
                if ( otherTabContentBox )
                    otherTabContentBox.style.display = 'none';
            } // if closing another tab
        } // loop to deactivate tabs
        
        // Now activate the new tab:
        targetContentBox.style.display = 'block';
        targetTab.className = 'active';
        
    } // if targetTab

    return false; // do not handle the click loading

} // srsSwitchToTab

function srsToggleFAQSection( sectionAnchor )
{
    // WARNING: This function relies on the HTML structure remaining somewhat consistent!
    
    // Make sure we have proper parent nodes, which are *assumed* to be the faq section:
    if ( sectionAnchor.parentNode && sectionAnchor.parentNode.parentNode )
    {
        var faqSection = sectionAnchor.parentNode.parentNode;
        if ( faqSection.className == "active" )
            faqSection.className = "";
        else
	        faqSection.className="active";
	} // if parents exist
	
	return false; // prevent click from occuring
	
} // srsToggleFAQSection

function srsToggleFAQQuestion( questionAnchor )
{
    // WARNING: This function relies on the HTML structure remaining somewhat consistent!
    
    // Make sure we have proper parent nodes, which are *assumed* to be the faq section:
    if ( questionAnchor.parentNode )
    {
        if ( questionAnchor.parentNode.className == "active" )
            questionAnchor.parentNode.className = "";
        else
	        questionAnchor.parentNode.className="active";
	} // if parent exists
	
	return false; // prevent click from occuring
	
} // srsToggleFAQQuestion
