// ajax post php http://www.captain.at/howto-ajax-form-post-request.php
//if we use "&" character it wont work...
//but if we use escape();

//var poststr = "mytextarea1=" + escape(encodeURI(
//document.getElementById("mytextarea1").value )) +"&mytextarea2=" +
//escape(encodeURI( document.getElementById("mytextarea2").value ));

//and next in php u use urldecode , it will work good.
//Global
var gUserN ="";
var gDiv = "mainWindow" ;
var http_request = false;
   function postAjax(url, parameters) {
	   // note this will post to 'mainWindow'  divTag
//	   alert(url);
//	   alert(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('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
	         if (http_request.readyState == 4) {
         if (http_request.status == 200) {
 //   alert(http_request.responseText);
            result = http_request.responseText;
	// alert(gDiv);
		    document.getElementById(gDiv).innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
		//	alert('responseText= ' + http_request.status);
		//	alert('location= ' + document.location);
		//	alert(window.location.href.indexOf("https")==-1);
			
         }
      }
   }

   function postLogon(formName, divTag) {
     //	    document.getElementById(divTag).innerHTML = 'sending...';
//	   alert(divTag) ;
//	   gDiv = divTag ;
	   // note formName not used now	
	  var poststr = "id=" + encodeURI( document.getElementById("userID").value) + "&passWord=" + encodeURI( document.getElementById("passWord").value)  ;
//	alert('str' + poststr);
	 document.getElementById(divTag).innerHTML = 'sending...';
      postAjax('logonResult.php', poststr);
}


   function postEditProfile(formName, divTag) {
alert(formName);
alert(divTag) ;
	   gDiv = divTag ;
	//   alert(gDiv) ;
	   // note formName not used now	
	  var poststr = "id=" + encodeURI( document.resultForm.sId.value) ;
 // 	alert('str ' + poststr);
     document.getElementById('logonWindow').innerHTML = 'Loged On';
     document.getElementById(divTag).innerHTML = 'sending...';
      postAjax('editProfile.php', poststr);
	  
   }

 function postSaveProfile(formName, divTag) {
	//   alert(divTag) ;
	   gDiv = divTag ;
//	   alert(gDiv) ;
	   // note formName not used now	
		var poststr = "id=" + encodeURI( document.editForm.sId.value) 
		+ "&sSaveOK=" + encodeURI( document.editForm.sSaveOK.value) ;
    document.getElementById(divTag).innerHTML = 'sending...';
//	  	alert('str ' + poststr);
      postAjax('logonResult.php', poststr);  
   }


function postSRAAmenu(formName, divTag) {
	alert(formName);
	alert(divTag);
	 gDiv = divTag ;
	 postAjax('sraaMenu.php', 'id=nothing_passed');
	 document.getElementById('logonWindow').innerHTML = 'Loged On';
}

// end ajax post php http://www.captain.at/howto-ajax-form-post-request.php


function postAJAX_not_used(url, query, handler)
{
    var status = false;
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

    // Native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = handler;
        request.open("post", url, true);
        request.setRequestHeader("Content-Type", contentType);
        request.send(query);
        status = true;

    // ActiveX XMLHttpRequest object
    } else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = handler;
            request.open("post", url, true);
            request.setRequestHeader("Content-Type", contentType);
            request.send(query);
            status = true;
        }
    }

    return status;
}

function formQuery_not_Used(form)
{
    var elements = form.elements;
    var pairs = new Array();

    for (var i = 0; i < elements.length; i++) {

        if ((name = elements[i].name) && (value = elements[i].value))
            pairs.push(name + "=" + encodeURIComponent(value));
    }

    return pairs.join("&");
}


function logonSRAA(userID, passWord){
// is this used ??? alert('in logonSRAA');
// alert(userID);
// alert(passWord);


} 
        



function requestCustomerInfo(userID) { 
alert('in rci');
			var url = "testPHP2.php?id="; // The server-side script 
		// alert('test'); 
		 //  alert(userID);
        //    var sId = document.getElementById("txtCustomerId").value; 
			var sId = userID;
	//		 alert(sId);
			// alert(url);
			// alert(url + escape(sId));
            http.open("GET", url + escape(sId), true); 
            http.onreadystatechange = handleHttpResponse; 
            http.send(null); 
        } 
		
       function handleHttpResponse() { 
	   alert('xxx');
	   alert(http.readyState.value);
        if (http.readyState == 4) { 
              if(http.status==200) { 
                  var results=http.responseText; 
				  alert(http.responseText);
           //   document.getElementById('divCustomerInfo').innerHTML = results; 
              } 
              } 
        } 
        
        
function getHTTPObject() { 
  var xmlhttp; 

  if(window.XMLHttpRequest){ 
    xmlhttp = new XMLHttpRequest(); 
  } 
  else if (window.ActiveXObject){ 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    if (!xmlhttp){ 
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    
} 
  return xmlhttp; 

  
} 
var http = getHTTPObject(); // We create the HTTP Object 


function mJap(divTo){
	var sId = document.getElementById("txtCustomerId").value; 
	var url = 'testPHP2.php?id=' + sId ;
//	alert(url);
//	alert(sId);
// alert(divTo);
mJah(url,divTo);

}



// function mJap2(divTo){
//	var sId = document.getElementById("userID").value; 
//	var sPass = document.getElementById("passWord").value; 
//	var url = 	'logonResult.php?id=' 
//				+ 
//				sId 	
//				+ '&' + 	
//				'sPass=' + sPass;
//				
// 	alert(url);
//	mJah(url, divTo);
//}



function mJapP(url, target) {
//	 alert(url);
//	 alert(target);
	var sId = document.getElementById("userID").value; 
	var sPass = document.getElementById("passWord").value; 
	var furl = url + '?id=' + sId + '&passWord=' + sPass ;
//	alert(furl);
	
	// native XMLHttpRequest object
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", furl, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", furl, true);
            req.send();
        		}	
    }
		

	maddHistoryEvent(url,target) ;

}    

function mJapP_1(url, target) {
	// edit profile
//	 alert(url);
//	 alert(target);
//	var sId = document.getElementById("userID").value; 

	var furl = url + '?id=' + document.result.sId.value ;
//	alert(furl);
	
	// native XMLHttpRequest object
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", furl, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", furl, true);
            req.send();
        		}	
    }
		

//	maddHistoryEvent(url,target) ;

}    

function mJapP_2(url, target, inSid) {
//	save profile btn
alert(inSid);
//	 alert(url);
//	 alert(target);   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// alert(document.getElementById("sIdH").value) ;
	var sId = inSid;
//	var sId = document.getElementById("sIdH").value; 
// alert('my sid');
// alert(sId);
//	var sId = document.getElementById("userID").value; 
//	var sPass = document.getElementById("passWord").value; 
//	var furl = url + '?id=' + sId + '&passWord=' + sPass ;
	var furl = url + '?id=' + sId;
//	alert(furl);
	
	// native XMLHttpRequest object
    document.getElementById(target).innerHTML = 'sending...';
//    document.getElementById('pEditWindow').innerHTML = '';	
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", furl, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {testjahDone(target);};
            req.open("GET", furl, true);
            req.send();
        		}	
    }
		

//	maddHistoryEvent(url,target) ;

}    

function testjahDone(target){
//alert(target);	
}

function bookmarkMe(url, name)
{
// alert(url);
// alert(name);
	if (window.sidebar) 
	{ 
	// Mozilla Firefox Bookmark	
	alert('After you add this bookmark \nYou have to go to bookmark properties \nAnd uncheck the option load this bookmark in the sidbar \nI am working on this...');
	window.sidebar.addPanel(name, url,"false");	} 
	else if( window.external ) { 
	// IE Favorite		
	window.external.AddFavorite( url, name); }	
	else if(window.opera && window.print) { 
	// Opera Hotlist		
	return true; } 
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 


