﻿// This file is employed by the Join.aspx 

// Configuration information
/*
var registrationformid;
var emailaddressid;
var stateid;
var countryid;
var dobmonthid;
var dobdayid;
var dobyearid;
*/
// End of configuration
var pageisvalid = true;
var tempargs;
var tempuserargs;
AjaxPro.timeoutPeriod = 40*1000;
AjaxPro.onTimeout = handleTimeout;

var previous_email = "";


function handleTimeout(ms,req)
{
    //alert("Sorry there was an internal error.");
    var answer = confirm("There was an internal error. Do you want to try again?");
    if(answer)
    {
        checkForDuplicateEmailAddress(null, tempargs);
    }
    else 
    {
        document.getElementById("warn_email").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";
        return;
    } 
}

var value;
var email;

// method for FireFox 
function  checkuserFF(user)
{
    try 
    {
        showLayer("warn_username","<img src='images/ajax_loading_sq.gif' border='0' />");
        Membership.CheckUsernameAvailability(user.value,null,checkForDuplicateUsername_CallBack);
     }
    catch(ex)
    {
        alert("checkuserFF "+ex);
    }
}

// The Ajax method to check availability of username
function checkuser(sender, args)
{
    
    try 
    {
        hideLayer("usernamemsg");
        if((args.Value.length < 6) || (args.Value.length > 20))
        {
             document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";             
        }
        else 
        {
            var filter = /^[A-Z|a-z|0-9|$_|\-|\']*$/;
            if(filter.test(args.Value))
            {
                showLayer("usernamemsg","<span class='membership_errors'>Checking <img src='images/ajax_loading_sq.gif' border='0' /></span>");
                tempuserargs = args.Value;
                Membership.CheckUsernameAvailability(args.Value,args,checkForDuplicateUsername_CallBack);
                //var el = document.getElementById("txtValue");
                //alert(value);
                if(value != null)
                {
                if(value == '0')
                    {
                        args.IsValid = true;
                        document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_ok.gif' border='0' />";
                    }
                    else 
                    {
                        args.IsValid = false;
                        document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";
                    }
                }
                else 
                {
                    document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";
                }
            }
            else 
            {
                document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";
            }
        }   
        
    } 
    catch(ex)
    {
        alert("checkuser "+ex);
    }   
}

// The Ajax response method	
function checkForDuplicateUsername_CallBack(response) 
{
		    try 
		    {
		    var ds = response.value;
		   		    
		    if(ds!=null && typeof(ds) == "object" && ds.Tables!=null) 
	        {
		        var s = new Array();
		        value = ds.Tables[0].Rows[0].status;
		        if(value == '0')
		        {
		             hideLayer("usernamemsg");
		             //showLayer("usernamemsg","<img src='images/icons/warn.gif'border='0'/><span class='required'>This user name is already taken and hence unavaliable, please use a different username.</span>");
		             document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_ok.gif' border='0' />";
		        }
		        else 
		        {
		            showLayer("usernamemsg","<span class='membership_errors'>Username is not available.</span>");
		            document.getElementById("warn_username").innerHTML = "<img src='images/cn_form_error.gif' border='0' />";
		            //s[s.length] = "<span class='required'>This user name is already taken and hence unavaliable, please use a different username.</span>";												
		            //document.getElementById("usernamemsg").innerHTML = s.join("");		        	       
		        }
	        }
	        } catch(ex)
            {
               alert("server response "+ex);
            }	             	        	       
 }
 
 // Ajax method to check for pre-existing email address 
 function checkForDuplicateEmailAddress(sender, args)
 {
    
    if(args.Value == "") 
    {
        hideLayer("emailmsg");
        return;
    }
    
    var image_path = document.getElementById('warn_email').innerHTML; 
    document.getElementById('warn_email').innerHTML = "";
    if((image_path.match('mages/cn_form_ok.gif')) && (document.getElementById("ctl00_PageShellHolder_Membership_Join1_txtEmailAddress").value == tempargs.Value))
    {
        //alert(tempargs.Value);
    }
    else 
    {
        try 
        {
            tempargs = args;
            
            //showLayer("warn_email","<img src='images/ajax_loading_sq.gif' border='0' />");
            if(args.Value.length  <= 0)
            {
                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
            }
            else 
            {
                 var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
                 if(filter.test(args.Value))
                 {
                    changeButtonText();
                    showLayer("emailmsg","<span class='membership_errors'>Checking <img src='images/ajax_loading_sq.gif' border='0' /></span>");
                    Membership.CheckEmailAvailability(args.Value,checkForDuplicateEmailAddress_CallBack);
                    if(email != null)
                    {
                     if(email == '0')
                        {
                            args.IsValid = true;
                        }
                        else 
                        {
                            args.IsValid = false;
                        }
                    }
                 }
                 else 
                 {
                    showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                 }
                  
                   
            }    
        } 
        catch(ex)
        {
            alert(ex.description);
        }
  }   
	
 }
 
 // The Ajax response method to check for duplicate email address
 function checkForDuplicateEmailAddress_CallBack(response)
 {
            changeButtonTextToOriginal();
            try 
            {
            var ds = response.value;
            if(ds!=null && typeof(ds) == "object" && ds.Tables!=null) 
	        {
		        var s = new Array();
		        //alert("Code: "+ds.Tables[0].Rows[0].status+" ConsumerID: "+ds.Tables[0].Rows[0].Error);		       
		        switch (ds.Tables[0].Rows[0].status)
		        {
                case "0":
                            { 
                                //s[s.length] = "The Email Address is avaliable";
                                showLayer("warn_email","<img src='images/cn_form_ok.gif' border='0' />");
                                hideLayer("emailmsg");
                                email = '0';
                                break;
                            }
                case "1":
                            { 
                                s[s.length] = "<span class='membership_errors'>There is a pending registration on this email address.  Please click <a href=# onclick='sendconfirmation();' >here</a> if you wish to receive another registration confirmation request email.</span>";
                                showLayer("emailmsg",s.join(""));
                                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                email = '1';
                                break;
                            }
                case "2":
                            { 
                               s[s.length] = "<span class='membership_errors'>There is a pending request for this email address. Please choose another email address.</span>";
                               showLayer("emailmsg",s.join(""));
                               showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                               email = '1';
                               break;
                            }
                case "3":
                            { 
                                s[s.length] = "<span class='membership_errors'>Non responsive web service.</span>";
                                showLayer("emailmsg",s.join(""));
                                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                email = '1';
                                break;
                            }
                case "4":
                            { 
                                //s[s.length] = "<span class='required'>Please enter an email address.</span>";
                                hideLayer("emailmsg");
                                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                email = '0';
                                break;
                            }
                case "5":
                            { 
                                //s[s.length] = "<img src='images/icons/warn.gif'border='0'/><span class='required'>This email address is already registered on this site. Click <a href='ForgotLogin.aspx?email="+ds.Tables[0].Rows[0].Email+"' >here</a> if you wish to retrieve login information for this email address.</span>";
                                s[s.length] = "<span class='membership_errors'>This email address is already registered.</span>";
                                showLayer("emailmsg",s.join(""));
                                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                email = '1';
                                break;
                            }
                case "6":
                            { 
                                s[s.length] = "<span class='membership_errors'>This pre-registered email address cannot be used.</span>";
                                showLayer("emailmsg",s.join(""));
                                showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                email = '1';
                                break;
                            }            
                
                default : 
                            {
                                 alert("There was an internal error.");
                                 s[s.length] = "<span class='membership_errors'>There was an internal error.  Please try again later.</span>";
                                 showLayer("emailmsg",s.join(""));
                                 showLayer("warn_email","<img src='images/cn_form_error.gif' border='0' />");
                                 email = '1';
                                 break;
                            }
                }
                	     
		        //alert("The email address code is: "+email);
		        
	        }
	  }
	  catch(ex)
	  {
	    alert("There was an internal error.");
	  }		 
 }
 
 // Ajax method to send email using EMI web services if previous unconfirmed regsitration is found.
 function sendconfirmation()
 {
    var email = document.getElementById(emailaddressid).value;
    var spath = window.location.href;
    var spage = spath.substring(spath.lastIndexOf('/') + 1);
    try 
    {
    var snewpath = spath.replace(spage,emailconfirmationpagename);
    //hideLayer("ErrorSummary");
    Membership.SendEmailAjax(email,snewpath,websitename,replyemail,sendconfirmation_CallBack);
    } catch(ex)
    {
        alert(ex.description);
    }
    
 }
 
 // The Ajax response method after sending the email.
 function sendconfirmation_CallBack(response)
 {
    var ds = response.value;
     if(ds!=null && typeof(ds) == "object" && ds.Tables!=null) 
	 {
                hideLayer(registrationformid);
                showLayer(registrationformid,"<div class='content'><div class='form_column_inner'>An email requesting a registration confirmation is sent.<br/><a href='index.aspx' target='_self' >Click here to return to the home page.</a></div></div>");
     }
 }
 
function checkUsernameLength(sender,args)
{
    var str = args.Value;
    if(str.length < 6)
    {
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
    }    
}

function disableState(country)
{
     var ele = document.getElementById(stateid);
     if(country.selectedIndex == 221)
     {
        ele.selectedIndex= 0;
        //ele.disabled = false;
     }
     else 
     {
        ele.selectedIndex= 54; 
        //ele.disabled = true;
     } 
}

function changeCountry(state)
{
    
    if(state.value == 0 || state.value == 54)
    {
        
    }
    else 
    {
       var ele = document.getElementById(countryid);
       ele.selectedIndex = 221;
    }
}

function showLayer(name,msg)
{
    document.getElementById(name).className = "showMsg";
    document.getElementById(name).innerHTML = msg;
}
function hideLayer(name)
{
     document.getElementById(name).className = "hideMsg";     
}

// This is for checking the lenght of the province field
function checkLength(sender,args)
{
    var txt = args.Value;
    if (txt.length > 20)
    {
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
    }
}

function checkmaxLength(sender,args)
{
    var txt = args.Value;
    if (txt.length > 20)
    {
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
    }
}

function limitText(limitField) 
{
	if (limitField.value.length > 20) 
	{
		limitField.value = limitField.value.substring(0, 20);
	} 
}

// This file containes functions for the Date of Birth control.

function UTLogin_popWin(url, name, features) {
	win=window.open(url, name, features);
	win.focus();
}

//-------------------------------------------------------------------------
// DATE SELECT LIST NEEDS TO RELOAD NUM OF DAYS ACCORDING TO MONTH AND YEAR
//-------------------------------------------------------------------------
function UTLogin_reload_days() {
 //which_month_droplist = document.getElementById("DateOfBirth_drpMonth");
 //which_day_droplist = document.getElementById("DateOfBirth_drpDay");
 //which_year_droplist = document.getElementById("DateOfBirth_drpYear");
 
 which_month_droplist = document.getElementById(dobmonthid);
 which_day_droplist = document.getElementById(dobdayid);
 which_year_droplist = document.getElementById(dobyearid);
 
 cur_day_selected=which_day_droplist.selectedIndex;
 num_days=UTLogin_getDaysInMonth(which_year_droplist.options[which_year_droplist.selectedIndex].value, which_month_droplist.options[which_month_droplist.selectedIndex].value-1); 
 //alert("num_days : " + num_days)
 UTLogin_relist_day(which_day_droplist, num_days);
 if(cur_day_selected > num_days - 1) {
  which_day_droplist.selectedIndex=num_days;
 } else {
  which_day_droplist.selectedIndex=cur_day_selected;
 }
}
//-------------------------------------------------------------------------
// REBUILDS DAYS AVAILABLE (called by UTLogin_reload_days())
//-------------------------------------------------------------------------
function UTLogin_relist_day(which_day_droplist, num_days) {
 which_day_droplist.options.length=0
 which_day_droplist[0] = new Option("Day", "0");
 for(i=1;i<num_days + 1;i++) {
  which_day_droplist[i] = new Option(i,i);
 }
}
 
//-------------------------------------------------------------------------
// RETURNS NUMBER OF DAYS ON YEAR AND MONTH (INCLUDES LEAP YEAR) : called by UTLogin_reload_days()
//-------------------------------------------------------------------------
function UTLogin_getDaysInMonth( aYear, aMonth ) {
 //alert(aMonth + " : Year - > " + aYear)
    vMonthLookup = new Array(31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if (aMonth != 1) {
        // -- Month isn't February so just look up the day total.
        return vMonthLookup[aMonth];
    }
    // -- Month is February so determine if it is a leap year.
    if (aYear%4 == 0) {
        if ((aYear%400 != 0) && (aYear%100 == 0)) {  
            return 28;  
        } 
        return 29;
    } else { 
  return 28;
 }
}


//-------------------------------------------------------------------------
// Ajax method to check for the correct format of the date and coppa check
//-------------------------------------------------------------------------
function checkForDateFormat(sender, args)
{
    var s = new Array();
    var msg = "";	 
    month = document.getElementById(dobmonthid);
    day = document.getElementById(dobdayid);
    year = document.getElementById(dobyearid);
    if((month.value == '0') || (day.value == '0') || (year.value == '0'))
    {
        if(month.value == '0') 
        {
         msg += "Please choose a month; ";
        }
        if(day.value == '0') 
        {
         msg += "Please choose a day; ";
        }
        if(year.value == '0') 
        {
         msg += "Please choose a year.";
        }
        showLayer("datemsg","<span class='membership_errors'>"+msg+"</span>");
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
        hideLayer("datemsg");
        /* var year_value = parseInt(year.value);
        var month_value = parseInt(month.value) - 1;
        var day_value = parseInt(day.value);
        //var date1 = new Date(Date.UTC((year_value+18), month_value, day_value)); 
        var date1 = new Date((year_value + 18), month_value, day_value);
        var now = new Date;
        if ((now - date1) < 0) 
        {
       
           args.IsValid = false;
           s[s.length] = "<span class='required'>You must be atleast 18 years old to sign up.</span>";
           showLayer("datemsg",s.join(""));
        } 
        else 
        {
            args.IsValid = true;
            hideLayer("datemsg");             
        } */
           
    }
    
}

function showLayer(name,msg)
{
    document.getElementById(name).className = "showMsg";
    document.getElementById(name).innerHTML = msg;
}
function hideLayer(name)
{
     document.getElementById(name).className = "hideMsg";     
}
function displaySummaryMessage()
{
    var ele = document.getElementById("ctl00_PageShellHolder_Membership_Join1_ValidationSummary1");   
    if(ele != null)
    {
        if(ele.innerHTML != "")
        {
            ele.innerHTML = "<br/><span class='form_error'>- Your Information is incomplete or incorrect.</span>";
            //document.getElementById("ctl00_PageShellHolder_Membership_Join1_btnSubmit").src = "images/cn_button_submit.gif";  
                            
        }         
    }
}
function changeButtonText()
{
   document.getElementById("ctl00_PageShellHolder_Membership_Join1_btnSubmit").src = "images/processing.gif";     
}

function changeButtonTextToOriginal()
{
   document.getElementById("ctl00_PageShellHolder_Membership_Join1_btnSubmit").src = "images/cn_button_submit.gif";     
}
/*
function displaySummaryMessage()
{
    if (typeof(ValidatorOnSubmit) == "function")   
    {
        alert(ValidatorOnSubmit())
        /*
        if(ValidatorOnSubmit())
        {
            document.getElementById("ctl00_PageShellHolder_Membership_Join1_ValidationSummary1").innerHTML = "<br/><span class='form_error'>- Your Information is incomplete or incorrect.</span>";
            document.getElementById("ctl00_PageShellHolder_Membership_Join1_btnSubmit").src = "images/cn_button_submit.gif";  
        }
        else 
        {
            document.getElementById("ctl00_PageShellHolder_Membership_Join1_btnSubmit").src = "images/processing.gif"; 
        }
        
    }
}
*/







