if (document.domain=='localhost') {
   urlhost='http://localhost/CanadaTourism';
} else {
   urlhost='http://'+document.domain;
}

var refresh = '';
var sPath = window.location.pathname;

if (sPath !='/') {
  if (location.href.indexOf("q=cache:") > -1) { 
     // google cache page 
  } else { 
    if (window == top && navigator.userAgent.toLowerCase().indexOf("googlebot") <= -1) {
      if (document.domain != 'localhost') {
          var url='window.location.replace ("'+urlhost+'")';
          eval(url);
      }
    } 
  }
}

function calcHeight() {
 //window.scroll(0,0);
 if (location.href.indexOf("q=cache:") > -1) { return; }

 if (document.getElementById('iframe1').contentWindow.document.title != 'members') { 
     document.getElementById('searchTable').style.display='block';
 }
 
 if (document.getElementById('iframe1').contentWindow.document.title == 'Canada Tourism Picture') { 
     document.getElementById('homepage').style.display='table-cell';
 } else {
     document.getElementById('homepage').style.display='none';
 }
 
  document.getElementById('iframe1').style.height= '170px'; //reset size
	if (document.all)  {
	    var newheight = document.getElementById('iframe1').contentWindow.document.body.scrollHeight; //explorer
	} else if (document.getElementById) {
	    var newheight = document.getElementById('iframe1').contentDocument.height; //netscape 8
	} else if (document.layers)  {
	    var newheight = document.getElementById('iframe1').contentDocument.height; //netscape 4
	}
	  document.getElementById('iframe1').style.height= newheight+'px';
}

var lastCategory = "";

function ajaxFunction(province) {
var xmlhttp;
  if (window.XMLHttpRequest)  {
    xmlhttp=new XMLHttpRequest();
  } else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function() {
  if(xmlhttp.readyState==4) {
    data=xmlhttp.responseText; 
    var items = data.split(',');
    var length = items.length;

    var opt = document.getElementById('Category').options;
    opt.length = 0;
          
    for (var i = 0; i < length-1; i++) { 
      opt[i] = new Option(items[i]);
      opt[i].value = items[i];
      if (opt[i].value == lastCategory) { var foundCat = true; }
    }
    if (foundCat == true) { document.getElementById('Category').value=lastCategory; }
    if (lastCategory=='') { document.getElementById('Province').value=province; }
   }
}
  var category = "ajaxCategory.asp?Province="+province;
  xmlhttp.open("GET",category,true);
  xmlhttp.send(null);
}

function getParam(url,name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(url);
  if( results == null )
    return "";
  else
    return results[1];
}

function getCategory(url,name) {
  cat = unescape(getParam(url,name));
  parent.document.getElementById('Category').value = cat;
}

function getprovince(Prov){
  if (document.getElementById('Category')) {
     lastCategory=document.getElementById('Category').value;
     document.getElementById('Province').value = Prov;
     document.getElementById('City').value = "";
     document.getElementById('Region').value = "";
     ajaxFunction(Prov);
     flashmap(Prov);
  }
}

function flashmap(Prov) {
  if (parent.document.embeds && document.embeds['CanadaMap']) {
      parent.document.embeds['CanadaMap'].TGotoLabel("/", Prov);
  } else {
      parent.document.getElementById('CanadaMap').TGotoLabel("/", Prov);
  }
}

function getregion(args){
  var cat;
  arg = args.split(",");
  if (arg[1] == '') {
     url= parent.document.getElementById('iframe1').contentWindow.location.href;
     arg[1] = unescape(getParam(url,'s_Province'));
  }
    
  if (document.getElementById('Category')) {
      document.getElementById('Region').value = arg[0];
      document.getElementById('Province').value = arg[1];
      cat = escape(document.getElementById('Category').value);
      document.getElementById('City').value = "";
  } else {
      document.getElementById('iframe1').contentWindow.document.cat='';
  }
     
  if (document.getElementById('iframe1').contentWindow.document.title == 'members') {
      var answer = confirm('You have select Region '+arg[0]+" : "+arg[2]);
      if (answer) { document.getElementById('iframe1').contentWindow.document.getElementById('Region').value=arg[0]; }
  } else {
      document.getElementById('iframe1').src='codeCharge/ByProvince.asp?s_Region='+arg[0]+'&s_Province='+
      arg[1]+'&s_Category='+cat+'&refresh='+refresh; refresh='';
  }
}

function removeRegion(Prov) {
  if (Prov != 'City') { 
     document.getElementById('City').value = "";
     flashmap(Prov);
  };
  document.getElementById('Region').value = "";
}

function trim(str) {
  return str.replace(/^\s+|\s+$/g, '') ;
}

function search() {
  //region=escape(document.getElementById('Region').value);
  document.getElementById('Province').value == "" ? 
  document.getElementById('Province').value = "Alberta" : Prov=escape(document.getElementById('Province').value);
  category=escape(document.getElementById('Category').value);
  city=escape(trim(document.getElementById('City').value));
  if (isNaN(city)==false && city != '') {
    document.getElementById('iframe1').src='codeCharge/ByProvince.asp?adID='+city;
  } else {
    document.getElementById('iframe1').src='codeCharge/ByProvince.asp?s_Province='+Prov+'&s_Category='+category+'&s_City='+city+'&refresh='+refresh; refresh='';
  }
}

function login() {
  var contact = escape(document.getElementById('contact').value);
  var pass = escape(document.getElementById('pass').value);
  
  if (contact!='' && pass!='') {
     url= parent.document.getElementById('iframe1').contentWindow.location.href;
     q = "contact="+contact+"&pass="+pass +
     '&s_Province='+getParam(url,'s_Province')+'&s_Category='+getParam(url,'s_Category')+
     '&s_City='+getParam(url,'s_City')+'&s_Region='+getParam(url,'s_Region');
     document.getElementById('iframe1').contentWindow.document.location.href = "codeCharge/Template-Login.asp?"+q;
  } else {
     alert('Please, enter contact Email and Password');
  }
}

function CreateBookmarkLink() { 
 title = document.title;  
 url = window.location.href; 
  
  if (window.sidebar) { // Mozilla Firefox Bookmark 
    //window.sidebar.addPanel(title, url,"");
      alert('Firefox users need to press CTRL+D to Bookmark this page')
  } else if( window.external ) { // IE Favorite 
      window.external.AddFavorite( url, title); } 
  else if(window.opera && window.print) { // Opera Hotlist 
    return true;
  } 
}

var geocoder;
var map;
   
function loadMap(e,address,lat,lng) {
  if (e==null) { e = window.event; }
  myTip = document.getElementById('tableMap');
  myTip.style.top= (e.pageY ? e.pageY : e.clientY)-200+'px';
  myTip.style.left=(e.pageX ? e.pageX : e.clientX)-200+'px';
  document.getElementById('tableMap').style.display='block';
  map = new GMap2(document.getElementById("map"));
      
  if (lat == "" || lng == "") {
     geocoder = new GClientGeocoder();
     geocoder.getLocations(address, addToMap);
  } else {
     point = new GLatLng(lat,lng);
     map.setCenter(point, 15);
     map.setUIToDefault();
     marker = new GMarker(point);
     map.addOverlay(marker);
     map.panTo(point);
  }
}

function addToMap(response) {
  place = response.Placemark[0];
  point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
  map.setCenter(point, 15);
  map.setUIToDefault();
  marker = new GMarker(point);
  map.addOverlay(marker);
  //marker.closeInfoWindowHtml(place.address);
}
   
function closeMap() {
  document.getElementById('tableMap').style.display='none';
}