//Code Review Comments:Write description for every funtion.
var xmlHttp;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5") != -1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6") != -1) || (navigator.userAgent.indexOf("Opera/6") != -1)) ? 1 : 0;
//netscape, safari, mozilla behave the same 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

//Code Review Comments:Write description of the function
//This function opens login page from the home page by clicking on the Login hyperlink
//added new code here
function OpenLogin(userId) {
    if (userId == null || userId == "") {
        var mysurvey = dhtmlmodal.open("surveybox", "ajax", "Login.aspx", "", "width=393px,height=230px,resize=0,scrolling=0,center=1", "recal")
       
//    var returnvalue = window.showModalDialog("frmLogin.aspx", "", "dialogHeight:280px;dialogWidth:360px;status:0;center:Yes;toolbar:0;navigationURL=0");
//    if (returnvalue == 'Registration') {
//        window.location.href = "frmregForm.aspx";
//    }
//    if (returnvalue == 'success') {
//        window.location.href = "frmAccountInformation.aspx";
//    }
}
else {
    window.location.href = "frmEventsDetailsView.aspx";
}
  //  document.getElementById('login').style.display = "";

}
function ViewPostalCode(strPostCode) {

    var str;
    //        if (rbPostalMap=="1")   
    //        {
    str = "http://maps.google.com/maps?f=d&hl=en&saddr=&daddr=" + strPostCode;
    //        }else
    //        {
    //         str="http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&keepicon=true&lang=&pc=" + obj1 +"&advanced=&client=public&addr2=&quicksearch=SG27QF&addr3=&addr1=";
    //        }
    window.open(str);
}


       
      

var http = createRequestObject();

function createRequestObject() {
    var req;
    if (window.XMLHttpRequest) {
        // Firefox, Safari, Opera...
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // Internet Explorer 5+
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        // old browser is being used. 
        alert('Problem creating the XMLHttpRequest object');
    }
    return req;
}

function sendRequest(Status,eventId) {
    // Open server script for requests

    if (Status == "Yes") {
        http.open('get', 'frmEventsView.aspx?SendEmail=true&RSVP=Yes', false);
    } else {
        http.open('get', 'frmEventsView.aspx?SendEmail=true&RSVP=No', false);
        //window.location.href = "webform2.aspx?type=download";
    }
    //http.onreadystatechange = handleResponse;    
    http.send(null);    

}

function donothing() {
}


function OpenRSVP(UserId,EventId,EventType) {
    if (UserId == null || UserId == "") {

        window.location.href = "frmregForm.aspx";
         
    }
    else
    {
        if (EventType == "RSVP") {
            sendRequest("Yes", EventId);
            alert("RSVP Sent.");
            window.location.reload();
            //var mysurvey = dhtmlmodal.open("surveybox", "ajax", "RSVP.aspx?RSVP=true", "", "width=393px,height=230px,resize=0,scrolling=0,center=1", "recal")
        }
        else {
            sendRequest("No", EventId);
            //alert("Notice: Please disable any popup blockers");
            setTimeout('window.location.reload()', 5000);
            window.location.href = "webform2.aspx?type=download";
            //window.open('webform2.aspx?type=download', 'Jack', 'height = 1px, width = 1px, status = no,top =1000px, toolbar = no,menubar = no, location = no');
            //setTimeout('window.location.reload()', 5000);
            //var mysurvey = dhtmlmodal.open("surveybox", "ajax", "RSVP.aspx?RSVP=false", "", "width=393px,height=230px,resize=0,scrolling=0,center=1", "recal")
        }
    }
        }

//Code Review Comments:Write description of the function
//This function opens login page from the home page by clicking on the Registration hyperlink
function OpenHomeRegistration() {
window.location.href = "frmregForm.aspx";
}
function OpenCampaignForDonation(EventId)
 {
     window.location.href = "frmEventsView.aspx?Eid=" + EventId;
     //    window.location.href = "frmCampaignPublicView.aspx?Id=0";
     alert("Donation functionality is not implemented");
}

//Code Review Comments:Write description of the function
//This function navigates the user to Find Event page
function CloseRSVP(Eventid) {
    window.location.href = "frmEventsView.aspx?Eid=" + Eventid;
}

function OpenEvent() {
    window.location.href = "frmFindEvent.aspx";
}

//Code Review Comments: 1.Function name should be in pascal casing.
//                      2.Write description of the function
//This function displays calendars at runtime.             
function EventsDisplay(day, month, year) {
      xmlHttp = GetXmlHttpObject(StateChangeHandler);
    //Send the xmlHttp get to the specified url
    var url = "Home.aspx?day=" + day + "&month=" + month + "&year=" + year;
    xmlHttp_Get(xmlHttp, url);
}


//Code Review Comments: Write description of the function
//This function displays calendars at runtime(XMLHttp send GET request).
function xmlHttp_Get(xmlhttp, url) {
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
}

//Code Review Comments: 1.Write description of the function
//               2.Function name should be in pascal casing.
//This function displays calendars at runtime.
function BuildCal(m, y, cM, cH, cDW, cD, brdr, eventDates) {
    var events = eventDates.split('~');
    var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
    oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

    var todaydate = new Date() //DD added
    var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

    dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
    var t = '<div><table width="100%" class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
    t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
    for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
    t += '</tr><tr align="center">';
    
    for (i = 1; i <= 42; i++) {
        var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
        if (x != '&nbsp;') {
                        
            if (x == scanfortoday) //DD added
                t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
            else
                if (events[x-1] == 1) {
                    t += '<td class="' + cD + '"><a style="color:Red;text-decoration:none;" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
            }
            else {
                t += '<td class="' + cD + '"><a class="calanc" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
            }            
        }
        else {
            t += '<td class="' + cD + '">' + x + '</td>';
        }
        if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
    }
    return t += '</tr></table></div>';
}

function BuildCal1(m, y, cM, cH, cDW, cD, brdr, eventDates) {
    var events = eventDates.split('-');
    var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
    oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

    var todaydate = new Date() //DD added
    var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

    dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
    var t = '<div><table width="100%" class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
    t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
    for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
    t += '</tr><tr align="center">';

    for (i = 1; i <= 42; i++) {
        var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
        if (x != '&nbsp;') {

            if (x == scanfortoday) //DD added
                t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
            else
                if (events[x - 1] == 1) {
                    t += '<td class="' + cD + '"><a style="color:Red;text-decoration:none;" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
                }
                else {
                    t += '<td class="' + cD + '"><a class="calanc" href="javascript:EventsDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
                }
        }
        else {
            t += '<td class="' + cD + '">' + x + '</td>';
        }
        if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
    }
    return t += '</tr></table></div>';
}



//Code Review Comments: Write description of the function
//This function gets XML HTTP handler type
function GetXmlHttpObject(handler) {
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie) {
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';

        //Attempt to create the object 
        try {
            objXmlHttp = new ActiveXObject(strObjName);
            objXmlHttp.onreadystatechange = handler;
        }
        catch (e) {
            //Object creation errored 
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
            return;
        }
    }
    else if (is_opera) {
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.');
        return;
    }
    else {
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest();
        objXmlHttp.onload = handler;
        objXmlHttp.onerror = handler;
    }

    //Return the instantiated object 
    return objXmlHttp;
}

function newCookie(name, value, days) {
    var days = 10;   // the number at the left reflects the number of days for the cookie to last
    // modify it according to your needs
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

//Code Review Comments: Write description of the function
//This function gets XML HTTP object state.
function StateChangeHandler() {
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        //Gather the results from the callback
        var str = xmlHttp.responseText;
        if (str.search("~") == -1) {
            if (str.search("$") == -1) {
                document.getElementById('sidebar1').innerHTML = str;
                document.getElementById('containerCol2ID').innerHTML = "<a style='text-decoration:none' href='#'>No Events Exist &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</a>";
                document.getElementById('containerCol1ID').innerHTML = "<a style='text-decoration:none' href='#'>No Campaigns Exist &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</a>";
            }
            else {
                var strCsplits = str.split('$');
                document.getElementById('sidebar1').innerHTML = strCsplits[0];
                //document.getElementById('containerCol1ID').innerHTML = "<a style='text-decoration:none' href='frmCampaignPublicView.aspx'>" + strCsplits[1] + "</a>";
                //document.getElementById('containerCol2ID').innerHTML = "<a style='text-decoration:none' href='#'>No Events Exist &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</a>";
            }
            
        }
        else {
            var strsplits = str.split('~');
            document.getElementById('sidebar1').innerHTML = strsplits[0];
            var strCampaign = strsplits[1];
            
            if (strCampaign.search("$") == -1) {
                document.getElementById('containerCol1ID').innerHTML = "<a style='text-decoration:none' href='#'>No Campaigns Exist &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</a>";
                document.getElementById('containerCol2ID').innerHTML = strCampaign;
            }
            else {
                var strCsplits1 = strCampaign.split('$');
//                document.getElementById('containerCol1ID').innerHTML = strCsplits1[1]; //"<a style='text-decoration:none' href='frmCampaignPublicView.aspx'>" + strCsplits1[1] + "</a>";
//                document.getElementById('containerCol2ID').innerHTML = strCsplits1[0]; //"<a style='text-decoration:none' href='frmEventsView.aspx'>" + strCsplits1[0] + "</a>";
            }
        }
        //Populate the innerHTML of the div with the results
       
    }
}

//Code Review Comments: Write description of the function
//This function checks user login credentials
function CheckLogin(userId, password) {    
   
    xmlHttp = GetXmlHttpObject(StateChangeHandlerLogin);
    var userName = Trim(document.getElementById(userId).value);
    var pwd = Trim(document.getElementById(password).value);
    //Send the xmlHttp get to the specified url
    var url = document.URL + "?Uid=" + userName + "&Pwd=" + pwd;
    xmlHttp_Get(xmlHttp, url);
}

//Code Review Comments: 1.Write description of the function
//                      2.Function name should be in pascal casing
//This function gets XML HTTP handler status and verify user login credentials.
function StateChangeHandlerLogin() {
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        //Gather the results from the callback
        var strTotalValue = xmlHttp.responseText;
        if (strTotalValue.substring(4, 5) != '<') {
            if (strTotalValue == "false") {
                alert("Invalid user login credentials");
                window.returnValue = "fail";
                
                return false;
            }
            else {
                document.getElementById('lblWarningMessage').style.display = "none";
                window.returnValue = 'success';
                window.opener = top;
                window.close();                
                
                return true;
            }
        }            
    }
}

//Code Review Comments: 1.Write description of the function
//                      2.Variable declarations should be in camel casing
//                      3.Provide one line gap between code and return status within the function
//                      4.Avoid empty spaces among the code lines within the function
//This function checks user login credentials and returns response.
function CheckLoginDetails(userId, pwd, remember) {

    var strTotalValue;
    var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
    var userName =Trim(document.getElementById(userId).value);
    var password = Trim(document.getElementById(pwd).value);
    if (userName != "" && password != "") {
        if (window.ActiveXObject) {
            req = new ActiveXObject(strObjName);
            var URL1 = "frmLogin.aspx?Uid=" + userName + "&Pwd=" + password;
            req.open("GET", URL1, false);
            req.send();
            strTotalValue = req.responseText;
            if (strTotalValue.substring(4, 5) == '<') {
                alert("Invalid user login credentials");
//                document.getElementById(userId).value = "";
               document.getElementById(pwd).value = "";
                document.getElementById(userId).focus();
                window.returnValue = -1;
                
                return false;
            }
            else if (strTotalValue.substring(0, 5) == 'false') {
            alert("Invalid user login credentials");
//            document.getElementById(userId).value = "";
            document.getElementById(pwd).value = "";
            document.getElementById(userId).focus();
            window.returnValue = -1;
                
                return false;
            }
            else {
                var splitvalues = strTotalValue.split('~');

                document.getElementById('lblrow').style.display = "none";
                document.getElementById('lblWarningMessage').style.display = "none";
                window.returnValue = 'success';

                if (document.getElementById(remember).checked)
                    newCookie("Politicalendar", userName, 10);
                else
                    newCookie("Politicalendar", "", -50);

                if (splitvalues[2] == 0) {
                    window.location.href = "frmAccountInformation.aspx?status=edit";
                }
                else if (splitvalues[2] == 1) {
                    window.location.href = "frmMyorganizer.aspx";
                }                
                return true;                
            }
        }
        else if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = function () {
                if (req.readyState == 4) {
                    strTotalValue = req.responseText;
                    if (strTotalValue.substring(4, 5) == '<') {

                        alert("Invalid user login credentials");
                        //                document.getElementById(userId).value = "";
                        document.getElementById(pwd).value = "";
                        document.getElementById(userId).focus();
                        window.returnValue = -1;

                        return false;
                    }
                    else if (strTotalValue.substring(0, 5) == 'false') {

                        alert("Invalid user login credentials");
                        //            document.getElementById(userId).value = "";
                        document.getElementById(pwd).value = "";
                        document.getElementById(userId).focus();
                        window.returnValue = -1;

                        return false;
                    }
                    else {

                        var splitvalues = strTotalValue.split('~');

                        document.getElementById('lblrow').style.display = "none";
                        document.getElementById('lblWarningMessage').style.display = "none";
                        window.returnValue = 'success';

                        if(document.getElementById(remember).checked)
                            newCookie("Politicalendar", userName, 10);
                        else
                            newCookie("Politicalendar", "", -50);

                        if (splitvalues[2] == 0) {
                            window.location.href = "frmAccountInformation.aspx?status=edit";
                        }
                        else if (splitvalues[2] == 1) {
                            window.location.href = "frmMyorganizer.aspx";
                        }
                        return true;
                    }
                }
            }
            req.open("GET", "frmLogin.aspx?Uid=" + userName + "&Pwd=" + password, true);
            req.send(null);
            
        }
//        if (window.returnValue != 'success') {
//            if (strTotalValue == "true") {
//                document.getElementById('lblWarningMessage').style.display = "none";
//                window.opener.location = "frmAccountInformation.aspx";
//                window.parent.close();
//            }
//            else {
//               
//                alert("Invalid user login credentials");
//                document.getElementById(userId).value = "";
//                document.getElementById(pwd).value = "";
//                document.getElementById(userId).focus();

//                return false;
//            } 
//        }
    }
    else {
        if ((document.getElementById(userId).value == "") && (document.getElementById(pwd).value == "")) {
            alert("Enter Email Id and Password");
            document.getElementById(userId).focus();
        }
        else if (document.getElementById(userId).value == "") {
        alert("Enter Email Id");
        document.getElementById(userId).focus();
        }
        else if (document.getElementById(pwd).value == "") {
        alert("Enter Password");
        document.getElementById(pwd).focus();
        }        
    }
}

//Code Review Comments: 1.Write description of the function
//                      2.Variable declarations should be in camel casing
//                      3.Avoid empty spaces among the code lines within the function
//This function checks user login credentials and returns response.
function CheckPasswordDetails(userId) {
    var strValue;
    var strObj = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
    var userName = Trim(document.getElementById(userId).value);
    if (userName != "") {
        if (window.ActiveXObject) {
            req = new ActiveXObject(strObj);
            var URL1 = "frmLogin.aspx?User=" + userName;
            req.open("GET", URL1, false);
            req.send();
            strValue = req.responseText;
            if (strValue.substring(4, 5) == '<') {
                alert("Enter valid Email Id");
                document.getElementById(userId).value = "";
                window.returnValue = -1;

                return false;
            }
            else if (strValue.substring(0, 5) == 'false') {
                alert("Email Id does not exist");
                document.getElementById(userId).value = "";
                window.returnValue = -1;
                
                return false;
            }
            else if (strValue.substring(0, 4) == 'true') {
            alert("Your login details have been sent to your Email Id");
            window.location.href = "Home.aspx";
            }
            else if (strValue.substring(0, 13) == 'notvalidemail') {
            alert("Email Id does not exist");
            document.getElementById(userId).value = "";
            window.returnValue = -1;
            
            return false;
            }
            else if (strValue.substring(0, 12) == 'invalidemail') {
            alert("Invalid Email Id");
            document.getElementById(userId).value = "";
            window.returnValue = -1;
            
            return false;
            }
            else {
                document.getElementById('lblWarningMessage').style.display = "none";
                window.returnValue = 'success';
                window.location.href = "#";
                
                return true;
            }
        }
        else if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = fnResult;
            req.open("GET", document.URL + "?Uid=" + userName, true);
            req.send(null);
            strValue = req.responseText;
            if (strValue.substring(4, 5) != '<') {
                if (strValue == "false") {
                    alert("Email Id does not exist");
                    document.getElementById(userId).value = "";
                    
                    return false;
                }
                else {
                    document.getElementById('lblWarningMessage').style.display = "none";
                    window.returnValue = 'success';
                    window.location.href = "#";

                    return true;
                }
            }
        }
        
    }
    else {
        alert("Enter Email Id");
        document.getElementById(userId).value = "";
        document.getElementById(userId).focus();
   }

}

//Code Review Comments: 1.Write description of the function
//                      2.Function name should be in pascal casing
//This function hides login and forgot password screens in the login screen based on the screen name
function DisplayNone() {
    document.getElementById('login').style.display = "none";
    document.getElementById('forgotpassword').style.display = "";
}

//Code Review Comments: 1.Write description of the function
//                      2.Function name should be in pascal casing
//This function hides login and forgot password screens in the login screen based on the screen name
function UserType(controlType) 
{
    var control = document.getElementById(controlType);
    if (control.cells != undefined) {
        if (control.cells.length > 0) {
            for (var i = 0; i < control.cells.length; i++) {
                contrchecked = document.getElementById(controlType + "_" + i);
                if (contrchecked.checked) {
                    if (i == 0) {
                        document.getElementById('trEmp').style.display = "";
                        document.getElementById('trEmpRev').style.display = "";
                        document.getElementById('trOffice').style.display = "";
                        document.getElementById('trOfficeRev').style.display = "";                       
                        document.getElementById('trFax').style.display = "";
                        document.getElementById('trPhysicalAddress').style.display = "";
                        document.getElementById('trPAddress').style.display = "";
                        document.getElementById('trPCity').style.display = "";
                        document.getElementById('trPState').style.display = "";
                        document.getElementById('trMailingConfirm').style.display = "";
                        document.getElementById('trMailingAddress').style.display = "";
                        document.getElementById('trMAddress').style.display = "";
                        document.getElementById('trMCity').style.display = "";
                        document.getElementById('trMCityRev').style.display = "";
                        document.getElementById('trMState').style.display = "";
                        document.getElementById('trPhysicalAddress').style.display = "";
                        document.getElementById('trPAddressRev').style.display = "";
                        document.getElementById('trPCityRev').style.display = "";
                        document.getElementById('trMAddressRev').style.display = "";
                        document.getElementById('trMZipRev').style.display = "";
                        document.getElementById('trPStateRow').style.display = "";
                        document.getElementById('trButtons').style.display = "";                                                                            
                    }
                    else 
                    {
                        document.getElementById('trEmp').style.display = 'none';
                        document.getElementById('trEmpRev').style.display = 'none';
                        document.getElementById('trOffice').style.display = 'none';
                        document.getElementById('trOfficeRev').style.display = 'none';
                        document.getElementById('trFax').style.display = 'none';
                        document.getElementById('trPhysicalAddress').style.display = 'none';
                        document.getElementById('trPAddress').style.display = 'none';
                        document.getElementById('trPCity').style.display = 'none';
                        document.getElementById('trPState').style.display = 'none';
                        document.getElementById('trMailingConfirm').style.display = 'none';
                        document.getElementById('trMailingAddress').style.display = 'none';
                        document.getElementById('trMAddress').style.display = 'none';
                        document.getElementById('trMCity').style.display = 'none';
                        document.getElementById('trMCityRev').style.display = 'none';
                        document.getElementById('trMState').style.display = 'none';
                        document.getElementById('trPhysicalAddress').style.display = 'none';
                        document.getElementById('trPAddressRev').style.display = 'none';
                        document.getElementById('trPCityRev').style.display = 'none';
                        document.getElementById('trMAddressRev').style.display = 'none';
                        document.getElementById('trMZipRev').style.display = 'none';
                        document.getElementById('trPStateRow').style.display = 'none';
                        document.getElementById('trButtons').style.display = "";                                                      
                    }
                }
            }
        }
    }
}

function CloseLogin()
{
    document.getElementById('forgotpassword').style.display = 'none';
    document.getElementById('login').style.display = '';
}

function LogOut() {
    window.location.href = "frmLogOut.aspx";
}

function OpenRegistration() {
//    window.returnValue = 'Registration';
//    window.opener = top;
    //    window.close();
    window.location = "frmregForm.aspx";
    return true;
}

function buildCalOrganizer(m, y, cM, cH, cDW, cD, brdr) {
    var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
    oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

    var todaydate = new Date() //DD added
    var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

    dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
    var t = '<div class="' + cM + '"><table  class="' + cM + '" cols="7"  cellpadding="0" border="0" width="100%" height="20%" cellspacing="0"><tr align="center">';
    t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
    for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
    t += '</tr><tr align="center">';
    for (i = 1; i <= 42; i++) {
        var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
        if (x != '&nbsp;') {
            if (x == scanfortoday) //DD added
                t += '<td class="' + cD + '"><a style="color:red; text-decoration:none;" href="javascript:Organizerdisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
            else
                t += '<td class="' + cD + '"><a class="calanc" href="javascript:Organizerdisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
        }
        else {
            t += '<td class="' + cD + '">' + x + '</td>';
        }
        if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
    }
    return t += '</tr></table></div>';
}

function Organizerdisplay(day, month, year) {
    // alert("day" + day + "month" + month + "year" + year);
    xmlHttp = GetXmlHttpObject(OrganizerHandler);

    //Send the xmlHttp get to the specified url
    var url = "ReloadOrganizer.aspx?day=" + day + "&month=" + month + "&year=" + year;
    //alert(url);
    xmlHttp_Get(xmlHttp, url);
}

function OrganizerHandler() {
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        //Gather the results from the callback
        var strResponse = xmlHttp.responseText;
        var strEventsDoc = strResponse.split('~');
        var strEvents = strEventsDoc[0].split('$');
        var strInterestedEvents = strEvents[1];
        var strSheduledEvents = strEvents[0];
        document.getElementById('ctl00_ContentPlaceHolder_upcommingevents').innerHTML = strInterestedEvents;
        document.getElementById('ctl00_ContentPlaceHolder_dateevents').innerHTML = strSheduledEvents;
        
    }
}


function BuildFormCal(m, y, cM, cH, cDW, cD, brdr) {
    var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
    oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

    var todaydate = new Date() //DD added
    var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

    dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
    var t = '<div class="' + cM + '"><table class="' + cM + '" cols="7"  cellpadding="0" border="1" cellspacing="0"><tr align="center">';
    t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
    for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
    t += '</tr><tr align="center">';
    for (i = 1; i <= 42; i++) {
        var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
        if (x != '&nbsp;') {
            if (x == scanfortoday) //DD added
                t += '<td class="' + cD + '"><a style="color:red; text-decoration:none;" href="javascript:Eventsdisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
            else
                t += '<td class="' + cD + '"><a class="calanc" href="javascript:Eventsdisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
        }
        else {
            t += '<td class="' + cD + '">' + x + '</td>';
        }
        if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
    }
    return t += '</tr></table></div>';
}

//Validations for Registration Form:


var RegExprAlphabets = /[a-zA-Z\s]+/;
var RegExprEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var RegWeburl = /^([a-z0-9_-]+\.)*[a-z0-9_-]+(\.[a-z]{2,6}){1,2}$/;

function RegularExpressionValidator(controlID, validatorID, validationExpression) {

    var value = document.getElementById(controlID).value;
    var validator = document.getElementById(validatorID);

    if (value.length == 0) {
        validator.style.display = "none";
        return true;
    }
    var rx = new RegExp(validationExpression);
    var matches = rx.exec(value);
    var validator_IsValid = (matches != null && value == matches[0]);
    validator.style.display = validator_IsValid ? "none" : "inline";

    validator.visible = true;
    return validator_IsValid;
}

function Trim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function RequiredFieldValidator(controlID, validatorID, initialValue) {

    var control = document.getElementById(controlID);

    var validator_IsValid = false
    if (control != null) {
        validator_IsValid = ((control.value) != (initialValue));
        control.style.border = validator_IsValid ? "1px solid #999999" : "1px solid #FF0000";        
        if ((validatorID).length != 0)
            document.getElementById(validatorID).style.display = validator_IsValid ? "none" : "inline";
    }
    return validator_IsValid;
}

function RegistrationSubmit(controlType) {
var page_IsValid = true;
var control = document.getElementById(controlType);
if (control.cells != undefined) {
    if (control.cells.length > 0) {
        for (var i = 0; i < control.cells.length; i++) {
            contrchecked = document.getElementById(controlType + "_" + i);
            if (contrchecked.checked) {
                if (i == 0) {
                    page_IsValid = (RequiredFieldValidator('<%= txtFirstName.ClientID %>','') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtLastName.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtEmail.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPhone.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtEmployer.ClientID %>','') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPosition.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtofficephone.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtcellphone.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPAddress.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPcity.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= ddlState.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPZipcode.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtMcity.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= ddlMstate.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtMZipCode.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= rdCreateProfile.ClientID %>', '') && page_IsValid);
                }
                else {
                    page_IsValid = (RequiredFieldValidator('<%= txtFirstName.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtLastName.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtEmail.ClientID %>', '') && page_IsValid);
                    page_IsValid = (RequiredFieldValidator('<%= txtPhone.ClientID %>', '') && page_IsValid);
                }
            }
        }
    }
}
                     
    return page_IsValid;
}


function BlockText(obj) {
    if (obj.value.length > 99) {
        return false;
    }
    return true;
}
	



//function CountyDisplay(StateId) {
//      xmlHttp = GetXmlHttpObject(CountyHandler);
//    //Send the xmlHttp get to the specified url
//    var url = document.URL + "?StateId=" + StateId ;
//    xmlHttp_Get(xmlHttp, url);
//}


////This function gets XML HTTP object state.
//function CountyHandler() {
//    //readyState of 4 or 'complete' represents that data has been returned 
//    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
//        //Gather the results from the callback
//        var str = xmlHttp.responseText;
//        }
//    }

    //This method loads county details based on the selected stateId
    function CountyStateDisplay(value) {
        var stateId = value; //aluedocument.getElementById(controlId).value;
        var listControl = document.getElementById('ctl00_ContentPlaceHolder_lstCounty');
        while (listControl.options.length > 0) {
            var newOption = new Option(); // Create a new instance of ListItem
            listControl.options.selectedIndex = 0;
            listControl.remove(listControl.options.selectedIndex); //Remove the item from Source Listbox 
        }
        xmlHttp = GetXmlHttpObject(FindCountyHandler);
        //Send the xmlHttp get to the specified url
        var url = document.URL.replace("#","") + "?StateId=" + stateId;
        xmlHttp_Get(xmlHttp, url);
    }

    //This function gets XML HTTP object state.
    function FindCountyHandler() {
        //readyState of 4 or 'complete' represents that data has been returned
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
            //Gather the results from the callback
            var strTotalValue = xmlHttp.responseText;
            
            if (parseInt(strTotalValue.indexOf("$"))>-1) {
                var Countydata = strTotalValue.split('$')
                if (parseInt(Countydata[0].indexOf("~")) > -1)
                var splitValues = Countydata[0].split('~');
                var listControl = document.getElementById('ctl00_ContentPlaceHolder_lstCounty');

                while (listControl.options.length > 0) {
                    var newOption = new Option(); // Create a new instance of ListItem
                    listControl.options.selectedIndex = 0;
                    listControl.remove(listControl.options.selectedIndex); //Remove the item from Source Listbox 
                }
                          
                if(splitValues!=null)
                {
                    for (var i = 0; i < splitValues.length; i++) {
                        AddItem(splitValues[i], splitValues[i + 1]);
                        i++;
                    }
                }
            }
        }
    }

    //This method adds items to the listbox 
    function AddItem(Text, Value) {
        // Create an Option object        
        var opt = document.createElement("option");
        // Add an Option object to Drop Down/List Box
        document.getElementById('ctl00_ContentPlaceHolder_lstCounty').options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
    }





//Profile pAges

    //This method loads county details based on the selected stateId
    function CountyStateDisplayProfile() {
        var index = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State1').selectedIndex;
        var Value = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State1')[index].value;
        var Text = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State1')[index].innerHTML;
        var opt = document.createElement("option");
        document.getElementById('ctl00_ContentPlaceHolder_lstPref_State2').options.add(opt);        
        opt.text = Text;
        opt.value = Value;

        var stateId = Value; //aluedocument.getElementById(controlId).value;
        xmlHttp = GetXmlHttpObject(FindCountyHandler1);
        //Send the xmlHttp get to the specified url
        var url = "frmAccountInformation.aspx?StateId=" + stateId;
        xmlHttp_Get(xmlHttp, url);
    }

    //This function gets XML HTTP object state.
    function FindCountyHandler1() {
        //readyState of 4 or 'complete' represents that data has been returned
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
            //Gather the results from the callback
            var strTotalValue = xmlHttp.responseText;
            
             if (strTotalValue.indexOf("$")>0) 
             {
                var Countydata = strTotalValue.split('$')
                if (Countydata[0].indexOf("~") > 0)
                var splitValues = Countydata[0].split('~');
                var listControl = document.getElementById('ctl00_ContentPlaceHolder_lstCounty');

                while (listControl.options.length > 0) 
                {
                    var newOption = new Option(); // Create a new instance of ListItem
                    listControl.options.selectedIndex = 0;
                    listControl.remove(listControl.options.selectedIndex); //Remove the item from Source Listbox 
                }
               

            for (var i = 0; i < splitValues.length; i++) 
                {
                AddItem1(splitValues[i], splitValues[i + 1]);
                i++;
                }
            }

        }
    }

    //This method adds items to the listbox 
    function AddItem1(Text, Value) {
        // Create an Option object        
        var opt = document.createElement("option");
        // Add an Option object to Drop Down/List Box
        document.getElementById('ctl00_ContentPlaceHolder_lstPref_Countries1').options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
    }


   // ctl00_ContentPlaceHolder_lstPref_Countries1

   // ctl00_ContentPlaceHolder_lstPref_State2

    // ctl00_ContentPlaceHolder_btnStateAdd

    //ctl00_ContentPlaceHolder_lstPref_State1

    function CountyStateRemoveProfile() {
    
        var index = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State2').selectedIndex;
        var Value = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State2')[index].value;

        var Text = document.getElementById('ctl00_ContentPlaceHolder_lstPref_State2')[index].innerHTML;
        var opt = document.createElement("option");
        document.getElementById('ctl00_ContentPlaceHolder_lstPref_State1').options.add(opt);
        opt.text = Text;
        opt.value = Value;
        document.getElementById('ctl00_ContentPlaceHolder_lstPref_State2').options.remove(opt);
        var stateId = Value; //aluedocument.getElementById(controlId).value;
        xmlHttp = GetXmlHttpObject(FindCountyHandlerRemove);
        //Send the xmlHttp get to the specified url
        var url = "frmAccountInformation.aspx?StateId=" + stateId+"&Status=Remove";
        xmlHttp_Get(xmlHttp, url);

    }

    function FindCountyHandlerRemove() {
        //readyState of 4 or 'complete' represents that data has been returned
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
            //Gather the results from the callback
            var strTotalValue = xmlHttp.responseText;
            var Countydata = strTotalValue.split('$')
            var splitValues = Countydata[0].split('~');
            for (var i = 0; i < splitValues.length; i++) {
                RemoveItem(splitValues[i], splitValues[i + 1]);
                i++;
            }

        }
    }

    //This method adds items to the listbox 
    function RemoveItem(Text, Value) {
        // Create an Option object        
        var opt = document.createElement("option");
        // Add an Option object to Drop Down/List Box
        document.getElementById('ctl00_ContentPlaceHolder_lstPref_Countries1').options.remove(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
    }


    function BuildProfileCal(m, y, cM, cH, cDW, cD, brdr, eventDates) {
        var events = eventDates.split('~');
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {

                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block"  ><b>' + x + '</b></a></td>';
                else
                    if (events[x - 1] == 1) {
                    t += '<td class="' + cD + '"><a style="color:Red;text-decoration:none;"><b>' + x + '</b></a></td>';
                }
                else {
                    t += '<td class="' + cD + '"><a class="calanc" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }




    function BuildDayCalendar(m, y, cM, cH, cDW, cD, brdr,hdnvalue) {        
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added
        var x0="1"
        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table width="100%" class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '"><a href="javascript:CalendarEventsDayDisplay('+ x0 +',' + m + ',' + y + ',' + hdnvalue + ');" style="color:#ffffff;text-decoration:none;">' + mn[m - 1] + ' - ' + y + '</a></td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {
                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:CalendarEventsDayDisplay(' + x + ',' + m + ',' + y + ',' + hdnvalue + ');" ><b>' + x + '</b></a></td>';
                else {
                    t += '<td class="' + cD + '"><a class="calanc" href="javascript:CalendarEventsDayDisplay(' + x + ',' + m + ',' + y + ',' + hdnvalue + ');" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }

    function CalendarEventsDayDisplay(day, month, year) {        
        xmlHttp = GetXmlHttpObject(DisplayCalendarData);
        //Send the xmlHttp get to the specified url
        var page = 'month';
        if (document.getElementById('ctl00_ContentPlaceHolder_DayView1').style.display == "inline")
         {
            page = 'day';
        }
        else if (document.getElementById('ctl00_ContentPlaceHolder_WeekView1').style.display == "inline")
         {
        page = 'week';
        }
        var url = "frmCalendarView.aspx?page=" + page + "&day=" + day + "&month=" + month + "&year=" + year;
        xmlHttp_Get(xmlHttp, url);   
        //window.location.href = "frmCalendarView.aspx?day=" + day + "&month=" + month + "&year=" + year;
    }

    function DisplayCalendarData() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
            //Gather the results from the callback
            var strTotalValue = xmlHttp.responseText;
            if (strTotalValue.search("$") == -1) {

            }
            else {
                var splitdata = strTotalValue.split('$');
                if (document.getElementById('ctl00_ContentPlaceHolder_DayView1').style.display == "inline") {
                    document.getElementById('ctl00_ContentPlaceHolder_DayView1').innerHTML = splitdata[0];
                }
                else if (document.getElementById('ctl00_ContentPlaceHolder_WeekView1').style.display == "inline") {
                document.getElementById('ctl00_ContentPlaceHolder_WeekView1').innerHTML = splitdata[0];
                }
                else {
                    document.getElementById('ctl00_ContentPlaceHolder_MonthView1').innerHTML = splitdata[0];
                }
                
            }
        }
    }
    function BuildWeekCalendar(m, y, cM, cH, cDW, cD, brdr) {
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table width="100%" class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {
                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:CalendarEventsWeekDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
                else {
                    t += '<td class="' + cD + '"><a class="calanc" href="javascript:CalendarEventsWeekDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }
    function CalendarEventsWeekDisplay(day, month, year) {
        window.location.href = "frmCalendarView.aspx?page=week&day=" + day + "&month=" + month + "&year=" + year;
    }

    function BuildMonthCalendar(m, y, cM, cH, cDW, cD, brdr) {
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table width="100%" class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {
                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:CalendarEventsMonthDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
                else {
                    t += '<td class="' + cD + '"><a class="calanc" href="javascript:CalendarEventsMonthDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }

    function CalendarEventsMonthDisplay(day, month, year) {
        window.location.href = "frmCalendarView.aspx?page=month&day=" + day + "&month=" + month + "&year=" + year;
    }



    function BuildCampaign(m, y, cM, cH, cDW, cD, brdr) {
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {
                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:CampaignEventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
               else {
                   t += '<td class="' + cD + '"><a class="calanc" href="javascript:CampaignEventsDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }

    function CampaignEventsDisplay() {
        //window.location.href = "frmCalendarView.aspx?page=month&day=" + day + "&month=" + month + "&year=" + year;
    }


    function BuildCalForProfileView(m, y, cM, cH, cDW, cD, brdr) {
        var mn = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od = oD.getDay() + 1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table class="' + cM + '" cols="7"  cellpadding="0" border="0" cellspacing="0"><tr align="center">';
        t += '<td colspan="7" align="center" class="' + cH + '">' + mn[m - 1] + ' - ' + y + '</td></tr><tr align="center">';
        for (s = 0; s < 7; s++) t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
        t += '</tr><tr align="center">';

        for (i = 1; i <= 42; i++) {
            var x = ((i - oD.od >= 0) && (i - oD.od < dim[m - 1])) ? i - oD.od + 1 : '&nbsp;';
            if (x != '&nbsp;') {
                if (x == scanfortoday) //DD added
                    t += '<td class="' + cD + '"><a style="color:#FFF; background-color:#777; text-decoration:none; display:block" href="javascript:CampaignEventsDisplay(' + x + ',' + m + ',' + y + ');" ><b>' + x + '</b></a></td>';
                else {
                    t += '<td class="' + cD + '"><a class="calanc" href="javascript:CampaignEventsDisplay(' + x + ',' + m + ',' + y + ');" >' + x + '</a></td>';
                }
            }
            else {
                t += '<td class="' + cD + '">' + x + '</td>';
            }
            if (((i) % 7 == 0) && (i < 36)) t += '</tr><tr align="center">';
        }
        return t += '</tr></table></div>';
    }

    function CampaignEventsDisplay() {
        //window.location.href = "frmCalendarView.aspx?page=month&day=" + day + "&month=" + month + "&year=" + year;
    }
