var ct = "powerattny"; // contract type
// onkeypress="autoCheckBox(this,'formname','thecheckboxname')"

/*var usa = "/contracts/powerattny/?loc=US&ad=from_drop_down";
var canada = "/contracts/powerattny/?loc=CA&ad=from_drop_down";
var uk = "/contracts/powerattny/?loc=GB&ad=from_drop_down";*/

var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;

var didPostBack = false;

function signCountyOrParish()
{
   jurisdictionCode = (getFormObject("powerattny", "signGovState")?getFormObject("powerattny", "signGovState").value:'');
   if (jurisdictionCode =="Louisiana" && getObject('countyOrParish'))
   {
      getObject('countyOrParish').innerHTML = "<b>Parish&nbsp;Requirements&nbsp;for&nbsp;Recording&nbsp;Document</b>";
   }
   else if(jurisdictionCode =="Alaska" && getObject('countyOrParish'))
   {
      getObject('countyOrParish').innerHTML = "<b>Judicial&nbsp;District&nbsp;Requirements&nbsp;for&nbsp;Recording&nbsp;Document</b>";
   }
   else if(getObject('countyOrParish'))
   {
      getObject('countyOrParish').innerHTML = "<b>County&nbsp;Requirements&nbsp;for&nbsp;Recording&nbsp;Document</b>";
   }
}

function displayHintDiv(governingLaw) {
   setVisDisp('hintDiv1', getFormObject(ct,"hintDisplay").checked && governingLaw != "Louisiana");
   setVisDisp('hintDiv2', getFormObject(ct,"hintDisplay").checked && governingLaw == "Louisiana");
}

function displayAssistanceDiv()
{
   setVisDisp('assistanceDiv', getFormObject(ct,'assistanceDisplay').checked);
}


/*function chkUKPOASelection()
{
   var govCountry = getFormObject(ct,"governLaw").value;

   setVisDisp("UKPOASelDiv", govCountry == "uk");
}*/

function postBack(url, fromDisplay)
{
   
   if (!didPostBack && ((fromDisplay == 'nation') || (fromDisplay == 'ukSelDiv') || (fromDisplay == 'country' && getFormObject(ct,"governLaw").value == 'uk') || (fromDisplay == 'country' && getFormObject(ct,"governLaw").value == 'canada') || (fromDisplay == 'country' && getFormObject(ct,"governLaw").value == 'usa') || (fromDisplay == 'country' && getFormObject(ct,"governLaw").value == 'australia')))
   {
      didPostBack = true;
      var f=document.createElement("FORM");
      var vs=document.createElement("INPUT");
      var sid=document.createElement("INPUT");
      var un=document.createElement("INPUT");
      f.style.display="none";
      f.appendChild(vs);
      f.appendChild(sid);
      f.appendChild(un);
      vs.name="variablestring";
      vs.value=createVarString();
      sid.name="SID";
      sid.value=SID;
      un.name="UN";
      un.value=GetCookie("UID");
      f.action=url;
      f.method="POST";
      getObject("content").appendChild(f);
      saveReq=false;
      f.submit();
   }
}


function onlyNumeric(event)
{
   if(isIE)
      iKeyCode = event.keyCode;

   else
      iKeyCode = event.which;

   if( (iKeyCode >= 32 && iKeyCode <= 43) || (iKeyCode == 45 || iKeyCode == 47) || iKeyCode >= 58)
         return false;

   return true;
}

function getGovernLaw(sitePrefix)
{
   var govCountry = getFormObject(ct,"governLaw").value;
   var url;

   if (govCountry == "canada")
   {
      url = "http://"+sitePrefix+".lawdepot.com/contracts/powerattny/?loc=CA&ad=from_drop_down";
   }
   else if (govCountry == "usa")
   {
      url = "http://"+sitePrefix+".lawdepot.com/contracts/powerattny/?loc=US&ad=from_drop_down";
   }
   else if (govCountry == "australia")
   {
      url = "http://"+sitePrefix+".lawdepot.com/contracts/powerattny/?loc=AU&ad=from_drop_down";
   }
   else
   {
      url = "http://"+sitePrefix+".lawdepot.co.uk/contracts/powerattny/?loc=GB&ad=from_drop_down";
   }

   postBack(url,'nation');
}

function chkGoverningLaw()
{
   var country = getFormObject('hiddenform',"country").value;
   var govCountry = getFormObject(ct,"governLaw").value;
   var witness;
   var governingLaw;

   setVisDisp("usaDiv1", govCountry == "usa");
   setVisDisp("canadaDiv1", govCountry == "canada");
   setVisDisp("ukDiv1", govCountry == "uk");
   setVisDisp("australiaDiv1", govCountry == "australia");
   setVisDisp("usaDiv2", govCountry == "usa");
   setVisDisp("canadaDiv2", govCountry == "canada");
   setVisDisp("ukDiv2", govCountry == "uk");
   setVisDisp("australiaDiv2", govCountry == "australia");
   setVisDisp("UKTypeOfPOA", govCountry == "uk");
   setVisDisp("UKPOASelDiv", govCountry == "uk" && getFormObject(ct,'governingCountry').value != 'Scotland');
   setVisDisp("ScotlandSelDiv", govCountry == "uk" && getFormObject(ct,'governingCountry').value == 'Scotland');


   if (govCountry == "uk")
         UKDisplay();

   else if (govCountry == 'australia')
   {
      governingLaw = getFormObject("powerattny","governingTerritory").value;
      AustraliaDisplay();
   }
   else
      governingLaw = northAmericaDisplay();

   return governingLaw;
}


// function to display div based on answers selected
function divdisplay()
{
   var witness;
   var govCountry=getFormObject(ct,"governLaw").value;
   var country = getFormObject('hiddenform',"country").value;
   var governingLaw;


   chkGoverningLaw();

   displayOtherPowers();
   if (country == "Canada")
   {
      governingLaw = getFormObject("powerattny","governingProv").value;
      setVisDisp("powersErrMge", false);
   }

   else if (country == "USA")
   {
      governingLaw = getFormObject("powerattny","governingState").value;
   }

   else if (country == "Australia")
   {
      governingLaw = getFormObject("powerattny","governingTerritory").value;
   }

   else
   {
      governingLaw = getFormObject("powerattny","governingCountry").value;
   }

   setVisDisp("detailDiv1", governingLaw != "Louisiana");
   setVisDisp("detailDiv2". governingLaw == "Louisiana");

   displayHintDiv(governingLaw);
   if (country == 'USA')
      displayAssistanceDiv();

   setVisDisp("governLawHint1", country == "USA" || country == "Canada");
   setVisDisp("governLawHint2", country == "UK" && getFormObject(ct,'governingCountry').value != 'Scotland');
   setVisDisp('governLawHint3', country == 'Australia')
   
   setVisDisp("viewResultDiv", country == "Australia" || country == 'UK' || country == "USA" || (country == "Canada" && governingLaw != 'Quebec'));
   signCountyOrParish()
}  // end of divdisplay function


function chkBox(formName,inputName,checkbox)
{
   if (getFormObject(formName,inputName).value == "")
      getFormObject(formName, checkbox).checked = false;

}

function autoCheckBox(formName,inputName,checkbox)
{
   //getFormObject(formName,inputName+"Box").checked = getFormObject(formName,inputName).value == "";

   if (getFormObject(formName,inputName).value != "")
      getFormObject(formName, checkbox).checked = true;

   else
      getFormObject(formName, checkbox).checked = false;  
}



function specifyDate()
{
  if(document.getElementById("agreementDate").value == "specific")
    setVisDisp("dateDisplay",true);

  else
    setVisDisp('dateDisplay',false);

}
