//<![CDATA[
function adjust_images_by_id ( tagid, maxwidth ) {
  var obj_container = findObj ( tagid );
  var objs = obj_container.getElementsByTagName( 'img' );
  adjust_images ( objs, maxwidth );
}
function adjust_images_by_name ( tagname, maxwidth ) {
  var obj_containers = getElementsByClassName(document, tagname);
  var objs = new Array();
  for(var i = 0; i < obj_containers.length; i++) {
	var images = obj_containers[i].getElementsByTagName( 'img' );
	objs = objs.concat(images);
  }
  adjust_images ( objs, maxwidth );
}
/**
* Este método elimina el px de las dimensiones...
* @public
* @param {string} dimension    ej. (102px) y esta funcion devuelve el numero 102
* @return integer
*/
function dimension2int( d ) {
  d = new String ( d );
  if (d.indexOf ( 'px' ) > -1) d = d.replace ( 'px', '' );
  return d;
}
function adjust_images ( images, maxwidth ) {
  var w = 0;
  var h = 0;
  var ratio = 1;  
  for(var i = 0; i < images.length; i++) {
     w = dimension2int(images[i].width);
     if (!(w > 0)) w = dimension2int(images[i].style.width);
     if (w > maxwidth) {	   
       h = dimension2int(images[i].height);
       if (!(h > 0)) h = dimension2int(images[i].style.height);
       images[i].style.width = maxwidth+'px';
       images[i].width       = maxwidth;
       if (h > 0) {
         images[i].style.height = (h * maxwidth / w)+'px';
         images[i].height 	    = h * maxwidth / w;
       }
     }
  }
  return true;
}
function switch_Panels( id1, id2 ) { //v1.0 by caridy
  var obj1 = findObj ( id1 );
  var obj2 = findObj ( id2 );
  if (obj1)
    obj1.style.display = 'none';
  if (obj2)
    obj2.style.display = 'block';
  return false;
}
function adjust_Panels () {  // v1.0 by caridy - for adjust height in multiple div
    var panels = adjust_Panels.arguments;
	var largest = 0, i, obj;
	for(i = 0; i < panels.length; i++) {
	  obj = findObj ( panels[i] );
	  if (obj.scrollHeight > largest)
	     largest = obj.scrollHeight;
	}
	for(i = 0; i < panels.length; i++) {
	  obj = findObj ( panels[i] );
	  obj.style.height = String ( largest ) + 'px' ;
	}
}
function display_Advanced_Search() { //v1.0 by caridy
  document.forms['PredefinedSearchForm'].style.display = 'none';
  document.forms['AdvSearchForm'].style.display 	   = 'block';
  return false;
}
function display_Predefined_Search() { //v1.0 by caridy
  document.forms['PredefinedSearchForm'].style.display = 'block';
  document.forms['AdvSearchForm'].style.display 	   = 'none';
  return false;
}
function open_window(theURL,winName,features) {
  window.open(theURL,winName,features);
} 
function view_photo(obj){ //v1.0 by caridy
  w = 720;
  h = 580;
  /// detect a special case of "web browser"
  is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
  if (!is_ie)
    h = h + 95;
  window.open(obj.href,'','scrollbars=yes,width='+w+',height='+h);
  return false;
}
function display_forums(obj){ //v1.0 by caridy
  w = 880;
  h = 580;
  /// detect a special case of "web browser"
  is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
  if (!is_ie)
    h = h + 95;
  window.open(obj.href,'forums','scrollbars=yes,width='+w+',height='+h);
  return false;
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
function external_navigate(url){ //v1.0 by caridy
  if (url != '')
    window.open(url,'','');
  return false;
}
function navigate( url ) {
	document.location.href = url;
}
function recommend ( url ) {
  var page = base64encode(utf16to8(document.URL)); // url = utf8to16(base64decode(page));
  var title = document.title;
  if ( url.indexOf ('?') == -1 )
    location.href = url + '?_title=' + title  + '&_url=' + page;
  else
    location.href = url + '&_title=' + title  + '&_url=' + page;
}
function validate_xhtml ( obj ) {
  var page = escape ( document.URL ); // aqui codifico la url para que los parametros no se mesclen...
  var url  = obj.href;
  if ( url.indexOf ('?') == -1 )
    external_navigate ( url + '?uri=' + page );
  else
    external_navigate ( url + '&uri=' + page );
  return false;
}
function validate_css ( obj ) {
  var page = escape ( document.URL ); // aqui codifico la url para que los parametros no se mesclen...
  var url  = obj.href;
  if ( url.indexOf ('?') == -1 )
    external_navigate ( url + '?uri=' + page );
  else
    external_navigate ( url + '&uri=' + page );
  return false;
}
function add_to_favorites ( msg ) {
  var page = document.url;
  var title = document.title;
  if (msg != null)
    alert ( msg );
  window.external.AddFavorite( document.location,  document.title );
  return false;
}
function navegate( url ) {
  if (url != '')
    location.href = url;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

// standard date display function with y2k compatibility
function displayDate() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Deciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( " " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year);
}

function email_onblur(correo)
{
  aux = new String(correo);
  var aux1=aux.indexOf("@",1);
  if (aux1 == -1)
    return true;
  if (aux.indexOf(".",aux1) == -1)
    return true;
  return false; // check passed
}

function validaphone(phone)
{
    var regEx = /[0-9]{6}/;
    if(regEx.test(phone))
    {
    return false;
    }
    else
    {
    return true;
    }
}
function close_window () {
  window.close ();
}
function check_email( correo )
{
  aux = new String(correo);
  var aux1=aux.indexOf("@",1);
  if (aux1 == -1)
    return true;
  if (aux.indexOf(".",aux1) == -1)
    return true;
  return false; // check passed
}
function check_passport( pass, confirmpass )
{
  if(pass != confirmpass)
    return false;
  else
    return true;
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.1 modify by caridy
  if (!isNaN(TMS_CURRENT_LANG) || (TMS_CURRENT_LANG == 'eng')) {
    var VALIDATE_EMAIL 			= " must contain an e-mail address.\n";
	var VALIDATE_NUMBER 		= " must contain a number.\n";
	var VALIDATE_QUOTED_NUMBER 	= " must contain a quoted number";
	var VALIDATE_REQUIRED_FIELD = " is required.\n";
	var VALIDATE_ERROR_OCCURRED = "The following error(s) occurred:\n";
  } else { // spanish por defecto
    var VALIDATE_EMAIL 			= " debe contener una dirección de E-mail.\n";
	var VALIDATE_NUMBER 		= " debe contener un número.\n";
	var VALIDATE_QUOTED_NUMBER 	= " debe contener un número entre ";
	var VALIDATE_REQUIRED_FIELD = " es requerido.\n";
	var VALIDATE_ERROR_OCCURRED = "Han ocurrido los siguientes errores:\n";
  }
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+VALIDATE_EMAIL;
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+VALIDATE_NUMBER;
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+VALIDATE_QUOTED_NUMBER+min+'..'+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+VALIDATE_REQUIRED_FIELD; }
  } if (errors) alert(VALIDATE_ERROR_OCCURRED+errors);
  document.MM_returnValue = (errors == '');
}
function validate_field() { //v4.1 by caridy (sources: validateForm from macromedia MX 2004)
  var i,p,q,nm,test,num,min,max,errors='',args=validate_field.arguments;
  for (i=0; i<(args.length-2); i+=4) {
    test=args[i+2];
    msg=args[i+3];
	val=MM_findObj(args[i]);
    if (val) {
	  nm=val.name;
	  if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) {
		  p=val.indexOf('@');
          if (p<1 || p==(val.length-1))
		    errors+='- '+msg+'\n';
        }
		else if (test!='R') {
		  num = parseFloat(val);
          if (isNaN(val))
		    errors+='- '+msg+'\n';
          if (test.indexOf('inRange') != -1) {
		    p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num)
		      errors+='- '+msg+'\n';
          }
		}
	  }
	  else if (test.charAt(0) == 'R')
	    errors+='- '+msg+'\n';
	}
  }
  document.MM_returnValue = (errors == '');
  return errors;
}
function validate_check( obj, msg ) {
  errors='';
  val=MM_findObj(obj);
  if ((val) && (val.checked != true))
    errors+='- '+msg+'\n';
  document.MM_returnValue = (errors == '');
  return errors;
}

// Fromulario de combio de fecha... (add by caridy)

// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function updateCalendar(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the     s function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, updateCalendar, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapImage( obj, src ) { // caridy: v1.0
   document.swapImages = new Array;
   if (!obj.src) obj = document.getElementById( obj );
   if (obj && obj.src && document.swapImages) {
	 document.swapImages.push ( obj.src );
     obj.src = src;
   }
   obj.hideFocus = true;
}
function nextImage( obj, items ) { // caridy: v1.0
   if (!obj.src) obj = document.getElementById( obj );
   if (obj && obj.src && items && (items.length > 1)) {
	 var j = 0;
	 for (var i=0; i<items.length-1; i++)
	   if (obj.src.indexOf(items[i]) >= 0)
	     j = i + 1;
     obj.src = items[j];
   }
  obj.hideFocus = true;
}
function restoreImage( obj, newsrc ) { // caridy: v1.0
  if (obj && obj.src && document.swapImages)
    if (!newsrc) obj.src = document.swapImages.pop(); else obj.src = newsrc;
  obj.hideFocus = true;
}
// Cookies control, by caridy...
function createCookie(name,value,days)
{
	var expires = "";
	if (days) {
	  var date = new Date();
	  date.setTime(date.getTime()+(days*24*60*60*1000));
	  var expires = "; expires="+date.toGMTString();
	}
	document.cookie = name + "=" + value + expires + "; path=/";
	return true;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
	  var c = ca[i];
	  while (c.charAt(0)==' ') 
	    c = c.substring( 1, c.length );
	  if (c.indexOf(nameEQ) == 0) 
	    return c.substring( nameEQ.length, c.length );
	}
	return null;
}

function eraseCookie(name)
{
	return createCookie(name,"",-1);
} 
function switch_fieldset( anch, fs_id, id ) { //v1.0 by caridy
  var obj_container = findObj ( fs_id );
  for (var i = 0; i < obj_container.childNodes.length; i++) {
    if (obj_container.childNodes[i].nodeName == 'DIV') {
		obj_container.childNodes[i].style.display = 'none';
	} else if (obj_container.childNodes[i].nodeName == 'LEGEND') {
	    for (var j = 0; j < obj_container.childNodes[i].childNodes.length; j++) {
		   if (obj_container.childNodes[i].childNodes[j].nodeName == 'A')
		     obj_container.childNodes[i].childNodes[j].className = 'lclose';
		}
	}
  }		
  var obj1 = findObj ( id );
  if (obj1)
    obj1.style.display = 'block';
  anch.className = 'lopen';
  return false;
}

// select HTMLEntity
function auto_selection ( id, value ) {
  var id_obj = findObj ( id );
  if (id_obj)
	for (var i = 0; i < id_obj.length; i++)
	  if (id_obj.options[i].value == value)
		id_obj.options[i].selected = true;
  return true;
}
function insert_into_list ( obj, value, text ) {
	var n = obj.options.length;
	var j = n;
	if ( navigator.appName == 'Netscape' )
	  obj.add ( document.createElement("option"), null );
	else  
	  obj.add ( document.createElement("option"), j );
	obj.options[n].value = value;
	obj.options[n].text  = text;
}
function reset_list ( obj ) {
   while (obj.options.length > 0) { // eliminando todos los elementos...
	if ( navigator.appName == 'Netscape' )
	  obj.options[0] = null;
	else  
	  obj.options.remove (0);
   }
}

//]]>