// return Object by id

function getObj(id)
{
	itm = null;

	if(document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if(document.all)
	{
		itm = document.all[id];
	}
	else if(document.layers)
	{
		itm = document.layers[id];
	}

	return itm;
}


// get selected value

function getDropDownValue(objID)
{
	Obj = getObj(objID);

    if(Obj.selectedIndex != -1)
	{
        return Obj.options[Obj.selectedIndex].value;
	}
	else
	   return '';
}

function showHide(element, controller) {
  if (controller.checked) {
    $(element).hide();
  }
  else {
    $(element).show();
  }
}

function showDiv(divID)
{
	getObj(divID).style.display = "";
}

function hideDiv(divID)
{
	getObj(divID).style.display = "none";
	return false;
}

var IE = document.all ? true : false;
var curX, curY;

function cursorPos(e)
{
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX +
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY +
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }

    curX = cursor.x;
    curY = cursor.y;

    curX += 'px';
  	curY += 'px';

    return true;
}

function findPosX(elemID)
{
	obj = getObj(elemID);
	var curleft = 0;

	if(obj.offsetParent)
	    while(1)
	    {
	      curleft += obj.offsetLeft;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.x)
	    curleft += obj.x;
	return curleft;
}

function findPosY(elemID)
{
	obj = getObj(elemID);
	var curtop = 0;

	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	return curtop;
}

function setPos(objID, x, y)
{
	var obj = getObj(objID);
	obj.style.left = x + 'px';
	obj.style.top = y + 'px';
}

function roundNumber(num, dec)
{
	var result = new String(Math.round(num*Math.pow(10, dec)) / Math.pow(10, dec));

  if (result.indexOf('.') < 0) {
    result += '.00';
  }
  else if (result.indexOf('.') == (result.length - 2)) {
    result += '0'; 
  }

	return result;
}

function vehiclesShowTerms(locId) {
	getTerms(locId);
	getObj('divContent').innerHTML = getObj('term').innerHTML;
	getObj('divWnd').style.left=curX;
	getObj('divWnd').style.top=curY;
	showDiv('divWnd');
	return false;
}

function payNowPopup() {
	getObj('divContent').innerHTML = getObj('payNowDiv').innerHTML;
	getObj('divWnd').style.left=curX;
	getObj('divWnd').style.top=curY;
	showDiv('divWnd');
	return false;
}

function payLocPopup() {
	getObj('divContent').innerHTML = getObj('payLocalDiv').innerHTML;
	getObj('divWnd').style.left=curX;
	getObj('divWnd').style.top=curY;
	showDiv('divWnd');
	return false;
}

