document.IN_swapArray=new Array(); // para o setSource
document.imageHandler=new Array(); // para o preload

function locationURL(){

	var lang = document.getElementById('ctl00_VariationLabel').value;
	var	urlDest = '/CustomControls/SendAFriendPage.aspx?URLArtigo=';
	//alert(urlDest);
	urlDest = urlDest + document.location.toString();
	
	//alert(urlDest + '&lang=' + lang);
	window.open(urlDest + '&lang=' + lang,'popup','height=650,width=450,status=yes');
	//document.location = urlDest;
}



function ListaRecursosPaginada_GotoToPage(psUrlPage, psValue)
{    
    window.location.href= psUrlPage + "page=" + psValue;
}

function ListaArtigosPaginada_GotoToPage(psUrlPage, psValue)
{    
    window.location.href= psUrlPage + "page=" + psValue;
}


function IN_getImage(oImage_IN, doc) { //v1.0
	var i,tImage;if(!doc) doc=document;
	if(!(tImage=doc.images[oImage_IN])&&!(doc.all)&&doc.getElementById) tImage=doc.getElementById[oImage_IN];
	if(!(tImage=doc.images[oImage_IN])&&doc.all) tImage=doc.all[oImage_IN];
	for(i=0;!tImage&&doc.images&&i<doc.layers.length;i++) tImage=IN_getImage(oImage_IN,doc.layers[i].document);return tImage;
}

function IN_setImageSource(oImage_IN, strNewSrc) { //v1.0
	tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=strNewSrc;}
}

function IN_setImageSourceOriginal(oImage_IN) { //v1.0
	tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=document.IN_swapArray[oImage_IN];}
}

function IN_setImageSourceOriginalObjectDiv(objectDiv, oImage_IN) { //v1.0
	if (document.getElementById(objectDiv) == null || document.getElementById(objectDiv).style.display == '' || document.getElementById(objectDiv).style.display == 'none') {
		tImage=IN_getImage(oImage_IN);if(tImage){if (document.IN_swapArray[oImage_IN]==null||document.IN_swapArray[oImage_IN]==undefined) {document.IN_swapArray[oImage_IN]=tImage.src;}tImage.src=document.IN_swapArray[oImage_IN];}
	}
}

function IN_setpreloadImages() {
	for(i=0;i<IN_setpreloadImages.arguments.length;i++) {
		document.imageHandler[IN_setpreloadImages.arguments[i]]=new Image();
		document.imageHandler[IN_setpreloadImages.arguments[i]].src=IN_setpreloadImages.arguments[i];
	}
}

/* MUDANÇA DE IMAGEM - IMAGE GALLERY */
function showPic(whichpic, placeholder, hrefplaceholder, hrefactive) {
	if (document.getElementById) {
		document.getElementById(placeholder).src = whichpic.href;
		document.getElementById(hrefplaceholder).href = whichpic.href;
		for(i = 0; i < document.links.length; i++) {
			if(document.links[i].name == hrefactive) {
				document.links[i].className = '';
			}
		}
		whichpic.className = 'imgActive opacityFoto';
		return false;
	} else {
		return true;
	}
}

/*// RETIRAR BG INPUT

function bgFields() {
  var thisform = document.getElementsByTagName("input");
  for (var i=0; i<thisform.length; i++) {
    
    if (thisform[i].className.indexOf("inputBg") == -1) continue;
	
	thisform[i].onfocus = function() {
		this.className="cleanBg";
     }
     
     thisform[i].onblur = function() {
		this.className="inputBg";
	}

    }    
   }


// HOVER LIs

function highlightRows() {
	if(!document.getElementsByTagName) return false;

	var thisOls = document.getElementsByTagName("ul");
	for (var i=0; i<thisOls.length; i++) {

	if (thisOls[i].className.indexOf("hoverLis") == -1) continue;
	
		var thisLis = thisOls[i].getElementsByTagName("li");  
	
		for (var i=0; i<thisLis.length; i++) {
						
			thisLis[i].onmouseover = function() {
			this.style.backgroundColor="#f0f0f0";
		}
			
		thisLis[i].onmouseout = function() {
		this.style.backgroundColor="";
		}
    }
  }
}*/


// INCIAR FUNÇÕES
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


//addLoadEvent(bgFields);

//addLoadEvent(highlightRows);

//addLoadEvent(prepareForms);


// RETIRAR VALUE INPUT
/*function resetFields(whichform) {
  for (var i=0; i<whichform.elements.length; i++) {
    var element = whichform.elements[i];
    if (element.type == "submit") continue;
    if (!element.defaultValue) continue;
    element.onfocus = function() {
    if (this.value == this.defaultValue) {
      this.value = "";
     }
    }
    element.onblur = function() {
      if (this.value == "") {
        this.value = this.defaultValue;
      }
    }
  }
}

function prepareForms() {
  for (var i=0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
    resetFields(thisform);
    }
}*/





loadi9aGenericFunctions = function () {

	i9aGenericFunctions.initialize();
	
}

window.i9aGenericFunctions= {

	initialize: function() {
		//alert("i9aGenericFunctions.initialize");
	},
	
	obtemCodigoTecla: function( e ) 		
	{
		var cod;
		
		if (document.all){
			cod=e.keyCode;
		}else {
			cod=e.which;
		}
	

	
		if (Number(cod)==13){
			
			if (document.all){
				e.keyCode=0;
			}else {
				e.which=0;
			}
		}		
	
		return cod;
	},

	/*
	Verifica validar a inserção de caracteres apenas numéricos
	numa input box:
	Recebe:		o 'event'
	Devolve:	true | false consoante a tecla seja numérica ou não	
	Deve ser chamada nos eventos onkeydown e onkeypress 
	Ex: onkeydown="return i9aGenericFunctions.invalidaNaoNumerico(event);" 
	*/
	invalidaNaoNumerico: function( pEvent )
	{		
		var key_code = this.obtemCodigoTecla(pEvent);
	
		if (key_code==8 || key_code == 9  ||  key_code==0 ||  key_code==39 || key_code==46
		    ||( !pEvent.shiftKey &&
              (key_code==35 ||  key_code==36 ||  key_code==37 ||  key_code==39) )		
		) //teclas DEL e outras tais com DEL_backspace e cursores (9 = tab) (35-39=cursores+home+end)
		{
			return true;
		}
	
	  if ((key_code < 48) || (key_code > 57)) { // Not numeric
	    if ((key_code < 96) || (key_code > 105)){	// num Lock    
	      return false;
	    }
	  }
	  return true;
	}
	
	

};

addLoadEvent(loadi9aGenericFunctions);
