// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// Helper Function SearchForm
function groupProd () {
	var selPl = document.searchForm.selMatPlate.selectedIndex;
	var selSt = document.searchForm.selMatStand.selectedIndex;
	var selPlate = document.searchForm.selMatPlate.options[selPl].value;
	var selStand = document.searchForm.selMatStand.options[selSt].value;
	var selPlateGroup = selPlate.indexOf("c");
	var selStandGroup = selStand.indexOf("c");

    if ((document.searchForm.selMatPlate.options[0].selected == true || selPlateGroup == 0)  && (document.searchForm.selMatStand.options[0].selected == true || selStandGroup == 0)){
		document.searchForm.gp.checked = true;
	}else{
	    document.searchForm.gp.checked = false;
	}
}

function manageTil(clickEvent,numList,numBol,numSm,numDefault){
	var selTil = document.searchForm.selTil;
	var displList = document.searchForm.displList;
	var displBol = document.searchForm.displBol;
	var displSm = document.searchForm.displSm;
	
	if (clickEvent=='displBol'){
		displList.checked=false;
		displSm.checked=false;		
	}
	if (clickEvent=='displList'){
		displBol.checked=false;
		displSm.checked=false;
	}	
	if (clickEvent=='displSm'){
		displList.checked=false;
		displBol.checked=false;
	}	
	
	if (displBol.checked == true && displList.checked == false && displSm.checked == false){
		for (var i=0; i<selTil.length; i++) {
			if (selTil.options[i].value == numBol){
				selTil.options[i].selected = true;
			}
		}
	}
	else if (displList.checked == true && displBol.checked == false && displSm.checked == false){
		for (var i=0; i<selTil.length; i++) {
			if (selTil.options[i].value == numList){
				selTil.options[i].selected = true;
			}
		}
	}
	else if (displSm.checked == true && displList.checked == false && displBol.checked == false){
		for (var i=0; i<selTil.length; i++) {
			if (selTil.options[i].value == numSm){
				selTil.options[i].selected = true;
			}
		}	
	}	
	else {
		for (var i=0; i<selTil.length; i++) {
			if (selTil.options[i].value == numDefault){
				selTil.options[i].selected = true;
			}
		}
	}
}

function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}

function prodFrameHeight(whichLayer,fOffset,setStyle){
	var elem, vis, docHeight, arrayPageSize;
	docHeight = getWindowHeight();
	arrayPageSize = getPageSize();
	var pageHeight = arrayPageSize[1];
	if (document.getElementById){
		elem = document.getElementById(whichLayer);
	}
	else if(document.all){
		elem = document.all[whichLayer];
	}
	else if( document.layers ){
		elem = document.layers[whichLayer];
	}
	
	if (elem && setStyle==1){
		vis = elem.style;
		vis.height=docHeight-fOffset;
		vis.overflow='auto';
		vis.overflowX='hidden';
	}else if (elem && setStyle==2){
		vis = elem.style; 
		vis.overflow='visible';
		vis.overflowX='hidden';
	}
}

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 

function toggleLayer( whichLayer )
{  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
	elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works    
	elem = document.layers[whichLayer];  
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}



function findPos(inputObj) {
	var returnValueX = inputObj.offsetLeft;
	var returnValueY = inputObj.offsetTop;
	while((inputObj = inputObj.offsetParent) != null){
		returnValueX += inputObj.offsetLeft;
		returnValueY += inputObj.offsetTop;
	}
	return [returnValueX,returnValueY];
}
	


function getScrollXY(outp) {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  if (outp == 'left'){
		  return scrOfX;
	  }else if (outp == 'top'){
		   return scrOfY;
	  }
	//  return [ scrOfX, scrOfY ];
}


function classChange(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}


// MM
function MM_nbGroup(event, grpName) { 
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
// Chance CSS
function chance_css(id) {
	var hoverClass = 'menu_hover';
	var normalClass = 'menu';
	for (var i=0;i<numScrollPages;i++){
		var id_all = "LINK_" + i;
		identity_new=document.getElementById(id_all);
		identity_new.className=normalClass;
	}	
	identity=document.getElementById(id);
	identity.className=hoverClass;
}

function btn_text(t_string){return t_string;}
var btn_messege = btn_text("Please wait...");
function disable_submit(btn){btn.SUBMIT_BTN.value=btn_messege;btn.SUBMIT_BTN.disabled=true;}



var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}


