
function handleError()
{
return true;
}
window.onerror = handleError;


$(document).ready(function() {
	// form check boxes
		var buttons = $('div.form fieldset input.submitalign, #check').button();
				
	// form dates overlays
		$('input[type="date"]').datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'dd/mm/yy' 
		});	
		$('.DatePicker').datepicker({
			changeMonth: true,
			changeYear: false,
			dateFormat: 'dd/mm/yy' 
		});	
		

    // notifications and cookies
    $("#accessnotificationclose").click(function() {
        $(".accessnotification").slideUp();
        $.cookie('access_notification', 'shown', { expires: 150000 }); // cookie time!
        return false;        
    });
    var access_notification = $.cookie('access_notification');
    if (access_notification == 'shown') {
        $(".accessnotification").hide();                           
    };

    $("#dashboardnotificationclose").click(function() {
        $(".dashboardnotification").slideUp();
        $.cookie('dashboard_notification', 'shown', { expires: 150000 }); // cookie time!
        return false;        
    });
    var dashboard_notification = $.cookie('access_notification');
    if (dashboard_notification == 'shown') {
        $(".dashboardnotification").hide();                           
    };
    
    
    // dashboard modals
    
		$(".passwordchange").dialog({
			resizable: false,
			height:400,
			width: 300,
			modal: true,
			autoOpen: false,
			resizable: false
		});	
		
		$("a.passwordchangebutton").click(function() {
		
		    $('a.fauxpassword').click();
		    

		});	
		
		$("a.profilechangebutton").click(function() {
		
		    $('a.fauxprofile').click();
		   

		});			
		
		
	// form modal overlay: terms and conditions
		$("#dialog-confirm").dialog({
			bgiframe: true,
			modal: true,
			height:450,
			width: 500,
			autoOpen: false,
			position: 'top',
			resizable: false,
			buttons: {
				'Accept': function() {
					$("#terms").attr('checked', true);
					$(this).dialog('close');
				},
				'Decline': function() {
					$("#terms").attr('checked', false);
					$(this).dialog('close');
				}
			}
		});	
		

    $("#submitfriend").click(function() {   
        // First, disable the form from submitting
        $('#subForm').submit(function() { return false; });
        
        // Grab form action
        formAction = $("#theForm form").attr("action");

        
        // Hacking together id for email field
        // Replace the xxxxx below:
        // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
        id = "dkkijl";
        emailId = id + "-" + id;
        
        // Validate email address with regex
        if (!checkEmail(emailId)) 
        {
            alert("Please enter a valid email address");
            return;
        }
        
        // Serialize form values to be submitted with POST
        var str = $("#subForm").serialize();

        // Add form action to end of serialized data
        final = str + "&action=" + formAction;
        
        $.getJSON("http://www.websuite.co.nz/mail/proxy.php?"+final+'&jsonpcallback=?',
            function(data){
                //Check to make sure that the email was accepted
                if (data != 'success') {
                    alert('There was an error submitting your subscription.');
                }
                else
                {
                    //$("#theForm").hide(); // If successfully submitted hides the form
                    
                    $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
                }
            }
        );      
    });



	
		
		

	// form slider
		
		$(".inlineslider").parent().find('input').val(0 + '%');
		$(".inlineslider").slider({
			range: "min",
			value: 0,
			min: 0,
			max: 100,
			step: 5,
			slide: function(event, ui) {
				$(this).parent().find('input').val(ui.value + '%');
			}
		});	
		$(".inlineslider").parent().find('input').change(function() {
			var tempval = $(this).val();
			var tempval2 = parseInt(tempval);

			$(this).parent().parent().find('.inlineslider').slider( 'value' , tempval2 );
			$(this).val(tempval2 + '%');
		});
		
		
	// form autofills
		$("input#region").autocomplete({
			delay: 0,
			source: ["aaaaa", "aaabbb", "aaaaccc", "aaaaddd", "aaaaarrr", "aaaaafff", "aaaaeee"]
			
		});
		$("input#subregion").autocomplete({
			delay: 0,
			source: ["aaaaa", "aaabbb", "aaaaccc", "aaaaddd", "aaaaarrr", "aaaaafff", "aaaaeee"]
		});
		$("input#industry").autocomplete({
			delay: 0,
			source: ["aaaaa", "aaabbb", "aaaaccc", "aaaaddd", "aaaaarrr", "aaaaafff", "aaaaeee"]
		});
		$("input#description").autocomplete({
			delay: 0,
			source: ["aaaaa", "aaabbb", "aaaaccc", "aaaaddd", "aaaaarrr", "aaaaafff", "aaaaeee"]
		});
		
	// form progress bar	
		$("#formprogress").slider({
			range: "min",
			value: 51,
			min: 0,
			max: 100
		});	
		$("#formprogress").slider( 'disable' );
 
	    // form login form
    	
	    //$("#headeruser").keyup(function () {
        //    var value = $(this).val();
        //    $("#ctl00_ContentPlaceHolder1_userForm_tbLogon").val(value);
        //}).keyup();
        
        //$("#headerpassword").keyup(function () {
        //    var value = $(this).val();
        //    $("#ctl00_ContentPlaceHolder1_userForm_tbPassword").val(value);
        //}).keyup();
        
        //$('#headerlogin_submit').bind('click', function() {
        //    $('#ctl00_ContentPlaceHolder1_userForm_btnLogon').click();
        //    return false;
        //});
        
    });
    
    
                function checkEmail(email)
                {              
                                var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                                var emailVal = $("#" + email).val();
                                return pattern.test(emailVal);
                }


