﻿/**** miscellaneous javascript functions ****/

/* Replaced previous function with jQuery supremacy!!!
 */
function addLoadEvent(func) {
  if (typeof($) == 'function'){ // use jQuery
    $(document).ready(func);
  } else {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function() {
        if (oldonload) {
          oldonload();
        }
        func();
      }
    }
  }	
}

/* change document stylesheet to one with a different font size */
function setFontChange(title) {

   var i, a;

   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {

     if(a.getAttribute("rel").indexOf("style") != -1

        && a.getAttribute("title")) {

       a.disabled = true;

       if(a.getAttribute("title") == title) a.disabled = false;

     }

   }

}

/* radio and checkbox functions */
function checkAnOption(cGroup, cValue) {
	var cAi;
	for (cAi = 0; cAi < cGroup.length; cAi++) 
		if (cGroup[cAi].value == cValue) cGroup[cAi].checked = true;
}
function whichRadioChecked(radioGroup) {
	var rI;
	for (rI = 0; rI < radioGroup.length; rI++)
		if (radioGroup[rI].checked) return radioGroup[rI].value;
	return null;
}
// a duplicate of the above function except this returns the ID and not the 
// value of the checked Radio Button. 
function whichRadioCheckedID(radioGroup) {
    var rI;
    for (rI = 0; rI < radioGroup.length; rI++)
        if (radioGroup[rI].checked) return radioGroup[rI].id;
    return null;
}




function whichBoxChecked(boxGroup){
	var bI, bValues = "";
	for (bI = 0; bI < boxGroup.length; bI++)
		if (boxGroup[bI].checked) bValues = bValues + boxGroup[bI].value + ", ";
	return bValues;
}
function selectIndexValue(ref) {return document.forms[0].elements[ref].options[document.forms[0].elements[ref].selectedIndex].value;}



/* handle javascript execution errors */
var errorMsg = '';

function errorHandler(msg,url,l) {
    errorMsg += 'Error: ' + msg + '\n';
    errorMsg += 'URL: ' + url + '\n';
    errorMsg += 'Line: ' + l + '\n\n';
    
    return true;
}

function showError() {
    alert(errorMsg);
}

// addLoadEvent(function() { var xx = "addLoadEvent() test success"; alert(xx); });

//used for the click calling option in home loans section
function ClicktoCall(id){
	var w=370;
	var h=450;
	var leftPos=(screen.width)?(screen.width-w)/2:100;
	var topPos=(screen.height)?(screen.height-h)/2:100;
	var settings='width='+w+',height='+h+',top='+topPos+',left='+leftPos+',';
	settings = settings+'location=no,directories=no,menubar=no,toolbar=no,';
	settings = settings+'status=no,scrollbars=no,resizable=no,dependent=no';
	var sUrl='http://www.nascomms.com/ccConnect/Dialer.aspx?clientId='+id;
	var ccWindow=window.open(sUrl,'ClickCalling',settings);
	ccWindow.focus();
}

function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}


function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}
