//This is not ajax! This is asynchron js request handling
// *********************
// Exception definitions
// *********************
function Exception() {
    this.message = new String();
    this.errorID = null;
}
Exception.prototype.getMessage = function() {
    return this.message;
}
Exception.prototype.getErrorID = function() {
    return this.errorID;
}
Exception.prototype.toString = function() {
    return this.message;
}
// MethodNotImplementedException Exception
function MethodNotImplementedException() {
    this.message = "Method Not Implemented!";
    this.errorID = 1;
}
MethodNotImplementedException.prototype = new Exception();
MethodNotImplementedException.constructor = MethodNotImplementedException;
// MethodNotImplementedException Exception end
// MicrosoftXMLHTTPInitErrorException Exception
function MicrosoftXMLHTTPInitErrorException() {
    this.message = "Microsoft.XMLHTTP could not be inited";
    this.errorID = 2;
}
MicrosoftXMLHTTPInitErrorException.prototype = new Exception();
MicrosoftXMLHTTPInitErrorException.constructor = MicrosoftXMLHTTPInitErrorException;
// MicrosoftXMLHTTPInitErrorException Exception end
// XMLHttpNotImplementedException Exception
function XMLHttpNotImplementedException() {
    this.message = "XMLHttp object could not be found!";
    this.errorID = 3;
}
XMLHttpNotImplementedException.prototype = new Exception();
XMLHttpNotImplementedException.constructor = XMLHttpNotImplementedException;
// XMLHttpNotImplementedException Exception end
// RSSVersionNotCompatibleException Exception
function RSSVersionNotCompatibleException() {
    this.message = "RSS Version not compatible";
    this.errorID = 4;
}
RSSVersionNotCompatibleException.prototype = new Exception();
RSSVersionNotCompatibleException.constructor = RSSVersionNotCompatibleException;
// XMLHttpNotImplemented Exception end
// DotMediaNewsVersionNotCompatibleException Exception
function DotMediaNewsVersionNotCompatibleException() {
    this.message = "Not Correct Version of DotMediaNews XML File";
    this.errorID = 5;
}
DotMediaNewsVersionNotCompatibleException.prototype = new Exception();
DotMediaNewsVersionNotCompatibleException.constructor = DotMediaNewsVersionNotCompatibleException;
// DotMediaNewsVersionNotCompatibleException Exception end
// *************************
// Exception definitions end
// *************************

// *********************
// DXMLHttpRequest Class
// *********************
function DXMLHttpRequestShell() {
    this.XMLHttp = null;
    
    this.init();
}
DXMLHttpRequestShell.prototype.init = function() {
    if (window.ActiveXObject) {
        try {
            this.XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(ex) {
            throw new MicrosoftXMLHTTPInitErrorException();
        }
    } else if (window.XMLHttpRequest){
        this.XMLHttp = new XMLHttpRequest();
    } else {
        throw new XMLHttpNotImplementedException();
    }
    
    var obj = this;
    this.XMLHttp.onreadystatechange = function() {
        obj._onLoadHandler();
    };
}
DXMLHttpRequestShell.prototype.getReadyState = function() {
    return this.XMLHttp.readyState;
}
DXMLHttpRequestShell.prototype.getServerStatusId = function() {
    return this.XMLHttp.status;
}
DXMLHttpRequestShell.prototype.getServerStatusText = function() {
    return this.XMLHttp.statusText;
}
DXMLHttpRequestShell.prototype.getResponseXML = function() {
    if (this.getReadyState() == 4) {
        return this.XMLHttp.responseXML;
    }
}
DXMLHttpRequestShell.prototype.getResponseText = function() {
    if (this.getReadyState() == 4) {
    	var result = "";
    	try {
    		result = this.XMLHttp.responseText;
    	} catch (e) {
    		result = "yes";
    	}
        return result;
    }
}
DXMLHttpRequestShell.prototype._onLoadHandler = function() {
    if (this.getReadyState() == 4) {
        if (this.getServerStatusId() == 200 || this.getServerStatusId() == 304) {
            try {
                this.onLoad();
            } catch (ex) {
                alert(ex);
            }
        }
    }
}
DXMLHttpRequestShell.prototype.fastGetUrl = function(url) {
    try {
        this.XMLHttp.open("GET", url, true);
        this.XMLHttp.send(null);
    } catch(ex) {
        throw ex;
    }
}
DXMLHttpRequestShell.prototype.onLoad = function() {
    throw new MethodNotImplementedException();
}
DXMLHttpRequestShell.prototype.getAttributeValue = function(attributeName, XMLNodeObject) {
    for (var i = 0; i < XMLNodeObject.attributes.length; i++) {
        with (XMLNodeObject.attributes.item(i)) {
            if (nodeName == attributeName) {
                return nodeValue;
            }
        }
    }
    
    return null;
}
DXMLHttpRequestShell.prototype.getAllData = function(XMLNodeObject) {
    var collection = {
        name : "",
        attributes : {},
        value : "",
        childNodes : []
    };

    with (XMLNodeObject) {
        collection.name = nodeName;
        if (hasChildNodes()) {
            collection.value = firstChild.nodeValue;
        }
    }
    
    if (XMLNodeObject.attributes.length > 0) {
        for (var i = 0; i < XMLNodeObject.attributes.length; i++) {
            with (XMLNodeObject.attributes.item(i)) {
                collection.attributes[nodeName] = nodeValue;
            }
        }
    }
    
    if (XMLNodeObject.childNodes.length > 0) {
        for (var i = 0; i < XMLNodeObject.childNodes.length; i++) {
            var currentNode = XMLNodeObject.childNodes.item(i);
            if (currentNode.nodeName.indexOf("#") != 0) {
                collection.childNodes.push(
                    this.getAllData(currentNode
                ));
            }
        }
    }
    
    return collection;
}

function AddFavorites(){
    this.mode = null;
}
AddFavorites.prototype = new DXMLHttpRequestShell();
AddFavorites.constructor = AddFavorites;
AddFavorites.prototype.sendQuery = function(url, id) {
    this.mode = "add";
    this.init();
    try{
        this.fastGetUrl(url + id + "/addfavorites.html");
    }
    catch(e)
    {
        this.fastGetUrl(url + id + "/addfavorites.html");
    }
}
AddFavorites.prototype.sendQueryRemove = function(url, id) {
    this.mode = "remove";
    this.init();
    
    try{
        this.fastGetUrl(url + id + "/removefavorites.html");
    }
    catch(e)
    {
        this.fastGetUrl(url + id + "/removefavorites.html");
    }
}
AddFavorites.prototype.onLoad = function() {
	
    if (this.mode == "add") {
		if(this.getResponseText() == "no") {
			alert("Already in your favorites!\nTo view, click above on \"My Favorites Only\".");
		} else {
			alert("Successfully added to your favorites. \nTo view, click above on \"My Favorites Only\".");
		}
	} else if (this.mode == "remove") {
	   handleCategorySelect(document.getElementById("vendorCategories").options[document.getElementById("vendorCategories").selectedIndex].value);
	}
}


function AddCustomerFavorites(){
    this.mode = null;
}
AddCustomerFavorites.prototype = new DXMLHttpRequestShell();
AddCustomerFavorites.constructor = AddFavorites;
AddCustomerFavorites.prototype.sendQuery = function(url, id) {
	
    this.mode = "add";
    this.init();
    
    try{
        this.fastGetUrl(url + id + "/addcustomerfavorites.html");
    }
    catch(e)
    {
        this.fastGetUrl(url + id + "/addcustomerfavorites.html");
    }
}
AddCustomerFavorites.prototype.sendQueryRemove = function(url, id) {
    this.mode = "remove";
    this.init();
    
    try{
        this.fastGetUrl(url + id + "/removecustomerfavorites.html");
    }
    catch(e)
    {
        this.fastGetUrl(url + id + "/removecustomerfavorites.html");
    }
}
AddCustomerFavorites.prototype.onLoad = function() {
    if (this.mode == "add") {
		if(this.getResponseText() == "no") {
			alert("Already in your favorites!\nTo view, click above on \"My Favorites Only\".");
		} else {
			alert("Successfully added to your favorites. \nTo view, click above on \"My Favorites Only\".");
		}
	} else if (this.mode == "remove") {
	   handleCategorySelect();
	}
}

function AddCustomVendor(){
}
AddCustomVendor.prototype = new DXMLHttpRequestShell();
AddCustomVendor.costrutcor = AddCustomVendor();
AddCustomVendor.prototype.Send = function (url, name) {
	this.init();
    try {
        this.fastGetUrl(url + "addcustomvendor/" + name);
    }
    catch(e) {
        this.fastGetUrl(url + "addcustomvendor/" + name);
    }
}
AddCustomVendor.prototype.onLoad = function() {
	alert("OK");
}

function UserReport(){
    this.mode = null;
}
UserReport.prototype = new DXMLHttpRequestShell();
UserReport.constructor = UserReport;
UserReport.prototype.sendQuery = function(url, id) {
    this.mode = "add";
    this.init();
    try{
        this.fastGetUrl(url + id + "/userreport.html");
    }
    catch(e)
    {
        this.fastGetUrl(url + id + "/userreport.html");
    }
}
UserReport.prototype.onLoad = function() {
	
    if (this.mode == "add") {
		if(this.getResponseText() == "no") {
			alert("You have already REPORTED this user.");
		} else {
			alert("Thank you for your REPORT message.\n We will investigate promptly.");
		}
	} else if (this.mode == "remove") {
	   handleCategorySelect(document.getElementById("vendorCategories").options[document.getElementById("vendorCategories").selectedIndex].value);
	}
}


function ChangeMailStatus(){
}
ChangeMailStatus.prototype = new DXMLHttpRequestShell();
ChangeMailStatus.constructor = ChangeMailStatus;
ChangeMailStatus.prototype.sendStatus = function(mailID) {
    this.init();
    try{
	this.fastGetUrl("http://nepabridal.com/changemailstatus/" + mailID);
    }
    catch(e)
    {
	this.fastGetUrl("http://nepabridal.com/changemailstatus/" + mailID);
    }
}
ChangeMailStatus.prototype.onLoad = function() {
	//
}

function CheckUser() {
}
CheckUser.prototype = new DXMLHttpRequestShell();
CheckUser.constructor = CheckUser;
CheckUser.prototype.onLoad = function() {
	if(this.getResponseText() == "yes" || this.getResponseText() == "\nyes")
		sleep(0);
	else
		sleep(1);
}
CheckUser.prototype.CheckLogin = function(username, password) {
this.init();
this.fastGetUrl("checkloginuser/" + username + "/" + password);
}
// *************************
// DXMLHttpRequest Class end
// *************************

