function ColumnOver(columnName)
{
	var vCol = document.getElementById(columnName);
	if(vCol != null)
		vCol.className = "PaneSelected";
}
function ColumnOff(columnName)
{
	var vCol = document.getElementById(columnName);
	if(vCol != null)
		vCol.className = "NoPaneSelected";
}
function OpenLinkPage(ParentUrl, NewUrl)
{
	window.location.href = ParentUrl;
	window.open(NewUrl);
}
function EditModulePopUp(strUrl)
{
	modWindow= window.open (strUrl,'Modules')//,
	//'left=20,top=20,width=750,height=600,location=0,toolbar=0,scollbars=1,menubar=0,resizable=1,status=1');

}
function EditTabPopUp(strUrl)
{
	modWindow= window.open (strUrl,'Pages',
	'left=20,top=20,width=500,height=250,location=0,toolbar=0,scollbars=1,menubar=0,resizable=1,status=1');
}

function RefreshParent()
{
	if (window.opener && !window.opener.closed)
	{
		window.opener.window.location.href = window.opener.window.location.href;
	}

}

function RefreshParent2(strUrl)
{
	if (window.opener && !window.opener.closed)
	{
		window.opener.window.location.href = strUrl;
	}
}

function RefreshSelf(strUrl)
{
	window.opener.window.location.href = strUrl;
}

function CloseWindow()
{
	window.close();
}

function ShowHideElement(strObj)
{
	var obj = document.getElementById(strObj); 
	if(obj != null)
	{
		if (obj.style.display == '')
		{
			obj.style.display = 'none';
		}
		else
		{
			obj.style.display = '';
		}
	}
}

function BeforePrint()
{
	var obj1 = document.getElementById('tableBannerId');
	obj1.style.display = 'none';
}

function AfterPrint()
{
	var obj1 = document.getElementById('tableBannerId');
	obj1.style.display = '';
}
function ResizeContent()
{
	var obj = document.getElementById('<%= this.bodyMain.ClientID %>');
	var content = document.getElementById('divContent');
	//alert("Body: " + obj);
	//alert("content: " + content);
	var banner = document.getElementById('tableBannerId');
	//alert("banner: " + banner);
	//alert(obj.clientHeight);
	content.style.height = (obj.clientHeight - banner.clientHeight) - 14;
	//content.style.height = content.style.height - 5;
}
// Supplymgmt functions

function DetailsPopUp(strUrl)
{
	modWindow= window.open (strUrl,'Details',
	'left=20,top=20,width=750,height=600,location=0,toolbar=0,scollbars=1,menubar=0,resizable=1,status=1');
		//	'left=20,top=20,width=750,height=600,location=no,toolbar=no,menubar=no,resizable=yes,status=yes');

}
function EnableDiscountOverride(strCkbOverride, strTxtDiscountEa, strTxtDiscountAmt)
{
	var ckbOverride = document.getElementById(strCkbOverride);
	var txtDiscountEa = document.getElementById(strTxtDiscountEa);
	var txtDiscountAmt = document.getElementById(strTxtDiscountAmt);
	if(ckbOverride.checked == true)
	{
		txtDiscountEa.disabled = false;
		txtDiscountAmt.disabled = false;
	}
	else
	{
		txtDiscountEa.disabled = true;
		txtDiscountAmt.disabled = true;
	}
}
function CalcDiscountAmt(strDiscountEa, strDiscountAmt, dWholesale) 
{
	var objDiscountAmt		= document.getElementById(strDiscountAmt);
	var objDiscountEa	= document.getElementById(strDiscountEa);

	spot = objDiscountEa.value.indexOf("%");
	if (spot >= 0)    //percent?
	{
		numpart = objDiscountEa.value.substr(0,spot);
	    
		if (!IsNumber(numpart))
		{
			alert("When entering a percentage, you must also enter a number.");
			return false
	}
	    
		objDiscountAmt.value = RoundDecimals(dWholesale - (dWholesale * (numpart / 100)), 2);
	}
	else
	{
		if (!IsNumber(objDiscountEa.value)) 
		{
			alert("Discount Amount Must Be A Number!");
			return false
		}
		objDiscountAmt.value = RoundDecimals(dWholesale - objDiscountEa.value, 2);
	}
	// Make sure discount difference is not negative
	var dDiscountEaValue = RoundDecimals(dWholesale - objDiscountAmt.value, 2);
	if(dDiscountEaValue < 0)
		dDiscountEaValue = 0;
	objDiscountEa.value = dDiscountEaValue;  
}
      
function CalcDiscountEa(strDiscountEa, strDiscountAmt, dWholesale) 
{
	var objDiscountAmt		= document.getElementById(strDiscountAmt);
	var objDiscountEa	= document.getElementById(strDiscountEa);
	

	if (!IsNumber(objDiscountAmt.value)) 
	{
		alert("Discount Price Must Be A Number!");
		return false
	}
	// Make sure discount difference is not negative
	var dDiscountEaValue = RoundDecimals(dWholesale - objDiscountAmt.value, 2);
	if(dDiscountEaValue < 0)
		dDiscountEaValue = 0;
	objDiscountEa.value = dDiscountEaValue;     
}

// ok

function IsNumber(sText)
{      
	var ValidChars = "0123456789.";

	for (i=0; i<sText.length; i++) 
	{var Char2 = sText.charAt(i);if (ValidChars.indexOf(Char2) == -1)return false;}
	return true;     
}

function RoundDecimals(dNumber, dPlaces) 
{
	var d1 = dNumber * Math.pow(10, dPlaces)
	var d2 = Math.round(d1)
	var d3 = d2 / Math.pow(10, dPlaces)
	return FormatDecimalNumber(d3, dPlaces)
}

function FormatDecimalNumber(roundedValue, decimalPlaces) 
{

    // Convert the number to a string
    var strRoundedValue = roundedValue.toString()
    
    // Locate the decimal point
    var decimalLocation = strRoundedValue.indexOf(".")

    // Is there a decimal point?
    if (decimalLocation == -1) 
    {
        
        // If no, then all decimal places will be padded with 0s
        decimalLength = 0
        
        // If decimalPlaces is greater than zero, tack on a decimal point
        strRoundedValue += decimalPlaces > 0 ? "." : ""
    }
    else 
    {

        // If yes, then only the extra decimal places will be padded with 0s
        decimalLength = strRoundedValue.length - decimalLocation - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var padTotal = decimalPlaces - decimalLength
    
    if (padTotal > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= padTotal; counter++) 
            strRoundedValue += "0"
        }
    return strRoundedValue
}



//End Supplymgmt functions

