/********************************
 * sim_navMenus.js
 * AbrAhAm HerrerA, March 16 2007
 *
 ********************************/


// function to expand and contract an html code block
// divExpCollp = name of div to display/hide
// divChange = name of div to change text
// divDefault = default text (when page is loaded)
// divOnClick = text to be displayed once the link is clicked on
// estado = if this is set to 'true' will force the 'divExpCollp' div to display
// created by AbrAhAm HerrerA (March 16, 2004)
function expand(divExpCollp,divChange,divDefault,divOnClick,estado) {
  if (document.layers) //netscape 4 or 5
  {
    if (estado) { 
	document.layers[divExpCollp].display = 'block'; 
	document.layers[divChange].document.open();
	document.layers[divChange].document.write(divOnClick);
	document.layers[divChange].document.close(); 
	return; 
    }
	current = (document.layers[divExpCollp].display == 'none') ? 'block' : 'none';
	changeDiv = (document.layers[divExpCollp].display == 'none') ? divOnClick : divDefault;
	document.layers[divExpCollp].display = current;
	document.layers[divChange].document.open();
	document.layers[divChange].document.write(current);
	document.layers[divChange].document.close(); 
	return;
    }
    else if (document.all) //internet explorer
    {
	if (estado) { document.all[divExpCollp].style.display = 'block'; eval (divChange + '.innerHTML = divOnClick'); return; }
	current = (document.all[divExpCollp].style.display == 'none') ? 'block' : 'none';
	changeDiv = (document.all[divExpCollp].style.display == 'none') ? divOnClick : divDefault;
	document.all[divExpCollp].style.display = current;
	//if (divChange) { eval (divChange + '.innerHTML = changeDiv'); }
      if (divChange) { document.all[divChange].innerHTML = changeDiv; }
    }
    else if (document.getElementById) //netscape 6 or firefox or mozilla
    {
	if (estado) { document.getElementById(divExpCollp).style.display = 'block'; eval (divChange + '.innerHTML = divOnClick'); return; }
	current = (document.getElementById(divExpCollp).style.display == 'none') ? 'block' : 'none';
	changeDiv = (document.getElementById(divExpCollp).style.display == 'none') ? divOnClick : divDefault;
	document.getElementById(divExpCollp).style.display = current;
	//if (divChange) { eval (divChange + '.innerHTML = changeDiv'); }
      if(divChange) {
          divChangeRef = document.getElementById(divChange);
          divChangeRef.innerHTML = changeDiv;
      }
    }
}

// function to display a toggled div
// pass div ID and image id through url location
// also accepts bookmarks
// AbrAhAm HerrerA 09-09
function displSelectedDiv(){
  var thisURL = self.location.href;
  var thisTemp = thisURL.split("?");
  var thisDiv = thisTemp[thisTemp.length-2];
  var lastStr = thisTemp[thisTemp.length-1].split("#");
  var thisImg = lastStr[0];
  if (thisURL.indexOf("?") > 0) {
    if (thisTemp[1].charAt(0) != '2') {
      expand(thisDiv,thisImg,'<img src=\'/all_images/toggle.gif\'>','<img src=\'/all_images/toggle_backRed.gif\'>');
    }
  }
}


// JavaScript function to display emails
// and prevent spam
// by AbrAhAm HerrerA 
function displayEmail(name,domain,clase,link,subject) {
 
  thisEmail = (name + "@" + domain);
  classStr = (clase) ? " class=\"" + clase + "\"" : '';
  linkStr = (link) ? link : thisEmail;
  if (subject) { thisEmail += "?subject=" + subject; }
  document.write("<a href=\"mailto:" + thisEmail + "\"" + classStr + ">" + linkStr + "</a>");
} 

//opens a new window
function Start(page,wdth,hght) {

var NS = (navigator.appName=="Netscape")?true:false;

if (!wdth) { wdth=450; }
if (!hght) { hght=300; }

var argms = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width="+wdth+",height="+hght+",alwaysRaised=no,dependant=no,screenX=100,screenY=120";

OpenWin = this.open(page,"popup",argms);
OpenWin.focus();

}

//opens a second new window 
function Start2(page) {

OpenWin = this.open(page, "popup", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=400,height=100,alwaysRaised=no,dependant=no,screenX=100,screenY=120");
OpenWin.focus();

}

//shows  different banners on homepage
// img : image should be under the /all_images/homepage_images/case_studies/ directory
// lnk : link or URL of site
// tgt : target of link (by default target should be in the same window)
// by AbrAhAm HerrerA
var alertTimerId = 0;
function dispBanner(img,lnk,tgt) {
  tgtStr = (tgt) ? " target=\"" + tgt + "\"" : '';
  var bannerSpan = "banner";
  var thisIMG = "/all_images/homepage_images/case_studies/" + img;
  var image1 = "<SPAN ID=mainBanner name=mainBanner style=\"width: 512px; height: 140px;\"><a href='" + lnk + "' " + tgtStr + "><img src='" + thisIMG + "' style=\"width: 512px; height: 140px; border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; -khtml-opacity: 0; opacity: 0;\" id=\"blendimage\"></a></SPAN>"; //background-image: url(" + thisIMG + "); background-repeat: no-repeat; 
  if (document.layers) //netscape 4 or 5
  {
    document.layers["banner"].document.open();
    document.layers["banner"].document.write(image1);
    document.layers["banner"].document.close(); 
  }
  else if (document.all) // internet explorer
  {
    eval (bannerSpan + '.innerHTML = image1');
    opacity('blendimage', 0, 100, 500);
  }
  else if (document.getElementById) //netscape 6 or firefox or mozilla
  {
    eval (bannerSpan + '.innerHTML = image1');
    document.getElementById('mainBanner').style.visibility='visible'
    blendimage('mainBanner','blendimage',thisIMG,300)
  }
  clearTimeout ( alertTimerId );
  //alert(alertTimerId );
}

// Displays new banners on homepage
// img : image should be under the /all_images/homepage_new_images/ directory
// lnk : link or URL of site
// tgt : target of link (by default target should be in the same window)
// by AbrAhAm HerrerA
function dispNewBanner(img,lnk,tgt) {
  var tgtStr = (tgt) ? " target=\"" + tgt + "\"" : '';
  var thisIMG = "/all_images/homepage_new_images/" + img + ".jpg";
  //var newIMG = "<a href='" + lnk + "' " + tgtStr + "><img src='" + thisIMG + "' style=\"width: 486px; height: 175px; border: 0; filter: alpha(opacity=0); -moz-opacity: 0; -khtml-opacity: 0; opacity: 0;\" id=\"blendimage\" /></a>"; 
  var newIMG = "<a href='" + lnk + "' " + tgtStr + "><span id=mainBanner name=mainBanner><img src='" + thisIMG + "' style=\"width: 486px; height: 175px; border: 0; opacity: 1; -webkit-transition: opacity 1s linear;\" id=\"blendimage\" /></span></a>"; 
  document.getElementById('banner').innerHTML = newIMG;
  if (document.all) opacity('blendimage', 0, 100, 500); else blendimage('mainBanner','blendimage',thisIMG,300);
}

//resets banner to its original
function resetBanner(img,lnk) {
  alertTimerId = setTimeout('alert(alertTimerId);dispBanner(img,lnk);', 1000);
  alert(alertTimerId+"=");
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//alert(imagefile);
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


function isObjectt(obj) {
  //returns true is it is an array
  if (obj.constructor.toString().indexOf("simuliaMenu") == -1)
    return false;
  else
    return true;
}

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Philip Myers :: http://virtualipod.tripod.com/bookmark.html */

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

// function to display new Nav menus -- not in use
function displayNavMenus() {

   var frag = document.createDocumentFragment();
   var span = document.createElement('span');
   var table = document.createElement('table');
   table.setAttribute("width", "740");
   table.setAttribute("height", "175");
   table.setAttribute("border", "0");
   table.setAttribute("cellpadding", "0");
   table.setAttribute("cellspacing", "0");
   var tbody = document.createElement("tbody");
   table.appendChild(tbody);
   frag.appendChild(table);

   // first row
   var tr1 = document.createElement('tr');
   // first row : first column
   var td11 = document.createElement('td');
   td11.setAttribute("width","486");
   td11.setAttribute("rowspan","7");
   var mainSpan = document.createElement('span');
   mainSpan.setAttribute("id","banner");
   mainSpan.setAttribute("name","banner");
   var a11 = document.createElement('a');
   a11.setAttribute("href",url1);
   a11.setAttribute("target",target1);
   var imgMain = document.createElement('img');
   imgMain.setAttribute("src",imgBNR1);
   imgMain.setAttribute("width","486");
   imgMain.setAttribute("height","175");
   imgMain.setAttribute("border","0");
   a11.appendChild(imgMain);
   mainSpan.appendChild(a11);
   td11.appendChild(mainSpan);
   tr1.appendChild(td11);
   // first row : second column 
   var td12 = document.createElement('td');
   td12.setAttribute("width","254");
   var onMouseOver1 = "MCO_resetImgs();dispNewBanner('" + item01 + "','" + url1 + "');MM_swapImage('" + item01 + "','','" + sideNavON1 + "',1)";
   var a12 = document.createElement('a');
   a12.setAttribute("href",url1);
   a12.setAttribute("target",target1);
   a12.setAttribute("onMouseOver",onMouseOver1);
   var imgSide1 = document.createElement('img');
   imgSide1.setAttribute("src",sideNavON1);
   imgSide1.setAttribute("alt",title1);
   imgSide1.setAttribute("name",item01);
   imgSide1.setAttribute("id",item01);
   imgSide1.setAttribute("width","254");
   imgSide1.setAttribute("height","38");
   imgSide1.setAttribute("border","0");
   a12.appendChild(imgSide1);
   td12.appendChild(a12);
   tr1.appendChild(td12);
   tbody.appendChild(tr1);

   // second row
   var tr2 = document.createElement('tr');
   var td21 = document.createElement('td');
   td21.setAttribute("width","254");
   td21.setAttribute("height","8");
   var imgBlnk1 = document.createElement('img');
   imgBlnk1.setAttribute("src","/all_images/spacer.gif");
   imgBlnk1.setAttribute("width","8");
   imgBlnk1.setAttribute("height","8");
   td21.appendChild(imgBlnk1);
   tr2.appendChild(td21);
   tbody.appendChild(tr2);

   // third row
   var tr3 = document.createElement('tr');
   var td31 = document.createElement('td');
   td31.setAttribute("width","254");
   var onMouseOver2 = "MCO_resetImgs();dispNewBanner('" + item02 + "','" + url2 + "');MM_swapImage('" + item02 + "','','" + sideNavON2 + "',1)";
   var a31 = document.createElement('a');
   a31.setAttribute("href",url2);
   a31.setAttribute("target",target2);
   a31.setAttribute("onMouseOver",onMouseOver2);
   var imgSide2 = document.createElement('img');
   imgSide2.setAttribute("src",sideNavOFF2);
   imgSide2.setAttribute("alt",title2);
   imgSide2.setAttribute("name",item02);
   imgSide2.setAttribute("id",item02);
   imgSide2.setAttribute("width","254");
   imgSide2.setAttribute("height","38");
   imgSide2.setAttribute("border","0");
   a31.appendChild(imgSide2);
   td31.appendChild(a31);
   tr3.appendChild(td31);
   tbody.appendChild(tr3);

   var tr4 = document.createElement('tr');
   var td41 = document.createElement('td');
   td41.setAttribute("width","254");
   td41.setAttribute("height","7");
   var imgBlnk2 = document.createElement('img');
   imgBlnk2.setAttribute("src","/all_images/spacer.gif");
   imgBlnk2.setAttribute("width","7");
   imgBlnk2.setAttribute("height","7");
   td41.appendChild(imgBlnk2);
   tr4.appendChild(td41);
   tbody.appendChild(tr4);

   var tr5 = document.createElement('tr');
   var td51 = document.createElement('td');
   td51.setAttribute("width","254");
   var onMouseOver3 = "MCO_resetImgs();dispNewBanner('" + item03 + "','" + url3 + "');MM_swapImage('" + item03 + "','','" + sideNavON3 + "',1)";
   var a51 = document.createElement('a');
   a51.setAttribute("href",url3);
   a51.setAttribute("target",target3);
   a51.setAttribute("onMouseOver",onMouseOver3);
   var imgSide3 = document.createElement('img');
   imgSide3.setAttribute("src",sideNavOFF3);
   imgSide3.setAttribute("alt",title3);
   imgSide3.setAttribute("name",item03);
   imgSide3.setAttribute("id",item03);
   imgSide3.setAttribute("width","254");
   imgSide3.setAttribute("height","38");
   imgSide3.setAttribute("border","0");
   a51.appendChild(imgSide3);
   td51.appendChild(a51);
   tr5.appendChild(td51);
   tbody.appendChild(tr5);

   var tr6 = document.createElement('tr');
   var td61 = document.createElement('td');
   td61.setAttribute("width","254");
   td61.setAttribute("height","8");
   var imgBlnk3 = document.createElement('img');
   imgBlnk3.setAttribute("src","/all_images/spacer.gif");
   imgBlnk3.setAttribute("width","8");
   imgBlnk3.setAttribute("height","8");
   td61.appendChild(imgBlnk3);
   tr6.appendChild(td61);
   tbody.appendChild(tr6);

   var tr7 = document.createElement('tr');
   var td71 = document.createElement('td');
   td71.setAttribute("width","254");
   var onMouseOver4 = "MCO_resetImgs();dispNewBanner('" + item04 + "','" + url4 + "');MM_swapImage('" + item04 + "','','" + sideNavON4 + "',1)";
   var a71 = document.createElement('a');
   a71.setAttribute("href",url4);
   a71.setAttribute("target",target4);
   a71.setAttribute("onMouseOver",onMouseOver4);
   var imgSide4 = document.createElement('img');
   imgSide4.setAttribute("src",sideNavOFF4);
   imgSide4.setAttribute("alt",title4);
   imgSide4.setAttribute("name",item04);
   imgSide4.setAttribute("id",item04);
   imgSide4.setAttribute("width","254");
   imgSide4.setAttribute("height","38");
   imgSide4.setAttribute("border","0");
   a71.appendChild(imgSide4);
   td71.appendChild(a71);
   tr7.appendChild(td71);
   tbody.appendChild(tr7);

   document.getElementById("navMenus").appendChild(frag);
}
/************************************************
* Function to display the NEW! icon up to 30 days
* of the posted day (unless otherwise specified).
* Parameters needed:
*      mes -> 2 digits month of the year
*      dia -> 2 digits day of the month
*      anual -> 4 digits year
* Optional parameter:
*      cuanto -> by default is 30 days but can be modified
* created by AbrAhAm HerrerA - Sep 9, 2008
************************************************/

function newIcon(mes,dia,anual,cuanto)
{
  var validDate = true;
  //alert(mes +'/'+dia);

  // validates input values
  if (!isUnsignedInteger(mes))
  {
    validDate = false;
    return false;
  }
  if (!isUnsignedInteger(dia))
  {
    validDate = false;
    return false;
  }
  var thisYear = new Date();
  if (!anual) 
  {
    anual = thisYear.getUTCFullYear();
  }
  else if (!isUnsignedInteger(anual))
  {
    validDate = false;
    return false;
  }
  if ((!cuanto) || (!isUnsignedInteger(cuanto)))
  {
    cuanto = 30;
  }

  // validates month
  if ((mes < 1) && (mes > 12))
  {
    validDate = false;
    return false;
  }
  else 
  {
    var actualMonth = mes;
    mes--;
  }
  // validates day
  if ((dia < 1) && (dia > 31))
  {
    validDate = false;
    return false;
  }
  // validates year
  if (anual < 1)
  {
    validDate = false;
    return false;
  }
  else if (anual < 1000)
  {
    anual += 1900
  }
  
  //alert(mes+'/'+dia+'/'+anual+' - '+cuanto)
  var myDate=new Date();
  myDate.setFullYear(anual,mes,dia);
  //alert(myDate.getMonth()+'/'+myDate.getDay()+'/'+myDate.getYear())
  var today = new Date();
  var nDate = new Date();
  nDate = myDate;
  nDate.setDate(nDate.getDate()+cuanto);
  //alert(nDate.getMonth()+'/'+nDate.getDay()+'/'+nDate.getYear())
  //alert(nDate+' - '+today)

  if (validDate)
  {
    if (nDate > today)
    {
      document.write(' <IMG SRC="/all_images/icon_new.gif" WIDTH="22" HEIGHT="7" BORDER="0" ALT="Posted on: ' + actualMonth + '/' + dia + '" TITLE="Posted on: ' + actualMonth + '/' + dia + '"> ');
    }
  }
}

// validates any Integer numbers
function isInteger(s) {
return (s.toString().search(/^-?[0-9]+$/) == 0);
}

// validates positive Integer numbers
function isUnsignedInteger(s) {
return (s.toString().search(/^[0-9]+$/) == 0);
}

/************************************************
* Function to display the UPDATED! icon up to 30 days
* of the posted day.
* Parameters needed:
*      mes -> 2 digits month of the year
*      dia -> 2 digits day of the month
*      anual -> 4 digits year
* Optional parameter:
*      cuanto -> by default is 30 days but can be modified
* created by AbrAhAm HerrerA - Sep 9, 2008
************************************************/

function updateIcon(mes,dia,anual,cuanto)
{
  var validDate = true;
  //alert(mes +'/'+dia);

  // validates input values
  if (!isUnsignedInteger(mes))
  {
    validDate = false;
    return false;
  }
  if (!isUnsignedInteger(dia))
  {
    validDate = false;
    return false;
  }
  var thisYear = new Date();
  if (!anual) 
  {
    anual = thisYear.getUTCFullYear();
  }
  else if (!isUnsignedInteger(anual))
  {
    validDate = false;
    return false;
  }
  if ((!cuanto) || (!isUnsignedInteger(cuanto)))
  {
    cuanto = 30;
  }

  // validates month
  if ((mes < 1) && (mes > 12))
  {
    validDate = false;
    return false;
  }
  else 
  {
    var actualMonth = mes;
    mes--;
  }
  // validates day
  if ((dia < 1) && (dia > 31))
  {
    validDate = false;
    return false;
  }
  // validates year
  if (anual < 1)
  {
    validDate = false;
    return false;
  }
  else if (anual < 1000)
  {
    anual += 1900
  }
  
  //alert(mes+'/'+dia+'/'+anual+' - '+cuanto)
  var myDate=new Date();
  myDate.setFullYear(anual,mes,dia);
  //alert(myDate.getMonth()+'/'+myDate.getDay()+'/'+myDate.getYear())
  var today = new Date();
  var nDate = new Date();
  nDate = myDate;
  nDate.setDate(nDate.getDate()+cuanto);
  //alert(nDate.getMonth()+'/'+nDate.getDay()+'/'+nDate.getYear())
  //alert(nDate+' - '+today)

  if (validDate)
  {
    if (nDate > today)
    {
      document.write(' <IMG SRC="/all_images/icon_updated.gif" WIDTH="46" HEIGHT="7" BORDER="0" ALT="Last Updated on: ' + actualMonth + '/' + dia + '" TITLE="Last Updated on: ' + actualMonth + '/' + dia + '"> ');
    }
  }
}

function thisYEAR()
{
var thisDate = new Date();
var thisYear = thisDate.getYear();
if (thisYear < 1000)
  thisYear += 1900;
document.write(thisYear);
}

