/******************************************************************************
* Filename:    basic.js                                                       *
* Description: Every page should link to this script. It initializes all the  *
*              Javascript functions from this and other scripts. This page    *
*              shouldn't contain more than a handful of its own Javascript.   *
* Author:      Michael A. Smith and Dan Crane                                 *
* Modified:    2006-11-21                                                     *
******************************************************************************/

/** Stuff that needs to happen when the page loads. If you need to define a
    specific init() for a given page, please call the function localInit() and
    enclose init() in it at the top, like so:
  window.onload = localInit;
	function localInit() {
	  init();
	  // ... other stuff ...
  }
*/
// This is the legalese quit message for external links.
var quitMsg = "You are leaving a LANXESS Web site and entering a third party Web site.\nLANXESS does not own or control and shall have no liability with respect to the content of the third party Web site.";
window.onload = init;
function init() {
  makeHoverById("topnav", "LI");
  popupWindows();
  rolloverImages();
  validateForms();
	setupPageFunctions();
}
/** Makes the "_go" disappear form our_products fxnModules -- if Javascript is
    disabled then "_go" will appear and the form will stay functional. */
function noGo() {
	document.getElementById("tButton").style.display = "none";
}

function isNum(obj){
	notNum = "";
	//all numbers?
	if(obj.value.length > 0){
		str = obj.value.toString();
		nums = "1234567890-";
		for(i=0;i<str.length;i++){
			cr = str.charAt(i);
			if(nums.indexOf(cr)== -1 ){
				notNum = "t";
			}
		}
		if(notNum == "t"){
			alert("This field can only contain numbers");
			obj.value = "";
			obj.value.length = 0;
			obj.focus();
		}
	}
}


function fullScreenVideo(l){
	//var url = "/library/fullscreenvideo.cfm";
	//FadeOpacity("fadeDiv",0,60,500,10);
	vdiv = document.getElementById('videoDiv');
	vdiv.style.display="block";
	vdiv.style.height="432px";
	vdiv.style.width="720px";
	vdiv.style.zIndex="1000";
	switch(l){
		case "home":
		 vdiv.style.top="390px";
		 vdiv.style.left="20px";
		 var linkTxt = "<b>See how Bayferrox<sup>&reg;</sup> pigments are made.</b><a href=\"javascript:minimizeVideo();\"><img src=\"/images/minimize.png\" alt=\"minimize\" style=\"vertical-align:middle;\" /> minimize</a></span>";
		 break;
		default:
		 vdiv.style.top="100px";
		 vdiv.style.left="50px";
		 var linkTxt = "<b>See how Bayferrox<sup>&reg;</sup> pigments are made.</b><a href=\"javascript:closeVideo();\"><img src=\"/images/minimize.png\" alt=\"close\" style=\"vertical-align:middle;\" /> close</a></span>";
		 break;
	}
	vobj = vdiv.getElementsByTagName('object')[0];
	vobj.style.height="414px";
	vobj.style.width="720px";
	vobj.style.float="left";
	vobj.style.margin="0px";
	vobj.style.padding="0px";
	writeToDiv('linkToggle',linkTxt);
}

function minimizeVideo(){
	vdiv = document.getElementById('videoDiv');
	vdiv.style.height="226px";
	vdiv.style.width="360px";
	vdiv.style.zIndex="1000";
	vdiv.style.top="600px";
	vdiv.style.left="20px";
	var linkTxt = "<b>See how Bayferrox<sup>&reg;</sup> pigments are made.</b><a href=\"javascript:fullScreenVideo('home');\"><img src=\"/images/fullscreen.png\" alt=\"full screen\" style=\"vertical-align:middle;\" /> maximize</a></span>";
	vobj = vdiv.getElementsByTagName('object')[0];
	vobj.style.height="207px";
	vobj.style.width="360px";
	writeToDiv('linkToggle',linkTxt);
}

function closeVideo(){
	vdiv = document.getElementById('videoDiv');
	vdiv.style.display="none";
}

function resizeIt(ID){
	document.getElementById(ID).style.height="auto";
}

//for writing the time divs in schedulePop.php
function writeToDiv(ID,contents) {
	if(document.layers){
		var oLayer;
		oLayer = document.layers[ID].document;
		oLayer.open();
		oLayer.write(contents);
		oLayer.close();
		
	}else if(parseInt(navigator.appVersion) >=5 && navigator.appName == "Netscape"){
		document.getElementById(ID).innerHTML = contents;
		
	}else if(document.all){
		document.all[ID].innerHTML = contents
		
	}
	
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps){
	if(elemId == "fadeDiv"){
		fade = document.getElementById("fadeDiv");
		fade.style.visibility="visible";
		contentDiv = document.getElementById("content");
		cheight = (contentDiv.offsetHeight+104).toString()+"px";
		cwidth = contentDiv.offsetWidth.toString()+"px";
		getleft = findPos(contentDiv);
		cleft = getleft[0].toString()+"px";
		fade.style.height = cheight;
		fade.style.width = cwidth;
		fade.style.left = cleft;
	}
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity,delta, timePerStep){
	SetOpacity(document.getElementById(elemId),Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps) setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", "+ delta + ", " + timePerStep + ");",timePerStep);
  	if(elemId == 'fadeDiv' && fromOpacity==50 && stepNum == steps) document.getElementById(elemId).style.visibility="hidden";
}

function SetOpacity(elem, opacityAsInt){
    var opacityAsDecimal = opacityAsInt;
   
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
   else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
    
    elem.style.opacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function findPos(obj){
	var curleft = curtop = 0;
	if(obj.offsetParent) {
		do{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}while(obj = obj.offsetParent);
		
		return [curleft,curtop];
	}
}


function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;} 


