///////////////////////////////////////////////////////////////////////////////
// Script:  field_handler.js
// Cteated: October 11, 2007
// Purpose: handles drop downs and info for text area
// Programmer: Konstantin Glazov
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// fills date values for drop down box
function fillDateValues(id) {

	var bDay = document.getElementById( id + 'bDay');
	var bMonth = document.getElementById( id + 'bMonth');
	var bYear = document.getElementById( id + 'bYear');
    
    // extract labels from hidden field 
    var lday = document.getElementById("lday").value;
    var lmonth = document.getElementById("lmonth").value;
    var lyear = document.getElementById("lyear").value;
    
	bDay.options[0] = new Option(lday,'');
	bMonth.options[0] = new Option(lmonth,'');
	bYear.options[0] = new Option(lyear,'');

	for ( i=1; i<=31; i++ )	{
		val = i.toString();
		if (val.length < 2) val = "0" + val;
		
		o1 = new Option(val,val);
		bDay.options[i]=o1;
	}

	for ( i=1; i<=12; i++ )	{
		val = i.toString();
		if (val.length < 2) val = "0" + val;
		
		o1 = new Option(val,val);
		bMonth.options[i]=o1;
	}
    var currentTime = new Date(); 
	var year = currentTime.getFullYear(); 
	for ( i=1925; i <= year; i++ ) {
		o1 = new Option(i,i);
		bYear.options[i-1924]=o1;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Checks number of characters in text area as user type it
// when given limit is reached overlimit character will be destarded
function limitText(limitField, limitNum) {
	if ((limitNum - document.getElementById(limitField).value.length) >= 0) {
		document.getElementById('chrLeft').innerHTML = limitNum - document.getElementById(limitField).value.length;
	} else {
		document.getElementById('chrLeft').innerHTML = 0;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Is country Canada or USA? Show its state or province name representatively
function showSP(ref) {

	var country = document.getElementById(ref+'country');
	var s_index	= document.getElementById(ref+'country').selectedIndex;

    var countryVal = country.options[country.options.selectedIndex].value;
    var stateBlock = document.getElementById(ref+'stateBlock');
    var usaDD = document.getElementById(ref+'spUsa');

    var cndDD = document.getElementById(ref+'spCanada');
    var spcMsg = document.getElementById(ref+'spcMsg');

  /*  if ((countryVal == "United+States") || (countryVal == "Canada"))  {
	   stateBlock.style.display = "inline";
       if (countryVal == "United+States")  {
           usaDD.style.display = "inline";
           usaDD.disabled = false;
           spcMsg.innerHTML = "State";
      
	       if (cndDD.style.display == "inline")  {
	         cndDD.disabled = true;
	         cndDD.style.display = "none";
	       }      
       }
       else if (countryVal == "Canada")  {
	       cndDD.style.display = "inline";
	       cndDD.disabled = false;
	       spcMsg.innerHTML = "Province";
	      
	       if (usaDD.style.display == "inline")  {
	         usaDD.disabled = true;
	         usaDD.style.display = "none";
	       }      
       }
    } */
	  if ((s_index == "1") || (s_index == "2"))  {
	   stateBlock.style.display = "inline";
       if (s_index == "2")  {
           usaDD.style.display = "inline";
           usaDD.disabled = false;
           spcMsg.innerHTML = "State";
      
	       if (cndDD.style.display == "inline")  {
	         cndDD.disabled = true;
	         cndDD.style.display = "none";
	       }      
       }
       else if (s_index == "1")  {
	       cndDD.style.display = "inline";
	       cndDD.disabled = false;
	       spcMsg.innerHTML = "Province";
	      
	       if (usaDD.style.display == "inline")  {
	         usaDD.disabled = true;
	         usaDD.style.display = "none";
	       }      
       }
    }
	else {
	   if (usaDD.style.display == "inline")  {
	      usaDD.disabled = true;
	      usaDD.style.display = "none";
	   }
	   else if (cndDD.style.display == "inline")  {
	      cndDD.disabled = true;
	      cndDD.style.display = "none";
	   }
	   stateBlock.style.display = "none";
    }
}

///////////////////////////////////////////////////////////////////////////////
// show relative link and taggle HTML block by open/close  
function showRelativeLink(thisObj) {
	if (thisObj) {
		var parent = thisObj.parentNode.parentNode;
		if (parent.tagName == "DL") {
			parent.style.display = "none";
			document.getElementById("title").innerHTML = document.getElementById("title").innerHTML
			parent.className = (parent.className == "faq closed" ? "faq open" : "faq closed");
			parent.style.display = "block";
		}
	}
	
}
