/**
 * Script for calling the api and returning the code to include.
 * This script simply makes an AJAX request on the API and return the answer
 * to the calling site, so that one can include widgets on his page.
 *
 * @author Martin Albrecht <martin.albrecht@javacoffee.de>
 * @version 2010-08-24
 */
//var url = "http://www.gewinnspiele.com/api/api.php?src="+widgetType;

if( typeof widgetType === 'undefined' ) {
  widgetType = 'newLotteries.htm';
}

//function createCORSRequest(method, url){
//    var xhr = new XMLHttpRequest();
//    if ("withCredentials" in xhr){
//        xhr.open(method, url, true);
//    } else if (typeof XDomainRequest != "undefined"){
//        xhr = new XDomainRequest();
//        xhr.open(method, url);
//    } else {
//        xhr = null;
//    }
//    return xhr;
//}
//
//var request = createCORSRequest("get", url, true);
//if (request){
//    request.onload = function(){
//        document.write(request.responseText);
//        //do something with request.responseText
//    };
//    request.send();
//}

//var invocation = new XMLHttpRequest();
//
//
//function callOtherDomain() {
//  if(invocation) {
//    invocation.open('GET', url, true);
//    invocation.onreadystatechange = handler;
//    invocation.send();
//  } else {
//    alert("No Invocation TookPlace At All");
//  }
//}
//
//function handler(evtXHR) {
//  if (invocation.readyState == 4) {
//    if (invocation.status == 200) {
//      var response = invocation.responseXML;
//      document.write(response);
//    } else {
//      alert("Invocation Errors Occured: "+invocation.status);
//    }
//  } else {
//    dump("currently the application is at" + invocation.readyState);
//  }
//}
//
//callOtherDomain();

var xmlhttp = null;
var url = "http://www.gewinnspiele.com/api/api.php?src=";
//var url = "api.php?src=";

if(window.XMLHttpRequest) {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp = new XMLHttpRequest();  
} else {
  // code for IE6, IE5
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  //xmlhttp = new XDomainRequest();
}

xmlhttp.obj = this.obj;
xmlhttp.onreadystatechange = function() {
  if( xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    document.getElementById('gsComWidgetDiv').innerHTML = xmlhttp.responseText;
    //document.write(xmlhttp.responseText);
  }
}

if(window.XMLHttpRequest) {
  xmlhttp.open("GET", url+widgetType, true);
} else {
  xmlhttp.open("GET", url+widgetType, false);
}
xmlhttp.send(null);
