/***POSTCODE ANYWHERE***/
function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin_lite(Postcode, Building) {
  PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin('KR23-JW62-GY99-FM29', Postcode, Building, '', '');
}
function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin_lite(Postcode, Building, suffix) {
  PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin('KR23-JW62-GY99-FM29', Postcode, Building, '', suffix);
}
function PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10Begin(Key, Postcode, Building, UserName, suffix)
{
  if(suffix==null || suffix=="undefined") suffix = '';

  var scriptTag = document.getElementById("PCA38d38252878f434581f85b249661cd94");
  var headTag = document.getElementsByTagName("head").item(0);
  var strUrl = "";

  //Build the url
  strUrl = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveByPostcodeAndBuilding/v1.10/json.ws?";
  strUrl += "&Key=" + escape(Key);
  strUrl += "&Postcode=" + escape(Postcode);
  strUrl += "&Building=" + escape(Building);
  strUrl += "&UserName=" + escape(UserName);
  strUrl += "&CallbackFunction=PostcodeAnywhere_Interactive_RetrieveByPostcodeAndBuilding_v1_10End" + suffix;

  //Make the request
  if (scriptTag) {
    try { headTag.removeChild(scriptTag); }
    catch (e) { } //Ignore
  }
  scriptTag = document.createElement("script");
  scriptTag.src = strUrl
  scriptTag.type = "text/javascript";
  scriptTag.id = "PCA38d38252878f434581f85b249661cd94";
  headTag.appendChild(scriptTag);
}
/***********************/

//$(document).ready(function(){
//$('#ExamList').hide();
//});

var rrc = {};
rrc.SetRegion = function(parameter){
  
      $.ajax({
          type: "POST",
          url: "/base/WorldExam/VenueList/"+parameter+".aspx",
          data: "{}",
          contentType: "application/json; charset=utf-8",         
          dataType: "json",
          success: AjaxSucceeded,
          error: AjaxFailed
      }); 
  
      function AjaxSucceeded(result) {
        //ret = result[0].Name + "<br/>" +  result[0].Street;
        
        var region = {'AMER' : 'The Americas' ,  'ASIA' : 'Asia' , 'OCEAN' : 'Oceania',  'AFRIC' : 'Africa' ,  'MDEST' : 'Middle East' ,  'EUROP' : 'Europe' };
        
        var ret = "<div class='exam'>";
        for(x=0; x<result.length; x++)
        {
          ret += "<div class='examitem'>";
          ret += "<div class='container'><div class='examcolumns'>";
          ret += "<div class='examcol1'>" + IsNull(result[x].Country,'<strong>','</strong><br/>' + IsNull(result[x].Name,'','<br/>') +  IsNull(result[x].Building,'','<br/>') 
            + IsNull(result[x].Street,'','<br/>') + IsNull(result[x].Town,'','<br/>') + IsNull(result[x].Area,'','<br/>') 
            + IsNull(result[x].County,'','<br/>') + IsNull(result[x].PostCode,'','<br/>')) 
            + "</div>";
              
          ret += "<div class='examcol2'>" + IsNull(result[x].Phone,'p: ','<br/>') + IsNull(result[x].Fax,'f: ','<br/>') 
            + IsNull(result[x].Website,'w: <a href="'+result[x].Website+'">','</a><br/>') 
            + IsNull(result[x].Email,'e: <a href="mailto:'+result[x].Email+'">','</a><br/>')
            + "</div>"
          ret += "</div></div><div class='clearfix'/></div>";
        }
        ret += "</div>";
        $('#ExamList').hide();
        $('#ExamList').html(ret);
        //$('#ExamList').fadeIn(1500);
        $('#ExamList').dialog({ show: {effect: 'fade', duration: 500 }, hide: { effect: 'fade', duration: 500 } ,title: 'Exam Centres in '+region[parameter] ,width: 800, height: 500, modal: true, resizable: false }).parent(".ui-dialog").wrap("<div class='cupertino'></div>");
      }
      function AjaxFailed(result) {
        alert(result.status + ' ' + result.statusText);
      }  
  
      function IsNull(s, pre, post)
      {
        if (s == undefined || s == "")
          return "";
        else
          return pre + s + post;
      }
  
} 

