
//==========================================
// global vars
//==========================================
var searchRaw = null;//article grid raw
var dfoc;//delayed focus

//==========================================
// localize browser
//==========================================

var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0
var ff = (document.getElementById && (ie != 1)) ? 1 : 0

//==========================================
// GetWinHeight
//==========================================

function GetWinHeight() 
{
   if (window.innerHeight)
      /* NN4 and compatible */
      return window.innerHeight;
   else if
   (document.documentElement && document.documentElement.clientHeight)
      /* MSIE6 in std. mode - Opera a Mozilla which use window.innerHeight */
      return document.documentElement.clientHeight;
   else if (document.body && document.body.clientHeight)
      /* older MSIE + MSIE6 in quirk mode */
      return document.body.clientHeight;
   else
      return null;
}

//==========================================
// GetWinWidth
//==========================================

function GetWinWidth()
{
	if (window.innerWidth) 
      /* NN4 and compatible */
		return window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
      /* MSIE6 in std. mode - Opera a Mozilla which use window.innerHeight */
		return document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
      /* older MSIE + MSIE6 in quirk mode */
		return document.body.clientWidth;
	else 
		return null;
}

//==========================================
// Get element by id
//==========================================

function GetById(id)
{
	itm = null;

	if (ie)
	{
		itm = document.all[id];
	}
	else if (ff)
	{
		itm = document.getElementById(id);
	}
	else if (ns)
	{
		itm = document.layers[id];
	}
	
	return itm;
}

//==========================================
// SetCookie
//==========================================

function SetCookie (name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

//==========================================
// GetCookie
//==========================================

function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  

	var i = 0;  
	while (i < clen) 
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) 
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) 
			break;   
	}  

	return null;

}

//==========================================
// getCookieVal
//==========================================

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) 
	{ 
		endstr = document.cookie.length; 
	}
	
	return unescape(document.cookie.substring(offset, endstr));
}

//==========================================
// DeleteCookie
//==========================================

function DeleteCookie (name)
{
    document.cookie = name + "=" + getCookie(name) + "; expires=" + (new Date()).toGMTString() + ";";
}

//==========================================
// Inicialization
//==========================================

function Inicialization(divBody, divWaiting)
{
   document.getElementById(divBody).style.display = "";
   document.getElementById(divWaiting).style.display = "none";
}

//==========================================
// Trim
//==========================================

function Trim(value)
{
	if(value.length < 1)
		return "";
	value = RTrim(value);
	value = LTrim(value);
	if(value=="")
		return "";
	else
		return value;
}

//==========================================
// RTrim
//==========================================

function RTrim(value)
{
	var w_space = String.fromCharCode(32);
	var v_length = value.length;
	var strTemp = "";
	if(v_length < 0)
		return"";

	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(value.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = value.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
} 

//==========================================
// LTrim
//==========================================
function LTrim(value)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
		return"";

	var v_length = value.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(value.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = value.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} 
	return strTemp;
} 

//==========================================
// SetFocus
//==========================================
function SetFocus(id)
{
	a = GetById(id);
	if (a != null)
		a.focus();
}

//==========================================
// Popup
//==========================================
function Popup(url, width, height)
{
var left = (screen.width/2) - width/2;
var top = (screen.height/2) - height/2;
if (left < 0)
	left = 0
if (top < 0)
	top = 0

winHandle = window.open(url, "image" ,"directories=no,resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no, height="+height+",width="+width+",top="+top+",left=" + left +" "); 
winHandle.focus();
winHandle.resizeTo(width, height);
winHandle.moveTo(left, top);

}
//==========================================
// DoPostBackSpecial
//==========================================
function DoPostBackSpecial(eventTarget, eventArgument) 
{
	var theform = document.forms["_main:_mainform"];
	if (!theform) 
	{
		theform = document._main__mainform;
	}
	if (!theform) 
	{
		theform = document.forms["__aspnetForm"];
	}
	if (!theform) 
	{
		theform = document.__aspnetForm;
	}
	
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();		
}

//==========================================
// Dynamic IFRAME
//==========================================

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["txtBlockFrame"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller


