/* Javascript code for IMTUSA (via TADICE S.L.  */
/* Written by Paula Molinero, based on          */
/* sevaral code samples and other               */
/* online resources.                            */
/* ____________________________________________ */

var siteName  = 'IMTUSA';
var webPath   = '/home/clients/projects/imtusa/html/';
var separator = ' / ';


//--- Base functions --------------------------------------------------------------------------- //
function trimString (string) 
{
    var tstring = "";
    var splitstring = "";
    
    string = '' + string;
    splitstring = string.split(" ");
    for(i = 0; i < splitstring.length; i++)
    tstring += splitstring[i];
    return tstring;
}

//--- Execute script
//--- example: onChange="execScript('procRanking.php?FieldID=1&Ranking='+this.value);"
function execScript(myPage) 
{
    ActionPageImage = new Image();
    ActionPageImage.src = myPage;
}

function topOfThePage () { window.scrollTo(0,0) }

// Escape strings
function Escape (text) 
{
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  
  return text.replace(arguments.callee.sRE, '\\$1');
}

// print innerHTML content
function printInnerText (ID,Str)
{
    document.getElementById(ID).innerHTML = Str;
}

// Redirection
function redir (thisURL)
{
    if (thisURL) { location.href = thisURL; }
}

// Switch CSS classes
function switchClass(id, newClass) 
{
    if (myElement=document.getElementById(id)) { myElement.className = newClass; }
}

//--- Visibility functions --------------------------------------------------------------------- //
function vis1(objID,vis)
{
    if (!vis) { vis = 'block'; } 
    
    if(myElement = document.getElementById(objID))
    {
        if(myElement.style.display == vis) { myElement.style.display = 'none'; }
        else { myElement.style.display = vis; }
    }
}

function vis2(objID,total)
{
    if(objID > 0)
    {
        for(i = 1; i <= total; i++)
        {
            var id = 'sub' + i;
            myElement = document.getElementById(id);
            
            if(i == objID) { myElement.style.display = 'block'; }
            else { myElement.style.display = 'none'; }
        }
    }
}

function vis3(ID,imgPathOn,imgPathOff)
{
    for (i=1;i<=6;i++)
    {
        var blockID = 'block'+i;
        var imgID   = 'img'+i;

        if (ID == i)
        {
            if (myElement = document.getElementById(blockID))
            {
                if (myElement.style.display == 'block')
                {
                    myElement.style.display = 'none';
                    if (myImg = document.getElementById (imgID)) { myImg.src = imgPathOn; }
                }
                else
                {
                    myElement.style.display = 'block';
                    if (myImg = document.getElementById (imgID)) { myImg.src = imgPathOff; }
                }
            }
        }
        else
        {        
            if (myElement = document.getElementById(blockID))
            {
                myElement.style.display = 'none';
                if (myImg = document.getElementById (imgID)) { myImg.src = imgPathOn; }
            }
        }

    }
}

function displayLargePic (pic,num,code)
{
    if (myPic = document.getElementById ('largepic')) { myPic.src = 'img_REPOSITORY/'+pic; }
    
    var picNote = new Array (3);
    
    picNote['cuntis']         = 'Cubierta circular Balneario de Cuntis (6 fotos)';
    picNote['palexco']        = 'Palacio de congresos Palexco - Pto. de La Coru&ntilde;a (6 fotos)';
    picNote['pontevea']       = 'Impermeabilizaci&oacute;n de piscina en Casa Rural Pontevea (3 fotos)';
    picNote['plazadelparque'] = 'Cubierta inclinada Plaza del Parque, La Coru&ntilde;a (3 fotos)';
    picNote['emalcsa']        = 'Cubierta Emalcsa, La Grela (5 fotos)';
    picNote['perillo']        = 'Cubierta en Perillo';
    
    printInnerText ('picNum',num);
    printInnerText ('picNote', picNote[code]);
}

//--- Confirmation boxes ----------------------------------------------------------------------- //
function confirmBox1 (msg,fwd)
{
    var where_to = confirm(msg);
    if (where_to == true) { window.location = fwd; }
}
function confirmBox2 (msg,fwd,rwd) 
{
    var where_to = confirm(msg);
    if (where_to == true) { window.location = fwd; }
    else { window.location = rwd; }
}
function confirmBox3 (msg) 
{
    var where_to = confirm(msg);
    if (where_to == false) { history.go(-1); }
    else { return true; }
}


//--- cookie functions by quirksmode.org -------------------------------------------------------- //
function createCookie(name,value,mins)
{
    if (mins) 
    {
        var date = new Date();
        date.setTime(date.getTime()+(mins*60));
        var expires = "; expires="+date.toGMTString();
    }
    else { var expires = ""; }
    document.cookie = name+"="+value+expires+"; path="+webPath;
}
  
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;
}
  
function eraseCookie(name) { createCookie(name,"",-1); }
