﻿var currentStat = 'reset';
var baseJuris = 'WY';

function resizeFrame(){    
	if(currentStat == 'reset'){
		maximize();
	}else if(currentStat == 'max'){
		reset();
	}else{
		parent.location.reload();
	}
}


function clickButton(e, buttonid) {

    var evt = e ? e : window.event;
    if (e.srcElement.type != "submit") {
        if (e.srcElement.type != "textarea") {
            if (e.srcElement.href == null) {
                if (buttonid) {
                    if (evt.keyCode == 13) {
                        evt.keyCode = 0;
                        buttonid.click();
                        return false;
                    }
                }
            }
        }
    }
}


function reset(winName){
	var bodyFrameset = parent.document.getElementById('body');
	bodyFrameset.cols="240px,*";
	currentStat='reset';
}
     
var counter=0;
function countClick()
{
    counter++;
    if(counter > 1)
    {       
       alert('Please Wait.....The server is processing your previous request.');       
       return false;    
    }
     return true;
}

function assignTabIndex() {
   if (getBrowser()=='IE') {
       var numberForms = document.forms.length;
       var formIndex,elIndex;
       document.body.tabIndex = 1;
       for (formIndex = 0; formIndex < numberForms; formIndex++)
       {
           //alert(document.forms[formIndex].name);
           elIndex = document.forms[formIndex].length;
           for (elmIndex = 0; elmIndex < elIndex; elmIndex++)
           {
		       var obj =  document.forms[formIndex].elements[elmIndex];
		       //alert(obj.name+"..."+obj.disabled+"...."+obj.readOnly)		       
		       if(obj.disabled || obj.readOnly)
		         obj.tabIndex=-1;
		       else
			     obj.tabIndex = 1;
//               document.forms[formIndex].elements[elmIndex].tabIndex = 1;
           }
    
       }    
       var numberLinks = document.links.length;
       for (formIndex = 0; formIndex < numberLinks; formIndex++)  {
           if (((document.links[formIndex].parentNode.tagName == "TH") || (document.links[formIndex].parentNode.tagName == "TD")) && (document.links[formIndex].target != "WAS_help")) {
                document.links[formIndex].tabIndex = 1;
           }    
       }
   }
}
function checkMaxLength(e, el) {
    switch (e.keyCode) {
        case 37: // left
            return true;
        case 38: // up
            return true;
        case 39: // right
            return true;
        case 40: // down
            return true;
        case 8: // backspace
            return true;
        case 46: // delete
            return true;
        case 27: // escape
            el.value = '';
            return true;
    }
    return (el.value.length < el.getAttribute("TAMaxLength"));
}
function setLength(el) {
    if (el.value.length > el.getAttribute("TAMaxLength")) {
        el.value = el.value.substring(0, el.getAttribute("TAMaxLength"));
    }
}

function addDays(date, noOfDays) {
    dateArray = date.split('/');
    month = dateArray[0] * 1;
    day = dateArray[1] * 1;
    year = dateArray[2] * 1;
    day = day + noOfDays;
    var noOfDaysInAMonth = getNoOfDaysOfMonth(month, year);
    while (day > noOfDaysInAMonth) {
        month = month + 1;
        day = day - noOfDaysInAMonth;
        if (month > 12) {
            month = month - 12;
            year = year + 1;
        }
        noOfDaysInAMonth = getNoOfDaysOfMonth(month, year);
    }
    if (!isNaN(month) && !isNaN(year) && !isNaN(day) && month != undefined && year != undefined && day != NaN) {
        return pad(month.toString(), 2, '0', 1) + '/' + pad(day.toString(), 2, '0', 1) + '/' + year;
    }
    else {
        return '';
    }
}

var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

function pad(str, len, pad, dir) {

    if (typeof (len) == "undefined") { var len = 0; }
    if (typeof (pad) == "undefined") { var pad = ' '; }
    if (typeof (dir) == "undefined") { var dir = STR_PAD_RIGHT; }

    if (len + 1 >= str.length) {

        switch (dir) {

            case STR_PAD_LEFT:
                str = Array(len + 1 - str.length).join(pad) + str;
                break;

            case STR_PAD_BOTH:
                var right = Math.ceil((padlen = len - str.length) / 2);
                var left = padlen - right;
                str = Array(left + 1).join(pad) + str + Array(right + 1).join(pad);
                break;

            default:
                str = str + Array(len + 1 - str.length).join(pad);
                break;

        }
    }
    return str;
}

function getNoOfDaysOfMonth(month, year) {
    if (month == 1) {
        return 31;
    }
    else if (month == 2) {
        if (year % 4 == 0)
            return 29;
        else
            return 28;
    }
    else if (month == 3) {
        return 31;
    }
    else if (month == 4) {
        return 30;
    }
    else if (month == 5) {
        return 31;
    }
    else if (month == 6) {
        return 30;
    }
    else if (month == 7) {
        return 31;
    }
    else if (month == 8) {
        return 31;
    }
    else if (month == 9) {
        return 30;
    }
    else if (month == 10) {
        return 31;
    }
    else if (month == 11) {
        return 30;
    }
    else if (month == 12) {
        return 31;
    }
    else {
        return '  ';
    }
}


var signOutWarn = 0;
var moveToLogInPage = 0;
var TempMinutesToWarning = 0;
var TempMinutesBeforeLoggedOut = 0;

function resetSessionTime() {
    try {
        TempMinutesToWarning = parseInt(minutesToWarning);
    }
    catch (e) {
        TempMinutesToWarning = 478;
    }

    if (signOutWarn) {
        clearTimeout(signOutWarn);
    }
    if (moveToLogInPage) {
        clearTimeout(moveToLogInPage);
    }

    signOutWarn = setTimeout("signOutWarning()", TempMinutesToWarning * 60 * 1000);
    
}

function signOutWarning() {
    try {
        TempMinutesBeforeLoggedOut = parseInt(minutesBeforeLoggedOut);
    }
    catch (e) {
        TempMinutesBeforeLoggedOut = 2;
    }

    var currentTime = new Date();
    var expiredTime = new Date();
    var minutes = expiredTime.getMinutes();
    minutes += TempMinutesBeforeLoggedOut;
    expiredTime.setMinutes(minutes);

    moveToLogInPage = setTimeout("redirectToLoginPage", TempMinutesBeforeLoggedOut * 60 * 1000);

    var answer = confirm("If you want to continue the session click OK, otherwise click CANCEL\nCurrent Time :" + currentTime + "\nApproximate Time left for time out : " + TempMinutesBeforeLoggedOut + " min");
    if (answer) {
        currentTime = new Date();
        if (currentTime > expiredTime) {
            redirectToLoginPage();
        }
        else {
            increaseTimeoutTime();
            resetSessionTime();
        }
    }
    else {
        redirectToLoginPage();
    }
}

function increaseTimeoutTime() {
    var button = document.getElementById("btnTimeOut");
    button.click();
}

function redirectToLoginPage() {
    alert("Your session time could not be increased");
    window.location = loginUrl;
}
function clickButton(e, buttonid) {

    var evt = e ? e : window.event;
    if (e.srcElement.type != "submit") {
        if (e.srcElement.type != "textarea") {

            if (e.srcElement.href == null) {
                if (buttonid) {
                    if (evt.keyCode == 13) {
                        evt.keyCode = 0;
                        buttonid.click();
                        return false;
                    }
                }
            }
        }
    }
}
var newwindow;
function openInPopup(url) {
    var widthIs = (parseInt(screen.width) - 20);
    var heightIs = (parseInt(screen.height) - 80);
    try {
        closePopUpIfExit(url);
    }
    catch (err) {
    }
    //newwindow = window.open(url, 'Inquiry', 'height=' + window.screen.availHeight + ',width=' + window.screen.availWidth + ',scrollbars=yes,status=yes,left=0,top=0, toolbar=no,menubar=no,location=center,resizable=yes', true);
    newwindow = window.open(url, 'Inquiry', 'height=630,width=865,scrollbars=yes,status=yes,left=100,top=20, toolbar=no,menubar=no,location=center,resizable=yes', true);
    

    //    setTimeout('newwindow.focus();', 250);
}

function closePopUpIfExit(url) {
    try {
        if (window.parent.opener == null) {
            for (i = 1; i < 4; i++) {
                if (parent.frames[i].newwindow != null) {
                    parent.frames[i].newwindow.close();
                } else {
                    var widthIs = (parseInt(screen.width) - 20);
                    var heightIs = (parseInt(screen.height) - 80);
                    newwindow = window.open(url, 'Inquiry', 'height=630,width=865,scrollbars=yes,status=yes,left=100,top=20, toolbar=no,menubar=no,location=center,resizable=yes', true);
                    newwindow.close();
                    break;
                }
            }
        }
    }
    catch (e) {
    }
}

function uncheckOthers(id) {
    var elm = document.getElementsByTagName('input');
        for (var i = 0; i < elm.length; i++) {
        if (elm.item(i).id.substring(id.id.lastIndexOf('_')) == id.id.substring(id.id.lastIndexOf('_'))) {
            if (elm.item(i).type == "checkbox" && elm.item(i) != id)
                elm.item(i).checked = false;
        }
    }
}

function popupCheck() {

    var windowTest;
    var i = new RegExp('object', 'gi');

    var divTag = document.getElementById("popup-check");
    try {
        windowTest = window.open('', 'child', 'width=1,height=1,status=no,resizable=yes');
        windowTest.close();
    }
    catch (e) { }

    if (!i.test(String(windowTest))) {
        divTag.innerHTML = '<b>Warning:</b> A pop-up blocker is enabled for this site! System requires pop-up blocker to be disabled ' +
            'in order to function properly. Please disable your pop-up blocker. <br><b>Open Link in a New tab for instructions on how to disable the popup blocker:<br></b> ' +
            '>> IE users can <a href="http:\/\/windows.microsoft.com\/en-US\/windows-vista\/Internet-Explorer-Pop-up-Blocker-frequently-asked-questions" target="_blank">Click here<\/a> to select various options. <br>' +
            '>> Firefox users can <a href="http:\/\/support.mozilla.com\/en-US\/kb\/pop-up%20blocker" target="_blank">Click here<\/a> to select various options.';
    }
}
