/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}


function callServer(formtopost) {
  // Build the URL to connect to
  document.getElementById("statusbar").style.display="inline";
  var params = "";
  
  params = getparams(formtopost);
  
  //alert(params);
  
  var url = "notisave.php";

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updatePage;

  // Send the request
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send(params);
  
  // should we perform the restore form? 
  
  if(params.indexOf("&expired=Y") != -1){
   return false;
  } else {
  return true;
  }
  
}



function updatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
   
   //document.getElementById("statusbar").innerHTML = "Informacion guardada 
   
  document.getElementById("statusbar").innerHTML = response;
  document.getElementById("statusbar").style.backgroundColor = "lime";
  
  if(response.indexOf("como expirada.") != -1){
  window.location.reload();
  }
  
  }
}





function callServerExp(formtopost) {
  // Build the URL to connect to
  document.getElementById("Expstatusbar").style.display="inline";
  var params = "";
  
  Expparams = Expgetparams(formtopost);
  
  var url = "notisave.php";

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = ExpupdatePage;

  // Send the request
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send(Expparams);
  
  if(Expparams.indexOf("&expired=N") != -1){
   return false;
  } else {
  return true;
  }
  
  
}



function ExpupdatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
   
   //document.getElementById("statusbar").innerHTML = "Informacion guardada 
   
  document.getElementById("Expstatusbar").innerHTML = response;
  document.getElementById("Expstatusbar").style.backgroundColor = "lime";
  
  if(response.indexOf("no expirada.") != -1){
  window.location.reload();
  }
  
  }
}



function NewcallServer(formtopost) {
  // Build the URL to connect t
 // document.getElementById("statusbar").style.display="inline";
  
  var params = "expired=N&areapub=no&action=updtnew";
 
  var url = "notisave.php";

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = NewupdatePage;

  // Send the request
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send(params);
  
}



function NewupdatePage() {
  if (xmlHttp.readyState == 4) {
   
  window.location.reload();
  
  }
}

function DelcallServer(recID) {
  // Build the URL to connect to
  
  var params = "id="+recID+"&action=updtdel";
 
  var url = "notisave.php";

  // Open a connection to the server
  xmlHttp.open("POST", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = DelupdatePage;

  // Send the request
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.send(params);
  
}



function DelupdatePage() {
  if (xmlHttp.readyState == 4) {
   
  window.location.reload();
  
  }
}

function deleteRecord(recID){

var mychoice = confirm("Estas seguro de eliminar esta nota? no hay forma de recuperarla.");

if(mychoice){
DelcallServer(recID);
}

}

function makevisible(){

document.getElementById("dateontop").style.display="block";
document.getElementById("copynotice").style.display="block";
document.getElementById("subcontainer").style.display="block";
if(pagename != "acerca" && pagename != "informacion"){
document.getElementById("medicoguardia").style.display="block";
}
}

function hide(which){
if(which == 1){
document.getElementById("locationnava").style.display="none";
document.getElementById("locationnavc").style.display="none";
} else if (which == 2){
document.getElementById("locationnava").style.display="block";
document.getElementById("locationnavc").style.display="none";
} else if (which == 3){
document.getElementById("locationnava").style.display="none";
document.getElementById("locationnavc").style.display="block";
}

}
	
function alertuser(){
alert('Muy pronto esta seccion sera habilitada. Gracias.');
	
}

function currclose(currtoclose){
document.getElementById(currtoclose).style.display="none";
}

function showcurr(currtoclose){
document.getElementById(currtoclose).style.display="block";
}



function makeEditable(formtochange){
dstart = "dstart"+formtochange;
dend = "dend"+formtochange;
expired = "expired"+formtochange;
titular = "titular"+formtochange;
noticia = "noticia"+formtochange;
editbtn = "editbtn"+formtochange;
areapub = "areapub"+formtochange;
highlight = "highlight"+formtochange;


// transform fields
dstartObj = document.getElementById(dstart);
dstartVal = dstartObj.innerHTML;
dstartObj.innerHTML = "<input type='text' size='10' name='dstart' value='"+dstartVal+"' class='textEditor'>";

dendObj = document.getElementById(dend);
dendVal = dendObj.innerHTML;
dendObj.innerHTML = "<input type='text' size='10' name='dend' value='"+dendVal+"' class='textEditor'>";

expiredObj = document.getElementById(expired);
expiredVal = expiredObj.innerHTML;

checkedVal1="";
checkedVal2="";

if(expiredVal == "N"){
checkedVal1 = "checked";
}else{
checkedVal2 = "checked";
}
expiredObj.innerHTML = "<input type='radio' name='expired' value='N' "+checkedVal1+">N "+"<input type='radio' name='expired' value='Y' "+checkedVal2+">Y";

areapubObj = document.getElementById(areapub);
areapubVal = areapubObj.innerHTML;

areapubVal1="";
areapubVal2="";
areapubVal3="";

if(areapubVal == "udp"){
areapubVal1 = "checked";
}else if (areapubVal == "med"){
areapubVal2 = "checked";
}else if (areapubVal == "no"){
areapubVal3 = "checked";
}
areapubObj.innerHTML = "<input type='radio' name='areapub' value='udp' "+areapubVal1+">udp "+"<input type='radio' name='areapub' value='med' "+areapubVal2+">med"+" <input type='radio' name='areapub' value='no' "+areapubVal3+">no";


highlightObj = document.getElementById(highlight);
highlightVal = highlightObj.innerHTML;

highlightVal1="";
highlightVal2="";

if(highlightVal == "N"){
highlightVal1 = "checked";
}else{
highlightVal2 = "checked";
}
highlightObj.innerHTML = "<input type='radio' name='highlight' value='N' "+highlightVal1+">N "+"<input type='radio' name='highlight' value='Y' "+highlightVal2+">Y";


titularObj = document.getElementById(titular);
titularVal = titularObj.innerHTML;
titularObj.innerHTML = "<textarea name='titular' cols='62' rows='2' class='textEditor'>"+titularVal+"</textarea>";

noticiaObj = document.getElementById(noticia);
noticiaVal = noticiaObj.innerHTML;
noticiaObj.innerHTML = "<textarea name='noticia' cols='70' rows='6' class='textEditor'>"+noticiaVal+"</textarea>";

editbtnObj = document.getElementById(editbtn);
editbtnVal = editbtnObj.innerHTML;
editbtnObj.innerHTML = "<a href='#' onclick='savechanges("+formtochange+"); return false;'>Guardar</a>";

}

function savechanges(formtosave){
//alert(formtosave);
mychange = callServer(formtosave);
if(mychange){
restoreForm(formtosave);
}

}

function saveExpchanges(formtosave){

mychange = callServerExp(formtosave);
if(mychange){
restoreExpForm(formtosave);
}
}

function restoreForm(formtochange){

form = formtochange;
//alert(form);
dstart = "dstart"+formtochange;
dend = "dend"+formtochange;
expired = "expired"+formtochange;
titular = "titular"+formtochange;
noticia = "noticia"+formtochange;
editbtn = "editbtn"+formtochange;
areapub = "areapub"+formtochange;
highlight = "highlight"+formtochange;

// transform fields
dstartObj = document.getElementById(dstart);
dstartVal = document.forms[form].dstart.value;
dstartObj.innerHTML = dstartVal;

dendObj = document.getElementById(dend);
dendVal = document.forms[form].dend.value;
dendObj.innerHTML = dendVal;

expiredObj = document.getElementById(expired);

if(document.forms[form].expired[0].checked == true){
expiredVal = document.forms[form].expired[0].value;
}else if (document.forms[form].expired[1].checked == true){
expiredVal = document.forms[form].expired[1].value;
}
expiredObj.innerHTML = expiredVal;


highlightObj = document.getElementById(highlight);

if(document.forms[form].highlight[0].checked == true){
highlightVal = document.forms[form].highlight[0].value;
}else if (document.forms[form].highlight[1].checked == true){
highlightVal = document.forms[form].highlight[1].value;
}
highlightObj.innerHTML = highlightVal;

areapubObj = document.getElementById(areapub);

if(document.forms[form].areapub[0].checked == true){
areapubVal = document.forms[form].areapub[0].value;
}else if (document.forms[form].areapub[1].checked == true){
areapubVal = document.forms[form].areapub[1].value;
}else if (document.forms[form].areapub[2].checked == true){
areapubVal = document.forms[form].areapub[2].value;
}
areapubObj.innerHTML = areapubVal;


titularObj = document.getElementById(titular);
titularVal = document.forms[form].titular.value;
titularObj.innerHTML = titularVal;

noticiaObj = document.getElementById(noticia);
noticiaVal = document.forms[form].noticia.value;
noticiaObj.innerHTML = noticiaVal;

editbtnObj = document.getElementById(editbtn);
editbtnObj.innerHTML = "<a href='#' onclick='makeEditable(\""+formtochange+"\"); return false;'>Editar</a>";

}




function restoreExpForm(formtochange){

form = formtochange;
formVals = eval('document.forms["Expnota'+formtochange+'"]');
//alert(form);
expired = "Expexpired"+formtochange;
titular = "Exptitular"+formtochange;
editbtn = "Expeditbtn"+formtochange;
areapub = "Expareapub"+formtochange;

expiredObj = document.getElementById(expired);

if(formVals.expired[0].checked == true){
expiredVal = formVals.expired[0].value;
}else if (formVals.expired[1].checked == true){
expiredVal = formVals.expired[1].value;
}
expiredObj.innerHTML = expiredVal;


areapubObj = document.getElementById(areapub);

if(formVals.areapub[0].checked == true){
areapubVal = formVals.areapub[0].value;
}else if (formVals.areapub[1].checked == true){
areapubVal = formVals.areapub[1].value;
}else if (formVals.areapub[2].checked == true){
areapubVal = formVals.areapub[2].value;
}
areapubObj.innerHTML = areapubVal;


titularObj = document.getElementById(titular);
titularVal = formVals.titular.value;
titularObj.innerHTML = titularVal;

editbtnObj = document.getElementById(editbtn);
editbtnObj.innerHTML = "<a href='#' onclick='makeExpEditable(\""+formtochange+"\"); return false;'>Editar</a>";

}






function getparams(formtochange){

form = formtochange;

dstart = "dstart"+formtochange;
dend = "dend"+formtochange;
expired = "expired"+formtochange;
titular = "titular"+formtochange;
noticia = "noticia"+formtochange;
editbtn = "editbtn"+formtochange;
areapub = "areapub"+formtochange;
highlight = "highlight"+formtochange;

// get values fields

idVal = document.forms[form].idr.value;
//alert(idVal);
dstartValTmp = document.forms[form].dstart.value;
dstartValArr = dstartValTmp.split("/");
dstartVal = dstartValArr[2]+"-"+dstartValArr[1]+"-"+dstartValArr[0];

dendValTmp = document.forms[form].dend.value;
dendValArr = dendValTmp.split("/");
dendVal = dendValArr[2]+"-"+dendValArr[1]+"-"+dendValArr[0];


if(document.forms[form].expired[0].checked == true){
expiredVal = document.forms[form].expired[0].value;
}else if (document.forms[form].expired[1].checked == true){
expiredVal = document.forms[form].expired[1].value;
}

if(document.forms[form].areapub[0].checked == true){
areapubVal = document.forms[form].areapub[0].value;
}else if (document.forms[form].areapub[1].checked == true){
areapubVal = document.forms[form].areapub[1].value;
}else if (document.forms[form].areapub[2].checked == true){
areapubVal = document.forms[form].areapub[2].value;
}

if(document.forms[form].highlight[0].checked == true){
highlightVal = document.forms[form].highlight[0].value;
}else if (document.forms[form].highlight[1].checked == true){
highlightVal = document.forms[form].highlight[1].value;
}


titularVal = document.forms[form].titular.value;
noticiaVal = document.forms[form].noticia.value;

parameters = "id="+idVal+"&dstart="+dstartVal+"&dend="+dendVal+"&expired="+expiredVal+"&areapub="+areapubVal+"&highlight="+highlightVal+"&titular="+escape(titularVal)+"&noticia="+escape(noticiaVal)+"&action=updt";

return parameters;
}


function Expgetparams(formtochange){

form = eval('document.forms["Expnota'+formtochange+'"]');
//alert(form)

expired = "Expexpired"+formtochange;
titular = "Exptitular"+formtochange;
editbtn = "Expeditbtn"+formtochange;
areapub = "Expareapub"+formtochange;

// get values fields

idVal = form.idr.value;
//alert(idVal);


if(form.expired[0].checked == true){
expiredVal = form.expired[0].value;
}else if (form.expired[1].checked == true){
expiredVal = form.expired[1].value;
}

if(form.areapub[0].checked == true){
areapubVal = form.areapub[0].value;
}else if (form.areapub[1].checked == true){
areapubVal = form.areapub[1].value;
}else if (form.areapub[2].checked == true){
areapubVal = form.areapub[2].value;
}

titularVal = form.titular.value;

parameters = "id="+idVal+"&expired="+expiredVal+"&areapub="+areapubVal+"&titular="+escape(titularVal)+"&action=updtExp";

return parameters;

}


function makeExpEditable(formtochange){
expired = "Expexpired"+formtochange;
titular = "Exptitular"+formtochange;
editbtn = "Expeditbtn"+formtochange;
areapub = "Expareapub"+formtochange;

// transform fields
expiredObj = document.getElementById(expired);
expiredVal = expiredObj.innerHTML;

checkedVal1="";
checkedVal2="";

if(expiredVal == "N"){
checkedVal1 = "checked";
}else{
checkedVal2 = "checked";
}
expiredObj.innerHTML = "<input type='radio' name='expired' value='N' "+checkedVal1+">N "+"<input type='radio' name='expired' value='Y' "+checkedVal2+">Y";


areapubObj = document.getElementById(areapub);
areapubVal = areapubObj.innerHTML;

areapubVal1="";
areapubVal2="";
areapubVal3="";

if(areapubVal == "udp"){
areapubVal1 = "checked";
}else if (areapubVal == "med"){
areapubVal2 = "checked";
}else if (areapubVal == "no"){
areapubVal3 = "checked";
}
areapubObj.innerHTML = "<input type='radio' name='areapub' value='udp' "+areapubVal1+">udp "+"<input type='radio' name='areapub' value='med' "+areapubVal2+">med"+" <input type='radio' name='areapub' value='no' "+areapubVal3+">no";


titularObj = document.getElementById(titular);
titularVal = titularObj.innerHTML;
titularObj.innerHTML = "<textarea name='titular' cols='62' rows='2' class='textEditor'>"+titularVal+"</textarea>";


editbtnObj = document.getElementById(editbtn);
editbtnVal = editbtnObj.innerHTML;
editbtnObj.innerHTML = "<a href='#' onclick='saveExpchanges("+formtochange+"); return false;'>Guardar</a>";

}

prevtoggle = 100;
mynum = "";
function togglenote(note){
// turn on the first note
if(note != 100){

note = note+"";
//console.log(note);
if(note.indexOf('b')!= -1){

mytmparray = note.split('b');
mynum = mytmparray[0];

document.getElementById("noteb"+mynum).style.display = "block";
document.getElementById("moreb"+mynum).innerHTML = "<img src=\"images/less.gif\" alt=\"-\" width=\"9\" height=\"9\" border=\"0\"/>";
note = mynum;
}else{
document.getElementById("note"+note).style.display = "block";
document.getElementById("more"+note).innerHTML = "<img src=\"images/less.gif\" alt=\"-\" width=\"9\" height=\"9\" border=\"0\"/>";
mynum = "";
}
}
if(prevtoggle == note){
prevtoggle = 100
initNewsHeaders(100)
} else {
prevtoggle = note
initNewsHeaders(note)
}
}

function initNewsHeaders(ignorenote){

if(mynum == ""){
for(x=0;x<=numofnotes;x++){
if(x!=ignorenote){

document.getElementById("note"+x).style.display = "none";
document.getElementById("more"+x).innerHTML = "<img src=\"images/more.gif\" alt=\"+\" width=\"9\" height=\"9\" border=\"0\"/>";
}
}
}else{
for(x=0;x<=numofnotesb;x++){
if(x!=ignorenote){
document.getElementById("noteb"+x).style.display = "none";
document.getElementById("moreb"+x).innerHTML = "<img src=\"images/more.gif\" alt=\"+\" width=\"9\" height=\"9\" border=\"0\"/>";
}
}
}
}

function setovercolor(obj){
document.getElementById("title"+obj).style.backgroundColor = "#b9e4e6";
}

function removecolor(obj){
document.getElementById("title"+obj).style.backgroundColor = "";
}

function setovercolorb(obj){
document.getElementById("titleb"+obj).style.backgroundColor = "#b9e4e6";
}

function removecolorb(obj){
document.getElementById("titleb"+obj).style.backgroundColor = "";
}



// CSS platform Specific switch for Win or Mac
function macorpcCSS(){ 
if (navigator.appVersion.toLowerCase().indexOf("win")!=-1) {
return true;
} else {
return false;
}


}























