﻿// display appropriate buttons on splash page based on which country the user selects from dropdown menu
//search for 'http://stage.' in url
if	(location.hostname.search(/(stage\.sunpowercorp\.)/) >= 0)
	{
		prefix = "http://stage.sunpowercorp.";
		altPrefix = "http://stage.sunpowercorp.";
	}
else
	{
		prefix = "http://www.sunpowercorp.";
	}

function countrySelector(countryList) 
	{
		var countryID = countryList.options[countryList.selectedIndex].value;
		if((countryID == "usa") || (countryID == "ita") || (countryID == "aus") || (countryID == "deu") || (countryID == "esp") || (countryID == "fra") /*|| (countryID == 'jap')*/ ) 
		{ // show segment menu
			document.getElementById("segment_menu").style.display = 'block';
			document.getElementById("segment_menu").style.visibility = 'visible';
			document.getElementById("country_submit").style.display = 'none';
			document.getElementById("country_submit").style.visibility = 'hidden';
		} 
		else 
		{ // show submit button
			document.getElementById("country_submit").style.display = 'block';
			document.getElementById("country_submit").style.visibility = 'visible';
			document.getElementById("segment_menu").style.display = 'none';
			document.getElementById("segment_menu").style.visibility = 'hidden';
		}
		changeUrl();
		changeSegmentUrl();
	}

function getPrefix()
	{
		var countryList = document.getElementById("countryList");
		var countryID = countryList.options[countryList.selectedIndex].value;
		if(countryID == "can") 
		{
			return prefix + "com";
		} 
		else if(countryID == "aus") 
		{
			return prefix + "com.au";
		} 
		else if(countryID == "deu") 
		{
			return prefix + "de";
		} 
		else if(countryID == "fra") 
		{
			return prefix + "fr";
		} 
		else if(countryID == "ita") 
		{
			return prefix + "it";
		} 
		else if(countryID == "kor") 
		{
			return prefix + "kr/main";
		} 
		else if(countryID == "jap") 
		{
			return prefix + "jp/main";
		} 
		else if(countryID == "esp") 
		{
			return prefix + "es";
		}
		else if(countryID == "usa") 
		{
			return prefix + "com";
		}
		/* else if(countryID == "jap") {
			return prefix + "jp";
		}*/
	}

function changeUrl() 
	{
		document.getElementById("submit_btn").href = getPrefix();
	}

function changeSegmentUrl()
	{
		var segmentLinks = document.getElementById("segment_menu").getElementsByTagName('a');
		segmentLinks[0].href = getPrefix() + '/residential';
		segmentLinks[1].href = getPrefix() + '/business';
		segmentLinks[2].href = getPrefix() + '/utility';
	}
