﻿/// <reference path="intellisense/jquery-1.3.2-vsdoc2.js" />

$(document).ready(function() {
		
			// call the plugin on the desired form
			$("#aspnetForm").slideLock({
			
				// set the options - all are given, not all are required
				labelText: "<br/>Slide Verification<br/><span class='smalltext'>(Please slide the tab to the<br/> right when ready to send</span>) ",
				noteText: "",
				lockText: "Draft",
				unlockText: "Ready",
				iconURL: "/images/chrome/arrow_right.png",
				inputID: "sliderInput",
				onCSS: "#333",
				offCSS: "#aaa",
				inputValue: 1,
				saltValue: 9,
				checkValue: 10,
				js_check: "js_check",
				submitID: "#sendmail"
			
			});
			 
		});

$(function() {
    
    	
   

    $('#sendmail').bind('click', function(evt) {

        evt.preventDefault();
        if ($("#aspnetForm").valid()) {

            var dictionary = {};
            var query = {};
            //alert('test');
            dictionary = { "WebPartId": $(this).parents('.part').attr('id'), "Action": "PartAction", "PartAction": "SendMail", "Name": $('#txtname').val(), "Company": $('#txtcompany').val(), "EmailAddress": $('#txtemail').val(), "PhoneNumber": $('#txtphonenumber').val(), "SendDirectory": $('#chkUKDirectory').attr('checked'),"NewsType": $('#chkNewsType').attr('checked'), "Comments": $('#txtcomments').val() , "Address1": $('#txtAddress1').val(), "Address2": $('#txtAddress2').val(), "Town": $('#txtTown').val(), "County": $('#txtCounty').val(), "Postcode": $('#txtPostcode').val()};
            //alert(dictionary.WebPartId + '-' + dictionary.Action + '-' + dictionary.PartAction + '-' + dictionary.Name + '-' + dictionary.Company + '-' + dictionary.EmailAddress + '-' + dictionary.PhoneNumber);
            query.dic = dictionary;
            $.ajax({
                type: "POST",
                url: "/errors.aspx/GetActionsPart",
                data: JSON.stringify(query),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(obj) {
                    //alert('send button clicked');
                    if (obj.Scripts != null && obj.Scripts.length > 0) {
                        $(obj.Scripts).each(function() {
                            eval(this.toString());
                        });
                    }
                }
            });
        }
        return false;
    });

    validateContactUsForm();
});


function validateContactUsForm() {
    // validate signup form on keyup and submit
  
    $("#aspnetForm").validate({
        debug: true,
        success: "valid",
        errorPlacement: function(error, element) {
            var placement = element.parent().find('label');
            error.insertAfter(placement);
        },
        rules: {
            txtname: {
                required: true,
                minlength: 3 
            },
            txtcompany: {
                required: true,
                minlength: 3
            },
            txtemail: {
                required: true,
                email: true

            },
            txtphonenumber: {
                required: true,
                digits: true,
                minlength: 8

            },
             txtAddress1: {
                required: true,
                minlength: 3
            },
            txtTown: {
                required: true,
                minlength: 3
            },
            txtCounty: {
                required: true,
                minlength: 3
            },
            txtPostcode: {
                required: true,
                minlength: 3
            },
            messages: {
            txtname: {
                    required: "Please, enter your name"
                    //,range: "Please select a form type"
                },
                txtcompany: {
                    required: "Please, enter your company name"
                   
                },
                txtemail: {
                    required: "Please, enter your email address",
                    email: "Please, enter a valid email address"
                },
                txtphonenumber: {
                    required: "Please, enter your contact phonenumber"
                }
            }
        }
    });
}

