﻿//Toggles between ENG and SR
function SwitchLang()
{
	//alert("Serbian translation coming soon. Cekaj molim te\n;-) [Jared typed this]");
	//return;
	
	if(document.location.toString().toLowerCase().indexOf('/sr/') > 0)
	{
		document.location = document.location.toString().toLowerCase().replace('/sr','');
	}
	else
	{
		document.location = '/sr' + document.location.pathname;
	}
}


//Shows either Silverlight or Flash depending on what's installed. Prefers Silverlight b/c that's cooler.
function DoVideoSwap()
{	
	var url = document.location.href;
	if(url && url.toLowerCase().indexOf("forceflash=true") > 0)
		return; //so I can test it and make sure it works for the poor suckers w/o Silverlight

	var player = new StartPlayer_0();
	var player = new StartPlayer_1();
		
	if(Silverlight.available)
	{
		document.all.FlashVideo_0.style.display = "none";
		document.all.FlashVideo_1.style.display = "none";	
		document.all.divPlayer_0.style.display = "block";
		document.all.divPlayer_1.style.display = "block";
	}
}


//Validates and allows user to check comment before submitting
function SubmitComment()
{
	var firstname = trim(document.forms[0].firstname.value);
	var lastname = trim(document.forms[0].lastname.value);
	var city = trim(document.forms[0].city.value);
	var	comment = trim(document.forms[0].comment.value);
	var sig = trim(document.forms[0].sig.value);
	
	if(firstname=='' || lastname=='' || city=='' || comment=='' || sig=='')
	{
		alert('Please fill out all the fields');
		return;
	}
	
	var msg = 'Would you like to submit the following comment?\n\n' + comment + '\n   - ' + sig;
	if (confirm(msg))
	{
		document.forms[0].submit();
	}
	
}


//Helper functions
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}