﻿var gdws_sessionTimerInterval = 3300000;
var gdws_doSessionWarning = true;
var gdws_logoutUrl;
var gdws_sessionTimer = setTimeout('WarnSessionExpiring()', gdws_sessionTimerInterval);
var gdws_sessionResetUrl;

function WarnSessionExpiring(){
	if(gdws_doSessionWarning){
		if(confirm("Your session is about to expire.\n\nClick 'OK' to keep your session active.\n\nClick 'Cancel' to let your session expire.")){
			processXMLHttp(resetSessionTimer,null,gdws_sessionResetUrl,null,false);
		}else{
			location.href = gdws_logoutUrl;
		}
	}
}

function resetSessionTimer(){
	gdws_sessionTimer = setTimeout('WarnSessionExpiring()', gdws_sessionTimerInterval);
}

function gO(id)
{
	return document.getElementById(id);
}

function enterKeyPress(e, oFunction)
{
	if(!e.which){
		theKey = e.keyCode;
	}else{
		theKey = e.which;
	}
	if(theKey==13){
		if (e && e.preventDefault){
			e.preventDefault();
		}else{
			e.returnValue = false;
		}
		return oFunction();
	}
}

function doValidationFail(alertString, input){
	alert(alertString);
	try{
		input.select();
		input.focus();
	}catch(err){}
	return false;
}

function checkRequiredString(o, alertstr, length){
	if(o){
		if(o.value == '' || o.value == 'undefined')
			return doValidationFail(alertstr, o);
		if(length && !isNaN(toNumber(length))){
			if(o.value.length < length)
				return doValidationFail(alertstr, o);
		}
		return true;
	}
	return doValidationFail(alertstr, o);
}

function HasSpecialChars(StringToSearch)
{
    var re = /[!"$%&'()*+/:;<=>?@[\\\]_`{|}~]/;
    if (StringToSearch.search(re) > -1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checkSSN(oSSNInput, bChangeAlert)
{
  var sNewSSN = oSSNInput.value.replace(/-/g,'');
  if(sNewSSN != ''){
    //var re = /^\d{3}-?\d{2}-?\d{4}$/;
    var re = /(?!000)(?!666)([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(?!00)(\d{2})\2(?!0000)(\d{4})/;
    
    if((sNewSSN.search(re)==-1) || (Number(sNewSSN)<1) || (Number(sNewSSN)>791999999) || (Number(sNewSSN) == 111111111) || (Number(sNewSSN) == 222222222) || (Number(sNewSSN) == 333333333) || (Number(sNewSSN) == 444444444) || (Number(sNewSSN) == 555555555) || (Number(sNewSSN) == 666666666) || (Number(sNewSSN) == 777777777) || (Number(sNewSSN) == 888888888) || (Number(sNewSSN) == 999999999)){
      alert('Please enter a valid social security number.');
      oSSNInput.select();
      oSSNInput.focus();
      return false;
    }else{
		oSSNInput.value = sNewSSN;
		if(bChangeAlert)
			doChangeAlert("If this SSN has previously been filed with our Department,\nyou will also need to file an ammended return.\n\nA link will be provided at the end of this quarter\'s filing\nprocess.");
		return true; 
    }
  }else{
    oSSNInput.value = sNewSSN;
    if(bChangeAlert)
		doChangeAlert("If this SSN has previously been filed with our Department,\nyou will also need to file an ammended return.\n\nA link will be provided at the end of this quarter\'s filing\nprocess.");
    return true;
  }
}

function formatZipCode(oZipInput){
	if(checkZipCode(oZipInput)){
		var s = oZipInput.value;
		if(s.search(/^\d{9}$/) != -1)
			oZipInput.value = s.substr(0, 5) + "-" + s.substr(5);
	}else{
		alert(oZipInput.value + " is not a valid zip code. Please enter a valid zip code.");
		oZipInput.select();
		oZipInput.focus();
	}
}

function checkZipCode(oZipInput){
	if(oZipInput.value.search(/^\d{5}$/) == -1 && oZipInput.value.search(/^\d{5}-?\d{4}$/) == -1){
		return false;
	}else{
		return true;
	}
}

function clearInitialDate(o){
	if(o.value == "mm/dd/yyyy")
		o.value = "";
	o.select();
	o.focus();
}

function checkDate(oDateInput){
	return(isValidDate(oDateInput.value));
}

function isValidDate(sDate){
	var re = /^(1[0-2]|[1-9]|0[1-9])\/{1}([1-2]?[0-9]|0[1-9]|3[0-1])?\/?\d{4}$/
	if(sDate.search(re)==-1)
		return false;
	var oDate = new Date(sDate)
	var aDate = sDate.split('/')
	var iDay = oDate.getDate()
	var iDayEntered = aDate[1] * 1
	if(iDay - iDayEntered != 0){
		return false;
	}else{
		return true;
	}
}

function formatDate(o){
	var s = o.value;
    if (s.length == 6)
	{
	    s = fixSixDigits(s);
	}
	s = insertSlashes(s);
	if(s.search(/\/\d{2}$/) != -1)
		s = fixTwoDigitYear(s);
	if(s != null && s.length > 0){
		if(isValidDate(s)){
			var d = new Date(s);
			if(!isNaN(d))
				s = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
			o.value = s;
		}else{
			alert(o.value + " is not a valid year.\nPlease enter a valid date");
			o.select();
			o.focus();
		}
	}
}
function fixSixDigits(SixDigitDate)
{
    var year = SixDigitDate.substr(4,2);
    if (toNumber(year) <= 30)
    {
       year  = '20' + year 
    }
    else
    {
        year  = '19' + year 
    }	    
    return SixDigitDate.substr(0,4) + year;
}
function insertSlashes(sDate){
	sDate = sDate.replace(/\./g, "/");
	sDate = sDate.replace(/\-/g, "/");
	if(sDate.search(/\-/) == -1){
		var s = sDate;
		if(sDate.search(/^\d{8}$/) != -1){
			sDate = s.substr(0,2) + "/" + s.substr(2,2) + "/" + s.substr(4);
		}
	}
	return sDate;
}

function fixTwoDigitYear(s){
	var d = new Date(s);
	var t = new Date()
	var tyear = String(t.getFullYear()).substr(1);
	var r = "";
	if(!isNaN(d)){
		var y = d.getYear();
		var year = String(y);
		if(year.length < 2)
			year = "0" + year;
		
		// anything over 30 will default to year 19XX, anything under 30 will default to year 20XX
		y <= 30 ? year = "20" + year : year = "19" + year;
		r = (d.getMonth() + 1) + "/" + d.getDate() + "/" + year;
	}
	return r;
}

function doChangeAlert(sThis){
  alert(sThis);
  //document.forms.frmThis['NotifyAmmended'].value = "yes";
}

function hov(loc,cls){
	if(loc.className)
		loc.className=cls;
}

function writeCookie(name, value, expires) {
  var today = new Date();
  today.setTime(today.getTime());
  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() : "" );
}

function deleteCookie(name) {
  if (getCookie(name)) document.cookie = name + "=" +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function readCookie(name){
	var a = document.cookie.split(";");
	for(i = 0; i < a.length; i++){
		o = a[i].split("=");
		if(o[0] == name){
			return o[1];
		}
	}
}

function getQueryStringValue(name){
	var result;
	var q = window.location.search;
	if(q)
	{
		q = q.substring(1);
		var a = q.split("&");
		for(i = 0; i < a.length; i++)
		{
			o = a[i].split("=");
			if(o[0].toLowerCase() == name.toLowerCase())
			{
				result = decodeURIComponent(o[1]);
			}
		}
	}
	return result;
}

function OpenWindow(sURL, sWindowName, bToolbar, bScrollBars, lWidth, lHeight, lTop, lLeft) {
    if(typeof lTop == 'undefined') {
	    lTop = (screen.height - lHeight) / 2
    }
    if(typeof lLeft == 'undefined') {
	    lLeft = (screen.width - lWidth) / 2
    }
    if(bToolbar == true){
	    bToolbar = 'yes'
    }else{
	    bToolbar = 'no'
    }
    if(bScrollBars == true){
	    bScrollBars = 'yes'
    }else{
	    bScrollBars = 'no'
    }
    var lsFeatures = 'toolbar='+bToolbar+',menubar='+bToolbar+',location=no,scrollbars='+bScrollBars+',resizable=yes,status=yes';	
    lsFeatures += ',top='+ lTop
    lsFeatures += ',left='+ lLeft
    if(lWidth > 0){lsFeatures += ',width='+lWidth};
    if(lHeight > 0){lsFeatures += ',height='+lHeight};
    popupWin = window.open(sURL, sWindowName, lsFeatures);
    popupWin.focus();
}

function toNumber(s){
	return Number(String(s).replace(/[\$\,]/g,''))
}

function GetYCoord(e) 
{
    if (e.pageY) 
    {
        return e.pageY;
    }
    else if (e.clientY)
    {
        return e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    }
    else 
    {
        return null;
    }
}

function GetXCoord(e) 
{
    if (e.pageX) 
    {
        return e.pageX;
    }
    else if (e.clientX)
    {
        return e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    }
    else 
    {
        return null;
    }
}

function CheckForDollarsAmounts(e)
{
    var currentKeyPress;
    
    if(!e.which)
    {
		currentKeyPress = e.keyCode;
	}
	else
	{
	    currentKeyPress = e.which;
	}
	if ((currentKeyPress < 48 || currentKeyPress > 57)&&(currentKeyPress!=46)&&(currentKeyPress!=13)&&(currentKeyPress!=9)&&(currentKeyPress!=8))
	{
	    alert("Please enter numbers or decimal only.");
	    return false;
	}
}

function CheckForValidNumber(e)
{
    var currentKeyPress;
    
    if(!e.which)
    {
		currentKeyPress = e.keyCode;
	}
	else
	{
	    currentKeyPress = e.which;
	}
	if ((currentKeyPress < 48 || currentKeyPress > 57)&&(currentKeyPress!=13)&&(currentKeyPress!=9)&&(currentKeyPress!=8))
	{
	    alert("Please only enter numbers.  Do not enter decimals or cents.");
	    return false;
	}
}
function Trim(StringToTrim)
{
    return StringToTrim.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function UrlEncode(InputString)
{
    return escape(InputString).replace(/\+/g, "%2B").replace(/\+/g, "%2F");
}