
function publish() {
	    var options = { 
        //target:        '#output1',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       redirect  // post-submit callback 
 
        // other available options: 
        //url:       "preview.php",         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#adminFrm').ajaxForm(options); 	
}

function redirect() {
	window.location = 'index.php';
}


function preview() {
	    var options = { 
        //target:        '#output1',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        // other available options: 
        url:       "preview.php"         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#adminFrm').ajaxForm(options); 	
}

 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	$('#preview_box').html( responseText);
	/*
	win = window.open(", ", 'popup', 'toolbar = no, status = no');
	win.document.write("" + responseText + "");
	*/
} 

function showMail(id) {
	var content = '';
	content += "<form id='mailFrm' action='sendmail.php' method='post'>";
	content += "<p>Your name: <input type='text' name ='name' id ='name' size='20' onchange='evlMail()'/></p>";
	content += "<p>Your email: <input type='text' name ='email' id ='email' size='20' onchange='evlMail()'/></p>";
	content += "<p>Friends' emails: - separated by &acute;;&acute; <input type='text' name ='femail' id ='femail' size='20' onchange='evlMail()'/></p>";
	content += "<p>Send me a copy: <input type='checkbox' name ='copy' id ='copy' /></p>";
	content += "<p><input type='submit' name='send' id='send' value='Send now' onclick='sendMail()' disabled></p>";
	content += "<input type='hidden' name='id' value='"+id+"'>";
	content += "</form>";
	
	$('#mail').empty();
	$('#mail').html(content);
	
}

function evlMail() {
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var femail = document.getElementById('femail').value;
	var copy = document.getElementById('copy').value;
	var btn = document.getElementById('send');
	
	if(name !='' && email !='' && femail !='') {
		btn.disabled = false;
	}
	
}

function sendMail() {
	 var options = { 
        //target:        '#output1',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       mailDone  // post-submit callback 
 
        // other available options: 
        //url:       "preview.php",         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
	
	var btn = document.getElementById('send');
 
    // bind form using 'ajaxForm' 
	btn.disabled = true;
	btn.value = 'Sending...';
    $('#mailFrm').ajaxForm(options); 
}

function mailDone(responseText, statusText) {
	$('#mail').empty();
	$('#mail').html(responseText);	
}

function send_client(region){
	var client_id = $("#client").val();
	var client_name = $("#client").children("[@selected]").text();
	client_name = client_name.replace(/\s+/g,'-');
	window.location = "http://www.lewiswire.com/"+region+"/lewiswire/"+client_name+"/c/"+client_id;
	
}

function del_client(id){
	var answer = confirm("Are you sure you want to delete this client?");
	if(answer){
		window.location = "?d_id="+id;
	}
}
/**

Here follows added JS by NP of Resolution Creative. It powers the LHS Sidebar show/hide archive

**/

$(document).ready(function(){
	$('h2.toggle:first')
		.append('<span style="padding-left:5px">-</span>')
		.css('cursor','pointer')
		.toggle(
			function(){
				$(this).next('div').slideUp('1800');	
				$(this).children('span').html('+');
			},
			function(){
				$(this).next('div').slideDown('1800');	
				$(this).children('span').html('-');
			}
		);


	$('h2.toggle:not(:first)')
		.append('<span style="padding-left:5px">+</span>')
		.css('cursor','pointer')
		.toggle(
			function(){
				$(this).next('div').slideDown('1800');	
				$(this).children('span').html('-');
			},
			function(){
				$(this).next('div').slideUp('1800');	
				$(this).children('span').html('+');
			}
		);
 	$('a.collapse')
        	.click(
            		function(){
                		$(this).parent('div').prev('h2.toggle').click()
             		}
        	);

});

