servername = 'http://www.discountfootballkits.com/'; 
//servername = 'http://vv15/first/discountfootballkits.com/'; 


// CallbackObject
function CallBackObject(){
  this.XmlHttp = this.GetHttpObject();
}

CallBackObject.prototype.GetHttpObject = function(){
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

CallBackObject.prototype.DoCallBack = function(url, postData)
{
  var theData = '';
  var theform = document.forms[0];
  var thePage = window.location.pathname + window.location.search;
  var eName = '';

  for( eName in postData ){
	if( eName && eName != ''){
        if( eName == 'hometypes[]'){            
            for (var k = 0; k <  postData[eName].length; k++){           
               theData = theData + escape(eName.split("$").join(":")) + '=' + postData[eName][k] + '&';
            } 
        }
        else {
            theData = theData + escape(eName.split("$").join(":")) + '=' + postData[eName] + '&';
        }
    }
  }

  if( this.XmlHttp ){
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 ){
      var oThis = this;
      this.XmlHttp.open('POST', url, true);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      this.XmlHttp.send(theData);
    }
  }
}

CallBackObject.prototype.AbortCallBack = function()
{
  if( this.XmlHttp )
    this.XmlHttp.abort();
  this.XmlHttp = null;
}

CallBackObject.prototype.OnLoading = function()
{
  // Loading
}

CallBackObject.prototype.OnLoaded = function()
{
  // Loaded
}

CallBackObject.prototype.OnInteractive = function()
{
  // Interactive
}

CallBackObject.prototype.OnComplete = function(responseText, responseXml)
{

  // Complete
}

CallBackObject.prototype.OnAbort = function()
{
	// Abort
}

CallBackObject.prototype.OnError = function(status, statusText)
{
  // Error
}

CallBackObject.prototype.ReadyStateChange = function(){
  if( this.XmlHttp.readyState == 1 ){
    this.OnLoading();
  }
  else if( this.XmlHttp.readyState == 2 ){
    this.OnLoaded();
  }
  else if( this.XmlHttp.readyState == 3 ){
    this.OnInteractive();
  }
  else if( this.XmlHttp.readyState == 4 ){
    if( this.XmlHttp.status == 0 )
      this.OnAbort();
    else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);
  }
}
// Callback Object End
//--------------------------------------------------------------------

var cbo = new CallBackObject();

cbo.OnLoading = function() {}
cbo.OnAbort   = function(){alert('Request has been aborted');};
cbo.OnError   = function(status, statusText){ alert('Error - ' + statusText); };

function el(id) {
    return document.getElementById(id);
}

function findPosX(obj){
    var curleft = 0;
    if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } }
    else if (obj.x) { curleft += obj.x; }
    return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent;}}
    else if (obj.y) { curtop += obj.y; }
    return curtop;
}

function postcodeshowpopup(obj_reper, codename, titletxt, postCodeVal){
    var obj = el('postcodemain_popupdiv');
    obj.style.visibility = "visible";
    obj.style.zIndex=190000;
    obj.style.display="block";
    obj.style.left = parseInt((findPosX(el(obj_reper)) - 130 - obj.style.width), 10) + "px";
	obj.style.top  = parseInt((findPosY(el(obj_reper)) - 110 + el(obj_reper).offsetHeight), 10) +"px";

    var objtitle = el('postcodetitle');
	objtitle.innerHTML = titletxt;

//

	cbo.OnLoading = function(){
        var txt = '<br /><br /><br /><br />Loading ...';
        var loaderDiv = el('postcodepopupdiv_msg');
        loaderDiv.innerHTML = '';
        loaderDiv.innerHTML = txt;
    };
	//xmlhttpPost("postcode/delivery_result.php");

	cbo.OnComplete = function(text, xml){
        var loaderDiv = el('postcodepopupdiv_msg');
		//alert(text);
        loaderDiv.innerHTML = text;
		//document.getElementById('postcodepopupdiv_msg').innerHTML = text;
		//alert(document.getElementById('postcodepopupdiv_msg').innerHTML);
    };

    var data = {"postcode" : postCodeVal};

    cbo.DoCallBack(servername+codename, data);
	
}

function postcodeclosepopup(){
    var obj = el('postcodemain_popupdiv');
    obj.style.visibility = "hidden";
    //history.go(0);
}

function xmlhttpPost(strURL) 
{
	var xmlHttpReq = false;
	var thisform = this;
	//	alert(thisform);
	// Checks if browser is Mozilla or Safari
	if (window.XMLHttpRequest){thisform.xmlHttpReq = new XMLHttpRequest();}
	// Checks if browser is Internet Explorer
	else if (window.ActiveXObject){thisform.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");}


	thisform.xmlHttpReq.open('POST',js_http_path+strURL, true);	thisform.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	thisform.xmlHttpReq.onreadystatechange = function() 
	{
		
		if (thisform.xmlHttpReq.readyState == 4) {
			
			updatepage(thisform.xmlHttpReq.responseText);
		
		
		}
	}
	thisform.xmlHttpReq.send(getquerystring());
}

function getquerystring() 
{
	var postcode= document.getElementById('postcode').value;
	qstr = 'postcode=' + escape(postcode);  // NOTE: no '?' before querystring
	return qstr;
}

function updatepage(str)
{
	document.getElementById('resultPost').innerHTML = str;
}

