﻿// This function is used to redirect to online application pages
function careerApply(intID) {
    var strID = "hdnURL" + intID;
    var strURL = document.aspnetForm[strID].value;
    window.location.href = strURL;
}

// Leaving-Site Alert //
function exitWarning()  {
        var msg = "The link you selected is outside the WaterStone Bank website.\r\rClick <OK> if you would like to continue linking to the new page.\r\rClick <CANCEL> if you would like to stay in the WaterStone Bank website."
        return confirm(msg);
}

function exitWarningRedirect(ctrlObj)  {
	var msg = "The link you selected is outside the WaterStone Bank website.\r\rClick <OK> if you would like to continue linking to the new page.\r\rClick <CANCEL> if you would like to stay in the WaterStone Bank website."
	if(confirm(msg)) {
		window.location.href = ctrlObj;
	} else {
		// Do nothing
	}	
}

// Pop-up Window Function //
function openBrWindow(strURL,strName,strFeatures) {
  window.open(strURL,strName,strFeatures)
  self.name="main";
}

// This function is used to open calculators in new window
function openCalculator() {
    var strURL = document.aspnetForm.ctl00_ddlCalculators.value;
    if (strURL != "More") {
        location.reload(true);
        strURL = "calculators/" + strURL + ".html";
        newwindow = openBrWindow(strURL, "Calculator", "scrollbars=yes,resizable=yes,width=500,height=500");
        newwindow.focus();
    } else {
        // Do nothing (vb handler will redirect to resource center page)
    }
}

// This function returns an object's style properties
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

// This function is used to count the number of characters in a textbox
function toCount(entrance,exit,text,characters) {
  var entranceObj=getObject(entrance);
  var exitObj=getObject(exit);
  var length=characters - entranceObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable"> '+text+' </span>';
    entranceObj.value=entranceObj.value.substr(0,characters);
  }
  exitObj.innerHTML = text.replace("{CHAR}",length);
}


// Begin Phone Number Formatter //
var n;
var p;
var p1;

function fncFormatPhone(m){
	n=m.name;
	p1=m
	ValidatePhone()
}

function ValidatePhone(){
	p=p1.value
	if(p.length==3){
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
		document.form1.elements[n].value="";
		document.form1.elements[n].value=pp;
	}
	if(p.length>3){
		d1=p.indexOf('(')
		d2=p.indexOf(')')
		if (d2==-1){
			l30=p.length;
			p30=p.substring(0,4);
			p30=p30+")"
			p31=p.substring(4,l30);
			pp=p30+p31;
			document.form1.elements[n].value="";
			document.form1.elements[n].value=pp;
		}
	}
	if(p.length>5){
		p11=p.substring(d1+1,d2);
		if(p11.length>3){
			p12=p11;
			l12=p12.length;
			l15=p.length
			p13=p11.substring(0,3);
			p14=p11.substring(3,l12);
			p15=p.substring(d2+1,l15);
			document.form1.elements[n].value="";
			pp="("+p13+")"+p14+p15;
			document.form1.elements[n].value=pp;
		}
		l16=p.length;
		p16=p.substring(d2+1,l16);
		l17=p16.length;
		if(l17>3&&p16.indexOf('-')==-1){
			p17=p.substring(d2+1,d2+4);
			p18=p.substring(d2+4,l16);
			p19=p.substring(0,d2+1);
			pp=p19+p17+"-"+p18;
			document.form1.elements[n].value="";
			document.form1.elements[n].value=pp;
		}
	}
	setTimeout(ValidatePhone,100)
}

function testphone(obj1){
	p=obj1.value
	p=p.replace("(","")
	p=p.replace(")","")
	p=p.replace("-","")
	p=p.replace("-","")
	if (isNaN(p)==true){
		alert("Check phone");
		return false;
	}
}
// End Phone Number Formatter //

// Set variables are used for AddThis toolbar //
var addthis_config = { ui_cobrand: "<i>WaterStone Bank</i>", ui_header_color: "#ffffff", ui_header_background: "#3e647e", data_track_clickback: true }


