﻿/* bad browser check */
function isIeLessThan7()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{ 
		temp=navigator.appVersion.split('MSIE');

		// Parse the string for the "6" in 6.0
		ieVer=parseInt(temp[1]);

		// Is it less than 7?
		if (ieVer < 7)
			return true;
		else
			return false;
	}
	else
		return false;
}
/* END bad browser check */

function toggleSaveRemove(vin)
{
	if (document.getElementById('save'+vin).style.display!='none')
	{
	document.getElementById('save'+vin).style.display='none';
	document.getElementById('delete'+vin).style.display='block';
	}
	else
	{
	document.getElementById('save'+vin).style.display='block';
	document.getElementById('delete'+vin).style.display='none';
	}
}

/* Window Boundary object*/  
// Object to hold Window Boundary values 
var WindowBounds = new Object();
    WindowBounds.PageWidth  = 0;
    WindowBounds.PageHeight = 0;
    WindowBounds.VisibleTop = 0;
    WindowBounds.VisibleLeft = 0;
    WindowBounds.VisibleWidth  = 0;
    WindowBounds.VisibleHeight = 0;
        
// function to calculate window boundary object values
function GetWindowBounds()
{
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
	{
		WindowBounds.PageWidth = window.innerWidth + window.scrollMaxX;
		WindowBounds.PageHeight = window.innerHeight + window.scrollMaxY;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
	{
		WindowBounds.PageWidth = document.body.scrollWidth;
		WindowBounds.PageHeight = document.body.scrollHeight;
	}
	else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	{ 
		WindowBounds.PageWidth = document.body.offsetWidth + document.body.offsetLeft; 
		WindowBounds.PageHeight = document.body.offsetHeight + document.body.offsetTop; 
	}

    if (document.documentElement && document.documentElement.scrollTop)
    {
        WindowBounds.VisibleTop      = document.documentElement.scrollTop;
        WindowBounds.VisibleLeft     = document.documentElement.scrollLeft;
        WindowBounds.VisibleWidth    = document.documentElement.clientWidth;
        WindowBounds.VisibleHeight   = document.documentElement.clientHeight;
    } 
    else if (document.body)
    {
        WindowBounds.VisibleTop      = document.body.scrollTop;
        WindowBounds.VisibleLeft     = document.body.scrollLeft;
		WindowBounds.VisibleWidth    = document.body.clientWidth;
        WindowBounds.VisibleHeight   = document.body.clientHeight;
    } 
    else
    {
        WindowBounds.VisibleTop      		= window.pageYOffset;
        WindowBounds.VisibleLeft     		= window.pageXOffset;	
        WindowBounds.VisibleWidth    		= window.innerWidth;
        WindowBounds.VisibleHeight   		= window.innerHeight;
    }
	
	if (navigator.userAgent.indexOf('Safari') > -1)
	{
		WindowBounds.VisibleHeight = window.innerHeight;
	}
   	return WindowBounds;
    
}

/* END Window Boundary object*/



/* Simple JavaScript string trim function */
function Trim(s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
    s = s.substring(1,s.length);
  }

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
    s = s.substring(0,s.length-1);
  }
  return s;
}
/* END Simple JavaScript string trim function */


/* Simple JavaScript div show/hide toggle */
function toggleDiv(id)
{
    if (document.getElementById(id).style.display == "block")
        document.getElementById(id).style.display = "none";
    else
        document.getElementById(id).style.display = "block";
        
}
function toggleDivWithImage(id, imgId)
{
	
    if (document.getElementById(id).style.display == "block")
    {
        document.getElementById(id).style.display = "none";
        document.getElementById(imgId).src="images/minus2plus.gif";
	}
    else
    {
        document.getElementById(id).style.display = "block";
        document.getElementById(imgId).src="images/plus2minus.gif";
	}
}
/* END Simple JavaScript div show/hide toggle */



/* Dynamic select options */
function setOptionsWithValues(id, options, values)
{
	clearOptions(id);
	for (i=0; i<options.length; i++)
	{
		appendOptionLastWithValue(id, options[i], values[i]);
	}

}
function setOptions(id, options)
{
	clearOptions(id);
	for (i=0; i<options.length; i++)
	{
		appendOptionLast(id, options[i]);
	}
}
function appendOptionLastWithOptionId(id, option, optionId)
{
	var elOptNew = document.createElement('option');
	elOptNew.text = option;
	elOptNew.value = option;
	elOptNew.id = optionId;
	var elSel = document.getElementById(id);
	if (elSel!=undefined)
	{
		try 
		{
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) 
		{
			elSel.add(elOptNew); // IE only
		}
	}
}
function appendOptionLastWithValue(id, option, value)
{
	var elOptNew = document.createElement('option');
	elOptNew.text = option;
	elOptNew.value = value;
	var elSel = document.getElementById(id);
	if (elSel!=undefined)
	{
		try 
		{
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) 
		{
			elSel.add(elOptNew); // IE only
		}
	}
}
function appendOptionLast(id, option)
{
	appendOptionLastWithValue(id, option, option);
}
function clearOptions(id)
{
	var elSel = document.getElementById(id);
	if (elSel!=undefined)
	{
		var i;
		for (i = elSel.length - 1; i>=0; i--) 
		{
			elSel.remove(i);
		}
	}
}
/* END Dynamic select options  */


/* execute the text in an input field by id */
function execInputString(id)
{
	var code = document.getElementById(id).value;
	eval(code);
}
/* END execute the text in an input field by id */
// Gets the Char Code of the pressed key ...
function getKey(e)
{ 
    var charCode
    if(e && e.which){
        e = e
        charCode = e.which
    }
    else{
        e = event
        charCode = e.keyCode 
    }
	return charCode
}

//checks if the parameter is enter 
function isKeyEnter(charCode)
{ 
    return (charCode == 13) ? true : false;
}

//checks if the parameter is a number
function isKeyNumber(charCode)
{
	return ((charCode >= 48) && (charCode <= 57)) ? true : false;
}

//SCROLLING DIVS

var gabrielsTimer;

function moveDivHorizontal(Direction, innerDivId, contentWidth, outerWidth, stepSpeed, overflowFn, movedFn) 
{
	var obj = document.getElementById(innerDivId);
	var newVal = parseInt(obj.style.left) + (stepSpeed*Direction);
	obj.style.left = ((newVal > 0) ? '0' : ((newVal < outerWidth - contentWidth) ? parseInt(outerWidth - contentWidth) : newVal)) + 'px' ;
	if ((Direction < 0 && newVal < outerWidth - contentWidth) || (Direction > 0 && newVal > 0))
		eval(overflowFn);
	else
		eval(movedFn);
	gabrielsTimer = setTimeout('moveDivHorizontal(' + Direction + ', "' + innerDivId + '", ' + contentWidth + ', ' + outerWidth + ', ' + stepSpeed + ', "' + overflowFn + '", "' + movedFn + '");', 50);
}

function moveDivHorizontalNo() 
{
	clearTimeout(gabrielsTimer);
}

// END OF SCROLLING DIVS
