//var domainName="http://www.dukewalk.com/";
var domainUrl = "http://www.dukewalk.com/";
//method to go to dulk walk domain
function dukewalk(domain) {
    window.location = domainUrl + "dw/" + domain;
}
//method will redirect dulkwalk show all the domain that are related to this search
//terms.
function dukesearch(search) {
    window.location = domainUrl + "dw/?search=true&domain=" + search;
}
//This method shall return such a dulk walk domain exists or not.
function dukewalk_exists(domain) {
    make_ajax_request(domainUrl + "dw/", "?exists=true&domain=" + domain);
}
//This method shall return current url for this dukewalk domain.
//It may be a dns domain or if it may be based on ip,port,etc.
//Result Example :  http://www.google.com/
//  http://10.2.3.4:8080/
function dukeurl(domain) {
    var req = domainUrl + "dw/?geturl=true&domain=" + domain;
     make_ajax_request(req,"");
}

function dukehostorip(domain) {
    var req = domainUrl + "dw/?gethost=true&domain=" + domain;
     make_ajax_request(req,"");
}
function dukeport(domain) {
    var req = domainUrl + "dw/?getport=true&domain=" + domain;
     make_ajax_request(req,"");
}
function dukeprotocol(domain) {
    var req = domainUrl + "dw/?getprotocol=true&domain=" + domain;
     make_ajax_request(req,"");
}
function dukecontext(domain) {
    var req = domainUrl + "dw/?getcontext=true&domain=" + domain;
     make_ajax_request(req,"");
}

// shall take you to a particular domain  page
// if a domain is "command engine" and page is demo.jsp
//and the resulting url for domain is http://1.2.3.4/
//then it shall take you to http://1.2.3.4/demo.jsp
function dukewalk_page(domain, page) {
    window.location = domainUrl + "dw/?domain=" + domain + "&page=" + page;
}
//User can send adminstrative message to the domain owner if he need to send some
//sort message.
function dukecontact_page(domain, message) {
    window.location = domainUrl + "dw/?domain=" + domain + "&contact=" + message;
}

//special way to submit a form.
function dukewalk_command(domain, command) {
    window.location = domainUrl + "dw/?domain=" + domain + "&command=" + command;
}

//Followings are ajax way to do walk , search , url,etc.
function dukewalk_ajax(domain) {
    make_ajax_request(window.location + "dw/", "?domain=" + domain + "&ajax=true");
}
function dukesearch_ajax(search) {
    make_ajax_request(domainUrl + "dw/", "?search=true&domain=" + search + "&ajax=true");
}

function dukeurl_ajax(domain) {
    make_ajax_request(domainUrl + "dw/", "?geturl=true&domain=" + domain + "&ajax=true");
}

var http_request = false;
function make_ajax_request(url, parameters) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    }
    if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('GET', url + parameters, true);
    http_request.send(null);
}
var result = null;
function alertContents() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;
        } else if (http_request.status == 302) {
            alert('The ajax response was.' + http_request.responseText);
            window.location = http_request.responseText;
        }
        else {
            alert('There was a problem with the request.' + http_request.status);
        }
    }
}

