﻿/*
 *   This file runs on every page, every time they are loaded. Do not remove it, it's a core file.
 *
 */
 
 
 
 /* Init */

 $(document).ready(function(){

    // Labels for forms
    $(":text").labelify();
 
    // Datepickers for date input fields
    $('input.date').datepicker();
	
	// Initialise tabs
	$('.tabs').tabs();
 
 });
 
// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w;
	var h;
	if(width) {
		w = width;	 
	} else {
		w = 500;	
	}
	if(height) {
		h = height;	 
	} else {
		h = 'auto';	
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			// Load the AJAX fetched content
			$("#dialog").html(data);
			// IE doesn't run the JS, so we'll do that manually
			if ($.browser.msie) {
				$(data).find('script').each(function(){
					eval($(this).html());									 
				});
			}	
		}
    });
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false,
		autoOpen: true
    });
}

function SendArticle(id) {
    var tmp = '';
    if ($("#Email1").get(0).value == '') { tmp += 'Your email is a required field\n' }
    if ($("#Email2").get(0).value == '') { tmp += 'Recipient email is a required field\n' }
    if (tmp != '') { alert(tmp); return }
    //Send article
    var url = "/webservices/WebService.asmx/SendArticle?ArticleID=" + id + "&Email1=" + $("#Email1").get(0).value + "&Email2=" + $("#Email2").get(0).value + "&Message=" + $("#EmailMessage").get(0).value + ""
    $.get(url);
    alert('Thank you')
    $("#dialog").html('').dialog('destroy');
}
