///////////////////
//
// Userinfo
// Web2.0 AJAX functions
// zur Kommunikation mit left_userinfo.php
//
// 2010 Marc Brauel , Onwerk GmbH, Mannheim
// V 1.0
///////////////////
 
 

  ////
  // create Ajax Object
  //
  var REQOBJ =
  { 
     /////
     // Properties
    bStatus: false,
    objAJAX: null,
	SOAPAnswer: '',
	SOAPRequest: '',
	SOAPAction: 'http://www.onwerk.de/sunpromotions/webservice/Userinfo',
	URL_WS: '',
	
	/////
    // Init the object
    init: function()
	{ 
	  try  /* w3c */
	  {
	    REQOBJ.objAJAX = new XMLHttpRequest();
	    REQOBJ.bStatus = true;
	    DEBUG('init w3c object');
	  }
	  catch(e_w3c) /* MSIE */
	  {
           try
		   {
              REQOBJ.objAJAX = new ActiveXObject("Msxml2.XMLHTTP");
			  REQOBJ.bStatus = true;
	  	      DEBUG('init new msie object');

		   }
		   catch(e_msie)
		   {
	           try
			   {
		          REQOBJ.objAJAX = new ActiveXObject("Microsoft.XMLHTTP");
			      REQOBJ.bStatus = true;
	  	          DEBUG('init old msie object');
			   }
			   catch(e_msie_old)
			   {
			     REQOBJ.bStatus = false;
  	             DEBUG('init failt:'+e_msie_old);
			     
			   }	/* MSIE alt */     
		   }	/* MSIE neu */     
	  } /* w3c */
    },// init

    /////
    // Send SOAP request
    //    
	doSend: function(userProfileId)
	{
      if((REQOBJ.URL_WS == "") || (REQOBJ.SOAPAction=="")){DEBUG('URL_WS or SOAPAction empty');return 'ERROR: URL_WS or SOAPAction empty';}
      if(!REQOBJ.bStatus){DEBUG('bStatus is false');return 'ERROR: Status is false';}
      
      try
      {
		REQOBJ.objAJAX.open('POST',REQOBJ.URL_WS,false); // synchron call
		REQOBJ.objAJAX.setRequestHeader("Man", "POST "+REQOBJ.URL_WS+" HTTP/1.1");
		REQOBJ.objAJAX.setRequestHeader("MessageType", "CALL");
		REQOBJ.objAJAX.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
		REQOBJ.objAJAX.setRequestHeader("SOAPAction", REQOBJ.SOAPAction);
        DEBUG('set header succeeded :'+REQOBJ.URL_WS) ;

/*
		REQOBJ.objAJAX.onreadystatechange = function(){
			if(REQOBJ.objAJAX.readyState == 4){
				if(REQOBJ.objAJAX.bStatus != 200 && REQOBJ.objAJAX.bStatus != 0) {
					//
                    // alert('Error sending:'+REQOBJ.objAJAX.statusText);
					//
			        return false;
				}
				REQOBJ.SOAPAnswer = REQOBJ.objAJAX.responseText;
			}//REQOBJ.objAJAX.readyState == 4
			} //REQOBJ.objAJAX.onreadystatechange
*/

        DEBUG('set response delegate succeeded') ;

		REQOBJ.SOAPRequest = '<?xml version="1.0" encoding="utf-8"?>\n'+
					'<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/">\n'+
					'<soap:Body>\n'+
					'<Userinfo xmlns="http://www.onwerk.de/sunpromotions/webservice">\n'+
					'  <userProfileId>'+userProfileId+'</userProfileId>\n'+
					'</Userinfo>\n'+
					'</soap:Body>\n'+
					'</soap:Envelope>\n';
        DEBUG('set request succeeded\n'+REQOBJ.SOAPRequest) ;
	      
		// REQOBJ.SOAPAnswer='';
// alert("doSend Request:\n"+REQOBJ.SOAPRequest);
		REQOBJ.objAJAX.send(REQOBJ.SOAPRequest);
		DEBUG('sending successfull') ;// alert("doSend Response:\n"+REQOBJ.objAJAX.responseText);

//alert(REQOBJ.objAJAX.responseText);
        return REQOBJ.objAJAX.responseXML ;       

       }
       catch(eSendError)
       {
         DEBUG('doSend failt:'+eSendError) ;
         return 'ERROR:'+eSendError;
       }
	}//doSend
  }//REQOBJ
     
  REQOBJ.init();


  function DEBUG(sText)
  {
    return;
    alert(sText);
  }
  
////-----------------------------------------------------------------

 //////////
 ///callUserInfo
 //
 //
 // [string] userProfileId - UserID
 // 
 // return
 // [string]  UserProfileId - UserID
 // [string]  Params => Params
 // [string]  PossibleGroups => TGroups
 // [string]  AddFlight => Parameter Add Flight
 // [string]  ShowLogin => Parameter ShwoLogin
 function callUserInfo(userProfileId)
 {
    var bResp;
    if(REQOBJ.bStatus)
    {
		  var result = REQOBJ.doSend(userProfileId)
          var arrResult = new Array();	    
	      try
	      {arrResult['UserProfileId'] =  result.getElementsByTagName("UserProfileId")[0].firstChild.nodeValue;	}
	      catch(e)
	      {arrResult['UserProfileId'] =  "";	}

	      try
	      {arrResult['Params'] =  result.getElementsByTagName("Params")[0].firstChild.nodeValue;	}
	      catch(e)
	      {arrResult['Params'] =  "";	}

	      try
	      {arrResult['PossibleGroups'] =  result.getElementsByTagName("PossibleGroups")[0].firstChild.nodeValue;	}
	      catch(e)
	      {arrResult['PossibleGroups'] =  "";	}

	      try
	      {thisResult['AddFlight'] =  result.getElementsByTagName("AddFlight")[0].firstChild.nodeValue;	}
	      catch(e)
	      {arrResult['AddFlight'] =  "";	}

  	      try
	      {arrResult['ShowLogin'] =  result.getElementsByTagName("ShowLogin")[0].firstChild.nodeValue;	}
	      catch(e)
	      {arrResult['ShowLogin'] =  "";	}

	       return arrResult;
	}//if(REQOBJ.bStatus)
	return "ERROR: bStatus="+REQOBJ.bStatus;
 }//
 REQOBJ.URL_WS = "http://login.sunpromotions.com/wDEU/wLayout/structure/left_userinfo.php";




 /*************************
 // Aufruf der Funktion
 
<script language="JavaScript" src="./left_userinfo.js"></script>
<script language="JavaScript">
 function testmyUserInfo(userProfileId)
 {
    var myResult = callUserInfo(userProfileId);
	// myResult['UserProfileId'];
	// myResult['Params'];
	// myResult['PossibleGroups'];
	// myResult['AddFlight'];
	// myResult['ShowLogin'];
 }
 </script>


 
 */
