var menu_Width = 100;
var menu_Top = 156;
var menuItem_SingleIE6 = 30;
var menuItem_Single = 28;
var nLeft = 0;
var windowSize = 0;
var pageReady = false;
var i;
var oShadow = null;
var botonera_Pad = 170;
var menuCount = new Array();
var currentSubject = 0;


function $(id)
{
	var e = document.getElementById(id);
	return (e != null ? e : document.createElement());
}
function isFF() { return (navigator.userAgent.indexOf("Firefox")!=-1); }
function isIE() { return (navigator.appVersion.indexOf("MSIE")!=-1); }
function isIE6() { return (navigator.appVersion.indexOf("MSIE 6.0")!=-1); }
function isIE7() { return (navigator.appVersion.indexOf("MSIE 7.0")!=-1); }

function GetLeftPosition(pos, px)
{
	$navigator = navigator.appName;
	var distanciawrapper = 761;
	var widthexplorador = 0;
	if ($navigator == "Netscape")
	{
		widthexplorador = window.innerWidth;
	}
	else
	{
		distanciawrapper = distanciawrapper + 4;
		widthexplorador = document.body.offsetWidth;
	}
	
	if (widthexplorador < 750)
	{
		ileft = botonera_Pad;   
	}
	else
	{
		ileft = (widthexplorador - distanciawrapper)/2 + botonera_Pad;   
	}
    value = ileft + (menu_Width * pos);
    if (px) value = value + 'px';
    return value;
}

function GetMenuHeight(positions)
{
    if (isIE6())
    {
        return (positions * menuItem_SingleIE6) + (positions/2);
    }
    else
    {
        return positions * menuItem_Single;
    }
}



function onWindowResize() {
	for( key in window.menus )
	{
		element = document.getElementById(indexes[key] + "Container");
		element.style.left = GetLeftPosition(key, false) + "px";
	}
}

function construct(isHome)
{
	lod();
	//idflash se carga desde default.aspx.cs
	
	if (isHome)
	{
		if (idflash != -1)
		{
		    PedidoGaleria.startRequest();
		    $('img_marco').style.display = 'block';
		}
	}
}

function lod()
{
	window.onresize = chSize;
	chSize();
}

function chSize()
{
	iPadding = document.body.offsetWidth;
    iTotal = (iPadding - 1024) / 2;
	/*
     *  Botonera
     */
    o = $("Footer");
    p = $("ContenidoSeccion");
    o.style.paddingLeft = botonera_Pad + iTotal - 174 + 'px';
    p.style.marginLeft = (iTotal + botonera_Pad) + 'px';
    
    /*
     *  Menu
     */
    i = 0;
    reg = ypSlideOutMenu.Registry;
    for (menu in reg) 
    {
        newleft = GetLeftPosition(i, true);
        $(menu + 'Container').style.left = newleft;
        i++;
    }
    /*
     *  Marco Galeria
     */
    g = $('img_marco');
    if (isIE6())
    {
        g.style.left = 592 + iTotal + 'px';
    }
    else if (isIE7())
    {
		if (iTotal > -6)
		{
			g.style.left = 591 + iTotal + 'px';
		}
		else
		{
			g.style.left = 584 + 'px';
		}
    }
    else
    {
		if (iTotal > -10)
		{
			g.style.left = 595 + iTotal + 'px';
		}
		else
		{
			g.style.left = 584 + 'px';
		}
        
    }
}

function initPage() {
	window.pageReady = true;
	
	/* Revisa el rubro actual para marcarlo */
	if( window.currentSubject > 0 ) {
		var id = getIdentificador( window.currentSubject );
		var img = document.getElementById( id );
		
		if( img ) {
			img.src = "images/bt_" + id + "_on.gif";
		}
	}
	
	
	/* Revisa la barra de contenido */
	var barra = document.getElementById( "BarraNavContenido" );
	
	if( barra ) {
		var texto = document.getElementById( "HistoryRubro" );
		
		if( texto ) {
			
			/*	Cantidad es sólo por seguridad,
				para que no pueda pasar que quede
				en el loop para siempre.
			*/
			var cantidad = 1;
			
			while( barra.offsetWidth > 550 && cantidad < 75 ) {
				//texto.lastChild.nodeValue = texto.lastChild.nodeValue.substr( 0, texto.lastChild.nodeValue.length - 5 ) + "...";
				texto.innerHTML = texto.innerHTML.substr( 0, texto.innerHTML.length - 5 ) + "...";
				cantidad++;
			}
		}
	}
}

function redireccionar() {
	var link = document.getElementById("combo").value;
	location.href = link;
}

function readWindowSize() {
	window.windowSize = getWindowSize();
	$navigator = navigator.appName;
	
	if ($navigator == "Microsoft Internet Explorer")
	{
		window.nLeft = parseInt( ( windowSize["w"] - 750 ) / 2 ) + 170;
	}
	else
	{
		window.nLeft = parseInt( ( windowSize["w"] - 750 ) / 2 ) + 170;
	}
}
	
var menus = new Array();

/*
var overColors = {
	"thecenter" : "#d3004a",
	"jewish" : "#ff7e00",
	"programs" : "#e7b900",
	"management" : "#94be00",
	"communication" : "#09757f"
}
*/

var overColors = {
	"thecenter" : "#d3004a",
	"jewish" : "#ff7e00",
	"programs" : "#e7b900",
	"management" : "#2e9c00",
	"communication" : "#008f9e"
}
	
var bgOverColors = {
	"thecenter" : "#fbe5ed",
	"jewish" : "#ffe5cc",
	"programs" : "#faf1cc",
	"management" : "#eaf2cc",
	"communication" : "#e1eeef"
}
	
var indexes = [
	"thecenter",
	"jewish",
	"programs",
	"management",
	"communication"
]
	
var selectedMenu = null;

function preloadImage( url ) {
	var oImage = new Image();
	
	oImage.src = url;
}

function imageOnMouseOver( img ) {
	if( !pageReady )
		return;
	img = checkImage( img );
	img.src = "../images/bt_" + img.id + "_over.gif";
	document.getElementById( img.id + "Label" ).style.color = overColors[img.id];
	document.getElementById( img.id + "Cell" ).style.backgroundColor = bgOverColors[img.id];
	//ypSlideOutMenu.showMenu( img.id );
	selectedMenu = img.id;
}

function imageOnMouseOut( img ) {
	if( !pageReady )
		return;

	img = checkImage( img );
	
	if( selectedMenu != img.id || menuCount[img.id] == 0 ) {
		if( window.currentSubject != getIDRubro( img.id ) ) {
			img.src = "../images/bt_" + img.id + "_off.gif";
		}
		else {
			img.src = "../images/bt_" + img.id + "_on.gif";
		}
		document.getElementById( img.id + "Label" ).style.color = "#6a6a6a";
		document.getElementById( img.id + "Cell" ).style.backgroundColor = "";
		//ypSlideOutMenu.hideMenu( img.id );
	}
}

function setCurrentSubject( subjectID ) {
	window.currentSubject = subjectID;
}

function onMenuShow( id ) {
	imageOnMouseOver( id );
}

function onMenuHide( id ) {
	imageOnMouseOut( id );
}

function imageOnMouseDown( img ) {
	if( !pageReady )
		return;
		
	img = checkImage( img );
	img.src = "../images/bt_" + img.id + "_on.gif";
}

function imageOnMouseUp( img ) {

	if( !pageReady )
		return;
	
	img = checkImage( img );
	img.src = "../images/bt_" + img.id + "_over.gif";
	
	var ID = getIDRubro(img.id);
	
	window.location = "Home.aspx?h=" + ID;
}

function getIdentificador( id ) {
	switch( id ) {
		case "JCCE":
			return "thecenter";
			break;
			
		case "JCJI":
			return "jewish";
			break;
		
		case "JCMA":
			return "management";
			break;
		
		case "JCCN":
			return "communication";
			break;
		
		case "programs":
			return "programs";
			break;
	}
}

function getIDRubro( id ) {
	switch( id ) {
		case "thecenter":
			return "CEJC";
			break;
			
		case "jewish":
			return "JIJC";
			break;
		
		case "management":
			return "CMJC";
			break;
		
		case "programs":
			return "PRJC";
			break;
	}
}

function checkImage( o ) {
	if( !( o.src ) ) {
		return document.getElementById( o );
	}
	else
		return o;
}

function activateSearch() {
	var oSearch = document.getElementById( "Busqueda" )
	
	if( oSearch ) {
		if( oSearch.className != "InputBusquedaActivo" ) {
			oSearch.className = "InputBusquedaActivo";
			oSearch.value = "";
			oSearch.focus()
		}
	}
}

function activateSuscribirse() {
	var oSearch = document.getElementById( "Wucmenudesplegable2_txtnewsletter" )
	
	if( oSearch ) {
		if( oSearch.className != "InputNewsletter" ) {
			oSearch.className = "InputNewsletter";
			oSearch.value = "";
			oSearch.focus()
		}
	}
}
function finishedLoadingMenus() {
	for (var i = 0; i < menus.length; i++) {
		menus[i].onactivate = new Function("selectedMenu = indexes[" + i + "]; // showShadow( indexes[" + i + "] );")
		menus[i].ondeactivate = new Function("selectedMenu = null; imageOnMouseOut(indexes[" + i + "]); // hideShadow( indexes[" + i + "] );")
	}
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}
	
function getWindowSize() {
	var w = 0, h = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	}
	else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		}
	}
	
	return { "w" : w, "h" : h }
}

function showShadow( container ) {
	return;
	
	getShadow();
	
	var oMenu = document.getElementById( container + "Container" );
	
	if( oMenu ) {
		alert( oMenu.style.top )
		oShadow.style.width = oMenu.style.width;
		oShadow.style.height = oMenu.style.height;
		oShadow.style.top = parseInt( oMenu.style.top ) + 5 + "px";
		oShadow.style.left = parseInt( oMenu.style.left ) + 5 + "px";
		
		oShadow.style.display = "";
	}
}

function getShadow() {
	if( oShadow == null )
		oShadow = document.getElementById( "shadow" );
}

function changeLanguage() {	
	window.location = "/lang.asp?ID=" + document.getElementById( "Idiomas" ).value + "&Return=" + escape( window.location.href );
}

function checkRemember() {
	var oCheck = document.getElementById( "RememberMe" );

	if( oCheck ) {
		oCheck.checked = !oCheck.checked;
	}
}

function checkRememberGrande() {
	var oCheck = document.formGrande.RememberMe

	if( oCheck ) {
		oCheck.checked = !oCheck.checked;
	}
}

function downloadFile( url ) {
	/*
	if( document.createElement ) {
		var iframe = document.createElement( "iframe" );
		
		if( iframe ) {
			iframe.src = '/downloadFile.asp?url=' + url;
			iframe.style.display = 'none';
			iframe.width = 0;
			iframe.height = 0;
			document.appendChild( iframe );
		}
		else {
			window.open( '/downloadFile.asp?url=' + url );
		}
	}
	else {
		window.open( '/downloadFile.asp?url=' + url );
	}
	*/
	
	window.open( '/downloadFile.asp?url=' + url );
}

function olvidoPassword() {
	document.formGrande.action='use-forgot.asp';
	document.formGrande.submit();
}

function olvidoPasswordArriba() {
	document.loginArriba.action='use-forgot.asp';
	document.loginArriba.submit();
}
function olvidoPasswordPH() {
	document.fLog.action='use-forgot.asp';
	document.fLog.submit();
}

function openWindow( url, width, height, scrollbars, resizable ) {
	if( scrollbars ) {
		scrollbars = "1";
	}
	else {
		scrollbars = "0";
	}
	
	if( resizable ) {
		resizable = "1";
	}
	else {
		resizable = "0"
	}
	
	window.open( url, "JCCPopup", "top=50, left=50, height=" + height + ", width=" + width + ", scrollbars=" + scrollbars + ", menubar=no, titlebar=no, resizable=" + resizable );
}

function searchContents() {

	var searchField = document.getElementById( "Busqueda" );

	var searchForm = document.getElementById( "frmBusqueda" );

	if(searchField)
	{
		if( searchField.value.length > 0 && searchField.value.length < 100 )
		{
			window.location = "searchresults.aspx?q=" + encodeURI( searchField.value );
			
		}
	}
}

function isIE()
{
	return document.all?true:false;
}	

function onRealSearchKeyPress(e)
{
	if( e.keyCode == 13 ) 
	{
		/*Cancela el submit*/
		if (isIE())
		{
			e.cancelBubble = true;
			e.returnValue = false;
			e.cancel = true;
		}
		//return false;
		
		searchContents();

		e.preventDefault();e.stopPropagation();
	}
}
function onSearchKeyPress(e) {
	if( e.keyCode == 13 ) 
	{
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		
		//searchContents();
	}
}

/* WebTrends Live */
function wtl_Tag5_152061()
{
	var SERVER= "";
	var CONTENTGROUP= "";
	
	var wtl_URL= document.URL;
	var wtl_Title= document.title;

	function D8( d)
	{
		var fwd=1, seed= new Date('01/01/2000'), key= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var s= key.charAt( d.getFullYear()-2000)+key.charAt( d.getMonth()+1)+key.charAt( d.getDate());
		s+= key.charAt( d.getHours())+key.charAt( d.getMinutes())+key.charAt( d.getSeconds());
		while( seed.getDay()!=fwd) seed= new Date(seed.getTime() + 86400000);
		var w= Math.floor( (d.getTime()-(seed.getTime()+86400000)) / 604800000 );
		s+= key.charAt( (w-(w%16))/16 );
		s+= key.charAt( w%16);
		return s;
	}
	
	function A( B, C)
	{
		W+="&"+B+"="+escape(C);
	}

	var t = new Date();
	var W="http"+(document.URL.indexOf('https:')==0?'s':'')+"://statse.webtrendslive.com/S152061/button5.asp?tagver=5&si=152061&fw=1";
	A( "server", typeof(SERVER)== "string" ? SERVER : "");
	A( "Group", typeof(CONTENTGROUP)== "string" ? CONTENTGROUP : "");
	A( "tz", t.getTimezoneOffset());
	A( "ch", t.getHours());
	A( "cl", D8(t));
	A( "ti", typeof(wtl_Title)== "string" ? wtl_Title : document.title);
	A( "url", typeof(wtl_URL)== "string" ? wtl_URL : document.URL);
	A( "rf", window.document.referrer);
	A( "js", "Yes");
	A( "ul", navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage);
	if(typeof(screen)=="object")
	{
	A( "sr", screen.width+"x"+screen.height);
	A( "cd", screen.colorDepth);
	A( "jo", navigator.javaEnabled()?"Yes":"No");
	}
	if( W.length>2048 && navigator.userAgent.indexOf('MSIE')>=0)
		W= W.substring( 0, 2043)+"&tu=1";

	document.write('<IMG ID="WTL_152061" BORDER="0" WIDTH="1" HEIGHT="1" SRC="'+W+'">');
}



function backgroundOnMouseOver1(id){
	document.getElementById(id + "Label").style.color = "#5d0d18";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-opcionelegido.png')";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOut1(id){
	document.getElementById(id + "Label").style.color = "#ffffff";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-menu2.png')";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOver2(id){
	document.getElementById(id + "Label").style.color = "#000000";
	document.getElementById(id + "Label").style.backgroundImage ="url('images/header/fondo-menuelegido.png')";
	document.getElementById(id + "Label").style.fontWeight = "bold";
	document.getElementById(id + "Label").style.backgroundRepeat = "repeat-x";
}
function backgroundOnMouseOut2(id){
	document.getElementById(id + "Label").style.color = "#ffffff";
	document.getElementById(id + "Label").style.backgroundImage ="none";
	document.getElementById(id + "Label").style.backgroundColor ="#818181";
	document.getElementById(id + "Label").style.fontWeight = "normal";
}

function ResizeIFrame(id)
{
	if (!window.opera && document.all && document.getElementById){
		id.style.height=id.contentWindow.document.body.scrollHeight;
	} else if(document.getElementById) {
		id.style.height=id.contentDocument.body.scrollHeight+"px";
	}
}


