// CiberBromas General Script
// Made by Alberto Martinez Perez (http://www.ciberbromas.com)


// WINDOW & PARAMETERS
var WindowTop=7, WindowLeft=7, PopupWidth=780, PopupHeight=530,
    Width1024=850, Height1024=675, Width640=600, Height640=415;

var LastPopup=null;

function OpenPopup(Page,Window,Width,Height,ScrollBars,Resizable){
 var Options=new String(), Scroll=new String("no"), Resize=new String("no");

 if (ScrollBars) Scroll="yes";
 if (Resizable) Resize="yes";
 Options="width="+Width+",height="+Height+
  ",screenY="+WindowTop+",top="+WindowTop+",screenX="+WindowLeft+",left="+WindowLeft+
  ",status=no,location=no,toolbar=no,menubar=no,hotkeys=no"+
  ",resizable="+Resize+",scrollbars="+Scroll;
 LastPopup=window.open(Page,Window,Options,true);
 LastPopup.window.focus();
 return LastPopup;
}


function ExtractParameters(Str) {
 var SubStrings;
 Str=Str.substring(1,Str.length);// to eliminate the '?'
 SubStrings=Str.split("&");
 return SubStrings;
}


function CheckParameter(Index,Parameters) {
 if (Index>Parameters.length-1) return false
  else return Parameters[Index];
}


function GetPopupWidth() {
 var Width=PopupWidth;
 if (screen.width>=1024) Width=Width1024
 else if (screen.width<800) Width=Width640;
 return Width;
}


function GetPopupHeight() {
 var Height=PopupHeight;
 if (screen.width>=1024)Height=Height1024
 else if (screen.width<800) Height=Height640;
 return Height;
}




//STATUS

function ShowStatus(Text){
 window.status=Text;
 return true;
}

function RestoreStatusMoz() {
 if (window.status!=window.defaultStatus) window.status=window.defaultStatus;
}

function AssingEvents() { // Mozilla don't re-assing the default text after leaving the object that changed the status
 window.defaultStatus="CiberBromas: bromas, animaciones, imágenes, juegos, textos graciosos...";
 if (window.addEventListener)
   for(i=0;i<document.links.length;i++) document.links[i].addEventListener("mouseout",RestoreStatusMoz,false);
}




//MISC
function GetBrowser() {
 var Agent=navigator.userAgent.toUpperCase();

 if (Agent.indexOf("OPERA")!=-1) return "OPR"
 else if (Agent.indexOf("MSIE")!=-1) return "IE"
 else if (Agent.indexOf("GECKO")!=-1) return "MOZ";
}




function ReplaceChar(Str,Old,New) {
 var
  Index1=0,Index2=0,Temp=new String("");
 Index2=Str.indexOf(Old);
 while (Index2>=0) {
  Temp=Temp+Str.substring(Index1,Index2)+New;
  Index1=Index2+1;
  Index2=Str.indexOf(Old,Index2+1);
 } // of while
 Temp=Temp+Str.substring(Index1,Str.length);
 return Temp;
}


function MaskedEmail(Domain,Text,Name) {
 document.write('<a href="'+'ma'+'ilto:'+Name+'@'+Domain+'">'+Text+'</a>');
}



// ***** CIBERBROMAS SPECIFIC *****


// MISC
function CheckFrames() {
  if (window==top) top.location.href="index.html";
  else if (window==parent.MYTOPFRAME) parent.MYTOPFRAME.location.href="index.html";
}


var Background=1;

function ToggleBackground(){
 if (GetBrowser()=="IE") {  // IE
   if (Background==1) {
     with (document.styleSheets[0]) addRule("body", "background-image: none",rules.length);
     Background=0;
   }
   else {
     with (document.styleSheets[0]) removeRule(rules.length-1);
     Background=1;
   }
 } // of IE

 if (GetBrowser()=="MOZ") { //Mozilla
   if (Background==1) {
     with (document.styleSheets[0]) insertRule("body {background-image: none;}",cssRules.length);
     Background=0; //
   }
   else {
     with (document.styleSheets[0]) deleteRule(cssRules.length-1);
     Background=1;
   }
 } // of Mozilla
}




// DOWNLOAD

var
  LocationA='http://www.angelfire.com/weird/ciberbromas/Descargas.html?',
//  LocationImg='http://members.fortunecity.com/ciberbromas/Imagen.html?';
  LocationImg='Imagen.html?';


var DownloadWidth=600, DownloadHeight=400;

function Download(Loc,Name) {
 window.location.href=Loc+"/"+Name+".zip";
}

function DownloadA(Loc,Name) {
 var Popup;
 Popup=OpenPopup("Descargar.html","Donwload",DownloadWidth,DownloadHeight+60,false);
 Popup.location.href=LocationA+Loc+"&"+Name;
}




// VIEW

function ShowImage(Loc,Image) {
 var Width=GetPopupWidth(), Height=GetPopupHeight();

 if (LastPopup!=null) LastPopup.close();
 OpenPopup(LocationImg+Loc+"&"+Image,"Imagenes",Width,Height,true,true);
}



function ShowText(Loc,Text) {
 var Width=GetPopupWidth(), Height=GetPopupHeight();

 if (LastPopup!=null) LastPopup.close();
 OpenPopup(Loc+"/"+Text,"Textos",Width,Height,true,true);
}



function ShowAnim(Loc,Anim,AnimWidth,AnimHeight,BackColor) {
 var Width=GetPopupWidth(), Height=GetPopupHeight(),
     OpenString=new String();

 OpenString="PopupAnim.html?"+Loc+"&"+Anim+"&"+AnimWidth+"&"+AnimHeight;
 if (BackColor) OpenString=OpenString+"&"+BackColor;

 if (LastPopup!=null) LastPopup.close();
 OpenPopup(OpenString,"Animaciones",Width,Height,true,true);
}



// PAGE FOOT
var
 Animaciones=1,  AnimacionesEng=1,  AnimacionesHtml="Animaciones",
 Bromas=4, BromasEng=1, BromasHtml="Bromas",
 Imagenes=6,  ImagenesEng=0,  ImagenesHtml="Imagenes",
 Textos=2,  TextosEng=0,  TextosHtml="Textos",
 Juegos=2, JuegosEng=1, JuegosHtml="Juegos",
 Personajes=4, PersonajesEng=0, PersonajesHtml="Personajes",
 XiaoXiao=1,  XiaoXiaoEng=0,  XiaoXiaoHtml="XiaoXiao";
 Autoescuela=1,  AutoescuelaEng=0,  AutoescuelaHtml="Autoescuela";


function WriteFoot(Section) {
 var i;
 var Number=eval(Section), NumberEng=eval(Section+"Eng"),
     HtmlName=eval(Section+"Html");

 AssingEvents();
 document.write('<P STYLE="margin: 7px 0px; padding: 0px; font-size: 1pt;">&nbsp;<P><P CLASS="PIE">');
 document.write('Más&nbsp;en&nbsp;esta&nbsp;sección:&nbsp;&nbsp;&nbsp;')
 document.write('<A CLASS="PIE" HREF="'+HtmlName+
  '.html" ONMOUSEOVER="return ShowStatus(\''+Section+' - 1\',event)">1</A> ');// the first page is a special case (don't have a number)
 for(i=2;i<=Number;i++)
  document.write('<A CLASS="PIE" HREF="'+HtmlName+i+
  '.html" ONMOUSEOVER="return ShowStatus(\''+Section+' - '+i+'\',event)">'+i+'</A> ')

 if (NumberEng>0) {
  document.write('<A CLASS="PIE" HREF="'+HtmlName+
  'Eng.html" ONMOUSEOVER="return ShowStatus(\''+Section+' - En Ingl&eacute;s\',event)">Ingl&eacute;s</A> ');// the first page is a special case (don't have a number)
  for(i=2;i<=NumberEng;i++)
   document.write('<A CLASS="PIE" HREF="'+HtmlName+'Eng'+i+
   '.html" ONMOUSEOVER="window.staturs=\''+Section+' - En Ingl&eacute;s '+i+'\',event)">Ingl&eacute;s&nbsp;'+i+'</A> ');
 } // of if

 document.write('</P>');
}

// CiberBromas General Script
// Made by Alberto Martinez Perez (ciberbromas@yahoo.es)
