// navigation functions

function navOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#a28f7f';
		}
	}
}

function navOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'nav-select') {
			document.getElementById(navName).style.background = '#73563f';
		}
	}
}

function dnavSelect(navName) {
	if (document.getElementById) {
		document.getElementById(navName).className = 'dnav-select';
	}
}

function dnavOn(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.background = '#ede9e6';
		}
	}
}

function dnavOff(navName) {
	if (document.getElementById) {
		if (document.getElementById(navName).className != 'dnav-select') {
			document.getElementById(navName).style.background = '#ffffff';
		}
	}
}

function showMenu(divName) {
	if (document.getElementById) {
		document.getElementById(divName).style.display = 'block';
	}
}

function hideMenu(divName) {
	if (document.getElementById) {
		document.getElementById(divName).style.display = 'none';
	}
}

// investor info change

function showInv1() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#000000';
		document.getElementById('inv-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-info1').style.display = 'block';
		document.getElementById('inv-info2').style.display = 'none';
	}
}

function showInv2() {
	if (document.getElementById) {
		document.getElementById('inv-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-tab-r-a').style.color = '#000000';
		document.getElementById('inv-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('inv-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('inv-info1').style.display = 'none';
		document.getElementById('inv-info2').style.display = 'block';
	}
}


// investor info callout change

function showInvCallout1() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#000000';
		document.getElementById('inv-call-tab-r-a').style.color = '#cc3300';
		document.getElementById('inv-call-info1').style.display = 'block';
		document.getElementById('inv-call-info2').style.display = 'none';
	}
}

function showInvCallout2() {
	if (document.getElementById) {
		document.getElementById('inv-call-tab-l-a').style.color = '#cc3300';
		document.getElementById('inv-call-tab-r-a').style.color = '#000000';
		document.getElementById('inv-call-info1').style.display = 'none';
		document.getElementById('inv-call-info2').style.display = 'block';
	}
}

// content tabs change

function showContent1() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#000000';
		document.getElementById('content-tab-r-a').style.color = '#a28f7f';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-info1').style.display = 'block';
		document.getElementById('content-info2').style.display = 'none';
	}
}

function showContent2() {
	if (document.getElementById) {
		document.getElementById('content-tab-l-a').style.color = '#a28f7f';
		document.getElementById('content-tab-r-a').style.color = '#000000';
		document.getElementById('content-tab-l').style.borderBottom = '1px solid #e4e2cf';
		document.getElementById('content-tab-l-p').style.borderTop = '4px solid #c1b5aa';
		document.getElementById('content-tab-r').style.borderBottom = '1px solid #ffffff';
		document.getElementById('content-tab-r-p').style.borderTop = '4px solid #e44c16';
		document.getElementById('content-info1').style.display = 'none';
		document.getElementById('content-info2').style.display = 'block';
	}
}

// dropdown select location change
function sel(Url) {
	if (Url) {
  	window.open(Url,"_blank");
  }
}

// open a popup window
function openwin(url,w,h,s) {
  var scrl;
	if (s) { scrl="scrollbars=yes,"; w = w+16; }
	else { scrl="scrollbars=no,"; }

	if (!w) w = 640;
	if (!h) h = 480;

	fenster = window.open(url,"_blank",scrl+"resizable=yes,width="+w+",height="+h+",screenX=50,screenY=50");
	fenster.focus();
}

// font change functions

function fontsizeup() {
  active = getActiveStyleSheet();
  setActiveStyleSheet('large');
  document.getElementById('u-reg').style.display = 'inline';
  document.getElementById('u-large').style.display = 'none';
}

function fontsizedown() {
  active = getActiveStyleSheet();
  setActiveStyleSheet('reg');
  document.getElementById('u-reg').style.display = 'none';
  document.getElementById('u-large').style.display = 'inline';
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('reg');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

//

//hide/show lang dropdown when onmouseover/onmouseout on main navigation
function showHideLang(){
	/*
	if (document.getElementById){
	    lang_container = document.getElementById('lang-container');
	    if (lang_container.style.visibility == 'hidden'){
	    	 lang_container.style.visibility = 'visible';
	    }else {
	    	 lang_container.style.visibility = 'hidden';
	    }
	}
	*/
}

function MM_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
  var obj=MM_findObj(objStr);
  if (obj) eval('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
}

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 getURLById(id)
{
	return "id=" + document.getElementById(id).innerHTML + "&i=" + id;
}

function redirect(id)
{

	window.location = 'biblioteca_patologias.asp?' + getURLById(id);
}

function redirectURL(url)
{

	window.location = url;
}
function getBackToList()
{	
	var url = window.location.href;
	var urlparts = url.split('?');
	var url_redir = urlparts[0];
	window.location = url_redir;
}

function showPopUpAlertaFarma(page) {

    	var izquierda = (screen.availWidth - 500) / 2;
    	var arriba = (screen.availHeight - 180) / 2;
    	open('AvisoAlertasFarma.asp?url=' + page,'aviso','top='+arriba+',left='+izquierda +',width=330,height=210,scrollbars=0,toolbars=0,menubar=0,statusbar=0');
}

function EsMedico(valor) {

 myRow = document.getElementById('Esp');
 myRowAux = document.getElementById('EspAux');

 myRowNum = document.getElementById('NumCol');
 myRowNumAux = document.getElementById('NumColAux');

 especialidad = document.getElementById('especialidad')
 RowDetEsp = document.getElementById('DetEsp');

 RowDetEspAux = document.getElementById('DetEspAux')

 my = document.getElementById('DetEsp')

 if (valor == "1") {
  myRow.style.display = '';
  myRowAux.style.display = '';

  myRowNum.style.display = '';
  myRowNumAux.style.display = '';

  RowDetEspAux.style.display = 'none';

  if (especialidad[especialidad.selectedIndex].value == "53") {
   RowDetEsp.style.display = '';
  }
  else {
   RowDetEsp.style.display = 'none';
  }

 }
 else {


  myRow.style.display = 'none';
  myRowAux.style.display = '';

  myRowNum.style.display = 'none';
  myRowNumAux.style.display = '';
  my.style.display = 'none';

  RowDetEspAux.style.display = '';

  especialidad.selectedIndex = 0;

 }
}


function setMenuStyle(id)
{
	var id_array = new Array("nav-acerca", "nav-Productos", "nav-actualidad", "nav-servicios", "nav-formacion", "nav-biblioteca");
	for (i=0; i<id_array.length; i++)
	{
		if(id==id_array[i])
			document.getElementById(id_array[i]).className = "nav-select";
		else
			document.getElementById(id_array[i]).className = "nav";
	}

}

function Submitir_Baja() {

	if (confirm("Est seguro de darse de baja ?")==true)
		{
			document.Formulario.submit();
		}
}

function compruebaEmail(obj) {


 email = obj.value
 if (email.length > 0)
	 {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,5})+$/.test(email)){
		return (true)
		}
		alert("Mail incorrecto.\n\nEj: nombre@dominio.ext");
		obj.focus();
		return (false)
	 }
}

var sub_list_show = false;
var last_id_showen;
function ShowEmailForm(content_form, Action, tpl_id, email)
{	
    var content_target	= content_form;    
    switch(Action)
    {
        case "off":			
            content_target.style.display = "none";
            break;
        case "on":	        	
            content_target.style.display = "block";            
            document.getElementById("iframe_emails").src = "../MD/email_send.aspx?to=" + email + "&tpl_id=" + tpl_id;            
		    break;
    } 
    return false;   
}

var pre_info;
function ShowClientInfo(content_form, Action, webuser_id)
{	
    var content_target	= content_form;         
    switch(Action)
    {		
        case "off":			           
            content_target.innerHTML = pre_info;
            break;
        case "on":	  
			pre_info = content_target.innerHTML;           
            document.getElementById("iframe_clients").src = "../RUN/run_client_info.aspx?webuser_id=" + webuser_id;            
            content_target.innerHTML += document.getElementById("client_info").innerHTML;            
            content_target.innerHTML = content_target.innerHTML.replace('###WEBUSERID###', webuser_id);            
            window.location = "#client_" + webuser_id;
		    break;
    } 
    return false;   
}

function trim (str) 
{
	str = this != window? this : str;
	return str.replace(/^s+/, '').replace(/s+$/, '');
}

/*** Show the float login ***/
function SwitchModal()
{
	float_shadow = document.createElement("div");
	float_shadow.id = "shadow";

	docBody = document.getElementsByTagName("body").item(0);
	docBody.appendChild(float_shadow);

	t = document.getElementById("shadow");
	t.style.position = "absolute";
	t.style.width = parseInt(docBody.clientWidth) + 20 + "px";
	t.style.height = docBody.clientHeight + "px";
	t.style.backgroundColor = "#CCCCCC";

	if(navigator.userAgent.indexOf("IE")!=-1)
		t.style.filter="alpha(opacity:50)";
	else
		t.style.MozOpacity=0.5;
	t.style.top = 0;
	t.style.left = 0;
	//document.getElementById("login_float").style.zIndex = t.style.zIndex + 100;
}

function ShowFloatLogin(modal_obj)
{
	//SwitchModal();
	document.getElementById("login_float").style.display = "block";
	document.getElementById("fr_login_float").src = "login.asp";
}

/*** Llenar contenido ***/
//** params -> a=1&b=2&c=3
function GetContent(list_script, target_id, method, params)
{	
    var myConn 	= new XHConn();    
    var content_target	= document.getElementById(target_id);		    
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {content_target.innerHTML=oXML.responseText;};			
	myConn.connect(list_script, method, params, fnWhenDone);    
	/*myConn.connect("options_menu.aspx", "GET", "section_id=1", fnWhenDone);   */
}

//*** Recuperar los hijos para llenar el listado de opciones **//
function BindMenu(parent, uri)
{		
	var mylist=document.getElementById(parent);			
	if(mylist!=undefined)
	{
		for (i=0; i<mylist.childNodes.length; i++)
		{
			nodeId = mylist.childNodes[i].childNodes[1].id;
			if(nodeId.indexOf('sub_list_')!=-1)
			{
				var section_id = nodeId.substr(9);				
				//** Fill the list menu			
				GetContent(uri + "options_menu.aspx", nodeId, "GET", "section_id=" + section_id);				
			}		
		}
	}
}

//** Actualiza el email del cliente - Seccion "Verificar emails" NetForce
function UpdateEmail(id)
{		
	var myConn 	= new XHConn(); 
    var old_email=document.getElementById("email_" + id);    
    var textbox_email=document.getElementById("textbox_" + id);
    var new_email = document.getElementById("new_email_" + id).value;
    new_email = new_email.replace(/^\s+|\s+$/g,'');        
    //** Actualizar resultado en el listado con el nuevo email
    old_email.innerHTML = "<span style='color:red'>Modificando.....</span>";
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {old_email.innerHTML=oXML.responseText;};				
	myConn.connect("update_email.aspx", "GET", "user_id=" + id + "&new_email=" + new_email, fnWhenDone);
	
	/*var fnWhenDone = function (oXML) {textbox_email.innerHTML=oXML.responseText;};			
	myConn.connect("update_email.aspx", "GET", "user_id=" + id, fnWhenDone);*/
	
}

//** Actualiza el email del cliente - Seccion "Verificar emails" NetForce
function GetEmailBlocks(id)
{		
	var myConn 	= new XHConn(); 
    var email_blocks = document.getElementById(id);           
    //** Actualizar resultado en el listado de bloques 
    email_blocks.innerHTML = "<span style='color:red'>Cargando bloques.....</span>";    
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {email_blocks.innerHTML=oXML.responseText; CheckRBValue(); window.location="#list"};						
	myConn.connect("email_blocks.aspx", "GET", "speciality_id=" + document.getElementById("section_list").value + "&type_id=" + document.getElementById("type_list").value + "&available=" + ((document.getElementById("available").checked)?1:0) + "&no_deleted=" + ((document.getElementById("no_deleted").checked)?1:0) + "&keyword=" + document.getElementById("keyword").value, fnWhenDone);	
}

//*** Recuperar los hijos para llenar el listado de opciones **//
function DeleteImage(image_id, table_name, table_img_field, table_key_name, table_id, file_name)
{	
	if(confirm("Está seguro ue desea borrar la imagen?"))
	{
		var myConn 	= new XHConn();    		
		var params	= 'table_name=' + table_name + '&table_img_field=' + table_img_field + '&table_key_name=' + table_key_name + '&table_id=' + table_id + '&file_name=' + file_name;		
		var content_target	= document.getElementById(image_id);		
		content_target.innerHTML = "Eliminando imagen...";					    
		if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) {content_target.innerHTML=oXML.responseText;};			
		myConn.connect("../remove_image.aspx", 'GET', params, fnWhenDone);    
		return true;
	}
	else
		return false;
}

function printDOMTree(domElement, destinationWindow)
{
  // Use destination window to print the tree.  If destinationWIndow is
  //   not specified, create a new window and print the tree into that window
  var outputWindow=destinationWindow;
  if (!outputWindow)
    outputWindow=window.open();

  // make a valid html page
  outputWindow.document.open("text/html", "replace");
  outputWindow.document.write("<HTML><HEAD><TITLE>DOM</TITLE></HEAD><BODY>\n");
  outputWindow.document.write("<CODE>\n");
  traverseDOMTree(outputWindow.document, domElement, 1);
  outputWindow.document.write("</CODE>\n");
  outputWindow.document.write("</BODY></HTML>\n");
  
  // Here we must close the document object, otherwise Mozilla browsers 
  //   might keep showing "loading in progress" state.
  outputWindow.document.close();
}

//** Traverse the dom
function traverseDOMTree(currentElement, depth, row_id)
{
  if (currentElement)
  {
    var j;
    var tagName=currentElement.id;    
    //** For each element to update call the function    
    if(tagName!=undefined && tagName.indexOf("____ajax___")!=-1)
    {			
		var tmp = tagName.split("____ajax___");
		var tmp1 = tmp[1];
		var tmp2 = tmp1.split("____");
		select_action		= tmp2[0];
		select_field_result	= tmp2[1];			
		FillField(tagName, "../ajax_fill_form.aspx", document.getElementById(tagName).innerHTML, tmp[0], select_action, select_field_result, row_id);				
    }
    
    // Traverse the tree
    var i=0;
    var currentElementChild=currentElement.childNodes[i];
    while (currentElementChild)
    {
      // Recursively traverse the tree structure of the child node
      traverseDOMTree(currentElementChild, depth+1, row_id);
      i++;
      currentElementChild=currentElement.childNodes[i];
    }      
  }  
}

/*** Llenar los campos de un formulario ***/
function FillForm(form_id, row_id)
{	
	window.location="#form_point";
	var domElement=document.getElementById(form_id);		
	traverseDOMTree(domElement, 1, row_id);	
	//** Set le flag to update
	document.forms[0].action_hidden_id.value = "update";	
	document.forms[0].client_id.value = row_id;
}

/*** Llenar los campos de un formulario ***/
function FillField(target_id, server_function, element_code, type, select_action, select_field_result, row_id)
{		
    var myConn 	= new XHConn();    
    var content_target	= document.getElementById(target_id);		    
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {content_target.innerHTML=oXML.responseText;};			
	myConn.connect(server_function, "POST", "element_code=" + element_code + "&type=" + type + "&select_action=" + select_action + "&select_field_result=" + select_field_result + "&row_id=" + row_id, fnWhenDone);   	
}

//*** Ocultar y mostrar el menu ***//
function HideMenu()
{
	document.getElementById("list_menu_left").style.display = "none";
	document.getElementById("plus").style.display = "block";
	document.getElementById("minus").style.display = "none";
}
function ExpanMenu()
{
	document.getElementById("list_menu_left").style.display = "block";
	document.getElementById("plus").style.display = "none";
	document.getElementById("minus").style.display = "block";
}

//*** Ocultar y mostrar el search ***//
function HideSearch()
{
	document.getElementById("search_content").style.display = "none";
	document.getElementById("splus").style.display = "block";
	document.getElementById("sminus").style.display = "none";
}
function ExpanSearch()
{
	document.getElementById("search_content").style.display = "block";
	document.getElementById("splus").style.display = "none";
	document.getElementById("sminus").style.display = "block";
}

//** Confirm delete action
function ConfirmDelete()
{			
	if(confirm("¿Esta seguro que desea borrar los elemento seleccionados?"))
	{
		if(document.forms[0].submit_action!=undefined)
			document.forms[0].submit_action.value = "delete";
		return true;
	}
	else
		return false;
}

//** Check the first radiobutton of block
function CheckRBValue()
{	
var checked = false;
	for(i=0; i<document.forms[0].length; i++)
	{	
		if(value_checked=='')	
		{			
			if(document.forms[0].elements[i].type == "radio" && document.forms[0].elements[i].name == "block")
			{				
				document.forms[0].elements[i].checked = true;
				document.forms[0].elements[i].style.backgroundColor = "red";
				checked = true;
				break;
			}
		}
		else
		{		
			if(document.forms[0].elements[i].type == "radio" && document.forms[0].elements[i].name == "block" && document.forms[0].elements[i].value == value_checked )
			{
				document.forms[0].elements[i].checked = true;
				document.forms[0].elements[i].style.backgroundColor = "red";
				checked = true;
				break;
			}
		}	
	}
	//** Verificar si se marco al menos 1
	if(checked == false && document.forms[0].block!=undefined)
	{
		document.forms[0].block[0].checked = true;		
	}
}

//** Check all the checkbox by a pattern
function CheckAll(pattern, group_id)
{
	for(i=0; i<document.forms[0].length; i++)
	{
		if(document.forms[0].elements[i].id.indexOf(pattern)!=-1 && document.forms[0].elements[i].type=="checkbox")		
			if(document.getElementById(group_id).checked==true)
			{
				if(document.getElementById('str_' + group_id)!=undefined)
					document.getElementById('str_' + group_id).innerHTML = "Desmarcar todos"
				document.forms[0].elements[i].checked = true;		
			}
			else
			{	
				if(document.getElementById('str_' + group_id)!=undefined)
					document.getElementById('str_' + group_id).innerHTML = "Marcar todos"
				document.forms[0].elements[i].checked = false;	
			}
			
			
	}	
}

//** Only numbers in textbox
function numbersOnly(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
}

//** Check for valid numeric strings
function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

//** Check the radio
function CheckRadio(radioObj, newValue)
{
	if(!radioObj)
		return;
	if(newValue=='')	
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}	
}

//** Submit form passing action parameter
function SubmitAction(action)
{
	document.forms[0].action = action;	
	document.forms[0].submit();	
}

//** Syncronize the courses from extern sources
function SynchronizeCourses(id, url_channel)
{		
	var myConn 	= new XHConn(); 
    var update_info = document.getElementById(id);           
    //** Actualizar cursos
    update_info.innerHTML = "<span style='color:red'><br><b>Actualizando curso de la fuente externa.....</b><br></span>";    
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {update_info.innerHTML=oXML.responseText;};						
	myConn.connect("../WS/update_courses.aspx", "GET", "url=http://www.google.com", fnWhenDone);	
}

//****************************************************************************//
//************ RUN Registro Unico de Novartis) Functions
//****************************************************************************//


//** Syncronize the courses from extern sources
function UpdateSpecialitiesList(id, type_id, webuserid)
{	
	var myConn 	= new XHConn(); 
    var spec_target = document.getElementById(id);           
    //** Actualizar cursos      	
    spec_target.innerHTML = "<span><b>Actualizando especialidades...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {spec_target.innerHTML=oXML.responseText;};						
	myConn.connect("../update_spec_list.aspx", "GET", "type_id=" + type_id + "&webuserid=" + webuserid, fnWhenDone);	
}

function SwitchRUNMenu(option)
{	
	//** Menu object
	ObjMenu1 = document.getElementById("menu1");
	OblContent1 = document.getElementById("form_room");
	ObjMenu2 = document.getElementById("menu2");
	OblContent2 = document.getElementById("service_selected");
	OblContent3 = document.getElementById("complete_box");		
	OblContent4 = document.getElementById("sendmail_box");	
	OblContent5 = document.getElementById("show_room");				
	
	switch(option)
	{
		case 2:		
			ObjMenu1.className='';
			ObjMenu2.className='menu_run_seleted';			
			
			//** Content
			if(OblContent1!=undefined)
				OblContent1.style.display = 'none';
			if(OblContent2!=undefined)	
				OblContent2.style.display = 'block';
			if(OblContent3!=undefined)			
				OblContent3.style.display = 'none';
			if(OblContent4!=undefined)
				OblContent4.style.display = 'block';
			if(OblContent5!=undefined)
				OblContent5.style.display = 'none';	
			break;
		case 3:
			ObjMenu1.className='';
			ObjMenu2.className='';			
			
			//** Content
			if(OblContent1!=undefined)
				OblContent1.style.display = 'none';
			if(OblContent2!=undefined)		
				OblContent2.style.display = 'none';			
			break;
		default:		
			ObjMenu1.className='menu_run_seleted';
			ObjMenu2.className='';						
			//** Content
			if(OblContent1!=undefined)
				OblContent1.style.display = 'block';
			if(OblContent2!=undefined)	
				OblContent2.style.display = 'none';	
			if(OblContent3!=undefined)			
				OblContent3.style.display = 'block';
			if(OblContent4!=undefined)
				OblContent4.style.display = 'none';	
			if(OblContent5!=undefined)
				OblContent5.style.display = 'block';					
			break;
	}
}

//** Create the string like '1|2|5|66' from checked boxes
function CreateCheckedStr(chkbox_name)
{
	var str_checked = '';	
	for(i=0; i<document.forms[0].elements.length; i++)
	{
		if(document.forms[0].elements[i].checkbox="radio" && document.forms[0].elements[i].name==chkbox_name && document.forms[0].elements[i].checked==true)
		{
			str_checked += document.forms[0].elements[i].value + '|';
		}
	}
	return str_checked.substr(0, str_checked.length-1);
}

//** Submit the register form 
function SubmitRegister(id)
{	
	//** Set the parameters
	email = document.forms[0].elements["Services_email"].value;
	pass = document.forms[0].elements["Services_clave"].value;
	siteid = document.forms[0].url_id.value;
	serv_str = CreateCheckedStr('services_chk');
	cour_str = CreateCheckedStr('courses_chk');	
	query_string = 'email=' + email + '&pass=' + pass + '&siteid=' + siteid + '&serv_str=' + serv_str + '&cour_str=' + cour_str;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n del registro...</b></span>";   
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	
	var fnWhenDone = function (oXML) {

		if(oXML.responseText.indexOf('SUCCESS')!=-1)
		{	
			SwitchRUNMenu(2);
		}
		else	
		{
			
			target.innerHTML=oXML.responseText;
			document.forms[0].enviar.focus();
		}
	};

	myConn.connect("../RUN/run_new_account.aspx", "POST", query_string, fnWhenDone);	
}

//** Submit the forgot password
function SubmitForgotPass(id)
{	
	//** Set the parameters
	email = document.forms[0].elements["email"].value;	
	query_string = 'email=' + email;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {		
			target.innerHTML=oXML.responseText;			
	};						
	myConn.connect("../RUN/run_send_pass.aspx", "POST", query_string, fnWhenDone);		
}


//** Submit the delete form 
function SubmitDeleteAccount(id)
{	
	//** Set the parameters
	email = document.forms[0].elements["email"].value;	
	pass  = document.forms[0].elements["clave"].value;
	query_string = 'email=' + email + '&clave=' + pass;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {		
			target.innerHTML=oXML.responseText;			
	};						
	myConn.connect("../RUN/run_complete_delete.aspx", "POST", query_string, fnWhenDone);		
}

//** Submit the cancel infomail form 
function SubmitNotInfomail(id)
{	
	//** Set the parameters
	email = document.forms[0].elements["email"].value;	
	pass  = document.forms[0].elements["clave"].value;
	query_string = 'email=' + email + '&clave=' + pass;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {		
			target.innerHTML=oXML.responseText;			
	};						
	myConn.connect("../RUN/run_complete_notinfomail.aspx", "POST", query_string, fnWhenDone);		
}

//** Submit the update of register form 
function SubmitUpdateRegister(id)
{	
	//** Set the parameters
	webuserid	= document.forms[0].elements["hid_WebUserId"].value;
	infomail = 0;
	if(document.forms[0].elements["FormRegister_infomailu_0"].checked){
		infomail=1;
	}
	//infomail = (document.forms[0].elements["FormRegister_infomailu_0"].checked)?1:0;
	type		= document.forms[0].elements["FormRegister_type_list"].value;	
	speciality	= document.forms[0].elements["speciality_list"].value;
	name		= document.forms[0].elements["FormRegister_name"].value;
	last_name	= document.forms[0].elements["FormRegister_last_name"].value;
	center		= document.forms[0].elements["FormRegister_center"].value;
	cp			= document.forms[0].elements["FormRegister_cp"].value;
	center_address	= document.forms[0].elements["FormRegister_center_address"].value;
	center_loc		= document.forms[0].elements["FormRegister_center_loc"].value;
	center_prov		= document.forms[0].elements["FormRegister_center_prov"].value;
	center_country	= document.forms[0].elements["FormRegister_center_country"].value;
	center_tel		= document.forms[0].elements["FormRegister_tel"].value;
	email			= document.forms[0].elements["Services_email"].value;		
	serv_str = CreateCheckedStr('services_chk');	
	cour_str = CreateCheckedStr('courses_chk');			
	
	query_string = 'webuserid=' + webuserid + '&infomail=' + infomail + '&type=' + type + '&speciality=' + speciality + '&name=' + name;
	query_string += '&last_name=' + last_name + '&center=' + center + '&cp=' + cp + '&center_address=' + center_address;
	query_string += '&center_loc=' + center_loc + '&center_prov=' + center_prov + '&center_country=' + center_country;
	query_string += '&center_tel=' + center_tel + '&email=' + email + '&serv_str=' + serv_str + '&cour_str=' + cour_str;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n de la actualización...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {
		if(oXML.responseText.indexOf('SUCCESS')!=-1)
		{		
			SwitchRUNMenu(2);
		}
		else	
		{
			target.innerHTML=oXML.responseText;
			document.forms[0].enviar.focus();
		}
	};						
	myConn.connect("../RUN/run_complete_update_account.aspx", "POST", query_string, fnWhenDone);		
}

//** Submit the change password form 
function SubmitChangePass(id)
{	
	//** Set the parameters
	email = document.forms[0].elements["email"].value;	
	pass  = document.forms[0].elements["clave"].value;
	new_pass  = document.forms[0].elements["new_clave"].value;
	query_string = 'email=' + email + '&clave=' + pass + '&new_clave=' + new_pass;	
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {		
			target.innerHTML=oXML.responseText;			
	};						
	myConn.connect("../RUN/run_complete_change_pass.aspx", "POST", query_string, fnWhenDone);		
}


//** Submit the saving of queries 
function SubmitSaveQuery(id_target, name, query)
{	
	//** Set the parameters	
	query_string = 'nombre=' + name + '&query=' + query;		
	
	var myConn 	= new XHConn(); 
    var target = document.getElementById(id_target);           
    //** Actualizar cursos      	
    target.innerHTML = "<span style='color:red'><img src='../UI/images/loading.gif'> <b>Enviando informaci&oacute;n...</b></span>";      
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");    
	var fnWhenDone = function (oXML) {		
			target.innerHTML=oXML.responseText;			
	};						
	myConn.connect("../MD/save_query.aspx", "POST", query_string, fnWhenDone);		
}

//**** Encoding the URL
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

//**** Decoding the URL
function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while   
   return plaintext;
}

