// Cookie Functions  ////////////////////  (:)

// Set the cookie.

// SetCookie('your_cookie_name', 'your_cookie_value', exp);

// Get the cookie.

// var someVariable = GetCookie('your_cookie_name');



var expDays = 100;

var exp = new Date(); 

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));



function getCookieVal (offset) {  

        var endstr = document.cookie.indexOf (";", offset);  

        if (endstr == -1) { endstr = document.cookie.length; }

        return unescape(document.cookie.substring(offset, endstr));

}



function GetCookie (name) {  

        var arg = name + "=";  

        var alen = arg.length;  

        var clen = document.cookie.length;  

        var i = 0;  

        while (i < clen) {    

                var j = i + alen;    

                if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    

                i = document.cookie.indexOf(" ", i) + 1;    

                if (i == 0) break;   

        }  

        return null;

}



function SetCookie (name, value) {  

        var argv = SetCookie.arguments;  

        var argc = SetCookie.arguments.length;  

        var expires = (argc > 2) ? argv[2] : null;  

        var path = (argc > 3) ? argv[3] : null;  

        var domain = (argc > 4) ? argv[4] : null;  

        var secure = (argc > 5) ? argv[5] : false;  

        document.cookie = name + "=" + escape (value) + 

        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 

        ((path == null) ? "" : ("; path=" + path)) +  

        ((domain == null) ? "" : ("; domain=" + domain)) +    

        ((secure == true) ? "; secure" : "");

}



// cookieForms saves form content of a page.



// use the following code to call it:

//  <body oncontextmenu="return false" ondragstart="return false" onselectstart="return false" onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">



// It works on text fields and dropdowns in IE 5+

// It only works on text fields in Netscape 4.5





function cookieForms() { 
if (document.forms[0].name == 'formulario_no_memorizable') {
// formularios no memorizables
} else {

        var mode = cookieForms.arguments[0];

        

        for(f=1; f<cookieForms.arguments.length; f++) {

                formName = cookieForms.arguments[f];

                

                if(mode == 'open') {        

                        cookieValue = GetCookie('saved_'+formName);

                        if(cookieValue != null) {

                                var cookieArray = cookieValue.split('#cf#');

                                

                                if(cookieArray.length == document[formName].elements.length) {

                                        for(i=0; i<document[formName].elements.length; i++) {

                                        

                                                if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }

                                                else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true;
                                                
                                                
                                                 }

                                                else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }

                                                else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }

                                        }

                                }

                        }

                }


                                

                if(mode == 'save') {        

                        cookieValue = '';

                        for(i=0; i<document[formName].elements.length; i++) {

                                fieldType = document[formName].elements[i].type;

                                

                                if(fieldType == 'password') { passValue = ''; }

                                else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }

                                else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }

                                else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }

                                else { passValue = document[formName].elements[i].value; }

                        

                                cookieValue = cookieValue + passValue + '#cf#';

                        }

                        cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter

                        

                        SetCookie('saved_'+formName, cookieValue, exp);                

                }        
                
                 if(mode == 'delete') {

                        cookieValue = '';

                        for(i=0; i<document[formName].elements.length; i++) {

                                fieldType = document[formName].elements[i].type;



                                if(fieldType == 'password') { passValue = ''; }

                                else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }

                                else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }

                                else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }

                                else { passValue = document[formName].elements[i].value; }



                                cookieValue = cookieValue + passValue + '#cf#';

                        }

                        cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter

                        var expDays = 100;

                        var exp = new Date();

                        exp.setTime(exp.getTime() - (expDays*24*60*60*1000));

                        SetCookie('saved_'+formName, cookieValue, exp);

                }

        }
        

        
        }

}

// css class scripts


function change(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

}


function changeBG(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

SetCookie (id, newClass)
//alert(document.cookie)
}
 
function setBG(id) {
var newClass = GetCookie (id)
if(newClass == undefined) {
newClass = "bg1"
}
changeBG(id, newClass)
}


//image scripts

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

function MM_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
  //var obj=MM_findObj(objStr);
   var obj=thisMovie(objStr);
  
  if (obj) ('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
}



// status bar

function setStatus(staText) {
if(!staText) {
staText = 'No se ha definido el status';
}
	window.defaultStatus =staText;
}


// browser scripts

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function subir(){
//window.parent.center.location="#arriba";
window.parent.scroll(0,0)
}


function blinkIt() {
var blkobj = document.getElementById("blink");
      blkobj.style.visibility=(blkobj.style.visibility=='visible')?'hidden':'visible';
 }


function deleteMessage(id,from,from2,page,extra_arg) {
if(confirm('Se eliminará el mensaje de '+from2+'. Esta seguro?')==true) {
document.location.href=from+'.php?dm='+id+'&page='+page+extra_arg;
}
}

function normalWin(theURL,winName,features) { 
  window.open(theURL,winName,features);
}
function modlessWin(theURL,args,features) { 
var myObject = new Object();
myObject.myParent = window;
modelessWindow = window.showModelessDialog(theURL,myObject,features);
}


function cambiarForo(mid,fid,desde){
url='cambiarForo.php?msg='+mid+'&fid='+fid+'&desde='+desde;

if (document.all&&window.print) { 
modlessWin(url,'','help:0;resizable:1;dialogWidth:350px;dialogHeight:400px;center:1;resizable:0;status:0;scroll:0');
} else {
normalWin(url,'CFWin','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=350,height=400');
		}
}


function hidemenuDown() {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
var movie = 'menuDown';
var movieEl = window.parent.center[movie];
  }	else {
var movieEl = parent.center.document['menuDown'];
  }
if(movieEl) {
if (movieEl.PercentLoaded() == 100) { 
var elFrame = movieEl.TCurrentFrame( "/menu/" );
if(elFrame > 0) {
movieEl.TGotoFrame("/menu", 0); 
//alert(elFrame)
			}
		}
	}
	
}
function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}


