//Preload some navigation images
var preloaded_image01 = new Image();
preloaded_image01.src = "/images/header_selected.png";
var preloaded_image02 = new Image();
preloaded_image02.src = "/images/raquo.png";
var preloaded_image03 = new Image();
preloaded_image03.src = "/images/raquo_hover.png";
var preloaded_image04 = new Image();
preloaded_image04.src = "/images/transparent.gif";

function openVolumeIDInstructions()
{
	window.open('/downloads-and-trials/volume_serial_number_instructions/what_is_this','volume_id_instructions_popup','height=500,width=720,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no');
	return false;
}

var submit_count = 0;
function fillInVolumeID(text_field_id, instructions_id)
{
	if (isIE())
	{
		var XLApp = new ActiveXObject("ActXSysID.ActSysInfo");
		var volume_id = XLApp.SerialNumber;

		if (volume_id != '')
		{
			document.getElementById(text_field_id).value = volume_id;
			document.getElementById(text_field_id).readOnly = true;
			document.getElementById(instructions_id).style.display = 'none';
		}
	}
}

function isIE()
{
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function displayStateOrProvinceField(country_select_box)
{
	var selected_country = country_select_box.options[country_select_box.selectedIndex].text;

	if (selected_country == 'USA' || selected_country == '')
	{
		document.getElementById('provinces').style.display = 'none';
		document.getElementById('Province_text_field').value = '';
		document.getElementById('states').style.display = '';
	}
	else
	{
		document.getElementById('states').style.display = 'none';
		document.getElementById('StateProvince_select_list').value = '';		
		document.getElementById('provinces').style.display = '';
	}
}

function displayDownloadInstructionsEmailNote(distribution_method_select_box)
{
	var selected_distribution_method = distribution_method_select_box.options[distribution_method_select_box.selectedIndex].value;

	if (selected_distribution_method == 'cd' || selected_distribution_method == '')
	{
		document.getElementById('download_instructions_email_note').style.display = 'none';
	}
	else
	{
		document.getElementById('download_instructions_email_note').style.display = 'block';
	}
}

function downloadFile(form)
{
	var URL = form.site.options[form.site.selectedIndex].value;
	window.location.href = URL;
}

// The following five functions (appearFloatingAd, appear, disappear, getStyle, findPosY) are for floating overlay ads
function appearFloatingAd(name, now)
{
	if (typeof(name) != 'undefined')
	{
		if (readCookie(name))
		{
			last_displayed_at = readCookie(name);

			// Determine the number of hours since an ad was displayed
			num_hours_since_displayed = (now - last_displayed_at) / (60 * 60);

			// If an ad has not been displayed in the last 4 hours, display another one
			if (num_hours_since_displayed >= 4)
			{
				createCookie(name, now, 7);
				
				appear();
			}
		}
		else
		{
			createCookie(name, now, 7);
			
			appear();
		}
	}
	else
	{
		appear();
	}
}

var timeout;
function appear()
{
	var the_style = getStyle("floatingFlash");

	if (the_style)
	{
		var current_top = findPosY(document.getElementById('floatingFlash'));
		
		var new_top = current_top + 6;
		
		if (document.layers)
		{
			the_style.top = new_top;
		}
		else
		{
			the_style.top = new_top + "px";
		}
	
		if (new_top < 130)
		{
			the_timeout = setTimeout('appear();',10);
		}
	}	
}

function disappear()
{
	var the_style = getStyle("floatingFlash");
	the_style.display = 'none';
}

function getStyle(ref)
{
	if(document.getElementById && document.getElementById(ref))
	{
		return document.getElementById(ref).style;
	}
	else if (document.all && document.all(ref))
	{
		return document.all(ref).style;
	}
	else if (document.layers && document.layers[ref])
	{
		return document.layers[ref];
	}
	else
	{
		return false;
	}
}

function findPosY(obj)
{
	var curtop = 0;
	
	if(obj.offsetParent)
	{
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
		    break;
		  obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

//Cookie functions
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}