



function GetWindowSize(getWidth) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth + ', Height = ' + myHeight);
  if (getWidth) 
    return myWidth
  else
    return myHeight
  
}




function FindPosX(obj)
{
    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(obj)
{
    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 FindHeight(obj)
{
    return (obj.offsetHeight);
}



function FindWidth(obj)
{
    return (obj.offsetWidth);
}


function SetCookie(name, value, isSession) 
{
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	
	var newCookie = name + "=" + value + "; path=/; "
	if (isSession == false)
		newCookie += "expires=" + expDate.toGMTString();
	document.cookie = newCookie;
}




function GetCookie(name) 
{
	var allCookies = String(document.cookie);	
	var cookieStart = allCookies.indexOf(name);
	if(cookieStart != -1) 
	{
		cookieStart = cookieStart + name.length + 1;
		var cookieEnd = allCookies.indexOf(";", cookieStart);
		if(cookieEnd == -1) 
		{
		    cookieEnd = allCookies.length;
		}
		return allCookies.substring(cookieStart, cookieEnd);
	} 
	else 
	{
		return false;
	}
}


function InsertAtCursor(fld, val) 
{
	if (document.selection) 
	{
		//ie support
		fld.focus();
		sel = document.selection.createRange();
		sel.text = val;
	}
	else if (fld.selectionStart || fld.selectionStart == "0") 
	{
		//moz/netscape support
		var startPos = fld.selectionStart;
		var endPos = fld.selectionEnd;
		fld.value = fld.value.substring(0, startPos) + val + fld.value.substring(endPos, fld.value.length);
	} 
	else 
	{
		fld.value += val;
	}
}



function PopulateRanges(data, fldId)
{
    var fld = document.getElementById(fldId);
    ClearListBox(fld);
    var dataArray = data.split(";");
    var opt = new Option("<Select Range>", "0");
            fld.options[0] = opt;
    var curOpt = 1;
    for (var i=0; i < dataArray.length; i++)
    {
        var thisOpt = dataArray[i].split (",");
        var opt = new Option(thisOpt[1], thisOpt[0]);
        if (thisOpt[0] != '')
        {
            fld.options[curOpt++] = opt;
        }
    }
    fld.style.backgroundColor = '#ffffff';
}


function ClearListBox (fld)
{
    while (fld.options.length > 0)
    {
        fld.options[0] = null;
    }
}

function UrlEncode(str) 
{
    str = escape(str);
    str = str.replace('+', '%2B');
    str = str.replace('%20', '+');
    str = str.replace('*', '%2A');
    str = str.replace('/', '%2F');
    str = str.replace('@', '%40');
    return str;
}



function PopulateItems(data, fldId, optsIncluded)
{
    var fldIdLhs = "cbo_" + fldId + "_Avail";
//alert (fldIdLhs);
    var fld = document.getElementById(fldIdLhs);
    ClearListBox(fld);
    var dataArray = data.split(";");
    var re = /~~/i;
    var curOpt = 0;
    if (optsIncluded == false)
    {
        for (var i=0; i < dataArray.length; i++)
        {
            var thisOpt = dataArray[i].split (",");
            var opt = new Option(thisOpt[2].replace(re,","), thisOpt[0]);
            if (thisOpt[0] != '')
            {
                fld.options[curOpt++] = opt;
            }
        }
    }
    else
    {
        for (var i=0; i < dataArray.length; i++)
        {
            var thisOpt = dataArray[i].split (",");
            var opt = new Option(thisOpt[6].replace(re,","), thisOpt[0] + "-" + thisOpt[8]);
            if (thisOpt[0] != '')
            {
                fld.options[curOpt++] = opt;
            }
        }
    }
}



function ImperialToMetricWgt(impValue, unit)
{
    var metValue = (impValue * 453.59237) / unit;
    //alert (impValue + ", " + metValue);
    
    var ret = metValue * 100;
    ret = Math.round(ret);
    ret /= 100;
    return (ret);
}




function ImperialToMetricLen(impValue, unit)
{
    var metValue = (impValue * 0.0254) / unit;
    //alert (impValue + ", " + metValue);
    var ret = metValue * 100;
    ret = Math.round(ret);
    ret /= 100;
    return (ret);
}
