/**************************************************************/
/**************************************************************/
/*   THIS SECTION SHOULD BE THE ONLY AREA THAT NEEDS EDITING  */
/**************************************************************/
/**************************************************************/
/*
 * LAST UPDATED: 10/25/2011
 * REASON: TURN OFF DANVERSBANK REGIONALIZED TOOL TIPS
*/
regionalizedToolTipsActive = false; /*Set to false to turn off CEB and BEB regionalized tooltips*/
activeOCO =["dan", "DAN"]; /* Set all allowed oco to display tool tips for when regionalizedToolTipsActive is set to true*/ 
cebtoolTipActive = false; /* Set to false to turn off CEB tooltop on homepage login box */
bebtoolTipActive = false; /* Set to false to turn off BEB tooltop on homepage login box */
cebSplashOn = false;  /* set to true to display splashbox for CEB login ONLY */
bebSplashOn = false; /* set to true to display splashbox for BEB login ONLY */
/*
UPDATE THE CONTENT BELOW TO DISPLAY APPROPRIATE MESSAGE IN CEB OR BEB SPLASHBOX,
KEEP IN MIND THE SPACE AVAILABLE IN SPLASHBOX FOR MESSAGE. 
*/
oco = "";
ceb_oco_tt_img = "blue_bubble.png"; //default ceb tooltip image name
beb_oco_tt_img = "beb_bubble.png";  //default beb tooltip image name
ceb_oco_tt_link = "https://www.peoples.com/info/video_login.html"; //default ceb tooltip link
beb_oco_tt_link = "/"; //default beb tooltip link
cebOutageAlert = '<font class="paragraphHeader" style="line-height:110%;">Temporarily Unavailable</font><BR><font class="content" style="color:#ff0000;">Personal Banking is temporarily unavailable, we apologize<BR>for the inconvenience. Please try again shortly.</font>';
bebOutageAlert = '<font class="paragraphHeader" style="line-height:110%;">System Maintenance</font><BR><font class="content" style="color:#ff0000;">eTreasury+ is unavailable for scheduled maintenance. We apologize for the inconvenience.</font>';
/*
BELOW ASSIGNS WHICH ONLINE BANKING TAB IS ACTIVE BY DEFAULT ON THE HOMEPAGE
SET IT TO 'ceb' FOR PERSONAL ONLINE BANKING TO BE DEFAULT
SET IT TO 'bib' FOR BUSINESS ONLINE BANKING TO BE DEFAULT

function obTypeDefault(){
	obType('ceb');
}
*/
/*CHECK IF (ORIGINAL CUSTOMER OF) PARAMETER EXITS FOR REGIONALIZED TOOL TIPS - CALLED BY regionalizedToolTips() */
function getQSPRAM() {
	var qstr = document.location.search.substring(1);
	if(qstr.length > 0) {
		pairs = qstr.split("&");
	 	var qstrLen = pairs.length;
	  	for(i=0;i<qstrLen;i++) {
	   		var temppair = decodeURIComponent(pairs[i]);
	   		var temppair2 = temppair.replace(/=/, '=\'');
	   		pairs[i] = temppair2.concat("'");
	   		eval(pairs[i]);
		}
	}
	return oco;
}
function regionalizedToolTips(){
	oco = getQSPRAM();
	var ocoimg = "";
	var ocohref = "";
	oco = oco.replace(/[^a-zA-Z 0-9]+/g,'');
	//Check if oco is from allowed values if not turn off tool tips
	if (activeOCO.toString().indexOf(oco) == -1) {
		cebtoolTipActive=false;
		bebtoolTipActive=false;
	} else {
		if (oco != "") {
			Set_Cookie("oco2", oco, '365', '/', '', false);
		} else {
			oco = Get_Cookie("oco2");
			if(oco != null && activeOCO.toString().indexOf(oco) != -1){
				oco = oco.replace(/[^a-zA-Z 0-9]+/g,'');
			} else {
				cebtoolTipActive=false;
				bebtoolTipActive=false;
			}
		}		
	}	
	/*if (oco != "" && oco != null) {ocoimg = oco + "_";ocohref = oco;}ceb_oco_tt_img = ocoimg + "blue_bubble.png";	beb_oco_tt_img = ocoimg + "beb_bubble.png";	ceb_oco_tt_link += ocohref;	beb_oco_tt_link += ocohref;*/
}
/*END OF ORIGIANL CUSTOMER OF CHECK*/
/**************************************************************/
/**************************************************************/
if (regionalizedToolTipsActive) {
	regionalizedToolTips();
}
/* DO NOT CHANGE */
cebURL = "https://cibng.ibanking-services.com/cib/CEBMainServlet/Login?FIORG=136&FIFID=221172186";
bebURL = "https://peoplesunited.ebanking-services.com/nubi/signin.aspx";
/* DO NOT CHANGE */

	function checkCoord() {
		//CALL obType WHEN CEBSPLASHPAGE IS ON
		//obType('ceb');
		
		document.getElementById("cebexitcoord").coords = "214,9,229,22";
		document.getElementById("ceblinkcoord").coords = "0";
		/*
		document.getElementById("bebexitcoord").coords = "213,8,229,22";	
		document.getElementById("beblinkcoord").coords = "0";
		*/
	}
	
	function toolTipOff(obtype) {
		var tpSpan = document.getElementById(obtype);
		tpSpan.className = "toolTipOff";
		document.otherLogin_form.otherService.style.visibility = "visible";
	}
	
	function tooltipOn(obtype) {
		var tpSpan = document.getElementById(obtype);			
		// REGIONALIZED CEB TOOLTIP
		/*
		if (obtype == "tooltip" && cebtoolTipActive && oco!="" && oco!= null) {			
			document.getElementById("ceblinkcoord").href = ceb_oco_tt_link + "?cm_sp=Home_Page-_-Tool_Tip_Consumer-_-"+oco+"_conv_062011";
			document.otherLogin_form.otherService.style.visibility = "hidden";
			document.getElementById("cebbubble").width = "239";
			document.getElementById("cebbubble").height = "138";			
			tpSpan.className = "toolTipOn";
		} else
		*/
		if (obtype == "tooltip" && cebtoolTipActive) {
			//NONE REGIONALIZED CEB TOOLTIP
			document.getElementById("cebbubble").src = "/images/"+ceb_oco_tt_img;
			document.getElementById("ceblinkcoord").href = ceb_oco_tt_link;
			document.otherLogin_form.otherService.style.visibility = "hidden";
			document.getElementById("cebbubble").width = "239";
			document.getElementById("cebbubble").height = "162";			
			tpSpan.className = "toolTipOn";
		  } /*else if (obtype == "bebtooltip" && bebtoolTipActive && oco!="" && oco!= null) {
			//REGIONALIZED BEB TOOLTIP
			document.getElementById("beblinkcoord").href = beb_oco_tt_link + "?cm_sp=Home_Page-_-Tool_Tip_SmallBiz-_-"+oco+"_conv_062011";
			document.otherLogin_form.otherService.style.visibility = "hidden";
			document.getElementById("bebbubble").width = "239";
			document.getElementById("bebbubble").height = "119";
			tpSpan.className = "bebtoolTipOn";
		 } else if (obtype == "bebtooltip" && bebtoolTipActive) {
			//NON REGIONALIZED BEB TOOLTIP
			document.getElementById("bebbubble").src = "/images/"+beb_oco_tt_img;
			document.getElementById("beblinkcoord").href = beb_oco_tt_link;
			document.otherLogin_form.otherService.style.visibility = "hidden";
			document.getElementById("bebbubble").width = "239";
			document.getElementById("bebbubble").height = "119";
			tpSpan.className = "bebtoolTipOn";	
		}
		*/
	}
		
	function obType(frmID) {
		switch (frmID) {
			case "ceb":
				if (bebtoolTipActive) {
					toolTipOff('bebtooltip');
				}
				document.getElementById("bibformbox").style.display = "none";
				document.getElementById("cebformbox").style.display = "";
				//document.getElementById("cebl").checked = true;
				if (cebSplashOn)
					document.getElementById("cebformbox").innerHTML = cebOutageAlert;
				else
					document.getElementById("useridCEB").value = "USER ID";
			break;
			case "bib":
				if (cebtoolTipActive) {
					toolTipOff('tooltip');
				}
				document.getElementById("cebformbox").style.display = "none";
				document.getElementById("bibformbox").style.display = "";
				//document.getElementById("bibl").checked = true;
				if (bebSplashOn) {
					document.getElementById("bibformbox").innerHTML = bebOutageAlert;
				} else {
					document.getElementById("useridBIB").value = "USER ID";
					document.getElementById("companyidBIB").value = "COMPANY ID";	
				}
			break;
		}
	}

	function Input(inputID){
		switch (inputID){
			case "useridCEB":
				if (document.getElementById("useridCEB").value == "USER ID") {
					document.getElementById("useridCEB").value = "";
				}
			break;
			case "useridBIB":
				if (document.getElementById("useridBIB").value == "USER ID") {
					document.getElementById("useridBIB").value = "";
				} 
				if (document.getElementById("companyidBIB").value == "") {
					document.getElementById("companyidBIB").value = "COMPANY ID";
				}
			break;
			case "companyidBIB":
				if (document.getElementById("companyidBIB").value == "COMPANY ID") {
					document.getElementById("companyidBIB").value = "";
				}
				if (document.getElementById("useridBIB").value == "") {
					document.getElementById("useridBIB").value = "USER ID";
				}
			break;
		}
	}	
	
	function getRequiredArray(formname)
	{
		//alert("************** getRequiredArray formname = " + formname);
		if (formname == "bibform") {
			order = ["companyidBIB","useridBIB"]
		}
		else if (formname == "cebform") {
			order = ["useridCEB"]
		}		
				
		return order;
	}

	function getWriteError(fieldID)
	{
		//alert("************** getWriteError fieldID = " + fieldID);
		switch (fieldID) {
			case "useridBIB":
				var error = "- Please Enter a valid User Id.\n";
				return error;
				break;
			case "companyidBIB":
				var error = "- Please Enter a valid Company Id.\n";
				return error;
				break;
			case "useridCEB":
				var error = "- Please Enter a valid User Id.\n";
				return error;
				break;
		}//end switch
		//alert("************** getWriteError error = " + error);
		return true;
	}
	
	function getClearRequired(fieldID)
	{
		//alert("************** getClearRequired fieldID = " + fieldID);
		switch (fieldID) {
			case "companyidBIB":
				var clear = "";
				return clear;
				break;
			case "useridBIB":
				var clear = "";
				return clear;
				break;
			case "useridCEB":
				var clear = "";
				return clear;
				break;
			default:
				var clear = "";
				return clear;
		}//end switch
		//alert("************** getClearRequired clear = " + clear);
		return true;
	}

/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
	
	function gotoSubmit(formname)
	{
		//alert("************** gotoSubmit formname = " + formname);
		if (formname == "bibform") {
			var formHandle = document.bibform;
		}
		else if (formname == "cebform") {
			var formHandle = document.cebform;
		}	
		
		var errorFound = false;
		var errorDesc = "The following error(s) occurred:\n\n";
		
		//Clear the current Inner HTML
		clearRequiredFieldsInnerHTML(formname);

		//Get the required Array
		var requiredArray = getRequiredArray(formname);
		
		//var temp;
		for(var x=0; x<requiredArray.length; x++)
		{ 
			if(!(general_check_required(formHandle, requiredArray[x])))
			{ 
				var arrayItem = "error_" + requiredArray[x];

				//alert("************** gotoSubmit arrayItem = " + arrayItem);
				
				//document.getElementById(arrayItem).innerHTML = getWriteError(requiredArray[x]);	
				errorDesc += (getWriteError(requiredArray[x]));

				if(!errorFound && document.getElementById(requiredArray[x])) 
				{
					//alert("************** gotoSubmit focus = " + requiredArray[x]);
					document.getElementById(requiredArray[x]).focus();
					errorFound = true;
				}//end if
				
			}//end if 
		}//end for	
		/*	End required field check */	
		if(errorFound){
			alert(errorDesc);
			return false;
		}

		// Pass values from input fields to hidden fields
 		if (formname == "bibform") {
			formHandle.companyid.value = formHandle.companyidBIB.value;
			formHandle.userid.value = formHandle.useridBIB.value;
		}
		else if (formname == "cebform") {
			formHandle.userid.value = formHandle.useridCEB.value;
		}		

		// clear up input fields
 		if (formname == "bibform") {
			formHandle.companyidBIB.value = "";
			formHandle.useridBIB.value = "";
		}
		else if (formname == "cebform") {
			formHandle.useridCEB.value = "";
		}		

		//Validate that the userid doesn't contain special characters, only alphanumeric
		var numaric = formHandle.userid.value;
		for(var j=0; j<numaric.length; j++)
		{
			var alphaa = numaric.charAt(j);
			var hh = alphaa.charCodeAt(0);
			// 0-9 || A-Z || a-z || space(32) || #(35) || &(38) || *(42) || -(45) || .(46) || @(64) || _(95)
			if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 35) || (hh == 38) || (hh == 42) || (hh == 45) || (hh == 46) || (hh == 64) || (hh == 95))
			{
			}
			else {
				
				if (formname == "bibform") {
					window.alert("The User ID contains an invalid character. You are being re-directed to Business Internet Banking log in page. We apologize for the inconvenience. Please re-enter your User ID.");
					location.href=bebURL;
				}
				else if (formname == "cebform") {
					window.alert("The User ID contains an invalid character. You are being re-directed to the Internet Banking logon page. Please re-enter your User ID and Password when prompted. We apologize for any inconvenience.");
					location.href=cebURL;

				}
				return false;
			}
		}

		//Validate that the password doesn't contain special characters, only alphanumeric
		var numaric = formHandle.password.value;
		for(var j=0; j<numaric.length; j++)
		{
			var alphaa = numaric.charAt(j);
			var hh = alphaa.charCodeAt(0);
			// 0-9 || A-Z || a-z || space(32) || #(35) || &(38) || *(42) || -(45) || .(46) || @(64) || _(95)
			if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 35) || (hh == 38) || (hh == 42) || (hh == 45) || (hh == 46) || (hh == 64) || (hh == 95))
			{
			}
			else {
				
				if (formname == "bibform") {
					window.alert("The User ID and/or Password contain an invalid character. Re-directing to Business Internet  Banking log in page. We apologize for the inconvenience. Please re-enter your User ID and Password.");
					location.href=bebURL;
				}
				else if (formname == "cebform") {
					window.alert("The User ID and/or Password contains an invalid character. You are being re-directed to the Internet Banking logon page. Please re-enter your User ID and Password when prompted. We apologize for any inconvenience.");
					location.href=cebURL;
				}
				return false;
			}
		}
		//return true;
		// call coremetrics tags
		if (formname == "bibform") {
		 	cmCreateConversionEventTag("LOGIN TO BEB",2,"LOGIN",null);
		}
		else if (formname == "cebform") {
			cmCreateConversionEventTag("LOGIN TO CEB",2,"LOGIN",null);
		}
	 	cmCreatePageviewTag('POL-HOME','1001',null,null,cm_customer_id);
		// end coremetrics continue submitting form
		//****** Submit Form ******
		//****** Submit Form ******
		formHandle.submit();
		
		return true;
	
	}//end gotoSubmit

	function clearRequiredFieldsInnerHTML(formname) 
	{
		var requiredArray = getRequiredArray(formname);
		
		for(var x=0; x<requiredArray.length; x++)
		{ 
			var arrayItem = "error_" + requiredArray[x];

			document.getElementById(arrayItem).innerHTML = getClearRequired(requiredArray[x]);
		}//end for
		
	}

//	function clearRequiredFieldsInnerHTML(formname) 
//	{
//		var requiredArray = getRequiredArray(formname);
//		
//		for(var x=0; x<requiredArray.length; x++)
//		{ 
//			var arrayItem = "error_" + requiredArray[x];
//
//			alert("************** clearRequiredFieldsInnerHTML arrayItem = " + arrayItem);		
//
//			document.getElementById(arrayItem).innerHTML = getClearRequired(requiredArray[x]);
//		}//end for
//		
//	}
			
	function general_check_required(formHandle, transferType)
	{	
		//text fields only
		var stringHandler = formHandle[transferType].value;
				
		if( stringHandler == "" || stringHandler == null || stringHandler == "USER ID" || stringHandler == "COMPANY ID")
			return false;
		return true;
	}
