// Set the stylesheet
		function setActiveStyleSheet(title) {
		var i, obj;
		for(i=0; (obj = document.getElementsByTagName("link")[i]); i++) {
			if(obj.getAttribute("rel").indexOf("style") != -1
				&& obj.getAttribute("title")) {
			obj.disabled = true;
			if(obj.getAttribute("title") == title) {
			obj.disabled = false;
			setCookie("sscStyle", obj.getAttribute("title"), 365);
			}
			}
		}
		}

// Get the current active stylesheet
function getActiveStyleSheet() {
var i, obj;
 for(i=0; (obj = document.getElementsByTagName("link")[i]); i++) {
  if(obj.getAttribute("rel").indexOf("style") != -1
  && obj.getAttribute("title")
  && !obj.disabled) return obj.getAttribute("title");
  }
  return null;
}


// Set cookie
function setCookie(c_name, value, days) {
if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
 document.cookie = c_name+"="+value+expires+"; path=/";
}

// retrieve values from cookie
function getCookie(c_name) {
if (document.cookie.length>0) {
	c_index = document.cookie.indexOf(c_name + '=');
	if (c_index != -1) {
		c_index=c_index+c_name.length+1;
		 c_end=document.cookie.indexOf(";",c_index);
		  if (c_end==-1) {
		  c_end=document.cookie.length
		  }
			return unescape(document.cookie.substring(c_index,c_end));
    } 
  }
  return null;
}

// delete cookie
function deleteCookie(c_name)
{
  document.cookie = c_name += "=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
}



// get the preferred stylesheet
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}


// set style class for disabled links
function setSelectedObj(name) {
var i, obj;
if (name != "" && name != null) {
	for (i=0; name.length >= i; i++) {
	obj = document.getElementById(name[i]);
	if (obj != null && obj != "") {
		obj.className = obj.className + "_selected";
		//if ((obj.className.indexOf("menuBar") == -1) && (obj.getAttribute("href") != "" || obj.getAttribute("href") != null)) obj.href = "#";
		}
	}
}
return false;
}


// set style for active and unactive stylesheet links
function setStylesheetLinks (title) {
if (title == null || title == "") title = getActiveStyleSheet();
linkArray = [ document.getElementById("small"), document.getElementById("medium"), document.getElementById("large")];

	for(i=0; (obj= linkArray[i]); i++) {
		if ( obj != null ) {
			if (obj.id == title) {
			obj.className = "nav_selected " + title + "Font";
			} else {
			obj.className = "nav " + obj.className.substring(obj.className.indexOf(" "));
			}
		}
	}

}

// toggle object between show and hide
function showHideObj(name) {
var i, obj;
if (name != "" && name != null) {
	obj = document.getElementById(name);
	if (obj != null && obj != "") {
		if (obj.className.indexOf("_selected") == -1) 
		{
		obj.className = obj.className + "_selected";
		}
		else {
		obj.className = obj.className.substring(0, obj.className.indexOf("_selected"));
		
		}
	}
}
return false;
}

// If Save Info checkbox is checked, save info into cookies.
function setFormCookie(theForm) {
	if (theForm.Save_Info.checked == true) {
		setCookie("FName", theForm.First_Name.value, 365);
		setCookie("LName", theForm.Last_Name.value, 365);
		setCookie("Company", theForm.Company.value, 365);
		setCookie("Phone", theForm.Phone.value, 365);
		setCookie("Email", theForm.Email.value, 365);
		setCookie("JTitle", theForm.Job_Title.value, 365);
		setCookie("SaveInfo", " checked", 365);
		
		//set cookies for request info/demo forms
		if (theForm.Zip != null && theForm.Zip.value != "") {
		setCookie("Zip", theForm.Zip.value, 365);
		}
		if (theForm.Country != null && theForm.Country.value != "") {
		setCookie("Country", theForm.Country.value, 365);
		}
		if (theForm.Comp_Type != null && theForm.Comp_Type.selectedIndex != 0) {
		Comp_Type_Value = theForm.Comp_Type[theForm.Comp_Type.selectedIndex].value;
		setCookie("Comp_Type", Comp_Type_Value, 365);
		}
		if (theForm.AUM != null && theForm.AUM.selectedIndex != 0) {
		AUM_Value = theForm.AUM[theForm.AUM.selectedIndex].value;
		setCookie("AUM", AUM_Value, 365);
		}
	}
	else
	{
		deleteCookie("FName");
		deleteCookie("LName");
		deleteCookie("Company");
		deleteCookie("Phone");
		deleteCookie("Email");
		deleteCookie("JTitle");
		deleteCookie("Country");
		deleteCookie("Zip");
		deleteCookie("AUM");
		deleteCookie("Comp_Type");
		setCookie("SaveInfo", " unchecked", 365);
	}
}

// Preselect selectbox
function selectboxSelector(list,value) {
	if (list != null) {
		for (i=0; i < list.length; i++) {
			if (list.options[i].value == value) {
				list.options[i].selected = 1;
				break;
			}
		}
	}
}

// Fill text field with cookie value
function getValueForField(control, name) {
	if (control != null) {
		if (name == "FirstLastName" ) {
			var fName = cookie('FName');
			var lName = cookie('LName');
			var FLName = "";
			if (fName != null || lName != null) {
				FLName = fName + ' ' + lName;
			}
			control.value = FLName;
		}
		else {
			var cookie = getCookie(name);
			control.value = cookie ? cookie : "";
		}
		
	}
}

// Opens up subscription area
function openSubscription(checker,table,arrow) {
	if (checker == 1) {
		obj = document.getElementById(table);
		obj2 = document.getElementById(arrow);
		//try {
		if (obj.style.display == 'none') {
		obj.style.display = 'block';
		obj2.src = "http://www.ssctech.com/images/icons/arrow_up.gif";
		}
		else if (obj.style.display == 'block') {
		obj.style.display = 'none';
		obj2.src = "http://www.ssctech.com/images/icons/arrow_down.gif";
		}
	}
}

// Opens/Closes display areas
function toggleDisplay(table) {
	obj = document.getElementById(table);
	if (obj != null) {
		if (obj.className.indexOf('_selected') < 0 ) {
		obj.className = obj.className + '_selected';
		}
		else if (obj.className.indexOf('_selected') > 0 ) {
		obj.className = obj.className.substring(0, obj.className.indexOf('_selected'));
		}
	}
}

// Closes all toggleable elements
function closeAllDisplay(element, cName) {
	arr = document.getElementsByTagName(element);
	 for(var i=0; i < arr.length; i++) {
		var  obj = arr.item(i)
        if (obj.className.indexOf(cName + '_selected') >= 0) {
			obj.className = cName;
		}
     }
}

// Opens flash piece
function flashMovieInsert(link, w, h) {
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width=' + w  + ' height=' + h  + ' id="flash" align="middle" VIEWASTEXT>\n');
document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
document.write('<param name="movie" value="' + link + '"/>\n');
document.write('<param name="quality" value="best" />\n');
document.write('<param name="bgcolor" value="#ffffff" />\n');
document.write('<embed src="' + link + '" quality="best" border=0 bgcolor="#ffffff" width=' + w  + ' height=' + h  + ' name="flash" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');                        
document.write('</object>\n');
}


// checks browser and version
function checkBrowser(){

// Checks for Netscape 6 and below
	if(window.navigator.product) {	
		if (navigator.vendor.indexOf("Netscape") != -1 && parseFloat(window.navigator.vendorSub) < 7.0){
			obj = document.getElementById("browserMessage");
			obj.className = "showBrowserMsg";	
		}
	}
	else 
	{
		// Checks for IE 5.0 and below
			if (navigator.appName.indexOf("Internet Explorer") != -1 && getInternetExplorerVersion() < 6.0) {
				obj = document.getElementById("browserMessage");
				obj.className = "showBrowserMsg";
			}
			
			
		// Checks for Opera Users
			if (navigator.appName.indexOf("Opera") != -1 && parseFloat(navigator.appVersion) < 9 ) {
				obj = document.getElementById("browserMessage");
				obj.className = "showBrowserMsg";
			}
	}
}

// helper function to check version of IE
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}


// onload functions 
  // set the preferred stylesheet from the cookie or load preferred stylesheet
  var cookie = getCookie("sscStyle");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  
  


// on unload window, set cookie to current stylesheet
window.onunload = function(e) {
  //var title = getActiveStyleSheet();
 // setCookie("sscStyle", title, 365);
  
}
