﻿

function callCrossDomainAjax(site, callback, type) {

    if (!site) {
        alert('No site was passed.');
        return false;
    }

    var typ = "";
    if (type == "xml")
        typ = "xml";
    else
        typ = "json";
    var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from ' + type + ' where url="' + site + '"') + '&format=' + typ + '&_maxage=1&callback=?';

    //$.ajaxSetup({ cache: true });
    $.getJSON(yql, cbFunc);

    function cbFunc(data) {

        if (typeof callback == 'function') {
            if (type == "xml") {
                callback(data.results[0]);
            } else {
            callback(jQuery.trim(data.query.results.body.p));
                //callback(data.results[0]);
            }
        }

    }
}

