﻿// JavaScript Document

//Added By ECSR, JAN 20, 2006
//To validate input entered into Quality text box
//Start

function checkfields()
{	
	var Qty = document.frmproductDetails.txtQty.value;

	if(document.frmproductDetails.txtQty.value=="")
		{
			alert("Please Enter Quantity.")
			document.frmproductDetails.txtQty.focus();
			return false;
		}  else if (isNaN(Qty) || (Qty<=0)) {
			alert("Please enter positive numbers only in Quantity.")
			document.frmproductDetails.txtQty.select();
			return false;
		} 
	
	return true;
}

//Added By ECSR, JAN 20, 2006
//To validate input entered into Quality text box
//End

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var mrg,mrgp;

function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}


function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}


function calcMargins()
{
	var uc,rp,margin,marginpercent,p4,p8,p12,up,qty;
	var msgstr,msgstr1;
	var i;
	qty=document.frmproductDetails.txtQty.value;
		
	for(i=0;i<document.frmproductDetails.elements.length;i++)
	{
		if (document.frmproductDetails.elements[i].type=="hidden")
		{
			if (document.frmproductDetails.elements[i].name=="txtUC")
			{
				uc=document.frmproductDetails.elements[i].value
			}
			
			else if (document.frmproductDetails.elements[i].name=="txtRP")
			{
				rp=document.frmproductDetails.elements[i].value
				//up=rp;
			}
			else if (document.frmproductDetails.elements[i].name=="txt4P")
			{
				p4=document.frmproductDetails.elements[i].value
				//up=p4/4;
			}
			else if (document.frmproductDetails.elements[i].name=="txt8P")
			{
				p8=document.frmproductDetails.elements[i].value
				//up=p8/8;
			}
			else if (document.frmproductDetails.elements[i].name=="txt12P")
			{
				p12=document.frmproductDetails.elements[i].value
				//up=p12/12;
			}
		}
	}
	if(qty>=1 && qty<4)
		up=rp;
	else if(qty>=4 && qty<8)
		up=p4/4; 
	else if(qty>=8 && qty<12)
		up=p8/8;
	else if(qty>=12)
		up=p12/12;
	margin=((up*qty)-(uc*qty));
	marginpercent =(margin/(up*qty)) *100;
	msgstr=new String();
	msgstr="$"+FormatNumber(margin,2); 
	msgstr1=new String();
	msgstr1=FormatNumber(marginpercent,2)
	msgstr=msgstr.concat(" ("+msgstr1+"%)")  
	document.getElementById("margindisplay").innerText=msgstr   
	//document.getElementById("margincol").innerText=msgstr   
}



