var href = self.location.href;
if (href.match("^https") == "https"){
      var httpstohttp = "true";
      
      if(href.match("wbnl_done") || href.match("wbnl_failed")){
           httpstohttp = "false";
      }
      else if(href.match("wnominativi") || href.match("web/wpreventivo_")){
            httpstohttp = "false";
      }
      else if(href.match("agency/booking/booking") || href.match("agency/booking/nomi")){
            httpstohttp = "false";
      }
      else if(href.match("wbnl_done_agency") || href.match("wbnl_failed_agency")){
            httpstohttp = "false";
      }
      else if(href.match("wminibnl_done") || href.match("mwnominativi") || href.match("wminibnl_failed")){
            httpstohttp = "false";
      }
      else if(href.match("wbnl_done_user") || href.match("wuser_conf_pay") || href.match("wbnl_failed_user")){
            httpstohttp = "false";
      }
      else if(href.match("wssb_done_user") || href.match("/mobyclub/wedit_all")){
            httpstohttp = "false";
      }
      else if(href.match("wssb_paypal") || href.match("wssb_back")){
            httpstohttp = "false";
      }
      
      if(httpstohttp == "true"){
            var path = href.substring(8, href.length);
            var relativePath = path.substring(path.indexOf('/'), path.length);
            var hostName = path.substring(0, path.indexOf('/'));
			// se siamo in spazio agenzie
			if(href.match("/agency")) {
				// se url e secure e sto facendo il logout
				if("secure" == href.substring(8, 14) && href.match("agency/logout")) {
					hostName = hostName.replace("secure.","agency.");
				} else if("www" == href.substring(8, 11) && href.match("agency/logout")) {
					hostName = hostName.replace("www.","agency.");
				}
				var newHref = 'http://' + hostName + relativePath;
				self.location = newHref;
			// se siamo in mobyclub
			} else {
			 	 var newHref = 'http://' + hostName + relativePath;
			 	 self.location = newHref;
			}            

      }
} else { 
	// se url e in http
	var path = href.substring(7, href.length);
    var relativePath = path.substring(path.indexOf('/'), path.length);
    var hostName = path.substring(0, path.indexOf('/'));
	// se siamo in spazio agenzie
	if(href.match("/agency")) {
		// se url e secure e sto facendo il logout
		if("secure" == href.substring(7, 13) && href.match("agency/logout")) {
			hostName = hostName.replace("secure.","agency.");
		    var newHref = 'http://' + hostName + relativePath;
			self.location = newHref;
		}
	// se siamo in mobyclub
	} 
	else if (!href.match("mobyclub")){
		 // altrimenti
		 if("secure" == href.substring(7, 13)) {
		 	hostName = hostName.replace("secure.","www.");
		 	var newHref = 'http://' + hostName + relativePath;
		 	self.location = newHref;
		 }
	}
}

