﻿// JScript File


   function isValidEntry()
   {
   
     var errorHeader = 'Please correct the following errors:\n';
     var errorMessage= '';
     
     var allNodes = $('txt_fname', 'txt_lname', 'txt_zip', 'txt_mobilephone');
     
      if(isEmailAddress($F('txt_email')))
     {
      
      if($F('txt_email') != $F('txt_conemail'))
      {
        errorMessage += '- Confirm email does not match\n';
      }
     
     }
     else
     {
       errorMessage +='- Email should not be in a valid format\n';
     
     }
     
     for(i=0; i<allNodes.length; i++)
     {
          
       if(allNodes[i].value.empty() || allNodes[i].value.blank())     
       {
         switch(i)
         {
          case 0:
            errorMessage += '- First name should not be blank\n';
            break;
          case 1:
            errorMessage += '- Last name should not be blank\n';
            break;
          case 2:
            errorMessage += '- Zip should not be blank\n';
            break;
          case 3:
            errorMessage += '- Mobile number should not be blank\n';
            break;
         
            
         }
       }
     }
     
    
     if(errorMessage != '')
     {
       alert(errorHeader + errorMessage);
       return false;
       
     }
        return true;
      
    }     
    
    function postActionEmailUpdate()
    {

       var formName = $('emailUpdate');
       
       formName.request(
        {
         onComplete: mailResponse
        
        }
       
       );

    }
    
    function mailResponse(originalRequest)
    {
        alert(originalRequest.responseText);
        window.location="default.htm";
        

    }
    
    function doSendAction()
    {
      if(isValidEntry())
      {
       postActionEmailUpdate();
       return true;
      }
      else
      {
       return false;
      
      }
    
    }
    
    function blurAnchors()
    {
        if(document.getElementsByTagName)
        {
            var a = document.getElementsByTagName("a");
            for(var i = 0; i < a.length; i++)
            {
                a[i].onfocus = function(){this.blur()};
            }
        }
    }
    
    function confirmDelete(message, URL)
    {
     Dialog.confirm(message,
      {
       width: 300,
       className: "alphacube",
       okLabel: "Delete",
       cancelLabel: "Cancel",
       id: "myDialogID",
       onOk: function(){location.href= URL; return true;}
      });
    }
    
    function showBlurbPopup(imagePath, blurbTitle)
    {
     var win = new Window(
     {
        className: "alphacube",
        title: blurbTitle,
        width: 500,
        height: 600,
        destroyOnClose: true,
        recenterAuto: true
     });
   
    win.getContent().update("<img src=" + imagePath + "></img>");
    win.showCenter();
    
    }
    
    function windowjsAlert(message)
    {
     Dialog.alert(message,{
       width: 300,
       className: "alphacube",
       okLabel: "Ok",
       id: "myDialogID",
       onOk: function(){window.location="index.aspx";}
     });
    
    }
    
   function showPostResult(resultValue)
     {
      $('txt_pass').value = resultValue.responseText;
     }
     


//advantage connections script   

function doSendAction_adcon()
    {
      if(isValidEntry_adcon())
      {
       postActionAdvantageConnection();
       return true;
      }
      else
      {
       return false;
      
      }
    
    }

 function isValidEntry_adcon()
   {
   
     var errorHeader = 'Please correct the following errors:\n';
     var errorMessage= '';
     
     var allNodes = $('txt_fname', 'txt_lname', 'txt_city', 'txt_zip', 'txt_mobilenumber');
     
      if(isEmailAddress($F('txt_email')))
     {
      
      if($F('txt_email') != $F('txt_conemail'))
      {
        errorMessage += '- Confirm email does not match\n';
      }
     
     }
     else
     {
       errorMessage +='- Email should not be in a valid format\n';
     
     }
     
     for(i=0; i<allNodes.length; i++)
     {
          
       if(allNodes[i].value.empty() || allNodes[i].value.blank())     
       {
         switch(i)
         {
          case 0:
            errorMessage += '- First name should not be blank\n';
            break;
          case 1:
            errorMessage += '- Last name should not be blank\n';
            break;
          case 2:
            errorMessage += '- City should not be blank\n';
            break;
          case 3:
            errorMessage += '- Zip should not be blank\n';
            break;
          case 4:
            errorMessage += '- Mobile number should not be blank\n';
            break;
                   
         }
       }
     }
     
     
     if(!isTelephoneNumber($F('txt_couponcode')))
     {
      errorMessage += '- Coupon code should be in correct format\n';
     }
     
    
     if(errorMessage != '')
     {
       alert(errorHeader + errorMessage);
       return false;
       
     }
        return true;
      
    }     
    
    
     function postActionAdvantageConnection()
     {
         var formName = $('advantageconnection');
           
           formName.request(
            {
             onComplete: postResponse
            
            }
           
           );
     
     }
      
    function postResponse(originalRequest)
    {
        alert(originalRequest.responseText);
        window.location="default.htm";
    }
    
    
    
