var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

if (document.getElementById)
{
	document.write('<style type="text/css">')
	document.write('.switchcontent{display:none;}')
	document.write('</style>')
}

function getElementbyClass(classname)
{
	ccollect=new Array()
	var inc=0
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].className==classname)
		ccollect[inc++]=alltags[i]
	}
}

function contractcontent(omit)
{
	var inc=0
	while (ccollect[inc])
	{
		if (ccollect[inc].id!=omit)
		ccollect[inc].style.display="none"
		inc++
	}
}

function expandcontent(cid)
{
	if (typeof ccollect!="undefined")
	{
		if (collapseprevious=="yes")
		contractcontent(cid)
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
		return false;
	}
}

function revivecontent()
{
	contractcontent("omitnothing")
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
	document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) 
{ 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
	offset = document.cookie.indexOf(search)
	if (offset != -1) 
	{ 
		offset += search.length
		end = document.cookie.indexOf(";", offset);
		if (end == -1) end = document.cookie.length;
		returnvalue=unescape(document.cookie.substring(offset, end))
	}
}
return returnvalue;
}

function getselectedItem()
{
	if (get_cookie(window.location.pathname) != "")
	{
		selectedItem=get_cookie(window.location.pathname)
		return selectedItem
	}
	else
		return ""
}

function saveswitchstate()
{
	var inc=0, selectedItem=""
	while (ccollect[inc])
	{
		if (ccollect[inc].style.display=="block")
		selectedItem+=ccollect[inc].id+"|"
		inc++
	}
	document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload()
{
	uniqueidn=window.location.pathname+"firsttimeload"
	getElementbyClass("switchcontent")
	if (enablepersist=="on" && typeof ccollect!="undefined")
	{
		document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
		firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
	if (!firsttimeload)
		revivecontent()
	}
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
	window.onunload=saveswitchstate

function OpenDemoRoom(lang)
{
	if (pageTracker)
	{
		// In case Google Analytics doesn't properly support Events, add a pageview.
		pageTracker._trackPageview("demo_room/"+lang+".html");
		pageTracker._trackEvent("DEMO REQUEST", "User clicks on demo button");
	}
	var theURL = "https://secure.3gsp.eu/conference/MeetingPro.php?mid=0&language="+lang;
	var win = window.open( theURL, "dcc", "fullscreen=yes,resizable=yes" );
	if (win == null)
	{		
		// popup blocker; open in this window
		top.location = theURL;
	}
}

//calculator.html
function changeNumParticipants()
{
	var numEl = document.getElementById('numParticipants');
	var num = numEl.value;
	for (i=1; i <= 6; i++)
	{
		var country = document.getElementById('office'+i);
		if (num > 0)
		{
			country.style.visibility = '';
		}
		else
		{
			country.style.visibility = 'hidden';
		}
		var partnum = document.getElementById('num'+i);
		num -= partnum.value;
	}
}

function Calculator()
{
	var el = document.getElementById( 'mainCountry' );
	var why = "";
	if (el.value == '-1')
	{
		why+= calculator_select_country;
	}
	var numEl = document.getElementById('numParticipants');
	var num = numEl.value;
	var travelers = false;
	for (i=1; i <= 6; i++)
	{
		var country = document.getElementById('country'+i);
		if (country.value != -1)
		{
			travelers = true;
			break;
		}
		var partnum = document.getElementById('num'+i);
		num -= partnum.value;
		if (num <= 0)
		{
			break;
		}
	}
	if (why != "")
	{
		alert( why );
		return false;
	}
	if (!travelers)
	{
		return confirm( calculator_confirm_travel );
	}
	return true;	
}

function Calculator3()
{
	var why = "";
	var el = document.getElementById( 'duration' );
	if (isNaN(parseInt(el.value)) || parseInt(el.value) == 0)
	{
		why+= calculator3_meeting_duration;
	}
	var el2 = document.getElementById( 'numMeetings' );
	if (isNaN(parseFloat(el2.value)) || parseFloat(el2.value) == 0)
	{
		why+= calculator3_meetings_number;
	}
	if (why != "")
	{
		alert( why );
		return false;
	}
	return true;	
}

function Newsletter()
{
	if ( document.newsletter.email.value == "")
	{
		alert(index_enter_email);
		document.newsletter.focus();
		return false;
	}
	else
	{
		return emailCheck(document.newsletter.email.value);
		document.newsletter.email.focus();
		return false;
	}
	return true;	
}

function Inquiry()
{
	var why = "";
	var firstName = document.getElementById( 'firstName' );
	if (firstName.value == "")
	{
		why+= inquiry_first_name;
	}
	var lastName = document.getElementById( 'lastName' );
	if (lastName.value == "")
	{
		why+= inquiry_last_name;
	}
	var country = document.getElementById( 'country' );
	if (country != null && country.value == -1)
	{
		why+= inquiry_country;
	}
	var email = document.getElementById( 'email' );
	if (email != null)
	{
		var emailStr = email.value;
		var domainPos = emailStr.indexOf( '@' );
		if (domainPos == -1)
		{
			why+= inquiry_email;
		}
		else
		{
			var domain = emailStr.substring( domainPos );
			var topDomainPos = domain.indexOf( '.' );
			if (topDomainPos == -1)
			{
				why+= inquiry_email;
			}
		}
	}
	if (why != "")
	{
		alert( why );
		return false;
	}
	return true;	
}

function validateForm(form)
{
	switch (form)
	{
		case "calculator": 
			return Calculator();
		case "calculator3": 
			return Calculator3();
		case "newsletter":
			return Newsletter();
		case "inquiry":
			return Inquiry();
	}
}


