function HelperShowHide(id)
{
    helper = jQuery('#'+id);
    helper_ico = jQuery('#img_' + id);

    if (!jQuery(helper).is(':visible'))
    {
        jQuery(helper).css('width', '100%');
        jQuery(helper).show();
        jQuery(helper).css('position', 'relative');
        jQuery(helper_ico).attr('src', '/img/help_small_open.gif');
    }
    else
    {
        jQuery(helper).hide();
        jQuery(helper_ico).attr('src', '/img/help_small.gif');
    }
}

function ErrorShowHide(id)
{
    helper = jQuery('#'+id);

    if (!jQuery(helper).is(':visible'))
    {
        jQuery(helper).css('width', '100%');
        jQuery(helper).show();
        jQuery(helper).css('position', 'relative');
    }
    else
    {
        jQuery(helper).hide();
    }
}

function AddSubmit(name, id)
{
    jQuery('#'+id).append('<input name="'+name+'" type="hidden"/>');
}


function DisableSubmits()
{
    jQuery('[name="input"]').attr("disabled","disabled");
}

function ShowSectionFromUrl(id)
{
    jQuery('#section_selector_type').each(function()
    {
        if(jQuery(this).val() == id)
        {
            jQuery(this).attr('selected', 'selected');
        }
    });
    
    // check ShowSection function below
    HideAllSections();
    jQuery('#section_' + id).css('display', 'block');
}

function ShowSection(id)
{
    HideAllSections();
    jQuery('#section_' + id).css('display', 'block');
}

function ShowSectionFromPulldown(id, id_pulldown)
{
        HideAllSections();

        var selected = jQuery("select option:selected").val();

	jQuery('#section_'+selected).show();
	jQuery('#attach_files').show();
}

function HideAllSections()
{
    for (i = 0; i < selection_array.length; i++)
    {
        jQuery('#'+selection_array[i]).hide();
    }
}

function PutSignature()
{
    var selected = jQuery("select[id='SendMessage[signature_list]'] option:selected").val();
    var val_signature = ss[selected];

    jQuery("textarea[id='SendMessage[signature]']").val(val_signature);
}

function PutSignatureCreateTicket()
{
    var selected = jQuery("select[id='CreateTicket[signature_list]'] option:selected").val();
    var val_signature = ss[selected];

    jQuery("textarea[id='CreateTicket[signature]']").val(val_signature);
}

function PutSignatureForwardMessage()
{
    var selected = jQuery("select[id='ForwardMessage[signature_list]'] option:selected").val();
    var val_signature = ss[selected];

    jQuery("textarea[id='ForwardMessage[signature]']").val(val_signature);
}

function CheckMailDomain(id)
{
    var email = document.getElementsByName(id.id+'[email]')[0].value;
    var filter_domain = /^^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+)\.[a-zA-Z0-9.-]+$/;
    var spec_domain = /^(msn|yahoo|hotmail|aol)$/;
    var domain = email.match(filter_domain);
    var product_tmp = location.hostname.match('([a-z]+)');
    var product = 'this product';

    if(product_tmp)
    {
            product = product_tmp[1];
    }

    if (domain && domain[1].search(spec_domain) != -1)
    {
            var content = 'To ensure your important questions are answered in a timely manner, and there is no chance of interruption, we recommend that you submit using an email account from an ESP other than Hotmail, Yahoo, Msn or Aol services due to their aggressive filtering.\nIf you decide to send your question using an email account from one of those ESPs and you have not received a reply within 24 hours, check your spam / junkmail folder and be sure that Implix.com and '+product+' are whitelisted.\n\nIf you still want to send your question using your email '+ email +' press OK.\n ';
            return confirm(content);
    }
    return;
}

var selection_array = new Array();
var section_to_show = false;

function ToggleSection(pId)
{
    jQuery('#'+pId).toggle();

    if(jQuery('#'+pId).is(':visible'))
    {
        jQuery('#toggle_section_' + pId).attr('src', 'img/section_up.gif').attr('title', 'click to show section');
    }
    else
    {
        jQuery('#toggle_section_' + pId).attr('src', 'img/section_down.gif').attr('title', 'click to hide section');
    }
}

/*
 * Used by spellchecker for simple input type=text fields
 */
function openSpellChecker(ElementId)
{
    oTB = jQuery('[id ="'+ElementId+'"]')[0];
    lang = jQuery('#spell_language').val();
    var speller = new spellChecker( oTB , lang);
    speller.openChecker();

    return false;
}

function ClearValue(ElementId)
{
    jQuery('#'+ElementId).val('');
}

/*
 * Used to clear input type file
 * with hack for opera, ie etc
 */
function ClearInputFile(ElementId)
{
    var name = jQuery('#'+ElementId).attr('name');
    var size = jQuery('#'+ElementId).attr('size');
    var target = jQuery('#'+ElementId).parent();
    
    if ( $.browser.msie ) {
        jQuery('#'+ElementId).val('Clear');
    }

    jQuery('#'+ElementId).remove();
    var hrev = jQuery(target).html();
    jQuery(target).children().remove();
    var input_text = '<input id="'+ElementId+'" name="'+name+'" type="file" value="" maxlength="" class="FormInputBox" size="'+size+'"/>';
    jQuery(target).prepend(input_text+hrev);
    jQuery(target).find('input').attr('style', 'margin: 0px;');
    jQuery(target).find('img').attr('style', 'margin-left: -5px; margin-bottom: -5px; border: 0px');
}
