
function GetPressRelease(){	
		emailwindow=dhtmlmodal.open('FileListBox', 'iframe', '/modalfiles/Login.asp', '', 'width=260px,height=140px,center=1,resize=0,scrolling=0')
}
function GetSampleLetter(){	
		emailwindow=dhtmlmodal.open('FileListBox', 'iframe', 'modalfiles/Letter.asp', '', 'width=560px,height=540px,center=1,resize=0,scrolling=0')
}

function validateLoginForm(){
        var LoginPassword = window.frames['_iframe-FileListBox'].document.forms['CommentCard'].elements['LoginPin'].value;
        
		if(LoginPassword != "Press"){
			alert("Please enter a valid password.");
		}
		else {
		    if (document.getElementById("FileListBox")) {document.getElementById("FileListBox").style.display = "none";}
		    emailwindow=dhtmlmodal.open('FileListBox', 'iframe', '/modalfiles/FileList.asp', '', 'width=450px,height=560px,center=1,resize=0,scrolling=0')
		}
}
function closeFileList(){
        if (document.getElementById("FileListBox")) {document.getElementById("FileListBox").style.display = "none";}  
	    document.getElementById("interVeil").style.display = "none";
	}




    function PaperlessOpen() {
		emailwindow=dhtmlmodal.open('RegisterBox', 'iframe', '/modalfiles/DD.asp', '', 'width=580px,height=490px,center=1,resize=1,scrolling=1')
        }
                
    function closeQuestionaire(){
        if (document.getElementById("RegisterBox")) {document.getElementById("RegisterBox").style.display = "none";}
	    document.getElementById("interVeil").style.display = "none";
	}
	
	
function DDContactDetails(){
	var sErrors = "";
	var bValid = true;   
    var BankType = "";
    var Agree = "";
        if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Agree'].checked == true) {Agree = "Agree"};
        if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Type1'].checked == true) {BankType = "Bank"};
        if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Type2'].checked == true) {BankType = "Building Society"};
    var BankName = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Name'].value;
    var BankAddress = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Address'].value;
    var BankPostcode = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['PostcodeBank'].value;
    var BankSort = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['SortCode'].value;
    var AccountHolder = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AccountName'].value;
    var AccountNo = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AccountNumber'].value;
    var Usage = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Amount'].value;
  
  
    if(Agree != "Agree"){sErrors = sErrors + "Please tick that you wish to set up a Direct Debit \n"; bValid = false;}
	if(BankType.length == 0){sErrors = sErrors + "Please tell us whether your account is with a bank or building society\n"; bValid = false;}
	
	if(BankName.length == 0 || BankName == "Name"){sErrors = sErrors + "Please tell us your bank or building society name\n"; bValid = false;}
	if(BankAddress.length == 0 || BankAddress == "Address"){sErrors = sErrors + "Please tell us your bank or building society address\n"; bValid = false;}
	if(BankPostcode.length == 0 || BankPostcode == "Postcode"){sErrors = sErrors + "Please tell us your bank or building society postcode\n"; bValid = false;}
	if(BankSort.length != 6 || BankSort == "Sort code"){sErrors = sErrors + "Please tell us your bank or building society sort code\n"; bValid = false;}
	
	if(IsNumeric(BankSort) == false){sErrors = sErrors + "Please tell us a valid bank or building society sort code\n"; bValid = false;}
	
	if(AccountHolder.length == 0 || AccountHolder == "Name of account holder"){sErrors = sErrors + "Please tell us the name of the account holder\n"; bValid = false;}
	if(AccountNo.length != 8 || AccountNo == "Account number"){sErrors = sErrors + "Please tell us your account number\n"; bValid = false;}
	
	if(IsNumeric(AccountNo) == false){sErrors = sErrors + "Please tell us a valid account number\n"; bValid = false;}
	
	if(Usage.length == 0 || Usage < 10 ){sErrors = sErrors + "Please tell us your estimated usage per month (min £10.00) \n"; bValid = false;}
	

    

	    if(bValid == false)
	    {
		    alert(sErrors);
	    }
	    else {
	    	    
	    window.frames['_iframe-RegisterBox'].document.getElementById("panel3").style.display = "block";
	    window.frames['_iframe-RegisterBox'].document.getElementById("panel2").style.display = "none";
	    window.frames['_iframe-RegisterBox'].document.getElementById("Div1").style.display = "none";
          
	    }
	}

function sendPaperless(){
	var sErrors = "";
	var bValid = true;   
    var Agree = "";
    var Contact = "";
    if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AgreePay'].checked == true) {Agree = "Agree"};
    if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AgreeContact'].checked == true) {Contact = "Dont Contact"};
    
    var Title = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Title'].value;
    var FirstName = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['FirstName'].value;
    var LastName = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['LastName'].value;
    var House = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['House'].value;
    var AddressLine1 = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AddressLine1'].value;
    var AddressLine2 = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AddressLine2'].value;
    var Town = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Town'].value;
    var Postcode = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Postcode'].value;
    var Country = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Country'].value;
    var Email = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Email'].value;
    var Email2 = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Email2'].value;

	if(Agree != "Agree"){sErrors = sErrors + "Please tick that you wish to pay from this account\n"; bValid = false;}
	if(Title.length == 0 || Title == "Title"){sErrors = sErrors + "Please tell us your title (eg Mr, Mrs, Sir)\n"; bValid = false;}
	if(FirstName.length == 0 || FirstName == "First name(s)"){sErrors = sErrors + "Please tell us your first name\n"; bValid = false;}
	if(LastName.length == 0 || LastName == "Last name"){sErrors = sErrors + "Please tell us your surname\n"; bValid = false;}
	if(House.length == 0 || House == "House name / number"){sErrors = sErrors + "Please tell us your house name or number \n"; bValid = false;}
	if(AddressLine1.length == 0 || AddressLine1 == "Address line 1"){sErrors = sErrors + "Please tell us your address \n"; bValid = false;}
	if(Town.length == 0 || Town == "Town / City"){sErrors = sErrors + "Please tell us your town or city \n"; bValid = false;}
	if(Postcode.length == 0 || Postcode == "Postcode"){sErrors = sErrors + "Please tell us your postcode \n"; bValid = false;}
	if(Email.length == 0 || Email == "Email"){sErrors = sErrors + "Please tell us your email address \n"; bValid = false;}
	if(Email2 != Email){sErrors = sErrors + "Please confirm your email address \n"; bValid = false;}

	if(bValid == false)
	    {
		    alert(sErrors);
	    }
	else {
	
        var BankType = "";
        if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Type1'].checked == true) {BankType = "Bank"};
        if (window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Type2'].checked == true) {BankType = "Building Society"};
        
        var BankName = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Name'].value;
        var BankAddress = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Address'].value;
        var BankPostcode = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['PostcodeBank'].value;
        var BankSort = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['SortCode'].value;
        var AccountHolder = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AccountName'].value;
        var AccountNo = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['AccountNumber'].value;
        var Usage = window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].elements['Amount'].value;
		    
	    // send Email
        var message = "";
          message += "<p>A visitor to your site has made a paperless DD instruction with the following details:</p>";
          
          message += "<p>Type: " + BankType + "<br/>";
          message += "Name: " + BankName + "<br/>";
          message += "Address: " + BankAddress + "<br/>";
          message += "Postcode: " + BankPostcode + "<br/>";
          message += "Sort code: " + BankSort + "<br/>";
          message += "Account number: " + AccountNo + "<br/>";
          message += "Account holder name: " + AccountHolder + "</p>";
          
          message += "<p>Estimated Usage: " + Usage + "<br/>";
          message += "Agree to use this account: " + Agree + "<br/>";
          message += "DO NOT contact for marketing: " + Contact + "</p>";
          
          message += "<p>Title: " + Usage + "<br/>";
          message += "FirstName: " + FirstName + "<br/>";
          message += "LastName: " + LastName + "<br/>";
          message += "House: " + House + "<br/>";
          message += "AddressLine1: " + AddressLine1 + "<br/>";
          message += "AddressLine2: " + AddressLine2 + "<br/>";
          message += "Town: " + Town + "<br/>";
          message += "Postcode: " + Postcode + "<br/>";
          message += "Country: " + Country + "<br/>";
          message += "Email: " + Email + "<br/>";
          
          message += "</p>";
           
          //send email to sales
          SendMessage ("payments@webpost.co.uk", "payments@webpost.co.uk", "", "dan@bagshots.com", "Paperless DD Instruction", message, "", "")
          window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].action = "Confirm.asp";
          window.frames['_iframe-RegisterBox'].document.forms['CommentCard'].submit();
          
	    }
	}
	
function SendMessage (from, to, cc, bcc, subject, message, attachments, path){
    var Email = "";
    Email += "&from=" + from;
    Email += "&to=" + to;
    Email += "&CC=" + cc;
    Email += "&BCC=" + bcc;
    Email += "&subject=" + subject;
    Email += "&message=" + message;
    Email += "&attachments=" + attachments;
    Email += "&attachmentsPath=" + path;
    ajaxOptions = {
        method: "post",
        parameters: Email,
        onSuccess: function(transport){
        }.bind(this),
        onFailure: function(){
            alert("There was a problem sending the email");
        }.bind(this),
        onComplete: function(){
        }.bind(this)
    };
    new Ajax.Request("/AjaxCalls/Email.aspx", ajaxOptions);
}
	
	
	
	function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

