//Start Valerie Rimmer Javascript

function get_URL()
{
	var URL_line=document.URL
	alert(URL_line)
}

//End Valerie Rimmer Javascript


//These functions are for navigation or data checking

function go_home(textobj)
{
window.location="textobj.value"
}

function new_user()
{
window.location="Register_Yourself.cfm"
}

function setvaluenext(textobj)
{
	textobj.value="next"
}

function setvalueprevious(textobj)
{
	textobj.value="previous"
}

function setvalueview(textobj)
{
	textobj.value="view"
	//alert(textobj.value)
}


function changeword()
{//alert ("You just clicked that button")
    var newword="Buying"
	document.forms[1].Buying.value=newword;
 //	alert(document.forms[1].Buying.value)
}

function survey()
{
if (document.forms[1].Buying.value!="Buying")
	//{
	//alert("You are an asswipe")
	//alert(document.forms[1].Buying.value)
	//}
//else
	{var popurl="Quick_Survey.cfm"
	 winpops=window.open(popurl,"","width=400,height=338,left=200, top=200")
	}
}

function windopen(url, name, xwidth, yheight) 
{

var dim="width="+xwidth+", height="+yheight+",menubar=no,toolbar=no,scrollbars=yes,statusbar=yes, resizable=yes,location=yes, left=20, top=20"
popupWin = window.open(url, name, dim);
popupWin.focus();
}

function windopenfull(url, name, xwidth, yheight) 
{

var dim="width="+xwidth+", height="+yheight+",menubar=yes,toolbar=yes,scrollbars=yes,statusbar=yes, resizable=yes,location=yes, left=20, top=20"
popupWin = window.open(url, name, dim);
popupWin.focus();
}

function vistaopen(url, name, xwidth, yheight) 
{

var dim="width="+xwidth+", height="+yheight+",menubar=no, toolbar=no,scrollbars=no,resizable=no,location=no, left=10, top=10"
popupWin = window.open(url, name, dim);
popupWin.focus();
}

function checkval()
{
	return 1
}	


function msieversion()
   {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0
   }

//This function checks to see whether the browser is Explorer 
function check_browser() 
{

if (msieversion() > 4.9) 
 	return 1
else (msieversion() < 4.9) 
	return 2

}//end function bracket


function check_search_browser(textobj) {

if (document.all) 
	{textobj.value="Microsoft"}
	
else if (document.layers) 
{
   if (navigator.appVersion.substring(0,4) > 4.5)
		{textobj.value="Net46"}
	else
		{textobj.value="Net45"}
}
else 
		{textobj.value="Net45"}

return textobj
}//end function bracket


function test_email(inobj) {
var Ctrl = inobj.value.toString();

if (Ctrl.indexOf('@',0)==-1)
	{
	alert("Your e-mail address is invalid.  Please try again.")
	inobj.select();
	return(false);
	}
return true;
}

function test_spanishemail(inobj) {
var Ctrl = inobj.value.toString();

if (Ctrl.indexOf('@',0)==-1)
	{
	alert("Colocar el correo electronico en el siguiente formato xxxxx@xxxxx.xxx")
	inobj.select();
	return(false);
	}
return true;
}
function check_data()
{
if (Form.State=="AA")
	{alert("Please select a state from the listbox marked State.");
	 return false;
	}
}

function Previous_Page()
{
window.history.back()
}

//function getfile(textobj,total_name)
//{
//	var newstr="_"
//	var quote=" "
//	totalobj=eval("document" + total_name);
	
//	var oldstr=textobj.value.toString();
//	alert(oldstr);
//	while (oldstr.search(quote) != -1) 
//		{
//		oldstr=oldstr.replace(quote,newstr);		
//		}
//	bogus=oldstr;
//	textobj.value=bogus;
//	totalobj.value=bogus;

//	alert(bogus)
//	alert(textobj.value);
//	alert(totalobj.value);
//	return(textobj);
//}


function getfile(textobj,total_name)
{
totalobj=eval("document" + total_name);

bogus=textobj.value;
totalobj.value=bogus;
//	alert(bogus)
//	alert(totalobj.value);
}


//These functions are used in the worksheets.

function selectobj(textobj)
//This function selects the first text field on the page so a user does not have to tab to it
{
textobj.select()
}

function notouch(textobj, total_name)
//This function prevents users from changing data in total fields.  It is old and should not be used.
{
alert ("Oops, please do not change this total field.");
textobj.value=oldnum;
oldfield=eval("document."+total_name+lastfield);
//alert(oldfield.name);
oldfield.select();
}

function init_oldnum(textobj,total_name)
//This function sets variable oldnum to the existing value in the field
{
if (validnum=="false")
	{
	validnum="true";
	oldfield=eval("document."+total_name+lastfield);
//	alert (oldfield);
	oldfield.value=oldnum;
	oldfield.select();

	}
else
	{
//	alert("Validnum is true");
	oldnum=parseFloat(textobj.value);
	textobj.select();
	}
}

function get_total(textobj,total_name)
//This function keeps running total of any total field.  Inputs are the current text field and the text version of the document.formname.totalfieldname reference

{
totalobj=eval("document" + total_name);
//alert(totalobj);
totalnum=parseInt(totalobj.value);
//alert(totalnum);
newnum=parseInt(textobj.value);
//alert(newnum);
if (isNaN(newnum))
	{
	alert ("Please input a valid number not less than 1.")
	validnum="false";
//	alert(lastfield)
    newnum=0;
	textobj.value=newnum;
	}

	totalnum=totalnum+newnum-oldnum;
	totalobj.value=totalnum;

	lastfield=textobj.name;

	if (filename=="Cash_Flow_Statement")
	{net_cash_flow_calc(document.Cash_Flow)}
	if (filename=="Net_Worth")
	{net_worth_calc(document.Net_Worth)}
	if (filename=="Property_Basis")
	{net_property_basis_calc(document.Property_Basis)}
	if (filename=="Net_Proceeds")
	{net_proceeds_calc(document.Net_Proceeds)}
	if (filename=="App1003")
	{total_income_calc(document.App1003)}
	
//	alert(totalobj.value);

}

function get_foot(textobj,total_name1,total_name2)
//This function keeps running column and row total of any total field.  Inputs are the current text field and the text version of the document.formname.totalfieldname reference

{
//alert(total_name1);
//alert(total_name2);
totalobj1=eval("document" + total_name1);
totalobj2=eval("document" + total_name2);
//alert(totalobj1);
//alert(totalobj2);

totalnum1=parseInt(totalobj1.value);
totalnum2=parseInt(totalobj2.value);
//alert(totalnum1);
//alert(totalnum2);

newnum=parseInt(textobj.value);
//alert(newnum);

if (isNaN(newnum))
	{
	alert ("Please input a valid number not less than 1.")
	validnum="false";
//	alert(lastfield)
    newnum=0;
	textobj.value=newnum;
	}

	totalnum1=totalnum1+newnum-oldnum;
	totalobj1.value=totalnum1;
	
	totalnum2=totalnum2+newnum-oldnum;
	totalobj2.value=totalnum2;
	
	lastfield=textobj.name;
	total_income_calc(document.App1003);

//	alert(totalobj.value);

}

function get_minus_foot(textobj,total_name1,total_name2)
//This function keeps running column and row total of any total field.  Inputs are the current text field and the text version of the document.formname.totalfieldname reference

{
//alert(total_name1);
//alert(total_name2);
totalobj1=eval("document" + total_name1);
totalobj2=eval("document" + total_name2);
//alert(totalobj1);
//alert(totalobj2);

totalnum1=parseInt(totalobj1.value);
totalnum2=parseInt(totalobj2.value);
//alert(totalnum1);
//alert(totalnum2);

newnum=parseInt(textobj.value);
//alert(newnum);

if (isNaN(newnum))
	{
	alert ("Please input a valid number not less than 1.")
	validnum="false";
//	alert(lastfield)
    newnum=0;
	textobj.value=newnum;
	}

	totalnum1=totalnum1-newnum+oldnum;
	totalobj1.value=totalnum1;
	
	totalnum2=totalnum2+newnum-oldnum;
	totalobj2.value=totalnum2;
	
	lastfield=textobj.name;
	total_income_calc(document.App1003);

//	alert(totalobj.value);

}

//The following function calculates totals on the 1003 Application Form

function total_income_calc(formobj)
{

//calculate total market value of real estate owned	
	totalvalue=parseInt(formobj.Total_Value.value);
	formobj.Real_Estate_Amount.value=totalvalue;

//calculate net rental income from real estate owned	
	netrentinc=parseInt(formobj.Total1_NRI.value)+parseInt(formobj.Total2_NRI.value)+
	parseInt(formobj.Total3_NRI.value)+parseInt(formobj.Total4_NRI.value);
	formobj.Total_NetRent.value=netrentinc;
	formobj.Total_NRI.value=netrentinc;

	basis=parseInt(formobj.Total_Base.value)+parseInt(formobj.Total_Overtime.value)+
	parseInt(formobj.Total_Bonus.value)+parseInt(formobj.Total_Commission.value)+
	parseInt(formobj.Total_DivInt.value)+parseInt(formobj.Total_NetRent.value)+
	parseInt(formobj.Total_Other1.value)+parseInt(formobj.Total_Other2.value)+
	parseInt(formobj.Total_Other3.value);
	formobj.Grand_Total.value=basis;
}

//The following function calculates totals on the Property Basis Worksheet

function net_proceeds_calc(formobj)
{
	basis=parseInt(formobj.Purchase_Price.value)+parseInt(formobj.Purchase_Fees.value)+
	parseInt(formobj.Total_Improvements.value)+parseInt(formobj.Total_Fixup.value)-
	parseInt(formobj.Total_Subs.value);
	formobj.Total_Basis.value=basis;
}

//The following function calculates totals on the Seller Net Proceeds Worksheet

function net_proceeds_calc(formobj)
{
	price=parseInt(formobj.Sales_Price.value);
	seller=parseInt(formobj.Total_Seller.value);
	buyer=parseInt(formobj.Total_Buyer.value);

	net_cash=price-seller+buyer;

	addback=parseInt(formobj.Payoff_Balance.value)+parseInt(formobj.Seller_Points.value)+
		parseInt(formobj.Property_Taxes.value)+ parseInt(formobj.Assessments.value)-
		parseInt(formobj.B_Property_Taxes.value)- parseInt(formobj.B_Assessments.value);

	formobj.Net_Cash.value=net_cash;
	formobj.Net_Sale_Price.value=net_cash+addback;

}


//The following function calculates totals on the Property Basis Worksheet

function net_property_basis_calc(formobj)
{
	price=parseInt(formobj.Purchase_Price.value);
	fees=parseInt(formobj.Purchase_Fees.value);
	improve=parseInt(formobj.Total_Improvements.value);
	fixup=parseInt(formobj.Total_Fixup.value);
	subs=parseInt(formobj.Total_Subs.value);
	
	basis=price+fees+improve+fixup-subs;

	formobj.Total_Basis.value=basis;


}



//Functions for the Loan Payment Calculator

function round_numbers(number) {

decimal_number=number-Math.round(number);
decimal_number=decimal_number*100;
decimal_number=Math.round(decimal_number);
decimal_number=decimal_number*.01;
//alert (decimal_number);
number=Math.round(number);
number=number+decimal_number;
//alert(number);
return (number);
}

function checkey(e)
{

if (navigator.appName=="Netscape")
	{
		charcode=e.which;
	}
else 
	{
		charcode=e.keyCode;
	}

//alert (charcode);
if (charcode > 31 && (charcode < 48 || charcode > 57) && charcode != 46)
	{
		alert ("Please input a valid number.");
	}

}

//This function removes commas and dollar signs and determines whether or not the user's input is a valid number

function checknum(inObj) {
var inStr = inObj.value.toString()
//alert (inStr);

var pos=0
var findstr=","
pos=inStr.indexOf(findstr)

while (pos != -1)
	{
	preString=inStr.substring(0,pos)
	postString=inStr.substring(pos+1,inStr.length)
	inStr=preString+postString
	pos=inStr.indexOf(findstr)
	}

findstr="$"
pos=inStr.indexOf(findstr)
	
while (pos != -1)
	{
	preString=inStr.substring(0,pos)
	postString=inStr.substring(pos+1,inStr.length)
	inStr=preString+postString
	pos=inStr.indexOf(findstr)
	}	
	
	inObj.value=inStr

if (isNaN(inStr))
	{
	alert("You have not input a valid number in this field.  Please try again.")
	inObj.select();
	return(false);
	}
return true;
}

//This function is the same as checknum but also removes decimal points from numbers that should be integers.
function checkint(inObj) {
var inStr = inObj.value.toString()
//alert (inStr);

var pos=0
var findstr=","
pos=inStr.indexOf(findstr)

while (pos != -1)
	{
	preString=inStr.substring(0,pos)
	postString=inStr.substring(pos+1,inStr.length)
	inStr=preString+postString
	pos=inStr.indexOf(findstr)
	}

findstr="$"
pos=inStr.indexOf(findstr)
	
while (pos != -1)
	{
	preString=inStr.substring(0,pos)
	postString=inStr.substring(pos+1,inStr.length)
	inStr=preString+postString
	pos=inStr.indexOf(findstr)
	}	
	
	inObj.value=inStr

findstr="."
pos=inStr.indexOf(findstr)
	
while (pos != -1)
	{
	preString=inStr.substring(0,pos)
	postString=inStr.substring(pos+1,inStr.length)
	inStr=preString+postString
	pos=inStr.indexOf(findstr)
	}	
	
	inObj.value=inStr	
	
if (isNaN(inStr))
	{
	alert("You have not input a valid number in this field.  Please try again.")
	inObj.select();
	return(false);
	}
return true;
}



function repnum(inObj) {
var inStr = inObj.value.toString()
//alert (inStr);
	
if (isNaN(inStr))
	{
	alert("You have not input a valid number in this field.  Please try again.")
	inObj.select();
	return(false);
	}
return true;
}

//This function removes single quotation marks from text fields so that database inserts can complete
function repquote(inObj) 
{
	var newstr="`"
	var quote="'"
	var oldstr=inObj.value.toString();
	while (oldstr.search(quote) != -1) 
		{
		oldstr=oldstr.replace(quote,newstr);		
		}
	inObj.value=oldstr;
	return(inObj)
}

function get_factor(rate,term,factor)
{

factor=1+rate;
factor = Math.pow(factor,term);
factor=1/factor;
factor=1-factor;
factor=factor/rate;

if (isNaN(factor))
{
     factor=0;
}

return (factor);

}

function get_payment(amount,factor,payment)
{
 payment=amount/factor;
 if (payment > 100000000)
	 {
      payment=0;
	 }
 payment=round_numbers(payment);
 return (payment);
}

function total_pmts(payment, total)
{
payment=payment*12;
payment=round_numbers(payment);
total=payment;

return (total);
}


function calc_payment(formobj)
{
//begin function
var number="True";
var factor1=0;
var factor2=0;
var pmt_before_taxes1=0;
var pmt_before_taxes2=0;
var total_pmts1=0;
var total_pmts2=0;
var total_interest1=0;
var total_interest2=0;
var total_principal1=0;
var total_principal2=0;

var totals=new Array()
  totals[1]=0
  totals[2]=0 

loan_amount1=parseInt(formobj.Loan_Amount.value);
interest_rate1=parseFloat(formobj.Rate.value);
loan_term1=parseInt(formobj.Term.value);
interest_rate1=interest_rate1/1200;
loan_term1=loan_term1*12;

factor1=get_factor(interest_rate1, loan_term1, factor1);	

loan_amount2=parseInt(formobj.Loan_Amount2.value);
interest_rate2=parseFloat(formobj.Rate2.value);
loan_term2=parseInt(formobj.Term2.value);
interest_rate2=interest_rate2/1200;
loan_term2=loan_term2*12;

factor2=get_factor(interest_rate2, loan_term2, factor2);	

if (factor1 > 0)
	{
	 pmt_before_taxes1=get_payment(loan_amount1,factor1,pmt_before_taxes1);
	 total_pmts1=total_pmts(pmt_before_taxes1,total_pmts1);
	 amort_payments(loan_amount1,interest_rate1,pmt_before_taxes1,totals)
	 total_interest1=totals[0]
	 total_principal1=totals[1]
	 total_pmts1=total_pmts(pmt_before_taxes1, total_pmts1);

	}	
if (factor2 > 0)
	{
	 pmt_before_taxes2=get_payment(loan_amount2,factor2,pmt_before_taxes2);
	 total_pmts2=total_pmts(pmt_before_taxes2,total_pmts2);
	 amort_payments(loan_amount2,interest_rate2,pmt_before_taxes2,totals)
	 total_interest2=totals[0]
	 total_principal2=totals[1]
	 total_pmts2=total_pmts(pmt_before_taxes2, total_pmts2);
	}

formobj.Pmt_Before_Taxes.value=pmt_before_taxes1+pmt_before_taxes2;
formobj.Total_Interest.value=total_interest1+total_interest2;
formobj.Total_Principal.value=total_principal1+total_principal2;
formobj.Pmt_Per_Year.value=total_pmts1+total_pmts2
	
} //end function	



function amort_payments (amount, rate, payment, tot_array)
{
//tot_array[0] is interest
//tot_array[1] is principal

total_interest=0
total_principal=0

for (counter=1; counter < 13; ++counter) 
    {
     monthly_interest=amount*rate;
     monthly_principal=payment-monthly_interest;
     total_interest=total_interest+monthly_interest;
     total_principal=total_principal+monthly_principal;
     amount=amount-total_principal;
    }

//formobj.Total_Interest.value=round_numbers(total_interest);
//formobj.Total_Principal.value=round_numbers(total_principal);

tot_array[0]=round_numbers(total_interest);
tot_array[1]=round_numbers(total_principal);

return (tot_array)
}

function calc_total_monthly(formobj)  

{

payment=formobj.Pmt_Before_Taxes.value;
//alert(payment);
purchase_price=formobj.Purchase_Price.value;
//alert(purchase_price);
tax_rate=formobj.Tax_Rate.value;
tax_rate=tax_rate/100;

total_tax=tax_rate*purchase_price;
monthly_tax=round_numbers(total_tax/12);

insurance=formobj.Insurance.value;
monthly_ins=round_numbers(insurance/12);

hoa_fee=parseFloat(formobj.HOA_Fee.value);

payment=round_numbers(payment);

grand_total=round_numbers(payment+monthly_tax+monthly_ins+hoa_fee);

formobj.Property_Tax.value=round_numbers(total_tax);
formobj.Total_Loan_Payment.value=grand_total;

}

//Function for the Net Worth Worksheet

function net_worth_calc(formobj)
{
	assets=formobj.Total_Assets.value;
	liabs=formobj.Total_Liabs.value;
	formobj.Net_Worth.value=assets-liabs;
}

//Function for Cash Flow Worksheet

function net_cash_flow_calc(formobj)
{
	income=formobj.Total_Income.value;
	annual=formobj.Total_Annual_Ex.value;
	monthly=formobj.Total_Monthly_Ex.value;
	
	income_divide=income/12;
	annual_divide=annual/12;
	
	net_cash=income_divide-annual_divide-monthly;
	net_cash=Math.round(net_cash);
	formobj.Net_Cash_Flow.value=net_cash;
	
}

//This function sets a form value if a user checks a dynamically created checkbox (Used on fees page)
function set_checked(chkbox)
{
chkbox.value="1";
}

//This function submits a form without user intervention.
function subform(formobj)
{
formobj.submit()
}


//These functions track values for the CMA report

function totalup(textobj,element_id, add_number, counter)

{

checknum(textobj);
if (isNaN(textobj.value))
	{
	textobj.select();
	}
else
	{
	 var adj_element_number=(22 * parseInt(counter)) + parseInt(element_id) + parseInt(add_number);
	 var price_element_number= 22 * parseInt(counter) + parseInt(element_id) + 22;
	 var total_adj=parseInt(document.Report_CMA.elements[adj_element_number].value) + parseInt(textobj.value);
	 var  total_price=parseInt(document.Report_CMA.elements[price_element_number].value) + parseInt(textobj.value);

document.Report_CMA.elements[adj_element_number].value=total_adj;
document.Report_CMA.elements[price_element_number].value=total_price;
	}	
return
}

//These functions make pop-up menus appear

function showit(which)
{
clear_delayhide()
thecontent=(which==-1)? "" : submenu[which]
if (document.getElementById||document.all)
menuobj.innerHTML=thecontent
else if (document.layers){
menuobj.document.write(thecontent)
menuobj.document.close()
}
}

function showit2(which)
{
clear_delayhide()
thecontent=(which==-1)? "" : submenu[which]
if (document.getElementById||document.all)
menuobj2.innerHTML=thecontent
else if (document.layers){
menuobj2.document.write(thecontent)
menuobj2.document.close()
}
}


function resetit(e){
if (document.all&&!menuobj.contains(e.toElement))
delayhide=setTimeout("showit(-1)",delay_hide)
else if (document.getElementById&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhide=setTimeout("showit(-1)",delay_hide)

if (document.all&&!menuobj2.contains(e.toElement))
delayhide=setTimeout("showit2(-1)",delay_hide)
else if (document.getElementById&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhide=setTimeout("showit2(-1)",delay_hide)
}

function clear_delayhide(){
if (window.delayhide)
clearTimeout(delayhide)
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}



function backscreen(backwards)
{
window.blur();
history.go(backwards);
}


function StartingDrag() {
      StartingImage = event.srcElement;
      return;
 }
 
function DroppingNow() {
   SwitchImages(event.srcElement, StartingImage);

   return;
}
 
function SwitchImages(Obj1, Obj2) {
	var temp = Obj1.src;
	Obj1.src = Obj2.src;
	Obj2.src = temp;
	
	old_id='Picture_' + StartingImage.id;
	new_id='Picture_' + event.srcElement.id;
	
	old_number=document.getElementById(old_id).value
	new_number=document.getElementById(new_id).value	

	document.getElementById(new_id).value=old_number;
	document.getElementById(old_id).value=new_number;	
	
	
	ResizeImg(Obj1);
	ResizeImg(Obj2);
	return;
}
   function ResizeImg(inObj) {
      if (inObj.src.indexOf('_vert') > 0) {
         inObj.height = IMG_WIDTH;
         inObj.width  = IMG_HEIGHT;
      } else {
         inObj.height = IMG_HEIGHT;
         inObj.width  = IMG_WIDTH;
      }
      return;
   }
   function cancelEvent() {
      // SEEMINGLY USELESS EVENT MUST BE CALLED...
      window.event.returnValue = false;
   }
   
   function SaveOrder() {
      alert('Saving the order...');
      var ob1;
      var ob2;
      // BUBBLE LOOP THRU THEM...
      for (var xx = 1; xx < MAX_IMG; xx++) {
         for (yy = xx + 1; yy <= MAX_IMG; yy++) {
            ob1 = document.getElementById('img' + xx);
            ob2 = document.getElementById('img' + yy);
            if ((ImageIsBlank(ob1)) && (!ImageIsBlank(ob2))) {
               SwitchImages(ob1, ob2);
            }
         }
      }
      alert('the images are now collapsed together, with all blank spaces removed.');
      alert('submitting the form...');
      frmMain.submit();
      return;
   }
   function ImageIsBlank(inObj) {
      return (inObj.src.indexOf(BLANK_IMG) > 0);
   }

function DroppingTrash() {
   DeleteImages(StartingImage);

   return;
}

function DeleteImages(Obj1) {

	var temp = Obj1.src;
	old_id='Picture_' + StartingImage.id;
	trash='Trash';

	Obj1.src = 'GIF_Images/photo_deleted.gif';	
	old_number=document.getElementById(old_id).value
	new_number=document.getElementById(trash).value	+ ',' + old_number

//	alert(old_number);
//	alert(new_number);
	document.getElementById(trash).value=new_number;
	document.getElementById(old_id).value=0;	
	return;
}
   
function update_field(formname, formaction) 
{
	if (formaction=='Upload')
		{document.getElementById(formname).value='Upload'}
	if (formaction=='GoHome')
		{document.getElementById(formname).value='GoHome'}	
	return
}

function addview(Obj1, fieldname) {

	var list_id = Obj1.id;
	list_id_length=Obj1.length;
	storage=fieldname;
	storage_var='';
	currlist=document.getElementById(storage).value
	
	if (Obj1.checked)
	{
		if (currlist.indexOf(list_id) == -1)
		
		{if (currlist.length==0)
			{storage_var=currlist + list_id}
		 else
			{storage_var=currlist + ',' + list_id}	
		}		

	}
	else
	{
		if (currlist.indexOf(list_id) != -1)	
		{storage_var=currlist.replace(list_id,'x')}

		first_comma=storage_var.indexOf(',');
			
		if (first_comma == 0)			
			{storage_var=storage_var.substr(1)}
		
	    storage_var=storage_var.replace('x,','')
	    storage_var=storage_var.replace('x','')
		
		last_comma=storage_var.lastIndexOf(',')
		alert(last_comma)
		
		if (last_comma==storage_var.length-1)
			{storage_var=storage_var.substr(0,storage_var.length-1)}

	}
	document.getElementById(storage).value=storage_var;
	return;
}	

//This function detects screen resolution and loads a corresponding style sheet
function sniffer() 
{
     var screen_height = screen.height;
     var screen_width = screen.width;
	 var answer=0;
     if (screen_height <= 768)  
	 {
                   screen_width = 1024;
                   screen_height = 768;
                   document.getElementById("foo").href="style_1.css";
				   alert("Normal");
				   answer="Normal";
     } 
     else
	 {
	screen_width = 1280;
	screen_height = 1024;
                  document.getElementById("foo").href="style_2.css";
				  alert("Tiny");
				  answer="Tiny";
     }
	 
	if (answer=0)
		{
		alert("Houston, we have a problem.");
   		}
  
}
   