public function advancedEditAction()
 {
     $valid = true;
     $formValues = new Varien_Object(Mage::app()->getRequest()->getParams());
     /** @var $api Smartbear_Alertsite_Model_AlertsiteApi */
     $api = Mage::getModel('alertsite/alertsiteapi');
     //Let's first check to be sure that the data isn't all the same
     if ($formValues->getBasicSiteId() == $api->getDeviceId() && $formValues->getDejaUrlId() == $api->getDejaclickDeviceId() && strtolower($formValues->getLoginEmail()) == strtolower($api->getUsername()) && $formValues->getPassword() == $api->getPassword()) {
         Mage::getSingleton('adminhtml/session')->addSuccess("All settings identical");
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     }
     //Check to make sure all form fields are set before continueing
     if (!$formValues->getBasicSiteId() || !$formValues->getDejaUrlId() || !$formValues->getLoginEmail() || !$formValues->getPassword()) {
         Mage::getSingleton('adminhtml/session')->addError('All fields are required to recover/update your account');
         $valid = false;
     }
     //We have all required fields, now let's check them all
     if ($valid) {
         //First we'll chek to be sure we can login with the username/password provided
         $valid = $api->login($formValues->getLoginEmail(), $formValues->getPassword());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError('Unable to login with provided Login Email and Account Password values - please check');
         }
     }
     //Then we'll check each DejaClick and Device ID to be sure they exist and are enabled
     if ($valid) {
         $valid = $api->verifyDejaDevice($formValues->getDejaUrlId(), $formValues->getLoginEmail());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError("Problem with DejaClick Device ID - " . $api->getErrorMessage());
         }
     }
     if ($valid) {
         $valid = $api->verifySiteDevice($formValues->getBasicSiteId(), $formValues->getLoginEmail());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError("Problem with Site Device ID - " . $api->getErrorMessage());
         }
     }
     if (!$valid) {
         Mage::getSingleton('core/session')->setFormData($formValues);
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     } else {
         //We've validated their account details, now we need to actually save the information to the config
         //$api->getApiReturnData()->
         $api->setCustId((string) $api->getApiReturnData()->Request->Custid);
         $api->setLogin(strtolower($formValues->getLoginEmail()));
         $api->setPass($formValues->getPassword());
         $api->setSiteUrl((string) $api->getApiReturnData()->Request->Device->Descrip);
         $api->setSiteId($formValues->getBasicSiteId());
         $api->setDejaId($formValues->getDejaUrlId());
         $api->save();
         Mage::getSingleton('adminhtml/session')->addSuccess("AlertSite configuration saved");
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     }
 }