function fix_sps(str1,str2) {
    var list1 = new Array();
    var list2 = new Array();
    var nodes = document.getElementsByTagName('*')
    for (i = 0; i<nodes.length; i++)
    {
        if (nodes[i].className.indexOf(str1) >= 0 )
        {
            list1.push(nodes[i]);
        }
        if (nodes[i].className.indexOf(str2) >= 0 )
        {
            list2.push(nodes[i]);
        }

    }

    big1=0;
    big2=0;
    for (var i=0; i<list1.length; i++)
    {
        if (list1[i].clientHeight>big1) big1=list1[i].clientHeight;
    }
    for (var i=0; i<list2.length; i++)
    {
        if (list2[i].clientHeight>big2) big2=list2[i].clientHeight;
    }
    if (big1>big2) bigger=big1; else bigger=big2;
    for (i = 0; i<list1.length; i++) {
        list1[i].style.height=bigger + 'px';
    }
    for (i = 0; i<list2.length; i++) {
        list2[i].style.height=bigger + 'px';
    }
}
function show_bar() {
    ob1=document.getElementById('z_win');
    obj = document.getElementById("win");
    obj.innerHTML = "Please enter 5 digits Zip Code!";
    pos = ob1.getBoundingClientRect();
    PosX = pos.left;
    PosY = pos.top;
    scroll_top=document.documentElement.scrollTop;
    obj.style.top = PosY - obj.offsetHeight + ob1.offsetHeight + scroll_top + 'px';
    obj.style.left = PosX + 'px';
    obj.style.visibility = "visible";
    setTimeout('hide_bar()',15000);
}
function hide_bar() {
    document.getElementById("win").style.visibility="hidden";
}
function allowOnly09(chek_str) {
    var re = new RegExp("^[\\d]{5}$");
    return re.test(chek_str);
}
function cd_states(zip) {
    frm=document.loan_form;
    frm.descr.value=frm.prd_id.options[frm.prd_id.selectedIndex].innerHTML;
    frm.zipcode.value=zip;
    document.getElementById('he_out').style.display='';
    getServiceResponse('',frm.page_no.value,frm.prd_id.value,frm.zipcode.value,'he_out');
    document.getElementById('he_out').focus();
    return false;
}
function loan_states(zip)
{
    frm=document.loan_form;
    frm.zipcode.value=zip;
    document.getElementById('he_out').style.display='';
    getServiceResponse(frm.amount.value,frm.page_no.value,frm.prd_id.value,frm.zipcode.value,'he_out');
    document.getElementById('he_out').focus();
    return false;
}
function changeTab(num) {
    document.getElementById('cont_top').className = 'top_form_CU_'+num;
    document.getElementById('cont_img').src = 'images/applyfast_contact_us_top_'+num+'.gif';
    for (var i=1; i<=4; i++) {
        if (num==i) {
            document.getElementById('head_'+i).className = 'top_cu_part_'+i+'_act';
            document.form_4371.let_subj.value = i;
        } else {
            document.getElementById('head_'+i).className = 'top_cu_part_'+i;
        }
    }
    document.form_4371.ch_num.focus();
    document.form_4371.fname.focus();
}

//===========================================================================
function trim(x)
{
  var ch,c
  ch=x.toString()
  c=ch.charAt(0)
  while (c==" ")
  { ch=ch.slice(1)
  c=ch.charAt(0)
  }
  c=ch.charAt(ch.length-1)
  while(c==" ")
  { ch=ch.slice(0,-1)
  c=ch.charAt(ch.length-1)
  }
  return ch;
}

//===========================================================================
function check_url(url)
{
  var re = new RegExp("^http[s]?://[\\w\\.-]+\\.[A-Za-z]{2,}.*");
  var re2 = new RegExp("^http[s]?://[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
  return(re.test(url) || re2.test(url));
}

//===========================================================================
function check_mail(email)
{ var re = new RegExp("^[\\w\\.-]+@[\\w\\.-]+\\.[A-Za-z]{2,}");
  return (re.test(email));
}

function setCookieCat(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function CheckAllFormData() {
    //If All right then is_ok=1
    is_ok=1;

    tmp1 = document.form_4371.ch_num;
    if( trim(tmp1.value)!='' ) { document.getElementById('ch_num_text').className='inumb'; }
    else {
        is_ok=0;
        document.getElementById('ch_num_text').className='inumb_noright';
        document.form_4371.ch_num.focus();
    }
    tmp1 = document.form_4371.bodymessg;
    if( trim(tmp1.value)!='' ) { document.getElementById('bodymessg_text').className='imessg'; }
    else {
        is_ok=0;
        document.getElementById('bodymessg_text').className='imessg_noright';
        document.form_4371.bodymessg.focus();
    }

    tmp1 = document.form_4371.question;
    if( trim(tmp1.value)!='' ) { document.getElementById('question_text').className='iquest'; }
    else {
        is_ok=0;
        document.getElementById('question_text').className='iquest_noright';
        document.form_4371.question.focus();
    }

    tmp1 = document.form_4371.email;
    if( check_mail(tmp1.value) ) { document.getElementById('email_text').className='imail'; }
    else {
        is_ok=0;
        document.getElementById('email_text').className='imail_noright';
        document.form_4371.email.focus();
    }

    tmp1 = document.form_4371.fname;
    if( trim(tmp1.value)!='' ) { document.getElementById('fname_text').className='iname'; }
    else {
        is_ok=0;
        document.getElementById('fname_text').className='iname_noright';
        document.form_4371.fname.focus();
    }

    if (is_ok==1) {
        if(confirm('Send now?')) { document.form_4371.action.value='2'; document.form_4371.submit(); }
        else {return false;}
    } else {
        document.getElementById('warning_msg').style.display='block';
        return false;
    }
}

function getBodyScrollTop() {
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

//******************************* SEND RESULT LOANS CD **************************************************
function getServiceResponse(amount,page_no,prd_id,zipcode,outputId) {
    var outEl = document.getElementById(outputId);
    setCookieCat('zip',zipcode,'Fri, 01-Jan-2010 00:00:01 GMT');
    frm=document.loan_form;
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            outEl.innerHTML=req.responseText;
            init();
        } else {
            outEl.innerHTML='LOADING...';
        }
    }
    req.open('get', 'fast.php', true);
    req.send( {amount:amount,page_no:page_no,prd_id:prd_id,zipcode:zipcode} );
}

function isNumber(chk_value) {
    if (chk_value==""||chk_value==0) return false;
    if (!isNaN(chk_value)) return true;
    return false;
}

/*
originally written by paul sowden <paul@idontsmoke.co.uk> | http://idontsmoke.co.uk
modified and localized by alexander shurkayev <alshur@narod.ru> | http://htmlcoder.visions.ru
*/

var img_dir = "./images/"; // image folder
var sort_case_sensitive = false; // case sensitive
//initial_sort_id = 0;
//initial_sort_up = 1;

function _sort(a, b) {
    var a = a[0];
    var b = b[0];
    var _a = (a + '').replace(/,/, '.');
    var _b = (b + '').replace(/,/, '.');
    if (parseFloat(_a) && parseFloat(_b)) return sort_numbers(parseFloat(_a), parseFloat(_b));
    else if (!sort_case_sensitive) return sort_insensitive(a, b);
    else return sort_sensitive(a, b);
}

function sort_numbers(a, b) {
    return a - b;
}

function sort_insensitive(a, b) {
    var anew = a.toLowerCase();
    var bnew = b.toLowerCase();
    if (anew < bnew) return -1;
    if (anew > bnew) return 1;
    return 0;
}

function sort_sensitive(a, b) {
    if (a < b) return -1;
    if (a > b) return 1;
    return 0;
}

function getConcatenedTextContent(node) {
    var _result = "";
    if (node == null) {
        return _result;
    }
    var childrens = node.childNodes;
    var i = 0;
    while (i < childrens.length) {
        var child = childrens.item(i);
        switch (child.nodeType) {
            case 1: // ELEMENT_NODE
            case 5: // ENTITY_REFERENCE_NODE
                _result += getConcatenedTextContent(child);
                break;
            case 3: // TEXT_NODE
            case 2: // ATTRIBUTE_NODE
            case 4: // CDATA_SECTION_NODE
                _result += child.nodeValue;
                break;
            case 6: // ENTITY_NODE
            case 7: // PROCESSING_INSTRUCTION_NODE
            case 8: // COMMENT_NODE
            case 9: // DOCUMENT_NODE
            case 10: // DOCUMENT_TYPE_NODE
            case 11: // DOCUMENT_FRAGMENT_NODE
            case 12: // NOTATION_NODE
            // skip
            break;
        }
        i++;
    }
    return _result;
}

function sort(e) {
    var el = window.event ? window.event.srcElement : e.currentTarget;
    while (el.tagName.toLowerCase() != "th") el = el.parentNode;
    var a = new Array();
    var name = el.lastChild.nodeValue;
    var dad = el.parentNode;
    var table = dad.parentNode.parentNode;
    var up = table.up;
    var node, arrow, curcol;
    //for (var i = 0; (node = dad.getElementsByTagName("th").item(i)); i++) {
    for (var i = 0; (node = dad.childNodes[i]); i++) {
        if (node.lastChild.nodeValue == name){
            curcol = i;
            if (node.className == "curcol"){
                arrow = node.firstChild;
                table.up = Number(!up);
            }else{
                node.className = "curcol";
                arrow = node.insertBefore(document.createElement("img"),node.firstChild);
                table.up = 0;
            }
            arrow.src = img_dir + table.up + ".gif";
            arrow.alt = "";
        }else{
            if (node.className == "curcol"){
                node.className = "";
                if (node.firstChild) node.removeChild(node.firstChild);
            }
        }
    }
    var tbody = table.getElementsByTagName("tbody").item(0);
    //var tbody = table.tBodies[0];
    //for (var i = 0; (node = tbody.getElementsByTagName("tr").item(i)); i++) {
    for (var i = 0; (node = tbody.rows[i]); i++) {
        a[i] = new Array();
        a[i][0] = getConcatenedTextContent(node.getElementsByTagName("td").item(curcol));
        a[i][1] = getConcatenedTextContent(node.getElementsByTagName("td").item(1));
        a[i][2] = getConcatenedTextContent(node.getElementsByTagName("td").item(0));
        a[i][3] = node;
    }
    a.sort(_sort);
    if (table.up) a.reverse();
    for (var i = 0; i < a.length; i++) {
        tbody.appendChild(a[i][3]);
    }
}

function init(e) {
    if (!document.getElementsByTagName) return;

    for (var j = 0; (thead = document.getElementsByTagName("thead").item(j)); j++) {
        var node;
        for (var i = 0; (node = thead.getElementsByTagName("th").item(i)); i++) {
            if (node.addEventListener) node.addEventListener("click", sort, false);
            else if (node.attachEvent) node.attachEvent("onclick", sort);
            node.title = "Click on a header to sort the column";
        }
        thead.parentNode.up = 0;

        if (typeof(initial_sort_id) != "undefined"){
            td_for_event = thead.getElementsByTagName("th").item(initial_sort_id);
            if (document.createEvent){
                var evt = document.createEvent("MouseEvents");
                evt.initMouseEvent("click", false, false, window, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, td_for_event);
                td_for_event.dispatchEvent(evt);
            } else if (td_for_event.fireEvent) td_for_event.fireEvent("onclick");
            if (typeof(initial_sort_up) != "undefined" && initial_sort_up){
                if (td_for_event.dispatchEvent) td_for_event.dispatchEvent(evt);
                else if (td_for_event.fireEvent) td_for_event.fireEvent("onclick");
            }
        }
    }
}

function changeVisible(iId) {
    document.getElementById('top_head').className='top_form'+iId;
    for (var i=1; i<4; i++) {
        document.getElementById('body_'+i).style.display=(i==iId?'':'none');
        document.getElementById('hist'+i).className='part_'+(i==iId?'1':'2');
    }
}
function checkNum(elId) {
    var tmpEl = document.getElementById(elId);
    if (!allowOnly09(tmpEl.value)) {
        tmpEl.style.borderColor='#E77817';
        show_bar();
        return false;
    } else {
        tmpEl.style.borderColor='';
        hide_bar();
        setCookieCat('zip',tmpEl.value,'Fri, 01-Jan-2010 00:00:01 GMT');
        return true;
    }
}

function getLoan(amountId,zipId,outputId,pageNo,prdId) {
    var tmpEl_1 = document.getElementById(amountId);
    var tmpEl_2 = document.getElementById(zipId);
    if (!isNumber(tmpEl_1.value)) {
        tmpEl_1.style.borderColor='#E77817';
        return false;
    } else {
        tmpEl_1.style.borderColor='';
        if (!checkNum(zipId)) {
            return false;
        } else {
            document.getElementById(outputId).style.display='';
            getServiceResponse(tmpEl_1.value,pageNo,prdId,tmpEl_2.value,outputId);
            return true;
        }
    }
}
function getCD(zipId,outputId,pageNo,prdId,closeId,textId) {
    var tmpEl_1 = document.getElementById(zipId);
    if (!checkNum(zipId)) {
        return false;
    } else {
        if (closeId == undefined) closeId = '';
        if (closeId.length>0) {
            document.getElementById(closeId).style.display='';
            document.getElementById(textId).style.display='none';
        }
        document.getElementById(outputId).style.display='';
        getServiceResponse('',pageNo,prdId,tmpEl_1.value,outputId);
        return true;
    }
}
function sendFormFaq() {
    is_ok=1;
    tmp2 = document.form_faq.number;
    if (trim(tmp2.value)!='') {
        document.getElementById('text_num').style.color='';
    } else {
        is_ok=0;
        document.getElementById('text_num').style.color='red';
        document.form_faq.number.focus();
    }
    tmp2 = document.form_faq.messg;
    if (trim(tmp2.value)!='') {
        document.getElementById('text_mess').style.color='';
    } else {
        is_ok=0;
        document.getElementById('text_mess').style.color='red';
        tmp2.focus();
    }
    tmp2 = document.form_faq.femail;
    if (tmp2.value!='') {
        if (check_mail(tmp2.value)) {
            document.getElementById('text_email').style.color='';
        }
    } else {
        is_ok=0;
        document.getElementById('text_email').style.color='red';
        tmp2.focus();
    }
    tmp2 = document.form_faq.fname;
    if (trim(tmp2.value)) {
        document.getElementById('text_fname').style.color='';
    } else {
        is_ok=0;
        document.getElementById('text_fname').style.color='red';
        tmp2.focus();
    }
    if (is_ok==1) {
        document.form_faq.func.value='post_quest';
        document.form_faq.submit();
    } else return false;
}
function getBracket(type) {
    if (type=='o') return '<';
    else return '>';
}
function checkNewsComment() {
    //If All right then is_ok=1
    var is_ok=1;
    var tmp1 = document.form_comm_news.ch_num;
    if (trim(tmp1.value)!='') { document.getElementById('ch_num_text').className='ch_num'; }
    else {
        is_ok=0;
        document.getElementById('ch_num_text').className='ch_num_noright';
        document.form_comm_news.ch_num.focus();
    }
    tmp1 = document.form_comm_news.bodymessg;
    if (trim(tmp1.value)!='') { document.getElementById('bodymessg_text').className='name_f_news'; }
    else {
        is_ok=0;
        document.getElementById('bodymessg_text').className='name_f_news_noright';
        document.form_comm_news.bodymessg.focus();
    }
    tmp1 = document.form_comm_news.email;
    if (tmp1.value!='') {
        if (check_mail(tmp1.value) ) { document.getElementById('email_text').className='name_f_news'; }
        else {
            is_ok=0;
            document.getElementById('email_text').className='name_f_news_noright';
            document.form_comm_news.email.focus();
        }
    }
    tmp1 = document.form_comm_news.fname;
    if (trim(tmp1.value)!='') { document.getElementById('fname_text').className='name_f_news'; }
    else {
        is_ok=0;
        document.getElementById('fname_text').className='name_f_news_noright';
        document.form_comm_news.fname.focus();
    }
    if (is_ok==1) {
        if (confirm('Send now?')) { document.form_comm_news.action.value='post_comm'; document.form_comm_news.submit(); }
        else return false;
    }
}

function checkProd(prdId) {
    if (prdId==66977) location.href = "./Certificate-Deposit.php";
    if (prdId==66978 || prdId==66979) location.href = "./Money-Market.php";
}