﻿// JScript File

// Global


var m_EOLifeCookieExpiredays = 365;
function SetAsHomePage(oObj)
{
    if(IsMicrosoft()){
        oObj.style.behavior="url(#default#homepage)";
        oObj.setHomePage(window.location.host);
    }else{
        alert('Go to Preferences in the Edit Menu\n Choose Navigator from the list on the left\n Click on the "Use Current Page" button')
    }
}
function runCmdClick(oCmd){
    if (IsMicrosoft())
    {
	    // IE
	    oCmd.click();
    }
    else
    {
	    // FireFox
	    var e = document.createEvent("MouseEvents");
	    e.initEvent("click", true, true);
	    oCmd.dispatchEvent(e);
    }
}
function getMyFolderElementName()
{
    var sName = '';
    if(document.getElementById('MyFolderCommandID'))
    {
        sName = document.getElementById('MyFolderCommandID').value;
    }
    return sName;
}

function getEOLifeCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start = document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
    return ""
}

function setEOLifeCookie(c_name,value)
{
    var expiredays = m_EOLifeCookieExpiredays;
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function IsMicrosoft() {
    if (navigator.appName.indexOf("Microsoft") !=-1) {
        return true;
    } else {
        return false;
    }
}
function doUpdateMemoAdd(sAct,sArg)
{
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
       
        var oInputs = document.getElementsByTagName("input");
        var oCmd;
        for(var i=0;i<oInputs.length;i++){
            if(oInputs[i].id.indexOf("cmdDoPostBackMemoAdd")>0){
                oCmd = oInputs[i];
            }
        }
        if( oCmd != null){ 
            theForm.__EVENTTARGET.value = sAct;
            theForm.__EVENTARGUMENT.value = sArg;
            runCmdClick(oCmd)
        }
    }
}

function OpenVideo() {

    window.location = "/articles/video_articles/full_list.aspx";
}

function doUpdate(sAct,sArg)
{
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
       
        var oInputs = document.getElementsByTagName("input");
        var oCmd;
        for(var i=0;i<oInputs.length;i++){
            if(oInputs[i].id.indexOf("cmdDoPostBack")>0){
                oCmd = oInputs[i];
            }
        }
        if( oCmd != null){ 
            theForm.__EVENTTARGET.value = sAct;
            theForm.__EVENTARGUMENT.value = sArg;
            runCmdClick(oCmd)
        }
    }
}
function doCmdUpdate(sCmd,sAct,sArg)
{
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        var oCmd = document.getElementById(sCmd);
        if( oCmd != null){ 
            theForm.__EVENTTARGET.value = sAct;
            theForm.__EVENTARGUMENT.value = sArg;
            runCmdClick(oCmd)
        }
    }
}
function DocumentWrite(sHtml)
{
    //alert(sHtml);
	document.writeln(sHtml);
}

function WriteFlashObj(sSrc,sWidth,sHeight,bTrans,sFlashVars,sID)
{
    var sObj = "";
	var sWMode = "";
	var sObjID = sSrc.replace(".swf","");
	var sVars = "";
	var sPrfx = "?";
	if(sFlashVars){
	    sVars = sFlashVars;
	}
	if(sID){
	    sObjID = sID;
	}else{
	    sObjID = sSrc.replace(".swf","");
	}
	sObj = sObj+"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' width='"+sWidth+"' height='"+sHeight+"' id='"+sObjID+"' align='middle' VIEWASTEXT>";
	sObj = sObj+"<param name='allowScriptAccess' value='sameDomain' />";
	sObj = sObj+"<param name='movie' value='"+sSrc+"' />";
	sObj = sObj+"<param name='quality' value='high' />";
	sObj = sObj+"<param name='bgcolor' value='#ffffff' />";
	sObj = sObj+"<param name='flashvars' value='"+sVars+"' />";
	if(bTrans == true){
		sObj = sObj+"<PARAM NAME='WMode' VALUE='Transparent'>";
		sWMode = "wmode='transparent'";
	}
	sObj = sObj+"<embed src='"+sSrc+"' flashvars='"+sVars+"' quality='high' bgcolor='#ffffff' "+sWMode+" width='"+sWidth+"' height='"+sHeight+"' ID='"+sObjID+"' NAME='bg' align='middle' allowScriptAccess='sameDomain' swLiveConnect=true ID='bg' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	sObj = sObj+"</object>";
	
	DocumentWrite(sObj);
}
function SetPopUp()
{
	document.write ("<div dir='rtl' class='PopUpWin' name='PopUpWin' id='PopUpWin' Style='position:absolute; z-index: 99999; background-color:#ED1B2D; display: none;'>")
	document.write ("<div style='height:20px'><img src='/images/x_closing.gif' onclick='HidePopUp()' style='cursor:pointer;float:left; padding-top:7px; padding-left:5px;' /></div>");
	document.write ("<input type='hidden' id='PopUpParent'> ");
	document.write ("<span class='PopUpCaption' id='PopUpCaption' ></span>");
	document.write ("<iFrame id='PopUpFrame' src='' Width='100%' Height='100%' frameBorder='no'></iframe>");
	document.write ("</div>");
}
function ShowPopUp(sUrl, sLeft, sWidth, sHeight, sParent)
{
	//hideDropDownLists();
	var oPopUpWin = document.getElementById('PopUpWin');
	var oPopUpFarme = document.getElementById('PopUpFrame');
	var oPopUpParent = document.getElementById('PopUpParent');
	
	oPopUpWin.style.display = "block";
	oPopUpWin.style.width = sWidth;
	oPopUpWin.style.height = sHeight;
	oPopUpWin.style.left = sLeft;
	
	oPopUpFarme.src = sUrl;
	oPopUpParent.value = sParent;
	
	var vTopY = 0;
    if (document.documentElement != null) {
        vTopY = document.documentElement.scrollTop;
    }else{
        vTopY = window.scrollY;
    }
    if(IsMicrosoft()){
        vTopY = event.clientY+vTopY;
        vTopY = vTopY-parseInt(sHeight);
    }
    
    oPopUpWin.style.top = vTopY+"px";
    
    if(IsMicrosoft()){
        oPopUpFarme.window.close = HidePopUp;
    }else{
        oPopUpFarme.contentWindow.close = HidePopUp;
    }
}

function HidePopUp()
{
	var oPopUpWin = document.getElementById('PopUpWin');
	var oPopUpFarme = document.getElementById('PopUpFrame');
	oPopUpWin.style.display = "none";
	oPopUpFarme.src ="";
}

function SearchOnKey()
{
    var iEnter = 13;
    if(IsMicrosoft()){
        switch(event.keyCode){
	        case iEnter: doUpdate("Search",""); break;
        }
    }
}

function ResizeBack(iNewHeight){
    var oMainBg = document.getElementById("MainBg");
    var oInnerBg = document.getElementById("InnerBg");
    var iMinHeight = 700;
    
    if(iNewHeight){
        iMinHeight = iNewHeight+100;
    }
    if(oInnerBg != null){
        if(parseInt(oInnerBg.offsetHeight)<iMinHeight){
            oInnerBg.style.height = iMinHeight+"px"
        }
    }
    if(oMainBg != null){
        var iHeight = 0;
        var iMainHeight = parseInt(oMainBg.offsetHeight);
        setTimeout("ResizeBackDelay("+iMainHeight+");",100);
    }
}
function ResizeBackDelay(MainHeight){
    var oSwf_obj = document.getElementById("bg_swf_obj");
    var oSwf = document.getElementById("bg_swf");
    if(oSwf && oSwf_obj)
    {
        var iOfset = 0;
        if(IsMicrosoft()){
            iOfset = 0;
        }else{
            iOfset = 0;
        }
        oSwf_obj.style.height = (MainHeight+iOfset)+"px";
        oSwf.style.height = oSwf_obj.style.height;    
    }
}
function _ResizeBack(NewHeight){
            
    var obg_main = document.getElementById("bg_main");
    if(obg_main != null){
        var iHeight = 0;
        var iMainHeight = parseInt(obg_main.offsetHeight);
        var iBodyHeight = 700;
        var cDrgOfset = 160;
        
        if(iMainHeight < iBodyHeight){
            iMainHeight = iBodyHeight;
        }
        if(NewHeight){
            iHeight = NewHeight+cDrgOfset;
        }else{
            iHeight = iMainHeight;
        }
        /*
        if (document.documentElement)
            iHeight = parseInt(document.documentElement.scrollHeight);
        else if (document.body)
            iHeight = parseInt(document.body.scrollHeight);
        
        if (oFooter != null){
            oFooter.style.top = (iHeight+25)+"px";
        }
       */
       //alert(iHeight)
       setTimeout("ResizeBackDelay("+iHeight+","+iMainHeight+");",100);
    }
}
function _ResizeBackDelay(NewHeight,MainHeight){
    var oObj = document.getElementById("bg_swf");
    var oFooter = document.getElementById("BotFooter");
    var iHeight = NewHeight;
    var iMainHeight = MainHeight;
    var iFHeight = iHeight-iMainHeight;
    oObj.style.height = (iHeight+100)+"px";
    if (oFooter != null && iFHeight > 0){
        oFooter.style.top = (iFHeight- 0)+"px";
    }
}
function EOLifeResizeSwf(sSwfName,sMainName){
    setTimeout("EOLifeResizeSwfDelay('"+sSwfName+"','"+sMainName+"');",50);
}
function EOLifeResizeSwfDelay(sSwfName,sMainName){
    var oSwfName = document.getElementById(sSwfName);
    var oMainName = document.getElementById(sMainName);
    if(oSwfName != null && oMainName != null){
    
        oSwfName.style.height = oMainName.offsetHeight + "px";
    }
}

function ShowComment(sHiddId,sShowId)
{
	var oToHidd = document.getElementById(sHiddId);
	var oToShow = document.getElementById(sShowId);
	
	oToHidd.style.display = 'none';
	oToShow.style.display = '';
	
	ResizeBack();
}

function ValidateEmail(strValue) 
{
    var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{2})(\.[a-z]{2})*$)/;
    var bRet = true;
    //check for valid email
    if(strValue != "") {
        bRet = objRegExp.test(strValue);
    }
	    
    return bRet;
}

function EOLifePrintItem(sBodyID){
    
    var oBody = document.getElementById(sBodyID);
    if(oBody)
    {
        var sHtml = ''
        sHtml = oBody.outerHTML;
        sHtml = sHtml.replace('/images/Promo/Promo1.png', '');
        sHtml = sHtml.replace('/images/Promo/Promo2.png', '');
        sHtml = sHtml.replace('/images/Promo/Promo3.png', '');
        var oWin = window.open('/PrintItem.htm?bodyID='+sBodyID, 'Print', 'scrollbars=yes,resizable=yes,menubar=no,toolbar=no,status=yes,width=800,height=650,top=0,right=0' );  				
        //var sHtml = "<div style='width:100%; text-align:center'><div dir='rtl' style='width:702px; margin:auto; text-align:right; font-family:Arial; font-size:12px'>"+sHtml+"</div></div>";
        //oWin.document.write(sHtml);
        oWin.focus();
        //oWin.print();
    }
}

function setEnterSearch(e, sTargetID)
{
    var oTarget = document.getElementById(sTargetID);
    var iEnter = 13;
    if(oTarget != null)
    {
        if(e.keyCode == iEnter)
        {
            doClientSearch(sTargetID);
        }
    }
    return false;
}

function SetEnter(e,sTargetID)
{
    var oTarget = document.getElementById(sTargetID);
    var iEnter = 13;
    if(oTarget != null){
        switch(e.keyCode){
	        case iEnter: 
	            if(oTarget.name == ""){
	                __doPostBack(oTarget.id.replace(/_/g,"$"), "");
	            }else{
	                runCmdClick(oTarget);
	            }
	            break;
        }
    }
}

function TextMaxLength(oObj,iMax) {
    if ( oObj.value.length > iMax )
    {
        oObj.value = oObj.value.substring( 0, iMax );
        return false;
    }
}


ModalPopup = function(elem, options) {
    options = options || {};
    var HasBackground = (options.HasBackground != null) ? options.HasBackground : true;
    var BackgroundColor = options.BackgroundColor || '#000000';
    var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
    BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
    var BackgroundOnClick = options.BackgroundOnClick || function() { };
    var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
    var Zindex = options.Zindex || 90000;
    var AddLeft = options.AddLeft || 0; //in px
    var AddTop = options.AddTop || 0; //in px
    showSelectElements(false);
    function _Convert(val) {
        if (!val) { return; }
        val = val.replace("px", "");
        if (isNaN(val)) { return 0; }
        return parseInt(val);
    }
    var popup = document.getElementById(elem);
    if (!popup) { return; }
    var winW = (document.layers || (document.getElementById && !document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
    var winH = window.innerHeight ? window.innerHeight : (document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
    popup.style.display = "block";
    popup.style.visibility = "visible";
    var currentStyle;
    if (popup.currentStyle) {
        currentStyle = popup.currentStyle;
    }
    else if (window.getComputedStyle) {
        currentStyle = document.defaultView.getComputedStyle(popup, null);
    } else {
        currentStyle = popup.style;
    }

    var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

    var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

    if (isIe6()) {
        popup.style.position = "absolute";
    } else {
        popup.style.position = "fixed";
    }
    popup.style.left = (winW / 2 - elemW / 2 + AddLeft) + "px";

    if (isIe6()) {
        popup.style.top = Number(getScrollTopPosition()) + 150 + 'px';
    } else {
        popup.style.top = (winH / 2 - elemH / 2 + AddTop - 10) + "px";
    }

    popup.style.zIndex = Zindex + 1;

    if (HasBackground) {
        if (!ModalPopup._BackgroundDiv) {
            //			ModalPopup._BackgroundDiv = document.createElement('div');
            //			ModalPopup._BackgroundDiv.style.display = "none";
            //			ModalPopup._BackgroundDiv.style.width = "100%";
            //			ModalPopup._BackgroundDiv.style.position = "absolute";
            //			ModalPopup._BackgroundDiv.style.top = "0px";
            //			ModalPopup._BackgroundDiv.style.left = "0px";
            //			document.body.appendChild(ModalPopup._BackgroundDiv);

            ModalPopup._BackgroundDiv = document.getElementById("PopupBackgroundDiv");
        }
        ModalPopup._BackgroundDiv.onclick = BackgroundOnClick;
        ModalPopup._BackgroundDiv.style.background = BackgroundColor;
        var browser = navigator.appName;
        if (browser.Contains == 'Mozilla Firefox') {
            ModalPopup._BackgroundDiv.style.height = '100%';
        }
        else {
            ModalPopup._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
        }
        
        ModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity + ")";
        ModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
        ModalPopup._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
        ModalPopup._BackgroundDiv.style.zIndex = Zindex;
        ModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;

        ModalPopup._BackgroundDiv.style.display = "";
    }

}

ModalPopup.Close = function(id) {
	showSelectElements(true);
	if (id) {
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";
	} 
	if  (ModalPopup._BackgroundDiv) {
		ModalPopup._BackgroundDiv.style.display = "none";
	}
}

function isIe6()
{
    var bIe6 = false;
    var version = 999; // we assume a sane browser    
    if (navigator.appVersion.indexOf("MSIE") != -1)
    {
        version = parseFloat(navigator.appVersion.split("MSIE")[1]);    
        if(version < 7)
        {
           bIe6 = true;
        }
    }
    return bIe6
}

function showModal(sModalName)
{
    ModalPopup(sModalName);
}
function PopupOpenNewsletter(nID)
{ 	
    NewsletterP = window.open('/NewsLetterPrev.aspx?ID=' + nID, 'Newsletter', 'scrollbars=yes,resizable=yes,menubar=no,toolbar=no,status=yes,width=1024,height=768,top=0,left=0' );
    NewsletterP.focus();
    return;	
}
function getScrollTopPosition()
{
var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0)
    {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
    return ScrollTop;
}
function showSelectElements(bShow)
{
    if(isIe6())
    {
        var items = document.getElementsByTagName('select');
        for(var i=0; i<items.length; i++)
        {
            var oObj = document.getElementById(items[i].id);
            if(oObj)
            {
                if(bShow)
                {
                    oObj.style.display='';
                }else{
                    oObj.style.display='none';
                }
            }
        }        
    }
}