function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideLayers() {
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function getCoords(element){
		for (var lx=0,ly=0;element!=null;
			lx+=element.offsetLeft,ly+=element.offsetTop,element=element.offsetParent);
		return {x:lx,y:ly}
	}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


function isNumeric(sText) {
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) IsNumber = false;
   }
   return IsNumber;
}

function simpleslide(){// v2.2, Mod'd
if (arguments.length<4){return;}var v1=arguments,v2=v1[0];if (v2==""){return;}var	v3=eval("findObj('"+v2+"')");if (v3==null){return;}var v4=parseInt(v1[1]),v5=parseInt(v1[2]),v6=parseInt(v1[3]);var v7=(v1.length>4)?parseInt(v1[4]):0,v8=(v1.length>5)?parseInt(v1[5]):0;var v9=10,v10=document.layers?v3:v3.style;if (v3.SL2!=null){clearTimeout(v3.SL2);}var v11=isNaN(parseInt(v10.left))?v3.offsetLeft:parseInt(v10.left);var v12=isNaN(parseInt(v10.top))?v3.offsetTop:parseInt(v10.top);if (v8!=0){if (v8==1){v4=v11-v4;v5=v12;}else if (v8==2){v4=v11+v4;v5=v12;}else if (v8==3){v5=v12-v5;v4=v11;}else {v5=v12+v5;v4=v11;}}var v13=v4,v14=v5;if ((v11!=v4)||(v12!=v5)){if (v7>0){v9=v6;var v15=v7,v16=v7,v17=Math.abs(v11-v4),v18=Math.abs(v12-v5);if (v17<v18){v16=(v17!=0)?((v18/v17)*v7):v7;}else {v15=(v18!=0)?((v17/v18)*v7):v7;}if (v15>=v17){v15=Math.min(Math.ceil(v15),v7);}if (v16>=v18){v16=Math.min(Math.ceil(v16),v7);}if ((v11<v4)&&(v11+v15<v4)){v4=v11+v15;}if ((v11>v4)&&(v11-v15>v4)){v4=v11-v15;}if ((v12<v5)&&(v12+v16<v5)){v5=v12+v16;}if ((v12>v5)&&(v12-v16>v5)){v5=v12-v16;}}else {var v17=((v4-v11)/v6),v18=((v5-v12)/v6);v17=(v17>0)?Math.ceil(v17):Math.floor(v17);v4=v11+v17;v18=(v18>0)?Math.ceil(v18):Math.floor(v18);v5=v12+v18;}var v19=((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1)&&(!window.opera))?"px":"";if (v17!=0){eval("v10.left = '"+v4+v19+"'");}if (v18!=0){eval("v10.top = '"+v5+v19+"'");}var v20="simpleslide('"+v2+"',"+v13+","+v14+","+v6+","+v7+",0)";v3.SL2=setTimeout(v20,v9);}}


function advslide(){// v2.2, Mod'd
if (!(isNumeric(arguments[arguments.length -1]))) doAfter = arguments[arguments.length -1];
if (arguments.length<4){return;}var v1=arguments,v2=v1[0];if (v2==""){return;}var	v3=eval("findObj('"+v2+"')");if (v3==null){return;}var v4=parseInt(v1[1]),v5=parseInt(v1[2]),v6=parseInt(v1[3]);var v7=(v1.length>4)?parseInt(v1[4]):0,v8=(v1.length>5)?parseInt(v1[5]):0;var v9=10,v10=document.layers?v3:v3.style;if (v3.SL2!=null){clearTimeout(v3.SL2);}var v11=isNaN(parseInt(v10.left))?v3.offsetLeft:parseInt(v10.left);var v12=isNaN(parseInt(v10.top))?v3.offsetTop:parseInt(v10.top);if (v8!=0){if (v8==1){v4=v11-v4;v5=v12;}else if (v8==2){v4=v11+v4;v5=v12;}else if (v8==3){v5=v12-v5;v4=v11;}else {v5=v12+v5;v4=v11;}}var v13=v4,v14=v5;if ((v11!=v4)||(v12!=v5)){if (v7>0){v9=v6;var v15=v7,v16=v7,v17=Math.abs(v11-v4),v18=Math.abs(v12-v5);if (v17<v18){v16=(v17!=0)?((v18/v17)*v7):v7;}else {v15=(v18!=0)?((v17/v18)*v7):v7;}if (v15>=v17){v15=Math.min(Math.ceil(v15),v7);}if (v16>=v18){v16=Math.min(Math.ceil(v16),v7);}if ((v11<v4)&&(v11+v15<v4)){v4=v11+v15;}if ((v11>v4)&&(v11-v15>v4)){v4=v11-v15;}if ((v12<v5)&&(v12+v16<v5)){v5=v12+v16;}if ((v12>v5)&&(v12-v16>v5)){v5=v12-v16;}}else {var v17=((v4-v11)/v6),v18=((v5-v12)/v6);v17=(v17>0)?Math.ceil(v17):Math.floor(v17);v4=v11+v17;v18=(v18>0)?Math.ceil(v18):Math.floor(v18);v5=v12+v18;}var v19=((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1)&&(!window.opera))?"px":"";if (v17!=0){eval("v10.left = '"+v4+v19+"'");}if (v18!=0){eval("v10.top = '"+v5+v19+"'");}var v20="advslide('"+v2+"',"+v13+","+v14+","+v6+","+v7+",0)";v3.SL2=setTimeout(v20,v9);} else eval(doAfter);}


// Set active or inactive
	function activate(target) {
		if (targetobj = findObj(target)) {
			if (!(targetobj.className.match('active'))) {
				targetobj.className = trimString(targetobj.className + ' active');
			}
		}
	}
	function deactivate(target) {
		if (targetobj = findObj(target)) targetobj.className = trimString(targetobj.className.replace("active", ""));
	}

var delayaction;

function show(obj,parentbtn) {
	clearTimeout(delayaction);
	// special case: the showing of sitespopup (includes repositioning)
	if (obj == 'sitespopup') {	
			findObj('sitespopup').style.top = getCoords(findObj('btn_sites')).y - findObj('sitespopup').offsetHeight + 25 + "px";
		}
	// special cases: the showing of categoriespopups (includes repositioning)
	if (obj == 'categoriespopup') {
			findObj('categoriespopup').style.top = getCoords(findObj('btn_categories')).y + "px";
			findObj('categoriespopup').style.left = getCoords(findObj('btn_categories')).x - getCoords(findObj('container')).x + "px";
			findObj('categoriespopup').style.display = 'block';
		}
	if (obj == 'categoriespopup1') {
			findObj('categoriespopup1').style.top = getCoords(findObj('btn_categories1')).y + "px";
			findObj('categoriespopup1').style.left = getCoords(findObj('btn_categories1')).x - getCoords(findObj('container')).x + "px";
			findObj('categoriespopup1').style.display = 'block';
		}
	if (obj == 'categoriespopup2') {
			findObj('categoriespopup2').style.top = getCoords(findObj('btn_categories2')).y + "px";
			findObj('categoriespopup2').style.left = getCoords(findObj('btn_categories2')).x - getCoords(findObj('container')).x + "px";
			findObj('categoriespopup2').style.display = 'block';
		}
	// special case: the showing of languagespopup (includes repositioning)
	if (obj == 'languagespopup') {
			findObj('languagespopup').style.top = getCoords(findObj('btn_languages')).y + "px";
			findObj('languagespopup').style.left = getCoords(findObj('btn_languages')).x - getCoords(findObj('container')).x + "px";
			findObj('languagespopup').style.display = 'block';
		}
	
	// if parentobj is defined and found
	if ((parentbtn != undefined) && (parentobj=findObj(parentbtn)) && (showobj=findObj(obj))) {			
			showobj.style.top = getCoords(parentobj).y - showobj.offsetHeight + parentobj.offsetHeight + "px";			
			if (navigator.appName.toLowerCase().indexOf("netscape") > -1) {
				showobj.style.left = getCoords(parentobj).x - getCoords(findObj('container')).x - 2 + "px";
				}
			else {
				
				showobj.style.left = getCoords(parentobj).x - getCoords(findObj('container')).x - 14 + "px";
				}
		}
	showHideLayers(obj,'','show')
}


function hide(obj,delaytime) {
	if (delaytime != undefined) {
		delayaction = setTimeout("showHideLayers('" + obj + "','','hide');if ('" + obj + "'.match('popup')) findObj('" + obj + "').style.top = '0px'",10);
	}
	else {
		showHideLayers(obj,'','hide');
	}
}

function focusfld(fieldid,action) {
		if (action==1) {
			findObj(fieldid).className = 'focused';
		}
		if (action==0) {
			findObj(fieldid).className = '';
		}
	}
	
function menuflip(tabnmbr) {
		if (tabnmbr==1) findObj('leftcol').className = 'menutab1';
		if (tabnmbr==2) findObj('leftcol').className = 'menutab2';
	}


//this one takes care of the submenus
function submenu(subnmbr) {
	
	//hide submenus
	
	var divs = document.getElementsByTagName('div');	//get all divs
	for(i=0;i<divs.length;i++){							//loop through divs
		if(divs[i].id.match(/sub\d/)){					//if their name has 'sub'
			hide(divs[i].id)							//hide them
		}
	}
	
	if (subnmbr!=null) {
	
		// get menu item y-coordinate
		var obj,locV;
		if (obj=findObj('item' + subnmbr)) {
			myElement = getCoords(obj);
			locV = myElement.y;
		}
		
		// set submenu to same coordinate -1
		// show menu	
		var obj;
		if (obj=findObj('sub' + subnmbr)) {
			obj.style.top = locV -2 + 'px';
			show('sub' + subnmbr);
		}
	}
}

var activepath = 0;


// switching tabs
function tab(tabnmbr) {
	// hide all tab contents	
		var divs = document.getElementsByTagName('div');	
		for(i=0;i<divs.length;i++){							
			if(divs[i].id.match(/tabcontent\d/)){					
				if (targetobj = findObj(divs[i].id)) targetobj.className = trimString(targetobj.className.replace("active", ""));							
			}
		}

	// set all tabs to inactive	
		var lis = document.getElementsByTagName('li');
		for(i=0;i<lis.length;i++){	
			if(lis[i].id.match(/tab\d/)){
				if (targetobj = findObj(lis[i].id)) targetobj.className = trimString(targetobj.className.replace("active", ""));
			}
		}

	// activate given tab
	if (tabnmbr != 'undefined') {
		if (targetobj = findObj('tab' + tabnmbr)) targetobj.className = trimString(targetobj.className + ' active');
		if (targetobj = findObj('tabcontent' + tabnmbr)) targetobj.className = trimString(targetobj.className + ' active');
	}
}

// Handle home page paths
	function openpath(pathnmbr) {
		if (pathnmbr != activepath) {
			if (findObj('campaign')) simpleslide('campaign',-2,293,5,0,0);
			for (i=1;i<5;i++) {
				if (i <= pathnmbr) simpleslide('path' + i,0,i*35-15,5,0,0);	
				if (i > pathnmbr) simpleslide('path' + i,0,i*35+82,5,0,0);
				if (i != pathnmbr) simpleslide('pathinfo' + i,0,-74,5,0,0); deactivate('path' + i);
			
			}
			advslide('pathinfo' + pathnmbr,0,23,5,0,0,'activate("path' + pathnmbr + '")') 	// name, x, y, spd, todoafter
			activepath = pathnmbr;
		}
		else {
			for (i=1;i<5;i++) {
				simpleslide('path' + i,0,i*35-15,5,0,0);
				simpleslide('pathinfo' + i,0,-74,5,0,0);
			}
			deactivate('path' + activepath);
			activepath = 0;
			if (findObj('campaign')) simpleslide('campaign',-2,179,5,0,0);
		}
	}


// Handle the region-country -selector
	var currregion, currcountry;
	
	function region(regionnmbr) {
		currregion = regionnmbr;
		// activate the right item in the region list
		var as = document.getElementsByTagName('a');
		for(i=0;i<as.length;i++){	
			if(as[i].id.match(/regionlistitem\d/)){
				if (targetobj = findObj(as[i].id)) deactivate(as[i].id);
			}
		}
		if (obj = findObj('regionlistitem' + regionnmbr)) {
			activate(obj.id);
			// change regions button text
			btntext = obj.innerHTML;
			if (btntext.length > 21) btntext = btntext.substr(0,21) + "..."; 
			findObj('regionsbtn').innerHTML = btntext;
			// change countries button text
			findObj('countriesbtn').innerHTML = "Select a country";
		}
		// activate the right country list
		var uls = document.getElementsByTagName('ul');
		for(i=0;i<uls.length;i++){	
			if(uls[i].id.match(/countrylist\d/)){
				if (targetobj = findObj(uls[i].id)) deactivate(uls[i].id);
			}
		}
		if (obj = findObj('countrylist' + regionnmbr)) {
			activate(obj.id);
		}
	}
	
	function country(itemid) {
 	//countryid = itemid.substr(15,itemid.length);
		// activate the right item in the region list
		var as = document.getElementsByTagName('a');
		for(i=0;i<as.length;i++){	
			if(as[i].id.match("countrylistitem")){
				if (targetobj = findObj(as[i].id)) deactivate(as[i].id);
			}
		}
		if (obj = findObj(itemid)) {
			activate(obj.id);
			// change regions button text
			btntext = obj.innerHTML;
			if (btntext.length > 21) btntext = btntext.substr(0,21) + "..."; 
			findObj('countriesbtn').innerHTML = btntext;
		}

		// activate the right country content
		//var divs = document.getElementsByTagName('div');
		//for(i=0;i<divs.length;i++){	
		//	if(divs[i].id.match("countrycontent")){
		//		if (targetobj = findObj(divs[i].id)) deactivate(divs[i].id);
		//	}
		//}
		//if (obj = findObj('countrycontent' + countryid)) {
		//	activate(obj.id);
		//}
		//else {
		//	activate('countrycontent0-0');
		//}

		
		//showHint(itemid);
		deactivate('countrycontent0-0');
		deactivate('countrycontent1-1');
		
		var countryid = itemid.substr(16,itemid.length);

		window.open("aspx/PersonalhelpInfo.aspx?Index=" + countryid, "", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=560,height=450")

		

	}


// Pop-up window

function popup(sourcenum,title) {
	if (findObj('popupwindow').style.display != 'none' && findObj('popupwindow').style.display != '') {
		if (obj=findObj('pagefade')) {
			obj.style.display = 'none';
		}
		if (obj=findObj('popupwindow')) {
			obj.style.display = 'none';
		}
		findObj('flashplaceholder').innerHTML = '';
	}
	else {
		if (obj=findObj('pagefade')) {
			obj.style.height = findObj('container').offsetHeight + 'px';
			obj.style.display = 'block';
		}
		if (obj=findObj('popupwindow')) {
			obj.style.display = 'block';
		}
		findObj('popuptitle').innerHTML = title;
		var so = new SWFObject("vacon_presentations.swf?kuvakansio=" + sourcenum, "presentationsengine", "930", "480", "8", "#ffffff");
		so.write("flashplaceholder");
		scroll(0,0);
	}
}


// Stretching Pop-up window (for MagNet)

function stretchpopup(source,title) {
	if (findObj('stretchpopupcontainer').style.display != 'none' && findObj('stretchpopupcontainer').style.display != '') {
		if (obj=findObj('pagefade')) {
			obj.style.display = 'none';
		}
		if (obj=findObj('stretchpopupcontainer')) {
			obj.style.display = 'none';
		}
		findObj('flashplaceholder').innerHTML = '';
	}
	else {
		if (obj=findObj('pagefade')) {
			obj.style.height = findObj('container').offsetHeight + 'px';
			obj.style.display = 'block';
		}
		if (obj=findObj('stretchpopupcontainer')) {
			obj.style.display = 'block';
		}
		findObj('stretchpopuptitle').innerHTML = title;
		findObj('flashplaceholder').style.height = "100%";
		var so = new SWFObject(source, "electronicpaper", "100%", "100%", "8", "#ffffff");
		so.write("flashplaceholder");
		scroll(0,0);
	}
}





// PRINTING

function printpage() {
		window.print();
	}


// MAILING

function mailpage() {
		document.location='mailto:?subject=Check this out!&body=' + location.href; 
	}


// TABLE STRIPES

onload = function() { stripe ('middlecol') };

 function stripe(id) {
    var table = document.getElementById(id);
    if (! table) { return; }
    
    var trs = table.getElementsByTagName("tr");

    for (var i = 0; i < trs.length; i += 2) {
      trs[i].className += " even";
    }
  }
  
  // HVAC campaign mini site functions

var currentcontent = 0;

function initpopup(popupname) {
	resetpopup(popupname);
	launchpopup(popupname);
}

// Fake pop-up window (new version)
function launchpopup(popupname,title) {
	// if there are no arguments, close all popups
	if (launchpopup.arguments.length == 0) {
		$(".popupwindow").css('display','none');
		$("#pagefade").css('display','none');
		resetpopup(); // reset all popups to startup state
		return;
	}
	// if the requested popup is already open, close it
	if (findObj(popupname).style.display != 'none' && findObj(popupname).style.display != '') {
		if (obj=findObj('pagefade')) {
			obj.style.display = 'none';
		}
		if (obj=findObj(popupname)) {
			obj.style.display = 'none';
		}
		resetpopup(popupname); // reset popups to startup state
	}
	// if the popup is not open, open it now
	else {
		if (obj=findObj('pagefade')) {
			obj.style.height = findObj('container').offsetHeight + 'px';
			obj.style.display = 'block';
		}
		if (obj=findObj(popupname)) {
			obj.style.display = 'block';
		}
		scroll(0,0);
	}
	
	// if this is the weftec popup, load iframe content
	if (popupname == "weftecpopup") {
		popuppage(1);
		frames['weftecpopupiframe'].location.href = "http://www.vacon.com/blank.html";
	}
}


function resetpopup(popupname) {
	if (resetpopup.arguments.length == 0) {
		resetpopup('hvacpopup');
		// resetpopup('weftecpopup');
	}
	if (popupname == "hvacpopup") {
		$("#hvacmaincontent").css('top','265px');
		$("#hvacnavibar").css('top','76px');
		$("#navibtn0").css('display','block');
		$("#navibtn02").css('display','none');
		$("#closebtn-green").css('display','none');
		
		$("#content0").fadeIn(1);
		$("#content1").fadeOut(1);
		$("#content2").fadeOut(1);
		$("#content3").fadeOut(1);
		$("#content4").fadeOut(1);
		$("#content5").fadeOut(1);
		$("#content6").fadeOut(1);
		$("#content7").fadeOut(1);
	}
	if (popupname == "weftecpopup") {
		frames['weftecpopupiframe'].location.href = "http://www.vacon.com/blank.html";
		$("#btn_back").fadeOut("slow");
	}
}

// Pop-up navigation
function popuppage(pagenum) {
	if (pagenum == 2) {
		$("#popuppage1").animate( { 
			left: "-930px"
		}, 1000 );
		$("#popuppage2").animate( { 
			left: "0px"
		}, 1000 );
		frames['weftecpopupiframe'].location.href = "http://digiumenterprise.com/answer/?sid=244967&chk=VSVPMKN7";
		$("#btn_back").fadeIn("slow");
	}
	if (pagenum == 1) {
		$("#popuppage1").animate( { 
			left: "0px"
		}, 1000 );
		$("#popuppage2").animate( { 
			left: "930px"
		}, 1000, function(){
			frames['weftecpopupiframe'].location.href = "http://www.vacon.com/blank.html";
		} );
		$("#btn_back").fadeOut("slow");
	}
}


function hvacnavi(itemnmbr) {
	// hide all contents
	$("#content0").fadeOut(200);
	$("#content1").fadeOut(200);
	$("#content2").fadeOut(200);
	$("#content3").fadeOut(200);
	$("#content4").fadeOut(200);
	$("#content5").fadeOut(200);
	$("#content6").fadeOut(200);
	$("#content7").fadeOut(200);
	
	
	// if there's no parameter, close the content area
	if (itemnmbr == undefined) {
		$("#closebtn-green").css('display','none');
		$("#hvacnavibar").animate( {
			top: "76px"
		}, 500, "swing");
		$("#hvacmaincontent").animate( {
			top: "265px"							  
		}, 500, "swing", function() {
			// after the animation
			$("#navibtn0").css('display','block');
			$("#navibtn02").css('display','none');
			// show default content
			$("#content0").fadeIn(500);
			currentcontent = 0;
		} );
	
	// benefits 1-4
	} else if (itemnmbr <= 4) {
	
	// show the content area
		$("#closebtn-green").css('display','none');
		$("#hvacnavibar").animate( {
			top: "76px"
		}, 500, "swing");
		$("#hvacmaincontent").animate( {
			top: "-76px"							  
		}, 500, "swing", function() {
			// after the animation
			$("#navibtn0").css('display','none');
			$("#navibtn02").css('display','block');
			// show content
			$("#content" + itemnmbr).fadeIn(500);
			currentcontent = itemnmbr;
		} );
	
	// Environment or form
	} else if (itemnmbr == 5 || itemnmbr == 6 || itemnmbr == 7) {
		// show the content area
		$("#hvacmaincontent").animate( {
			top: "-76px"
		}, 500, "swing", function() {
			// after the animation
			$("#navibtn0").css('display','block');
			$("#navibtn02").css('display','none');
			$("#closebtn-green").css('display','block');
			// show content
			$("#content" + itemnmbr).fadeIn(500);
			currentcontent = itemnmbr;
		} );
		$("#hvacnavibar").animate( {
				top: "516px"	
		}, 500, "swing");
	}
	
	// if this is the form page, reset the form
	if (itemnmbr == 6) {
		document.hvacform.firstname.value = "";
		document.hvacform.lastname.value = "";
		document.hvacform.telephone.value = "";
		document.hvacform.email.value = "";
		document.hvacform.company.value = "";
		document.hvacform.moreinformation.checked = false;
	}
	
}


