// +-------------------------------------------------------------------------------------------------------+
// | viscon() - Visibility Controller                                                                      |
// | This function is used to toggle visibility of individual sections that use the 'vistoggle' CSS class. |
// |                                                                                                       |
// | Parameters:                                                                                           |
// | e - The element that called the function (should always be the 'this' keyword).                       |
// | targetid - The 'id' of the element you wish to toggle (must be an element of class 'vistoggle').      |
// +-------------------------------------------------------------------------------------------------------+
function viscon(e, targetid)
{
	var ve = document.getElementById(targetid);
	
	if(ve.style.display == 'block')
	{
		e.className = 'oexpand';
		ve.style.display = 'none';
	}
	else
	{
		e.className = 'ocollapse';
		ve.style.display = 'block';
	}
}

// +---------------------------------------------------------------------------------+
// | mofx() - Mouse Over FX with CSS                                                 |
// | This function provides mouse over effect for any element.                       |
// |                                                                                 |
// | Parameters:                                                                     |
// | e - The element that called the function (should always be the 'this' keyword). |
// | msg - A string of text to display in the browsers status bar.                   |
// |                                                                                 |
// | Usage Notes:                                                                    |
// | The calling element should have two class definitions in the stylesheet.        |
// | One should be prefixed with 'n', this is the normal style.  The other prefixed  |
// | with 'o', the style to be applied when the mouse is over the element.           |
// +---------------------------------------------------------------------------------+
function mofx(e, msg)
{
	var c		= e.className;
	var item	= c.substring(1, c.length);
	
	c.charAt(0) == 'n' ? c = 'o' : c ='n';
	e.className = c + item;
	window.status = msg;
}

// +---------------------------------------------------------------------------------+
// | moexp() - Status text preparation                                               |
// | This function provides the correct status text for expand/collapse buttons.     |
// |                                                                                 |
// | Parameters:                                                                     |
// | e - The element that called the function (should always be the 'this' keyword). |			
// +---------------------------------------------------------------------------------+
function moexp(e)
{
	var msg;
	var c = e.className;
	
	c.substring(1, c.length) == 'expand' ? msg = 'Expand Section' : msg = 'Collapse Section';				
	mofx(e, msg);
}

// +------------------------------------------------+
// | dload() - Handles document downloads	    |
// |                                                |
// | Parameters:                                    |
// | fid - The document's id field in the database. |
// +------------------------------------------------+
function dload(d, wo)
{
	document.location.href = "?wx=" + wo + "&dx=" + d;
}

// +---------------------------------------------------------------+
// | validate() - Validates the form ensuring all data is correct. |
// |                                                               |
// | Parameters:                                                   |
// | f - A reference to the form to be validated.		   |
// +---------------------------------------------------------------+
function validate(f)
{
	with(f)
	{
		if(fcompany != 'pcltest' && fcontact != 'pcltest' && femail != 'pcltest' && fmedia.value != '5')
		{
			if(fcompany != '' && fcontact != '' && femail != '' && fmedia.value != '0')
			{
				with(femail)
				{
					var apos = value.indexOf('@');
					var dpos = value.lastIndexOf('.');
					
					if(!(apos < 1 || dpos - apos < 2))
					{
						fskip.value = 'false';						
						submit();
						return;
					}
				}
			}
		}
		else
		{
			fskip.value = 'true';
			submit();
			return;
		}
	}
	
	alert("Validation Failed: Please ensure you filled out all of the fields below:\nCompany Name\nContact Name\nEmail Address\nMedia Source");
}

function validatefeedback(f)
{
	with(f)
	{
		if(fcompany != '' && fcontact != '' && femail != '')
		{
			with(femail)
			{
				var apos = value.indexOf('@');
				var dpos = value.lastIndexOf('.');
					
				if(!(apos < 1 || dpos - apos < 2))
				{					
					submit();
					return;
				}
			}
		}
	}
	
	alert("Validation Failed: Please ensure you filled out all of the fields below:\nCompany Name\nContact Name\nEmail Address\n");
}
