// JavaScript Document

function setCookie(name, value, expiresDays, path, domain, secure)
{
	var today = new Date();
	today.setTime(today.getTime());
	
	if (expiresDays)
		expiresDays = expiresDays * 1000 * 60 * 60 * 24;
	
	var expires_date = new Date(today.getTime() + (expiresDays));
	var cookieStr = name + '=' + escape(value) +
		(expiresDays ? ";expires=" + expires_date.toGMTString() : "") +
		(path ? ";path=" + path : "") +
		(domain ? ";domain=" + domain : "") +
		(secure ? ";secure" : "");
	document.cookie = cookieStr;
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	
function divDisplay(tDiv){
	var tDivDisplay = document.getElementById(tDiv).style.display
	if(tDivDisplay == 'block'){document.getElementById(tDiv).style.display = 'none'}
	else {document.getElementById(tDiv).style.display = 'block'}
}

function launchQuickstart(){ return false; }
/*
function launchQuickstart(){
	cookie=getCookie("SITESEERQUICKSTARTVIEWED");
	if (!cookie || (cookie == 0)) {
		height = screen.availHeight;
		width = screen.availWidth / 2;
		left = screen.availWidth - width;
		w=window.open('quickStart.cfm','qswindow','height=' + height + ',width='+ width + ',top=5,left=' + left + ',scrollbars=yes,resizable=yes');
		if (w && w.open) w.moveTo(5,left);
	}
}
*/

function goPlugin(urlSearch,vBaseFly){
	if (urlSearch == '' || urlSearch == null)
		urlSearch = '?CID=8';		// default value
 	
	var url = 'http://www.skylineglobe.com/SkylineGlobe/WebClient/PresentationLayer/webclient/3dwebclient.aspx';

	url = url + urlSearch;
	
//	alert("Error: Need to comment out this alert\n and uncomment one of the next 4 lines\n in the code.");
//  var referrer = '&referrer=ss3ddev&initialize=1';		//Dev
//  var referrer = '&referrer=ss3dstaged&initialize=1';	// Staging
//  var referrer = '&referrer=siteseer3d&initialize=1';	// Production
    var referrer = '&referrer=SS3Dweb';  // V2 Rocks!!!

//	Add referrer to url
	url = url + referrer;

	// vBaseFly gets passed in from the start controller (views\start\index.html.erb)
	// it gets set there based on the industry of the account
	if (vBaseFly === undefined) vBaseFly = 'skylineglobeAE';
	url = url + '&basefly=' + vBaseFly + '.fly';

// tourism
//baseglobess3dtour.fly

	SGStartURL(url);
	//alert(url);
    //clipboardData.setData("Text", url);
	
    var ourURL = location.hostname;	

//  NOTE: cookies cannot contain ports in domain name -- just use hostname
	setCookie("SKYLINEINSTALLED", "1", 10 * 365, '/', ourURL, ''); // Will store cookie reference for host that served up the download page
//	setCookie("SKYLINEINSTALLED", "1", 10 * 365, '/', 'staging.siteseer3d.com', '');
//	setCookie("SKYLINEINSTALLED", "1", 10 * 365, '/', 'www.siteseer3d.com', '');
}
