function HelperShowHide(id)
{
	helper = document.getElementById(id);
	helper_ico = document.getElementById('img_' + id);

	if (helper.style.display == 'none')
	{
		helper.style.width = '100%';
		helper.style.display = '';
		helper.style.position = 'relative';
		helper_ico.src = '/img/help_small_open.gif';
	}
	else
	{
		helper.style.display = 'none';
		helper_ico.src = '/img/help_small.gif';
	}
}

function ErrorShowHide(id)
{
	helper = document.getElementById(id);

	if (helper.style.display == 'none')
	{
		helper.style.width = '100%';
		helper.style.display = '';
		helper.style.position = 'relative';
	}
	else
	{
		helper.style.display = 'none';
	}
}

function AddSubmit(name, id)
{
	el = document.createElement("input");
	el.setAttribute("type", "hidden");
	el.setAttribute("name", name);

	frm = document.getElementById(id);
	frm.appendChild(el);
}


function DisableSubmits()
{
	var btn = document.body.getElementsByTagName("input");

	for(i = 0; i < btn.length; i++)
	{
		att = btn[i].attributes;
		type = att.getNamedItem("type");

		if (type.nodeValue == "submit")
		{
			btn[i].setAttribute("disabled", "yes");
		}

	}

}

function ShowSectionFromUrl(id)
{

    // get element by id
    var pulldown = document.getElementById('section_selector_type');
   
    // check all options
	for(i=0; i<pulldown.options.length; i++)
	{
	   if(pulldown.options[i].value == id)
	   {
        	// set selected element      
            pulldown.options[i].selected = true
	   }
	}
    
    // check ShowSection function below
	HideAllSections();
	var section = document.getElementById("section_" + id);

	if(section != null)
	{
		
		section.style.display = "block";
	
		if (!document.all)
		{
			section.style.display = "table-row";
		}
	}
}

function ShowSection(id)
{

	HideAllSections();
	var section = document.getElementById("section_" + id);
	section.style.display = "block";

	if (!document.all)
	{
		section.style.display = "table-row";
	}
}

function ShowSectionFromPulldown(id, id_pulldown)
{
	HideAllSections();
	var pulldown = document.getElementById(id_pulldown);
	var section = document.getElementById("section_" + pulldown.options[pulldown.selectedIndex].value);
	
	section.style.display = "block";

	if (!document.all)
	{
		section.style.display = "table-row";
	}

	// show attach_files div
	element_files = document.getElementById('attach_files');
	
	if(element_files && (element_files.style.display == 'none'))
	{
		  element_files.style.display = '';
    }
	
}

function HideAllSections()
{
	for (i = 0; i < selection_array.length; i++)
	{
		tmp = document.getElementById(selection_array[i]);
		tmp.style.display = "none";
	}
}

function PutSignature()
{
	tmp = document.getElementById('SendMessage[signature_list]');
	sig = ss[tmp.options[tmp.selectedIndex].value];

	document.getElementById('SendMessage[signature]').value = sig;
}

function PutSignatureCreateTicket()
{
	tmp = document.getElementById('CreateTicket[signature_list]');
	sig = ss[tmp.options[tmp.selectedIndex].value];

	document.getElementById('CreateTicket[signature]').value = sig;
}

function PutSignatureForwardMessage()
{
	tmp = document.getElementById('ForwardMessage[signature_list]');
	sig = ss[tmp.options[tmp.selectedIndex].value];

	document.getElementById('ForwardMessage[signature]').value = sig;
}

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)
{
	var e = document.getElementById(pId);
	var p = document.getElementById('toggle_section_' + pId);

	if (null != e && null != p)
	{
		if ('none' == e.style.display)
		{
			e.style.display = '';
			p.src = 'img/section_up.gif';
			p.title = 'click to hide section';
		}
		else
		{
			e.style.display = 'none';
			p.src = 'img/section_down.gif';
			p.title = 'click to show section';
		}
	}
}

/*
 * Used by spellchecker for simple input type=text fields
 */
function openSpellChecker(ElementId)
{
	oTB = document.getElementsByName(ElementId)[0];
	lang = document.getElementById('spell_language').value;

	var speller = new spellChecker( oTB , lang);
	speller.openChecker();

	return false;
}
