function fixPngTransparency(elementID){
	// IF MSIE version 5 or 6
	if(navigator.userAgent.indexOf("MSIE 6") != -1 || navigator.userAgent.indexOf("MSIE 5") != -1){
		var pngImage 			= document.getElementById(elementID);
		var pngImageSrc			= pngImage.src;
		var spacerSrc			= '../images/spacer.gif';
		pngImage.src 			= spacerSrc;
		pngImage.style.filter 	= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngImageSrc+"', sizingMethod='image')";
	}
}
function isIE(){
	var browser = navigator.userAgent.toLowerCase();
	if(browser.indexOf("msie") == -1){
		return false;
	}
	return true;
}
function isIE6(){
	var browser = navigator.userAgent.toLowerCase();
	if(browser.indexOf("msie 6") == -1){
		return false;
	}
	return true;
}
function isOpera(){
	var browser = navigator.userAgent.toLowerCase();
	if(browser.indexOf("opera") == -1){
		return false;
	}
	return true;
}
/* Finding the position of an object */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/, ""); 
}

function goToProductCatalogPage(page){
				var theURL=page;
				if(theURL == "http://www.torfehgroup.com/logomaker/" || theURL == "http://www.torfehgroup.com/logo/"){
	var w=900;
	var h=700;
	}
	else{
	var w=800;
	var h=600;
	}
	var winName="PortFolio";
	  LeftPosition=(screen.width)?(screen.width-w)/2:100;
	  TopPosition=(screen.height)?(screen.height-h)/2:100;
	  
	  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',location=no,directories=no,status=0,menubar=no,addressbar=no,toolbar=no,resizable=no';
	  URL = theURL;
	  window.open(URL,winName,settings);
		}

function resizeElement(objId){
	if(screen.width < 1024){
		if(document.getElementById(objId)){
			currObj = document.getElementById(objId);
			
			if(objId == "leftnav"){
				//resize the leftnavigation to 156px;
				currObj.style.width = "156px";	
			}
			else if(objId == "extracolumn"){
				//hide the extracolumn from the user
				currObj.style.display = "none";
			}
			/*else if(objId == "topnavflash"){
				currObj.style.width = "754";
				document.getElementById("topnav_flash_embed").style.width = "754px";
			}*/
			else {
				//presume fullsized element and resize to 754px;
				currObj.style.width = "754px";
			}
 		}
	}
}

function resizeElementLowres(objId,newWidth){
	gettempname = getParam("template");
	tempname = gettempname.substring(0,2);
}

function writeTopNav(selected) {
   var topnav_html = createTopNav(selected);
   document.write(topnav_html);
}

function createTopNav(selected){
	var flashVars = new Array();
	
	//get the text colors based on the current body class
	if (selected) {
		var brandColor = selected;
	} else {
		var brandColor = (document.body.className ? document.body.className : 'default');
	}
	var bgColor2 = null;
	var bgColor = "FFFFFF";
        
	//define default colors
	if(brandColor != 'default'){
		//set general colors for branded topnav
		offStateColor = "FFFFFF";
		activeLineColor = "FFFFFF";
		bgColor = "FFFFFF";
	}
		
	if(brandColor.indexOf('green') != -1){		
		rollOverColor = "FFE878";
		lineColor = "A6D561";
		bgColor2 = '50C401';	
		if (brandColor.indexOf('small') != -1) {
			bgColor2 = '7FC31C';
		}
		if (brandColor.indexOf('solid') != -1) {
			bgColor2 = '7FC31C';
		}
	} else if(brandColor.indexOf('orange') != -1){
		
		if(brandColor.indexOf('corporate') != -1){
			offStateColor 	= "333333";
			rollOverColor 	= "eb7407";
			lineColor 		= "eb7407";
			activeLineColor = "ffd402";
		} else {
			rollOverColor = "FFE878";
			lineColor = "FFAB51";
			bgColor2 = 'FF7F00';
			if (brandColor.indexOf('small') != -1) {
				bgColor2 = 'FF7C00';	
			}
		}
	} else if(brandColor.indexOf('yellow') != -1){
		offStateColor = "000000";
		rollOverColor = "FFFFFF";
		lineColor = "D69C14";
		bgColor2 = 'FFB700';
		if (brandColor.indexOf('small') != -1) {
			bgColor2 = 'FFC801';
		}
		if (brandColor.indexOf('solid') != -1) {
			bgColor2 = 'FFBF00';
		}
	} else if(brandColor.indexOf('red') != -1){
		rollOverColor = "FF0000";
		lineColor = "B8564E";
		bgColor2 = 'B40500';
		if (brandColor.indexOf('small') != -1) {
			bgColor2 = 'C81502';	
		}
		if (brandColor.indexOf('solid') != -1) {
			bgColor2 = 'CC0000';	
		}
	} else if(brandColor.indexOf('purple') != -1){

		if(brandColor.indexOf('corporate') != -1){
			offStateColor 	= "333333";
			rollOverColor 	= "6b2c7c";
			lineColor 		= "6b2c7c";
			activeLineColor = "ce3182";
		} else {
			rollOverColor = "CC66FF";
			lineColor = "AE78C2";
			bgColor2 = '973CB1';
			if (brandColor.indexOf('small') != -1) {
				bgColor2 = '9B399C';	
			}
			if (brandColor.indexOf('solid') != -1) {
				bgColor2 = '69004B';	
			}
		}
	} else if(brandColor.indexOf('black') != -1){
		offStateColor = "999999";
		rollOverColor = "FFFFFF";
		lineColor = "666666";
		bgColor = "000000";
		headerColor = "#7F7F7F";
		activeLineColor = "FFFFFF";
	} else if(brandColor.indexOf('localhomepage') != -1){
		offStateColor = "FFFFFF";
		rollOverColor = "faeb93";
		lineColor = "a3a3a3";
		bgColor = "FEFFFF"; //this is supposed to be white but the flash seems to behave strangely if you make it 'real' white
		headerColor = "#7F7F7F";
		activeLineColor = "faeb93";
	} else {
		offStateColor = "333333";
		rollOverColor = "33832D";
		lineColor = "666666";
		bgColor = "000000";
		activeLineColor = "BDDAB1";	
	}
	
	if (bgColor2) {
		bgColor = bgColor2;
	}
	
	//set and combine the flashVars.
	flashVars[flashVars.length] = "xmlLocation=" + escape(xmlLocation);

	flashVars[flashVars.length] = "currTopLoc=" + escape(currTopLoc);
	flashVars[flashVars.length] = "currSubLoc=" + escape(currSubLoc);
	
	flashVars[flashVars.length] = "offStateColor=" + escape(offStateColor);
	flashVars[flashVars.length] = "rollOverColor=" + escape(rollOverColor);
	flashVars[flashVars.length] = "lineColor=" + escape(lineColor);

	flashVars[flashVars.length] = "bgColor=" + escape(bgColor);

	if(typeof(activeLineColor) != 'undefined'){
		flashVars[flashVars.length] = "activeLineColor=" + escape(activeLineColor);
	}
	flashVars[flashVars.length] = "cc=" + escape(cc);
	flashVars[flashVars.length] = "lc=" + escape(lc);
	flashVars[flashVars.length] = "regionname=" + escape(regionname);
	flashVars[flashVars.length] = "embedfonts=" + embedFonts();
	flashVars[flashVars.length] = "clipAlign=" + clipAlign;
	var isMSIE		= navigator.appName.indexOf("Microsoft") != -1;
	flashVars[flashVars.length] = "ismsie=" + isMSIE;        
	
	//*write dummy flash object with codebase if flash version < 7
	if(typeof(flashVersion) != "undefined"){
		if(flashVersion < 7){
			codebase = ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
		}
	}
	
	var flashID = "topnavflash";
	if (selected) {
		flashID += selected;
	}
	return createFlashTags(topnavSwf,'52','100%',flashVars.join("&"),'left',wmode,'none','#' + bgColor, flashID);
}


function getParam(paramName){
	//returns the value of the requested querystring parameter
	var docLoc = document.location.href;
	var indexOfHash = docLoc.indexOf('#');
	if (indexOfHash != -1) {
		docLoc = docLoc.substr(0, indexOfHash);
	}

	var qString = '';
	var params = new Array();

	if(docLoc.indexOf("?") != -1){
		qString = docLoc.split("?");
		qString = qString[1];
	}


	if(qString.indexOf("&") != -1){
		params = qString.split("&");
	}
	else if(qString.indexOf("=") != -1){
		params[params.length] = qString;
	}

	for(var i=0; i<params.length; i++){
		param = params[i].split("=");
		if(param[0] == paramName){
			return param[1];
		}
	}

	return '';
}

var newWindow;

function popupPage(type,url) {
	var height;
	var width;
	
	if(!url){
		url = '';
	}
	if(!type){
		type = 1;
	}
	if (type == 1) {
          width=420;
          height=500;
	} else if (type == 2) {
          width=420; 
          height=700;
	} else if(type == 3) {
          width=600;
          height=500;
	} else if(type == 4) {
          width=660;
          height=420;
	} else if(type == 5) {
          width=790;
          height=492;
	} else if(type == 6) {
          width=600;
          height=570;
	}

	var stats;
        stats = 'screenX='+width+',screenY='+height
		+ ',width='+width+',height='+height
		+ ',left=0,top=0'
		+ ',resizable=true'
		+ ',scrollbars=yes'
		+ ',status=no'
		+ ',menubar=no'
		+ ',location=no';
        newWindow = window.open(url, 'popup', stats); newWindow.focus();
        newWindow;
}

function popupPageSizeWidth(url, height, width){
        popupPageSize(width, height, url) 
};

function popupPageSize(width, height, url) {
	if(!url){
		url = '';
	}

	var stats;
        stats = 'screenX='+width+',screenY='+height
		+ ',width='+width+',height='+height
		+ ',left=0,top=0'
		+ ',resizable=true'
		+ ',scrollbars=yes'
		+ ',status=no'
		+ ',menubar=no'
		+ ',location=no';
        newWindow = window.open(url, 'popup', stats); newWindow.focus();
        newWindow;
}

function popUpWithArguments(popUrl,popName,left,top,resizable,scrollbars,toolbar,location,menubar,status,directories){
	
	left 		= (left == undefined ? '100' : left);
	top		= (top == undefined ? '100' : top);
	resizable	= (resizable == undefined ? 'yes' : resizable);
	scrollbars	= (scrollbars == undefined ? 'no' : scrollbars);
	toolbar		= (toolbar == undefined ? 'no' : toolbar);
	location	= (location == undefined ? 'no' : location);
	menubar		= (menubar == undefined ? 'no' : menubar);
	status		= (status == undefined ? 'no' : status);
	directories	= (directories == undefined ? 'no' : directories);
	
	var url = popUrl;
	var name = popName;
	var arguments = 'left='+left+',top='+top+',resizable='+resizable+',scrollbars='+scrollbars+',toolbar='+toolbar+',location='+location+',menubar='+menubar+',status='+status+',directories='+directories;

	window.open(url,name,arguments);
}

function submitSearch(objForm){
	setTimeout(function() {objForm.submit()},1000);
}
function submitSearchAndSubmit(objForm){
	setTimeout(function() {objForm.submit()},1000);
}
function embedFonts(){
	//returns false if no embedded fonts may be used in Flash.
	var lc = getParam("lc");
	var noEmbedArr = ["el", "bg", "hk", "ar", "zh", "zs", "tw", "id", "th", "vi", "sk", "ru", "gr", "he", "uk", "tr", "sr", "si", "ro", "pl", "hu", "he", "hr", "cs", "sl", "lt"];
	
	for (var x in noEmbedArr){
		if(lc == noEmbedArr[x]){
			return false;
		}
	}

	return true;	
}

function textAlign(){
	var lc = getParam("lc");
	var rightAlignArr = ["ar", "he"];
	
	for (var x in rightAlignArr){
		if(lc == rightAlignArr[x]){
			return "right";
		}
	}

	return "left";
}


/*
*	writeFlashTags() - used to display flash files
*/

function writeFlashTags(movie,height,width,flashVars,alignment,wmode,menu,backgroundcolor,id) {
    document.write(createFlashTags(movie, height, width, flashVars, alignment, wmode, menu, backgroundcolor, id));
}

function createFlashTags(movie,height,width, flashVars, alignment, wmode, menu, backgroundcolor, id) {
	//defaults
	wmode			= (wmode == undefined ? 'opaque' : wmode);
	menu			= (menu == undefined ? 'false' : menu);
	alignment		= (alignment == undefined ? 'false' : alignment);
	id				= (id == undefined ? 'false' : id);
	flashVars		= (flashVars == undefined ? '' : flashVars);
	backgroundcolor	= (backgroundcolor == undefined ? '' : backgroundcolor);
	var flashversion= getFlashVersion(10);
	var HTML 		= '';
	var isIE		= navigator.appVersion.toLowerCase().indexOf("msie");
	var isSafari	= navigator.appVersion.toLowerCase().indexOf("safari");
	
	if(id != false){
		var idAttribute = 'id="'+id+'"';
	} else {
		var idAttribute = '';
	}
	
	var classId = '';
	if(isIE != -1){
		//IE7 might act weird if this is not set...
		classId = 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	}
	var codebase = '';
	
	if(flashVersion == -1){
		codebase = ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"';
	}
	
	HTML += '<object type="application/x-shockwave-flash" '+classId+' '+codebase+' data="'+movie+'" width="'+width+'" height="'+height+'" '+idAttribute+'>';
	HTML += '	<param name="movie" value="'+movie+'" />';
	HTML += '	<param name="menu" value="'+menu+'" />';
	HTML += '	<param name="flashVars" value="' + flashVars + '" />';
	HTML += '	<param name="wmode" value="'+wmode+'" />';
	
	// If wmode is opaque and a backgroundcolor has been defined
	if(backgroundcolor != '' && wmode != 'transparent') {
		HTML += '	<param name="bgcolor" value="' + backgroundcolor + '" />';
	}
	
	HTML += '</' + 'object>';

	return HTML;
}
function enablePngImages()	{
	if(navigator.userAgent.indexOf("MSIE 6") != -1 || navigator.userAgent.indexOf("MSIE 5") != -1){
		var imgArr = document.getElementsByTagName("IMG");
		for(i=0; i<imgArr.length; i++){
			if(imgArr[i].src.toLowerCase().lastIndexOf(".png") != -1){
				imgArr[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgArr[i].src + "', sizingMethod='auto')";
				imgArr[i].src = "../images/the_spacer.gif";
			}
			
			if(imgArr[i].currentStyle.backgroundImage.lastIndexOf(".png") != -1){
				var img = imgArr[i].currentStyle.backgroundImage.substring(5,imgArr[i].currentStyle.backgroundImage.length-2);
				imgArr[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
				imgArr[i].style.backgroundImage = "url(../images/the_spacer.gif)";
			}
		}
	}
}
function enableBgPngImages(bgElements){
	if(navigator.userAgent.indexOf("MSIE 6") != -1 || navigator.userAgent.indexOf("MSIE 5") != -1){
		for(i=0; i<bgElements.length; i++){
			if(bgElements[i].currentStyle.backgroundImage.lastIndexOf(".png") != -1){
				//alert(bgElements[i]);
				var img = bgElements[i].currentStyle.backgroundImage.substring(5,bgElements[i].currentStyle.backgroundImage.length-2);
				bgElements[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
				bgElements[i].style.backgroundImage = "url(../images/the_spacer.gif)";
			}
		}
	}
}
function set3MonthCookie(name,value){
	var thisDate 	= new Date();
	var year		= thisDate.getUTCFullYear();
	//The month in the date object is zero based, the one here is added fr the calculations, and will be subtracted below again before creating the new date.
	var month		= thisDate.getUTCMonth() + 1;
	var newMonth	= month + 3;
	var day			= thisDate.getUTCDay();
	
	if(newMonth > 12){
		var difference = newMonth % 12;
		newMonth = month + difference;
		year += 1;
	}
	
	newMonth -= 1;
	
	var expDate = new Date(year,newMonth,day);
	setCookie(name, value, expDate);
}
var flashVersion = 0;
function getFlashVersion(maxVersion){
	var flashVersion_DONTKNOW = -1;
	var flashVersion = 0;
	var latestFlashVersion = (maxVersion == null) ? 10 : maxVersion;
	var agent = navigator.userAgent.toLowerCase();
	
	// FF1.0 >
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') {
			var splits = '';
            if (splits = flashPlugin.description.split('.')) {
                var firstPart = splits[0];
                var from = firstPart.lastIndexOf(' ') + 1;
                var to = firstPart.length;
                flashVersion = firstPart.substring(from, to) * 1;
            }
		}
	} else if (agent.indexOf("msie") != -1) {
		flashVersion = getIEFlashVersion();
		/*if(flashVersion != -1){
			flashVersion = flashVersion.substr(4,1);
		}*/
   } else {
		flashVersion = flashVersion_DONTKNOW;
	}
	return flashVersion;
}

function getIEFlashVersion(){
	var flash_versions = 10;
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	
	for (x = 2; x <= flash_versions; x++) {
		try {
 			axo = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if (axo) {
				
				version = x;
			}
		}
		catch(e) { }
	}

	if (!version) {
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			version = "WIN 6,0,21,0";
			axo.AllowScriptAccess = "always";
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version) {
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version) {
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version) {
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
var flashVersion_DONTKNOW = -1;
/*
*	End flash detect
*/

function redirTo(toUrl){
	//FireFox escape:
	toUrl = toUrl.replace(/&amp;/g, '&');
	document.location.href = toUrl;
}

/* Calculate download time */
function calculateDownloadTime(fileSize, bandwidth) {
	//<esi:vars>
		var clientSpeed = "$(GEO{'throughput'})".toLowerCase();
	//</esi:vars>
	if(clientSpeed.indexOf("throughput") != -1){
		clientSpeed = bandwidth;
	}
	if(fileSize != ''){
		fileSize = fileSize * 8192; //size is now in kbit.
		if(clientSpeed == 'vhigh')	{ document.write(Math.ceil(fileSize/(1000*60))); }
		else if(clientSpeed == 'high')	{ document.write(Math.ceil(fileSize/(300*60))); }
		else if(clientSpeed == 'med')		{ document.write(Math.ceil(fileSize/(128*60))); }
		else if(clientSpeed == 'low')   { document.write(Math.ceil(fileSize/(56*60))); }
		else { document.write('1'); }
	}
	else {
		document.write('1');
	}
}

/* Go to a url */
function goTo(url) {
	if(url == "no_prod_selected") {
		return true;
	}
	location.href=url;
}

/* Scale the body for pages where the content is not high enough. */
function scalePage() {
	pageheight = document.documentElement.clientHeight;
	contentheight = document.getElementById("content").offsetHeight;
	
	if (contentheight < pageheight) {
		document.getElementById("footerspacer").style.height = (pageheight - contentheight) + "px";
	}
}


// add activatePopups to the onload event stack...
OnLoadHandler.appendFunction("activatePopupsSoon()", true);
function activatePopupsSoon() {
	setTimeout(activatePopups, 500);
}
function activatePopups() {
	if(document.getElementById) {
		var allLinks = document.getElementsByTagName("a");
		for(var i=0; i < allLinks.length; i++) {
			if(allLinks[i].rel=="popup") {
				allLinks[i].onclick = popup;
				if (allLinks[i].captureEvents) allLinks[i].captureEvents(Event.CLICK);				
			}
		}
	}
}

function popup(e) {
	/*if (!e) var targetHref = window.event.which.href; */
	var targetHref = "";
	if (e) targetHref = e.target.href;
	if (!e) targetHref = window.event.srcElement.href;
	//alert("This popup should lead to: " + targetHref);
	// open popup with targetHref....
	
	// Generate a random window name
	var randomWinName="win" + Math.round(Math.random()*1000).toString();
	window.open(targetHref, randomWinName, "width=400,height=500,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes");

	return(false);
}