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("wpreventivo")){
            httpstohttp = "false";
      }
      else if(href.match("agency/booking/booking") || href.match("agency/booking/nomi") || href.match("agency/booking/webnominativi")){
            httpstohttp = "false";
      }
      else if(href.match("wbnl_done_agency") || href.match("wbnl_failed_agency")){
            httpstohttp = "false";
      }
      else if(href.match("wminibnl_done") || 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("wback_paypal")){
            httpstohttp = "false";
      }
      else if(href.match("unicredit_done") || href.match("unicredit_failed") || href.match("wunicredit_listener")){
            httpstohttp = "false";
      }
      else if(href.match("wunicredit_mod_done") || href.match("wunicredit_mod_failed")){
            httpstohttp = "false";
      }
      else if(href.match("agency/wuda") || href.match("agency/wumda") || href.match("agency/wufa") || href.match("agency/wumfa")){
            httpstohttp = "false";
      }
      else if(href.match("intesa_done") || href.match("intesa_failed") || href.match("intesa_canc")){
            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.");
				}
			// se siamo in mobyclub
			} else {
				if (!href.match("mobyclub")){
					 // altrimenti
					 if("secure" == href.substring(8, 14)) {
					 	hostName = hostName.replace("secure.","www.");
					 }
				}
			}
			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 {
		 // altrimenti
		 if(!href.match("wmobyclub_account_pop")){
			 if("secure" == href.substring(7, 13)) {
			 	hostName = hostName.replace("secure.","www.");
			 	var newHref = 'http://' + hostName + relativePath;
			 	self.location = newHref;
			 }
     	 }
	} 
//	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;
//		 }
//	}
}


