﻿// JScript File

//Sumit Rekhi ----  7/30/2009 ----- C-Support # 971A1A1751 - Changes for self swith date.User can choose the date he want to swith



function textToDate(s) {

    // parse s for month, day, year

    var dateArray = s.split('/');

    sdate = new Date(dateArray[2],dateArray[0]-1,dateArray[1]);

    return sdate;

}//end textToDate

 

//get the difference in days between two date objects

function timeDifference(laterdate,earlierdate) {

    var difference = laterdate.getTime() - earlierdate.getTime();

 

    var daysDifference = Math.floor(difference/1000/60/60/24);

    difference -= daysDifference*1000*60*60*24

    var hoursDifference = Math.floor(difference/1000/60/60);

    difference -= hoursDifference*1000*60*60

    var minutesDifference = Math.floor(difference/1000/60);

    difference -= minutesDifference*1000*60

    var secondsDifference = Math.floor(difference/1000);

 

            return daysDifference;

    //document.write('difference = ' + daysDifference + ' day/s ' + hoursDifference + ' hour/s ' + minutesDifference + ' minute/s ' + secondsDifference + ' second/s ');

}//end timeDifference

 

//check for a valid date

/**

 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

 */

// Declaring valid date character, minimum year and maximum year

var dtCh= "/";

var minYear=1900;

var maxYear=2100;

 

function isInteger(s){

            var i;

    for (i = 0; i < s.length; i++){   

        // Check that current character is number.

        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;

    }

    // All characters are numbers.

    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++){   

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}

 

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 DaysArray(n) {

            for (var i = 1; i <= n; i++) {

                        this[i] = 31

                        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}

                        if (i==2) {this[i] = 29}

   } 

   return this

}

 

function isDate(dtStr){

            var daysInMonth = DaysArray(12)

            var pos1=dtStr.indexOf(dtCh)

            var pos2=dtStr.indexOf(dtCh,pos1+1)

            var strMonth=dtStr.substring(0,pos1)

            var strDay=dtStr.substring(pos1+1,pos2)

            var strYear=dtStr.substring(pos2+1)

            strYr=strYear

            if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

            if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

            for (var i = 1; i <= 3; i++) {

                        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)

            }

            month=parseInt(strMonth)

            day=parseInt(strDay)

            year=parseInt(strYr)

            if (pos1==-1 || pos2==-1){

                        alert("The date format should be : mm/dd/yyyy")

                        return false

            }

            if (strMonth.length<1 || month<1 || month>12){

                        alert("Please enter a valid month")

                        return false

            }

            if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){

                        alert("Please enter a valid day")

                        return false

            }

            if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

                        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)

                        return false

            }

            if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){

                        alert("Please enter a valid date")

                        return false

            }

return true

}



//end generic date functions

 

 

/******************************************************

            Function: autoTabKeyPress

            Purpose:  auto tabs to next field

            Inputs:   form object, event, max value of 

                                                field before tabbing, field to set focus on

            Returns:  n/a

            *******************************************************/              

             

            function autoTabKeyPress(what,e,max,action) {

                        var strUserAgent = navigator.userAgent.toLowerCase(); 

                        var isNS6 = document.getElementById && (navigator.appName=="Netscape")?true:false;

            var isNS7 = strUserAgent.indexOf("netscape/7.0") > -1;

              if (isNS6 || isNS7) {

                                                if (e.target.value.length >= max)

                                                            eval(action);

                                    }

                                    else if (document.all) {

                                                if (what.value.length > (max-1))

                                                            eval(action);

                                                            

                                    }

                        }

 

 

/****************************************

 

 

Function to populate esiid field


*/
//switch hold
//Populate esiid and address fields when a user confirms their address - validate correct information as well
function addesiid(esiidValue, esiidControl, completeAddressValue, streetControl, aptUnitControl, cityControl, hiddenEsiidControl, hiddenAddressControl, hiddenZipControl, hidZip5Control, streetValue, aptUnitValue, cityValue, zipValue, isDunsMatch, dunsValue, TDSPvalue, confirmMsgControl, isTampered, strMoveinSwitch, premiseTypeValue)
{

//alert(premiseTypeValue.replace(/^\s*|\s*$/g,""));
    //Ensure the selected item is a residential premises
    if(premiseTypeValue.replace(/^\s*|\s*$/g,"") != "RESIDENTIAL") //the .replace trims white space off the ends
    {
        var resResponse = confirm("You have selected address: " + completeAddressValue + "\nOur records show that this is not a residence.\n\nPlease click 'OK' to confirm that this is the correct service address or press cancel to correct your service address.");
        
        //Redirect to call center screen if user confirms that the non-residence esiid is correct
        if(resResponse)
        {
            window.location = "contact_enrollment.aspx";
        }//end if
        else
        {
            return false;
        }//end else
    }//end if
    
    //End Ensure the selected item is a residential premises
    
    //Ensure the user selected an esiid from the correct TDSP for their selected product
    else if(isDunsMatch == "true")
    {
        var answer = confirm("You have selected address: " + completeAddressValue + "\nPlease click 'OK' to confirm that this is the correct service address.");

        //If the user confirms their address / esiid
        if(answer)
        {
            //get the controls for the esiid and address fields
            var esiidval = document.getElementById(esiidControl);
            var street = document.getElementById(streetControl);
            var unit = document.getElementById(aptUnitControl);
            var city = document.getElementById(cityControl);
            var confirmMsg = document.getElementById(confirmMsgControl);
            var hidEsiidval = document.getElementById(hiddenEsiidControl);
            var hidStreetAddress = document.getElementById(hiddenAddressControl);
            var hidZipval = document.getElementById(hiddenZipControl); //Full zip from ercot including plus 4 if available
            var hidZipValFirstFive = document.getElementById(hidZip5Control); //Only the first 5 digits of the zip from ercot
            
            //Assign the values to the controls
            esiidval.value = esiidValue;
            street.value = streetValue;
            unit.value = "";//aptUnitValue;
            city.value = cityValue;
            confirmMsg.innerHTML = "";
            hidEsiidval.value = esiidValue;
            hidStreetAddress.value = streetValue;
            hidZipval.value = zipValue;
            hidZipValFirstFive.value = zipValue.substring(0,5);
            
            //Make the address and esiid fields read-only so the user cannot change their
            //  address selection after choosing an esiid from the grid
            street.readOnly = true;
            street.className = "weasiTDReadonly";
            
            unit.readOnly = true;
            unit.className = "weasiTDReadonly";
            
            city.readOnly = true;
            city.className = "weasiTDReadonly";
            
            esiidval.readOnly = true;
            esiidval.className = "weasiTDReadonly";

            //hide the esiid selector grid
            //var lookupwindow = document.getElementById('esiidaddress');
            //lookupwindow.style.display = "none";
            //switch hold
            if (isTampered == "Y") {
                if (strMoveinSwitch == "MOVEIN")
                    window.location = "contact_enrollment.aspx?qs=sh";
                else if (strMoveinSwitch == "SWITCH")
                    window.location = "contact_enrollment.aspx?qs=shswitch";
            }

         }//end if

         else

             return false;
     }//end if duns match is true
     
     //The user selected an esiid from a non matching tdsp for their selected product
     //Redirect the user back to the product selection screen
     else
     {
        var reply = confirm("We're sorry, but the pricing we provided you earlier was based upon your selection earlier.\nBased upon your service address we have identified that you are served by " + TDSPvalue + ".\n\nPress OK to be redirected to the list of plans that are available at your service address or press cancel to correct your service address.");
        
        if(reply)
        {
            window.location = "new_switch.aspx?wrongTDSP=true&correctDuns=" + dunsValue; 
        }//end if
        else
        {
            return false;
        }    
     }//end else duns match is false

}//end addesiid



function fill_billing(s_street,s_apt,s_city,s_state,s_zip,b_street,b_apt,b_city,b_state,b_zip,cb_name)

{

    debugger;           
if(document.getElementById(cb_name).checked)

            {

 

            
document.getElementById(b_street).value = document.getElementById(s_street).value;

document.getElementById(b_apt).value = document.getElementById(s_apt).value;

document.getElementById(b_city).value = document.getElementById(s_city).value;

document.getElementById(b_state).value = document.getElementById(s_state).value;

document.getElementById(b_zip).value = document.getElementById(s_zip).value;

 

 

 

            }

            else

            {

                        document.getElementById(b_street).value = "";

                        document.getElementById(b_apt).value = "";

                        document.getElementById(b_city).value = "";

                        document.getElementById(b_state).value = "";

                        document.getElementById(b_zip).value = "";

 

            }


}

function fill_billingEnroll(s_street, s_apt, s_city, s_state, s_zip, b_street, b_apt, b_city, b_state, b_zip, cb_name) {

    debugger;
    if (document.getElementById(cb_name).checked) {

        document.getElementById(b_street).value = s_street;

        document.getElementById(b_apt).value = s_apt;

        document.getElementById(b_city).value = s_city;

        document.getElementById(b_state).value = s_state;

        document.getElementById(b_zip).value = s_zip;

    }

    else {

        document.getElementById(b_street).value = "";

        document.getElementById(b_apt).value = "";

        document.getElementById(b_city).value = "";

        document.getElementById(b_state).value = "";

        document.getElementById(b_zip).value = "";



    }





}


function checkEnter(e,button){

var characterCode

            var zbutton

             if(e && e.which){

             e = e

             characterCode = e.which

             }

             else{

             e = event

             characterCode = e.keyCode

             }          

             if(characterCode == 13){

            zbutton= document.getElementById(button);

            zbutton.click();

             return false

             }

return true

            

}

 
 //debugger;
//7/30/2009  C-Support # 971A1A1751 - Changes for self swith date.User can choose the date we want to swith

function setcheckbox(i)
{
 
 var chkmov=document.getElementById(i);
 if(chkmov!=null)
 {
 chkmov.checked=false;
 chkmov.disabled = true;
 }
}

function checkswicth(i,j)
{ 
 var chkmovin=document.getElementById(i);
 var textboxmovin=document.getElementById(j); 
  if(chkmovin!=null)
  {
      if(chkmovin.checked)
      {
       textboxmovin.style.display='';
      }
      else
      {
       textboxmovin.style.display='none';
      }
  }
} 

function changeval(i,j)

{
 var movestatus=document.getElementById(i);
 movestatus.style.display='';
 var moveswitch= document.getElementById(j);
 if(moveswitch!=null)
 moveswitch.style.display='none';
}

 

function changeval2(i,j)

{
 var movestatus=document.getElementById(i);
 if(movestatus!=null)
 {
  movestatus.style.display='none';
  var moveswitch= document.getElementById(j);
 }
 if(moveswitch!=null)
 moveswitch.style.display='none';
}

 

function disableenable(i,j,k)
//C-Support # 971A1A1751 - Changes for self swith date.User can choose the date he want to swith
{
    var chkMovin = document.getElementById(k);
    chkMovin.disabled = false;
    var currentprovider=document.getElementById(i);
    currentprovider.disabled = false;
    var movedatefield=document.getElementById(j);
    movedatefield.value = '';

}

 

function disableenable2(i,j,k)

{
 var currentprovider=document.getElementById(i);
 currentprovider.disabled = true;
 var chkMovin=document.getElementById(j);
 chkMovin.checked=false;
 chkMovin.disabled = true
 var swithdatefield=document.getElementById(k);
 if(swithdatefield!=null)
 {
  swithdatefield.value = '';
 }
}

 

function checkmovedate(i, dateMessage)
{
        
    var movedate=document.getElementById(i);

    //if(document.aspnetForm.ctl00$Content$SpecialControl$service_type[1].checked)
    if(document.aspnetForm.ctl00$ContentPlaceHolder1$Enrollment1$service_type[1].checked)
    {
        if(movedate.style.display!='none')
        {
            if(movedate.value == '')
            {
                alert('Please enter a move-in date! ie. 01/01/2007');
                document.getElementById(dateMessage).innerHTML = "* Please enter a move in date";
                //movedate.focus();
                return false;
            }
            else if(isDate(movedate.value) == false)
            {
                document.getElementById(dateMessage).innerHTML = "* Please enter a valid date (mm/dd/yyyy)";
                return false;
            }//end else
        }
    }//end if
}//end checkmovedate

//debugger;
// C-Support # 971A1A1751 - Changes for self swith date.User can choose the date he want to swith
function checkswichdate(i, dateMessage)
{
        
    var switchdate=document.getElementById(i);
    //var ddlcurrentprovider = document.getElementById(k);
    //if(document.aspnetForm.ctl00$Content$SpecialControl$service_type[1].checked)
    if(document.aspnetForm.ctl00_ContentPlaceHolder1_Enrollment1_chkSwitchDate.checked)
    {
        if(switchdate.value == '')
        {
            alert('Please enter a switch date! ie. 01/01/2007');
            document.getElementById(dateMessage).innerHTML = "* Please enter a switch date";
           
            //switchdate.focus();
            return false;
        }
        else if(isDate(switchdate.value) == false)
        {
            document.getElementById(dateMessage).innerHTML = "* Please enter a valid date (mm/dd/yyyy)";
            //ddlcurrentprovider.disable="false";
            return false;
        }//end else
        
    }//end if
}//end checkmovedate

//C-Support # 971A1A1751 - Changes for self swith date.User can choose the date he want to swith
//debugger;
function enableconfirm(i, labelTOSmsg, checked)

{
    var cb = document.getElementById(i);
    var tosMsg = document.getElementById(labelTOSmsg);

    cb.disabled = !checked;

    //Change button image / notification text based upon checked status
    if(checked)
    {
        cb.src='../Images/button_confirm_enrollment.jpg';
        if(tosMsg!=null)
        tosMsg.innerHTML = '';
    }
    else
    {

        cb.src='../Images/button_confirm_enrollment_disabled.jpg'
         if(tosMsg!=null)
        tosMsg.innerHTML = 'Please agree to the Terms of Service by checking the box above.';
    }//end else



}//end enableconfirm


//Toggles enabled state of all items in a given div (or other parent container control)

    function toggleDisabledDivItems(myDivControl) {
        
        var el = myDiv;
    
        try {
            el.disabled = el.disabled ? false : true;
        }//end try
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                toggleDisabledDivItems(el.childNodes[x]);
            }//end for
        }//end if
    }//end toggleDisabledDivItems
    
    
    function disableDivItems(myDivControl) {
        
        var el = myDivControl;
    
        try {
            el.disabled = true;
        }//end try
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                disableDivItems(el.childNodes[x]);
            }//end for
        }//end if
    }//end disableDivItems
    
    
    function enableDivItems(myDivControl) {
        
        var el = myDivControl;
    
        try {
            el.disabled = false;
        }//end try
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                enableDivItems(el.childNodes[x]);
            }//end for
        }//end if
    }//end enableDivItems


//End toggles enabled state of all items in a given div


//Change control size

//Given a control ID, height, width - set the dimensions of that control appropriately
function changeControlDimensions(ctrl, width, height)
{
    alert(ctrl + " " + width + " " + height);
    var myControl = document.getElementById(ctrl);
    alter(myControl);
    
    myControl.style.height = height;
    myControl.style.width = width;

}//end

//End change control size

