/***********************************************
 * This section is used for Survey popup
 * MUST BE AT TOP 
 ***********************************************/

// 2009-05-18 - MS
// Traps JavaScript errors, calls generic handler SyslogWriter.ashx on the server and sends the error message
// as QueryString.  SyslogWriter.ashx sends the error to the default syslog server.
window.onerror = function(message, url, line) 
{     
    var ClinetAppName = navigator.appName;
    var ClientAppVersion = navigator.appVersion;    
    var ErrorMessage = message + "|URL:" + url + " |Line:" + line +
        " |Browser: " + ClinetAppName + " |Version:" + ClientAppVersion +
        " |Referrer:" + document.referrer + 
        " |Document: " + document.URL;
        
    var tmpImage = document.createElement('img');
    tmpImage.src = "../SyslogWriter.ashx?jserror=" + ErrorMessage;
}
// End of Java Script error handler.


var properClickthrough = false;
function disableSurveyPopup(){
    properClickthrough = true;
}

function enableSurveyPopup(){
    properClickthrough = false;
}

function showExitSurvey()
{
    if (!properClickthrough)
    {
        window.onbeforeunload = null;
        // window.open(survey_url,'Survey','height=800,width=450');          
    }
}

window.onbeforeunload = showExitSurvey;

document.documentElement.onclick = disableSurveyPopup;   // this will DISABLE survey popup when user clicks on link from the current page
/*** End Exit Survey Popup section **************/

function isCellPhone(phone)
{
    ret = AN_WebService.isCellPhone(phone, OnVerifyPhoneComplete, OnVerifyPhoneTimeOut, OnVerifyPhoneError);
    return(true);
}

function OnVerifyPhoneComplete(arg) {	    
    if (arg == 1)
        showSMS();
    else
        hideSMS();
}

function OnVerifyPhoneTimeOut() {            
    //alert("TimeOut encountered when calling isCellPhone.");
}

function OnVerifyPhoneError() {
    //alert("Error encountered when calling isCellPhone.");
}	    

var browser=navigator.appName;
var howSlide;

if (document.images){
  preload_image_object = new Image();
  // set image url
	image_url = new Array();
	var ctr = 0;
	image_url[ctr] = "/images/elements/el_rightarrow_gray.gif";++ctr;
	image_url[ctr] = "/images/backgrounds/bg_bb_repeat.jpg";++ctr;
	image_url[ctr] = "/images/backgrounds/bg_bb_image.jpg";++ctr;
	image_url[ctr] = "/images/backgrounds/bg_home_login_blu.jpg";++ctr;
	
	image_url[ctr] = "/images/graphics/gfx_howitworks_add.jpg";++ctr;
	image_url[ctr] = "/images/graphics/gfx_howitworks_shop.jpg";++ctr;
	image_url[ctr] = "/images/graphics/gfx_howitworks_credit.jpg";++ctr;
	image_url[ctr] = "/images/graphics/gfx_howitworks_borrow.jpg";++ctr;
	
	var i = 0;
 	for(i=0; i<image_url.length; i++) {
    	preload_image_object.src = image_url[i];
    }
}

// Breadcrmb
var crumbsep = '<td align=center width=20><img class="bc_arrow" vspace="5" src="/images/elements/el_rightarrow_gray.gif" align="middle" /></td>';
var sectionsep = "/";
var rootpath = "/"; // Use "/" for root of domain.
var rootname = 'Welcome to AccountNow';
var ucfirst = 1; // if set to 1, makes "directory" default to "Directory"
var objurl = new Object;
var pageurl;
var protocol;
var rooturl;
var page_ar;
var currenturl;
var allbread;

function loadBreadcrumb(){
	objurl['/'] = 'Welcome to AccountNow';
	objurl['secure'] = 'New Customers';
	objurl['web-mkt'] = 'Promotions';
	objurl['services'] = 'Features';
	objurl['billpay'] = 'Online Bill Pay';	
	
	//x=y;
	// Grab the page's url and break it up into directory pieces
	pageurl = (new String(document.location));
	protocol = pageurl.substring(0, pageurl.indexOf("//") + 2);
	pageurl = pageurl.replace(protocol, ""); // remove protocol from pageurl
	
	rooturl = pageurl.substring(0, pageurl.indexOf(rootpath) + rootpath.length); // find rooturl
	
	if (rooturl.charAt(rooturl.length - 1) == "/") //remove trailing slash
	//{rooturl = rooturl.substring(0, rooturl.length - 1);}
	pageurl = pageurl.replace(rooturl, ""); // remove rooturl from pageurl
		if (pageurl.charAt(0) == '/') // remove beginning slash
			{pageurl = pageurl.substring(1, pageurl.length);}
	
	page_ar = pageurl.split(sectionsep);
	currenturl = protocol + rooturl;
	homeURL = currenturl;
	
	//allbread =  '<td align=center width=50><a class="size11 tahoma dkblue" href="' + currenturl + '">Home</a></td>'
	allbread =  '<td><a class="size11 tahoma dkblue" href="' + homeURL + '">Home</a></td>' + crumbsep
	
	
	for (i=0; i < page_ar.length-1; i++){
		var displayname = "";
		currenturl += page_ar[i] + "/";
		if (objurl[page_ar[i]]){
			displayname = objurl[page_ar[i]];
		} else {
		    if (ucfirst == 1){
				displayname = page_ar[i].charAt(0).toUpperCase() + page_ar[i].substring(1);
			} else { 
				displayname = page_ar[i];
			}
	  	}
	  	allbread += '<td><a class="size11 tahoma dkblue" href="' + currenturl + '">' + displayname + '</a></td>' + crumbsep;
	}
	
	//allbread += '<td id="pageh1" class="dkblue size11 bold tahoma">&nbsp;</td>'
}

//Testimonial Rotator
var quote;
var name;
var cityState;
function rotateComments(){
	var randNum = Math.floor(Math.random() * (4 - 0 + 1)) + 0;
	var commentArray = new Array(5);
		
		commentArray[0] = new Array(3)
		commentArray[0][0] = "It's a great card to use if you don't have a credit card..."
		commentArray[0][1] = "Dawn"
		commentArray[0][2] = "Tracy, CA"	
		
		commentArray[1] = new Array(3)
		commentArray[1][0] = "Hands down the best at giving a second chance..."
		commentArray[1][1] = "Pastor Iymarie"
		commentArray[1][2] = "Huntsville, AL"
		
		commentArray[2] = new Array(3)	
		commentArray[2][0] = "I don't spend money on expensive check cashing fees..."
		commentArray[2][1] = "Sara"
		commentArray[2][2] = "Franklin, TN"
		
		commentArray[3] = new Array(3)	
		commentArray[3][0] = "AccountNow doesn't nickel and dime you to death..."
		commentArray[3][1] = "Mary"
		commentArray[3][2] = "Cortland, NY"
		
		commentArray[4] = new Array(3)
		commentArray[4][0] = "Convenient and easy with kind customer service agents..."
		commentArray[4][1] = "Richard"
		commentArray[4][2] = "Cerritos, CA"
		
	quote = commentArray[randNum][0];
	name = commentArray[randNum][1];
	cityState = commentArray[randNum][2];
}

// Sign Up Form
function SetupDisplay(){
    if(WebForm_OnSubmit())
    {
        openModal();
        setTimeout("submitApp()",2000);
    }
}
function submitApp(){
    $('aspnetForm').submit();
}
function openModal(){
   YAHOO.application.modal.wait.show();  
}

document.onload = loadBreadcrumb();rotateComments();

// Tips
window.addEvent('domready', function(){
    var Tips2 = new Tips($$('.Tips2'), {
        initialize:function(){
            this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
        },
        onShow: function(toolTip) {
            this.fx.start(1);
        },
        onHide: function(toolTip) {
            this.fx.start(0);
        }
        });
        
        
    YAHOO.namespace("application.modal");
    if (!YAHOO.application.modal.wait){
        // Initialize the temporary Panel to display while waiting for appication to process
        YAHOO.application.modal.wait = new YAHOO.widget.Panel("wait",{width:"350px",height:"80px",fixedcenter:true,close:false,draggable:false,zindex:4,modal:true,visible:false} );
    }
    YAHOO.application.modal.wait.setHeader("Processing your approval, please wait...");
    YAHOO.application.modal.wait.setBody('<div class="center"><img src="/images/graphics/loading_bar_gray.gif" /></div>');
    YAHOO.application.modal.wait.render(document.body);
           
}); 
