
function addElement(){
  var ni = document.getElementById('mySpan');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newspan = document.createElement('span');
  var spanIdName = 'my'+num+'Span';
  newspan.setAttribute('id',spanIdName);
  newspan.innerHTML = '<input name=begin[] type=text size=4 maxlength=4/> to <input name=end[] type=text size=4 maxlength=4/> <a href=# onclick=removeElement("'+spanIdName+'");>Remove</a><br/>';
  ni.appendChild(newspan);
}

function removeElement(spanNum) {
  var d = document.getElementById('mySpan');
  var oldspan = document.getElementById(spanNum);
  d.removeChild(oldspan);
}


function resetyear(){
  $('years').innerHTML = '';
  $('queryform').method = 'get';
}

function OnCalculate(){
    document.queryform.action = "growth_resultf.php";
 //   document.Form1.target = "_blank";    // Open in a new window
    document.queryform.submit();             // Submit the page
    return true;
}

function OnPlotSeries(){
    document.queryform.action = "growth_plots.php";
 //   document.Form1.target = "_blank";    // Open in a new window
    document.queryform.submit();             // Submit the page
    return true;
}


function toggle(table){
    var boxen = document.getElementsByClassName('cbox-'+table);
    if(boxen[2].checked == false){
      for(x = 0; x < boxen.length; x++){
          boxen[x].checked = true;
     }
     }
     else{
         for(x = 0; x < boxen.length; x++){
          boxen[x].checked = false;
     }
     }
}

function untoggle(table){
    var boxen = document.getElementsByClassName('cbox-'+table);
      for(x = 0; x < boxen.length; x++){
          boxen[x].checked = false;
     }
}

/* *****************************************************************************
PROJECT             HOW MUCH IT WORTH, GROWTH CALCULATOR 
DATE                SUMMER 2006
CODE BY             YULIYA YUROVA, UIC

FILE DESCRIPTION    This file contains JS functions for cal_usgrowth.php test page 
*****************************************************************************  */

/*function to disable submit button once it clicked once (to prevent clicking several times) */

/*function submitonce()
{
         if( document.all || document.getElementById)
         {
                 for(i=0; i< queryform.length; i++)
                 {
                      var tempobj= document.queryform.elements[i]
                      if (tempobj.type.toLowerCase()=="submit" || tempobj.type.toLowerCase()=="clear")
                      {
                           tempobj.disabled= true
                      }
                 }
            
         }
}

/***  VALIDATES THE ENTRIES FOR THE CALCULATOR */
  re= /^(\d{4})$/
		 function validForm()
         {
                 if (document.queryform.begin.value == "")
                 {    if (document.queryform.end.value == "")
                      {      alert("Enter starting and ending years of growth period you want to calculate")
                             document.queryform.begin.focus()
                             return false
                       }
                       alert("Enter starting year!")
                       document.queryform.begin.focus()
                       return false
                  }
                  if (document.queryform.end.value == "")
                 {    alert("Enter ending year!")
                      document.queryform.end.focus()
                      return false
                  }   
				   
				  validbyear= re.exec(queryform.begin.value)
				  if (!(validbyear))        
                  {  alert(queryform.begin.value + " isn't a valid year!")
				     queryform.begin.focus()
                     return false
                  }    
				   else
				  {  if ((document.queryform.begin.value<"1790")||(document.queryform.begin.value>="2004"))
				       {alert("Starting Year must be between 1790 and 2003!")
					    document.queryform.begin.focus()
                        return false}
				  }
    			  valideyear= re.exec(queryform.end.value)
				  if (!(valideyear))        
                 {   alert(queryform.end.value + " isn't a valid year!")
				     queryform.end.focus()
                     return false
                  }    
				   else
				  {  if ((document.queryform.end.value<="1790")||(document.queryform.end.value>"2004"))
				       {alert("Ending Year must be between 1791 and 2004!")
					    document.queryform.end.focus()
                        return false}
				  }
				  
				  if (document.queryform.begin.value >= document.queryform.end.value)
				  {     alert("Starting Year must preceed Ending Year!")
					    document.queryform.begin.focus()
                        return false
				  }
				  
				   
			   if (document.queryform.method.value == -1 )        
                 {   alert("Select method!")
				     document.queryform.method.focus()
                     return false
                  } 
				//  submitonce(queryform)   
                  return true                     
          }	  

function calc_growthForm() {
/* composes code to show a calculator form*/

   // define table
   document.write("   <table class=statement WIDTH=100% CELLPADDING=0 CELLSPACING=0>");
   document.write("      <tr>");
   document.write("         <td width=50>&nbsp;</td><td width=20%></td>");
   document.write("			<td width=20%></td><td width=20%></td><td width=20%></td>");
   document.write("         <td width=50>&nbsp;&nbsp;</td>");
   document.write("      </tr>");
  
   // form tag
  document.write("   <form NAME='queryform' action='calc_usgrowth.php' method=post>");
 
  // form body
   document.write("      <tr><td width=50>&nbsp;</td>");
   document.write("         <td class=th align=right>Period Begins From</br>Starting Year</td>");
   document.write("         <td class=th align=right>Period Ends At</br>Year</td>");
   document.write("         <td class=th align=right>Using Method</td>");
   document.write("         <td ></td><td width=50>&nbsp;</td>");
   document.write("      </tr>");
   
   document.write("      <tr><td width=50>&nbsp;</td>");
   document.write("         <td class=th><input type=text name='bYear' size=20 style='background: palegreen;'></td>");
   document.write("         <td class=th><input type=text name='eYear' size=20 style='background: palegreen;'></td>");
   document.write("         <td class=th><select name='method'><option selected value=-1 style='background: palegreen;'>select</option>");
   document.write("               <option value=1>real US GDP</option>");
   document.write("               <option value=2>nominal US GDP</option>");
   document.write("             </select></td>");
   document.write("         <td ></td><td width=50>&nbsp;</td>");
   document.write("      </tr>");
   
   document.write("      <tr>");
   document.write("         <td colspan=6 height=20></td>");
   document.write("      </tr>");
   	
   document.write("      <tr><td width=50>&nbsp;</td>");
   document.write("         <td colspan=2 ><A onclick='return validForm();' href='javascript:void(1);'><IMG height=31 alt=Calculate src='images/calculate.jpg' width=164 align=absMiddle border=0></A> <input type=submit value='calculate growth rate' name='submit' onClick=' return validForm(); '></td>");
   document.write("         <td colspan=2 ><input type=reset value=' CLEAR '></td>");
   document.write("         <td></td>");
   document.write("      </tr>");
   document.write("      <tr><td colspan=6 height=20></td></tr>");
   document.write("      </form>");
   document.write("      </table>");

   }    // end function calc_growthForm()*/