/* ------------ Flash ------------ */
function gestionFlashObj() {
	var navegador_ = navigator.appName;
	if (navegador_ == "Microsoft Internet Explorer") {
		var obj;
		var i=document.getElementsByTagName("OBJECT").length -1;
		var aux="";
		if (i<0) return;
		while (aux!= null)
		{
			if (document.getElementsByTagName("OBJECT")[i]!= null){
				objecto=document.getElementsByTagName("OBJECT")[i];
				if (objecto.movie.indexOf(window.location.host)<0 && objecto.movie.indexOf("://")<0){
					objecto.movie=window.location.protocol+"//"+window.location.host+objecto.movie;
				};
				aux=document.getElementsByTagName("OBJECT")[i].outerHTML;
				document.getElementsByTagName("OBJECT")[i].outerHTML="<div id='objectoOb"+i+"'></div>";
				escribirPAntalla(document.getElementById("objectoOb"+i),aux);
				i--;
			};
		if (i<0) return;
		aux=document.getElementsByTagName("OBJECT")[i];
		}
	}
}
function escribirPAntalla(aux,cont) {
	if (aux!=null || cont!=null){
		aux.innerHTML=cont;
	}
}
/* ------------- End ------------- */

/* ----------- FAVICON ----------- */
var favicon = {
defaultPause: 2000,
change: function(iconURL, optionalDocTitle) {
  clearTimeout(this.loopTimer);
  if (optionalDocTitle) {
    document.title = optionalDocTitle;
  }
  this.addLink(iconURL, true);
},
animate: function(iconSequence, optionalDelay) {
  this.preloadIcons(iconSequence);
  this.iconSequence = iconSequence;
  this.sequencePause = (optionalDelay) ?  optionalDelay : this.defaultPause;
  favicon.index = 0;
  favicon.change(iconSequence[0]);
  this.loopTimer = setInterval(function() {
    favicon.index = (favicon.index+1) % favicon.iconSequence.length;
    favicon.addLink(favicon.iconSequence[favicon.index], false);
  }, favicon.sequencePause);
},
loopTimer: null,
preloadIcons: function(iconSequence) {
  var dummyImageForPreloading = document.createElement("img");
  for (var i=0; i<iconSequence.length; i++) {
    dummyImageForPreloading.src = iconSequence[i];
  }
},
addLink: function(iconURL) {
  var link = document.createElement("link");
  link.type = "image/x-icon";
  link.rel = "shortcut icon";
  link.href = iconURL;
  this.removeLinkIfExists();
  this.docHead.appendChild(link);
},
removeLinkIfExists: function() {
  var links = this.docHead.getElementsByTagName("link");
  for (var i=0; i<links.length; i++) {
    var link = links[i];
    if (link.type=="image/x-icon" && link.rel=="shortcut icon") {
      this.docHead.removeChild(link);
      return; // Assuming only one match at most.
    }
  }
},
docHead:document.getElementsByTagName("head")[0]
}
/* ------------ END ------------ */

/* Insercion de Cookie */
function SiteCookiePanda() {
	var expdate = new Date ();
	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // 24 hrs * 365 d. = 1 Ano
	if (document.getElementById("SiteCookie") != null) {
		if (document.getElementById("SiteCookie").value != "") {
			document.cookie="sitepanda=" + escape(document.getElementById("SiteCookie").value) + ";path=/;domain=.pandasecurity.com;expires=expdate.toGMTScring();";
		}
	}
};
SiteCookiePanda();


/*--------------  Selector -----------------*/
if (typeof (readCookie)!= 'undefined'){
	var Radio=document.getElementById("Radio"+readCookie("sitepanda"));
	if (Radio != null ){Radio.checked=true;};
};
/* ------------------- */

var paramSitepanda="particulares";

function CapturaSitePanda(){
	var sitep= "sitepanda=";
	var ca = document.cookie.split(';');
	for (var i=0;i<ca.length;i++){
		var cook=ca[i];
		while (cook.charAt(0)==' ') cook = cook.substring(1,cook.length);
		if (cook.indexOf(sitep) == 0) return cook.substring(sitep.length,cook.length);
	};
	return paramSitepanda;
};

function ExcepcionesMirar(Enlace){
var URLsHomes=new Array("http://www.pandasecurity.com/homeusers/","http://www.pandasecurity.com/spain/homeusers/","http://www.pandasecurity.com/enterprise/","http://www.pandasecurity.com/spain/enterprise/");
var Excepciones=new Array("/rolv3","/register","/keys/","downloads/webadmin","downloads/desktopsecure","/resources/","#", "/upgrade/", "mailto:", "javascript:", "acs.pandasoftware.com",".exe",".zip",".doc");
var NoExcepciones=new Array("pandasecurity.com");
	// Caso para las homes
	for (var x=0;x<URLsHomes.length;x++){
		if (Enlace.toLowerCase()==URLsHomes[x]){
			return true;
		}
	}
	// Excepciones
	for (var x=0;x<Excepciones.length;x++){
		if (Enlace.toLowerCase().indexOf(Excepciones[x])>-1){
			return true;
		}
	}
	// No excepciones
	for (var x=0;x<NoExcepciones.length;x++){
		if (Enlace.toLowerCase().indexOf(NoExcepciones[x])>-1){
			return false;
		}
	}
	return true;
};

function pasarParametro(para){
	for (var x=0;x<document.links.length;x++){
		var href=document.links[x].href;
		var inner=document.links[x].innerHTML;
		if (!ExcepcionesMirar(href)){
			
			if (href.indexOf("?")>-1){
				if (href.indexOf("sitepanda=")==-1){
					document.links[x].href=href;//+"&sitepanda="+para;
					document.links[x].innerHTML=inner;
				}
			}else{
				document.links[x].href=href;//+"?sitepanda="+para;
				document.links[x].innerHTML=inner;
			};
		};
	};
	return true;
};

function IniciarSitepanda(error){
	//alert(error);
	if (document.location.href.indexOf("NRMODE=Update")==-1 && document.location.href.indexOf("NRMODE=Unpublished")==-1){
		paramSitepanda=CapturaSitePanda();
		pasarParametro(paramSitepanda);
		favicon.change("/CMSPANDA/favicon.ico");
		gestionFlashObj();
	};
	return true;
};

document.onload=IniciarSitepanda();
window.onerror=IniciarSitepanda;


