﻿function clearInputText(thefield) {
	if (thefield.defaultValue==thefield.value)
		thefield.value = "";

}



function rememberCity(theValue) {
    if (document.locForm.remCity.checked) {
        var theLoc = document.locForm.location.value;

        if (theLoc != "" && theLoc != "AL" && theLoc != "FL" && theLoc != "GA" && theLoc != "SC") {

            //Set that cookie...
            //Set_Cookie('cityBank', theLoc, 30, '/', 'ameris.dev.trsg.net', '');
			var myDomain = document.domain;
			//alert(myDomain);
			Set_Cookie('cityBank', theLoc, 30, '/', myDomain, '');
        }
        
    } else {
    
        //Delete_Cookie('cityBank', '/', 'ameris.dev.trsg.net');
		Delete_Cookie('cityBank', '/', 'www.amerisbank.com');
    }
}

function checkLocation() {
    if (Get_Cookie('cityBank')) {
        var theLoc = Get_Cookie('cityBank');

        //Set the form...
        setLocation(theLoc);

        //loop through for a city match...
        for (i = 0; i < document.locForm.location.length; i++) {
            if (document.locForm.location[i].value == theLoc) {

                document.locForm.location[i].selected = true;
            }
        }

        document.locForm.remCity.checked = true

    } else {
        
    }
}

function setLocation(theLoc) {

    if (theLoc != "" && theLoc != "AL" && theLoc != "FL" && theLoc != "GA" && theLoc != "SC") {

        if (document.locForm.remCity.checked) {
            
            //Set that cookie...
            //Set_Cookie('cityBank', theLoc, 30, '/', 'ameris-new.dev.trsg.net', '');
			Set_Cookie('cityBank', theLoc, 30, '/', 'www.amerisbank.com', '');
        }

        var strForm = "";

        if (theLoc == "Lawrenceville") {
            strForm += "<div id=\"personal\" style=\"display: none;\"></div>";
            strForm += "<div id=\"business\" style=\"display: none;\"></div>";
            strForm += "<div id=\"personal-form\">";
            strForm += "<FORM id=\"jhlogin\" action=\"https://www.netteller.com/amerisbank/\" method=\"post\">";
            strForm += "<input type=\"submit\" id=\"sign_in\" name=\"Submit\" value=\"Access Your Account\" class=\"button_access_account\">";
            strForm += "</FORM>";
            strForm += "</div>";
        
			strForm += "<div class=\"clear\"></div>";
			strForm += "<div id=\"register\">";
			strForm += "<form action=\"https://cm.netteller.com/login2008/enroll.aspx?fi=amerisbank&bn=8d719f4065220314&burlid=379fa694ba7913ee\" method=\"post\">";
			///strForm += "<input type=\"submit\" name=\"submit\" value=\"New User Registration\" />";
			strForm += "</form>";
			strForm += "</div>";
			strForm += "</div>";

        } else if (theLoc == "Sparta" || theLoc == "Woodstock") {
            strForm += "<div id=\"loginTabs\">";
            strForm += "<a id=\"business\" onClick=\"javascript:display('business','personal');\">Business</a> or ";
            strForm += "<a id=\"personal\" onClick=\"javascript:display('personal','business');\">Personal</a>?";
            strForm += "</div>";

            strForm += "<div id=\"personal-form\">";
            strForm += "<form action=\"https://secure.mvnt4.com/slapi/SeamlessLoginClientServlet466\" method=\"post\" name=\"cebform\" id=\"cebform\" onsubmit=\"return gotoSubmit('cebform');\">";
            strForm += "<input type=\"hidden\" name=\"userid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"password\" value=\"none\" />";
            strForm += "<input type=\"hidden\" value=\"ceb\" name=\"target\" />";
            strForm += "<input type=\"hidden\" name=\"FIFID\" value=\"061201754\" />";
            strForm += "<input type=\"hidden\" name=\"FIORG\" value=\"466\" />";
            
            strForm += "<label id=\"error_useridCEB\" for=\"useridCEB\"></label><div class=\"lbox\"><input type=\"text\" name=\"useridCEB\" id=\"useridCEB\" value=\"User ID\" maxlength=\"20\" onfocus=\"clearInputText(this)\" /></div>";
            
            strForm += "<div class=\"lbutton\"><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\" /></div>";
            strForm += "</form>";

            strForm += "<div id=\"register\">";
            strForm += "<form action=\"https://cibng.ibanking-services.com/cib/themes/cib_enroll/enroll/enroll.jsp?FIORG=466&FIFID=061201754\" method=\"post\">";
            strForm += "<input type=\"submit\" name=\"submit\" style=\"margin-top:15px;\" value=\"Current Personal Customers\" /><div style=\"font-size:1.1em; font-weight:bold; margin-bottom:15px; text-align:center;\">First time accessing<br />Personal Internet Banking<br />on or after July 25.</div>";
            strForm += "<div class=\"lbutton\"><input type=\"submit\" name=\"submit\" style=\"margin-top:10px;\" value=\"New User Registration\" /></div>";
            strForm += "</form>";
            strForm += 
            "</div>";
            strForm += "</div>";

            strForm += "<div id=\"business-form\">";
            strForm += "<form action=\"https://secure.mvnt4.com/slapi/SeamlessLoginClientServlet466\" method=\"post\" name=\"bibform\" id=\"bibform\" onsubmit=\"return gotoSubmit('bibform');\">";
            strForm += "<input type=\"hidden\" name=\"companyid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"userid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"password\" value=\"none\" />";
            strForm += "<input type=\"hidden\" value=\"bib\" name=\"target\" />";
            
            strForm += "<label id=\"error_companyidBIB\" for=\"companyidBIB\"></label><div class=\"lbox\"><input type=\"text\" name=\"companyidBIB\" id=\"companyidBIB\" value=\"Company ID\" maxlength=\"20\"  onfocus=\"clearInputText(this)\" /></div>";
          	
          	strForm += "<label id=\"error_useridBIB\" for=\"useridBIB\"></label><div class=\"lbox\"><input type=\"text\" name=\"useridBIB\" id=\"useridBIB\" value=\"User ID\" maxlength=\"20\" onfocus=\"clearInputText(this)\" /></div>";
          	strForm += "<div class=\"lbutton\"><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\" /></div>";
          
            strForm += "</form>";
            strForm += "</div>";
			
			strForm += "</div>";

        } else {

            strForm += "<div id=\"loginTabs\">";
            strForm += "<a id=\"business\" onClick=\"javascript:display('business','personal');\">Business</a> or ";
            strForm += "<a id=\"personal\" onClick=\"javascript:display('personal','business');\">Personal</a>?";
            strForm += "</div>";

            
            strForm += "<div id=\"personal-form\">";
            strForm += "<form action=\"https://secure.mvnt4.com/slapi/SeamlessLoginClientServlet466\" method=\"post\" name=\"cebform\" id=\"cebform\" onsubmit=\"return gotoSubmit('cebform');\">";
            strForm += "<input type=\"hidden\" name=\"userid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"password\" value=\"none\" />";
            strForm += "<input type=\"hidden\" value=\"ceb\" name=\"target\" />";
            strForm += "<input type=\"hidden\" name=\"FIFID\" value=\"061201754\" />";
            strForm += "<input type=\"hidden\" name=\"FIORG\" value=\"466\" />";
            
           // strForm += "<label id=\"error_useridCEB\" for=\"useridCEB\"></label><div class=\"lbox\"><input type=\"text\" name=\"useridCEB\" id=\"useridCEB\" value=\"User ID\" maxlength=\"20\" onchange=\"ntptEventTag('linkto=OnlineLogin&place=ceb')\" onfocus=\"clearInputText(this)\" /></div>";
            strForm += "<label id=\"error_useridCEB\" for=\"useridCEB\"></label><div class=\"lbox\"><input type=\"text\" name=\"useridCEB\" id=\"useridCEB\" value=\"User ID\" maxlength=\"20\" onfocus=\"clearInputText(this)\" /></div>";
            
            strForm += "<div class=\"lbutton\"><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\" /></div>";
            
            //strForm += "<p><label id=\"error_useridCEB\" for=\"useridCEB\">User ID:</label><br /><input type=\"text\" name=\"useridCEB\" id=\"useridCEB\" style=\"width: 130px; background-color: #FFFFFF;\" maxlength=\"20\" onchange=\"ntptEventTag('linkto=OnlineLogin&place=ceb')\"></p>";
            //strForm += "<p style=\"padding-left: 80px;\"><label></label><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\"></p>";

            strForm += "</form>";

            strForm += "<div id=\"register\">";
            strForm += "<form action=\"https://cibng.ibanking-services.com/cib/themes/cib_enroll/enroll/enroll.jsp?FIORG=466&FIFID=061201754\" method=\"post\">";
            strForm += "<input type=\"submit\" name=\"submit\" value=\"New User Registration\" />";
            strForm += "</form>";
            strForm += 
            "</div>";
            strForm += "</div>";

            strForm += "<div id=\"business-form\">";
            strForm += "<form action=\"https://secure.mvnt4.com/slapi/SeamlessLoginClientServlet466\" method=\"post\" name=\"bibform\" id=\"bibform\" onsubmit=\"return gotoSubmit('bibform');\">";
            strForm += "<input type=\"hidden\" name=\"companyid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"userid\" value=\"\" />";
            strForm += "<input type=\"hidden\" name=\"password\" value=\"none\" />";
            strForm += "<input type=\"hidden\" value=\"bib\" name=\"target\" />";
            
            //strForm += "<p><label id=\"error_companyidBIB\" for=\"companyidBIB\">Company ID:</label><br /><input type=\"text\" name=\"companyidBIB\" id=\"companyidBIB\" style=\"width: 130px background-color: #FFFFFF;\" maxlength=\"20\" onchange=\"ntptEventTag('linkto=OnlineLogin&place=bib')\"></p>";
            //strForm += "<p><label id=\"error_useridBIB\" for=\"useridBIB\">User ID:</label><br /><input type=\"text\" name=\"useridBIB\" id=\"useridBIB\" style=\"width: 130px background-color: #FFFFFF;\" maxlength=\"20\"></p>";
            //strForm += "<p style=\"padding-left: 80px;\"><label></label><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\"></p>";
          	
          	//strForm += "<label id=\"error_companyidBIB\" for=\"companyidBIB\"></label><div class=\"lbox\"><input type=\"text\" name=\"companyidBIB\" id=\"companyidBIB\" value=\"Company ID\" maxlength=\"20\" onchange=\"ntptEventTag('linkto=OnlineLogin&place=bib')\" onfocus=\"clearInputText(this)\" /></div>";
            strForm += "<label id=\"error_companyidBIB\" for=\"companyidBIB\"></label><div class=\"lbox\"><input type=\"text\" name=\"companyidBIB\" id=\"companyidBIB\" value=\"Company ID\" maxlength=\"20\"  onfocus=\"clearInputText(this)\" /></div>";
          	
          	strForm += "<label id=\"error_useridBIB\" for=\"useridBIB\"></label><div class=\"lbox\"><input type=\"text\" name=\"useridBIB\" id=\"useridBIB\" value=\"User ID\" maxlength=\"20\" onfocus=\"clearInputText(this)\" /></div>";
          	strForm += "<div class=\"lbutton\"><input type=\"submit\" id=\"sign_in\" name=\"sign_in\" value=\"Continue\" /></div>";
          
            strForm += "</form>";
            strForm += "</div>";
        
			//strForm += "<div class=\"clear\"></div>";
			
			strForm += "</div>";
        }        

        document.getElementById('loginFormBox').innerHTML = strForm;

    } else {

        document.cebform.useridCEB.disabled = true;
        document.bibform.companyidBIB.disabled = true;
        document.bibform.useridBIB.disabled = true;

        document.getElementById('useridCEB').style.background = "#cccccc";
        document.getElementById('companyidBIB').style.background = "#cccccc";
        document.getElementById('useridBIB').style.background = "#cccccc";
    }
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
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;
    }
}

// this function gets the cookie, if it exists
// don't use this, it's weak and does not handle some cases
/* correctly, this is just to maintain legacy information
function Get_Cookie(name) {

    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) &&
(name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

*/

// this deletes the cookie when called
function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function checkLocationContact() {
    if (Get_Cookie('cityBank')) {
        var theLoc = Get_Cookie('cityBank');

        //Set the form...
        setLocationContact(theLoc);

        //loop through for a city match...
        for (i = 0; i < document.locForm.location.length; i++) {
            if (document.locForm.location[i].value == theLoc) {

                document.locForm.location[i].selected = true;
            }
        }

        document.locForm.remCity.checked = true

    } else {
        
    }
}

function setLocationContact(theLoc) {

    if (theLoc != "") {

        if (document.locForm.remCity.checked) {
            //Set that cookie...
            ///Set_Cookie('cityBank', theLoc, 30, '/', 'ameris-new.dev.trsg.net', '');
			Set_Cookie('cityBank', theLoc, 30, '/', 'www.amerisbank.com', '');
        }

        var setOnlineTelephoneBanking1;
		var setOnlineTelephoneBanking2;		

        if (theLoc == "Sparta" || theLoc == "Lawrenceville" || theLoc == "Woodstock") {
            setOnlineTelephoneBanking1 = document.getElementById("onlineTelephoneBanking1");
			setOnlineTelephoneBanking2 = document.getElementById("onlineTelephoneBanking2");
			setOnlineTelephoneBanking1.style.display="none";
			setOnlineTelephoneBanking2.style.display="block";
        } else {
            setOnlineTelephoneBanking1 = document.getElementById("onlineTelephoneBanking1");
			setOnlineTelephoneBanking2 = document.getElementById("onlineTelephoneBanking2");
			setOnlineTelephoneBanking1.style.display="block";
			setOnlineTelephoneBanking2.style.display="none";
        }
    }
}
