// JavaScript Document

/* Creation date: 4.4.2003 */

	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	
	IE5plus = IE5 || IE6;
	esIE = IEmac || IE4plus || IE4 || IE5 || IE6;
	IEMajor = 0;
	
	if (IE4plus)
	{
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
 
  function Confirm(link,text) 
  {
   if (confirm(text))
      window.location=link
  }
  function expw(listID) 
  {
   if (listID.style.display=="none") {listID.style.display="";}
   else {listID.style.display="none";}
   window.event.cancelBubble=true;
  }
  function contw(listID) 
  {
   if (listID.style.display=="show") {listID.style.display="";}
   else {listID.style.display="none";}
   window.event.cancelBubble=true;
  }
  if (document.images) 
  { 
   img1on = new Image();
   img1on.src = "./gfx/but1.jpg"; 
   img1off = new Image(); 
   img1off.src = "./gfx/but2.jpg"; 
  }
  function imgOn(imgName) { if (document.images) { document[imgName].src = eval(imgName + "on.src"); } }
  function imgOff(imgName){ if (document.images) { document[imgName].src = eval(imgName + "off.src"); } }

function put_smiley(smiley,outp)
{
 if(outp == 'preview')
 {
  document.forms['novica'].preview.value += ' ' + smiley + ' ';
  document.forms['novica'].preview.focus();
 }
 if(outp == 'message')
 {
  document.forms['novica'].message.value += ' ' + smiley + ' ';
  document.forms['novica'].message.focus();
 }
}

function insert_tag(mytag,outp)
{
 if(outp == 'preview')
 {
  document.forms['novica'].preview.value += ' [' + mytag + '] ';
  document.forms['novica'].preview.focus();
 }
 if(outp == 'message')
 {
  document.forms['novica'].message.value += ' [' + mytag + '] ';
  document.forms['novica'].message.focus();
 }	
}
var winnew,ret;
winnew = 0;
winpix = 0;
ret = 0;
function PixWindow(handle)
{
 ret = handle;
 winpix=window.open("newspix.php","previewWin","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=400");
}

function PixWindow_News()
{
 
 winpix=window.open("news_pix.php","previewWin","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=650,height=400");
}

function PreviewWindow()
{
  winnew=window.open("","previewWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=400");

 winnew.document.write('<html>');
 winnew.document.write('<head>');
 winnew.document.write('<title>Previsualización</title>');
 winnew.document.write('<link rel="stylesheet" type="text/css" href="css/preview.css" />');
 winnew.document.write('<meta http-equiv="Content-Type" content="text/html; charset=<?=_CHARSET;?>" />');
 winnew.document.write('</head>');
 winnew.document.write('<body bgcolor="#999999">');
 winnew.document.write('<table width="99%" bgcolor="#000000" cellspacing="1" cellpadding="3" align="center" class="MojText"><tr><td bgcolor="#ffffff">');
 winnew.document.write('<p id="tiph" style="width:99%; text-align:justify;"></p>');
 winnew.document.write('<p id="tipp" style="width:99%; text-align:justify;"></p>');
 winnew.document.write('<p id="tipm" style="width:99%; text-align:justify;"></p>');
 winnew.document.write('</td></tr></table></body></html>')
 if (winnew.focus) {winnew.focus()}
}

function ResetPreview()
{
  tiph.innerHTML = '';
  tipp.innerHTML = '';
  tipm.innerHTML = '';
}

function checkAll(field)
{
  for(i = 0; i < field.elements.length; i++)
     field[i].checked = true ;
}

function uncheckAll(field)
{
 for(i = 0; i < field.elements.length; i++)
    field[i].checked = false ;
}


function storeCaret (textEl)
{
 if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text)
{
 if (textEl.createTextRange && textEl.caretPos)
  {
   var caretPos = textEl.caretPos;
   caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
  }
 else{
	if (esIE) textEl.value  = text;
	else
  		alert('Su navegador no soporta esta función, inserte las etiquetas manualmente.');
 }
}

function MakePreview()
{
  var previewTxt = new String();
  previewTxt = document.novica.preview.value;
  previewTxt = previewTxt.replace(/\[B\]/gi, '<b>');
  previewTxt = previewTxt.replace(/\[\/B\]/gi, '</b>');
  previewTxt = previewTxt.replace(/\[I\]/gi, '<i>');
  previewTxt = previewTxt.replace(/\[\/I\]/gi, '</i>');
  previewTxt = previewTxt.replace(/\[U\]/gi, '<u>');
  previewTxt = previewTxt.replace(/\[\/U\]/gi, '</u>');
  previewTxt = previewTxt.replace(/\n/gi, '<br/>');
  
  var messageTxt = new String(); 
  messageTxt = document.novica.message.value;
  messageTxt = messageTxt.replace(/\[B\]/gi, '<b>');
  messageTxt = messageTxt.replace(/\[\/B\]/gi, '</b>');
  messageTxt = messageTxt.replace(/\[I\]/gi, '<i>');
  messageTxt = messageTxt.replace(/\[\/I\]/gi, '</i>');
  messageTxt = messageTxt.replace(/\[U\]/gi, '<u>');
  messageTxt = messageTxt.replace(/\[\/U\]/gi, '</u >');
  messageTxt = messageTxt.replace(/\n/gi, '<br/>');
}
 
function MakePreview2()
{
  var messageTxt = new String(); 
  messageTxt = document.novica.message.value;
  messageTxt = messageTxt.replace(/\[B\]/gi, '<b>');
  messageTxt = messageTxt.replace(/\[\/B\]/gi, '</b>');
  messageTxt = messageTxt.replace(/\[I\]/gi, '<i>');
  messageTxt = messageTxt.replace(/\[\/I\]/gi, '</i>');
  messageTxt = messageTxt.replace(/\[U\]/gi, '<u>');
  messageTxt = messageTxt.replace(/\[\/U\]/gi, '</u >');
  messageTxt = messageTxt.replace(/\n/gi, '<br/>');

  document.formnews.headline.value = '<font size="4" face="arial"><b>' + document.novica.headline.value  + '</b></font><br/><br/>';
  //winnew.tip.innerHTML += '<br/><br/>';
  document.formnews.message.value = messageTxt;
}

function checkemail(str){
	var regEmail = new RegExp("^([0-9a-zA-Z]([-.w_]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-w]*[0-9a-zA-Z])*.)+[a-zA-Z]{2,9})$");
	if (regEmail.test(str)) {return true;} else {return false;}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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 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_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_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];}
}

// Variables de color para el menú
var menuColor1 = "#28592c";
var menuColor1over = "#889E5A";
var menuColor2 = "#FAF8CC";
var menuColor2over = "#ddd97d";

function cambiaColorMenu(src)
{
	if (src.bgColor.toLowerCase()==menuColor1.toLowerCase()) {src.bgColor=menuColor1over;}
	else if (src.bgColor.toLowerCase()==menuColor1over.toLowerCase()) {src.bgColor=menuColor1;}
	else if (src.bgColor.toLowerCase()==menuColor2.toLowerCase()) {src.bgColor=menuColor2over;}
	else if (src.bgColor.toLowerCase()==menuColor2over.toLowerCase()) {src.bgColor=menuColor2;}
}

function openPictureWindow_Fever(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	if (imageType == "swf"){
	newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');
	newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');
	newWindow.document.write('</embed></object>');	}else{
	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function openPictureWindow_Fever_Mod(imageType,imageName,imageWidth,imageHeight,alt,desc,posLeft,posTop) {  // v4.01

	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 align="center">');
	newWindow.document.write('<TR><TD BGCOLOR="#899D5E" align="center"><FONT COLOR=white FACE=Arial SIZE=2><b>'+alt+'</b></FONT></TD></TR>');
	newWindow.document.write('<TR><TD align="center" bgcolor="#FFFFFF">');
	if (imageType == "swf"){
	newWindow.document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+imageWidth+'" height="'+imageHeight+'">');
	newWindow.document.write('<param name=movie value="'+imageName+'"><param name=quality value=high>');
	newWindow.document.write('<embed src="'+imageName+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+imageWidth+'" height="'+imageHeight+'">');
	newWindow.document.write('</embed></object>');	}else{
	newWindow.document.write('<img src="'+imageName+'" alt="'+alt+'">'); 	}
	newWindow.document.write('</TD></TR>');
	newWindow.document.write('<TR><TD BGCOLOR="#DBE1B0" align="center">');
	newWindow.document.write('<FONT COLOR=black FACE=Arial SIZE=2>'+desc+'</FONT>');
	newWindow.document.write('</TD></TR></TABLE>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();

}

var keyStr = "ABCDEFGHIJKLMNOP" +
            "QRSTUVWXYZabcdef" +
            "ghijklmnopqrstuv" +
            "wxyz0123456789+/" +
            "=";

function encode64(input) {
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  do {
     chr1 = input.charCodeAt(i++);
     chr2 = input.charCodeAt(i++);
     chr3 = input.charCodeAt(i++);

     enc1 = chr1 >> 2;
     enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
     enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
     enc4 = chr3 & 63;

     if (isNaN(chr2)) {
        enc3 = enc4 = 64;
     } else if (isNaN(chr3)) {
        enc4 = 64;
     }

     output = output + 
        keyStr.charAt(enc1) + 
        keyStr.charAt(enc2) + 
        keyStr.charAt(enc3) + 
        keyStr.charAt(enc4);
     chr1 = chr2 = chr3 = "";
     enc1 = enc2 = enc3 = enc4 = "";
  } while (i < input.length);

  return output;
}

function decode64(input) {
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  var base64test = /[^A-Za-z0-9\+\/\=]/g;
  if (base64test.exec(input)) {
     return(false);
  }
  input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

  do {
     enc1 = keyStr.indexOf(input.charAt(i++));
     enc2 = keyStr.indexOf(input.charAt(i++));
     enc3 = keyStr.indexOf(input.charAt(i++));
     enc4 = keyStr.indexOf(input.charAt(i++));

     chr1 = (enc1 << 2) | (enc2 >> 4);
     chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
     chr3 = ((enc3 & 3) << 6) | enc4;

     output = output + String.fromCharCode(chr1);

     if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
     }
     if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
     }

     chr1 = chr2 = chr3 = "";
     enc1 = enc2 = enc3 = enc4 = "";

  } while (i < input.length);

  return output;
}

function array_search( searchS, arraySA ) {
 var I = 0;
 var minI = 0;
 var maxI = arraySA.length - 1;
 //
 var s = "";
 //
 var foundB = false;
 //
 I = minI - 1;
 while ( ( I <= maxI ) && ( !( foundB ) ) ) {
  I = I + 1;
  s = arraySA[ I ];
  foundB = ( searchS == s );
  }
 if ( foundB ) {
  return( I );
 }
 else {
  return( -1000 ); // some negative number indicating not found
 }
}
