      
   //************** GLOBAL SOAP Variables ****************
     function WebServiceClient(strMethodName){
     
    // WebServiceClient.gUrl = 'http://localhost:3322/google_map/WebService.asmx?wsdl';
      //WebServiceClient.gUrl = 'http://www.taran.com.pl/mobile/google_map/WebService.asmx?wsdl';
   //  WebServiceClient.gUrl = 'http://localhost/google_map/WebService.asmx?wsdl';
     
     
      this._xmlhttp = null;
      this._xmlResp = null;
      this._strMethodName=strMethodName;
      this._content = "";
      this.IsConnected = false;
      
      }
      WebServiceClient.gServiceName = 'SPSTaranOdjazdy';
     
     //*****************************************************  
     
     //Function to create SOAP data packet.
       WebServiceClient.prototype._createSOAPData=function()
        {
           var soapAction = 'http://'+ WebServiceClient.gServiceName +'/'  + this._strMethodName;
            
            var data = '<?xml version=\'1.0\' encoding=\'utf-8\'?>'+
					'<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'>'+
					  '<soap:Body>'+
					    '<' + this._strMethodName + ' xmlns=\'http://'+ WebServiceClient.gServiceName +'/\'>'
					        + this._content + 
					   '</' + this._strMethodName + '>'+
					  '</soap:Body>'+
					'</soap:Envelope>';	
		    return data;
        }
        
        
        //Function to create XMLHttpRequest.
             WebServiceClient.prototype._getXmlHttpObject=function()
                {
                var xmlHttp=null;
                 
                try
                  {
                  // Firefox, Opera 8.0+, Safari
                  xmlHttp=new XMLHttpRequest();
                  }
                catch (e)
                  {
                  // Internet Explorer
                  try
                    {
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                    }
                  catch (e)
                    {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                  }
                return xmlHttp;
                }
            //Function to add new properties
                WebServiceClient.prototype.appendProperty = function(name, value)
                {
                    this._content += '<' + name + '>' + value + '</' + name + '>';
                }
               WebServiceClient.prototype.addPropertyString = function(str)
                {
                    this._content += str;
                }
                
             
            
            
            //Function to send and retrieve the SOAP Request.
                WebServiceClient.prototype.send=function(callback,callbackOnFail,opt_opts)
                {
      
                    var me = this;
                    this._xmlhttp=this._getXmlHttpObject()  ;
                    this._xmlhttp.open('POST', WebServiceClient.gUrl, true);
                   
                    this._xmlhttp.onreadystatechange = function(){
                        this.IsConnected  = false;

                        if (me._xmlhttp.readyState == 4)
                        {     
                            if (me._xmlhttp.status == 200) // only if "OK"
                            { 
                                try
                                {
                                   me._xmlResp = loadXmlDocument(me._xmlhttp.responseText);
                                   callback(me._xmlResp,200);
                                }
                                
                                catch (ex)
                                {
                                  if(callbackOnFail!=null)
                                    callbackOnFail(me._xmlhttp.status,me._xmlhttp.statusText);
                                  else
                                    alert(ex);
                                  //  window.location = window.location;
                                    return;
                                }
                            }
                            else
                            {
                                 if(callbackOnFail!=null)
                                    callbackOnFail(me._xmlhttp.status,me._xmlhttp.statusText,loadXmlDocument(me._xmlhttp.responseText),me._xmlhttp.responseText);
                                 else{
                                    //throw me._xmlhttp.statusText;
                                      // alert (me._xmlhttp.statusText +  " " +me._xmlhttp.responseText);
                                      // window.location = window.location;
                                    }
                            }
                        }
                    }
                    var data = this._createSOAPData();
                    
                    var soapAction = 'http://'+ WebServiceClient.gServiceName +'/'  + this._strMethodName;
                    this._xmlhttp.setRequestHeader('Content-Type', 'text/xml');
                    this._xmlhttp.setRequestHeader('Content-Length', data.length);
                    this._xmlhttp.setRequestHeader('SOAPAction', soapAction);
                    this._xmlhttp.send(data);
                    this.IsConnected  = true;
     }
     
     
     WebServiceClient.prototype.abort = function(){
        if(this._xmlhttp && this.IsConnected)
            this._xmlhttp.abort();
     }
     
                
    function getQString() {
        var args = new Object();
        var query = location.search.substring(1);
        var pairs = query.split("&");
        for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) continue;
        var argname = pairs[i].substring(0,pos);
        var value = pairs[i].substring(pos+1);
        args[argname] = unescape(value);
    }
    return args;
    } 
    
    
  //utworzenie dokumentu XML z stringa
  function loadXmlDocument(strXML)
  {
       var xmlDoc; 
       if (window.ActiveXObject)   // code for IE
         {
         xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
         xmlDoc.async="false";
         xmlDoc.loadXML(strXML);
        }
       else    // code for Mozilla, Firefox, Opera, etc.
        {
         var parser=new DOMParser();
         xmlDoc = parser.parseFromString(strXML,"text/xml");
        }
    
       
  return xmlDoc;
  }
  
  
  //transformacja XML + XSL, w wyniku zwracany jest obiekt div z kodem HTML
  function transformXmlDocument(xmlDoc,xslDoc)
  {
    var resultDocument;
    var div = document.createElement('div'); 
       // code for IE
        if (window.ActiveXObject)
          {
          resultDocument=xmlDoc.transformNode(xslDoc);
          div.innerHTML=resultDocument;
          }
        // code for Mozilla, Firefox, Opera, etc.
        else if (document.implementation 
        && document.implementation.createDocument)
          {
          xsltProcessor=new XSLTProcessor();
          xsltProcessor.importStylesheet(xslDoc);
          resultDocument = xsltProcessor.transformToFragment(xmlDoc,document);
          div.appendChild(resultDocument);
          }

    return div;
  }
      
function createCookie(name,value,seconds) {
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

 
 Authorization = function()
 {
    this._cookie = null;
    this._userData = null;
    
 }
 Authorization.prototype.authorize = function()
 {
    var divResp = document.getElementById('db2logResp');
    this._cookie = readCookie("db2TARANAuthorization");
    if(this._cookie==null){
     divResp.style.display='block';
     divResp.innerHTML="Aby moc zapisac zmiany wymagana jest autoryzajca";
     document.getElementById('loginForm').style.display = 'block';
     return false;
   }
   else
    this._userData = this._cookie.split('%');
   
   return true;
 }
 Authorization.prototype.getLogin = function()
 {
 if(this._userData!=null)
    return this._userData[0].split(':')[1];
    return "";
 }
 Authorization.prototype.getPass = function()
 {
    if(this._userData!=null)
        return this._userData[1].split(':')[1];
     return "";
 }
 //funkcja globalna służąca do logowania w bazie 
function logIn(event)
 {
    var content = "";
    var user  = document.getElementById('input_login').value;
    var pass = document.getElementById('input_password').value;
    wbs = new WebServiceClient("Authorization");
    wbs.appendProperty("username",user);
    wbs.appendProperty("password",pass);
    wbs.send(function(re){
    
        var result=re.getElementsByTagName('Acceptation')[0].firstChild.nodeValue
        if(result=="true") {createCookie("db2TARANAuthorization","user:"+user+"%pass:"+pass,60*60*24); loginResult(true)}
            else loginResult(false);          
    });
 }
 //wynik logowania
 function loginResult(args)
 {  
    var divResp = document.getElementById('db2logResp');
    if(args){
        divResp.innerHTML = "Logowanie przebieglo pomyslnie";
        window.setTimeout(function(){document.getElementById('loginForm').style.display = 'none'; sidebar.openTab(3)},1000);
        }
    else
        divResp.innerHTML = "Nie zalogowano, sprawdz login lub haslo";
 }
 

    
 