//function download(sermon_id) {
//  var input = eval("document.forms.download_form_"+ sermon_id +".download_select_"+ sermon_id);
//  if (!input.value) {
//    input.style.background = "#ff5544";
//    return;
//  }
//  document.location = "http://www.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value;
//}


function download(sermon_id, ppsuid) {
  var input = eval("document.forms.download_form_"+ sermon_id +".download_select_"+ sermon_id);
   
  var PPSUID = ppsuid;
              cfid = "u_ui";
              cFID = document.getElementById(cfid);
              
              afid = "c_i";
              aFID = document.getElementById(afid);
              
              bfid = "u_i";
              bFID = document.getElementById(bfid);
              
  if (!input.value) {
    input.style.background = "#ff5544";
    return;
  }
  if (!cFID.value) {
    cFID.value = 0;
    return;
  }
  //document.location = "http://www.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value;
  //window.open("http://www.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value + "&ck=" + bFID.value + ":" + aFID.value,'download'); 
  //document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value + "&ppsuid=" + cFID.value + "&ck=" + bFID.value + ":" + aFID.value,'download'; 
  document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value + "&ppsuid=" + cFID.value,'download'; 
}


function download_motion(sermon_id, ppsuid) {
  var input = eval("document.forms.download_form_"+ sermon_id +".download_select_"+ sermon_id);
  
  var PPSUID = ppsuid;
              cfid = "u_ui";
              cFID = document.getElementById(cfid);
  
              afid = "c_i";
              aFID = document.getElementById(afid);
              
              bfid = "u_i";
              bFID = document.getElementById(bfid);
              
  if (!input.value) {
    input.style.background = "#ff5544";
    return;
  }
 // alert(cFID.value);
  
  //document.location = "http://www.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value;
  //window.open("http://www.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text="+ input.value + "&ck=" + bFID.value + ":" + aFID.value,'download'); 
 //document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text="+ input.value + "&ck=" + bFID.value + ":" + aFID.value,'download'; 
 document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text="+ input.value,'download'; 
}

function resetDLWarn() { 
              fid = "downloadWarn";
              FID = document.getElementById(fid);
              FID.style.display = "none";
}

function download_select(sermon_id, ppsuid) {
  
              afid = "c_i";
              aFID = document.getElementById(afid);
              
              bfid = "u_i";
              bFID = document.getElementById(bfid);
              
  var PPSUID = ppsuid;
              cfid = "u_ui";
              cFID = document.getElementById(cfid);
  
              ds1 = "option1";
              DS1 = document.getElementById(ds1);
              ds2 = "option2";
              DS2 = document.getElementById(ds2);
              ds3 = "option3";
              DS3 = document.getElementById(ds3);
              ds4 = "option4";
              DS4 = document.getElementById(ds4);
              fid = "downloadWarn";
              FID = document.getElementById(fid);
          
        if (DS1.checked == true) { 
            //document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=text" + "&ppsuid=" + cFID.value   + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=text" + "&ppsuid=" + cFID.value,'download';
        }
        else if (DS2.checked == true) {
            //document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=notext" + "&ppsuid=" + cFID.value  + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=notext" + "&ppsuid=" + cFID.value,'download';
        }
        else if (DS3.checked == true) {
            //document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=blank" + "&ppsuid=" + cFID.value  + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=blank" + "&ppsuid=" + cFID.value,'download';
        }
        else if (DS4.checked == true) {
            //document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=zip" + "&ppsuid=" + cFID.value  + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://ppt.powerpointsermons.com/?page=download&sermon_id="+ sermon_id +"&text=zip" + "&ppsuid=" + cFID.value,'download';
        }
        else {
          FID.style.display = "";
          return;
        }
                
}


function download_select_motion(sermon_id, ppsuid) {
  
              cfid = "u_ui";
              cFID = document.getElementById(cfid);
              
              afid = "c_i";
              aFID = document.getElementById(afid);
              
              bfid = "u_i";
              bFID = document.getElementById(bfid);
              
  
              ds1 = "option1";
              DS1 = document.getElementById(ds1);
              ds2 = "option2";
              DS2 = document.getElementById(ds2);
              ds3 = "option3";
              DS3 = document.getElementById(ds3); 
              fid = "downloadWarn";
              FID = document.getElementById(fid);
          
        if (DS1.checked == true) { 
            //document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=mpg"  + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=mpg",'download';
        }
        else if (DS2.checked == true) {
            //document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=mp4" + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=mp4",'download';
        }
        else if (DS3.checked == true) {
            //document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=wmv" + "&ck=" + bFID.value + ":" + aFID.value,'download';
            document.location = "http://video.powerpointsermons.com/?page=download&sermon_id="+ sermon_id + "&ppsuid=" + cFID.value +"&text=wmv",'download';
        } 
        else {
          FID.style.display = "";
          return;
        }
                
}


function download_sample() {
              
              
              
              
              ds1 = "dl_1";
              DS1 = document.getElementById(ds1);
              ds2 = "dl_2";
              DS2 = document.getElementById(ds2);
              ds3 = "dl_3";
              DS3 = document.getElementById(ds3);
              ds4 = "dl_4"; 
              DS4 = document.getElementById(ds4);
              ds5 = "dl_5"; 
              DS5 = document.getElementById(ds5);
              ds6 = "dl_6"; 
              DS6 = document.getElementById(ds6);
              ds7 = "dl_7"; 
              DS7 = document.getElementById(ds7);
              fnid = "dlname";
              FNID = document.getElementById(fnid);
              emid = "dlemail";
              EMID = document.getElementById(emid);
              phid = "dlphone";
              PHID = document.getElementById(phid);
              hid = "reg_user_how";
              HID = document.getElementById(hid);
              hoid = "reg_how_other";
              HOID = document.getElementById(hoid);
              sid = "sample_id_ppt";
              SID = document.getElementById(sid);
              sid2 = "sample_id_motion";
              SID2 = document.getElementById(sid2);
              
              
              
              sample_id1 = SID.value;
              sample_id2 = SID2.value;
              
              goodSubmit = true;
              error = "Please complete the following and click submit again:";
              
              var inputname = eval(FNID);
              if (!inputname.value) {
                error = error + "\r\n- Please enter your name";
                goodSubmit = false;
              }
              var inputemail = eval(EMID);
              if (!inputemail.value) {
                error = error + "\r\n- Please enter your email address";
                goodSubmit = false;
              }
              var inputphone = eval(PHID);
              if (!inputphone.value) {
                error = error + "\r\n- Please enter your phone number";
                goodSubmit = false;
              }
              var inputhow = eval(HID);
              if (!inputhow.value) {
                error = error + "\r\n- Please let us know how you heard about us";
                goodSubmit = false;
                
              }
              else {
                otherQuery = "&how=" + inputhow.value;
              }
              if (inputhow.value == "Other" || inputhow.value == "other") {
                var inputhowother = eval(HOID);
                if (!inputhowother.value) {
                  error = error + "\r\n- Please let us know the other way you heard about us";
                  goodSubmit = false;
                }
                else {
                  otherQuery = "&how=" + inputhow.value + "&how_other=" + inputhowother.value;
                }
              }
               
              if (goodSubmit) {
                      if (DS1.checked == true) { 
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id1 +"&text=text"  + "&name=" + inputname.value + "&phone=" + inputphone.value + "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS2.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id1 +"&text=notext"  + "&name=" + inputname.value + "&phone=" + inputphone.value +  "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS3.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id1 +"&text=blank"  + "&name=" + inputname.value + "&phone=" + inputphone.value +  "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS4.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id1 +"&text=zip"  + "&name=" + inputname.value + "&phone=" + inputphone.value +  "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS5.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id2 +"&text=mpg"  + "&name=" + inputname.value + "&phone=" + inputphone.value +  "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS6.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id2 +"&text=mp4"  + "&name=" + inputname.value + "&phone=" + inputphone.value +  "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else if (DS7.checked == true) {
                            document.location = "http://www.powerpointsermons.com/?page=sample_download&sample_id="+ sample_id2 +"&text=wmv"  + "&name=" + inputname.value +  "&phone=" + inputphone.value + "&email=" + inputemail.value + otherQuery ,'download';
                        }
                        else {
                          alert("Please select a download option to continue.");
                          return;
                        }
              }
              else {
                alert(error);
                return;
              }
                 
}
            
            
function download_cpartner(sample_id) {
              
              fid = "download_select_sample";
              FID = document.getElementById(fid);
              var input = eval(FID);
              if (!input.value) {
                input.style.background = "#ff5544";
                return;
              } 
              document.location = "http://www.powerpointsermons.com/?page=cpartner_download&sample_id="+ sample_id +"&text="+ input.value;
            }

function two_free_download() {
  var input1 = eval("document.forms.download_form.name");
  var input2 = eval("document.forms.download_form.email");
 
  
  if (!input1.value) {
    input1.style.background = "#ff5544";
    var alert1 = true;
    var input_er = true; 
  }
  
  if (!input2.value) {
    input2.style.background = "#ff5544";
    var alert2 = true;
    var input_er = true; 
  }
  else {
    var email_check = emailCheck(input2.value);
    if (!email_check) {
      input2.style.background = "#ff5544";
      var input_er = true; 
    }
  }
  
  if (alert1 && alert2) {
    alert("Please provide us your name and email address to continue.");
  }
  else if (alert1) {
    alert("Please provide us your name to continue.");
  }
  else if (alert2) {
    alert("Please provide us a valid email address to continue.");
  }
  
  if (input_er) {
    return;
  }
  
  document.location = "http://www.powerpointsermons.com/?page=two_free_get&action=submit&name="+ input1.value +"&email="+ input2.value;
}


 
function emailCheck (emailStr) {
  var emailPat=/^(.+)@(.+)$/
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  var validChars="\[^\\s" + specialChars + "\]"
  var quotedUser="(\"[^\"]*\")"
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  var atom=validChars + '+'
  var word="(" + atom + "|" + quotedUser + ")"
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) {
    
          alert("Please enter a valid email address to continue. Email address seems incorrect (check @ and .'s)");
          
          return false
  }
  var user=matchArray[1]
  var domain=matchArray[2]
  
  if (user.match(userPat)==null) {
      alert("Please enter a valid email address to continue. The username doesn't seem to be valid.")
      return false
  }
  
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) {
            for (var i=1;i<=4;i++) {
              if (IPArray[i]>255) {
                  alert("Please enter a valid email address to continue. Destination IP address is invalid!")
                  return false
              }
      }
      return true
  }
  var domainArray=domain.match(domainPat)
  if (domainArray==null) {
          alert("Please enter a valid email address to continue. The domain name doesn't seem to be valid.")
      return false
  }
  
  var atomPat=new RegExp(atom,"g")
  var domArr=domain.match(atomPat)
  var len=domArr.length
  if (domArr[domArr.length-1].length<2 || 
      domArr[domArr.length-1].length>3) {
     // the address must end in a two letter or three letter word.
     alert("Please enter a valid email address to continue. The address must end in a three-letter domain, or two letter country.")
     return false
  }
  
  if (len<2) {
     var errStr="Please enter a valid email address to continue. This address is missing a hostname!"
     alert(errStr)
     return false
  }
  return true;
} 
