﻿
    function RVhttprequest(){};

        RVhttprequest.prototype.dopost=function(url,data,callbackFunc,sync){

	    if (url.indexOf('?')==-1)
		    url+='?rnd='+Math.random();
	    else
		    url+='&rnd='+Math.random();

	        var req;
		    if(window.XMLHttpRequest)		{
			    try			{
				    req=new XMLHttpRequest();
			    }
			    catch(e){}
		    }
		    else if(window.ActiveXObject)		{
			    try {
				    req = new ActiveXObject("Msxml2.XMLHTTP");
			    }
			    catch(e)			{
				    try				{
					    req = new ActiveXObject("Microsoft.XMLHTTP");
				    }
				    catch(e){}
			    }
		    }

	    if(!req)
		    return;

	    try	{
				    var async=(sync?false:true);
				    var fun=null;
				    if (async)		{
    				
					    fun=function()			{
						    if (req.readyState==4)	{
						     if (typeof(callbackFunc)=="function")
							    return callbackFunc(req);
						    else
							    return req;
    							
							    }
					    };
				    }

		    if (data)		{
			    req.open("POST", url, async);
			    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			    if(fun)
				    req.onreadystatechange=fun;
			    req.send(data);
		    }
		    else		{
    		
			    req.open("GET", url, async);
    			
			    if(fun)
				    req.onreadystatechange=fun;
			    req.send(null);
		    }

		    if(!async)		{
                if (typeof(callbackFunc)=="function"){
                    callbackFunc(req);
                } else	{
                    return req;
                }
		    }

	    }
	    catch(e){
    	
	        ShowErrorDialog(e)
		    var error = 'PLEASE COPY AND PASTE THIS ERROR AND EMAIL TO support@realview.com.au!!<br>' ;
		    for (var x in e)		{
			    error += x + ':  ' + e[x] + '<br>';
		    }
		    ///dbgwin(error);
	    }

    };

    function ShowErrorDialog(e) {
        alert('ajax error');
    };   