var defaultEmptyOK = false
var whitespace = " \t\n\r";

var isNav4,   isIE4 ;
var range = "";
var styleObj = "";

if (navigator.appVersion.charAt(0) == "4") {
	if  (navigator.appName == "Netscape"){
		isNav4 = true
	} else {
		isIE4 = true
		range = ".all"
		styleObj = ".style"
	}
}
if(isNav4){
	document.tags.td.fontFamily="arial";
	document.tags.th.fontFamily="arial";
	document.tags.th.color="teal";
	document.tags.th.fontSize="9pt";
	document.tags.td.fontSize="8pt";
	document.tags.caption.fontFamily="arial";
	document.tags.caption.color="teal";
	document.tags.caption.fontSize="9pt";

	document.ids.CLH.fontFamily="arial";
	document.ids.CLH.fontSize="8pt";
	document.ids.Stmnt1.fontSize="9pt";
	document.ids.Stmnt1.color="teal";	
	document.ids.Part1.width="10%";
	document.ids.Part2.width="10%";
	document.ids.Desc.width="20%";
	document.ids.A.width="8%";
	document.ids.B.width="8%";
	document.ids.C.width="8%";
	document.ids.D.width="8%";
	document.ids.R.width="8%";
	document.ids.CLH.width="5%";
	document.ids.Amnt.width="25%";
	document.ids.UL.fontFamily="arial";
	document.ids.UL.fontSize="7pt";
	document.ids.UL.color="red";
}
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function stripLeadingZeros(s)
{
   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), "0"))
       i++;
    
    return s.substring (i, s.length);
}



function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}

function ResetCheckBox(MyCheck, MyValue){
	eval("document." + MyCheck + ".checked=" + MyValue);
}
function SetAmount(MyAmount,MyaValue){

	var remainder= eval(MyaValue + "% LotSize");
	if (remainder >0){
 	var aValue = eval(MyaValue + "+ LotSize - remainder");
	} else {
	var aValue = eval(MyaValue);
	}
	eval("document." + MyAmount + ".value= aValue");
	return aValue;
}

function GetValue(CheckField,AmtField,amt,Desc)
 {
	if (eval("document." + CheckField + ".checked")) 
	{
		var res = "0";
		while(res == "0")
		{
			res=  window.prompt("Enter amount: \n(up to 8 digits)",amt);		
			if(res==null)
			{
				ResetCheckBox(CheckField,0);
				SetAmount(AmtField,"0");
				return false;
			}else	
			{
				res = stripWhitespace(res);
				res = stripLeadingZeros(res);
				if (!isInteger(res))
				{
					res="0";
				}else if (res.length > 8) 
				{
					window.alert("Up to 8 digits only please!");
					res = "0";
				}else 
				{
					res = SetAmount(AmtField,res);
					var K = CheckField.substring(13,CheckField.length);
					var rc= addtoQuote(CheckField, K ,res,Desc)
					if (!rc)
					{		
						ResetCheckBox(CheckField,0);
						SetAmount(AmtField,"0");
						return false;
					}	

				}	
			}
		}		
	}
	else 
	{
		SetAmount(AmtField,"0");
		var K = CheckField.substring(13,CheckField.length);
		var rc= addtoQuote(CheckField, K ,res,Desc);
	}
return true;
}


function ChangeValue(CheckField,AmtField,amt,Desc) {
amt = stripWhitespace(amt);
amt = stripLeadingZeros(amt);
if (amt ==0 ){
	ResetCheckBox(CheckField,0);
	var K = CheckField.substring(13,CheckField.length);
	addtoQuote(CheckField, K ,amt,Desc);
}else if(amt==""){
	ResetCheckBox(CheckField,0);
	SetAmount(AmtField,"0");
}else if(!isInteger(amt)){
	ResetCheckBox(CheckField,0);
	SetAmount(AmtField,"0");
}else {
	ResetCheckBox(CheckField,1);
	amt = SetAmount(AmtField,amt);
	var K = CheckField.substring(13,CheckField.length);
	var rc= addtoQuote( CheckField,K ,amt,Desc)	
	if (!rc)
	{		
		ResetCheckBox(CheckField,0);
		SetAmount(AmtField,"0");
	}	
}

}

var DrawWindow=null;

function openDrawing(Mytitle, Mysrc, MyHeight, MyWidth)
{
Mysrc1 = "http://208.56.145.66/" + Mysrc 

if (!MyWidth){
	MyWidth = 450
}
if(!MyHeight){
	MyHeight = 220
}
LeftPosition = (screen.width) ? (screen.width-MyWidth)/2 : 0;
TopPosition = (screen.height) ? (screen.height-MyHeight)/2 : 0;

openParam = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,dependent=no,width=" + MyWidth + ",height=" + MyHeight + ",top=" + TopPosition + ",left=" + LeftPosition
if (!DrawWindow){
DrawWindow =window.open("","DrawWindow", openParam )
var str = "<HTML>" +
	"<HEAD>" +
	"<TITLE>" + Mytitle +
	"</TITLE>" +
	"<LINK REL=STYLESHEET HREF='pole.css'></LINK>" +

	"</HEAD>" +
	"<BODY  BGCOLOR='teal' > " +
	"<SPAN ID=img >" +
	"<IMG SRC=" + Mysrc  + " ></IMG>" +
	"</SPAN>" +
	"</BODY>" +
	"</HTML>"

self.DrawWindow.document.open();
self.DrawWindow.document.write(str);
self.DrawWindow.document.close();
//self.DrawWindow.moveTo(120,250);
}else {
	self.DrawWindow.focus();
}

}

function CloseWindow()
{
if (isNav4){
	if (DrawWindow){
	if (!DrawWindow.closed) {
		DrawWindow.close();
	}
}
}
else{
	if (DrawWindow){
		DrawWindow.close();
	}
}
 DrawWindow=null;

}

function addtoQuote(CheckField, j ,value,partNum)
{
	if (eval("document." + CheckField + ".checked")) 
	{
		var list = top.menu.findItem(partNum);	
		if (list)
		{ 
			if (window.confirm("Part # :" + partNum + " is already requested! \nDo you wish to change the amount?")){
			top.menu.removeItem(list)
			} else {
				return false;
			}
		}
		if (top.menu.buyItem(partNum , "0", value))
		{
			return true;
		}
		return false;
	} 

	var list = top.menu.findItem(partNum);	
	if (list)
	{ 
		top.menu.removeItem(list)
	}
	return false;
} 
