// 06-15-05 - Open pledges were using the default page date to determine if to display or not, had to add PageID to the
//				querystring so the page id gets passed all the way through.
// 01-17-06 - Added autofill for city and state
// 01-17-06 - Added restrictions on zip code so that it will only except 5 characters if US zip code, and 6 characters
//              if it is a candian zip code.

var iindex
var premTable
var curbrowser 
var curversion
var premTableBody
var theTotalCell
var premiumcount 
var highestkcount
var selectedpremiums = new Array()
var selectedpremdesc = new Array()
var selecteditemsdesc = new Array()
var selectedpremamt = new Array()
var selectedstringnumber = new Array()
var selecteditems = new Array() 
var selecteditemsqty = new Array()
var premitemarray = new Array()
var premitemdescarray = new Array()
var premitemqtyarray = new Array()
var premarray = new Array()
var premseqarray = new Array()
var premdescarray = new Array()
var premamtarray = new Array()
var premstringnumberarray = new Array() 
var checkstr
var issubmitted


var premiumsizeerrorflag = "NO"
var premiumnotfounderrorflag = "NO" 
var obj;
var oldobj;
var objanswer;
var objcity;
var searching;
var searchwindow;
var IssueWindow;
var ShipWindow;

var actplgamt = 0;



var buttonimages = new Array( "images/buttonsubmit.gif"  , "images/buttonsubmit.gif", "images/buttonprocessing.gif" , "images/buttonRetry.gif" , "images/ButtonRetry.gif")


function init() {

        
		theTotalCell = document.getElementById("premiumtotal")
		premTable = document.getElementById("myTABLE")	
		premTableBody = premTable.tBodies[0]		

		issubmitted = ""
		premiumcount = 0
		
		if (document.form1.wrknopremiums.value == "")
		{
			GetPremiums(5000)		
		}
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value

				break
				}
		}
		
	var pm = parseFloat(chosenmode)
	
    if(pm > 0)
    {
    }
    else
    {
        pm = document.form1.wrkpaymode.value
     }   
        
        
    if(document.form1.wrklumponly.value != "YES")
        document.getElementById("inforow").style.display = 'none'        	

    if(pm == 51 || pm == 52 || pm  == 53 || pm == 54 || pm == 55)
    {
        displaycc();
        hideeft();               
        if(pm == 55)
        {
            document.getElementById("eftwarn").style.display = '';               
        }        
    }
    else if(pm == 61 || pm == 62 || pm  == 63 || pm == 64)
    {
        hidecc();
        displayeft();         
    }  
    else
    {
        hidecc();
        hideeft();                
    }   
		
	if(document.getElementById("hidecompline").value == 'Y')
	{
	    document.getElementById("CompLine").style.display = 'none';     	
	}
    document.form1.wrkesalu.focus()
}

function clearcc()
{

	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
    		document.getElementById("wrkccno").value = "";
    	}

}
function cleareft()
{
	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
        document.getElementById("wrkeftnum").value = "";
        document.getElementById("wrkrouting").value = "";
    }

}

function hidecc()
{
    
	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
    	
    		document.getElementById("ccrow1").style.display = 'none'; 
    		document.getElementById("ccrow2").style.display = 'none'; 
    		document.getElementById("ccrow3").style.display = 'none'; 
    		try{
			  document.getElementById("ccrow4").style.display = 'none';  
			}
			catch(e){}
    		 
	}
       
}

function hideeft()
{
	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
        document.getElementById("eftrow1").style.display= 'none'; 
        document.getElementById("eftrow2").style.display = 'none'; 
        
    }
    document.getElementById("eftwarn").style.display = 'none';

}

function displaycc()
{
	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
    	
    		document.getElementById("ccrow1").style.display = ''; 
    		document.getElementById("ccrow2").style.display = ''; 
    		document.getElementById("ccrow3").style.display = ''; 
    	try
        {
        
    		document.getElementById("ccrow4").style.display = ''; 
			}
			catch(e){}    		
	}
       
}

function displayeft()
{
	if(document.getElementById("DisplayCCInfo").value == 'Y')
	{
        document.getElementById("eftrow1").style.display= ''; 
        document.getElementById("eftrow2").style.display = ''; 
        document.getElementById("eftwarn").style.display = '';
     }
}


function initsurvey() {


	issubmitted = ""
	premiumcount = 0
	
	if(document.getElementById("hidecompline").value == 'Y')
	{
	    document.getElementById("CompLine").style.display = 'none';     	
	}	
	document.form1.wrkesalu.focus()

}


function initerr() {
		
		premTable = document.getElementById("myTABLE")
		premTableBody = premTable.tBodies[0]
		theTotalCell = document.getElementById("premiumtotal")
		issubmitted = ""
		premiumcount = 0
		

		for (i = 0; i < premarray.length; i++)
		{

			premarray[i] = " "
			premseqarray[i] = " "
			premitemarray[i] = " "
			premitemdescarray[i] = " "
			premitemqtyarray[i] = " "
			premstringnumberarray[i] = " "
			premdescarray[i] = " "
			premamtarray[i] = " "					
		}
			
		premarray = document.form1.wrkpremjoin.value.split(";")	 
		premseqarray = document.form1.wrkpremseqjoin.value.split(";")
		premitemarray = document.form1.wrkpremitemjoin.value.split(";")
		premitemdescarray = document.form1.wrkpremitemdescjoin.value.split(";") 
		premitemqtyarray = document.form1.wrkpremitemqtyjoin.value.split(";") 
		premstringnumberarray = document.form1.wrkpremstringnumberjoin.value.split(";") 
		premdescarray = document.form1.wrkpremdescjoin.value.split(";") 
		premamtarray = document.form1.wrkpremamtjoin.value.split(";") 
		
		rebuildPrem(document.form1)	
		
		document.form1.infonopay.selectedIndex = parseInt(document.form1.infonopay.value)
	
		recalctheinfonopay(document.form1)

}

function initexit() {

	premiumcount = 0	
	if (document.form1.wrkwpptyp.value == 'P') {
		if (document.form1.wrkprintpledge.value == "PRINT")
		{
			window.print()
			}
	}
}

function initerrexitsur()
{
        if(getQueryVariable("REPRINT") != "YES")
		{
		    SendAnswerEmails("SUR")
		}
}

function initerrexit() {


		
		
	if (document.form1.wrkpledgeerrorcc.value == 'C' || document.form1.wrkpledgeerrorprem.value == 'P'){

		premTable = document.getElementById("myTABLE")
		premTableBody = premTable.tBodies[0]
		theTotalCell = document.getElementById("premiumtotal")
		
		
		issubmitted = 0
		premiumcount = 0
		
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value

				break
				}
		}
				
	    var pm = parseFloat(chosenmode)
        if(pm == 51 || pm == 01 || pm  == 61)
        {
            if(document.form1.wrklumponly.value != "YES")
               document.getElementById("inforow").style.display = 'none'
        }
        else
        {
            if(document.form1.wrklumponly.value != "YES")
                 document.getElementById("inforow").style.display = ''
        }		

		for (i = 0; i < premarray.length; i++)
		{

			premarray[i] = " "
			premseqarray[i] = " "
			premitemarray[i] = " "
			premitemdescarray[i] = " "
			premitemqtyarray[i] = " "
			premstringnumberarray[i] = " "
			premdescarray[i] = " "
			premamtarray[i] = " "					
		}
			
		premarray = document.form1.wrkpremjoin.value.split(";")	 
		premseqarray = document.form1.wrkpremseqjoin.value.split(";")
		premitemarray = document.form1.wrkpremitemjoin.value.split(";")
		premitemdescarray = document.form1.wrkpremitemdescjoin.value.split(";") 
		premitemqtyarray = document.form1.wrkpremitemqtyjoin.value.split(";") 
		premstringnumberarray = document.form1.wrkpremstringnumberjoin.value.split(";") 
		premdescarray = document.form1.wrkpremdescjoin.value.split(";") 
		premamtarray = document.form1.wrkpremamtjoin.value.split(";") 
		
		rebuildPrem(document.form1)
		
	
		document.form1.infonopay.selectedIndex = parseInt(document.form1.infonopay.value)
		recalctheinfonopay(document.form1)
		if(document.form1.wrknopremiums.value == "")
		{
			GetPremiums(document.form1.infoplgamt.value);

		
		}
		else
		{
		    document.getElementById("noprem").style.display = 'none'
		}
		
		
		
		
	}
	else{


        if(getQueryVariable("REPRINT") != "YES")
		{
		    SendAnswerEmails("PLG")
		}
		premiumcount = 0
		
		if(document.form1.wrkpledgeerrorcc.value == "KM")
		{
		
		    window.open("https://commerce.cashnet.com/cashneta/webkbyu","KBYUMONTHLY","");
		}
		
		
		if (document.form1.wrkwpptyp.value == 'P') 
		{
			if (document.form1.wrkprintpledge.value == "PRINT")
				{
				window.print()
				}
		}
		
			

	}
} 

function insertpremiumRowShort(index)
{

    var premtable = document.getElementById("NEWPREMTABLE");

    var rows = premtable.getElementsByTagName("tr");
    var cells = rows[index].getElementsByTagName("td");


    addpremrow(cells[4].innerHTML.replace(/\&amp;/g,'&'), index);
    try{
        document.getElementById("premyes").checked = true;
    }catch(e){}
    
    //document.getElementById("premyes").checked = true;
    
    
}
function insertpremiumRow(form){
    var list = document.form1.wrkprem
    var checknum = list.selectedIndex



    var premselstring = list.options[list.selectedIndex].value

    addpremrow(premselstring, checknum);
    
        if(document.getElementById("wrkAddPrem").value == "Y")
        {
            list.selectedIndex = 0;
        }
        
} 
		
function addpremrow(premselstring,checknum) {
	var newCell
	var newwindow
	
	
	var startsubstr = premselstring.indexOf("&B=") 
	if (premiumnotfounderrorflag == "YES")
		{
		premiumnotfounderrorflag = "NO"
		return
		}
		
	if (premiumsizeerrorflag == "YES")
		{
		premiumsizeerrorflag = "NO"
		return
		}
	  

	if  (startsubstr == -1)
		{
			if(navigator.userAgent.indexOf("Safari") == -1)
				{
				var alertcomment = "You must select a " + document.form1.wrkpremterm.value + " before adding it to your list"
				alert(alertcomment)
				}
		return
		}
		startsubstr = startsubstr + 3	
	var endsubstr = premselstring.indexOf("&C=")
	var valprem = premselstring.substring(startsubstr,endsubstr)

	var startsubstr = premselstring.indexOf("&S=") + 3
	var endsubstr = startsubstr + 2
	var numbertoselect = premselstring.substring(startsubstr,endsubstr)
	if (parseFloat(numbertoselect) > 0 )
		{
		document.form1.wrkchecknum.value = checknum
		selecteditems[premiumcount] = new Array('none')
		selecteditemsqty[premiumcount] = new Array('0')
		selecteditemsdesc[premiumcount] = new Array(' ')

		opt = premselstring;// list.options[list.selectedIndex].value

			//opt = opt.replace(" ","|")
			opt = opt + '&BRSR=' + document.form1.wrkbrowser.value + '&VER=' + document.form1.wrkversion.value
		var gowhere = "selitems.asp?" + opt//list.options[list.selectedIndex].value  
			
//		var gowhere = "selitems.asp?" + list.options[list.selectedIndex].value  
		var newwindow = window.open(gowhere,"","")
//		var newwindow = window.open(gowhere,"","","")
		return
		}
		
	    startsubstr = premselstring.indexOf("&C=") + 3
	    endsubstr = premselstring.indexOf("&P=") 
	var valsize = premselstring.substring(startsubstr,endsubstr)
		if (valsize != "")
		{valsize = "&" + valsize}
		
	    startsubstr = premselstring.indexOf("&M=") + 3
	    endsubstr = premselstring.indexOf("&S=") 
	var valdesc = premselstring.substring(startsubstr,endsubstr)
	    startsubstr = premselstring.indexOf("&Q=") + 3
	    endsubstr = premselstring.indexOf("&M=") 
	var valamount = premselstring.substring(startsubstr,endsubstr)	


	var newRow = premTableBody.insertRow(-1)

		newCell = newRow.insertCell(0)
		selecteditems[premiumcount] = new Array('none')
		selecteditemsqty[premiumcount] = new Array('0')
		selecteditemsdesc[premiumcount] = new Array('0')	
		selectedpremiums[premiumcount] = valprem + valsize
		selectedstringnumber[premiumcount] = checknum
		selectedpremdesc[premiumcount] = valdesc
		
		
		selectedpremamt[premiumcount] = valamount

		premiumcount = premiumcount + 1

	var cellcontents = '<span class = "elements" style="display: none;" width = "5%"><center>' + premiumcount + '</center></span>'
	//var cellcontents = '<span class = "elements" width = "5%"><center>' + '' + '</center></span>'
		newCell.innerHTML = cellcontents
		
		newCell = newRow.insertCell(1)


	
		if(document.getElementById("wrkallowship").value == 'Y')
		{
		    if(document.getElementById("ShpAdrReq").value == 'Y')
		    {    
		        cellcontents = '<span class = "elements" width="70%" >' + valdesc + "<br>" + "<a href ='javascript:ShipTo(" + premiumcount + ")' style='color: red'>Recipient Required</a>"  +'</span>'
		    }
		    else
		    {
		        cellcontents = '<span class = "elements" width="70%" >' + valdesc + "<br>" + "<a href ='javascript:ShipTo(" + premiumcount + ")' style='color: blue'>Add Recipient</a>"  +'</span>'
		    }
		}
        else
        {
		    cellcontents = '<span class = "elements" width="70%" >' + valdesc +'</span>'
		}



		newCell.innerHTML = cellcontents
		
		newCell = newRow.insertCell(2)

		cellcontents = '<span class = "elements" width="5%" > <table align="right"> $' + valamount  + ' </table></span>'
		newCell.innerHTML = cellcontents

				
		newCell = newRow.insertCell(3)
		newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Remove" onclick="removeRow(this.form,0)"></span>'
		
		
		newCell = newRow.insertCell(4)
		
		
		
		if(document.getElementById("wrkpremshortlist").value == "Y")
		{
		    newCell.innerHTML = '<span class = "elements" style="display: none;" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		}
		else
		{
		    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		}

    	
    	
	    var newamt = updatepremtotal()
	
		if(document.all)
	    {
	        theTotalCell.innerText = "$ " + newamt + " "
        } 
        else
        {
            theTotalCell.textContent = "$ " + newamt + " "
        }
		
			if (document.form1.wrkwpptyp.value == "P" )
			{ 
				
			//form.wrkpremcode.value = ""
			//form.wrkpremsize.value = ""
			}
			try{
			    if(document.getElementById("wrkAddPrem").value == 'Y')
			    {
			        list.selectedIndex = 0;
			
			    }
			}
			catch(e){}
			//Popup Ship
			if(document.getElementById("ShpAdrReq").value == 'Y')
            {
			    ShipTo(premiumcount);
            }
            
            //alert(premiumcount);
            //addshipline(premiumcount);
            
}
function addshipline(premiumcount)
{
	
		
		
		alert(premTableBody.rows[premiumcount-1].cells[1].innerText);
		
		temp = premTableBody.rows[premiumcount-1].cells[1].innerText;
		
		premTableBody.rows[premiumcount-1].cells[1].innerHTML = premTableBody.rows[premiumcount-1].cells[1].innerHTML.replace(temp, temp + "<br>" + "Recipient: Brad Duerr");
		//premTableBody.rows[premiumcount-1].cells[1].innerText = premTableBody.rows[premiumcount-1].cells[1].innerText + "<br>" + "Brad Duerr";
		
		
		
    
}
function ShipTo(count)
{

	    var Stamp = new Date()
    	
	    var Hours
	    var Mins
	    var Seconds
	    var Time
    	
    	var SPageID = document.form1.wrkwpppid.value
    	
	    Hours = Stamp.getHours();
	    Mins = Stamp.getMinutes();
	    Seconds = Stamp.getSeconds();
	    Time = (Hours*10000) + (Mins*100) + Seconds;
        ShipWindow = window.open("AllegWebApplicationsV860/ShipToInstructions3.aspx?PCOUNT=" + count + "&PAGEID=" + SPageID + "&TIME="+Time,"ShipTo",config="height=795,width=550,status=1,scrollbars=1");
        ShipWindow.focus();
}



function removeRow(form,thisrow) {
	var whichrow = thisrow
	var list = document.form1.wrkprem
	try{     list.selectedIndex = 0	}	catch(e) {}
	
	
	if(ShipWindow != null)
	{
	    ShipWindow.close();

	 }  

	if(document.getElementById("wrkallowship").value == 'Y')
	{	
	    if(document.all)
	    {
	        document.getElementById("wrkshipstring").value = removeshipadr(premTableBody.rows[thisrow].cells[0].innerText);	
        } 
        else
        {
            document.getElementById("wrkshipstring").value = removeshipadr(premTableBody.rows[thisrow].cells[0].textContent);	
        }	

    }
	
    for(var i = whichrow; i < premTableBody.rows.length; i++)
    {
 
 	    if(document.all)
	    {
	        var indx = premTableBody.rows[i].cells[0].innerText
		var recpInfo = premTableBody.rows[i].cells[1].innerHTML
        } 
        else
        {
            var indx = premTableBody.rows[i].cells[0].textContent
		var recpInfo = premTableBody.rows[i].cells[1].innerHTML
        }	       
        
        indx = indx - 1
        var currow = premTableBody.rows[i];
 
        currow.deleteCell(0);
        
        var indxcell = currow.insertCell(0);
        var cellcontents = '<span class = "elements" width = "5%" style="display: none;"><center>' + indx + '</center></span>'
	indxcell.innerHTML = cellcontents


	if(i != whichrow)
	{
		var bg =  recpInfo.indexOf("ShipTo(");

		var ed = recpInfo.indexOf(')',bg);

		premTableBody.rows[i].cells[1].innerHTML = recpInfo.substr(0,bg+7) + indx + recpInfo.substr(ed, recpInfo.length); 

	}
	
     
  
    
    }			

    
    updatespremindexes(whichrow)
	premTableBody.deleteRow(whichrow)

	var newamt = updatepremtotal()
	premiumcount = premiumcount - 1;
	
 	    if(document.all)
	    {
	        theTotalCell.innerText = "$ " + newamt + ' '
        } 
        else
        {
            theTotalCell.textContent = "$ " + newamt + ' '
        }		
}

function updatespremindexes(currentindex)
{

    var cnt = selecteditems[currentindex].length
    

    ln = selectedpremiums.length;

    
    for(var i = currentindex; i < ln ; i++)
    {

			selectedpremiums[i] = selectedpremiums[i + 1]
			selectedpremdesc[i] = selectedpremdesc[i + 1]
			selectedpremamt[i] = selectedpremamt[i+1]
			selectedstringnumber[i] = selectedstringnumber[i +1]

		

		    for(var p = i; p<selecteditems.length-1;p++)
		    {
		        selecteditems[p].length = 0;
		        	    
		        		selecteditems[p] = new Array('none')
		                selecteditemsqty[p] = new Array('0')
		                selecteditemsdesc[p] = new Array('0')
		    		 
		        for(var r = 0; r < selecteditems[p+1].length; r++)
		        {

			        selecteditems[p][r] = selecteditems[p+1][r]
			        selecteditemsdesc[p][r] = selecteditemsdesc[p+1][r]
			        selecteditemsqty[p][r]	= selecteditemsqty[p+1][r]			        
		        }
		    
		    }  
		   

	}
	if(selectedpremiums.length != 0)
	{   
	    selectedpremiums.length = selectedpremiums.length -1;
    }
	if(selecteditems.length != 0)
	{   
	    selecteditems.length = selecteditems.length - 1;
    }    
 
}
function removeshipadr(seq)
{
    var newstr = "";
    var shipadrs = document.getElementById("wrkshipstring").value.split('|'); 

    var cnt = shipadrs.length;
    for(var x=0;x<cnt;x++)
    {
        var details = shipadrs[x].split('^^');
        if(details[0] == seq)
        {
            shipadrs[x] = "";
        }    
        else if(details[0] > seq)
        {
            details[0] = details[0] - 1;
            alldetails = "";
            alldetails = details[0];
            for(v = 1;v<details.length; v++)
            {
                
                alldetails =  alldetails + "^^" +details[v]
            
            }
            shipadrs[x] = alldetails;
        
        }
    }
    //length minus 2 because one is getting removed and indexing startes at 0
    
    for(var x=0;x<cnt;x++)
    {
        if(shipadrs[x] != "")
        {
            if(newstr == "")
            {
                newstr = shipadrs[x];
            }
            else
            {
                newstr = newstr + "|" + shipadrs[x];
            }
        }
    }   
    return newstr;
}
function updatepremtotal() {

	var plgpremamt = 0
	var currentamt
	var startsubstr
	var k = 0

	for (var i = 0; i < premarray.length; i++)
	{	

		premarray[i] = ""
	}	
	for (var i = 0; i < premTableBody.rows.length; i++) 
	{
 	    if(document.all)
	    {
	        var currentindex = premTableBody.rows[i].cells[0].innerText
        } 
        else
        {
            var currentindex = premTableBody.rows[i].cells[0].textContent
        }		
		var currentindex = currentindex - 1
		
			for (var j = 0; j < selecteditems[currentindex].length; j++)
			{
				if (j == 0)
				{
					premseqarray[k] = "S"
				}	
				else
				{
					premseqarray[k] = " "
				}		
				
				
			premarray[k] = selectedpremiums[currentindex]
			premdescarray[k] = selectedpremdesc[currentindex]
			premamtarray[k] = selectedpremamt[currentindex]
			premstringnumberarray[k] = selectedstringnumber[currentindex]
			premitemarray[k] = selecteditems[currentindex][j]
			premitemdescarray[k] = selecteditemsdesc[currentindex][j]
			premitemqtyarray[k] = selecteditemsqty[currentindex][j]	
			k = k  + 1
			highestkcount = k
			
			}
			
 	    if(document.all)
	    {
	        currentamt = premTableBody.rows[i].cells[2].innerText
        } 
        else
        {
            currentamt = premTableBody.rows[i].cells[2].textContent
        }				
		
		currentamt = currentamt.replace(",","")
		
		var startsubstr = currentamt.indexOf("$") + 1
		var currentamt = currentamt.substring(startsubstr,10)
		var	theCell = premTableBody.rows[i].cells[3]
		var buttoncell = '<span class = "elements" width = "10%"><input type="button" value = "Remove" onclick="removeRow(this.form,' + i + ')"></span>'
		theCell.innerHTML = buttoncell
		theCell = premTableBody.rows[i].cells[4]
		
		
        if(document.getElementById("wrkpremshortlist").value == "Y")
        {
            var buttoncell = '<span class = "elements" width = "10%" style="display: none;"><input type="button" value = "View" onclick="ViewTablePrem(this.form,' + i + ')"></span>'
            
        }
        else
        {
            var buttoncell = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,' + i + ')"></span>'
            
        }	
		            
		            		
		
		theCell.innerHTML = buttoncell
		plgpremamt = plgpremamt + parseFloat(currentamt)

	}
	
	
	return plgpremamt
}		
 
			
 

function togglepaymode(form,iindex) {
	var curplgamt = 0
	var chosenmode = "0"


	if (document.form1.wrklumponly.value != 'YES') {
		var listnopay = document.form1.infonopay
	}
	var currentamt = new String(" ")		
			
	if (document.form1.wrkonemodeonly.value == 'YES') {
			chosenmode = document.form1.wrkpaymode.value
	}
	else {			
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value
				break
				}
		}
	}

	for (var i = 0; i < document.form1.wrkpledgeamount.length; i++)
		{ 
		if (document.form1.wrkpledgeamount[i].checked) 
			{
			curplgamt = document.form1.wrkpledgeamount[i].value
			curplgamt = curplgamt.replace(",","")
			if (isNaN(curplgamt) || (curplgamt == "")){
				curplgamt = "0"
				}			
			curplgamt = parseFloat(curplgamt)
	
			break
			}
		}
	if (curplgamt == 0) {
			currentamt = document.form1.wrkpledgeamountother.value

			var startsubstr = currentamt.indexOf("$") + 1
			currentamt = currentamt.substring(startsubstr,startsubstr + 20)
			currentamt = currentamt.replace(",","")
			if (isNaN(currentamt) || (currentamt == "")){
				currentamt = "0"
			}
			
			curplgamt = parseFloat(currentamt)
			document.form1.wrkpledgeamountother.value = curplgamt
	}		


	

	var pm = parseFloat(chosenmode)
    var plgamt = 0;

	
	
	try {
	
	    if(pm == 01 || pm == 02 || pm == 03 || pm == 04|| pm == 05)
	    {
	        cleareft();
	        clearcc();
	    
	    }
	    else if(pm == 51 || pm == 52 || pm == 53 || pm == 54|| pm == 55) 
	    {
	        cleareft();
	    
	    }
	    else if(pm == 61 || pm == 62 || pm == 63 || pm == 64) 
	    {
	        clearcc();
	    }
	    
	    	
		if( pm == 01 || pm == 51 || pm == 61) {
			document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
			document.form1.infohowpay.value = " with a one time payment"
			document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
			plgamt = curplgamt;
				if (document.form1.wrklumponly.value != 'YES') {
					listnopay.selectedIndex = 1
					document.getElementById("inforow").style.display = 'none'
				}

				
				
			

		}		
		else {		
			
			if( pm == 02 || pm == 52 || pm == 62) {
				

				if (document.form1.wrkperiodic.value == "periodic"){
		
					document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					plgamt = (curplgamt * 12)						
					document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
				
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						document.getElementById("inforow").style.display = ''
					}
				}			
				else{
					
					document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					var paymt = Math.round(curplgamt / 12 * 100) / 100
					if (paymt * 12 < curplgamt) {
							paymt = paymt + .01
							paymt = Math.round(paymt * 100)
							paymt = paymt/100
							
					}						
					document.form1.infopaymt.value = "$ " + paymt.toFixed(2);
						if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						document.getElementById("inforow").style.display = ''
					}
				}
				
				
			}		
			else {	
				
				if( pm == 03 || pm == 53 || pm == 63) {
					if (document.form1.wrkperiodic.value == "periodic"){	
							
						document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
						document.form1.infohowpay.value = " with equal payments"
						plgamt = (curplgamt * 4)						
						document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
						if (document.form1.wrklumponly.value != 'YES') {
							listnopay.selectedIndex = 4
							document.getElementById("inforow").style.display = ''
						}
					}			
					else{
						document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
						document.form1.infohowpay.value = " with equal payments"
						var paymt = Math.round(curplgamt / 4 * 100) / 100
						if (paymt * 4 < curplgamt) {
								paymt = paymt + .01
								paymt = Math.round(paymt * 100)
								paymt = paymt/100
						}						
						document.form1.infopaymt.value = "$ " + paymt.toFixed(2)
						if (document.form1.wrklumponly.value != 'YES') {
							listnopay.selectedIndex = 4
							document.getElementById("inforow").style.display = ''
						}
					}		
				}		
				else {
					if( pm == 04 || pm == 54 || pm == 64) {
					
						if (document.form1.wrkperiodic.value == "periodic"){	
									
							document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
							document.form1.infohowpay.value = " with semiannual payments"
							plgamt = (curplgamt * 2)						
							document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
							if (document.form1.wrklumponly.value != 'YES') {
								listnopay.selectedIndex = 2
								document.getElementById("inforow").style.display = ''
							}
						}			
						else{
					
							document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
							document.form1.infohowpay.value = " with semiannual payments"
							var paymt = Math.round(curplgamt / 2 * 100) / 100
							if (paymt * 2 < curplgamt) {
									paymt = paymt + .01
									paymt = Math.round(paymt * 100)
									paymt = paymt/100
							}						
							document.form1.infopaymt.value = paymt.toFixed(2)
							if (document.form1.wrklumponly.value != 'YES') {
								listnopay.selectedIndex = 2
								document.getElementById("inforow").style.display = ''
							}
						}	
					}
					else 
				    {
					    if( pm == 05 || pm == 55) {
    					
						    if (document.form1.wrkperiodic.value == "periodic"){	
    									
							    document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
							    document.form1.infohowpay.value = " with monthly payments"
							    plgamt = (curplgamt * 12)						
							    document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
							    if (document.form1.wrklumponly.value != 'YES') {
								    listnopay.selectedIndex = 12
								    document.getElementById("inforow").style.display = ''
							    }
						    }			
						    else{
    					
							    document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
							    document.form1.infohowpay.value = " with monthly payments"
							    var paymt = Math.round(curplgamt / 12 * 100) / 100
							    if (paymt * 12 < curplgamt) {
									    paymt = paymt + .01
									    paymt = Math.round(paymt * 100)
									    paymt = paymt/100
							    }						
							    document.form1.infopaymt.value = paymt.toFixed(2)
							    if (document.form1.wrklumponly.value != 'YES') {
								    listnopay.selectedIndex = 12
								    document.getElementById("inforow").style.display = ''
							    }
						    }	
					    }				    
				    
				    }		
				}
			}
		}
    if(pm == 01 || pm == 02 || pm  == 03 || pm == 04 || pm == 05)
    {
        hidecc();
        hideeft(); 
        if(pm == 05)
        {
            document.getElementById("eftwarn").style.display = '';               
        }
        
    }
    if(pm == 51 || pm == 52 || pm  == 53 || pm == 54|| pm == 55)
    {
        displaycc();
        hideeft();               
        if(pm == 55)
        {
            document.getElementById("eftwarn").style.display = '';               
        }        
    }
    if(pm == 61 || pm == 62 || pm  == 63 || pm == 64)
    {
        hidecc();
        displayeft();         
    }   		
	}
	catch(e) {
	}
	
	if(document.form1.wrknopremiums.value == "")
	{
	    if(chosenmode == "0" || document.form1.wrkperiodic.value != "periodic")
		{
		    if(document.getElementById("wrkrefreshitems").value == "Y")
		    {
		        GetPremiums(curplgamt);
		    }
	    }
	    else
	    {
		    if(document.getElementById("wrkrefreshitems").value == "Y")
		    {	        
	            GetPremiums(plgamt);
	        }
	    }
	} 	

}			 

function togglepledgeamount(form,iindex) {
	var curplgamt = 0
	var chosenmode = "0"


	if (document.form1.wrklumponly.value != 'YES') {
		var listnopay = document.form1.infonopay
	}
	var currentamt = new String(" ")		
			
	if (document.form1.wrkonemodeonly.value == 'YES') {
			chosenmode = document.form1.wrkpaymode.value
	}
	else {			
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value
				    
				break
				}
		}
	}

	for (var i = 0; i < document.form1.wrkpledgeamount.length; i++)
		{ 
		if (document.form1.wrkpledgeamount[i].checked) 
			{
			curplgamt = document.form1.wrkpledgeamount[i].value
			curplgamt = curplgamt.replace(",","")
			if (isNaN(curplgamt) || (curplgamt == "")){
				curplgamt = "0"
				}			
			curplgamt = parseFloat(curplgamt)


	
			break
			}
		}
	if (curplgamt == 0 ) {
			currentamt = document.form1.wrkpledgeamountother.value

			var startsubstr = currentamt.indexOf("$") + 1
			currentamt = currentamt.substring(startsubstr,startsubstr + 20)
			currentamt = currentamt.replace(",","")
			

			if (isNaN(currentamt) || currentamt == ""){
				currentamt = "0"
			}
			//alert(currentamt);
			
			curplgamt = parseFloat(currentamt)
			//Changed so that if they select the other radio button the cursor will get moved into the amount field
			
			document.form1.wrkpledgeamountother.value = curplgamt
			if(curplgamt == 0)
			    document.form1.wrkpledgeamountother.select()
			
		
	}
	else
	{
	   
			//If another value is select put the other value back to zero and take away the focu
			document.form1.wrkpledgeamountother.value = 0
			document.form1.wrkpledgeamountother.blur()			
			
	
	}		


	

	var pm = parseFloat(chosenmode)
    var plgamt = 0;


	try {
		if( pm == 01 || pm == 51 || pm == 61) {
		
			document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
			document.form1.infohowpay.value = " with a onetime payment"
			document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
            plgamt = curplgamt;
				if (document.form1.wrklumponly.value != 'YES') {
					listnopay.selectedIndex = 1
					listnopay.style.display = 'none'
				}
			

		}		
		else {		
			
			if( pm == 02 || pm == 52 || pm == 62) {

				if (document.form1.wrkperiodic.value == "periodic"){	
		
					document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					plgamt = (curplgamt * 12)						
					document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
					
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						listnopay.style.display = ''
						}
					}			
				else{
					
					document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					var paymt = Math.round(curplgamt / 12 * 100) / 100
					if (paymt * 12 < curplgamt) {
							paymt = paymt + .01
							paymt = Math.round(paymt * 100)
							paymt = paymt/100
					}						
					document.form1.infopaymt.value = "$ " + paymt.toFixed(2)
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						listnopay.style.display = ''
					}
				}		
			}	
				
			else {	
				if( pm == 03 || pm == 53 || pm == 63) {
					if (document.form1.wrkperiodic.value == "periodic"){			
						document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
						document.form1.infohowpay.value = " with equal payments"
						plgamt = (curplgamt * 4)						
						document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
						
						if (document.form1.wrklumponly.value != 'YES') {
							listnopay.selectedIndex = 4
							listnopay.style.display = ''
							}
						}			
					else{
				
						document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
						document.form1.infohowpay.value = " with equal payments"
						var paymt = Math.round(curplgamt / 4 * 100) / 100
						if (paymt * 4 < curplgamt) {
								paymt = paymt + .01
								paymt = Math.round(paymt * 100)
								paymt = paymt/100
						}						
						document.form1.infopaymt.value = "$ " + paymt.toFixed(2)
						if (document.form1.wrklumponly.value != 'YES') {
							listnopay.selectedIndex = 4
							listnopay.style.display = ''
						}
					}
				}			
				else {
					if( pm == 04 || pm == 54 || pm == 64) {
						if (document.form1.wrkperiodic.value == "periodic"){			
							document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
							document.form1.infohowpay.value = " with semiannual payments"
							plgamt = (curplgamt * 2)						
							document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
							
							if (document.form1.wrklumponly.value != 'YES') {
								listnopay.selectedIndex = 2
								listnopay.style.display = ''
								}
							}			
						else{
							document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
							document.form1.infohowpay.value = " with semiannual payments"
							var paymt = Math.round(curplgamt / 2 * 100) / 100
							if (paymt * 2 < curplgamt) {
									paymt = paymt + .01
									paymt = Math.round(paymt * 100)
									paymt = paymt/100
							}						
							document.form1.infopaymt.value = paymt.toFixed(2)
							if (document.form1.wrklumponly.value != 'YES') {
								listnopay.selectedIndex = 2
								listnopay.style.display = ''
							}
						}	
					}	
					else
					{
					    if( pm == 05 || pm == 55) {
						    if (document.form1.wrkperiodic.value == "periodic"){			
							    document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
							    document.form1.infohowpay.value = " with sustaining monthly payments"
							    plgamt = (curplgamt * 12)						
							    document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
    							
							    if (document.form1.wrklumponly.value != 'YES') {
								    listnopay.selectedIndex = 12
								    listnopay.style.display = ''
								    }
							    }			
						    else{
							    document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
							    document.form1.infohowpay.value = " with sustaining monthly payments"
							    var paymt = Math.round(curplgamt / 12 * 100) / 100
							    if (paymt * 12 < curplgamt) {
									    paymt = paymt + .01
									    paymt = Math.round(paymt * 100)
									    paymt = paymt/100
							    }						
							    document.form1.infopaymt.value = paymt.toFixed(2)
							    if (document.form1.wrklumponly.value != 'YES') {
								    listnopay.selectedIndex = 12
								    listnopay.style.display = ''
							    }
						    }	
					}						
					
					}
						
				}
			}
		}
	}
	catch(e) {
	}
	
	
	if(document.form1.wrknopremiums.value == "")
	{
	    if(chosenmode == "0" || document.form1.wrkperiodic.value != "periodic")
		{
		    if(document.getElementById("wrkrefreshitems").value == "Y")
		    {		
		        GetPremiums(curplgamt);
		    }
	    }
	    else
	    {
	       
		    if(document.getElementById("wrkrefreshitems").value == "Y")
		    {	       
	            GetPremiums(plgamt);
	        }
	    }
	} 
	
	

}	

function SetRadioButton(form,iindex)
{

	document.form1.wrkpledgeamount[iindex].checked = true
	document.form1.wrkpledgeamountother.select()

}	



function toggleerr(form,iindex) {
	
	var curplgamt = 0.0
	var chosenmode = "0"
	if (document.form1.wrklumponly.value != 'YES') {
		var listnopay = document.form1.infonopay
	}
	var inamt = new String(" ")
	if (document.form1.wrkperiodic.value == "periodic"){ 
		inamt = document.form1.infopaymt.value
		}
	else{
		inamt = document.form1.infoplgamt.value
		}

	var startsubstr = inamt.indexOf("$") + 1
		
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var curplgamt = parseFloat(strpayamt)
		
	if (document.form1.wrkonemodeonly.value == 'YES') {
		chosenmode = document.form1.wrkpaymode.value
	}
	else {		
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value
				break
				}
		}

	}
	var pm = parseFloat(chosenmode)




	if( pm == 01 || pm == 51|| pm == 61) {
		document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
		document.form1.infohowpay.value = " with a onetime payment"
		document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
		if (document.form1.wrklumponly.value != 'YES') {
			listnopay.selectedIndex = 1
			document.getElementById("inforow").style.display = 'none'
		}
	}		
	else {	
		
		if( pm == 02 || pm == 52  || pm == 62) {

				if (document.form1.wrkperiodic.value == "periodic"){	
	
					document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					var plgamt = (curplgamt * 12)						
					document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
					
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						document.getElementById("inforow").style.display = ''
					}
				}			
				else{
				
					document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with monthly payments"
					var paymt = Math.round(curplgamt / 12 * 100) / 100
					if (paymt * 12 < curplgamt) {
															paymt = paymt + .01
										paymt = Math.round(paymt * 100)
										paymt = paymt/100
					}						
					document.form1.infopaymt.value = "$ " + paymt.toFixed(2)
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 12
						document.getElementById("inforow").style.display = ''
				}			
			}
			
		}		
		else {	
			if( pm == 03 || pm == 53  || pm == 63) {
				if (document.form1.wrkperiodic.value == "periodic"){			
					document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with equal payments"
					var plgamt = (curplgamt * 4)						
					document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 4
						document.getElementById("inforow").style.display = ''
					}
				}			
				else{
					document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
					document.form1.infohowpay.value = " with equal payments"
					var paymt = Math.round(curplgamt / 4 * 100) / 100
					if (paymt * 4 < curplgamt) {
						paymt = paymt + .01
						paymt = Math.round(paymt * 100)
						paymt = paymt/100
					}						
					document.form1.infopaymt.value = "$ " + paymt.toFixed(2)
					if (document.form1.wrklumponly.value != 'YES') {
						listnopay.selectedIndex = 4
						document.getElementById("inforow").style.display = ''
					}
				}	
			}		
			else {
				if( pm == 04 || pm == 54  || pm == 64) {
					if (document.form1.wrkperiodic.value == "periodic"){			
							document.form1.infopaymt.value = "$ " + curplgamt.toFixed(2)
							document.form1.infohowpay.value = " with semiannual payments"
							var plgamt = (curplgamt * 2)						
							document.form1.infoplgamt.value = "$ " + plgamt.toFixed(2)
							if (document.form1.wrklumponly.value != 'YES') {
								listnopay.selectedIndex = 2
								document.getElementById("inforow").style.display = ''
							}
						}			
					else{
						document.form1.infoplgamt.value = "$ " + curplgamt.toFixed(2)
						document.form1.infohowpay.value = " with semiannual payments"
						var paymt = Math.round(curplgamt / 2 * 100) / 100
						if (paymt * 2 < curplgamt) {
							paymt = paymt + .01
							paymt = Math.round(paymt * 100)
							paymt = paymt/100
						}						
						document.form1.infopaymt.value = paymt
						if (document.form1.wrklumponly.value != 'YES') {
							listnopay.selectedIndex = 2
							document.getElementById("inforow").style.display = ''
						}
					}	
				}		
			}
		}
	}
	
}		




function RecalcInfoNopay(form) {

	var finpayamt = 0.0
	var listnopay = document.form1.infonopay
	var inamt = new String(" ")
	
	
	if (document.form1.wrkperiodic.value == "periodic"){ 
		inamt = document.form1.infopaymt.value
		
		}
	else{
		inamt = document.form1.infoplgamt.value
		
		}
		
	
	var startsubstr = inamt.indexOf("$") + 1
		
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var plgamt = parseFloat(strpayamt)
	var nopay = 0
	nopay = listnopay.selectedIndex	
	
	for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
	{
		if (document.form1.wrkpaymode[i].checked) 
			{
			var chosenmode = document.form1.wrkpaymode[i].value
			
			break
			}
	}


	var pm = parseFloat(chosenmode)
	
	if (nopay > 1 && (pm == 1 || pm == 51 || pm == 61) ) {
		
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
		{
			if (document.form1.wrkpaymode[i].checked) {
					
				document.form1.wrkpaymode[i].checked = false
				if (i + 1 != document.form1.wrkpaymode.length) {
					document.form1.wrkpaymode[i + 1].checked = true
					document.form1.infohowpay.value = " with monthly payments"
						
						
				}						
				break
			}
		}
	}				

	if (nopay > 0) {
		if (document.form1.wrkperiodic.value == "periodic"){ 
			var finpayamt = (plgamt * nopay)
			document.form1.infoplgamt.value = "$ " + finpayamt
		}
		else{
		    
			var paymenttemp = (plgamt/nopay * 100)

			
			var finpayamt = Math.round(paymenttemp)

			finpayamt = finpayamt/100
			
			if (finpayamt * nopay < plgamt) {
				finpayamt = finpayamt + .01
			}
				finpayamt = Math.round(finpayamt * 100)
				finpayamt = finpayamt/100
				document.form1.infopaymt.value = "$ " + finpayamt
			
		}						
											
		
	}		

}

function RecalcInfoPlgAmterr(form) {
	var finpayamt = 0.0
	if (document.form1.wrklumponly != 'YES') {
		var listnopay = document.form1.infonopay
		var nopay = listnopay.selectedIndex
		if (nopay == 0) {
			nopay = 1
		}							
	}
	else {
		nopay = 1
	}		
	var inamt = new String(" ")
	inamt = document.form1.infoplgamt.value
	var startsubstr = inamt.indexOf("$") + 1
	
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var plgamt = parseFloat(strpayamt)

	var paymt = Math.round(plgamt / nopay * 100) / 100

	if (paymt * nopay < plgamt) {
			paymt = paymt + .01
			paymt = Math.round(paymt * 100)
			paymt = paymt/100
	}						
	document.form1.infopaymt.value =  paymt		
	document.form1.wrkpledgeamountother.value =  plgamt

}

function RecalcInfoPlgAmt(form) {

	var finpayamt = 0.0
	if (document.form1.wrklumponly != 'YES') {
		var listnopay = document.form1.infonopay
		var nopay = listnopay.selectedIndex
		if (nopay == 0) {
			nopay = 1
		}							
	}
	else {
		nopay = 1
	}		
				
	var inamt = new String(" ")
	inamt = document.form1.infoplgamt.value
	var startsubstr = inamt.indexOf("$") + 1
		
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var plgamt = parseFloat(strpayamt)
	var paymt = Math.round(plgamt / nopay * 100) / 100
	if (nopay * paymt < plgamt) {
		paymt = paymt + .01
		paymt = Math.round(paymt * 100)
		paymt = paymt/100
	}						
	
	document.form1.infopaymt.value =  paymt
	try{
		
		for (var i = 0; i < document.form1.wrkpledgeamount.length; i++) 
		{
			if (document.form1.wrkpledgeamount[i].checked) 
				{
				document.form1.wrkpledgeamount[i].checked = false
				break
				}
		}
		document.form1.wrkpledgeamount[document.form1.wrkpledgeamount.length - 1].checked = true
	}
	catch(e) {
	}	
	document.form1.wrkpledgeamountother.value = plgamt

}


function RecalcInfoPaymt(form) {

	var finpayamt = 0.0
	if (document.form1.wrklumponly != 'YES') {
		var listnopay = document.form1.infonopay
		var nopay = listnopay.selectedIndex
		if (nopay == 0) {
			nopay = 1
		}							
	}
	else {
		nopay = 1
	}		
				
	var inamt = new String(" ")
	inamt = document.form1.infopaymt.value
	var startsubstr = inamt.indexOf("$") + 1
		
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var payamt = parseFloat(strpayamt)
	var plgamt = (payamt * nopay)
							
	document.form1.infoplgamt.value =  plgamt		
	try{
		for (var i = 0; i < document.form1.wrkpledgeamount.length; i++) 
		{
			if (document.form1.wrkpledgeamount[i].checked) 
				{
				document.form1.wrkpledgeamount[i].checked = false
				break
				}
		}
		document.form1.wrkpledgeamount[document.form1.wrkpledgeamount.length - 1].checked = true
	}
	catch(e) {
	}	
	
	if (document.form1.wrkperiodic.value == "periodic"){
		document.form1.wrkpledgeamountother.value = payamt
	}
	else{
		document.form1.wrkpledgeamountother.value = plgamt
	}
}

function RecalcInfoPaymterr(form) {

	var finpayamt = 0.0
	if (document.form1.wrklumponly != 'YES') {
		var listnopay = document.form1.infonopay
		var nopay = listnopay.selectedIndex
		if (nopay == 0) {
			nopay = 1
		}							
	}
	else {
		nopay = 1
	}		
				
	var inamt = new String(" ")
	inamt = document.form1.infopaymt.value
	var startsubstr = inamt.indexOf("$") + 1
		
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")
	var payamt = parseFloat(strpayamt)
	var plgamt = (payamt * nopay)
		
							
		document.form1.infoplgamt.value =  plgamt
		document.form1.wrkpledgeamountother.value =  plgamt

}





function clearErrors(form)  {


		premiumnotfounderrorflag = "NO"


		premiumsizeerrorflag = "NO"

}

function clearPremcode(form)  {


}


function ViewSelPrem(form)  {
	var newwindow
	var list = document.form1.wrkprem
	var premselstring = list.options[list.selectedIndex].value
	
	var startsubstr = premselstring.indexOf("&B=")
	
	
	if (premiumnotfounderrorflag == "YES")
		{
		premiumnotfounderrorflag = "NO"
		return
		}
		
	if (premiumsizeerrorflag == "YES")
		{
		premiumsizeerrorflag = "NO"
		return
		}
		 
	if  (startsubstr == -1)
		{
		//if(document.getElementById("wrkAddPrem").value != 'Y')
		//{
		    var alertcomment = "You must select a " + document.form1.wrkpremterm.value + " before viewing"
		    alert(alertcomment)
		//}
		return
		}
	var list = document.form1.wrkprem
	var gowhere = "dspitems.asp?" + list.options[list.selectedIndex].value 
	var newwindow = window.open(gowhere,"","","WIDTH=540")
}

function ViewTablePrem(form,thisrow)  {

    if(document.all)
    {
        var currentindex = premTableBody.rows[thisrow].cells[0].innerText
    } 
    else
    {
        var currentindex = premTableBody.rows[thisrow].cells[0].textContent
    }		
	
	
	var currentindex = selectedstringnumber[currentindex - 1]
	var newwindow
	
try{
	    var list = document.form1.wrkprem
	    var gowhere = "dspitems.asp?" + list.options[currentindex].value 
}
catch(e){

    
    
    
        var premtable = document.getElementById("NEWPREMTABLE");

        var rows = premtable.getElementsByTagName("tr");
        var cells = rows[currentindex ].getElementsByTagName("td");    
    
       var gowhere = "dspitems.asp?" + cells[4].innerHTML
}       
	
	
	

	
	newwindow = window.open(gowhere,"","","WIDTH=540")
}



function showLoc(form) {
	var textstuff = '<input type="hidden" name="wrklocation" value=' + '"' + location.pathname + '"' +'>'

	document.write(textstuff)
}
function checkform(form) {
	
	if (issubmitted == "YES" || searching == true)
	{
        searching = false;
        searchwindow.focus();
		return false
	}
	else
	{

		if (checknameaddress(form) == false)
		{

		return false	
		}
		if (checktelephone(form) == false)
		{

		return false	
		}

		if (checkplgamount(form) == false)
		{
		return false	
		}

		if (document.form1.wrknopremiums.value != "YES" && document.getElementById("wrkpremshortlist").value != "Y")	
		{
			if (checkifpremiumselected(form) == false)
			{
			return false	
			}
		}
		if (checkpaymode(form) == false)
		{
		return false	
		}

		if (document.form1.wrknopremiums.value != "YES")	
		{		
		
		    if(document.getElementById("ShpAdrReq").value == 'Y')
		    { 
		        if(checkshipadr(form) == false)
		        {
		            return false
		        }
            }
        
            if(document.getElementById("premiumReq").value == 'Y')
            {
                if(checkpremcnt(form,1) == false)
                {
                    return false
                }
            
            }
            try
            {
        
                if(document.getElementById("premyes").checked)
                {
                    if(checkpremcnt(form,2) == false)
                    {
                        return false
                    }
                }
                if(document.getElementById("premno").checked)
                {
                    if(checkpremcnt(form,3) == false)
                    {
                        return false
                    }
                }
               
                
            }catch(exception){}
        }
        if(trim(document.getElementById("wrkwpnkid").value) != 0)
        {
            if(checkkid(form) == false)
            {
                return false
            }
       }
        
        
		//PUT IN ALERTS SO WE KNOW THIS VALUES
		document.form1.wrkpremjoin.value = premarray.join(";")
		document.form1.wrkpremseqjoin.value = premseqarray.join(";")
		document.form1.wrkpremitemjoin.value = premitemarray.join(";")
		document.form1.wrkpremitemdescjoin.value = premitemdescarray.join(";")
		document.form1.wrkpremitemqtyjoin.value = premitemqtyarray.join(";")
		document.form1.wrkpremstringnumberjoin.value = premstringnumberarray.join(";")
		document.form1.wrkpremdescjoin.value = premdescarray.join(";")

		document.form1.wrkpremamtjoin.value = premamtarray.join(";")
		
		
		
		var theactionurl = document.form1.wrkpledgeerrpage.value + ".asp"
		var theactionquery = location.search
		buttonimages[0] = buttonimages[2]

		var gowhere = theactionurl + theactionquery 

		
		document.form1.action = gowhere
	
		issubmitted = "YES"
		if(document.all)
        {
		    document.all.submit1.src = buttonimages[2]
		}
		
		return true
	}	
}

function checkformsurvey(form) {

	if (issubmitted == "YES")
	{

		return false
	}
	


	else
	{
		
		if (checknameaddress(form) == false)
		{
		return false
		}
	
		if (checktelephone(form) == false)
		{

		return false	
		}

		
			
		var theactionurl = document.form1.wrkpledgeerrpage.value + ".asp"
		var theactionquery = location.search
//		buttonimages[0] = buttonimages[2]

		var gowhere = theactionurl + theactionquery 

		
		document.form1.action = gowhere
	
		issubmitted = "YES"
//		document.all.submit1.src = buttonimages[2]
		
		return true
	}	
}



function checkformexitsurvey(form) {


		if (document.form1.wrkwsptyp.value != 'P') {
			var gowhere = document.form2.wrkreferrer.value 				
		}
		else
		{	
			var cursearch = document.form2.wrkreferrer.value.indexOf("?")
	
			if  (cursearch == -1)	
			{
			    gowhere = document.form2.wrkreferrer.value
			}
			else 
			{
				cursearch = parseInt(cursearch)
				var gowhere = document.form2.wrkreferrer.value	
				gowhere = gowhere.substring(0,cursearch)
			     
			}
			gowhere = gowhere + '?P=' + document.form2.wrkstartdef.value + '&USER=' + document.form2.wrkuser.value + '&PAGE=' + document.form2.wrkstartpage.value + '&BREAK=' + document.form2.wrkstartbreak.value + '&PROGRAM=' + document.form2.wrkstartprogram.value + '&DATEMM=' + document.form2.wrkstartdatemm.value + '&DATEDD=' + document.form2.wrkstartdatedd.value + '&DATEYY=' + document.form2.wrkstartdateyy.value 
			
		}		
		window.location.replace(gowhere);	
		return false
}

function onmouseover_submit1()
{
	if(document.all)
    {
	    document.all.submit1.src = buttonimages[1] // "images/buttonsubmit.gif"
	}
}	
function onmouseout_submit1()
{
    if(document.all)
    {
		document.all.submit1.src = buttonimages[0] //  "images/buttonsubmit.gif"
    }
}	

function onmouseover_submit1err()
{
    if(document.all)
    {	
	    document.all.submit1.src = buttonimages[4] //"images/buttonretry.gif"
    }
}	
function onmouseout_submit1err()
{
    if(document.all)
    {
    	document.all.submit1.src = buttonimages[3]  //"images/buttonRetry.gif"
    }
}	




function checkformerr(form) {
	

	if (issubmitted == "YES")
	{
	
		return false
	}
	else
	{
	

		if (checkplgamounterr(form) == false)
		{
		return false	
		}
	
		if (form.wrknopremiums.value != "YES" && document.getElementById("wrkpremshortlist").value != "Y")	
		{
			if (checkifpremiumselected(form) == false)
			{
			return false	
			}
		}
		
		if (document.form1.wrknopremiums.value != "YES")	
		{		
		    if(document.getElementById("ShpAdrReq").value == 'Y')
		    { 
		        if(checkshipadr(form) == false)
		        {
		            return false
		        }
            }
            
            if(document.getElementById("premiumReq").value == 'Y')
            {
                if(checkpremcnt(form,1) == false)
                {
                    return false
                }
            
            }
            
            try
            {
            
                if(document.getElementById("premyes").checked)
                {
                    if(checkpremcnt(form,2) == false)
                    {
                        return false
                    }
                }
                if(document.getElementById("premno").checked)
                {
                    if(checkpremcnt(form,3) == false)
                    {
                        return false
                    }
                }                
            }catch(exception){}
        }		
	
		if (checkpaymode(form) == false)
		{
		return false	
		}
		

		document.form1.wrkpremjoin.value = premarray.join(";")
		document.form1.wrkpremseqjoin.value = premseqarray.join(";")
		document.form1.wrkpremitemjoin.value = premitemarray.join(";")
		document.form1.wrkpremitemdescjoin.value = premitemdescarray.join(";")
		document.form1.wrkpremitemqtyjoin.value = premitemqtyarray.join(";")
		document.form1.wrkpremstringnumberjoin.value = premstringnumberarray.join(";")
		document.form1.wrkpremdescjoin.value = premdescarray.join(";")
		document.form1.wrkpremamtjoin.value = premamtarray.join(";")
	
		var theactionurl = document.form1.wrkpledgeerrpage.value + ".asp"
		var theactionquery = location.search
		var gowhere = theactionurl + theactionquery 
		isSubmitted = "YES"
		//document.form1.action = gowhere
		window.location.replace(gowhere);
		
		buttonimages[3] = buttonimages[2]   // Keep Processing image up
        if(document.all)
        {	
		    document.all.submit1.src = buttonimages[2] //"images/buttonsubmit.gif"
        }
		return true
	}		
}

function checkformerrbypass(form) {
	

	if (issubmitted == "YES")
	{
	
		return false
	}
	else
	{
	

		if (checkplgamounterr(form) == false)
		{
		return false	
		}
	
		if (document.form1.wrknopremiums.value != "YES"  && document.getElementById("wrkpremshortlist").value != "Y")	
		{
			if (checkifpremiumselected(form) == false)
			{
			return false	
			}
		}
		
		if (document.form1.wrknopremiums.value != "YES")	
		{		
		    if(document.getElementById("ShpAdrReq").value == 'Y')
		    { 
		        if(checkshipadr(form) == false)
		        {
		            return false
		        }
            }
            
            if(document.getElementById("premiumReq").value == 'Y')
            {
                if(checkpremcnt(form,1) == false)
                {
                    return false
                }
            }
            try
            {
            
                if(document.getElementById("premyes").checked)
                {
                    if(checkpremcnt(form,2) == false)
                    {
                        return false
                    }
                }
                if(document.getElementById("premno").checked)
                {
                    if(checkpremcnt(form,3) == false)
                    {
                        return false
                    }
                }                
            }catch(exception){}
        }		
		
		
	
		if (checkpaymode(form) == false)
		{
		return false	
		}
		

		document.form1.wrkpremjoin.value = premarray.join(";")
		document.form1.wrkpremseqjoin.value = premseqarray.join(";")
		document.form1.wrkpremitemjoin.value = premitemarray.join(";")
		document.form1.wrkpremitemdescjoin.value = premitemdescarray.join(";")
		document.form1.wrkpremitemqtyjoin.value = premitemqtyarray.join(";")
		document.form1.wrkpremstringnumberjoin.value = premstringnumberarray.join(";")
		document.form1.wrkpremdescjoin.value = premdescarray.join(";")
		document.form1.wrkpremamtjoin.value = premamtarray.join(";")
	
		var theactionurl = document.form1.wrkpledgeerrpage.value + ".asp"
		var theactionquery = location.search
		var gowhere = theactionurl + theactionquery 
		isSubmitted = "YES"
		gowhere = gowhere + '&BYPASS=BYPASS'
		document.form1.action = gowhere
		
		
		//alert(gowhere)
		//window.location.replace(gowhere);

		

		buttonimages[3] = buttonimages[2]   // Keep Processing image up
	    if(document.all)
        {
		    document.all.submit1.src = buttonimages[2] //"images/buttonsubmit.gif"
        }
		return true
	}		
}
		
function checkformexit(form) {

    try
    {
		if (document.form1.wrkwpptyp.value != 'P') {
			var gowhere = document.form2.wrkreferrer.value	
										
		}
		else
		{	
			var cursearch = document.form2.wrkreferrer.value.indexOf("?")
	
			if  (cursearch == -1)	
			{
			    gowhere = document.form2.wrkreferrer.value
			}
			else 
			{
				cursearch = parseInt(cursearch)
				var gowhere = document.form2.wrkreferrer.value	
				gowhere = gowhere.substring(0,cursearch)
			     
			}


			if(document.form2.wrkstartdef.value == "" || document.form2.wrkuser.value == "")
			{
			  gowhere = document.form2.wrkreferrer.value + '&User=' + document.form2.wrkuser.value 
		    }
			else
			{
			   
			gowhere = gowhere + '?P=' + document.form2.wrkstartdef.value + '&USER=' + document.form2.wrkuser.value + '&PAGE=' + document.form2.wrkstartpage.value + '&BREAK=' + document.form2.wrkstartbreak.value + '&PROGRAM=' + document.form2.wrkstartprogram.value + '&DATEMM=' + document.form2.wrkstartdatemm.value + '&DATEDD=' + document.form2.wrkstartdatedd.value + '&DATEYY=' + document.form2.wrkstartdateyy.value 
					
			}

		}	

		window.location.replace(gowhere);
		return false
	}
	catch(e)
	{
		window.location.replace(document.form1.wrkreferrer.value);
		return false	
	
	}
}

function checkformexitanotherpledge(form) {
				
    var startusr = document.form2.wrkuser.value

	var startpage = document.form2.wrkstartpage.value.toUpperCase()
	
	var cursearch = document.form2.wrkreferrer.value.indexOf('?')
				if  (cursearch == -1)	
			{
			    cursearch = document.form2.wrkreferrer.length
			}
			
				cursearch = parseInt(cursearch) - 10
				var gowhere = document.form2.wrkreferrer.value	
				gowhere = gowhere.substring(0,cursearch)
				
				
			     
				
		
	var startdef = document.form2.wrkstartdef.value.toUpperCase()
		
	var startbreak = document.form2.wrkstartbreak.value.toUpperCase()
	var startprogram = document.form2.wrkstartprogram.value
	var startdatemm = document.form2.wrkstartdatemm.value
	var startdatedd = document.form2.wrkstartdatedd.value
	var startdateyy = document.form2.wrkstartdateyy.value
	var trans = document.form1.wrktrans.value
	var refr = document.form2.wrkreferrer.value
	var curbrowser = document.form1.wrkbrowser.value
	var curversion = document.form1.wrkversion.value
			
    var gowhere = gowhere + startpage + '?P=' + startdef + '&trans='+ trans + '&REPLEDGE=REPLEDGE' + '&USER=' + startusr + '&PAGE=' + startpage + '&DEF=' + startdef + '&BREAK=' + startbreak + '&PROGRAM=' + startprogram + '&DATEMM=' + startdatemm + '&DATEDD=' + startdatedd + '&DATEYY=' + startdateyy +  '&BRSR=' + curbrowser + '&VER=' + curversion + '&REFR=' + refr 
	
	//document.form1.action = gowhere
		
    window.location.replace(gowhere);
    return false;
    //return true
}

function checkforminit(form) {

	document.form1.wrkuser.value = leftTrim(document.form1.wrkuser.value);
	if (document.form1.wrkuser.value < "A")
	{
		alert("You Must Enter a User Name")
		return false	
	}

	
	if (document.form1.wrkstartdatemm.value == 0 && (document.form1.wrkstartdatedd.value > 0 || document.form1.wrkstartdateyy.value > 0) )
	{
		alert("the date is partially selected")
		return false	
	}
	if (document.form1.wrkstartdatedd.value == 0 && (document.form1.wrkstartdatemm.value > 0 || document.form1.wrkstartdateyy.value > 0) )
	{
		alert("the date is partially selected")
		return false	
	}
	if (document.form1.wrkstartdateyy.value == 0 && (document.form1.wrkstartdatemm.value > 0 || document.form1.wrkstartdatedd.value > 0) )
	{
		alert("the date is partially selected")
		return false	
	}
	
	var cursearch = document.form1.wrkstartdefval.value.indexOf("&")
	if  (cursearch != -1)	{
		cursearch = parseInt(cursearch)
		document.form1.wrkstartdef.value = document.form1.wrkstartdefval.value.substring(0,cursearch)
	}
	
    var startusr = document.form1.wrkuser.value
	var startpage = document.form1.wrkstartpage.value.toUpperCase()	
	var startdef = document.form1.wrkstartdef.value.toUpperCase()
	var startbreak = document.form1.wrkstartbreak.value.toUpperCase()
	var startprogram = document.form1.wrkstartprogram.value
	var startdatemm = document.form1.wrkstartdatemm.value
	var startdatedd = document.form1.wrkstartdatedd.value
	var startdateyy = document.form1.wrkstartdateyy.value
	
	
	cursearch = startpage.indexOf(" ")
	if  (cursearch != -1)	{
		cursearch = parseInt(cursearch)
		startpage = startpage.substring(0,cursearch)			
	}
	

			
    var gowhere = startpage + '?P=' + startdef + '&USER=' + startusr + '&PAGE=' + startpage + '&DEF=' + startdef + '&BREAK=' + startbreak + '&PROGRAM=' + startprogram + '&DATEMM=' + startdatemm + '&DATEDD=' + startdatedd + '&DATEYY=' + startdateyy

	document.form1.action = gowhere
	
	return true
}

function checkforminitrefresh(form) {

	var stayhere = " "
	document.form1.wrkuser.value = leftTrim(document.form1.wrkuser.value);
	if (document.form1.wrkuser.value < "A")
	{
		alert("You Must Enter a User Name")
		return false	
	}
	
	var cursearch = document.form1.wrkstartdefval.value.indexOf("&")
	if  (cursearch != -1)	{
		cursearch = parseInt(cursearch)
		document.form1.wrkstartdef.value = document.form1.wrkstartdefval.value.substring(0,cursearch)
	}
	
    var startusr = document.form1.wrkuser.value
	var startpage = document.form1.wrkstartpage.value.toUpperCase()	
	var startdef = document.form1.wrkstartdef.value.toUpperCase()
	var startbreak = document.form1.wrkstartbreak.value.toUpperCase()
	var startprogram = document.form1.wrkstartprogram.value
	var startdatemm = document.form1.wrkstartdatemm.value
	var startdatedd = document.form1.wrkstartdatedd.value
	var startdateyy = document.form1.wrkstartdateyy.value
	
	cursearch = startpage.indexOf(" ")
	if  (cursearch != -1)	
		{
		cursearch = parseInt(cursearch)
		startpage = startpage.substring(0,cursearch)			
		}


	
	stayhere = window.location.href

	cursearch = stayhere.indexOf("?")

	if  (cursearch != -1)	
		{
		cursearch = parseInt(cursearch)
		stayhere = stayhere.substring(0,cursearch)			
		}
		
			
    var gowhere = stayhere + '?P=' + startdef + '&USER=' + startusr + '&PAGE=' + startpage + '&DEF=' + startdef + '&BREAK=' + startbreak + '&PROGRAM=' + startprogram + '&DATEMM=' + startdatemm + '&DATEDD=' + startdatedd + '&DATEYY=' + startdateyy 

	document.form1.action = gowhere

	return true
}

function getphysicalpage(form) {
		
		var cursearch = document.form1.wrkstartdefval.value.indexOf("&")
		if  (cursearch == -1)	{
		    document.form1.wrkstartpage.value = ""
		}
		
		else {
			
			cursearch = parseInt(cursearch)

			var checkstring = document.form1.wrkstartdefval.value.substring(cursearch + 1,cursearch + 21)
			cursearch = checkstring.indexOf(" ")

			if (cursearch != -1)
			{
				document.form1.wrkstartpage.value = checkstring.substring(0,cursearch)
			}
			else 
			{
				document.form1.wrkstartpage.value = checkstring
			}
						
		} 
}

function printformexit(form) {
	
	window.print()
	return false    
}

function checkkid(form){

     var maxage = document.getElementById("wrkMaxKidAge").value
     var kidyear = document.getElementById("wrkkidyy" + 1).value
    for(i = 1; i<=document.getElementById("wrkwpnkid").value; i++)
    {

        if(trim(document.getElementById("wrkkid" + i).value) != "")
        {
            if(trim(document.getElementById("wrkkidmm" + i).value) == "" || trim(document.getElementById("wrkkidyy" + i).value) == "" || trim(document.getElementById("wrkkiddd" + i).value) == "")
            {
                alert('Please provide a valid birthday for each kid');
                return(false)
            }
            if(kidyear < 1970 && kidyear > 2020)
            {
                alert("Please enter in a valid 4 digit year for your kid");
            }
            if(maxage < checkage(i))
            {
                alert(trim(document.getElementById("wrkkid" + i).value) + " exceeds the age of kids allowed");
                return(false)
            
            }
        }
    
    }
    return(true)

}
function checkage(i)
{

	var Stamp = new Date()

    var kidyear = document.getElementById("wrkkidyy" + i).value
	var kidmonth = document.getElementById("wrkkidmm" + i).value
	var kidday = document.getElementById("wrkkiddd" + i).value
	


	var difyear = Stamp.getFullYear() - kidyear;
	
	kidmonth = kidmonth - 1;//this is done because the Stamp object is zero based
	
	if(kidmonth > Stamp.getMonth())
	{

	    return difyear - 1;
	}
	else if(kidmonth < Stamp.getMonth())
	{

	    return difyear;
	}
	else if(kidmonth = Stamp.getMonth())
    {

        //Same month so check days


        if(kidday > Stamp.getDate())
        {
            return difyear -1;
        }
        else
        {
            return difyear;
        }
        
    
    }

}

function checktelephone(form) {

	var s = new String
	var i = 1
	var nd = 0
	if (document.form1.wrkphone.value == "" )
		{	
		return true
		}
	
	s = document.form1.wrkphone.value
	for(i = 0; i < s.length; i++) {
		if (s.substring(i,i + 1) >= '0' && s.substring(i,i + 1) <= '9') {
			nd++;
		}			
	}
	if (nd != 10) {
		alert('If the Telephone No. is entered it must contain 10 digits')
		document.form1.wrkphone.focus()
		document.form1.wrkphone.select()
		return(false)
	}
	else {
		return(true)
	}								
	
}	


function checknameaddress(form) {

    var startwithchar = /^\w/;
	if (document.form1.wrkesalu.value == "")
		{

		alert("Please enter your name.")
		
		document.form1.wrkesalu.focus()

		document.form1.wrkesalu.select()

		return false
		}
	else if(!document.form1.wrkesalu.value.match(startwithchar))
	{
		alert("Please enter a valid name.")
		document.form1.wrkesalu.focus()
		document.form1.wrkesalu.select()
		return false	    
	
	}


  
    //added this try catch until we add 2 address lines for the survey page
    try
    {
    
        if(trim(document.form1.wrkaddr.value) == "")
        {
            
            if(trim(document.form1.wrkaddr2.value) != "")
            {            
                document.form1.wrkaddr.value = trim(document.form1.wrkaddr2.value)
                document.form1.wrkaddr2.value = '';
            }   
        }
    }catch(exception){}

    
	if (document.form1.wrkaddr.value == "" )
		{	
		alert("Please enter your address.")
		document.form1.wrkaddr.focus()
		document.form1.wrkaddr.select()
		return false
		}
	else if(!document.form1.wrkaddr.value.match(startwithchar))
	{
		alert("Please enter a valid address.")
		document.form1.wrkaddr.focus()
		document.form1.wrkaddr.select()
		return false	
	
	
	}

	if (document.form1.wrkcity.value == "" )
		{	
		alert("Please enter your city.")
		document.form1.wrkcity.focus()
		document.form1.wrkcity.select()
		return false
		}
	else if(!document.form1.wrkcity.value.match(startwithchar))
	{
		alert("Please enter a valid city.")
		document.form1.wrkcity.focus()
		document.form1.wrkcity.select()
		return false	
	
	
	}		

	if (document.form1.wrkstate.value == "" )
		{	
		alert("Please enter your 2 character state or province.")
		document.form1.wrkstate.focus()
		document.form1.wrkstate.select()
		return false
		}
	else if(!document.form1.wrkstate.value.match(startwithchar))
	{
		alert("Please enter a valid state.")
		document.form1.wrkstate.focus()
		document.form1.wrkstate.select()
		return false	
	
	
	}		

	if (document.form1.wrkzipcd.value == "" )
		{	
		alert("Please enter your zip or postal code.")
		document.form1.wrkzipcd.focus()
		document.form1.wrkzipcd.select()
		return false
		}
	else
		{
		/*
		    var char1
		    var char2 
		    var char3
		    var char4 
		    var char5
		    var char6 
			var str = new String()
			str = document.form1.wrkzipcd.value
			str = str.toUpperCase()
			char1 = str.charAt(0)
			char2 = str.charAt(1)
			char3 = str.charAt(2)
			char4 = str.charAt(3)
			char5 = str.charAt(4)
			char6 = str.charAt(5)			
			if (char1 >= "A" && char1 <= "Z" && char2 >= "0" && char2 <= "9" && char3 >= "A" && char3 <= "Z" && char4 >= "0" && char4 <= "9" && char5 >= "A" && char5 <= "Z" && char6 >= "0" && char6 <= "9") 
			{
				//Good Address Candian
			}
			else
			{
				if (char1 >= "0" && char1 <= "9" && char2 >= "0" && char2 <= "9" && char3 >= "0" && char3 <= "9" && char4 >= "0" && char4 <= "9" && char5 >= "0" && char5 <= "9" && char6 == '' ) 
			 	{
			 		//Good Address US
			 	}
			 	else
			 	{
			 		alert("Invalid Zip: Please change and submit again")
			 		document.form1.wrkzipcd.focus()
					document.form1.wrkzipcd.select()
			 		return false
			 	}
			}
			*/
			//var zipExp = /^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z][ ]\d[A-Z]\d$/;
			var zipExp = /^\d{5}-\d{4}|\d{5}|[a-zA-Z]\d{1}[a-zA-Z](\-| |)\d{1}[a-zA-Z]\d{1}$/;
			if(!document.form1.wrkzipcd.value.match(zipExp))
			{
			 		alert("Invalid Zip: Please change and submit again")
			 		document.form1.wrkzipcd.focus()
					document.form1.wrkzipcd.select()
			 		return false			
			
			}
				
		}

	if (document.form1.wrkphonerequired.value == "Y")	
	{	
		if (document.form1.wrkphone.value == "" )
		{	
		alert("Please enter your telephone number.")
		document.form1.wrkphone.focus()
		document.form1.wrkphone.select()
		return false
		}
	}


    document.form1.wrkemail.value = trim(document.form1.wrkemail.value)
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;    
	if (document.form1.wrkEmailRequired.value == "Y")
	{	
		if (document.form1.wrkemail.value == "" )
		{	
		alert("Please enter your email address.")
		document.form1.wrkemail.focus()
		document.form1.wrkemail.select()
		return false
		}
		
		else if(!document.form1.wrkemail.value.match(emailExp))
		{
		    alert("Email address is not in the correct format.  Please correct the email address.");
		    document.form1.wrkemail.focus()
		    document.form1.wrkemail.select()
		    return false
		}
		
	}
	
	else if(document.form1.wrkemail.value != "")
	{
	    
		if(!document.form1.wrkemail.value.match(emailExp))
		{
		    alert("Email address is not in the correct format.  Please correct the email address.");
		    document.form1.wrkemail.focus()
		    document.form1.wrkemail.select()
		    return false
		}
	
	}
	
	return true
}

function checkplgamount(form) {
	try
	{
	var plgpremamt = 0
	var plgkeyedamount = 0
	var plgtotalamount = 0
		
	
    if(document.all)
    {
        var totalprem = theTotalCell.innerText
    } 
    else
    {
        var totalprem = theTotalCell.textContent
    }	
	var temp	
	
	var startsubstr = totalprem.indexOf("$") + 1
		
	var strplgpremamt = totalprem.substring(startsubstr,startsubstr + 20)

	var plgpremamt = parseFloat(strplgpremamt)
	
	var plgchosenamount = 0
		var chosenmode = "0"

	if (document.form1.wrkonemodeonly.value == 'YES') {
		chosenmode = document.form1.wrkpaymode.value
			
	}		
	else {
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
			{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value
				break
				}
			}
	}
	
		
	for (var i = 0; i < document.form1.wrkpledgeamount.length; i++) 
		{
			
		if (document.form1.wrkpledgeamount[i].checked) 
			{
			var plgchosenamount = document.form1.wrkpledgeamount[i].value

			plgchosenamount = plgchosenamount.replace(",","")
			if (isNaN(plgchosenamount) || (plgchosenamount == "")){
				plgchosenamount = "0"
				}			
			plgchosenamount = parseFloat(plgchosenamount)
			
			
			break
			}
		}
	var currentamt = document.form1.wrkpledgeamountother.value
	startsubstr = currentamt.indexOf("$") + 1	
	currentamt = currentamt.substring(startsubstr,startsubstr + 20)
	currentamt = currentamt.replace(",","")
	if (isNaN(currentamt) || (currentamt == "")){
		currentamt = "0"
		}
	plgkeyedamount = parseFloat(currentamt)
	
	var currentamt = document.form1.infoplgamt.value
	startsubstr = currentamt.indexOf("$") + 1	
	currentamt = currentamt.substring(startsubstr,startsubstr + 20)
	currentamt = currentamt.replace(",","")
	if (isNaN(currentamt) || (currentamt == "")){
		currentamt = "0"
		}		
	plgtotalamount = parseFloat(currentamt)

	
	if (parseFloat(plgchosenamount) == 0 )
	{
		//taken out to allow a zero pledge
		if 	(parseFloat(plgkeyedamount) == 0 && document.getElementById("wrkAllowZeroPlg").value == 'Y')
		{	
			var answer = confirm("You entered a zero gift.  Press <Ok> to continue or <Cancel> to change gift amount.")
			if(answer)
			{
				
			}
			else
			{
			
				if (isNaN(document.form1.wrkpledgeamount[0]))
				{
					document.form1.wrkpledgeamountother.focus()
					document.form1.wrkpledgeamountother.select()
				}
				else
				{
					document.form1.wrkpledgeamount[0].focus()
					document.form1.wrkpledgeamount[0].select()
				}
				return false
			
			}
			

		}
		else
		{
		    if(parseFloat(plgkeyedamount) == 0)
		    {
		        alert("Please select a pledge amount"); 
				if (isNaN(document.form1.wrkpledgeamount[0]))
				{
					document.form1.wrkpledgeamountother.focus()
					document.form1.wrkpledgeamountother.select()
				}
				else
				{
					document.form1.wrkpledgeamount[0].focus()
					document.form1.wrkpledgeamount[0].select()
				}
				return false		
		    }
	    }
		
	
				if (parseFloat(chosenmode) < 50)
					{
						temp = document.form1.infoplgamt.value
						temp = temp.replace("$"," ")
						temp = temp * 1.0
						if (document.form1.wrkMinCashPledge.value > temp)
						{

							alert("Please check to make sure you have chosen a payment method and that your donation amount is more than $" + document.form1.wrkMinCashPledge.value)
							document.form1.wrkpledgeamount[0].focus()
							document.form1.wrkpledgeamount[0].select()
							return false
							
						}
						
						temp = document.form1.infopaymt.value
						temp = temp.replace("$"," ")
						temp = temp * 1.0
						if (document.form1.wrkMinCashPay.value >  temp)
						{
							alert("Please check to make sure you have chosen a payment method and that your payment amount is more than $" + document.form1.wrkMinCashPay.value)
							return false
						}
					}
			        else if(parseFloat(chosenmode) > 59 && parseFloat(chosenmode) <70)
			        {			               
        			
						        temp = document.form1.infoplgamt.value
						        temp = temp.replace("$"," ")
						        temp = temp * 1.0
						        if (document.form1.wrkMinEFTPledge.value > temp)
						        {

							        alert("Please check to make sure you have chosen a payment method and that your donation amount is more than $" + document.form1.wrkMinEFTPledge.value)
							        document.form1.wrkpledgeamount[0].focus()
							        document.form1.wrkpledgeamount[0].select()
							        return false
        							
						        }
        						
						        temp = document.form1.infopaymt.value
						        temp = temp.replace("$"," ")
						        temp = temp * 1.0
						        if (document.form1.wrkMinEFTPay.value >  temp)
						        {
							        alert("Please check to make sure you have chosen a payment method and that your donation payment is more than $" + document.form1.wrkMinEFTPay.value)
							        return false
						        }			
        			
			        }						
					else
					{	
						temp = document.form1.infoplgamt.value
						temp = temp.replace("$"," ")
						temp = temp * 1.0
						if (document.form1.wrkMinCCPledge.value > temp)
						{

							alert("Please check to make sure you have chosen a payment method and that your donation amount is more than $" + document.form1.wrkMinCCPledge.value)
							document.form1.wrkpledgeamount[0].focus()
							document.form1.wrkpledgeamount[0].select()
							return false
							
						}
						
						temp = document.form1.infopaymt.value
						temp = temp.replace("$"," ")
						temp = temp * 1.0
						if (document.form1.wrkMinCCPay.value >  temp)
						{
							alert("Please check to make sure you have chosen a payment method and that your monthly amount is more than $" + document.form1.wrkMinCCPay.value)
							return false
						}			
					}
		}
			
	else
	{
		if 	(parseFloat(plgkeyedamount) > 0 )
		{	
			alert("You have both selected a " + document.form1.wrkpledgeterm.value + " amount and keyed a " + document.form1.wrkpledgeterm.value + " amount.  Please do one or the other.")
			document.form1.wrkpledgeamount[0].focus()
			document.form1.wrkpledgeamount[0].select()
			return false
		}
		else
		{
			
			if (parseFloat(chosenmode) < 50)
			{
				temp = document.form1.infoplgamt.value
				temp = temp.replace("$"," ")
				temp = temp * 1.0
				if (document.form1.wrkMinCashPledge.value > temp)
				{

					alert("Please check to make sure you have chosen a payment method and that your donation amount is more than $" + document.form1.wrkMinCashPledge.value)
					document.form1.wrkpledgeamount[0].focus()
					document.form1.wrkpledgeamount[0].select()
					return false
					
				}
				
				temp = document.form1.infopaymt.value
				temp = temp.replace("$"," ")
				temp = temp * 1.0
				if (document.form1.wrkMinCashPay.value >  temp)
				{
					alert("Please check to make sure you have chosen a payment method and that your monthly donation amount is more than $" + document.form1.wrkMinCashPay.value)
					return false
				}
			}
			else
			{	
				temp = document.form1.infoplgamt.value
				temp = temp.replace("$"," ")
				temp = temp * 1.0
				if (document.form1.wrkMinCCPledge.value > temp)
				{

					alert("Please check to make sure you have chosen a payment method and that your donation amount is more than $" + document.form1.wrkMinCCPledge.value)
					document.form1.wrkpledgeamount[0].focus()
					document.form1.wrkpledgeamount[0].select()
					return false
					
				}
				
				temp = document.form1.infopaymt.value
				temp = temp.replace("$"," ")
				temp = temp * 1.0
				if (document.form1.wrkMinCCPay.value >  temp)
				{
					alert("Please check to make sure you have chosen a payment method and that your monthly donation amount is more than $" + document.form1.wrkMinCCPay.value)
					return false
				}			
			}
			var plgtotal = document.form1.infoplgamt.value.replace("$","")
			//alert(plgtotal);
			//Changed for New Life
			//if (parseFloat(plgchosenamount) < parseFloat(plgpremamt))
			if (parseFloat(plgtotal) < parseFloat(plgpremamt))
			{
				var	alertmess ="The " + document.form1.wrkpledgeterm.value + " amount is less than the amount needed for your selected " + document.form1.wrkpremterm.value + "(s).  Please increase your " + document.form1.wrkpledgeterm.value + " amount to " + totalprem
				alert(alertmess)
				document.form1.wrkpledgeamount[0].focus()
				document.form1.wrkpledgeamount[0].select()
				return false
			}


				

			return true
			}
		}
	
		var plgtotal = document.form1.infoplgamt.value.replace("$","")
			//alert(plgtotal);
			//Changed for New Life
		//if (parseFloat(plgtotalamount) < parseFloat(plgpremamt))
		if (parseFloat(plgtotal) < parseFloat(plgpremamt))
		{
			var	alertmess ="The " + document.form1.wrkpledgeterm.value + " amount is less than the amount needed for your selected " + document.form1.wrkpremterm.value + "(s).  Please increase your " + document.form1.wrkpledgeterm.value + " amount to " + totalprem
			alert(alertmess)
			document.form1.wrkpledgeamount[0].focus()
			document.form1.wrkpledgeamount[0].select()
			return false
		}
		else
		{
			return true
		}
		

	}	

		
	catch(exception)
	{

	alert(exception.message)			
	document.form1.wrkpledgeamountother.focus()
	document.form1.wrkpledgeamountother.select()
	return false
	}

}

function checkifpremiumselected(form) {

    if(document.all)
    {
        var totalprem = theTotalCell.innerText
    } 
    else
    {
        var totalprem = theTotalCell.textContent
    }		
	var startsubstr = totalprem.indexOf("$") + 1
	var strplgpremamt = totalprem.substring(startsubstr,startsubstr + 20)
	var plgpremamt = parseFloat(strplgpremamt)

	var list = document.form1.wrkprem
	var checknum = list.selectedIndex
	var premselstring = list.options[list.selectedIndex].value
	var startsubstr = premselstring.indexOf("&B=")

	if  (startsubstr != -1)
		{
		startsubstr = startsubstr + 3	
		var endsubstr = premselstring.indexOf("&C=")
		var valprem = premselstring.substring(startsubstr,endsubstr)
		
		for (var i = 0; i < premarray.length; i++)
			{	
			startsubstr = premarray[i].indexOf(valprem)
			if (startsubstr != -1)
				{
				return true
				}		
			
			}	
			
			var	alertmess ="A " + document.form1.wrkpremterm.value + "  has been selected but has not been added to your list"
			alert(alertmess)
			document.form1.wrkprem.focus()

			return false
		
		}
	else
		{
		return true
		}			
			


}

function checkplgamounterr(form) {

	var plgpremamt = 0
	var plgkeyedamount  = 0
	
    if(document.all)
    {
        var totalprem = theTotalCell.innerText
    } 
    else
    {
        var totalprem = theTotalCell.textContent
    }	
		
	
	var startsubstr = totalprem.indexOf("$") + 1
		
	var strplgpremamt = totalprem.substring(startsubstr,startsubstr + 10)

	var plgpremamt = parseFloat(strplgpremamt)		
	

	
	var currentamt = document.form1.infoplgamt.value
	

		
	var startsubstr = currentamt.indexOf("$") + 1	
	var currentamt = currentamt.substring(startsubstr,startsubstr + 20)
	currentamt = currentamt.replace(",","")
	if (isNaN(currentamt)){
		currentamt = "0"
	}
	plgkeyedamount = parseFloat(currentamt)		

	if 	(parseFloat(plgkeyedamount) == 0 )
		{	
		alert("Please select or enter an amount.")
		document.form1.infoplgamt.focus()
		document.form1.infoplgamt.select()
		return false
		}
	else
		{
		if (parseFloat(plgkeyedamount) < parseFloat(plgpremamt))
			{
		var	alertmess ="The " + document.form1.wrkpledgeterm.value + " amount is less than the amount needed for your selected " + document.form1.wrkpremterm.value + "(s).  Please increase your " + document.form1.wrkpledgeterm.value + " amount to " + totalprem
			alert(alertmess)
			document.form1.infoplgamt.focus()
			document.form1.infoplgamt.select()
			return false
			}
		else
			{	
			return true
			}
		}		


}



function checkpremcnt(form,msg)
{

    if(premiumcount == 0 && msg < 3)
    {
        if(msg == 1)
        {
            alert("You must select at least one " + document.form1.wrkpremterm.value);
        }
        else if(msg == 2)
        {
            alert("You have selected to recieve a " + document.form1.wrkpremterm.value + ".  Please select a "+ document.form1.wrkpremterm.value+" or specify no " +document.form1.wrkpremterm.value); 
        }
        return false
    
    }
    if(premiumcount > 0 && msg == 3)
    {
        alert("You have specified to recieve no "+ document.form1.wrkpremterm.value + "(s).  Please remove all " +document.form1.wrkpremterm.value + "s."); 
        return false    
    }
    return true

}

function checkshipadr(form)
{

    var shipstr = window.document.getElementById("wrkshipstring").value
    if(premiumcount > 0)
    {
        if(shipstr == "")
        {
                alert("Please provide a shipping address for each gift");
                return false;
        }
        
        
        shipstr = shipstr.split("|");
        if(shipstr.length < premiumcount)
        {
            alert("Please provide a shipping address for each gift");
            return false;
        }
        
    }    
        return true
        


}

function checkpaymode(form) {

	var chosenmode = "0"

var plgkeyedamount = 0

	var currentamt = document.form1.wrkpledgeamountother.value
	startsubstr = currentamt.indexOf("$") + 1	
	currentamt = currentamt.substring(startsubstr,startsubstr + 20)
	currentamt = currentamt.replace(",","")
	if (isNaN(currentamt) || (currentamt == "")){
		currentamt = "0"
		}
		
		plgkeyedamount = parseFloat(currentamt)

    if 	(parseFloat(plgkeyedamount) == 0 && document.getElementById("wrkAllowZeroPlg").value == 'Y')
    {
        chosenmode = 01;
    
    }


	if (document.form1.wrkonemodeonly.value == 'YES') {
		chosenmode = document.form1.wrkpaymode.value
			
	}		
	else {
		for (var i = 0; i < document.form1.wrkpaymode.length; i++) 
			{
			if (document.form1.wrkpaymode[i].checked) 
				{
				var chosenmode = document.form1.wrkpaymode[i].value
				break
				}
			}
	}	
	
	if (parseFloat(chosenmode) == 0 )
		{	
		
		
		alert("Please select a method of payment.")
		if (document.form1.wrkonemodeonly.value != 'YES') {
			document.form1.wrkpaymode[0].focus()
			document.form1.wrkpaymode[0].select()
		}		
		
		return false
		}
		
	
	if (parseFloat(chosenmode) > 50 && parseFloat(chosenmode) < 60 && document.getElementById("DisplayCCInfo").value== 'Y')
		{
		var chosenpaycard = "0"
		for (var i = 0; i < document.form1.wrkpaycard.length; i++) 
			{
			if (document.form1.wrkpaycard[i].checked) 
				{
				var chosenpaycard = document.form1.wrkpaycard[i].value
				break
				}
			}
		if (parseFloat(chosenpaycard) == 0 )
			{	
			alert("Please select a credit card.")
				document.form1.wrkpaycard[0].focus()
				document.form1.wrkpaycard[0].select()
			return false
			}
			
		if (document.form1.wrkccno.value == "")
			{
			alert("Please enter a credit card number")
			document.form1.wrkccno.focus()
			document.form1.wrkccno.select()
			return false
			}
		
		    //removes spaces
		    document.form1.wrkccno.value = document.form1.wrkccno.value.replace(/\s/g, '');	
		    //removes dashes
		    document.form1.wrkccno.value = document.form1.wrkccno.value.replace(/-/g, '');	
			
		if(chosenpaycard == "A")
		{
		    //American Express has only 15 numbers
		    
		    if(document.form1.wrkccno.value.length != 15)
		    {
		        alert("Please check the number of digits in the credit card field");
		        document.form1.wrkccno.focus()
			    document.form1.wrkccno.select()
		        return false;
		    }
			
		
		}
		else
		{
		    if(document.form1.wrkccno.value.length != 16)
		    {
		        alert("Please check the number of digits in the credit card field");
		        document.form1.wrkccno.focus()
			    document.form1.wrkccno.select()		        
		        return false;
		    }		
		
		}				

			
			
		var chosenccexpmm = "00"
		for (var i = 0; i < document.form1.wrkccexpmm.length; i++) 
			{
			if (document.form1.wrkccexpmm[i].selected) 
				{
				var chosenccexpmm = document.form1.wrkccexpmm[i].value
				break
				}
			}
			
		if (parseFloat(chosenccexpmm) == 0 ) 
			{	
			alert("Please select a credit card expiration month.")
			document.form1.wrkccexpmm[0].focus()

			return false
			}
			
			
		var chosenccexpyyyy = "00"
		for (var i = 0; i < document.form1.wrkccexpyyyy.length; i++) 
			{
			if (document.form1.wrkccexpyyyy[i].selected) 
				{
				var chosenccexpyyyy = document.form1.wrkccexpyyyy[i].value
				break
				}
			}
			
		if (parseFloat(chosenccexpyyyy) == 0 )
			{	
			alert("Please select a credit card expiration year.")
			document.form1.wrkccexpyyyy[0].focus()

			return false
			}
		return true			
		}
	
	if (parseFloat(chosenmode) > 60)
	{

	    document.form1.wrkrouting.value = FixPhone(document.form1.wrkrouting.value);
	    document.form1.wrkeftnum.value = FixPhone(document.form1.wrkeftnum.value);
	    if(FixPhone(document.form1.wrkrouting.value) == "")
	    {
	        alert("Please enter EFT routing number.");
	        document.form1.wrkrouting.focus();
	        return false;
	    }
	    if(document.form1.wrkrouting.value.length !=9)
	    {
	        alert("Please enter a correct EFT routing number.");
	        document.form1.wrkrouting.focus();
	        return false;	    
	    }
	    if(FixPhone(document.form1.wrkeftnum.value) == "")
	    {
	        alert("Please enter EFT account number.");
	        document.form1.wrkeftnum.focus();
	        return false;
	    }
	    if(document.form1.wrkefttype.value == "C" || document.form1.wrkefttype.value == "S" || document.form1.wrkefttype.value == "c" || document.form1.wrkefttype.value == "s")
	    {
	    }
	    else
	    {
	        alert("Please enter your EFT Account Type.");
	        document.form1.wrkefttype.focus();
	        return false;
	    }
	    
	    return true;
	}			
	if (parseFloat(chosenmode) < 50 && document.getElementById("DisplayCCInfo").value == 'Y')
		{
			
		if (document.form1.wrkccno.value >= "0")
			{
			alert("You have selected the bill me method but have also entered a charge card number.")

				document.form1.wrkpaymode[0].focus()
				document.form1.wrkpaymode[0].select()
		
			return false
			}
			
		return true			
		}
		
	return true
}

function clearpremnn4(form) {

	document.form1.wrkpremtext.value = ""
	premiumcount = 0

}




function rebuildPrem(form) {
	var newCell
	var endit = false
	var i = 0
	var innercontents = " "
	var arraylength = premarray.length
	
	

	for (i = 0; i < premarray.length; i++)
	{
		
		if (premarray[i] != "") 
		{
			
			endit = false


			if ( i + 1 == arraylength)   {
				endit = true
				
			}

			else {
	
				if (premseqarray[i + 1] == 'S')  {
					endit = true
				}
			}
											 				
			if (premseqarray[i] == 'S') 
				{
					
				var valprem = premarray[i]
				selectedpremiums[premiumcount] = premarray[i]

				var valdesc = premdescarray[i]
				selectedpremdesc[premiumcount] = premdescarray[i]

		
				var valamount = premamtarray[i]
				selectedpremamt[premiumcount] = premamtarray[i]	
	
				var newRow = premTableBody.insertRow(-1)
				newCell = newRow.insertCell(0)
				
				selecteditems[premiumcount] = new Array('none')
				selecteditemsqty[premiumcount] = new Array('0')
				selecteditemsdesc[premiumcount] = new Array(' ')
	
				selectedstringnumber[premiumcount] = premstringnumberarray[i]
				checknum = premstringnumberarray[i]



				if (premitemarray[i] == 'none')

					{	
						
					
					premiumcount = premiumcount + 1
					var		cellcontents = '<span class = "elements" style="display: none;" width = "5%"><center>' + premiumcount + '</center></span>'
					//var		cellcontents = '<span class = "elements" width = "5%"><center>' + '' + '</center></span>'
					newCell.innerHTML = cellcontents
		
					newCell = newRow.insertCell(1)
					
					
		            if(document.getElementById("wrkallowship").value == 'Y')
		            {
		            
		                if(document.getElementById("ShpAdrReq").value == 'Y')
		                {    
		                    name = "Recipient Required";
		                }
		                else
		                {
		                    name = "Add Recipient";
		                }		            
		                
		                if(document.getElementById("wrkshipstring").value != "")
                        {
                            var shipadrs = document.getElementById("wrkshipstring").value.split('|'); 
                            for(var q = 0; q < shipadrs.length; q++)
                            {
                                var details = shipadrs[q].split('^^');	
                                if(details[0] == premiumcount)
                                {
                                    name = details[1] + ' ' + details[2];
                                }
                            
                            }	                
		                    
		                }

		                if(document.getElementById("ShpAdrReq").value == 'Y')
		                {
		                    cellcontents = '<span class = "elements" width="70%" >' + valdesc + "<br>" + " <a href ='javascript:ShipTo(" + premiumcount + ")' style='color: red'>" + name + "</a>"  +'</span>'
		                }
		                else
		                {
		                    cellcontents = '<span class = "elements" width="70%" >' + valdesc + "<br>" + " <a href ='javascript:ShipTo(" + premiumcount + ")' style='color: blue'>" + name + "</a>"  +'</span>'
		                }
		            
		            }
		            
                    else
                    {
		                cellcontents = '<span class = "elements" width="70%" >' + valdesc +'</span>'
		            }
		
							
					
					
					newCell.innerHTML = cellcontents
		
					newCell = newRow.insertCell(2)
					cellcontents = '<span class = "elements" width="5%" > <table align="right"> $' + valamount  + ' </table></span>'
					newCell.innerHTML = cellcontents
		
					newCell = newRow.insertCell(3)
					newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Remove" onclick="removeRow(this.form,0)"></span>'
		
					newCell = newRow.insertCell(4)
					
		            if(document.getElementById("wrkpremshortlist").value == "Y")
		            {
		                newCell.innerHTML = '<span class = "elements" style="display: none;" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		            }
		            else
		            {
		                newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		            }					
					//newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		          
		            //if(document.getElementById("wrkallowship").value == 'Y')
		           // {
		            //    newCell = newRow.insertCell(5)
		            //    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Ship Adr" onclick="ShipTo(form,' +premiumcount+')"></span>'	
    	                
    	         
    	            //}					
					
					}
				else
					{

					innercontents = '<table cellpadding = "0" cellspacing = "0" class = "elements"><tr>  <td width="15%" colspan = "3"><b>' + valdesc + '</b></td></tr>'				

					selecteditems[premiumcount][0] = premitemarray[i]
		
					selecteditemsdesc[premiumcount][0] = premitemdescarray[i]
	
					selecteditemsqty[premiumcount][0] = premitemqtyarray[i]
					
					var numberofitems = premitemqtyarray[i]
					var itemdesc = premitemdescarray[i]
					var itemcode = premitemarray[i]
					var itemcontents =  '<tr><td width="15%"><small><center>Qty-&nbsp;&nbsp;' + numberofitems + '</center></small></td>' + '<td width="20%"><small>Item-' + itemcode + '&nbsp;&nbsp;</small></td><td width="65%"><small>'  + itemdesc + '</small></td><tr>'
					innercontents = innercontents + itemcontents
					var itemcount = 1
					premiumcount = premiumcount + 1
					
					if (endit)
						{
										
						innercontents = innercontents + "</table>"
								
						var		cellcontents = '<span class = "elements" style="display: none;" width = "5%"><center>' + premiumcount + '</center></span>'
						//var		cellcontents = '<span class = "elements" width = "5%"><center>' + '' + '</center></span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(1)
						cellcontents = '<span class = "elements" width="70%" >' + innercontents  + '</span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(2)
						cellcontents = '<span class = "elements" width="5%" > <table align="right"> $' + valamount  + ' </table></span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(3)
						newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Remove" onclick="removeRow(this.form,0)"></span>'
		
						newCell = newRow.insertCell(4)
						
		                if(document.getElementById("wrkpremshortlist").value == "Y")
		                {
		                    newCell.innerHTML = '<span class = "elements" style="display: none;" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                }
		                else
		                {
		                    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                }						
						
						//newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                //if(document.getElementById("wrkallowship").value == 'Y')
		                //{
		                //    newCell = newRow.insertCell(5)
		                //    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Ship Adr" onclick="ShipTo(form,' +premiumcount+')"></span>'	
    	                //}					
						}
					}
				}			
			else
				{
				var premiumcountless = premiumcount - 1
	
				selecteditems[premiumcountless][itemcount] = premitemarray[i]
		
				selecteditemsdesc[premiumcountless][itemcount] = premitemdescarray[i]
				selecteditemsqty[premiumcountless][itemcount] = premitemqtyarray[i]
				var numberofitems = premitemqtyarray[i]
				var itemdesc = premitemdescarray[i]
				var itemcode = premitemarray[i]
				var itemcontents =  '<tr><td width="15%"><small><center>Qty-' + numberofitems + '&nbsp;&nbsp;</center></small></td>' + '<td width="20%"><small>Item-' + itemcode + '&nbsp;&nbsp;</small></td><td width="65%"><small>'  + itemdesc + '</small></td><tr>'
				innercontents = innercontents + itemcontents
				itemcount = itemcount + 1
				
				if (endit)
						{
						innercontents = innercontents + "</table>"
								
						//var		cellcontents = '<span class = "elements" width = "5%"><center>' + premiumcount + '</center></span>'
						var		cellcontents = '<span class = "elements" width = "5%"><center>' + '' + '</center></span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(1)
						cellcontents = '<span class = "elements" width="70%" >' + innercontents  + '</span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(2)
						cellcontents = '<span class = "elements" width="5%" > <table align="right"> $' + valamount  + ' </table></span>'
						newCell.innerHTML = cellcontents
		
						newCell = newRow.insertCell(3)
						newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Remove" onclick="removeRow(this.form,0)"></span>'
		
						newCell = newRow.insertCell(4)
		                if(document.getElementById("wrkpremshortlist").value == "Y")
		                {
		                    newCell.innerHTML = '<span class = "elements" style="display: none;" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                }
		                else
		                {
		                    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                }						
						
						//newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "View" onclick="ViewTablePrem(this.form,0)"></span>'
		                //if(document.getElementById("wrkallowship").value == 'Y')
		                //{
		                //    newCell = newRow.insertCell(5)
		                //    newCell.innerHTML = '<span class = "elements" width = "10%"><input type="button" value = "Ship Adr" onclick="ShipTo(form,' +premiumcount+')"></span>'	
    	                //}				
						}
				}
		}		
	}	
		var newamt = updatepremtotal()	
		
    if(document.all)
    {
        theTotalCell.innerText = "$ " + newamt + " "
    } 
    else
    {
        theTotalCell.textContent = "$ " + newamt + " "
    }		
	
}  

function recalctheinfonopay(form) {

	var curplgamt = 0.0
	var chosenmode = "0"
	var listnopay = document.form1.infonopay

	var inamt = new String(" ")
		
	inamt = document.form1.infopaymt.value
	

	var plgamt = new String(" ")
	
	plgamt = document.form1.infoplgamt.value
	
	
	
	var startsubstr = inamt.indexOf("$") + 1	
	var strpayamt = inamt.substring(startsubstr,startsubstr + 20)
	strpayamt = strpayamt.replace(",","")

	var startsubstr = plgamt.indexOf("$") + 1	
	var strplgamt = plgamt.substring(startsubstr,startsubstr + 20)
	strplgamt = strplgamt.replace(",","")

	var curplgamt = parseFloat(strplgamt)
	var curpayamt = parseFloat(strpayamt)
	var curnopay = parseInt(curplgamt/curpayamt)
	if (curnopay * curpayamt < curplgamt){
		curnopay = curnopay + 1
		}



	
					if (document.form1.wrklumponly.value != 'YES') {
					listnopay.selectedIndex = parseInt(curnopay)
					}
		
	}		

function keyedPremium(form){
		var enteredpremcode = document.form1.wrkpremcode.value.toUpperCase()
		premiumnotfounderrorflag = "NO"
		document.form1.wrkpremcode.value = enteredpremcode
		var list = document.form1.wrkprem
		var thisprem = ""
		for (var i = 0; i < document.form1.wrkprem.length; i++) 
		{

			var premselstring = list.options[parseInt(i)].value
			var startsubstr = premselstring.indexOf("&B=") 
			if  (startsubstr != -1)
			{ 
				startsubstr = startsubstr + 3
	
				var endsubstr = premselstring.indexOf("&C=")


				
				var thisprem = premselstring.substring(parseInt(startsubstr),parseInt(endsubstr))

				if (thisprem == enteredpremcode) 
					{
					list.selectedIndex = parseInt(i)
						
					return
					}
			}			
		}
		alert("This premium code not found")
		//form.wrkpremcode.select()
		//form.wrkpremcode.focus()

		list.selectedIndex = 0
		premiumnotfounderrorflag = "YES"

				
		return
		
}

function keyedPremiumSize(form){
		var enteredpremcode = document.form1.wrkpremcode.value.toUpperCase()
		var enteredpremsize = document.form1.wrkpremsize.value.toUpperCase()
		document.form1.wrkpremcode.value = enteredpremcode
		document.form1.wrkpremsize.value = enteredpremsize
		var listofsizes = ""
		var list = document.form1.wrkprem
		var thisprem = ""
		var foundprem = false
		premiumsizeerrorflag = "NO"
		for (var i = 0; i < document.form1.wrkprem.length; i++) 
		{

			var premselstring = list.options[parseInt(i)].value
			var startsubstr = premselstring.indexOf("&B=") 
			if  (startsubstr != -1)
			{ 
				startsubstr = startsubstr + 3	
				var endsubstr = premselstring.indexOf("&C=")
				var thisprem = premselstring.substring(parseInt(startsubstr),parseInt(endsubstr))
				if (thisprem == enteredpremcode) 
					{
					foundprem = true
					startsubstr = premselstring.indexOf("&C=") + 3
					endsubstr = premselstring.indexOf("&P=") 
					var thissize = premselstring.substring(parseInt(startsubstr),parseInt(endsubstr))
					if (listofsizes == ""){
						listofsizes = thissize
						}
					else{
						listofsizes = listofsizes + "; " + thissize
						}		
					if (thissize == enteredpremsize){ 
						list.selectedIndex = parseInt(i)
						return
						}
					}
			}			
		}
		if (foundprem){
			var sizeerror = 'This size not found, choose from the following: ' + listofsizes
			alert(sizeerror)

			document.form1.wrkpremsize.select()
			document.form1.wrkpremsize.focus()
			list.selectedIndex = 0
			premiumsizeerrorflag = "YES"
			return
			}
		else{
		//	alert("This premium not found")
		//	premiumnotfounderrorflag = "YES"
		//	form.wrkpremcode.focus()
		//	form.wrkpremcode.select()
		//	list.selectedIndex = 0
			return
			}	
		
}	

function SearchName(form)
{	
    var SName = document.form1.wrkesalu.value
    SName = SName.replace('&','and')
	SName = SName.toUpperCase()	
	SName = CleanSearch(SName)
	var SPageID = document.form1.wrkwpppid.value
	var gowhere = 'AllegWebApplicationsV860/Search.aspx?Name=' + SName + '&SEARCH=N' + '&PAGEID=' + SPageID
	searchwindow = window.open(gowhere,"SearchNames",config='height=840,width=670,status=yes,scrollbars=1')
	searchwindow.focus();
	return false

}
function SearchAddress(form)
{

    try
    {
        if(trim(document.form1.wrkaddr.value) == "")
        {
            
            if(trim(document.form1.wrkaddr2.value) != "")
            {            
                document.form1.wrkaddr.value = trim(document.form1.wrkaddr2.value)
                document.form1.wrkaddr2.value = '';
            }   
        }
    }catch(e){} //used if address line 2 is not displayed        
    
    var SAddr = trim(document.form1.wrkaddr.value)
    SAddr = SAddr.replace('#',' ')
    SAddr = SAddr.toUpperCase()
    SAddr = CleanSearch(SAddr)
    var SPageID = document.form1.wrkwpppid.value  
	var gowhere = 'AllegWebApplicationsV860/Search.aspx?Address=' + SAddr + '&SEARCH=A' + '&PAGEID=' + SPageID
	searchwindow = window.open(gowhere,"SearchNames",config='height=840,width=670,scrollbars=1')
	searchwindow.focus();
	return false
}
function SearchPhone(form)
{
    var SPhone= document.form1.wrkphone.value
    SPhone = FixPhone(SPhone);
    SPhone = SPhone.toUpperCase()
    SPhone = CleanSearch(SPhone)
    var SPageID = document.form1.wrkwpppid.value
	var gowhere = 'AllegWebApplicationsV860/Search.aspx?Phone=' + SPhone + '&SEARCH=P' + '&PAGEID=' + SPageID
	searchwindow = window.open(gowhere,"SearchNames",config='height=840,width=670,scrollbars=1')
	searchwindow.focus();
	return false
}
function FixPhone(s)
{

    s = s.replace(/[^0-9]/g,'');
    return s;    

}
function CleanSearch(s)
{

    s = s.replace(/[\[\<\>\{\}\[\]\\|~`\^#]/g,'');
    return s;

}
function SearchCompany(form)
{

    var SCompany= document.form1.wrkmname.value
    SCompany = SCompany.toUpperCase()
    SCompany = CleanSearch(SCompany)
    var SPageID = document.form1.wrkwpppid.value
	var gowhere = 'AllegWebApplicationsV860/Search.aspx?Company=' + SCompany + '&SEARCH=C' + '&PAGEID=' + SPageID
	searchwindow = window.open(gowhere,"SearchNames",config='height=840,width=670,scrollbars=1')
	searchwindow.focus();
	return false
}

function SelectDaySpon(form)
{
	var SPageID = document.form1.wrkwpppid.value
	var SDaysOut = document.form1.wrkDaysOut.value
	callltrs = document.getElementById("selectCall");
	var SStation = callltrs.options[callltrs.selectedIndex].value;
	var SPAmt = document.form1.infoplgamt.value

    SPAmt = SPAmt.replace('$','')
    SPAmt = SPAmt.replace(' ','')	
    
    if(SPAmt == '')	
	{	
	    alert("Please select a pledge amount before selecting Day Sponsor dates.");
		return false;
		//SPAmt = '0';
	}

	var gowhere  = 'AllegWebApplicationsV860/DayspnForm.aspx?PAGEID=' + SPageID + '&DAYSOUT=' + SDaysOut + '&STATION=' + SStation + '&AMOUNT=' + SPAmt + '&DEBUG=TRUE'

	var newwindow = window.open(gowhere,"DaySponsor",config='height=600,width=1000,status=yes');
	newwindow.focus();
	return false


}
function ClearNameAddress(form)
{
	document.form1.wrkesalu.value = ''
	document.form1.wrkmname.value = ''
	try{
	    document.form1.wrkaddr2.value = ''
	}
	catch(e){} //used if address line 2 is not displayed
	document.form1.wrkaddr.value  = ''
	document.form1.wrkcity.value  = ''
	document.form1.wrkstate.value = ''
	document.form1.wrkzipcd.value = ''
	document.form1.wrkphone.value = ''
	document.form1.wrkemail.value = ''
	document.form1.wrkstatn.value = ''
	document.form1.wrkmembr.value = ''
	document.form1.wrkVolSelected.value = ''
	



}	
function GetPremiums(curplgamt)
{
	var pageid
	var Stamp = new Date()

	var Hours
	var Mins
	var Seconds
	var Time
		
	Hours = Stamp.getHours();
	Mins = Stamp.getMinutes();
	Seconds = Stamp.getSeconds();
	Time = (Hours*10000) + (Mins*100) + Seconds

				if(typeof obj == 'undefined')
				{
				    try
				    {
					    obj = new ActiveXObject("Msxml2.XMLHTTP");
				    }
				    catch(e)
				    {
					    try
					    {
						    obj = new ActiveXObject("Microsoft.XMLHTTP");
					    }
					    catch(e1)
					    {
					        try
					        {
							    obj = false
						        obj = new XMLHttpRequest();
						        obj.overrideMimeType("text/plain");
        						
        						
						            if (!obj) {
								        alert('Cannot create XMLHTTP instance');
								        return false;
						        }				        
					        }
					        catch(e2)
					        {
						        obj = null;
						    }
					    }
				    }
			    }
				if(obj!=null)
				{
				    obj.abort();

					pageid = document.form1.wrkwpppid.value			

							
							if(document.getElementById("wrkpremshortlist").value == "Y")
							{
                                    var premtable = document.getElementById("NEWPREMTABLE");
                                    var premtableopt = document.getElementById("NEWPREMTABLEOPTIONS");
                                    premtableopt.innerHTML = "";
                                    
                                    var table = document.createElement("table");
                                    var tbody = document.createElement("tbody");
                                    var tr = document.createElement("tr");
                                    var td = document.createElement("td");
                                    td.innerHTML = ".....Loading " + document.form1.wrkpremterm.value+ "s.....";

                                    tr.appendChild(td);
                                    tbody.appendChild(tr);
                                    table.appendChild(tbody);
                                    premtable.innerHTML = "";
                                    premtable.appendChild(table);
                                   
                                   
							    obj.onreadystatechange = shortProcessResponse;
							}
							else
					        {   
					        
							    for(var i = 0; i<window.document.form1.wrkprem.length; i++)
							    {
    								
								    window.document.form1.wrkprem.options[i].text = '';
    							

							    }

							    window.document.form1.wrkprem.length = 1;
							    window.document.form1.wrkprem.options[0].text = '....Loading.....'					         
					            obj.onreadystatechange = ProcessResponse;
					        }
					obj.open("Get", "AllegWebApplicationsV860/PremiumFill.aspx?CURPLGAMT="+curplgamt+"&PAGEID=" + pageid + "&UNIQUE=" + Time,true);
					obj.send(null);
				}
				return false;


}
function shortProcessResponse()
{

				
		var premstr;
		var optstr;
		var descstr;
	
		var premtable = document.getElementById("NEWPREMTABLE");
		
		var premtableopt = document.getElementById("NEWPREMTABLEOPTIONS");
		
		var table = document.createElement("table");
		var tblopt = document.createElement("table");
		//table.setAttribute('className','elements');
		table.className = 'elements'
		tblopt.className = 'elements'		
				var cnt = 0;
        
        
				if(obj.readyState == 4)
				{

					if(obj.status == 200)
					{

                        
                        var tbody = document.createElement("tbody");
                        var tbodyopt = document.createElement("tbody");
						premstr = obj.responseText;
						premstr = premstr.split("#");
						
						//alert(premstr);
						if(premstr[0] != 'ERROR')
						{



                                
								var troptyes = document.createElement("tr");
								var tdpremyes = document.createElement("td");
								var tdpremyeslbl = document.createElement("td");
								var troptno = document.createElement("tr");
								var tdpremno = document.createElement("td");
								var tdpremnolbl = document.createElement("td");
								
							    if(document.all)
	                            {
								    var premyes = document.createElement("<input type='radio' name='premyesno' id='premyes'>");
							    }
							    else
							    {
							        var premyes = document.createElement("input");
							        premyes.type = "radio";
							        premyes.name = "premyesno";
							        premyes.id = "premyes";
							    }
							
							
							
							
								tdpremyeslbl.innerHTML = document.getElementById("wrkyespremopt").value;
								tdpremyes.appendChild(premyes);
				                troptyes.appendChild(tdpremyes);
				                troptyes.appendChild(tdpremyeslbl);
								
								//var premno = document.createElement("<input type='radio' name='premyesno' id='premno' checked>");
								
							    if(document.all)
	                            {
								    var premno = document.createElement("<input type='radio' name='premyesno' id='premno' checked>");
							    }
							    else
							    {
							        var premno = document.createElement("input");
							        premno.type = "radio";
							        premno.name = "premyesno";
							        premno.id = "premno";
							        premno.checked = "true";
							    }
															
								tdpremnolbl.innerHTML = document.getElementById("wrknopremopt").value;
				                tdpremno.appendChild(premno);
				                troptno.appendChild(tdpremno);
				                troptno.appendChild(tdpremnolbl);
								
                                tbodyopt.appendChild(troptno);
                                tbodyopt.appendChild(troptyes);
                                tblopt.appendChild(tbodyopt);
                                
                             //tbody.appendChild(tropt);

							for(var x = 3; x<premstr.length; x++)
							{
								optstr = premstr[x].split("^");
								premstr[x] = optstr[0]
								if(optstr[1] != null)
								{
								//alert(premstr[x]);
								
								
								
								
								var tr = document.createElement("tr");

								
								var tdcheck = document.createElement("td");
								var tdAmt = document.createElement("td");
								var tdDesc = document.createElement("td");
								var tdView = document.createElement("td");
								var tdhidden = document.createElement("td");
						
							
							    
								tdcheck.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id='cb' name='item1' type='button' value='Add' onclick='insertpremiumRowShort(" + cnt + ");' />"
								
								descstr = premstr[x].split("-");
								
								tdAmt.innerHTML = descstr[0] + "-";
								
								var tmpstr = descstr[1];
								for(var h = 2; h < descstr.length; h++)
								{
								    tmpstr = tmpstr + '-' + descstr[h]
								}
							
								tdDesc.innerHTML = tmpstr;
								
								
								//tdView.innerHTML = "<u>View Gift Details</u>"
								tdView.innerHTML = "<a href ='dspitems.asp?" + optstr[1] + "' target='_blank' style='color: blue'>View Gift Details</a>";
								tdhidden.innerHTML = optstr[1];
								
								
								
								tdAmt.setAttribute('vAlign','top');
								tdAmt.setAttribute('align','right');
								tdAmt.setAttribute('width','80');
								tdcheck.setAttribute('vAlign','top');
								tdDesc.setAttribute('vAlign','top');
								tdDesc.setAttribute('align','left');

								tdView.setAttribute('vAlign','top');

								
								tr.appendChild(tdcheck);
								
								tr.appendChild(tdAmt);
								
								tr.appendChild(tdDesc);
								
								tr.appendChild(tdView);
								
							
								tdhidden.style.display = 'none'; 
							
								tr.appendChild(tdhidden);
								
								tbody.appendChild(tr);
								cnt ++;

								}
								else
								{
	
									
								
								}
							}
							
							
							table.appendChild(tbody);
						    	

						}
						else
						{
						    alert("Premium Setup Error");
						}
						premstr = ' '

						
						
					}
					else
					{
						//alert("Premium Setup Error");
					}
	
		                 premtable.innerHTML = "";
		                 

		            //if premium is not required then we want to display yes no options.
		            if(document.getElementById("premiumReq").value != 'Y')
		            {
		     
		                premtableopt.appendChild(tblopt);
		                
		                
		                if(premiumcount > 0)
			            {   
			                document.getElementById("premyes").checked = true;
			            }		                
                    }
                    premtable.appendChild(table);			
				}
				


}
function ProcessResponse()
{
				
		var premstr;
		var optstr;

				if(obj.readyState == 4)
				{
					
					if(obj.status == 200)
					{

						premstr = obj.responseText;
						premstr = premstr.split("#");
						
						
						if(premstr[0] != 'ERROR')
						{

							for(var x = 0; x<premstr.length; x++)
							{
								optstr = premstr[x].split("^");
								premstr[x] = optstr[0]
								if(optstr[1] != null)
								{
									window.document.form1.wrkprem.options[x] = new Option(premstr[x],optstr[1],false,false);
								}
								else
								{
									window.document.form1.wrkprem.options[x] = new Option(premstr[x],'**head**',false,false);
									
								
								}
							}
						}
						else
						{
						    alert("Premium Setup Error");
						}
						premstr = ' '

						
						
					}
					else
					{
						//alert("Premium Setup Error");
					}
				
				}
}

function SendAnswerEmails(pagetype)
{
	var pageid
	var tranid


				try
				{
					objanswer = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						objanswer = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(e1)
					{
					        try
					        {
							    objanswer = false
						        objanswer = new XMLHttpRequest();
						        objanswer.overrideMimeType("text/plain");
        						
        						
						            if (!objanswer) {
								        alert('Cannot create XMLHTTP instance');
								        return false;
						        }				        
					        }
					        catch(e2)
					        {
						        objanswer = null;
						    }
					}
				}
				if(objanswer!=null)
				{
					
					if(pagetype == "PLG")
					{
					    pageid = document.form1.wrkwpppid.value
					    tranid = document.form1.wrktrans.value
                    }
                    else
                    {
                        pageid = document.form1.wrkwsspid.value
					    tranid = document.form1.wrktrans.value
                    
                    }
					if(tranid != "")
				    {
					    objanswer.onreadystatechange = ProcessAnswerResponse;
					    objanswer.open("Get", "AllegWebApplicationsV860/EmailManager.aspx?TRANID="+tranid+"&PAGEID=" + pageid+"&PAGETYPE=" + pagetype,true);
					    objanswer.send(null);
					}
				}
				return false;




}
function ProcessAnswerResponse()
{

				if(objanswer.readyState == 4)
				{

					if(objanswer.status == 200)
					{

					}
					else
					{
						alert(objanswer.statusText);
					}
				
				}
}
function NoChange()
{
    alert('Please open calendar to change dates.')
    window.document.form1.wrkdayscript.focus();
}

function GetCityState(form)
{


			
			
	    var Stamp = new Date()
    	
	    var Hours
	    var Mins
	    var Seconds
	    var Time
    	
    	
	    Hours = Stamp.getHours();
	    Mins = Stamp.getMinutes();
	    Seconds = Stamp.getSeconds();
	    Time = (Hours*10000) + (Mins*100) + Seconds;

        //var Zipcd = document.getElementsByName("wrkzipcd").value;
        var Zipcd = document.form1.wrkzipcd.value;
        if(Zipcd.length == 5 || Zipcd.length == 6 || Zipcd.length == 7)
	    {	
        
//alert(Zipcd);
				//var src = window.document.document.form1.wrksource.value;
				//alert(src)
				try
				{
					objcity = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						objcity = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(e1)
					{
					        try
					        {
							    objcity = false
						        objcity = new XMLHttpRequest();
						        objcity.overrideMimeType("text/plain");
        						
        						
						            if (!objcity) {
								        alert('Cannot create XMLHTTP instance');
								        return false;
						        }				        
					        }
					        catch(e2)
					        {
						        objcity = null;
						    }
					}
				}
				if(objcity!=null)
				{
					objcity.onreadystatechange = ProcessCityState;
					objcity.open("Get", "AllegWebApplicationsV860/FillCityState.aspx?ZIPCD=" + Zipcd + "&UNIQUE=" + Time,true);
					objcity.send(null);
				}
				return false;    
        }
    }
 function ProcessCityState()
{
				
		var str;

				if(objcity.readyState == 4)
				{

					if(objcity.status == 200)
					{ 
						str = objcity.responseText;
						if(str != "NO" && str != "")
						{
						    str = str.split("$$");
						    document.getElementById("Text4").value = str[0];
						    document.getElementById("Text5").value = str[1];
						}
					}
					else
					{
						alert(objcity.statusText);
					}
				
				}

    }   
    
    function CheckLength(form)
    {
  			var str = new String()
			str = document.form1.wrkzipcd.value
			str = str.toUpperCase()
			char1 = str.charAt(0)
			
			if (char1 >= "0" && char1 <= "9")
			{
			    document.form1.wrkzipcd.setAttribute('maxLength',5);
			}
			else
			{
			    document.form1.wrkzipcd.setAttribute('maxLength',7);
			} 
    }
    
    function getQueryVariable(varible)
    {
	    var query = window.location.search.substring(1);
	    var vars  = query.split("&")
	    for(var i=0;i<vars.length;i++)
	    {
		    var pair = vars[i].split("=")
		    if(pair[0] == varible)
		    {
			    return pair[1];
		    }
	    }		
    } 
    
    function leftTrim(sString) 
    {
        while (sString.substring(0,1) == ' ')
        {
            sString = sString.substring(1, sString.length);
        }
        return sString;
    }    
     function popupissue(url)
    {
        try
        {
            if(trim(document.form1.wrkaddr.value) == "")
            {
                
                if(trim(document.form1.wrkaddr2.value) != "")
                {            
                    document.form1.wrkaddr.value = trim(document.form1.wrkaddr2.value)
                    document.form1.wrkaddr2.value = '';
                }   
            }
        }	catch(e){} //used if address line 2 is not displayed
            IssueWindow = window.open(url,"Issue","location=1,status=1,scrollbars=1,width=500,height=550"); 
            IssueWindow.focus();
    }
     function popuplink(url,name,h,w)
    {


            window.open(url,name,"scrollbars=1,resizable=1,width=" + w + ",height="+h); 
    }    
    
    function popupissuepledge(url)
    {
    
        url = url + "?NAME=" + document.form1.wrkesalu.value;
        url = url + "&EMAIL=" + document.form1.wrkemail.value;
        url = url + "&PHONE=" + FixPhone(document.form1.wrkphone.value);
        
  
             try
            {             
                if(trim(document.form1.wrkaddr.value) == "")
                {
                    

                        if(trim(document.form1.wrkaddr2.value) != "")
                        {            
                            document.form1.wrkaddr.value = trim(document.form1.wrkaddr2.value)
                            document.form1.wrkaddr2.value = '';
                        }  
                }
            	        
            }catch(e){} //used if address line 2 is not displayed
            
        url = url + "&ADDR=" + document.form1.wrkaddr.value;
        url = url + "&CITY=" + document.form1.wrkcity.value;
        url = url + "&STATE=" + document.form1.wrkstate.value;
        url = url + "&ZIP=" + document.form1.wrkzipcd.value;
        
        url = url + "&USER=" + document.form1.wrkuser.value;
        window.open(url,"Issue","location=1,status=1,scrollbars=1,width=500,height=500"); 
    }
    
    function trim(stringToTrim) {
	    return stringToTrim.replace(/^\s+|\s+$/g,"");
    }  
    function keySearchName(form,e)
    {
        if(document.all)
        {
            if(window.event.keyCode == 13)
             {
                SearchName(form)
                searching = true
             }
        }
        else
        {
        //FireFox
             if(e.keyCode == 13)
            {    SearchName(form)
                searching = true
             }          
        
        }
    } 
    function keySearchComp(form,e)
    {
        if(document.all)
        {    
            if(window.event.keyCode == 13)
            {    SearchCompany(form)
                searching = true
             } 
        }
        else
        {
        //FireFox
             if(e.keyCode == 13)
            {    SearchCompany(form)
                searching = true
             }        
        
        }                        
    }  
    function keySearchAddress(form,e)
    {

        if(document.all)
        {    
            if(window.event.keyCode == 13)
             {   SearchAddress(form)
                searching = true
             }    
        }
        else
        {//FireFox
            if(e.keyCode == 13)
             {   SearchAddress(form)
                searching = true
             } 
        
        }                     
    }  
    function keySearchPhone(form,e)
    {

        if(document.all)
        {    
            if(window.event.keyCode == 13)
             {   SearchPhone(form)
                searching = true
             }      
        }
        else
        {//FireFox
             if(e.keyCode == 13)
             {   SearchPhone(form)
                searching = true
             }          
        
        }                   
    }      
    function JumpZip(form,e)
    {

        if(document.all)
        {    
            if(window.event.keyCode == 9)
             { 
                    document.form1.wrkstate.focus()               
             }      
        }
        else
        {//FireFox
             if(e.keyCode == 9)
             {  
                    document.form1.wrkstate.focus()
             }          
        
        }                       
    
    }         



