function changeCase(frmObj,firstcap)
{
    var index;
    var tmpStr;
    var tmpChar;
    var preString;
    var postString;
    var strlen;
    tmpStr = frmObj.value;
    if (firstcap==2)
    {
        tmpStr=frmObj.value.toLowerCase();
    }else
    if (firstcap==3)
    {
        tmpStr=frmObj.value.toUpperCase();
    }else
    {
        strLen = tmpStr.length;
        if (strLen > 0)  {
        for (index = 0; index < strLen; index++)  {
        if (index == 0)  {
        tmpChar = tmpStr.substring(0,1).toUpperCase();
        postString = tmpStr.substring(1,strLen);
        tmpStr = tmpChar + postString;
        }
        else {
        tmpChar = tmpStr.substring(index, index+1);
        if (tmpChar == " " && index < (strLen-1))  {
        tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
        preString = tmpStr.substring(0, index+1);
        postString = tmpStr.substring(index+2,strLen);
        tmpStr = preString + tmpChar + postString;
                 }
              }
           }
        }
    }
    frmObj.value = tmpStr;
}
function LogonAlert()
{
    var result;
    var debtor_exact_name=stripTrailingSlashes(document.getElementById('debtor_exact_name').value);
    var debtor_first_name=stripTrailingSlashes(document.getElementById('debtor_first_name').value);
    if (debtor_exact_name=='' && debtor_first_name=='')
    {
        return true;
    }
    result=confirm("If you have already filled in the form, then please click the 'cancel' button to remain on this page and then click the 'PROCEED' button to save the data, then log in at next page. Click the 'OK' button to log in now.");
    //alert("Result:"+result);
    return result;
}
function CheckEmail(frmObj)
{
    var result;
    var email=document.getElementById('email').value;
    if (email != "")
    {
        window.location = "forgotten.php?email=" + email;
        return false;
    }
    else
    {
        alert("Please enter your email address then click here.");
        return false;
    }    
    return true;
}
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
function SendTo_Template(object) {
     //document.forms[0].action = object.options[object.selectedIndex].value;
     document.load.submit();
}
function SendTo_load() {
     //document.forms[0].action = object.options[object.selectedIndex].value;    
     document.load.submit();
}
function SendTo_change_service() {
     //document.forms[0].action = object.options[object.selectedIndex].value;    
     document.change_service.submit();
}
function HideRows()
{
    if (debt_status==null)
    {
    debt_state_row.style.display='none';
    }
    else
    {
    debt_state_row.style.display='inline';
    }
    if (document.getElementById('debtor_type')!=null)
    {
        if (document.getElementById('debtor_type').value!="ind")
        {
            stripTrailingSlash(document.getElementById('debtor_exact_name'));
            document.getElementById('debtor_exact_name_row').style.display='inline';
            document.getElementById('debtor_title_row').style.display='none';
            document.getElementById('debtor_first_name_row').style.display='none';
            document.getElementById('debtor_surname_row').style.display='none';
            debtor_exact_name_label.innerHTML="Exact name of the company that owes you the money: (As it appeared on invoice)";
            document.getElementById('debtor_first_name').value+="/";
            document.getElementById('debtor_surname').value+="/";
            if (document.getElementById('debtor_contact_in_company')!=null)
            {
                document.getElementById('debtor_contact_in_company_row').style.display='inline';
                document.getElementById('debtor_position_in_company_row').style.display='inline';            
            }
        } else 
        {
            stripTrailingSlash(document.getElementById('debtor_first_name'));
            stripTrailingSlash(document.getElementById('debtor_surname'));
            document.getElementById('debtor_exact_name').value+="/";
            document.getElementById('debtor_exact_name_row').style.display='none';
            document.getElementById('debtor_title_row').style.display='inline';
            document.getElementById('debtor_first_name_row').style.display='inline';
            document.getElementById('debtor_surname_row').style.display='inline';
            debtor_exact_name_label.innerHTML="Exact name of the individual that owes you the money: (As it appeared on invoice)";
            if (document.getElementById('debtor_contact_in_company')!=null)
            {
                document.getElementById('debtor_contact_in_company_row').style.display='none';
                document.getElementById('debtor_position_in_company_row').style.display='none';            
            }
        }
    }
    return true;
}
function checkAccept()
{
    if (document.getElementById('accept_tcs')!=null)
    {
        if (document.getElementById('accept_tcs').checked!=true)
        { alert ("Please accept the conditions.");
        return false;
        }
    }
    return true;
}
function PaypalAlert()
{
    alert ("After making payment, please allow PayPal to return you to Collect-Debts, in order to complete your transaction, and receive your receipt.");
    return false;
}
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
/*alert("Key="+keycode);*/
if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function Left(str, n){
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function CheckDebtorForm(frmObj)
{
    try
    {
        if (!(parseFloat(document.getElementById('debt_amount').value)>50))
        {
            alert('Debt Amount must be greater than £50');
            return false;
        }
        if (document.getElementById('debt_year_incurred').value=='pre-2')
        {
            alert('Please select the year in which the debt was incurred.');
            return false;
        }
        if (document.getElementById('debt_year_incurred').value=='Select')
        {
            alert('Please select the year in which the debt was incurred.');
            return false;
        }
        if (document.getElementById('debt_how_incurred').value=='Select')
        {
            alert('Please select how the debt was incurred.');
            return false;
        }
    }
    catch (error)
    {
        return true;
    }
    return true;
}
function changeCase(frmObj,firstcap)
{
    var index;
    var tmpStr;
    var tmpChar;
    var preString;
    var postString;
    var strlen;
    tmpStr = frmObj.value;
    if (firstcap==2)
    {
        tmpStr=frmObj.value.toLowerCase();
    }else
    if (firstcap==3)
    {
        tmpStr=frmObj.value.toUpperCase();
    }else
    {
        strLen = tmpStr.length;
        if (strLen > 0)  {
        for (index = 0; index < strLen; index++)  {
        if (index == 0)  {
        tmpChar = tmpStr.substring(0,1).toUpperCase();
        postString = tmpStr.substring(1,strLen);
        tmpStr = tmpChar + postString;
        }
        else {
        tmpChar = tmpStr.substring(index, index+1);
        if (tmpChar == " " && index < (strLen-1))  {
        tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
        preString = tmpStr.substring(0, index+1);
        postString = tmpStr.substring(index+2,strLen);
        tmpStr = preString + tmpChar + postString;
                 }
              }
           }
        }
    }
    frmObj.value = tmpStr;
}
function changeCaseWorking(frmObj)
{
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value;
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}

function stripTrailingSlash(frmObj)
{
    while (Right(frmObj.value,1)=='/')
    {
        frmObj.value=Left(frmObj.value,frmObj.value.length-1);
    }
}
function stripTrailingSlashes(str)
{
    while (Right(str,1)=='/')
    {
        str=Left(str,str.length-1);
    }
    return str;
}
