//////////////////////////////////////////////////////////////////////////////////////////////////////////
//igs global js file containing global cart functions
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//new universal functions
function submitFormWithType(formname,type)
{
	document.forms[formname].Type.value = type;
	document.forms[formname].submit();
}

function submitFormWithTypeAndFields(formname,type,f1,f2,f3,f4,f5)
{
	document.forms[formname].Type.value = type;
	document.forms[formname].Field1.value = f1;
	document.forms[formname].Field2.value = f2;
	document.forms[formname].Field3.value = f3;
	document.forms[formname].Field4.value = f4;
	document.forms[formname].Field5.value = f5;
	document.forms[formname].submit();
}

//used on search function
function submitForm(formname)
{
	document.forms[formname].submit();
}

function submitFormtest(formname)
{
	alert(formname);
	alert(document.forms[formname].qhref.value);
	alert(document.forms[formname].qhctpo.value);
	document.forms[formname].submit();
}

function redirectto(furl)
{
	self.parent.location=furl;
}

function validqty(name,enter){
	if (digitvalidation(document.forms[name].Qty,1,1000,"Quantity must be a valid amount!",'i')==false) {
		document.forms[name].Qty.focus();
		if(enter=='Y'){
			return false;
		}
	}else {
		var maxqtyfield = document.forms[name].max;
		var maxqty = 0;
		if(maxqtyfield!=null){
			maxqty = parseFloat(maxqtyfield.value);
		}

		passqtytest=true;

		if(maxqty>0){
			//alert('maxqty='+maxqty);
			var qty = parseFloat(document.forms[name].Qty.value);
			if(qty>maxqty){
				passqtytest=false;
				alert('Quantity Entered is greater than the Maximum Quantity Allowed('+maxqty+')');
				document.forms[name].Qty.focus();
				if(enter=='Y'){
					return false;
				}
			}
		}

		if(passqtytest){
			if(enter=='Y'){
				return true;
			}else{
				document.forms[name].submit();
			}
		}
	}
}

function validqtymatrix(name,enter){
	var idx = document.forms[name].comboQty.selectedIndex;
	document.forms[name].Qty.value = document.forms[name].comboQty.options[idx].value;
	document.forms[name].sequence.value = document.forms[name].elements["fseq"+idx].value;

	return validqty(name,enter);
}

function validqtycombo(name,enter){
	document.forms[name].Field1.value = document.forms[name].itemcombo.options[document.forms[name].itemcombo.selectedIndex].value;

	return validqty(name,enter);
}

function phoneCheck(name) {
				var phone = document.forms[name].phone1.value;
				if ((document.forms[name].phone1.value=='0') || (document.forms[name].phone1.value=='')){
					document.write('(&nbsp;<input class=formBG type=text name=sPhone1 value="" size=3 maxlength=3>&nbsp;)');
					}
				else{
					document.write('(&nbsp;<input class=formBG type=text name=sPhone1 value='+phone+' size=3 maxlength=3>&nbsp;)');
					}
				}
function writePhoneIntl(name) {
				var phoneIntl = document.forms[name].phone1.value;
				if (document.forms[name].phone1.value==''){
					document.write('');
					}
				else{
					document.write('Intl. Prefix&nbsp;<input class=formBG type=text name=sPhone1 value='+phoneIntl+' size=3 maxlength=3>&nbsp;');
					}
				}
function writeEvePhoneIntl(name) {
				var phoneIntl = document.forms[name].phone1.value;
				if (document.forms[name].phone1.value!=''){
					document.write('Intl. Prefix&nbsp;<input class=formBG type=text name=sPhone4 value=\'\' size=3 maxlength=3>&nbsp;');
					}
				else{
					document.write('');
					}
				}

function writePhoneExt(name) {
				var phoneExt = document.forms[name].phone3.value;
				if (document.forms[name].phone3.value==''){
					document.write('');
					}
				else{
					document.write('Ext.&nbsp;<input class=formBG type=text name=sPhone1 value='+phoneExt+' size=4 maxlength=4>&nbsp;');
					}
				}
function writeEvePhoneExt(name) {
				var phoneIntl = document.forms[name].phone3.value;
				if (document.forms[name].phone3.value!=''){
					document.write('Ext.&nbsp;<input class=formBG type=text name=sPhone6 value=\'\' size=4 maxlength=4>&nbsp;');
					}
				else{
					document.write('');
					}
				}

//from itemlookupcombo
function editAnItem(name,item) {
	document.forms[name].id.value = item;
	document.forms[name].submit();
}

function buildComboRows(name) {
	var count = document.forms[name].lcount.value;
	for(i=0;i<count;i++) {
		var item = document.forms[name].elements['litem'+i].value;
		var desc = document.forms[name].elements['ldesc'+i].value;
		var qty = document.forms[name].elements['lqty'+i].value;
		var price = '$'+document.forms[name].elements['lprice'+i].value;
		var maint = document.forms[name].elements['lmaint'+i].value;
		var editalign = 'align="center"';
		var edit = maint;
		if(maint == 0) {
			editalign = 'align="center"';
			edit = '';
		}else {
			editalign = 'align="left"';
			edit = '<a href="javascript:editAnItem(\'itemedit\',\''+maint+'\')">Edit Item</a>&nbsp;&nbsp; ';
		}
		document.write('<tr><td '+editalign+' class="small" nowrap>'+edit+item+'</td><td align="center" class="small">'+desc+'</td><td align="center" class="small">'+qty+'</td><td align="center" class="small">'+price+'</td></tr>');
	}
}

//Specific for Humana to display AVAILABLE instead of QUANTITY ON HAND
function buildComboRowsHumana(name) {
    var count = document.forms[name].lcount.value;
    for(i=0;i<count;i++) {
        var item = document.forms[name].elements['litem'+i].value;
        var desc = document.forms[name].elements['ldesc'+i].value;
        var qty = document.forms[name].elements['lqty'+i].value;
        var price = '$'+document.forms[name].elements['lprice'+i].value;
        var maint = document.forms[name].elements['lmaint'+i].value;
        var editalign = 'align="center"';
        var edit = maint;
        if(maint == 0) {
            editalign = 'align="center"';
            edit = '';
        }else {
            editalign = 'align="left"';
            edit = '<a href="javascript:editAnItem(\'itemedit\',\''+maint+'\')">Edit Item</a>&nbsp;&nbsp; ';
        }
        document.write('<tr><td '+editalign+' class="matrixdata" nowrap>'+edit+item+'</td><td align="center" class="matrixdata">'+desc+'</td><td align="center" class="matrixdata">Available</td><td align="center" class="matrixdata">'+price+'</td></tr>');
    }
}

//from search-auth.js
//made office supplies a checked checkbox 10/25/05
function checkBoxAuth() {
	if (document.srchform.OfficeSupplyAuth.value == 'true') {
		document.write('<br>&nbsp;&nbsp;<font size="1">Managed Inventory<input type="checkbox" value="1" name="minv" checked>&nbsp;Office Supplies</font><input type="checkbox" value="1" name="oinv" checked>');
	}else {
		document.write('<input type="hidden" value="1" name="minv">');
	}
}

//from WaitHeader
var counter = 0;
function waitUpdate() {
counter ++;
if (counter<=10) {

   ID=window.setTimeout("waitUpdate();",1000);
}
else {
	submitFormWithTypeAndFields('gform','73',document.forms["wait"].as400key.value,document.forms["wait"].lineitemnumber.value);
	}
}

//from catitemlistheader
function digitvalidation(entered, min, max, alertbox, datatype)
{
	with (entered){
		checkvalue=parseFloat(value);
		if(datatype){
			smalldatatype=datatype.toLowerCase();
			if(smalldatatype.charAt(0)=="i"){
				checkvalue=parseInt(value);
				if((value.indexOf(".")!=-1)||(value.indexOf("-")!=-1)){
					checkvalue=checkvalue+1
				}
			}
		}

		if((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue){
			if(alertbox!=""){
				alert(alertbox);
			}
			return false;
		}else {
			return true;
		}
	}
}

//from viewcart
function adjustqty(name,type,field1,enter)
{
	document.forms['gform'].Type.value = type;
	document.forms['gform'].Field1.value = field1;
	document.forms['gform'].Qty.value = document.forms[name].Qty.value;

	var sequenceidx = document.forms[name].Qty.selectedIndex;
	//alert(sequenceidx);
	if(sequenceidx!=null){
		var seq = document.forms[name].elements["fseq"+sequenceidx].value;
		document.forms['gform'].Field2.value = seq;
	}

	//document.forms['gform'].submit();

	var maxqtyfield = document.forms[name].max;
	var maxqty = 0;
	if(maxqtyfield!=null){
		maxqty = parseFloat(maxqtyfield.value);
	}

	passqtytest=true;

	if(maxqty>0){
		//alert('maxqty='+maxqty);
		var qty = parseFloat(document.forms[name].Qty.value);
		if(qty>maxqty){
			passqtytest=false;
			alert('Quantity Entered is greater than the Maximum Quantity Allowed('+maxqty+')');
			document.forms[name].Qty.focus();
			if(enter=='Y'){
				return false;
			}
		}
	}

	if(passqtytest){
		if(enter=='Y'){
			return true;
		}else{
			document.forms['gform'].submit();
		}
	}
}

function adjustqtyIGS(name,type,field1,enter)
{
	document.forms['gform'].Type.value = type;
	document.forms['gform'].Field1.value = field1;
	document.forms['gform'].Qty.value = document.forms[name].Qty.value;

	var sequenceidx = document.forms[name].Qty.selectedIndex;
	//alert(sequenceidx);
	if(sequenceidx!=null){
		var seq = document.forms[name].elements["fseq"+sequenceidx].value;
		document.forms['gform'].Field2.value = seq;
	}

	//document.forms['gform'].submit();

	var maxqtyfield = document.forms[name].max;
	var maxqty = 0;
	if(maxqtyfield!=null){
		maxqty = parseFloat(maxqtyfield.value);
	}

	passqtytest=true;

	if(maxqty>0){
		//alert('maxqty='+maxqty);
		var qty = parseFloat(document.forms[name].Qty.value);
		if(qty>maxqty){
			passqtytest=false;
			alert('Quantity Entered is greater than the Maximum Quantity Allowed('+maxqty+')');
			document.forms[name].Qty.focus();
			if(enter=='Y'){
				return false;
			}
		}
	}	
	
	var qty = parseFloat(document.forms[name].Qty.value);	
	//alert(qty);
	if (isNaN(qty)){
		passqtytest=false;
		document.forms['gform'].Qty.value = 0;
		alert ('Please enter a quantity!');
		document.forms[name].Qty.focus();
	}

	if(passqtytest){
		if(enter=='Y'){
			return true;
		}else{
			document.forms['gform'].submit();
		}
	}
}

function deleteqty(type,field1) {
	document.forms['gform'].Type.value = type;
	document.forms['gform'].Field1.value = field1;
	document.forms['gform'].Qty.value = 0;
	document.forms['gform'].submit();
}

function evalbuymore(name)
{
	if(document.forms[name].Buy.value=="Y"){
		document.write('<a href="javascript:submitFormWithType(\'gform\',\'1\')">');
	}else{
		document.write('<a href="http://saturn.igetsmart.com/'+document.forms[name].Load.value+'/shop.html">');
	}
}

//from shipping
function nullvalidate(entered, alertbox)
{
	with (entered){
		if (value==null || value==""){
			if(name=="sState"){
				var idx = selectedIndex;
				var test = options[idx].value;
				//alert("test:"+test);
				if (test==null || test==""){
					if (alertbox!="") {
						alert(alertbox);
					}
					return false;
				}else{
					return true;
				}
			}else{
				if (alertbox!="") {
					alert(alertbox);
				}
				return false;
			}
		}else{
			return true;
		}
	}
}

function formvalidate(thisform)
{
	with (thisform)
	{
		if(((sCompany.value == null ) && (sAttn.value == null)) || ((sCompany.value == "") && (sAttn.value == ""))) {
			alert('Please fill out either the Company Name or the Attention field.');
			return false;
		}
		else
		{
			if (nullvalidate(sAddr1,"Address1 is invalid!")==false) {
				sAddr1.focus();
				return false;
			}
			if (nullvalidate(sCity,"City is invalid!")==false) {
				sCity.focus();
				return false;
			}
			if (nullvalidate(sState,"State is invalid!")==false) {
				sState.focus();
				return false;
			}
			if (nullvalidate(sZip,"ZipCode is invalid!")==false) {
				sZip.focus();
				return false;
			}
			if (shipvalidate()==false){
				sShipvia.focus();
				return false;
			}
			if (document.forms[0].ref.value == 'Y') {

				if (nullvalidate(sRelease,"Reference# is invalid!")==false) {
					sRelease.focus();
					return false;
				}
			}
		}
	}
	return true;
}

function validateshipping(name)
{
	var passedTest = true;
	if(((document.forms[name].sCompany.value == null ) && (document.forms[name].sAttn.value == null)) || ((document.forms[name].sCompany.value == "") && (document.forms[name].sAttn.value == ""))) {
		alert('Please fill out either the Company Name or the Attention field.');
		document.forms[name].sCompany.focus();
		passedTest = false;
	}else if(nullvalidate(document.forms[name].sAddr1,'Address1 is invalid!')==false){
		document.forms[name].sAddr1.focus();
		passedTest = false;
	}else if(nullvalidate(document.forms[name].sCity,'City is invalid!')==false){
		document.forms[name].sCity.focus();
		passedTest = false;
	//}else if(nullvalidate(document.forms[name].sState,'State is invalid!')==false){
		//document.forms[name].sState.focus();
		//passedTest = false;
	}else if(nullvalidate(document.forms[name].sZip,'ZipCode is invalid!')==false){
		document.forms[name].sZip.focus();
		passedTest = false;
	}else if(document.forms[name].ref.value == 'Y'){
		if(nullvalidate(document.forms[name].sRelease,'Reference# is invalid!')==false){
			document.forms[name].sRelease.focus();
			passedTest = false;
		}
	}

	if(passedTest){
		document.forms[name].submit();
	}
}

function writestar(name)
{
	if (document.forms[name].ref.value == 'Y') {
		document.write('<FONT COLOR="#FF0000">*</FONT>');
	}
}

function writediscount(name) {
	if (document.forms[name].discountVar) {
		if (document.forms[name].discountVar.value == 'true') {
			document.write("<tr><td class=large size=4>Enter Coupon# </td>");
			document.write("<td><input maxlength=35 size=35 type='text' name='sDiscount' value='' class=formBG></td></tr>");
		}
	}
}


//for new Site Generator to clear up classes
function writeshipdiscount(name) {
	if (document.forms[name].discountVar) {
		if (document.forms[name].discountVar.value == 'true') {
			document.write("<tr><td class=shipToBold size=4>Enter Coupon# </td>");
			document.write("<td><input maxlength=35 size=35 type='text' name='sDiscount' value='' class=formBG></td></tr>");
		}
	}
}

function shipvalidate(name)
{
	var cnty = document.forms[name].sCountry.options[document.forms[name].sCountry.selectedIndex].value;
	var via = document.forms[name].sShipvia.selectedIndex+1;
	var viaYN = document.forms[name].elements["flag"+via].value;

	if (cnty != ""){
		if (viaYN == "Y") {
			return true;
		}else{
			alert("Invalid Shipping Method!");
			return false;
		}
	}else {
		if (viaYN == "N") {
			return true;
		}else{
			alert("Invalid Shipping Method!");
			return false;
		}
	}
}

//from checkdiscount.js
function adddiscountamount(discountamount)
{
	if ((discountamount=="0.00")||(discountamount=="N/A")) {
		return false;
	}else {
		document.write("<tr><td colspan=7><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
		document.write("<tr>");
		document.write("	<td align=center class='cartRRowTotals' nowrap>Discount Amount:</td>");
		document.write("	<td width=7 class='cartRRowTotals'>&nbsp;</td>");
		document.write("	<td class='cartRRowTotals'>&nbsp;</td>");
		document.write("	<td width=7 class='cartRRowTotals'>&nbsp;</td>");
		document.write("	<td class='cartRRowTotals'>&nbsp;</td>");
		document.write("	<td width=7 class='cartRRowTotals'>&nbsp;</td>");
		document.write("	<td align=center class='cartRRowTotals'>$ " +discountamount+"</td>");
		document.write("</tr>");
		document.write("<tr><td colspan=7><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
	}
}

// T used on new formatted Template sites with 4 tds
function adddiscountamountT(discountamount)
{
	if ((discountamount=="0.00")||(discountamount=="N/A")) {
		return false;
	}else {
		document.write("<tr><td colspan='4'><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
		document.write("<tr class='regular'>");
		document.write("	<td colspan='2'>Discount Amount:</td>");
		document.write("	<td>&nbsp;</td>");
		document.write("	<td align='right'>$ " +discountamount+"&nbsp;&nbsp;</td>");
		document.write("</tr>");
		document.write("<tr><td colspan=4><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
	}
}

// adddiscountamountcard used on Cardinal site
function adddiscountamountcard(discountamount)
{
	if ((discountamount=="0.00")||(discountamount=="N/A")) {
		return false;
	}else {
		document.write("<tr><td colspan='4'><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
		document.write("<tr class='regular'>");
		document.write("	<td colspan='2'>Gift Certificate Amount:</td>");
		document.write("	<td>&nbsp;</td>");
		document.write("	<td align='right'>$ " +discountamount+"&nbsp;&nbsp;</td>");
		document.write("</tr>");
		document.write("<tr><td colspan=4><img src='https://saturn.igetsmart.com/igs/images/1x1.gif' border=0 height=1></td></tr>");
	}
}

function addinfomessage(infomessage)
{
	if (infomessage!="none") {
		document.write("<TR bgcolor='#FFFFFF'>");
		document.write("	<TD ALIGN=center><FONT SIZE=2 COLOR='black' FACE='Arial,Times New Roman'>Info Message:</FONT></TD>");
		document.write("	<TD COLSPAN='6' ALIGN=left><FONT SIZE=2 COLOR='black' FACE='Arial,Times New Roman'>" +infomessage+"</FONT></TD>");
		document.write("</tr>");
	}
}
// T used on new formatted Template sites with 4 tds
function addinfomessageT(infomessage)
{
	if (infomessage!="none") {
		document.write("<tr class='regular'>");
		document.write("	<td>Info Message:</td>");
		document.write("	<td colspan='3'>" +infomessage+"&nbsp;&nbsp;</td>");
		document.write("</tr>");
	}
}


//from filemaintenance
function confirmdeletion(name,imageClass)
{
	if (confirm("Are you sure?")) {
		document.forms[name].Type.value = '2002';
		document.forms[name].imageClass.value=imageClass;
		document.forms[name].submit();
	}
}

function getfileupload(name,Type, company, customer, id, imageClass, objectType)
{
	document.forms[name].Type.value = Type;
	document.forms[name].company.value = company;
	document.forms[name].customer.value = customer;
	document.forms[name].id.value = id;
	document.forms[name].imageClass.value = imageClass;
	document.forms[name].objectType.value = objectType;
	document.forms[name].submit();
}

//from filemaintenance
function uploadfile(name)
{
	strComment = document.forms[name].Comment.value;
	strFile = document.forms[name].File.value;
	if (strComment.length==0) {
		alert("Comment required. This entry must be completed before the form can be submitted for processing.");
		document.forms[name].Comment.focus();
		return false;
	}else{
		if (strFile.length==0) {
			alert("File name required. This entry must be completed before the form can be submitted for processing.");
			document.forms[name].File.focus();
			return false;
		}else{
			return true;
		}
	}
}

//from typelayoutimagesheader
function gettypelayoutdetail(name,type,imagekey,load,company,customer,id, optype,typelayoutkey,imagetype)
{
	document.forms[name].Type.value = type
	document.forms[name].ImageKey.value = imagekey;
	document.forms[name].Load.value = load;
	document.forms[name].company.value = company;
	document.forms[name].customer.value = customer;
	document.forms[name].id.value = id;
	document.forms[name].operationtype.value = optype;
	document.forms[name].typelayoutkey.value = typelayoutkey;
	document.forms[name].imagetype.value = imagetype;

	if(optype == "Delete"){
		if(confirm("Are you sure ?")){
			document.forms[name].Type.value = '3003';
			document.forms[name].submit();
		}
	}else{
		document.forms[name].submit();
	}
}

//from limitedinputtextfieldheader
function changeColor(name,f,c)
{
	document.forms[name].elements[f].style.color = c;
}

function lisub(name,type,limitedinputtextkey,text,warning,load,textlayoutkey,seq)
{
	document.forms[name].Type.value = type
	document.forms[name].LimitedInputTextKey.value = limitedinputtextkey
	document.forms[name].FieldText.value = text
	document.forms[name].Load.value = load
	document.forms[name].TextLayoutKey.value = textlayoutkey
	document.forms[name].TextSeq.value = seq
	if(warning == "Y"){
		if(confirm("Might affect some other textlayouts..Are you sure ?")){
			document.forms[name].submit()
		}
	}else{
		document.forms[name].submit()
	}
}

function addsub(name,type,limitedinputtextkey,warning,text,load,textlayoutkey,seq)
{
	document.forms[name].Type.value = type
	document.forms[name].LimitedInputTextKey.value = limitedinputtextkey
	document.forms[name].FieldText.value = text
	document.forms[name].Load.value = load
	document.forms[name].TextLayoutKey.value = textlayoutkey
	document.forms[name].TextSeq.value = seq
	
        document.forms[name].submit()	
}

//from settextheader
function hist(field1,field2)
{
	//document.forms['gform'].field1.value = document.forms['gform'].field2.options[document.forms['gform'].field2.selectedIndex].value;
	//.elements["fseq"+idx].value

	document.forms['gform'].elements[field1].value = document.forms['gform'].elements[field2].options[document.forms['gform'].elements[field2].selectedIndex].value;
}

function openstatus(path, x, y)
{
	detailWin = eval("'status=yes,menubar=no,scrollbars=yes,resizable=yes,width=" + x + ",height=" + y + "'");
	window.open(path, '_blank', detailWin);
	detailWin.opener=window;
}
function openstatustool(path, x, y)
{
	detailWin = eval("'status=yes,toolbar=yes,scrollbars=yes,resizable=no,width=" + x + ",height=" + y + "'");
	window.open(path, '_blank', detailWin);
	detailWin.opener=window;
}

//for Cardinal
function openstatus2(path, x, y)
{
	detailWin = eval("'status=no,toolbar=no,titlebar=no,menubar=no,scrollbars=no,resizable=no,width=" + x + ",height=" + y + "'");
	window.open(path, 'new_win', detailWin);
	detailWin.opener=window;
}

function checkonload(name)
{
	if(document.forms[name].onload.value=="Y"){
		document.forms[name].submit();
	}
}

//from wait
var counter = 0;

function runwait()
{
	counter ++;
	if (counter<=10) {
		ID=window.setTimeout("runwait();",1000);
	}else{
		submitForm('gform');
	}
}

//from itemsearchheader
function checkoffice(name,type,field1,field2,field3,field4,field5,officeCheck)
{
	var typeme = document.forms[name].Type.value;
	if (officeCheck == '1') {
		typeme = '8';
	}else if (officeCheck == '0') {
		typeme = '5';
	}

	if(document.forms[name].isQuote !=null){
		var quotetest = document.forms[name].isQuote.value;
		if (quotetest == 'true') {
			typeme = '127';
		}
	}

	submitFormWithTypeAndFields(name,typeme,field1,field2,field3,field4,field5);
}

//for sites with three release fields, like tektronixtwo - not really even used for them since theirs loads from page not lib
function joinThreeReleaseFields(name)
{
	var combinedSRelease;
	combinedSRelease  = document.forms[name].sRelease0.value;
	combinedSRelease += '-';
	combinedSRelease += document.forms[name].sRelease1.value;
	combinedSRelease += '-';
	combinedSRelease += document.forms[name].sRelease2.value;
	combinedSRelease += '-';
	combinedSRelease += document.forms[name].sRelease3.value;
	document.forms[name].sRelease.value = combinedSRelease;
}

function submitImprintText(name)
{

	var textnum = document.forms[name].textnum.value;
	var pass = true;
	for (var i = 0; i < textnum; i++) {
		var min = document.forms[name].elements['ms'+i].value;
		var fvalue = document.forms[name].elements['tt'+i].value;
		var flength = fvalue.length;

		if(flength<min){
			pass = false;
			alert('A field has not met minimum length!');
			document.forms[name].elements['tt'+i].focus();
		}
	}

	if(pass){
		submitForm(name);
	}
}


function RTrim(strMyString)
{
	return(strMyString.replace(/^\s*/,""));
}

function LTrim(strMyString)
{
	return(strMyString.replace(/\s*$/, ""));
}

function Trim(strMyString)
{
	return(RTrim(LTrim(strMyString)));
}

//pdf functionality for itemLookup(s)
function pdf()
{
	var path = document.forms['pdf'].pdfpath.value;
	if ((path == null)||(path == "None")||(path == "http://saturn.igetsmart.com/servlet/None")) {
		return false;
	}else {
		document.write("<a href='http://www.adobe.com/products/acrobat/readstep.html' target='_blank'>");
		document.write("<img src='http://saturn.igetsmart.com/igs/images/getacro.gif' border='0'></A><BR>");
		document.write("<a href='"+path+"' target='_blank' class='quote'>Click here to view PDF</A>");
	}
}

//build combo box for Cardinal - removed <td '+editalign+' class="matrixdata" nowrap>'+edit+item+'</td>
function buildComboRowsCardinal(name) {
	var count = document.forms[name].lcount.value;
	for(i=0;i<count;i++) {
		var item = document.forms[name].elements['litem'+i].value;
		var desc = document.forms[name].elements['ldesc'+i].value;
		var qty = document.forms[name].elements['lqty'+i].value;
		var price = '$'+document.forms[name].elements['lprice'+i].value;
		var maint = document.forms[name].elements['lmaint'+i].value;
		var editalign = 'align="center"';
		var edit = maint;
		if(maint == 0) {
			editalign = 'align="center"';
			edit = '';
		}else {
			editalign = 'align="left"';
			edit = '<a href="javascript:editAnItem(\'itemedit\',\''+maint+'\')">Edit Item</a>&nbsp;&nbsp; ';
		}
		document.write('<tr><td align="center" class="matrixdata">'+desc+'</td><td align="center" class="matrixdata">'+qty+'</td><td colspan="2" align="center" class="matrixdata">'+price+'</td></tr>');
	}
}

//drop down box for Cardinal's category search
function go1() {
	if (document.forms['selecter1'].elements['select1'].options[document.forms['selecter1'].elements['select1'].selectedIndex].value != "none") {
	location = document.forms['selecter1'].elements['select1'].options[document.forms['selecter1'].elements['select1'].selectedIndex].value
	}
}

//drop down box for Cardinal's price search
function go2() {
	if (document.forms['selecter2'].elements['select2'].options[document.forms['selecter2'].elements['select2'].selectedIndex].value != "none") {
	location = document.forms['selecter2'].elements['select2'].options[document.forms['selecter2'].elements['select2'].selectedIndex].value
	}
}

//drop down box for Cardinal's price search
function go3() {
	if (document.forms['selecter3'].elements['select3'].options[document.forms['selecter3'].elements['select3'].selectedIndex].value != "none") {
	location = document.forms['selecter3'].elements['select3'].options[document.forms['selecter3'].elements['select3'].selectedIndex].value
	}
}

//drop down box for Cardinal's price search
function go4() {
	if (document.forms['selecter4'].elements['select4'].options[document.forms['selecter4'].elements['select4'].selectedIndex].value != "none") {
	location = document.forms['selecter4'].elements['select4'].options[document.forms['selecter4'].elements['select4'].selectedIndex].value
	}
}

//drop down box for Cardinal's price search
function go5() {
	if (document.forms['selecter5'].elements['select5'].options[document.forms['selecter5'].elements['select5'].selectedIndex].value != "none") {
	location = document.forms['selecter5'].elements['select5'].options[document.forms['selecter5'].elements['select5'].selectedIndex].value
	}
}

//drop down box for Cardinal's price search
function go6() {
	if (document.forms['selecter6'].elements['select6'].options[document.forms['selecter6'].elements['select6'].selectedIndex].value != "none") {
	location = document.forms['selecter6'].elements['select6'].options[document.forms['selecter6'].elements['select6'].selectedIndex].value
	}
}



//simple broswer detect and css redirect for GENERIC SIDEBAR - RLC - 08/19/2002
function cssloadcheck(name) {
	browser_version= parseInt(navigator.appVersion);
	browser_type = navigator.appName;

	if(document.all){
		document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/'+name+'/'+name+'basic.css" type="text/css">');
		//alert('IE');
	}else if(document.layers){
		document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/'+name+'/'+name+'basicNetscape.css" type="text/css">');
		//alert('NS4x');
	}else if(document.getElementById){
		document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/'+name+'/'+name+'basic.css" type="text/css">');
		//alert('NS6x');
	}else{
		document.write("Unrecognized Browser Detected");
	}
}

//simple broswer detect and css redirect for Cardinal
function cssCheck() {
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (document.all) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/cardinal/basic.css" type="text/css">');
	//alert('IE');
	}

else if (document.layers) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/cardinal/basicNetscape.css" type="text/css">');
	//alert('NS4x');
	}

else if (document.getElementById) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/cardinal/basic.css" type="text/css">');
	//alert('NS6x');
	}

else {
  document.write("Unrecognized Browser Detected");
	}
}

//simple broswer detect and css redirect for AMS
function cssCheckAMS() {
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (document.all) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/ams/basic.css" type="text/css">');
	//alert('IE');
	}

else if (document.layers) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/ams/basicNetscape.css" type="text/css">');
	//alert('NS4x');
	}

else if (document.getElementById) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/ams/basic.css" type="text/css">');
	//alert('NS6x');
	}

else {
  document.write("Unrecognized Browser Detected");
	}
}

//simple broswer detect and css redirect for SFIStore
function cssCheckSFIStore() {
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (document.all) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/sfistore/basic.css" type="text/css">');
	//alert('IE');
	}

else if (document.layers) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/sfistore/basicNetscape.css" type="text/css">');
	//alert('NS4x');
	}

else if (document.getElementById) {
	document.write('<link rel="stylesheet" href="https://saturn.igetsmart.com/sfistore/basic.css" type="text/css">');
	//alert('NS6x');
	}

else {
  document.write("Unrecognized Browser Detected");
	}
}

//build combo box for AMS - removed <td '+editalign+' class="matrixdata" nowrap>'+edit+item+'</td>
function buildComboRowsAMS(name) {
	var count = document.forms[name].lcount.value;
	for(i=0;i<count;i++) {
		var item = document.forms[name].elements['litem'+i].value;
		var desc = document.forms[name].elements['ldesc'+i].value;
		var qty = document.forms[name].elements['lqty'+i].value;
		var price = '$'+document.forms[name].elements['lprice'+i].value;
		var maint = document.forms[name].elements['lmaint'+i].value;
		var editalign = 'align="center"';
		var edit = maint;
		if(maint == 0) {
			editalign = 'align="center"';
			edit = '';
		}else {
			editalign = 'align="left"';
			edit = '<a href="javascript:editAnItem(\'itemedit\',\''+maint+'\')">Edit Item</a>&nbsp;&nbsp; ';
		}
		document.write('<tr><td align="center" class="matrixdata">'+desc+'</td><td align="center" class="matrixdata">'+qty+'</td><td colspan="2" align="center" class="matrixdata">'+price+'</td></tr>');
	}
}

//build combo box for SFIStore - removed <td '+editalign+' class="matrixdata" nowrap>'+edit+item+'</td>
function buildComboRowsSFIStore(name) {
	var count = document.forms[name].lcount.value;
	for(i=0;i<count;i++) {
		var item = document.forms[name].elements['litem'+i].value;
		var desc = document.forms[name].elements['ldesc'+i].value;
		var qty = document.forms[name].elements['lqty'+i].value;
		var price = '$'+document.forms[name].elements['lprice'+i].value;
		var maint = document.forms[name].elements['lmaint'+i].value;
		var editalign = 'align="center"';
		var edit = maint;
		if(maint == 0) {
			editalign = 'align="center"';
			edit = '';
		}else {
			editalign = 'align="left"';
			edit = '<a href="javascript:editAnItem(\'itemedit\',\''+maint+'\')">Edit Item</a>&nbsp;&nbsp; ';
		}
		document.write('<tr><td align="center" class="matrixdata">'+desc+'</td><td align="center" class="matrixdata">'+qty+'</td><td colspan="2" align="center" class="matrixdata">'+price+'</td></tr>');
	}
}

//for billing page
function validatebilling(name)
{
	var passedTest = true;
	/*if(document.forms[name].bAttn.value == null) {
		alert('Please fill out the Name field.');
		document.forms[name].bAttn.focus();
		passedTest = false;
	}else if(document.forms[name].sAddr1.value == null) {
		alert('Please fill out the Address field.');
		document.forms[name].sAddr1.focus();
		passedTest = false;
	}else if(document.forms[name].sCity.value == null) {
		alert('Please fill out the City field.');
		document.forms[name].sCity.focus();
		passedTest = false;
	}else if(document.forms[name].sZip.value == null) {
		alert('Please fill out the Zip field.');
		document.forms[name].sZip.focus();
		passedTest = false;
	}*/

	if(nullvalidate(document.forms[name].bAddr1,'Address1 is invalid!')==false){
		document.forms[name].bAddr1.focus();
		passedTest = false;
	}else if(nullvalidate(document.forms[name].bCity,'City is invalid!')==false){
		document.forms[name].bCity.focus();
		passedTest = false;
	}else if(nullvalidate(document.forms[name].bZip,'ZipCode is invalid!')==false){
		document.forms[name].bZip.focus();
		passedTest = false;
	}

	if(CheckCardNumber(document.forms[name])){
	}else{
		passedTest = false;
	}
	if(passedTest){
		document.forms[name].submit();
	}
}

function RTrim(strMyString)
{
	return(strMyString.replace(/^\s*/,""));
}

function LTrim(strMyString)
{
	return(strMyString.replace(/\s*$/, ""));
}

function Trim(strMyString)
{
	return(RTrim(LTrim(strMyString)));
}

function trimmer(name){
	document.forms[name].bAttn.value = Trim(document.forms[name].bAttn.value);
	document.forms[name].bAddr1.value = Trim(document.forms[name].bAddr1.value);
}

// displays message if there's a credit card on file (added 12/5/03) 
// ONLY WORKS ON WORKFLOW SITE!! Site properties and user account both combine to submit info
function ccOnFile(name) {
	var cc = document.forms[name].shippingverifyerror.value;
	// checks if shippingverifyerror contains the word 'file' as in 'Credit Card On File'
	if (cc.match("file")) {
		document.write('<br>Complete the credit card fields below only if using a different card.');
	}
	else {
		document.write('&nbsp;');
	}
}	

// writes one button to submit form with validation if no credit card on file, alternative button with no validation if credit card is on file (added 12/5/03)
function checkSubmit(name) {
	var str = document.forms[name].shippingverifyerror.value;
	// checks if shippingverifyerror contains the word 'file' as in 'Credit Card On File'
	if (str.match("file")) {
		document.write('<a href=\"javascript:submitFormWithType(\'sform\',\'13\')\">');
	}
	else {
		document.write('<a href=\"javascript:validatebilling(\'sform\')\">');
	}
}

//for calculating subtotal on ViewCart and CheckoutCart pages
function writeTotal() {
	var count=100;
	var orderTotal=0.00;
	for(i=1;i<count;i++){
		var lineTotal = document.forms['form'+i];
		if(lineTotal!=null){
			var totalvalue = lineTotal.subtotal.value;
			orderTotal=orderTotal + parseFloat(totalvalue);
		}else{
			i=101;
		}
	}
	document.write(convertFloatToStringWithCents(Math.round(orderTotal*100)/100));
}

function convertFloatToStringWithCents(toconvert){
	var strTotal = String(toconvert);
	var idx = strTotal.indexOf(".");
	if(idx!=-1){
		var trail = strTotal.substring(idx+1,strTotal.length);
		if(trail.length<2){
			do{
				trail=trail+'0';
			}while(trail.length<2);
		}
		strTotal = strTotal.substring(0,idx+1)+trail;
	}else{
		strTotal = strTotal+'.00';
	}
	return(strTotal)
}

function writeOfficeTotal() {
	var officeCount=100;
	var officeOrderTotal=0.00;
	var officeSubtotal=0.00;
	for(i=1;i<officeCount;i++){
		var officeLineTotal = document.forms['form'+i];
		 if(officeLineTotal!=null){
			var officetotalvalue = officeLineTotal.officeSubtotal.value;
			officeOrderTotal=officeOrderTotal + parseFloat(officetotalvalue);
		}else{
			i=101;
		}
	}
	document.write(convertFloatToStringWithCents(Math.round(officeOrderTotal*100)/100));
}

function confirmDelete(name,key){
	if(confirm("Are You Sure?")){
		document.forms[name].Type.value = '128';
		document.forms[name].Field1.value=key;
		//alert(document.forms[name].Field1.value);
		document.forms[name].submit();
	}
}

function showAdd(show){
	if(show=='Y'){
	document.write('<a href=\"javascript:submitForm(\'templateform\')\"><img src=\"http://saturn.igetsmart.com/igs/images/updatejob.gif\" border=\"0\"></a>');
	}else if(show=='M'){
	document.write('<a href=\"javascript:submitFormWithType(\'gform\',\'130\')\"><img src=\"http://saturn.igetsmart.com/igs/images/returnquote.gif\" border=\"0\"></a>');
	}else{
	document.write('<a href=\"javascript:submitFormWithType(\'gform\',\'121\')\"><img src=\"http://saturn.igetsmart.com/igs/images/returnjob.gif\" border=\"0\"></a>');
	}
}

function showAddCheck(show){
	if(show=='Y'){
	document.write('<a href=\"\" onclick=\"return checkForm(\'templateform\')\"><img src=\"http://saturn.igetsmart.com/igs/images/updatejob.gif\" border=\"0\"></a>');
	}else if(show=='M'){
	document.write('<a href=\"javascript:submitFormWithType(\'gform\',\'130\')\"><img src=\"http://saturn.igetsmart.com/igs/images/returnquote.gif\" border=\"0\"></a>');
	}else{
	document.write('<a href=\"javascript:submitFormWithType(\'gform\',\'121\')\"><img src=\"http://saturn.igetsmart.com/igs/images/returnjob.gif\" border=\"0\"></a>');
	}
}

function showAddText(show){
	if(show=='Y'){
	document.write('After entering your information, click on the <strong>Update Job</strong> button,<br>which will take you to the Job Summary page.');
	}else if(show=='M'){
	document.write('After viewing your information, click on the <strong>Return to Vendor Quote</strong> button.');
	}else{
	document.write('After viewing your information, click on the <strong>Return to Job Summary</strong> button,<br>which will take you to the Job Summary page. ');
	}
}

function showAddHeader(show){
	if(show=='Y'){
	document.write('<img src="http://saturn.igetsmart.com/igs/images/job_info.gif" border="0">');
	}else if(show=='M'){
	document.write('<img src="http://saturn.igetsmart.com/igs/images/job_view.gif" border="0">');
	}else{
	document.write('<img src="http://saturn.igetsmart.com/igs/images/job_view.gif" border="0">');
	}
}
////////////////////////////////////////////////////////////////
//for quotes/bids
function writeShipMonth(date){
	//var date='$!qdshipdate';
	if(date!=''){
	var month = date.substring(4,6);
	document.write('<option selected value='+month+'>'+month+'</option>');
	}else{
	document.write('<option selected value=MM>MM</option>');
	}
}

function writeShipDay(date){
	//var date='$!qdshipdate';
	if(date!=''){
	var day = date.substring(6,8);
	document.write('<option selected value='+day+'>'+day+'</option>');
	}else{
	document.write('<option selected >DD</option>');
	}
}

function writeShipYear(date){
	//var date='$!qdshipdate';
	if(date!=''){
	var year = date.substring(0,4);
	document.write('<option selected value='+year+'>'+year+'</option>');
	}else{
	document.write('<option selected >YYYY</option>');
	}
}

function qdDateString(line){
	var combinedqdDate;
	combinedqdDate = document.forms['gform'].elements['qdYear'+line].value
	combinedqdDate += document.forms['gform'].elements['qdMonth'+line].value
	combinedqdDate += document.forms['gform'].elements['qdDay'+line].value
	document.forms['gform'].elements['qdshipdate'+line].value = combinedqdDate;
	//alert (combinedqdDate);
}

function reqDateString(){
	var combinedreqDate;
	combinedreqDate = document.forms['gform'].elements['reqYear'].value
	combinedreqDate += document.forms['gform'].elements['reqMonth'].value
	combinedreqDate += document.forms['gform'].elements['reqDay'].value
	document.forms['gform'].elements['reqdate'].value = combinedreqDate;
	//alert (combinedreqDate);
}

function sellCode(code){
	//var code='$!qdslcd';
	if(code=='M'){
	document.write('PER THOUSAND');
	}else if(code=='C'){
		document.write('PER HUNDRED');
	}else if(code=='E'){
		document.write('EACH');
	}else if(code=='L'){
		document.write('LOT');
	}
}

function writeDateQuote(date) {
	writeShipDate(date);
}

function writeShipDate(dateship) {
	//var dateShip='$dshdt';
	if((dateship!=null)&&(dateship.length>=8)){
		var yearship = dateship.substring(0,4);
		var monthship = dateship.substring(4,6);
		var dayship = dateship.substring(6,8);
		if(dateship == '0' || dateship == null) {
		document.write('&nbsp;');
		}else{
			document.write(monthship+'/'+dayship+'/'+yearship);
		}
	}else{
		document.write('Invalid Date');
	}
}

function writeBidType(bidtype) {
//alert('1'+bidtype+'2');
	if(bidtype=='D'){
		document.write('Quote Delivered Price');
	}else if(bidtype=='Q'){
	document.write('Quote All Charges');
	}else{
	document.write('Unkown bidtype:'+bidtype);
	}
}

function writeDisabledByBidType(bidtype,famt,oamt) {
//alert('3'+bidtype+'4');
	if(bidtype=='Q'){
		document.write('<td align="center" class="boldQuote">$<input size="10" class="boldQuote" type="text" name="freightamt" value='+famt+' ></td>');
		document.write('<td align="center" class="boldQuote">$<input size="10" class="boldQuote" type="text" name="otheramt" value='+oamt+' ></td>');
	}else{
		document.write('<td align="center" class="boldQuote"><input type="hidden" class="boldQuote" name="freightamt" value='+famt+'>$'+famt+'</td>');
		document.write('<td align="center" class="boldQuote"><input type="hidden" class="boldQuote" name="otheramt" value='+oamt+'>$'+oamt+'</td>');
	}
}

function writeSelectedTEST(name,combo){
	//var selectedidx = document.forms[name].elements[combo].selectedIndex;
	//alert('selectedidx:'+selectedidx);
	var combosize = document.forms[name].elements[combo].size;
	alert('combosize:'+combosize);
	var combolength = document.forms[name].elements[combo].length;
	alert('combolength:'+combolength);
	//var test = document.forms[name].elements[combo].options[1].value;
	//alert('test:'+test);

	//document.forms[name].Qty.value = document.forms[name].comboQty.options[idx].value;
	//document.forms[name].sequence.value = document.forms[name].elements["fseq"+idx].value;

	//<option value="$!qdslcd" selected>$!qdslcd</option>
}

function writeSelected(value,text,varvalue){
	if(value==varvalue){
//alert('selected:'+value);
		document.write('<option value="'+value+'" selected>'+text+'</option>');
	}else{
//alert('UNselected:'+value);
		document.write('<option value="'+value+'">'+text+'</option>');
	}
}

function ws(value,text,varvalue){//DUPE OF writeSelected but shorter to minimize download
	if(value==varvalue){
		document.write('<option value="'+value+'" selected>'+text+'</option>');
	}else{
		document.write('<option value="'+value+'">'+text+'</option>');
	}
}

function writeSelectedByForm(value,text,name,valuefield){
	var varvalue = document.forms[name].elements[valuefield].value
	if(value==varvalue){
//alert('selected:'+value);
		document.write('<option value="'+value+'" selected>'+text+'</option>');
	}else{
//alert('UNselected:'+value);
		document.write('<option value="'+value+'">'+text+'</option>');
	}
}

function displayQuantity() {
}

////////////////////////////////////////////////////////////////
function validateRegex(name){
		var cnt = document.forms[name].elements['numberofvalidations'].value;
//alert('cnt:'+cnt);

		if(cnt>0){
//alert('validations greater then 0.');
				for(i=0;i<cnt;i++) {
						var idx = document.forms[name].elements['regidx'+i].value;
						var exp = document.forms[name].elements['regexp'+i].value;
						var errormessage = document.forms[name].elements['regerr'+i].value;
						var regexp1 = new RegExp(exp);
//alert('Field:'+idx+' exp:'+exp);

						var fieldvalue = document.forms[name].elements['tt'+idx].value;
//alert('Field:'+idx+' fieldvalue:'+fieldvalue);

						if(regexp1.test(fieldvalue)){
//alert('Field:'+idx+' passed test');
						}else{
								document.forms[name].elements['tt'+idx].focus();
								alert(errormessage);
								event.returnValue=false;
								break;
						}
				}
		}
}

function validateAgree(name){
	if(document.forms[name].elements['agree'].value=="i agree"){
		document.forms[name].elements['agree'].focus();
		alert('Please type "I AGREE" in capital letters or we cannot approve the order!');
		event.returnValue=false;
	}else if(document.forms[name].elements['agree'].value!="I AGREE"){
		document.forms[name].elements['agree'].focus();
		alert('If you do not agree we cannot approve the order!');
		event.returnValue=false;
	}
}

//functions for formatting date and time

function formatAndWriteDate(tmpDate) {
	var date=tmpDate;
	if(date.length > 1){
		if (date.length == 7) {
			date = "0".concat(date)
		}

		var year = date.substring(0,4);
		var month = date.substring(4,6);
		var day = date.substring(6,8);
			if (date == '0' || date == null) {
				document.write('&nbsp;');
			}
			else {
				document.write(month+'/'+day+'/'+year);
			}
	}
}

function formatAndWriteTime(tmpTime) {
	var time=tmpTime;

	if(time.length > 1){

		var indicator = "am"

		var actualTime = parseInt(tmpTime, 10)


		if (actualTime >= 120000) {
			indicator = "pm"
		}

		if (actualTime >= 130000) {
			actualTime = actualTime - 120000
		}

		time = actualTime.toString()

		if (time.length == 5) {
			time = "0".concat(time)
		}

		var hr = time.substring(0,2);
		var mi = time.substring(2,4);
		var se = time.substring(4,6);

		document.write(hr+':'+mi+':'+se+' '+indicator)
	}
}

function saveComment(name) {
	comment = document.forms[name].incomment.value;
	if(comment.length<1){
		document.forms[name].incomment.focus();
		alert('No Comment Entered!');
	}else{
		document.forms[name].submit();
	}
}

function writeCommentfooter(name) {
	isvendor = document.forms[name].isvendor.value;
	if(isvendor=='Y'){
		document.write("<a class=\"quote\" href=\"javascript:submitFormWithType('gform','130')\">Return to Quote List</a>");
	}else{
		document.write("<a class=\"quote\" href=\"javascript:submitFormWithType('gform','121')\"><img src=\"http://saturn.igetsmart.com/igs/images/returnJobSummary.gif\" border=\"0\" ALT=\"Return to Job Summary\" ></a>");
	}
}

function open_win(path, x, y)
{
	detailWin = eval("'status=no,menubar=no,scrollbars=no,resizable=no,width=" + x + ",height=" + y + "'");
	window.open(path, 'new_win', detailWin);
	detailWin.opener=window;
}

function notifySmokeyOfFire(formname,fieldname,newcolor)
{
	document.forms[formname].haschanged.value = 'Y';
	document.forms[formname].elements[fieldname].style.color = newcolor;
}

function preventForestFires(formname,type,f1,f2,f3,f4,f5)
{
	var haschanged = document.forms[formname].haschanged.value;
	//alert(haschanged);
	if(haschanged=='Y'){
		alert('Please save your Job or any changes you have made will be lost.');
	}else{
		document.forms[formname].Type.value = type;
		document.forms[formname].Field1.value = f1;
		document.forms[formname].Field2.value = f2;
		document.forms[formname].Field3.value = f3;
		document.forms[formname].Field4.value = f4;
		document.forms[formname].Field5.value = f5;
		document.forms[formname].submit();
	}
}

function strltrim() {
	return this.replace(/^\s+/,'');
	}

function strrtrim() {
	return this.replace(/\s+$/,'');
	}

function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
	}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

//manager approval functions

//function to convert the Date variable into MM/DD/YY format on ManagerApprovalRRow
function writeApprovalDate(name) {
        var date=document.forms[name].Date.value;
		//alert (date);
        var year = date.substring(0,4);
        var month = date.substring(4,6);
        var day = date.substring(6,8);
                if (date == '0' || date == null) {
                        document.write('&nbsp;');
                }
                else {
                        document.write(month+'/'+day+'/'+year);
                }
    }

//function to display the Order# & Order Date on ViewCartHeader
function approvalHeader(name) {
//rewrite date in MM/DD/YYYY format from variable
    var date=document.forms['gform'].date.value;
	//alert (date);
    var year = date.substring(0,4);
    var month = date.substring(4,6);
    var day = date.substring(6,8);
    var newDate = month + "/" + day + "/" + year;
//test for companyordernumber
	var compordernum=document.forms['gform'].companyorder.value
	//alert (compordernum);
if ((compordernum == "") || (compordernum == null)) {
		document.write('<td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td>');
        }
	else {
		document.write('<td class="approvalHeader" align="center">Order#:</td>');
        document.write('<td class="approvalHeader" align="center">Order Date:</td></tr>');
        document.write('<tr><td class="redBold" align="center">'+compordernum+'</td>');
        document.write('<td class="redBold" align="center">'+newDate+'</td>');
        }
    }
	
//function to write Review, Approve, Deny buttons with alert message when an order has been adjusted
function reviewLink(name) {
	var num = document.forms[name].num.value;
	var compNum = document.forms[name].compNum.value;
	var changes = document.forms[name].changes.value;
	var webNum = document.forms[name].webNum.value;
		if (changes == 'true')
	document.write ('<a href="javascript:if (confirm(\'Order# '+compNum+' has been adjusted. If you Review this order these adjustments will be lost.\'))submitFormWithTypeAndFields(\'gform\',\'98\',\''+webNum+'\')" class="approval">Review</a>');
		else
	document.write ('<a href="javascript:submitFormWithTypeAndFields(\'gform\',\'98\',\''+webNum+'\')" class="approval">Review</a>');
}

function approveLink(name) {
	var num = document.forms[name].num.value;
	var compNum = document.forms[name].compNum.value;
	var changes = document.forms[name].changes.value;
	var webNum = document.forms[name].webNum.value;
		if (changes == 'true')
	document.write ('<a href="javascript:if (confirm(\'Order# '+compNum+' has been adjusted. If you Approve this order these adjustments will be lost.\'))submitFormWithTypeAndFields(\'gform\',\'100\',\''+webNum+'\')" class="approval">Approve</a>');
		else
	document.write ('<a href="javascript:submitFormWithTypeAndFields(\'gform\',\'100\',\''+webNum+'\')" class="approval">Approve</a>');
}

function denyLink(name) {
	var num = document.forms[name].num.value;
	var compNum = document.forms[name].compNum.value;
	var changes = document.forms[name].changes.value;
	var webNum = document.forms[name].webNum.value;
		if (changes == 'true')
	document.write ('<a href="javascript:if (confirm(\'Order# '+compNum+' has been adjusted. If you Deny this order these adjustments will be lost.\'))submitFormWithTypeAndFields(\'gform\',\'99\',\''+webNum+'\')" class="approval">Deny</a>');
		else
	document.write ('<a href="javascript:submitFormWithTypeAndFields(\'gform\',\'99\',\''+webNum+'\')" class="approval">Deny</a>');
}

//function to display an * next to an adjusted order
function checkApprovalOrderNum(name) {
	var num = document.forms[name].num.value;
	var compNum = document.forms[name].compNum.value;
		if (num == compNum) {
			document.write('<span class="rush">*</span>');
		}
		else {
			document.write('&nbsp;');
		}
    }

//function to display the Approve/Deny buttons on ViewCartFooter
function approvalButtons() {
	var compordernum=document.forms['gform'].companyorder.value;
	var webordernum="'" + document.forms['gform'].weborder.value + "'";
	//alert (webordernum);
    var siteName=document.forms['gform'].Load.value;
	document.write('&nbsp;');
    if ((document.forms['gform'].companyorder.value == "") || (document.forms['gform'].companyorder.value == null)) {
            document.write('&nbsp;');
        }
        else {
            document.write('&nbsp;<a href="javascript:submitFormWithTypeAndFields(\'gform\',100,'+webordernum+')"><img border=0 src="/'+siteName+'/images/approve2.gif"></a>&nbsp;<a href="javascript:submitFormWithTypeAndFields(\'gform\',99,'+webordernum+')"><img border=0 src="/'+siteName+'/images/unapprove2.gif"></a>');
        }
    }

//for PaineWebber FileType validation on FTPUploadFooter.txt
function validateFileType(form)
{
  if (form.filetype.selectedIndex == 0)
  {
    alert("Please select a File Type");
    return false;
  }
  return true;
}


// writes 'selected' if argument month is equal to the current month
// useful for selecting current month in combo box
/*function selectCurrentMonth(month)
{
    if (month.equals(new Date().getMonth()))
    {
        document.write("selected");
    }
}
*/

//to stop the form being submitted when enter key is pressed
function noenter() {
  return !(window.event && window.event.keyCode == 13); 
}
