/* vim: set expandtab tabstop=4 shiftwidth=4: */

var browserVersion = parseInt(navigator.appVersion);
var isNetscape = navigator.appName.indexOf("Netscape") != -1;
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var agent = navigator.userAgent.toLowerCase();
var isWindows = agent.indexOf("win") != -1;
var isMac = agent.indexOf("mac") != -1;
var isNix = agent.indexOf("X11") != -1;

function doConfirm(text)
{
    var val = confirm(text);
    return (!val) ? false : true;
}

function previewCharityWidget() {
	if (validateCharityWidget()) {
		$('div.toolsForm div#previewPane div#preview').fadeOut('slow', function() { $("div.toolsForm div#previewPane").css("border", "1px solid #000000"); $('div.toolsForm div#previewPane div.loader').fadeIn('slow'); });
		$.get("/tools/xhr-charity-widget/?stage=preview", $('div.toolsForm form#charityWidget').serialize(), function (message) {
			$("div.toolsForm div.loader").fadeOut('slow', function() { $("div.toolsForm div#previewPane div#preview").html(message); $("div.toolsForm div#previewPane div#preview").fadeIn('slow'); });
	    });
	}
		
	return false;
}

function generateCharityWidget() {
	if (validateCharityWidget()) {
		$('div.toolsForm div#previewPane div#preview').fadeOut('slow', function() { $("div.toolsForm div#previewPane").css("border", "1px solid #000000"); $('div.toolsForm div#previewPane div.loader').fadeIn('slow'); });
		$.get("/tools/xhr-charity-widget/?stage=generate", $('div.toolsForm form#charityWidget').serialize(), function (message) {
			$("div.toolsForm div.loader").fadeOut('slow', function() { $("div.toolsForm div#previewPane div#preview").html(message); $("div.toolsForm div#previewPane div#preview").fadeIn('slow'); });
	    });
	}
		
	return false;
}

function validateCharityWidget() {
	var valid = true;
	
	$('div.toolsForm form#charityWidget input:text').each(function() {
		if ($(this).attr("value") == "") {
			alert("Please Enter Your " + $(this).attr("rel"));
			valid = false;
			return false;
		}
	});
	
	return valid;
}

function sendContactBoxEmail() {
    $.get("/contact/xhr-box", $('div.contactBox form#contactBox').serialize(), function (message) {
        $("div.contactBox div.loader").fadeOut('slow', function() { $("div.contactBox div.returnMessage").html(message); $("div.contactBox div.returnMessage").fadeIn('slow'); });
    });
}

function sendCommentBoxEmail() {
    $.get("/blog/xhr-comment", $('div.commentBox form#commentBox').serialize(), function (message) {
        $("div.commentBox div.loader").fadeOut('slow', function() { $("div.commentBox div.returnMessage").html(message); $("div.commentBox div.returnMessage").fadeIn('slow'); });
    });
}

function validateCommentBox() {
    var valid = true;
    if ($('div.commentBox form#commentBox textarea.message').text() == "") {
        $(this).addClass('invalid');
        $(this).text('Please enter a comment');
        valid = false;
    }

    alert(valid);
    return false;
}
