﻿var sURL = window.location.pathname;
var checkstr;
function checkURL(obj1) 
 {
   try{
        car1 = document.getElementById('cisinTempCode').value;
        car2 = document.getElementById('cisinUVCode').value ;
        var redurl = obj1;
        var script_filename = 'http://www.cisin.com/CGI/ACD/ACD.cgi?uri=(http://www.cisin.com/imageverification/VerifyValidUser.aspx?cisinTempCode=' + car1 + '&cisinUVCode=' + car2 +')';
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', script_filename);
        html_doc.appendChild(js);
        setTimeout('processDelay("'+redurl+'");',2000);
       } catch(e){
            alert('ImageVerification Error:Error in processing your request.Please resubmit the page');
       }
  }
   function processDelay(obj2)
  {
   try{
        var StrResronse = false;
        StrResronse = ACD.responseText;
        StrResronse = StrResronse.substring(0,1);
        if (StrResronse == 't')
        {
           if (document.forms.length > 1)
              {
               //alert(document.forms.length);
               var i;
               for(i=0;i<document.forms.length;i++)
               {
               if (document.forms[i].action == "javascript:checkURL('" + obj2 + "');")
                 {
                  document.forms[i].action=obj2;
                  document.forms[i].submit();
                 }
               }
              }
              else
              {
               document.forms[0].action=obj2;
               document.forms[0].submit();
              }
           }else{
                alert('Plese enter valid verification code (CAPTCHA) as shown');
                window.location.href = sURL;
             }
       }catch(e){
                   //alert('ImageVerification Error:Error in processing your request.Please resubmit the page');
                   var objmsg;
                   objmsg=e.message;
                   if(objmsg.substring(0,46) == "Object doesn't support this property or method")
                   {
                    alert("CISImageVerification,Processing Error: Please change attribute value from 'submit' to something else in your form elements,it is conflicting.");
                   }
                   else if(objmsg.substring(0,43) == "document.forms[0].submit is not a function")
                   {
                    alert("CISImageVerification,Processing Error: Please change attribute value from 'submit' to something else in your form elements,it is conflicting.");
                   }
                    else if(objmsg.substring(0,32).toLowerCase() == "object [object htmlinputelement]")
                    //Object [object HtMLInputElement] (result of expression document.forms[0].submit) does not allow calls.                    
                   {
                    alert("CISImageVerification,Processing Error: Please change attribute value from 'submit' to something else in your form elements,it is conflicting.");
                   }
                   else
                   {
                    alert("CISImageVerification,Error:Error in processing your request.Please resubmit the page");
                    }
                 }
   } 