function getCookie_esp(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

var debug = getURLParam("debug");

var urlportal_c = "";
var mi_url_c = "";
	

if (document.location.host == ("media.hoycinema.com")) {
	//if (document.referrer != "" && document.referrer != "undefined" && document.referrer != null && document.referrer.indexOf("-origin.") > 0)
	if (document.referrer != "" && document.referrer != "undefined" && document.referrer != null)
	{//Si hay referer
		if  (!document.referrer.indexOf("-origin.") > 0)
		{//Si referer no es -origin.
			var cook = getCookie_esp("lastAccessed");
	
			//if (cook != "" && cook != "undefined" && cook != null && cook.indexOf("-origin") > 0) {
			if (cook.indexOf("-origin") > 0 || cook.indexOf("round-") > -1)
			{//Si la cookia es de -origin
				var curCookie = "lastAccessed=www.hoycinema.com; expires=Fri, 31-Dec-2010 00:00:00 GMT;path=/;domain=.hoycinema.com";
				document.cookie = curCookie;
	
			}
			//Redirecciono la pagina.
			if(debug != null && debug=="true")
			alert("document.location.href 2 "+document.location.href);

			pagina = document.location.href.replace("media.","www.");
			document.location.href=pagina;
		}
	}
}
else {

	if(document.location.host != "www.hoycinema.com" && document.location.host != "www1.hoycinema.com" && document.location.host != "www2.hoycinema.com") {	
	
			var curCookie = "lastAccessed=" + escape(document.location.host) + "; expires=Fri, 31-Dec-2010 00:00:00 GMT;path=/;domain=.hoycinema.com";
			document.cookie = curCookie;
	}
	else
	{
		
	
		var cook = getCookie_esp("lastAccessed");
		
		vengode = document.referrer;
		

		//ESTO NO VALE PARA NADA PORQUE SI NO NOS ENLAZAN NO SE VE.
		/*if(vengode.indexOf("ozu.") > 0) {
			vengode_c = "ozu.hoyinversion.com";
		} else{ 
			vengode_c = "";
		}*/

		if(vengode.indexOf("www.hoycinema.com") == -1 && vengode.indexOf("www.hoycinema.com") == -1)
		{
			if(vengode.indexOf("elcorreodigital.") > -1) {
				vengode_c = "elcorreodigital.hoycinema.com";
			} else if(vengode.indexOf("diariovasco.") > -1) {
				vengode_c = "diariovasco.hoycinema.com";
			} else if(vengode.indexOf("laverdad.") > -1) {
				vengode_c = "laverdad.hoycinema.com";
			} else if(vengode.indexOf("nortecastilla.") > -1) {
				vengode_c = "nortecastilla.hoycinema.com";
			} else if(vengode.indexOf("hoy.") > -1) {
				vengode_c = "hoy.hoycinema.com";
			} else if(vengode.indexOf("larioja.") > -1) {
				vengode_c = "larioja.hoycinema.com";
			} else if(vengode.indexOf("diariosur.") > -1) {
				vengode_c = "diariosur.hoycinema.com";
			} else if(vengode.indexOf("eldiariomontanes.") > -1) {
				vengode_c = "eldiariomontanes.hoycinema.com";
			} else if(vengode.indexOf("ideal.") > -1) {
				vengode_c = "ideal.hoycinema.com";
			} else if(vengode.indexOf("elcomerciodigital.") > -1) {
				vengode_c = "elcomerciodigital.hoycinema.com";
			} else if(vengode.indexOf("lasprovincias.") > -1) {
				vengode_c = "lasprovincias.hoycinema.com";
			} else if(vengode.indexOf("ozu.") > -1) {
				vengode_c = "ozu.hoycinema.com";
			} else if(vengode.indexOf("abc.") > -1) {
				vengode_c = "abc.hoycinema.com";
			} else if(vengode.indexOf("lavoz") > -1) {
					vengode_c = "lavozdigital.hoycinema.com";
			} else if(vengode.indexOf("hoyinversion.") > -1) {
				vengode_c = "www.hoycinema.com";
			} else{ 
				vengode_c = "";
			}

			if (vengode_c!="" && vengode_c.indexOf(document.location.host) == -1) {
					var curCookie = "lastAccessed=" + vengode_c + "; expires=Fri, 31-Dec-2011 00:00:00 GMT;path=/;domain=.hoycinema.com";
					document.cookie = curCookie;

					urlportal_c = "http://" + vengode_c;
					mi_url_c = "http://" + vengode_c;

					if(debug != null && debug=="true")
						alert("document.location.href 3 "+document.location.href);
					document.location.href = document.location.href.replace(document.location.host,vengode_c);
			}
		}	
		
	}

}
	

	
	



if (getCookie_esp("lastAccessed") != null && getCookie_esp("lastAccessed") != "" && getCookie_esp("lastAccessed").indexOf("round-") == -1)
{
	if((document.location.href.indexOf("www.hoycinema.com") >-1 || document.location.href.indexOf("www1.hoycinema.com") >-1 || document.location.href.indexOf("www2.hoycinema.com") >-1 || document.location.href.indexOf("media.hoycinema.com") >-1))
	{
		if(debug != null && debug=="true")
			alert("document.location.href 1 "+document.location.href);

		document.location.href = document.location.href.replace(document.location.host,getCookie_esp("lastAccessed"));



	}
}

