

function setPayPalChromeDirty() {

  // called by on click in chrome
  
  
  // TODO: need to put in check for chrome
       /*
        *  toggle to dirty now
        */

      setPaypalClickState("dirty");
        


}

function doReload() {

   // called by mouse over in chrome
   
   
   // TODO: get in the check for chrome here
   var state = getPaypalClickState();
   //alert("state is: "+state);
   if (state == "dirty")
   {   
       /*
        *  toggle to ready then reload
        */
       setPaypalClickState("ready");
       window.location.reload();
   }
}

function getPaypalClickState() {

      var paypalClickStateVal = "ready"; //document.getElementsByName("paypalClickState");
      
      var stateArray = document.getElementsByName("paypalClickState");
      
      for (i=0;i < stateArray.length;i++)
      {
        //alert(i+" "+stateArray[i].value);
        //document.getElementsByName("myInput")[i].value=''
        if (stateArray[i].value == "dirty")
        {
            paypalClickStateVal = "dirty";
        }
      }
      
      return paypalClickStateVal;
}


function setPaypalClickState(state) {

 
      //alert("setting click state to: "+state);   
      for (i=0;i < stateArray.length;i++)
      {
          document.getElementsByName("paypalClickState")[i].value=state;
      }
}

function payPalChromeCheck() {
    //alert("in the global file...");
    
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);

   //alert("Browser name: "+ browser+" Browser version: "+ version);
   
    // alert(" getting user agent ");
  var userAgent =  navigator.userAgent.toLowerCase();
  //alert(" "+userAgent);
  
  var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
  
  //alert("is chrome is set to: "+is_chrome);
  if (is_chrome)
  {
      //alert("you are using chrome.");
      /*
       *  paypalClickState
       *    should only have 2 states
       *    
       *    ready and dirty
       * 
       *    if the users browser is chrome, this hidden input variable will be checked.
       *    if the variable is found to be 'dirty' this function will reset it to 'ready'
       *    and then reload the page.
       */
      
      var paypalClickStateVal = "ready"; //document.getElementsByName("paypalClickState");
      
      var stateArray = document.getElementsByName("paypalClickState");
      
      for (i=0;i < stateArray.length;i++)
      {
        //alert(i+" "+stateArray[i].value);
        //document.getElementsByName("myInput")[i].value=''
        if (stateArray[i].value == "dirty")
        {
            paypalClickStateVal = "dirty";
        }
      }
      
      //alert("paypalClickStateVal is: "+paypalClickStateVal);
      if (paypalClickStateVal == "dirty")
      {
          for (i=0;i < stateArray.length;i++)
          {  
              document.getElementsByName("paypalClickState")[i].value='ready';
          }
          window.location.reload();
          //document.forms[3].submit();
          
      }
      else 
      { 
          //alert("not going to reload page.  setting paypalClickState to dirty and then going straight to paypal...");
          for (i=0;i < stateArray.length;i++)
          {  
              document.getElementsByName("paypalClickState")[i].value='dirty';
          }
      }
  }
}
