/********************************
* javascript for handling onLoad event. All functions to be performed onLoad need to be inserted into 
* the commands array. 
*********************************/

var commands = new Array(10);
var commandIter=0;

commands[commandIter++] = "globalInit()";

onLoad = function() {
	for (var i=0; i<commandIter; i++) {
		eval(commands[i]);
	}
}

function setImageSrc(img, srcName, imagesSources) {
	if (img!=null) {
		if (imagesSources==null) {
			imagesSources=document.images;
		} 
		if (imagesSources[srcName]!=null) {
			if (img.src && imagesSources[srcName]!=null) {
				img.src = imagesSources[srcName].src;
			}
		}
	}
}

// browser detection
function browserDetect()  {
    this.isNS4 = (document.layers)&&(navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==4) ? true : false;
    this.isIE4 = (document.all)&&(navigator.appName.indexOf("Microsoft") > -1)&&(parseInt(navigator.appVersion)==4) ? true : false;
    this.isIE5 = (document.getElementById)&&(navigator.appName.indexOf("Microsoft") > -1) ? true : false;
    this.isNS6 = (document.getElementById)&&(navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)>4) ? true : false;
    this.isOP5 = (document.getElementById)&&(navigator.appName=="Opera")&&(parseInt(navigator.appVersion)>4) ? true : false;
	
	var userAgent=navigator.userAgent.toLowerCase();
	this.isMac = (userAgent.indexOf("mac")!=-1);
}

// global object to store the browser detection result
var app = new browserDetect();

// initial scrollbar detection
function scrollbarDetect() {
	this.hasHScroll; //= (document.documentElement.scrollWidth>document.documentElement.clientWidth) ? true:false;
	this.hasVScroll = false; //(document.documentElement.scrollHeight>document.documentElement.clientHeight) ? true:false;
	this.initWidth = 0;
	this.initHeight = 0;
}

// global object to store the initial scrollbar detection result
var scroll = new scrollbarDetect();

// function to detect current horizontal scrollbar
function isHScrollbar() {
	return (document.documentElement.scrollWidth>document.documentElement.clientWidth) ? true:false;
}

// function to detect current vertical scrollbar
function isVScrollbar() {
	return (document.documentElement.scrollHeight>document.documentElement.clientHeight) ? true:false;	
}

// function that includes javascript file if browser supports java script
function includeJsFile (filePath) {
	if (!app.isNS4){
		document.writeln('<script language="javascript" src="' + filePath + '" type="text/javascript"></script>');
	}
}
// function that includes javascript file if browser supports java script than 
// it includes alternative file
function includeJsFileAlternative (filePath, altFilePath) {
	if (app.isNS4){
		document.writeln('<script language="javascript" src="' + altFilePath + '" type="text/javascript"/>');
	} else {
		includeJsFile(filePath)
	}
}

// header search form submit function
function submitSearch() {
	document.forms['searchForm'].submit();
}

// form submit function
function submitForm(form) {
	document.forms[form].submit();
}

// submit form with select values shows alert when value is not choosen value==''
function submitSelected(formName,selectId,message) {
  if (!document.forms[formName]) {
  	return false;
  }
  if (!document.forms[formName].elements[selectId]) {
  	return false;
  }
  var test = document.forms[formName].elements[selectId].value;
  if (document.forms[formName].elements[selectId].value=='') {
	  alert(message);
	  return false;
  }
  document.forms[formName].submit();
}

function isClass (elm, className) {
	if (elm==null || elm.nodeType!=1) {
		return false;
	}
	var classes = elm.className.split(' ');
	for (i=0; i<classes.length; i++) {
		if (classes[i]==className) {
			return true;
		}
	}
	return false;
}

function switchClass (elm, className, newClassName) {
	if (elm==null) {
		return;
	}
	var classes = elm.className.split(' ');
	var clsName = "";
	var separator = "";
	for (i=0; i<classes.length; i++) {
		if (classes[i]==className) {
			if (newClassName!='') {
				clsName = clsName + separator + newClassName
			}
		} else {
			clsName = clsName + separator + classes[i];
		}
		separator = " ";
	}
	elm.className=clsName;
}

function appendClass (elm, clsName) {
	if (elm==null) {
		return;
	}
	elm.className=elm.className + ' ' + clsName;
}

function findElementsOfClass (container, clsName) {
	if (container==null) {
		return;
	}
	var xChild = container.firstChild;
	var result = new Array();
	var count = 0;
	while(xChild) { // run over children
		//alert('Container child class: ' + xChild.className);
		if (isClass(xChild,clsName)) {
			result[count]=xChild;
			count++;
		}
		var subResult = findElementsOfClass(xChild,clsName);
		for (i=0; i<subResult.length; i++) {
			result[count]=subResult[i];
			count++;
		}
		xChild = xChild.nextSibling;
	}
	return result;
}

// cookie manipulation, with days se to negative value can be used to remove cookie	
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/PowerSolutions/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

// manages previous products list erase
function erasePreviousList() {
	eraseCookie('OnsemiPreviousProducts');
	document.forms['previousProducts'].elements['id'].value='';
	document.forms['previousProducts'].elements['id'].disabled='true';
}

// Set Netscape up to run the "captureMousePosition" function whenever // the mouse is moved. For Internet Explorer and Netscape 6, you can capture // the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition; } 
else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition; }
else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition; } 

// Global variables 
xMousePos = 0; // Horizontal position of the mouse on the screen 
yMousePos = 0; // Vertical position of the mouse on the screen 
xMousePosMax = 0; // Width of the page 
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
//        xMousePosMax = window.innerWidth+window.pageXOffset;
//        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.clientX; //+document.documentElement.scrollLeft;
        yMousePos = window.event.clientY; //+document.documentElement.scrollTop;
//        xMousePosMax = document.body.clientWidth+document.documentElement.scrollLeft;
//        yMousePosMax = document.body.clientHeight+document.documentElement.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.clientX;
        yMousePos = e.clientY;
//        xMousePosMax = window.innerWidth+window.pageXOffset;
//        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function clearInput(input, text) {
	if (text==null) {
		text="Enter part#/keyword";
	}
	if (input.value==text)
	  input.value="";
}

// sets element with id elmName checked value to true(default) or false
function setChecked(elmName, checked) {
	if (checked==null) {
		//default is true
		checked=true;
	}
	var elm = document.getElementById(elmName);
	if (elm!=null) {
		elm.checked=checked;
	}
}

function cntrSubmit(searchString) {
    cntAlphaNum = 0;
    allowedChars = new Array("*","-",".",",","/"," ","\"");
    
    while (searchString.charCodeAt(searchString.length-1)==32) {
        searchString = searchString.substr(0,searchString.length-1);
    }
    for ( i = 0; i < searchString.length; i++ ) {
        asc = searchString.toUpperCase().charCodeAt(i);
        if ( ((asc >= 48) && (asc <= 57)) || ((asc >= 65) && (asc <= 90)) ) {
            cntAlphaNum++;
        } else {
            found = false;
            for (j = 0; j < allowedChars.length; j++) {
                if ((asc == allowedChars[j].charCodeAt(0))) {
                    found = true;
                }
            }
            if (!found) {
                chars = "";
                for (k = 0; k < allowedChars.length; k++) {
                    chars+=", " + allowedChars[k];
                }
                alert("Only the following characters can be entered search : " + 
                "{A-Z, 0-9" +chars+" }");
                return false;
            }
        }
   }
   if ( cntAlphaNum < 3 ) {
        alert("You must enter at least 3 characters.");
        return false;
   }
   return true;
}

// global initialization function
function globalInit() {
	scroll.hasHScroll = (document.documentElement.scrollWidth>document.documentElement.clientWidth) ? true:false;
	scroll.hasVScroll = (document.documentElement.scrollHeight>document.documentElement.clientHeight) ? true:false;	
	scroll.initWidth = document.documentElement.clientWidth;
	scroll.initHeight = document.documentElement.clientHeight;
}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Klikni na obr?zek pro zav?en? okna" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

window.onload=onLoad;

