function guardaCookies() 
{
	cargarPagina("http://mail.terrabancomer.com/mail/loginCorreo.asp?tipobuzon=0");
}		
function LoadPage(url)
{
	window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame="+url;		
}

function cargarPagina(url)
{	
	if (getCookie('nID%5FUsuario')== null)
	{
		//alert("no Logeado, Url : "+url);
		SetCookie('Pagina',"");
		KillCookie('Pagina');
		SetCookie('Pagina',url);	
		window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame=Loginunico.asp";		
	}
	else
	{
		//alert("Logeado, Url : "+url);
		window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame="+url;				
	}	
}

function ClubCompras(url)
{
	window.open("../Club/SE_ClubCompras.asp", "CCTB","location=0, toolbar=1, directories=1, status=1, menubar=1, scrollbars=1, resizable=1, width=800, height=410");		
/*	if(getCookie('nID%5FUsuario')== null)
	{
		SetCookie('Pagina',"");
		KillCookie('Pagina');
		SetCookie('Pagina',url);	
		window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame=Loginunico.asp";		
	}
	else
	{	
		if(getCookie('TipoUsuario')==1)
		{
			w=800 
			h=600 
			if (window.screen) { 
			w = window.screen.availWidth-50; 
			h = window.screen.availHeight-50; 
			} 
			window.open('../../../ClubCompras.asp','NewWindow','location=no,scrollbars=yes,resizable=yes,width='+w+',height='+h+',left=0,top=0');	
		}
		else
		{
			alert('Para realizar compras, favor de dirigirse a su Administrador');
		}
	}	*/
}

function SUA_IDSE(url)
{
	if(getCookie('nID%5FUsuario')== null)
	{
		SetCookie('Pagina',"");
		KillCookie('Pagina');
		SetCookie('Pagina',url);	
		window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame=loginunico.asp";		
	}
	else
	{	
		if(getCookie('TipoUsuario')==1 || getCookie('TipoUsuario')==0 || getCookie('TipoUsuario')==2 || getCookie('TipoUsuario')==4 || getCookie('TipoUsuario')==10 || getCookie('TipoUsuario')==11)
		{
			window.top.ov_desktop.location.href="../../../OV_Mail_cargarmail.asp?frame="+url;
		}
		else
		{
			alert('Este servicio es exclusivo para los usuarios de la Zona de Negocios,\nConsulte a su administrador.');			
			LoadPage(getCookie('origen'));
			SetCookie('origen','');
		}
	}	
}


function Selecciona(forma,elemento,id)
{
	document.forms(forma).elements(elemento).value=id;	
} 
function OpenWindow(sUrl,sname,sfutures)
{
	newWin=window.open(sUrl,sname,sfutures);
}
function Refresh(URL)
{
		history.go(0);
}
function Max_Long(xy,Lon)
{
	var c=xy.value;
	var temp;
	
	if(c.length > Lon-1){
		temp=c.substring(0,Lon)
		xy.value="";
		xy.value=temp;
	}	
}

function Check_All(chkMaster,chkElemento)
{
	if (document.getElementsByName(chkElemento)!=null)
	{
		var len=0;
		var i=0;
		var val=0;
		
		if(typeof(chkElemento)!="undefined")
		{
			if(typeof(chkElemento.length)!='undefined')
				{len=chkElemento.length;}
				else
				{len=1}
		}
		
		if (chkMaster.checked==1){
			val=1;}
			
		if (len==1){
			chkElemento.checked=val;}
			
		if (len>1)
		{
			for (i=0;i<len;i++)
			{
				chkElemento[i].checked=val;
			}
		}		
	}
}	

function Uncheck_Master(chkMaster,chkElemento)
{
	if (chkMaster.checked==1)
	{
		chkMaster.checked=0;
	}
	else
	{
		Check_Master(chkMaster,chkElemento);
	}
}
function Check_Master(chkMaster,chkElemento)
{
	var len=0;
	var i=0;
	var val=0;
	var check=true;
	
	if(typeof(chkElemento)!="undefined")
		{
			if(typeof(chkElemento.length)!='undefined')
				{len=chkElemento.length;}
		}
	
	for (i=0;i<len;i++)
	{
		if(chkElemento[i].checked==0)
		   check=false;		    		
	}
			
	if (check==true)
		chkMaster.checked=1	
}

function exist_Cookie(CookieName)
{
	var bencontro=false;
	if(document.cookie!=""){
		thisCookie=document.cookie.split("; ");
		for(i=0;i<thisCookie.length;i++){
			if (CookieName == thisCookie[i].split("=")[0]){
				bencontro=true;
				break;}
			}
	}			
	return bencontro;		
}
function Cookie_List()
{
	if(document.cookie!=""){
		thisCookie=document.cookie.split("; ");
		for(i=0;i<thisCookie.length;i++)
		{
			alert(thisCookie[i].split("=")[0]+" : "+thisCookie[i].split("=")[1]);
		}			
	}				
}
function KillCookie(name)
 {
		expireDate=new Date()
		expireDate.setDate(expireDate.getDate()-1);
		document.cookie= name+"=0;expires="+ expireDate.toGMTString();
 }
function KillCookies()
 {
		if(document.cookie !="")
		{
			thisCookie=document.cookie.split("; ");
			expireDate=new Date();
			expireDate.setDate(expireDate.getDate()-1);
			for (i=0;i<thisCookie.length;i++)
			{	
				cookieName=thisCookie[i].split("=")[0];
				/*alert(cookieName+':'+thisCookie[i].split("=")[1]);*/
				document.cookie= cookieName+"=;expires="+ expireDate.toGMTString();
			}
		}		
 } 
function SetCookie(name,valor)
 {
	document.cookie=name+"="+valor+";path=/";
 }

 function ReadCookie(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 getCookie(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));
}
