﻿var defaultEmptyOK = false
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function isNull(strvalue)
{
    strvalue = strvalue.replace(/^\s+|\s+$/g, '');
    return strvalue;
}
function showError(lblName, strErrorMessage)
{
    document.getElementById(lblName).innerHTML = strErrorMessage;
}
function fnHandleTemplateImg(dvId){
    startTimeoutTimer();
    document.getElementById(dvId).innerHTML = '<img src="images/profile_pic.jpg" id="imgTemplate" />'
}
function validateEmail( VARIABLE) 
{

//var objRegExp  =/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
    result=new RegExp(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/); //Eg:  RegExp(/^\d{5,20}$/);
    if(result.test(VARIABLE))
    {
        return true;
    }
    return false;
}
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		    {
		    
		    }
		    else	
		    {
                //alert("Your Alpha Numeric Test Failed");
			    return false;
		    }
 		}
 //alert("Your Alpha Numeric Test Passed");
 return true;
}

function validatePassword(VARIABLE) 
{
//[a-zA-Z'.`-´\s]{1,40}
//^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$
//var objRegExp  =/(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
    result=new RegExp(/^^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/); //Eg:  RegExp(/^\d{5,20}$/);
    if(result.test(VARIABLE))
    {
        return true;
    }
    return false;
}

function fnCauseValidationFalse()
{
    PAGE_NAME = "";
}
function fnCauseValidationSele()
{
    PAGE_NAME = "SchNow_SelectServices";
}
function fnHandleBack()
{
    window.history.forward(+1); 
}
function fnHandleSearchPrefer()
{
    var chkSearchOptions_0 = document.getElementById('ctl00_chkSearchOptions_0');
    var chkSearchOptions_1 = document.getElementById('ctl00_chkSearchOptions_1');
    var chkSearchOptions_2 = document.getElementById('ctl00_chkSearchOptions_2');
    var chkSearchOptions_3 = document.getElementById('ctl00_chkSearchOptions_3');
    var chkSearchOptions_4 = document.getElementById('ctl00_chkSearchOptions_4');
    if (window.event.srcElement.id == "ctl00_chkSearchOptions_0")
    {
        chkSearchOptions_1.checked = false;
        chkSearchOptions_2.checked = false;
        chkSearchOptions_3.checked = false;
        chkSearchOptions_4.checked = false;
    }
    else if (chkSearchOptions_1.checked == true || chkSearchOptions_2.checked == true || chkSearchOptions_3.checked == true || chkSearchOptions_4.checked == true)
    {
        chkSearchOptions_0.checked = false;
    }
    
}
function validatePreferrSearch()
{
   // try{
        var spnSearchalert = document.getElementById('spnSearchalert');
        var txtSearch = document.getElementById('ctl00_txtSearch');
        var chkSearchOptions_0 = document.getElementById('ctl00_chkSearchOptions_0');
        var chkSearchOptions_1 = document.getElementById('ctl00_chkSearchOptions_1');
        var chkSearchOptions_2 = document.getElementById('ctl00_chkSearchOptions_2');
        var chkSearchOptions_3 = document.getElementById('ctl00_chkSearchOptions_3');
        var chkSearchOptions_4 = document.getElementById('ctl00_chkSearchOptions_4');
        
        if (isNull(txtSearch.value) == ""){
            showError('spnSearchalert', 'Please input a keyword for the search.')
            txtSearch.focus();
            return false;
        }
        if (chkSearchOptions_0.checked == false && chkSearchOptions_1.checked == false && chkSearchOptions_2.checked == false 
            && chkSearchOptions_3.checked == false && chkSearchOptions_4.checked == false){
            showError('spnSearchalert', 'Please select one search option.')
            return false;
        }
        PAGE_NAME = "";
        return true;
    //}
    //catch(err){alert('error')}
}

function checkFileExt(ctlFile, ext )
{
    var badName="", rx;
    ctlFile = ctlFile.toLowerCase();
    ext = ext.toLowerCase();

    rx=new RegExp("[^\.]\."+ ext +"\s*$", "i");
    ctlFile = ctlFile.replace(/^\s+/,'').replace(/\s+$/,''); 
          
    if( !rx.test(ctlFile) )
        badName+='\n\n' + ctlFile;
     
    if( badName)
        return "false";
}

function isFutureDate(gdate, emptyOK)
{
   
   var date = new String(gdate);
    var regd=new RegExp("/");
    if(!date.match(regd))
    {
	var array=new Array();
	array[0]=date.substring(0,2);
	
	array[1]=date.substring(2,4);
	array[2]=date.substring(4,date.length);
	date=array[0]+"/"+array[1]+"/"+array[2]
	gdate=date;
	}
	// Modified to use emptyOK - using form definition masks.
	if (isFutureDate.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (gdate=='//')) return true;
    else
    {
		if(isDate(0, 0, 0, gdate)!=false){
				var sValues = gdate.split("/") 
				Chkmonth=sValues[0]
				Chkday=sValues[1]
				Chkyear=sValues[2]
			} else {
				return false;
			}
		if (!Chkday || !Chkmonth || !Chkyear)
			return false;

		if (Chkyear/4 == parseInt(Chkyear/4))
			monthLength[1] = 29;

		if (Chkday > monthLength[Chkmonth-1])
			return false;

		monthLength[1] = 28;

		//var nowdateTime = document.getElementById('dateToday').value + " 23:59:59";
		var now = new Date();
        
		var dateToCheck = new Date();
		dateToCheck.setYear(Chkyear);
		dateToCheck.setMonth(Chkmonth-1);
		dateToCheck.setDate(Chkday);
		
		var checkDate = dateToCheck.getTime();
		
		//to check the Date to be greater than the Date 12/31/1800 
		
		var oldDate = new Date();
		oldDate.setFullYear(1800,11,31);
		
		if(Chkyear < 1800)
			return false;	
		
		var futureDate = (now <= checkDate);
		var pastDate = (now > checkDate);
		
		if(pastDate)
		{
			pastDate = (oldDate < checkDate);
		}
		
		return futureDate;
	}
}

function isPastDate(gdate, emptyOK)
{
   var date = new String(gdate);
    var regd=new RegExp("/");
    if(!date.match(regd))
    {
	var array=new Array();
	array[0]=date.substring(0,2);
	
	array[1]=date.substring(2,4);
	array[2]=date.substring(4,date.length);
	date=array[0]+"/"+array[1]+"/"+array[2]
	gdate=date;
	}
	// Modified to use emptyOK - using form definition masks.
	if (isPastDate.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (gdate=='//')) return true;
    else
    {
		if(isDate(0, 0, 0, gdate)!=false){
				var sValues = gdate.split("/") 
				Chkmonth=sValues[0]
				Chkday=sValues[1]
				Chkyear=sValues[2]
			} else {
				return false;
			}
		if (!Chkday || !Chkmonth || !Chkyear)
			return false;

		if (Chkyear/4 == parseInt(Chkyear/4))
			monthLength[1] = 29;

		if (Chkday > monthLength[Chkmonth-1])
			return false;

		monthLength[1] = 28;

		//var nowdateTime = document.getElementById('dateToday').value + " 23:59:59";
		var now = new Date();
        
		var dateToCheck = new Date();
		dateToCheck.setYear(Chkyear);
		dateToCheck.setMonth(Chkmonth-1);
		dateToCheck.setDate(Chkday);
		
		var checkDate = dateToCheck.getTime();
		
		//to check the Date to be greater than the Date 12/31/1800 
		
		var oldDate = new Date();
		oldDate.setFullYear(1800,11,31);
		
		if(Chkyear < 1800)
			return false;	
		
		var futureDate = (now <= checkDate);
		var pastDate = (now >= checkDate);
		
		if(pastDate)
		{
			pastDate = (oldDate < checkDate);
		}
		
		return pastDate;
	}
}

function isPastCurrentDate(gdate, emptyOK)
{
   
	// Modified to use emptyOK - using form definition masks.
	if (isPastDate.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (gdate=='//')) return true;
    else
    {
		if(isDate(0, 0, 0, gdate)!=false){
				var sValues = gdate.split("/") 
				Chkmonth=sValues[0]
				Chkday=sValues[1]
				Chkyear=sValues[2]
			} else {
				return false;
			}
		if (!Chkday || !Chkmonth || !Chkyear)
			return false;

		if (Chkyear/4 == parseInt(Chkyear/4))
			monthLength[1] = 29;

		if (Chkday > monthLength[Chkmonth-1])
			return false;

		monthLength[1] = 28;

		//var nowdateTime = document.getElementById('dateToday').value + " 23:59:59";
		var now = new Date();
        
		var dateToCheck = new Date();
		dateToCheck.setYear(Chkyear);
		dateToCheck.setMonth(Chkmonth-1);
		dateToCheck.setDate(Chkday);
		
		var checkDate = dateToCheck.getTime();
		
		//to check the Date to be greater than the Date 12/31/1800 
		
		var oldDate = new Date();
		oldDate.setFullYear(1800,11,31);
		
		if(Chkyear < 1800)
			return false;	
		
		var futureDate = (now <= checkDate);
		var pastDate = (now >= checkDate);
		
		if(pastDate)
		{
			pastDate = (oldDate < checkDate);
		}
		
		return pastDate;
	}
}

function isDate (year, month, day, FullDate){

  
    

	if(FullDate!=""){
	
         var date = new String(FullDate);
    var regd=new RegExp("/");
    if(!date.match(regd))
    {
	var array=new Array();
	array[0]=date.substring(0,2);
	
	array[1]=date.substring(2,4);
	array[2]=date.substring(4,date.length);
	date=array[0]+"/"+array[1]+"/"+array[2]
	FullDate=date;
	}	
	
		var sValues = FullDate.split("/") 
		month=Number(sValues[0])
		day=Number(sValues[1])
		year=sValues[2]
		}
// catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
	
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year, 10);
    var intMonth = parseInt(month, 10);
    var intDay = parseInt(day, 10);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    if (s == 0) return false;
    return ((s.length == 4));
}

function isMonth (s)
{if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = Number (s);
    return ((num >= a) && (num <= b));
}

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function fnShowHideHelp(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        document.getElementById(dvId).style.left = findPosX(ctlImg) + 7 + "px";
        document.getElementById(dvId).style.top = findPosY(ctlImg) + 14 + "px";
        document.getElementById(dvId).style.visibility = 'visible';
    }
    if (strAction == 'hide')
        document.getElementById(dvId).style.visibility = 'hidden';

    
}

function fnShowHideMaster(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        document.getElementById(dvId).style.left = findPosX(ctlImg) - 25 + "px";
        document.getElementById(dvId).style.top = findPosY(ctlImg) + 10 + "px";
        document.getElementById(dvId).style.visibility = 'visible';
    }
    if (strAction == 'hide')
        document.getElementById(dvId).style.visibility = 'hidden';
}
function fnShowHideMasterTellFriend(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        document.getElementById(dvId).style.left = findPosX(ctlImg) - 200 + "px";
        document.getElementById(dvId).style.top = findPosY(ctlImg) + 10 + "px";
        document.getElementById(dvId).style.visibility = 'visible';
    }
    if (strAction == 'hide')
        document.getElementById(dvId).style.visibility = 'hidden';
}

function fnShowHideMasterSessionLayer(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        setMaskSize(dvId);
        document.getElementById(dvId).style.visibility = 'visible';
        document.getElementById(dvId).style.display = 'block';
    }
    if (strAction == 'hide')
    {
        document.getElementById(dvId).style.visibility = 'hidden';
        document.getElementById(dvId).style.display = 'none';
    }
}

function fnShowHideMasterInsurance(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        document.getElementById(dvId).style.left = findPosX(ctlImg) + 5 + "px";
        document.getElementById(dvId).style.top = findPosY(ctlImg) + 8 + "px";
        document.getElementById(dvId).style.visibility = 'visible';
    }
    if (strAction == 'hide')
        document.getElementById(dvId).style.visibility = 'hidden';
}



function fnShowHideforall(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        document.getElementById(dvId).style.left = findPosX(ctlImg) - 155 + "px";
        document.getElementById(dvId).style.top = findPosY(ctlImg) + 10 + "px";
        document.getElementById(dvId).style.visibility = 'visible';
    }
    if (strAction == 'hide')
        document.getElementById(dvId).style.visibility = 'hidden';
}

function findPosX(obj)
  {
    //alert(obj.offsetParent)
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
            
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    
   // alert(curleft)
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    //alert(curtop)
    return curtop;
  }

        var sessionTimeout = 10; //length of time until logged out (minutes)
        var warningTime = 2; //length of time popup stays up for (minutes)
        //popup opens sessionTimeout minus warningTime minutes after the page is opened
        var thisTimer = null; //stop/start session timer
        var thisWarningTimer = null; //stop/start warning timer
        //var second = 0; //how long window has been open for (seconds)
        var howLong = 120; //how long to keep window open for (seconds)
        var tickerTimer = null // stop the timer also
        
        function startTimeoutTimer()
        {
           
            thisTimer = setTimeout("closeSession()", sessionTimeout * 60000);
            thisWarningTimer = setTimeout("popupAsk()", (sessionTimeout - warningTime) * 60000);
        }
        

        function refreshSession()
        {
            //ping server in iframe to restart session
            //refreshMe.document.location.href = "http://208.109.189.108:97/refreshsession1.aspx";
refreshMe.document.location.href = "https://www.preferr.net/ProvideriPreferr.aspx";
         
                //window.location = window.location;
            
            //restart timers
            clearTimeout(thisTimer);
            clearTimeout(thisWarningTimer);
            clearTimeout(tickerTimer);
            startTimeoutTimer();
            fnShowHideMasterSessionLayer(this, 'LayerSession', 'hide');
        }

        function closeSession()
        {
            //redirect to login page with logged out message
            document.location.href="https://www.preferr.net/Index.aspx";
        }

        function popupAsk()
        {
            //open popup window
            fnShowHideMasterSessionLayer(this, 'LayerSession', 'show');
            onPageOpen();
            //window.open('http://www.preferr.net/Popup.htm','Window', 'width=440, height=250, toolbar=no, scrollbars=no, resizable=no');
        }
        


        function onPageOpen()
        {
            //close page after howLong elapsed
            //var a = setTimeout("self.close()", howLong * 1000 + 1000);

            //run tick func every second
            tickerTimer = setInterval("tick()", 1000);
        }

        function tick()
        {
            //subtract one second
            howLong -= 1;
            var timeValue = "";
            var timeLeft = howLong //- second;

            //if at least a minute, parse number of minutes
            if ( timeLeft >= 60 )
            {
                timeValue = (timeLeft-(timeLeft % 60)) / 60 + " minute and ";
            }

            //append number of seconds
            timeValue += ( howLong % 60 ) + " seconds";

            //show message
            document.all['msg'].innerHTML = "There has been no server activity for an extended period of time.<BR>Your session will time out in " + timeValue + ".";

            window.focus();

        }

function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

function setMaskSize(dvId) {
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
	
	popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
	
		popWidth = theBody.scrollWidth;
	}
	gPopupMask = document.getElementById(dvId);
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = parseInt(popWidth, 10) - 10 + "px";
}

function stillHere()
{
    //resets timer on parent page and closes this window
    //window.opener.refreshSession();
    //window.close();
    refreshSession();
}

function goAway()
{
    //logout on parent page and close this window
   //window.opener.closeSession();
   closeSession();
   // window.close();
}

var decimalPointDelimiter = "."
function isFloat (s)

{   
    var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
     return true;
}

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function checkUSPhone (theField, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { 
		var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
		//if(theField.value.substring(0,1)==1){
		//	normalizedPhone=normalizedPhone.substring(normalizedPhone.length,1)
		//}
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return;
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
//	<attribute name="onfocus">this.value=stripCharsNotInBag(this.value, digits);</attribute>
//				<attribute name="onblur">checkUSPhone(this);</attribute>
    return returnString;
}

var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var digitsInUSPhoneNumber1 = 10;

function isUSPhoneNumber (s)
{   if (isEmpty(s))
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
       var normalizedPhone = stripCharsInBag(s, phoneNumberDelimiters)
    return (isInteger(normalizedPhone) && normalizedPhone.length == digitsInUSPhoneNumber1 && normalizedPhone!='0000000000')
}

function reformatUSPhone (USPhone)
{   
	if (USPhone.length <= 7)
		return (reformat (USPhone, "", 3, "-", 4 ))
	if (USPhone.length <= 10)
		return (reformat (USPhone, "", 3, "-", 3, "-", 4 ))
}

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}
function fnShowHideBlurr(ctlImg, dvId, strAction)
{
    if (strAction == 'show')
    {
        setMaskSize(dvId);
        document.getElementById(dvId).style.visibility = 'visible';
        document.getElementById(dvId).style.display = 'block';
        
    }
    if (strAction == 'hide')
    {
        document.getElementById(dvId).style.visibility = 'hidden';
        document.getElementById(dvId).style.display = 'none';
        
    }
    
    return false;
}