function gototop() {
  window.scrollTo(0,0);
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      alert('Please enter a valid email'); 
      return false;
   } 
   return true;
}

function checklen(exp,val) {
  if((val.length - 0) != (exp - 0)) {
    alert('Please enter ' + exp + ' characters');
    return false;
  }
  return true;
}


var GETDATA = new Array();

// Get the string that follows the "?" in the window's location.
var sGet = window.location.search;
if (sGet) // if has a value...
{
    // Drop the leading "?"
    sGet = sGet.substr(1);
    
    // Generate a string array of the name value pairs.
    // Each array element will have the form "foo=bar"
    var sNVPairs = sGet.split("&");
    
    // Now, for each name-value pair, we need to extract
    // the name and value.
    for (var i = 0; i < sNVPairs.length; i++)
    {
        // So, sNVPairs[i] contains the current element...
        // Split it at the equals sign.
        var sNV = sNVPairs[i].split("=");
        
        // Assign the pair to the GETDATA array.
        var sName = sNV[0];
        var sValue = sNV[1];
        GETDATA[sName] = sValue;
    }
}


function decode2(str) {
  
  return decodeURIComponent(str.replace(/\+/g,  " "));
}


function redirectForm() {
var repage;
if(document.getElementById('Loan_Amount').value != '' && document.getElementById('Loan_Type').value != '') { 
   if($('#Loan_Type').val() == 'Commercial Mortgage') {
     repage = 'commercial-mortgage-loan';
   } else {
     repage = 'business-loan-request';
   }
   window.location= 'http://www.smallbusinessloans.com/' + repage + '/?p=2&type=' + $('#Loan_Type').val()+ '&amt=' + encodeURIComponent($('#Loan_Amount').val());
} else { 
  alert('Please fill out both fields');
}
return false;
}



function getElementsByClass( searchClass, domNode, tagName) { 
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = " "+searchClass+" ";
  for(i=0,j=0; i<tags.length; i++) { 
    var test = " " + tags[i].className + " ";
    if (test.indexOf(tcl) != -1) 
      el[j++] = tags[i];
  } 
  return el;
} 

function nextPage(page,tpages) {
   for(var i = 1; i <= tpages; i++) {
     document.getElementById('page'+i).style.display='none';
   }
   document.getElementById(page).style.display = '';
}

function checkRequired(curpage) {
   var abc = document.getElementById(curpage);
   var felem = getElementsByClass("notempty",abc);
   var count = 0;
   for(var i = 1; i < felem.length; i++) {
     if(felem[i].value == '') count++;
   }
   if(count > 0) {
     alert('Please fill out all the required fields marked with a *');
     return false;
   } else {
     return true;
   }
}






/*
* Really easy field validation with Prototype
* http://tetlaw.id.au/view/javascript/really-easy-field-validation
* Andrew Tetlaw
* Version 1.5.4.3 (2007-11-06)
*
* Copyright (c) 2007 Andrew Tetlaw
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 
*/

