
//============ FILTER ====================
function applyFilter()
{
 
  var strSearch = document.getElementById("str_search").value;
	var colBlock = document.getElementById("col3");
  
	reset_selections();

	
	//hide col2
    show_hide("ul","col2","none",false);
    show_hide("li","col2","none",false);

	//hide all <ul> and <li> in col3
    show_hide("ul","col3","none",false);
    show_hide("li","col3","none",false);
	 	
  	//apply the filter
	xajax_applyFilter(strSearch);
  return false;
}
//============ BOOKMARKS PAGE ====================
//---------- TOP SELECTIONS ----------
function showHideALL(item)
{
    reset_colors("col1","white");
	reset_colors("col2","white"); 
	reset_selections();
  	if ( item == "groups" ){
		show_hide("","col3","none",true);
		show_hide("","col2","block",true); 
		show_hide("ul","col2","block",false); 
		show_hide("li","col2","block",false);
	}
  	if ( item == "bookmarks" ){
		show_hide("","col2","none",true);
		show_hide("","col3","block",true); 
		show_hide("ul","col3","block",false); 
		show_hide("li","col3","block",false);
	}
  	if ( item == "reset" ){
  	    resetBookmarks();
	}
    return false;
}
//---------- SELECT SELECTIONS ----------
function resetBookmarks(col,thecolor)
{
		show_hide("","col2","block",true); 
		show_hide("","col3","block",true); 
		show_hide("ul","col2","none",false); 
		show_hide("li","col2","none",false);
		show_hide("ul","col3","none",false); 
		show_hide("li","col3","none",false);
}

function reset_colors(col,thecolor)
{
  	var colBlock = document.getElementById(col);
  	var ulList = colBlock.getElementsByTagName("li");
  	for (var i = 0; i < ulList.length; i++)  {
    	ulList[i].style.backgroundColor = thecolor;
  	}
}

function reset_selections()
{
  	getObject('catSelected').innerHTML = "........."; 
  	getObject('grpSelected').innerHTML = "........."; 
}


function show_hide(tag, col,elProperty,flag)
{
   if ( flag ){
    document.getElementById(col).style.display = elProperty;
  } else {
  	var colBlock = document.getElementById(col);
  	var aList    = colBlock.getElementsByTagName(tag);
  	for (var i = 0; i < aList.length; i++)  {
    	aList[i].style.display = elProperty;
  	}
  }
  return true;
}


function showGRP(cat_id){
	resetBookmarks();
	show_hide("li","col2","block",false);
	show_hide("li","col3","block",false);

	ul_col2_OBJ  = getObject(cat_id);
	if ( !ul_col2_OBJ ){  alert("obj ul "+cat_id+" not found, advise the administrator!");  return false; 	}
   	ul_col2_OBJ.style.display = "block";
	
	reset_colors("col1","white");
    	reset_colors("col2","white");
    	getObject('cat_' + cat_id).style.backgroundColor = "yellow"; //highlight the category
   
	//setting selections
	getObject("catSelected").innerHTML = cat_id;
	getObject("grpSelected").innerHTML = ".........";
	return false;
}

function showBKM(grp_id){
	show_hide("","col3","block",true);
	show_hide("ul","col3","none",false);
	reset_colors("col2","white");
	getObject('grp_' + grp_id).style.backgroundColor = "yellow";
	ul_col3_OBJ = getObject("gr_" + grp_id);
	if ( !ul_col3_OBJ ){ alert("ERROR obj "+grp_id+" not found, advise the administrator!"); return false;	}
   	ul_col3_OBJ.style.display = "block";
	getObject("grpSelected").innerHTML = grp_id;
	return false;
}
//================================
var oldimg = "";
function showBigPreview(){
  	myname 	= "pre-view";
  	imgsel 	= getObject("img_preview").src;   
  	pos 	= imgsel.lastIndexOf("/");
  	imgsel 	= imgsel.substr( (pos+1) ); 
	if ( imgsel == "rss_webpage_mini.gif" ){
	  	newimg = "img/rss_webpage.gif";
  		w = 850;
  		h = 567;
	}  
	if ( imgsel == "pre-view1_mini.gif" ){
	  	newimg = "img/pre-view1.gif";
  		w = 850;
  		h = 487;
	}  
	if ( imgsel == "pre-view2_mini.gif" ){
	  	newimg = "img/pre-view2.gif";
  		w = 850;
  		h = 508;
	}  
	if ( imgsel == "navigator2_mini.gif" ){
	  	newimg = "img/navigator2.gif";
  		w = 876;
  		h = 574;
	}  

	if ( oldimg != newimg ){ //to avoid to make multiple img openings...
    	divM              	= document.createElement("div");
    	divM.className    	= "notesBox";
    	divM.style.width  	= w + "px";
    	divM.style.height 	= h + "px";
    	divM.style.border 	= "3px solid red";

    	divIMG            	= document.createElement("div");
    	divIMG.innerHTML	= "<img src='" + newimg + "' border='0' alt='pre-view' onload='closePreViewTime()'/>";
    
		document.body.appendChild(divM);
    	divM.appendChild(divIMG);
    	divM.style.top       = "1px";
    	divM.style.left      = "1px";
		divM.style.display   = "block";
	}
	oldimg = newimg;
  
}
function closePreView() {
 divM.style.display = "none";
 oldimg 			= "";
}
function closePreViewTime() {
 setTimeout("closePreView()",5000);
}

// - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function preView(sel){

   getObject('pre-rss').style.background = "white";   
   getObject('pre-hp').style.background = "white";   
   getObject('pre-bm').style.background = "white";   
   getObject('pre-nv').style.background = "white";   
   getObject(sel).style.background      = "yellow";   

   if ( sel == "pre-rss" ){
      getObject('img_preview').src = "img/rss_webpage_mini.gif";
   }
   if ( sel == "pre-hp" ){
      getObject('img_preview').src = "img/pre-view1_mini.gif";
   }
   if ( sel == "pre-bm" ){
      getObject('img_preview').src = "img/pre-view2_mini.gif";
   }
   if ( sel == "pre-nv" ){
      getObject('img_preview').src = "img/navigator2_mini.gif";
   }

}

//========================================================================
function hideTag(tag_id) {
   getObject(tag_id).style.display = "none";
}

function refreshparent() {
   opener.location.reload();
}
// - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showNotes(notes,nWidth,nHeight,xoffset,yoffset,e) {
    divNoteM              = document.createElement("div");
    divNoteM.className    = "notesBox";
    divNoteM.style.width  = nWidth + "px";
    divNoteM.style.height = nHeight + "px";
    document.body.appendChild(divNoteM);
    divNoteM.innerHTML       = notes;
    divNoteM.style.top       = (getMousePos(e,"y") + yoffset) + "px";
    divNoteM.style.left      = (getMousePos(e,"x") + xoffset) + "px";
	divNoteM.style.display   = "block";

}

function closeNotes() {
 divNoteM.style.display = "none";
}
//=========================
function getMousePos(event,pos){
if (typeof event == "undefined"){ event = window.event; }
var scrollingPosition 	= getScrollingPosition();
var cursorPosition 		= [0, 0];
if (typeof event.pageX != "undefined" && typeof event.x != "undefined"){
	cursorPosition[0] = event.pageX;
	cursorPosition[1] = event.pageY;
} else {
	cursorPosition[0] = event.clientX + scrollingPosition[0];
	cursorPosition[1] = event.clientY + scrollingPosition[1];
}
if ( pos == "x" ){ return cursorPosition[0]; }
if ( pos == "y" ){ return cursorPosition[1]; }
return false;
}
// - - - - - - - - - - - - - -
function getScrollingPosition()
{
var position = [0, 0];
if (typeof window.pageYOffset != 'undefined'){
	position = [window.pageXOffset,window.pageYOffset];
} else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0){
	position = [document.documentElement.scrollLeft,document.documentElement.scrollTop];
} else if (typeof document.body.scrollTop != 'undefined'){
	position = [document.body.scrollLeft,document.body.scrollTop];
  }
return position;
}
//=======================================================
var win= null;
function NewWindow(mypage,myname,w,h,scroll,menu,tool){
 var winl = (screen.width-w)/2;
 var wint = (screen.height-h)/2;
 var settings ='height='+h+',';
 settings +='width='+w+',';
 settings +='top='+wint+',';
 settings +='left='+winl+',';
 settings +='scrollbars='+scroll+',';
 settings +='menubar='+menu+',';
 settings +='toolbar='+tool+',';
 settings +='resizable=yes,';
 settings +='location=no,';
 settings +='status=no,';
 win=window.open(mypage,myname,settings);
 if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
} 

function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}
//================== FORMS ====================================
function validateForm(formName,bgColNotValid,bgColValid)
{
  var elements = document.forms[formName].elements;
  var emailPattern = /^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/;

  for (var i = 0; i < elements.length; i++)
  {
    if (/(^| )checkRequired( |$)/.test(elements[i].className) && elements[i].value == "")
    {
      elements[i].focus();
      elements[i].style.backgroundColor = bgColNotValid;
      alert("Please fill out this field.");
      return false;
    } else {
      elements[i].style.backgroundColor = bgColValid;
	}

    if (/(^| )checkEmail( |$)/.test(elements[i].className) && !emailPattern.test(elements[i].value))
    {
      elements[i].focus();
      elements[i].style.backgroundColor = bgColNotValid;
      alert("Please fill in a valid e-mail address.");
      return false;
    }
  }

  return true;
}

//=======================================================
function isFormCatValid() {
    var frmMain = document.forms[0];
    var isValid = true;
    
    for (var i=1; i < 4; i++) {
        if ( frmMain.elements[i].value == "" ) {
            isValid = false;
   document.password.pwd1.focus();
           alert(frmMain.elements[i].name + " cannot be empty!");
        }
    }

    return isValid;
}

//=======================================================
//Contador de caracteres.
function Contar(entrada,salida,texto,caracteres) {
	var entradaObj=getObject(entrada);
	var salidaObj=getObject(salida);
	var longitud=caracteres - entradaObj.value.length;
	if(longitud <= 0) {
		longitud=0;
		texto='<span style="color:#00FF00;font-weight:bold">&nbsp;'+texto+'&nbsp;</span>';
		entradaObj.value=entradaObj.value.substr(0,caracteres);
	}
	salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}
//-------------------------------------------------------
function getObject(obj) {
	if(document.getElementById) {
			return document.getElementById(obj);
	}
	if(document.all) {
			return document.all(obj);
	}
	return null;
}

//-------------------------------------------------------
function chkPWD(min,max){
if ( document.password.oldpwd.value == "" ){
  alert( "Old Password is mandatory!");
  document.password.oldpwd.focus();
  return false;
}
if ( document.password.pwd.value == "" ){
  alert("Password is mandatory!");
  document.password.pwd.focus();
  return false;
}
if ( document.password.pwd1.value == "" ){
  alert("Repeat password is mandatory!");
  document.password.pwd1.focus();
  return false;
}

if ( document.password.oldpwd.value.length < min ){
  alert( "Old Password has to be at least " + min + " chars long");
  document.password.oldpwd.focus();
  return false;
}
if ( document.password.pwd.value.length < min ){
  alert("New Password has to be at least " + min + " chars long");
  document.password.pwd.focus();
  return false;
}
if ( document.password.pwd1.value.length < min ){
  alert( "Repeat Password has to be at least " + min + " chars long");
  document.password.pwd1.focus();
  return false;
}


if ( document.password.oldpwd.value.length > max ){
  alert( "Old Password has to be max " + max + " chars long");
  document.password.oldpwd.focus();
  return false;
}
if ( document.password.pwd.value.length > max  ){
  alert("New Password has to be max " + max + " chars long");
  document.password.pwd.focus();
  return false;
}
if ( document.password.pwd1.value.length > max  ){
  alert( "Repeat Password has to be max " + min + " chars long");
  document.password.pwd1.focus();
  return false;
}


if ( document.password.pwd.value != document.password.pwd1.value ){
  alert("Yu have typed 2 new different passwords");
  document.password.pwd.value = "";
  document.password.pwd1.value = "";
  document.password.pwd.focus();
  return false;
}
return true;

}
