var domain = 'http://www.sacbee.com';

if(location.href.indexOf('https://') > -1) domain = '';

var isSameDomain = false;

if((location.protocol + '//' + location.hostname) == "http://www.sacbee.com") isSameDomain = true;
if((location.protocol + '//' + location.hostname) == "http://sacbee.com") isSameDomain = true;
if((location.protocol + '//' + location.hostname) == "http://dwb.sacbee.com") isSameDomain = true;

function isReqCompatible() {
   var ro;
   try {
      ro = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e) {
      ro = false;
   }
   
   if (typeof ro == "object" && isSameDomain == true) {
      return true;
   }
   else {
      return false;
   }
}

var uber = 2;

var uberURL = 'http://search.sacbee.com/search?site=sacbee_search&output=xml_no_dtd&client=sacbee_search&proxystylesheet=http://www.sacbee.com/static/live/capitolalert/capalert.xslt&restrict=CapAlert&q=';

function doUber1(v) {
   uberURL = 'http://localsearch.sacbee.com/sp?aff=9&keywords=' + v;
   doUberReq(v, 'blogs');
}

function doUber2(v) {
   uberURL = 'http://search.sacbee.com/search?site=sacbee_search&output=xml_no_dtd&client=sacbee_search&proxystylesheet=http://www.sacbee.com/static/live/capitolalert/capalert.xslt&restrict=CapAlert&q=' + v;
   doUberReq(v, 'capalert');
}

function doUberReq(v, w) {
   /*
   if (isReqCompatible()) {
      var r = new loadRequest('/dyn/top_search/search.html?word=' + v + '&location=' + w, 'uberWhereTo');
   } else {
      uberWhereTo();
   }
   */
   uberWhereTo();
}

function uberWhereTo() {
   location.href = uberURL;
}
function setUber(v) {
   uber = v;
}

function submitUber() {
   var q = document.uber_search.q.value;
   if (uber == 2) {
      doUber2(q);
   } else {
      doUber1(q);
   }
}

function loadRequest(url, method) {
   var _this = this;
   this.url = url;
   this.method = method
   
   if(window.XMLHttpRequest) {
      this.req = new XMLHttpRequest();
   } 
   else if(window.ActiveXObject) {
      this.req = new ActiveXObject('Microsoft.XMLHTTP');
   }
   
   if(this.req) {
      this.req.onreadystatechange = function() {
	 _this.getRequest();
      };
      this.req.open('GET', this.url, true);
      this.req.send(null);
   }
   else {
      return;
   }
}

loadRequest.prototype.getRequest = function() {
   if (this.req.readyState == 4) {
      if (this.req.status == 200) {
	 var m = eval(this.method);
	 m(this.req.responseText);
      }
   }
}

function evalCAReturn(v) {
   var d = eval('(' + v + ')');
   var s = d[0].s;
   var l = 'http://data.sacbee.com/' + 'capalert/';
   if(s == 'active') return;
   location.replace(l + 'login' + '.html' + '?prv=' + escape(document.location));
}
