﻿/**** miscellaneous javascript functions ****/

/* Standard jQuery 'onload' */
$(document).ready(function(){
    fixAppLinks();
});

/* Replaced the previous function with jQuery .ready() as this 
 * is actually faster (and cleaner)
 */
function addLoadEvent(func) {
  $(document).ready(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;
}
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();
}


/* Makes any links to the apps domain open using open_centerscreen
 * If they are not manually set to use something else
 */
function fixAppLinks(){
    $("a[href^=https://apps][onclick=]").click(function(){
        open_centerscreen(this.href);
        return false;
    })
}