// JavaScript Document


//EFECTUA BUSQUEDA
function busca() {
var termino = document.forms.busqf1.busqueda.value;
if (termino == "") {
} else {
	var cadena="?q=search/node/"+ termino;
	location.href=cadena;
}
}


//ABRE POPUP ENVIAR CONTACT FORM
function open_overlay_email() {
document.getElementById("overlay").style.visibility="visible";
document.getElementById("carousel").style.visibility="visible";
var _docHeight = document.body.offsetHeight;
document.getElementById("overlay").style.height=_docHeight;
document.getElementById("carousel").style.top="30%";
var cadena="";
document.getElementById("carousel").innerHTML="<img src='themes/foliage/images/top_jcarousel.png' style='margin-bottom:-8px'><div style='width:690px;min-width:690px;background-color:#fff;margin-bottom:-16px;'><span style='text-align:center'><p>Thank you for contacting Biosensors International. Someone shall be getting in touch with you shortly.<br />To continue browsing the Biosensors International website, please click 'Done' now<br />and you will be redirected to our home page.</p><p><a href='javascript:document.forms.f1.submit();'><strong>Done</strong></a></p></span></div><img src='themes/foliage/images/bottom_jcarousel.png'>";
}

//ENCIENDE/APAGA TEXTSIZE
function textOn(x) {
	if (x===0) {
		document.getElementById('textSize').style.backgroundPosition="0px 0px";
	}
	if (x==1) {
		document.getElementById('textSize').style.backgroundPosition="0px -15px";
	}
}


//VALIDA Y ENVIA LA CONTACT FORM
function comprueba () {
var error=0;

		if (document.forms.f1.MessageText.value === '') {
document.getElementById('fehl').innerHTML='Please write something in the Question/Comment textfield';
error=1;
		}
	
		if (document.forms.f1.Email.value === '') {
document.getElementById('fehl').innerHTML='Please provide an e-mail address';
error=1;
		}	

var apos=document.forms.f1.Email.value.indexOf("@");
var dotpos=document.forms.f1.Email.value.lastIndexOf(".");
if (document.forms.f1.Email.value === "" || apos<1 || dotpos-apos<2)
{
document.getElementById('fehl').innerHTML='Please provide a valid e-mail address';
error=1;
}


		if (document.forms.f1.LastName.value === '') {
document.getElementById('fehl').innerHTML='One or more required fields are empty';
error=1;
		}		
		if (document.forms.f1.Name.value === '') {
document.getElementById('fehl').innerHTML='One or more required fields are empty';
error=1;
		}	
		if (document.forms.f1.Title.value == '[ Title ]') {
document.getElementById('fehl').innerHTML='One or more required fields are empty ';
error=1;
		}		

if (error === 0) {
open_overlay_email(3);
}

}


//CAMBIA TAMAŅO DE TEXTO
function textSize(y) {
	if (y===0) {
	document.getElementById('resizable').style.fontSize='85%';
	document.getElementById('resizable').style.lineHeight='1.3em';
	}
	if (y==1) {
	document.getElementById('resizable').style.fontSize='100%';
	document.getElementById('resizable').style.lineHeight='1.3em';
	}
	if (y==2) {
	document.getElementById('resizable').style.fontSize='120%';
	document.getElementById('resizable').style.lineHeight='1.5em';
	}
}

//GENERA ESQUINAS REDONDEADAS EN IMAGENES
var ES = new Object();

function redondea() { 
if (document.getElementById('imagewrapper')) { ES.Round.create('imagewrapper'); }
if (document.getElementById('imagewrapper2')) { ES.Round.create('imagewrapper2'); }
if (document.getElementById('imagewrapper3')) { ES.Round.create('imagewrapper3'); }
if (document.getElementById('imagewrapper4')) { ES.Round.create('imagewrapper4'); }
if (document.getElementById('imagewrapper5')) { ES.Round.create('imagewrapper5'); }
if (document.getElementById('imagewrapper6')) { ES.Round.create('imagewrapper6'); }
if (document.getElementById('imagewrapper7')) { ES.Round.create('imagewrapper7'); }
if (document.getElementById('imagewrapper8')) { ES.Round.create('imagewrapper8'); }
if (document.getElementById('imagewrapper9')) { ES.Round.create('imagewrapper9'); }
};


ES.Round = {
create  :  function(wrapper) {
  for(var i = 1; 4 >= i;  i++) {
  var curve = document.createElement('span');
  curve.className = 'curve'+i;
  var target = document.getElementById(wrapper);
  target.appendChild(curve);
  }
 }
};


//DESPLIEGA LOS ELEMENTOS SHOW/HIDE
function displayer(aa,tops) {
	
var cadena="";
var cadena2="";
var cadena2b="";
var cadena3="";
var objCadena;
var objCadena2;
var objCadena2b;
var objCadena3;
for (var i=0; i<=tops; i++) {
	cadena="text"+i;
	cadena2="each_item"+i;
	cadena2b="each_itemClin"+i;
	cadena3="display"+i;
	objCadena=document.getElementById(cadena);
	objCadena2=document.getElementById(cadena2);
	objCadena2b=document.getElementById(cadena2b);
	objCadena3=document.getElementById(cadena3);
	if (objCadena && i!=aa) {
		if ( objCadena2 ) {
			objCadena2.style.background="url('themes/foliage/images/element_bg.jpg')";
			objCadena2.style.backgroundRepeat="no-repeat";
			}
		if ( objCadena2b ) {
			objCadena2b.style.background="url('themes/foliage/images/element_bg_clin.jpg')";
			objCadena2b.style.backgroundRepeat="no-repeat";
			}
		objCadena.style.display="none";
		objCadena3.style.display="inline";
	}
}

var open=0;
cadena="text"+aa;
objCadena=document.getElementById(cadena);
cadena2="each_item"+aa;
objCadena2=document.getElementById(cadena2);
cadena2b="each_itemClin"+aa;
objCadena2b=document.getElementById(cadena2b);
cadena3="display"+aa;
objCadena3=document.getElementById(cadena3);
if (objCadena.style.display=="none") {
	objCadena.style.display="block";
	if ( objCadena2 ) {
		objCadena2.style.background="url('themes/foliage/images/menu_tile2.jpg')";
		}
	if ( objCadena2b ) {
		objCadena2b.style.background="url('themes/foliage/images/menu_tile2.jpg')";
		}
	objCadena3.style.display="none";
	open=1;
	} 		
if (objCadena.style.display!="none" && open===0)	{
		objCadena.style.display="none";
	if ( objCadena2 ) {
			objCadena2.style.background="url('themes/foliage/images/element_bg.jpg')";
			objCadena2.style.backgroundRepeat="no-repeat";
		}
	if ( objCadena2b ) {
			objCadena2b.style.background="url('themes/foliage/images/element_bg_clin.jpg')";
			objCadena2b.style.backgroundRepeat="no-repeat";
		}
		objCadena3.style.display="inline";
	open=0;
	}
	
}

//ABRE LA VENTANA DE MEDIOS
function open_overlay(mediatype, url) {

if (url != "sites/default/files/BioMatrixMovie_768_452.swf")
{
var width = 1080;
var height = 810;
var middle = 540;
/*var width = 800;
var height = 645;
var middle = 400;*/
}
else
{
var width = 768;
var height = 452;
var middle = 384;
}


if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
document.getElementById("left_band").style.backgroundColor="#595959";
document.getElementById("right_band").style.backgroundColor="#595959";
}
document.getElementById("overlay").style.visibility="visible";
document.getElementById("media").style.visibility="visible";
var _docHeight = document.body.offsetHeight;
document.getElementById("overlay").style.height=_docHeight;

var _docWidth = document.getElementById("overlay").offsetWidth;
var cadena = "" + ((_docWidth/2)-middle) + "px";
document.getElementById("media").style.left = cadena;


var cadena="";
if (mediatype=="flash") {
cadena=cadena+'<div style="width:'+width+'px; text-align:right;margin-top:-19px;height:15px;padding:0px"><a href="#" onclick="close_overlay();return false;" title="Close Visualization"><img src="themes/foliage/images/close_button.jpg"></a></div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="FlashMovie" align="middle">	<param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="';
cadena=cadena + url;
cadena=cadena + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="';
cadena=cadena + url;
cadena = cadena + '" quality="high" scale="showall" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="FlashMovie" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

}

document.getElementById("media").innerHTML=cadena;

if (document.getElementById("bioflash")) {
	document.getElementById("bioflash").innerHTML="<img src='sites/default/files/web_images/T2-biomatrix4.jpg'>";
	}
}



//CIERRA LA VENTANA DE MEDIOS
function close_overlay() {
if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
document.getElementById("left_band").style.backgroundColor="#fff";
document.getElementById("right_band").style.backgroundColor="#fff";
}
document.getElementById("overlay").style.visibility="hidden";
document.getElementById("media").style.visibility="hidden";
if (document.getElementById("bioflash")) {
	var cadena="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='528' height='480'><param name='movie' value='sites/default/files/flash2.swf'><param name='quality' value='high'><embed src='sites/default/files/flash2.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='528' height='480'></embed></object>";
	document.getElementById("bioflash").innerHTML=cadena;
	}
}


//CUIDADO CON EL FLASH
function biomatrix(){
		var cadena="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='528' height='480'><param name='movie' value='sites/default/files/flash2.swf'><param name='quality' value='high'><embed src='sites/default/files/flash2.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='528' height='480'></embed></object>";
	if ( document.getElementById("bioflash").innerHTML != "<img src='sites/default/files/web_images/T2-biomatrix4.jpg'>" ) {
			document.getElementById("bioflash").innerHTML="<img src='sites/default/files/web_images/T2-biomatrix4.jpg'>";
	} else {
			document.getElementById("bioflash").innerHTML=cadena;
	}
}
function homeflash() {
			var cadena="<object style='margin-top:12px' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='990' height='395' id='BioMatrixMovieV2009v41_1024_576'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='wmode' value='transparent' /><param name='movie' value='sites/default/files/BioMatrixMovieV2009v41_1024_576.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#000000' /><embed src='sites/default/files/BioMatrixMovieV2009v41_1024_576.swf' quality='high' bgcolor='#000000' width='990' height='395' name='BioMatrixMovieV2009v41_1024_576' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed></object>";
	if ( document.getElementById("home_img").innerHTML != "<img src='sites/default/files/web_images/biohome.jpg'>" ) {
			document.getElementById("home_img").innerHTML="<img src='sites/default/files/web_images/biohome.jpg'>";
	} else {
			document.getElementById("home_img").innerHTML=cadena;
	}
}





//ABRE POPUP LEAVING SITE
function open_overlay_link(link) {
document.getElementById("overlay").style.visibility="visible";
document.getElementById("carousel").style.visibility="visible";
var _docHeight = document.body.offsetHeight;
document.getElementById("overlay").style.height=_docHeight;
document.getElementById("carousel").style.top="30%";
var cadena="<img src='themes/foliage/images/top_jcarousel.png' style='margin-bottom:-8px'><div style='width:690px;min-width:690px;background-color:#fff;margin-bottom:-16px;'><span style='text-align:center'><p>You are leaving Biosensors website.<br />Click OK to proceed to a different site.</p><p><a href='javascript:location.href=";
cadena=cadena+'"'+link;
cadena=cadena+'"';
cadena=cadena+"'><strong>OK</strong></a></p></span></div><img src='themes/foliage/images/bottom_jcarousel.png'>";
document.getElementById("carousel").innerHTML=cadena;
}



//SCROLL AL PRIMER ELEMENTO DEL jCAROUSEL ---NO FUNCIONA****************************
//function mycarousel_initCallback(carousel,state) {
//jQuery('#mycarousel').scroll(0);
//    };

//ABRE EL jCAROUSEL DINAMICO
function open_carousel(x,a,b,c,d,e,f) {
document.getElementById("overlay2").style.visibility="visible";
document.getElementById("carousel").style.visibility="visible";
var _docHeight = document.body.offsetHeight;
document.getElementById("overlay2").style.height=_docHeight;
// Destroy contents of wrapper
$('.cawrap *').remove();
// Create UL list
$('.cawrap').append('<ul id="mycarousel" class="jcarousel-skin-ie7"></ul>');
// Load your items into the carousellist
var i=1;
var cadena="";
var imagen=new Array("-",a,b,c,d,e,f);
   while (i<=x) {
   cadena="";
   cadena=cadena+"<li><img src='sites/default/files/web_images/";
   cadena=cadena+imagen[i];
   cadena=cadena+"'></li>";
   $('#mycarousel').append(cadena);
   i++;
   }
// Now apply carousel to list
jQuery('#mycarousel').jcarousel({
		scroll:1
		}); 
}

//CIERRA EL jCAROUSEL
function close_carousel() {
  document.getElementById("carousel").style.visibility="hidden";
  document.getElementById("overlay").style.visibility="hidden";
  document.getElementById("overlay2").style.visibility="hidden";
}


function footer() {
var altoviewport = $(document).height();

	var altopagewrap = document.getElementById("pageWrap").offsetHeight;
	var diferencia = altoviewport - altopagewrap - 15;
	if (diferencia > 120) {
		var cadena=""+diferencia+"px";
		document.getElementById("footer").style.height = cadena;
		}
if (window.innerHeight){
var altoviewport = window.innerHeight;
var anchoviewport = window.innerWidth;
} else {
var altoviewport = document.body.clientHeight;
var anchoviewport = document.body.clientWidth;
}		

document.getElementById("left_band").style.position = "absolute";
document.getElementById("left_band").style.top = "0";
document.getElementById("left_band").style.left = "0";
var  lwidth  =  ((anchoviewport-990)/2)-8;
if(lwidth < 0 ) {  lwidth = 0; } 
document.getElementById("left_band").style.width = lwidth+"px";
//document.getElementById("left_band").style.width = ""+((anchoviewport-990)/2)-8+"px";

document.getElementById("left_band").style.height = "" + $(document).height() + "px";
		
document.getElementById("right_band").style.position = "absolute";
document.getElementById("right_band").style.top = "0";
document.getElementById("right_band").style.left = ""+((((anchoviewport-990)/2)+980)+2)+"px";
var  rwidth  =  ((anchoviewport-990)/2);
if(rwidth < 0 ) {  rwidth = 0; } 

document.getElementById("right_band").style.width = rwidth+"px";


document.getElementById("right_band").style.height = "" + $(document).height() + "px";		

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
document.getElementById("left_band").style.width = ""+(((anchoviewport-990)/2)-2)+"px";
}

}
