function getXMLHttp(){
  var xmlHttp;
  try {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)  {
    //Internet Explorer
    try{      
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
      try{
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e){
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}
function MakeRequestBuildPowerCard(url, popup, customerNumber, origenPosX, origenPosY){
  var xmlHttp = getXMLHttp();
  var waitImg = document.getElementById("imgloader");

  xmlHttp.onreadystatechange = function()
  {
	if (xmlHttp.aborted==true) { 
	  return;
	}

    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
    {
		waitImg.style.display =  'none';	// to stop to show the imagen "ajaxLoader.gif"

		//Get the content of the popup in a temporary variable. At the end, the content must be restored.
		var tmp_contenPopup = popup.contentHTML;

		//Modify the content of the popup.
		popup.setContentHTML(xmlHttp.responseText);

		//define the new size for the popup and show the popup.
		var newsize = new OpenLayers.Size(550, 195);
		popup.setSize(newsize);

		//Get the powerCard division in order to assign the popup elements to it.
		var popupPCard = document.getElementById("popupPowerCard");

		//Clean all the elements inside of "popupPowerCard"
		var	divInPcard = popupPCard.getElementsByTagName("div");
		if (divInPcard.length > 0)
		{
			var elementsToDelete = new Array();
			for (var i=0;i<divInPcard.length;i++)
			{
				elementsToDelete[elementsToDelete.length] = divInPcard[i];
			}
			for (var j=0;j<elementsToDelete.length;j++)
			{
				elementsToDelete[j].parentNode.removeChild(elementsToDelete[j]);
			}
		}
		
		//Clone the div of the popup and assign the new one to the "powerCard" div.
		var popupElements = popup.div;
		var clonePopupElements = popupElements.cloneNode(true);
		clonePopupElements.id = customerNumber + "_popup_PC";
		popupPCard. appendChild(clonePopupElements);

		//Change the content html for the clone element in order to show the powerCard.
		var numChanges = 0	// Variable to take the control to finish the bucle.
		var divPopupPC =  document.getElementById(customerNumber + "_popup_PC");
		var contentdivPopupPC = divPopupPC.getElementsByTagName("div");
		for (var i=0; i<contentdivPopupPC.length; i++)
		{
			if (contentdivPopupPC[i].id == customerNumber + "_popup_contentDiv")
			{
				//Assign the content of the power card
				contentdivPopupPC[i].innerHTML = xmlHttp.responseText;
				numChanges++;
				
				//get the div "powercard big"
				var divPopup_contentDiv =  contentdivPopupPC[i].getElementsByTagName("div");
				for (var j=0; j<divPopup_contentDiv.length; j++)
				{
					if (divPopup_contentDiv[j].className == "powercard big")
					{
						divPopup_contentDiv[j].style.zoom = "73%";
						break;
					}
					
				}
			}
			else
			{
				//Assign the functionality of the close button in the html.
				if (contentdivPopupPC[i].id == customerNumber + "_popup_close")
				{
					contentdivPopupPC[i].setAttribute('onclick', 'hidePopupPCard()');
					numChanges++;
				}
			}
			
			//Check if is time to finish the bucle.
			if (numChanges == 2)
			{
				break;
			}
		}




		//Delete the position left and top of the clone popup.
		clonePopupElements.style.left = 0;
		clonePopupElements.style.top = 0;
		clonePopupElements.style.display = "block";

		//Get the position and size of the popup and assign it to the "powerCard" div.
		var leftPosition = 	parseFloat(popupElements.style.left);
		var topPosition = parseFloat(popupElements.style.top);
		var popupWidth = popupElements.style.width;
		var popupHeight = popupElements.style.height;

		//Calculate the offset of the position of the div "powerCard"
		var newPosX = map.getPixelFromLonLat(map.layerContainerOrigin ).x;
		var newPosY = map.getPixelFromLonLat(map.layerContainerOrigin ).y;
		var offsetX =  newPosX - origenPosX;
		var offsetY =  newPosY - origenPosY;

		popupPCard.style.left = leftPosition + 20 + offsetX + "px";	//20 is the offset beetween the left margen of the div "map" and left margen of the div "overview"
		popupPCard.style.top = topPosition + 54 + offsetY + "px";	//54 is the offset beetween the left margen of the div "map" and left margen of the div "overview"
		popupPCard.style.width = popupWidth;
		popupPCard.style.height = popupHeight;
		popupPCard.style.padding = "0px";

		//Check if the popup is in the right cuadrant.
		//In this case must check if the marker (popup) are near to the axe Y (less than 200 px)
		//If this is the case we need to change the decoration of the popup, Because when the visitor has a small screen, the info of the popup
		//was show out of the screen.
		var popupLonLat = popup.lonlat;			//Position of the lonlat of the popup
		var popuplonlatInPix = map.getPixelFromLonLat(popupLonLat);

		//Get the position of the center of the map. In order to divide the window in 4 cuadrants. THe position (0,0) will be in the center of the map.
		var centerMapInLonlat = map.getCenter();
		var centerMapInPix = map.getPixelFromLonLat(centerMapInLonlat)
		
		//compare the position of the marker (popup) with the center of the map.
		//and determine if it is in the top right or bottom right cuadrant
		if (popuplonlatInPix.x > centerMapInPix.x && popuplonlatInPix.x <= (centerMapInPix.x + 200))
		{
			popupPCard.style.left = leftPosition + 20 + offsetX + 200 + "px";	//20 is the offset beetween the left margen of the div "map" and left margen of the div "overview"
																				//200 is the amount of pixels to move in the right direction to avoid that the popup will be hidden

			//Change the position of the pointer of the popup (chub)
			for (var i=0; i<contentdivPopupPC.length; i++)
			{
				if (contentdivPopupPC[i].id == customerNumber + "_popup_FrameDecorationDiv_4")
				{
					var rightPosition = parseFloat(contentdivPopupPC[i].style.right);
					contentdivPopupPC[i].style.right = rightPosition + 200 + 'px';
				}
			}
		}

		//check if the popupPowerCard should be shown (Transaction completed).
		if (transaction)
		{
			popupPCard.style.display = 'block';
		}

		//Restore the content of the popup
		popup.setContentHTML(tmp_contenPopup);
		
		//End the transaction
		transaction = false;
    }
    else
    {
		waitImg.style.display =  'block'; 	// to show the imagen "ajaxLoader.gif"
    }
  }
  xmlHttp.open("GET",url, true);
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  xmlHttp.send();
  
  return xmlHttp;
}
