/* AJAX for site */

function currency(type) {
var xml;
$("#totals").fadeOut('fast');
//window.location.hash = type;
    $.ajax({
        type: "GET",
        url: "http://jd.selfip.net/tel/premium-listing/ajax.php",
        data: "cur="+type,
        dataType: "html",
        success: function(xml) {
        //var permonth = '';
        //alert(xml);
            /* Pull results and display them */
            //$("totals",xml).each(function() {
            $(newXML).find('totals').each(function() {
                var string = $("string", this).html();
                var permonth = $(this).find('permonth').text();
                //var permonth = $("permonth", this).text();
                var symbol = $("symbol", this).html();
                $("#permonth").html(symbol + permonth);
                $('[name=epdqdata]').val(string);
                $('[name=symbol]').val(symbol);
                $('[name=permonth]').val(permonth);
                $('[name=curtype]').val(type);
                
            });
            //alert('yep' + symbol);
            $("#totals").fadeIn('slow');
            
        },
        error: function() {
            alert('Nope!');
        }
    });
    return false;
}

/* Check promo code */
	$("#promo-form").submit(function() {
		submitPromo();
		return false;
	});
	
	function submitPromo() {
		var promo = $("#promo-code").val();
		$.ajax({
	        type: "GET",
	        url: "http://jd.selfip.net/tel/premium-listing/ajax.php",
	        data: "checkpromo="+promo,
	        dataType: "html",
	        success: function(xml) {
	        alert(xml);
	        	$('promo',xml).each(function() {
                var string = $("string", this).html();
                var result = $("result", this).text(); 
	           	$("#promo-result").html(string);
	           	if (result === 'true') {
	           		$("#checkout-text").html('Please click on <strong>Confirm ></strong> to create your .tel listing.');
	           		$("#checkout-form").attr("action", "order-success.php?oid=<?php echo $_SESSION['ordernum']; ?>");
	           		$(".payment").fadeOut("slow");
	           		$("#totals").fadeOut("slow");
	           		$(".payment-terms").fadeOut("slow");
				} else {
					$("#checkout-text").html('Clicking on the <strong>Confirm ></strong> button will send you to our <strong>secure</strong> payment page.');
					$(".payment").fadeIn("slow");
					$(".payment-terms").fadeIn("slow");
				}        	
	        	});
	        },
	        error: function(e) { alert(e); }
	    });	
}

function showTweets() {
	$(".twitter").html('<p>Tweet\'s are loading...</p>');
    $.get("http://www.tel-listing.com/premium-listing/ajax.php", "t=1", function(xml) {
    $(".twitter").fadeOut('slow', function (){
    	$(".twitter").html(xml).fadeIn('slow');
  	});
	}, "text");
}

