/* these scripts are not required by TinySite.XML, they are used in custom functions inside the pages */

// toggle element
function toggleElement(elementId, toggleProperty, toggleFactor) 
{
	elementId = document.getElementById(elementId);
	try
	{
		if(toggleProperty == 'display')
		{
			elementId.style.display = (elementId.style.display == toggleFactor ) ? "" : toggleFactor;
		}
		if(toggleProperty == 'visibility')
		{
			elementId.style.visibility = (elementId.style.visibility == toggleFactor ) ? "" : toggleFactor;
		}
		else if(toggleProperty != 'display' && toggleProperty != 'visibility')
		{
			alert('Invalid toggleProperty value (' + toggleProperty + '). Choose either "display" or "visibility".');
			return false;
		}
	}
	catch(e)
	{
		alert('Invalid toggleFactor value. It should be "block", "none", "visible" or "hidden".');
	}
}

function loadContactFormControls()
{
	checkBoxXmlRootFoder = 'Scripts';
	renderCheckBoxList('ContactFormOptions.xml', 'site_options');
}

function yourInstrument()
{
	checkBoxXmlRootFoder = 'Scripts';
	renderCheckBoxList('VacantPositions.xml', 'YourInstrumentLoader');
}

function vote()
{
	$('VotingPollForm').submit();
}

function sendThisEmailTo()
{
	radioButtonXmlScriptsFolder = 'Scripts';
	renderRadioButtonList('Scripts/RadioButton.XML/RadioButtonLists/SendThisEmailTo.xml', 'SendThisMailTo');
}

function validateContactForm()
{
	var title = 'Acid Machine Official Website';
	var tagline = 'Error';
	var cannotSend = 'Cannot send the contact form!<br /><br />';
	if($('customer_name').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + 'The "name" field cannot not be empty.', '', '');
		return false;
	}
	if($('customer_email').value == '' || $('customer_email').value.indexOf('@') < 0 || $('customer_email').value.indexOf('.') < 0)
	{
		openMessageBox('alert', title, tagline, cannotSend + 'The data in the "email" field is invalid.', '', '');
		return false;
	}
	if($('notes').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + 'You have to type a comment before sending it.', '', '');
		return false;
	}
	else
	{
		$('ContactForm').submit();
	}
}

function validatePlayWithUsForm()
{
	var title = 'Acid Machine Official Website';
	var tagline = 'Error';
	var cannotSend = 'Cannot send the contact form!<br /><br />';
	if($('customer_name').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + 'The "name" field cannot not be empty.', '', '');
		return false;
	}
	if($('customer_email').value == '' || $('customer_email').value.indexOf('@') < 0 || $('customer_email').value.indexOf('.') < 0)
	{
		openMessageBox('alert', title, tagline, cannotSend + 'The data in the "email" field is invalid.', '', '');
		return false;
	}
	if($('notes').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + 'You have to type something about yourself before sending the application form.', '', '');
		return false;
	}
	else
	{
		$('PlayWithUsForm').submit();
	}
}

function initTabStrips()
{
	TabStripScriptsFolder = 'Scripts';
}

function initBandLineUpTabStrip()
{
	createTabStrip('Scripts/Tabstrip.XML/TabSets/BandLineUp.xml', 'LineUpLoader');
}

function initMediaAndDownloadsTabStrip()
{
	createTabStrip('Scripts/Tabstrip.XML/TabSets/MediaAndDownloads.xml', 'MediaAndDownloads');
}

function initLogoContestTabStrip()
{
	$('BandLogoContestLoader').innerHTML = '';
	createTabStrip('Scripts/Tabstrip.XML/TabSets/BandLogoContest.xml', 'BandLogoContestLoader');
}

function initBandGallery(GalleryId)
{
	$('AcidMachineGallery').innerHTML = '';
	albumLoaderId = 'AcidMachineGallery';
	albumFeedFile = 'Images/Gallery/' + GalleryId + '/Album.xml';
	scriptsDirectory = 'Scripts/';
	createAlbum();
	$('GallerySelector').options.selectedIndex = GalleryId;
}

function initSubmitSiteUpload()
{
	uploadXmlScriptsRoot = 'Scripts';
	parseUploadXmlFeedFile('Scripts/Upload.XML/UploadLists/SubmitSite.xml', 'ChooseBannerLoader');
	$('submitSite').style.display = 'none';
}

function initSubmitLogoUpload()
{
	uploadXmlScriptsRoot = 'Scripts';
	if($('ChooseLogoLoader').innerHTML == '')
	{
		parseUploadXmlFeedFile('Scripts/Upload.XML/UploadLists/SubmitLogo.xml', 'ChooseLogoLoader');
	}
}

function validateSubmitLogoForm()
{
	$('LogoSubmissionForm').submit();
}

function setContactFormAction(ActionFile)
{
	$('ContactForm').setAttribute('action', 'Cgi-Bin/' + ActionFile);
}

function openVideoPopUp(VideoURL)
{
	window.open('Scripts/Tabstrip.XML/TabSets/Videos/' + VideoURL, 'videos', 'width=425, height=349, top=' + document.documentElement.offsetHeight/2 + ', left=' + document.documentElement.offsetWidth/2 + ', statusbar=0, resizable=0');
}

function validateSubmitSiteForm()
{
	var title = 'Acid Machine Official Website';
	var tagline = 'Error';
	var cannotSend = 'Cannot submit your site!<br /><br />';
	if($('url_submitter_name').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + '"Your Name" field should not be empty.', '', '');
		return false;
	}
	if($('url_submitter_email').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + '"Your Email" field should not be empty.', '', '');
		return false;
	}
	if($('url_submitter_email').value == '' || $('url_submitter_email').value.indexOf('@') < 0 || $('url_submitter_email').value.indexOf('.') < 0)
	{
		openMessageBox('alert', title, tagline, cannotSend + 'The data in the "Your Email" field is invalid.', '', '');
		return false;
	}
	if($('url_submitter_site').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + '"Site URL" field should not be empty.', '', '');
		return false;
	}
	if($('link_description').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + '"Link Description" field should not be empty.', '', '');
		return false;
	}
	if($('ChooseBannerLoader_UploadXml_list_Item_0_realFileUpload').value == '')
	{
		openMessageBox('alert', title, tagline, cannotSend + 'Choose image file for your banner. Only .png, .gif or .jpg files are allowed.', '', '');
		return false;
	}
	else
	{
		$('SubmitSiteForm').submit();
	}
}

function pageLoad()
{
	
}

if(window.attachEvent)
{
	window.attachEvent('onload', function(e)
		{
			//pageLoad();
		}
	);
}
else
{
	window.addEventListener('load', function(e)
		{
			//pageLoad();		
		}, true	
	);
}

function initCheckBoxXml()
{
	
}

function openExternalURL(URL)
{
	window.open(URL, '_blank', '');
}

function specifyElse()
{
	$('PromptInput').unselectable = false;
	openMessageBox('prompt', 'Acid Machine Voting Poll', 'Guitars', 'Tell us which is the best guitar brand:', 'submitCustomVote()', '');
}

function submitCustomVote()
{
	$('VotingPollLoader_List_Item10_input').value = $('PromptInput').value;
	vote();
}