function popup(url, target, width, height, features)
{
    var features1 = 'width=' + width + ',height=' + height;
    if (screen) {
        features1 += ',left=' + (screen.width - width) / 2 +
                ',top=' + (screen.height - height) /2;
    }
    if (features) {
        features1 += ',' + features;
    }

    wnd = window.open(url, target, features1);
    wnd.focus();

    return wnd;
}


function openURLInPopup(url, width, height)
{
    if (typeof(width) == "undefined") {
        width = 800;
        height = 600;
    }

    if (typeof(height) == "undefined") {
        height = 600;
    }

    popup(url, 'slideShow', width, height, 'menubar=0,location=0,toolbar=0,status=0,scrollbars=1');
}

function trailer(filename, w, h)
{
    url = "/flvplayer.php?filename=" + filename;
    wnd = popup(url, "Trailer", w + 30, h + 100, "menubar=0,location=0,toolbar=0,status=0,scrollbars=0,resizable=0");
    wnd.focus();
}

function validate(action, formName)
{
    if (formName == undefined) {
        formName = "form1";

    }

    document.forms[formName].elements["action"].value = action;
    document.forms[formName].submit();
}

function BoxOffice_jumpmenu(target, script_name, restore)
{
    str = target + ".location='" + script_name + ".php'";
    eval(str);

    if (restore)
        selObj.selectedIndex = 0;
}


function openURLInNewPage(url, target)
{
    myWidth = 800;
    myHeight = 600;

    if( typeof( window.innerWidth ) == 'number' ) {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement &&
            ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }

    if (typeof(target) == 'undefined') {
        target = 'newpage_' + Math.floor(Math.random() * 1000000000);
    }

    var features = 'width=' + myWidth + ',height=' + myHeight;
    features += 'menubar=1,location=1,toolbar=1,status=1,scrollbars=1';
    var wnd = window.open(url, target, features);
    wnd.focus();
    return;
}


var dateFromatISORegexp = /(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
var dateFromatISO = 'Y-m-d H:i:s';

// Simulates PHP's date function
Date.prototype.format = function(format) {
    var returnStr = '';
    var replace = Date.replaceChars;
    for (var i = 0; i < format.length; i++) {
        var curChar = format.charAt(i);
        if (replace[curChar])
        returnStr += replace[curChar].call(this);
    else
        returnStr += curChar;
    }
    return returnStr;
};

Date.replaceChars = {
    shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],

    // Day
    d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
    D: function() { return Date.replace.shortDays[this.getDay()]; },
    j: function() { return this.getDate(); },
    l: function() { return Date.replace.longDays[this.getDay()]; },
    N: function() { return this.getDay() + 1; },
    S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 13 && this.getDate() != 1 ? 'rd' : 'th'))); },
    w: function() { return this.getDay(); },
    z: function() { return "Not Yet Supported"; },

    // Week
    W: function() { return "Not Yet Supported"; },

    // Month
    F: function() { return Date.replace.longMonths[this.getMonth()]; },
    m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },
    M: function() { return Date.replace.shortMonths[this.getMonth()]; },
    n: function() { return this.getMonth() + 1; },
    t: function() { return "Not Yet Supported"; },

    // Year
    L: function() { return "Not Yet Supported"; },
    o: function() { return "Not Supported"; },
    Y: function() { return this.getFullYear(); },
    y: function() { return ('' + this.getFullYear()).substr(2); },
    // Time

    a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
    A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
    B: function() { return "Not Yet Supported"; },
    g: function() { return this.getHours() === 0 ? 12 : (this.getHours() > 12 ? this.getHours() - 12 : this.getHours()); },
    G: function() { return this.getHours(); },
    h: function() { return (this.getHours() < 10 || (12 < this.getHours() < 22) ? '0' : '') + (this.getHours() < 10 ? this.getHours() + 1 : this.getHours() - 12); },
    H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
    i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
    s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },

    // Timezone
    e: function() { return "Not Yet Supported"; },
    I: function() { return "Not Supported"; },
    O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
    T: function() { return "Not Yet Supported"; },
    Z: function() { return this.getTimezoneOffset() * 60; },

    // Full Date/Time
    c: function() { return "Not Yet Supported"; },
    r: function() { return this.toString(); },
    U: function() { return this.getTime() / 1000; }
};


/**
 * Remote script include
 */
if (! window._globals) {
    window._globals = $A([]);
}
window._globals._includedExternals = $A([]);

ScriptInclude = new Class.create({
    includeOnce: false,
    callback: Prototype.emptyFunction(),

    initialize: function (sources, callback) {
        this.callback = typeof(callback) != 'function' ? Prototype.emptyFunction() : callback;
        this.sources = $A((typeof(sources) == 'string' ? [sources] : sources));

        if (this.includeOnce === true) {
            this.sources = this.sources.findAll(function (item) {
                return (window._globals._includedExternals.indexOf(item) == -1);
            });
        }

        if (this.sources.size() === 0 && typeof(this.callback) == 'function') {
            this.callback();
        }

        this.sources.each(function (script) {
            this.includeScript(script);
        }.bind(this));
    },

    _includeElement : function(url) {
        return new Element('script', {language: 'javascript', type: 'text/javascript', src: url});
    },

    includeScript: function(script) {
        if (! this.includeOnce) {
            script += (script.indexOf('?') == -1 ? '?' : '&') + 'ts=' + new Date().getTime();
        }

        var htmlDoc = $$('head').shift();
        var aElement = this._includeElement(script);

        htmlDoc.appendChild(aElement);
        if (document.addEventListener) {
            if (Prototype.Browser.WebKit || Prototype.Browser.Opera) {
                var iframe = new Element('iframe', {src: script}).setStyle({display: 'none'});
                $$('body').shift().insert(iframe);
                Event.observe(iframe, 'load', this.scriptOnLoad.bind(this, script));
            } else {
                Event.observe(aElement, 'load', this.scriptOnLoad.bind(this, script));
            }
        } else {
            aElement.onreadystatechange = function() {
                if (aElement.readyState == 'complete' || aElement.readyState == 'loaded') {
                    aElement.onreadystatechange = null;
                    this.scriptOnLoad(script);
                }
            }.bind(this);
        }
    },

    scriptOnLoad: function (script) {
        window._globals._includedExternals.push(script);
        this.sources[this.sources.indexOf(script)] = null;
        this.sources = this.sources.compact();

        if (this.sources.size() === 0 && typeof(this.callback) == 'function') {
            this.callback();
        }
    }
});

ScriptIncludeOnce = new Class.create(ScriptInclude, {includeOnce: true });

StyleInclude = new Class.create(ScriptInclude, {
    includeOnce: true,
    _includeElement : function(url) {
        return new Element('link', {id:'titi', rel: 'stylesheet', type: 'text/css', href: url});
    }
});

function clear_fld(fld_id, fld_def_value)
{
    var def_value = $(fld_id).value.toLowerCase();
    var fld_def_value = fld_def_value.toLowerCase();
    if (def_value == fld_def_value) {
        $(fld_id).value = "";
    }
}
function go_to_name()
{
    var url = 'http://www.eva.ro/familie/jurnal-de-mamica/nume-pentru-bebe-articol-7083.html';
    var gender = $('gender').options[$('gender').selectedIndex].value;
    var ini = $('ini').options[$('ini').selectedIndex].value.toLowerCase();
    var anch = gender+ini;
    var to_url = url+"#"+anch;
    window.location.href = to_url;
}

function getPageSize() {
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;


}

function getPageScroll () {
    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;

    }

   arrayPageScroll = new Array('',yScroll)

   return arrayPageScroll;

}

function chfkbx(i)
{
    var h_img_id = "bg"+i;
    var ttl_id = "title"+i;
    var href_id = "href"+i;
    
    $("bg_container").style.backgroundImage = 'url('+BoxColaj[h_img_id]+')';
    last_url = BoxColaj[href_id];

}

function chfkbxtops(i)
{
    var h_img_id = "bg"+i;
    var ttl_id = "title"+i;
    var href_id = "href"+i;

    var bs_id = "bs"+i;
    for (var j=1; j <=4 ; j++) {
        var a_id = "a"+j;
        if (j == i) {
            $(a_id).className = 'selected';
        } else {
            $(a_id).className = '';
        }
    }
    $("background_image").src   =BoxColaj[h_img_id];
    $("background_image").alt   =BoxColaj[ttl_id];
    $("background_image").title =BoxColaj[ttl_id];
    $("article_url").href       = BoxColaj[href_id];
}






function set_selected(id)
{
    switch (id){
    case "a_r_articles":
        $("r_articles").style.display="block";
        $("c_articles").style.display="none";
        $("l_r_articles").className="active";
        $("l_c_articles").className="last";

        break;
    case "a_c_articles":
        $("c_articles").style.display="block";
        $("r_articles").style.display="none";
        $("l_r_articles").className="";
        $("l_c_articles").className="last active";

        break;
    }

}

function set_selected2(id)
{
    var ids = new Array('news', 'horoscop', 'timp_liber', 'lumea_cafelei');
    for (i=0; i<ids.length; i++) {

        var li = "l_"+ids[i];
        var div = "i_"+ids[i];
        if (id == ids[i]) {
            $(li).className      = i == 0 ? 'selected first' : 'selected';
            $(div).style.display = 'block';
        } else {
            if (i == 0) {
                 $(li).className      = 'first';
            } else {
                $(li).className      = '';
            }
            $(div).style.display = 'none';
        }
    }
}


function set_contest(href, image_id)
{
    $("details").innerHTML = $(image_id).title;
    $("details").href = href;
    var images = $("c_ul").getElementsByTagName("img");
    for (var i=0; i<images.length; i++) {
        var sel = $(images[i]).id;
        var li = sel.replace("img","li");
        if (sel == image_id) {
            $(li).className = "selected";
        } else {
            $(li).className = "";
        }
    }
    //alert(images);
}

function search_focus()
{
    var v = $("search_box").value;
    $("last_search").value = v;

    $("search_box").value = "";
}

function search_blur()
{
    var v = $("search_box").value;
    if (v == "") {
        $("search_box").value = $("last_search").value;
    }
}




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 addslashes(str) {
    str=str.replace(/\'/g,'\\\'');
    str=str.replace(/\"/g,'\\"');
    str=str.replace(/\\/g,'\\\\');
    str=str.replace(/\0/g,'\\0');
    return str;
}

function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\\\/g,'\\');
    str=str.replace(/\\0/g,'\0');
    return str;
}

function serviceHttp_request(service, container, other_params)
{
    $(container).innerHTML = "<div class=\"holder\"></div><div class=\"btm_holder\"></div>";
    var container_id = service+"_container";
    var c_html = $(container_id).innerHTML;
    if (c_html.length && ! other_params) {
        $(container).innerHTML = c_html;
        return false;
    }
    var ajaxRequest = new Ajax.Request(
        "/service_get.php", { method: 'post', parameters: 'action='+service + (other_params ? '&'+other_params: ''), evalScripts: true,
        onLoading:function(request){
            show_loader(container);

        },

        onComplete: function(response){
            //var container_id = service+"_container";

            $(container_id).innerHTML = response.responseText;
            $(container).innerHTML = "";
            $(container).innerHTML = response.responseText;
        }});

}

function show_loader(container)
{
    if ($(container.innerHTML != "")) {
        $(container).innerHTML = "<div class=\"holder\"><div style='position:relative'><img src='"+CFG.img_base_url+"/loader.gif' style='position:absolute;top:63px; left:124px;'></div></div><div class=\"btm_holder\"></div>";
    } else {
        return false;
    }
}

function all_signs_show()
{
    $('sign').hide();
    $('all_signs').show();
}

function all_signs_hide()
{
    $('all_signs').hide();
    $('sign').show();

}

function to_s_pos(pos)
{
    var ajaxRequest = new Ajax.Request(
        "/service_get.php", { method: 'post', parameters: 'action=specialist&pos='+pos, evalScripts: true,

        onComplete: function(response){
            $('index_question').innerHTML = response.responseText;
        }});
}

/**
 * !!!DO NOT DELETE THIS!!!
 * IMPLEMENTS CUSTOM MOUSEENTER AND MOUSELEAVE EVENTS SPECIFIC TO IE ON ALL BROWSERS
 *
 * USE: Element.observe('custom:mouseenter', function(event){ console.log(Element); })
 */

(function(){
    function firstCommonAncestor(elm1, elm2){
        var p = elm1.up();
        while( !elm2.descendantOf(p) ){
            p = p.up();
        }
        return p;
    }
    function stopEvent(e){
        try{
            e.stop();
        }catch(ex){}
    }
    Event.observe(document, 'mouseout', function(e){
        var from = e.element();
        var to = e.relatedTarget;
        p = null;
        if ( !to || (from !== to && !to.descendantOf(from))) {
            /* mouseleave should bubble up until the to element because we have left all elements up to that one */
            var stopOn = null;
            if( to ){
                if( from.descendantOf(to) ){
                    stopOn = to.childElements();
                }else{
                    p = firstCommonAncestor(from, to);
                    if( p && to.descendantOf(p) ){
                        stopOn = p.childElements();
                    }
                }
            }
            if( stopOn ){
                stopOn.invoke('observe', 'custom:mouseleave', stopEvent);
            }
            from.fire('custom:mouseleave');
            if( stopOn ){
                stopOn.invoke('stopObserving', 'custom:mouseleave', stopEvent);
            }
        }
        var p = null;
        if( to && !from.descendantOf(to)){
            /* mouseenter can bubble, no problem! */
            var stopOn = null;
            if( to.descendantOf(from)){
                stopOn = from.childElements();
            }else{
                // do first common ancestor's children, see below.
                p = firstCommonAncestor(to, from);
                stopOn = p.childElements();
            }
            if( stopOn ){
                stopOn.invoke('observe', 'custom:mouseenter', stopEvent);
            }
            to.fire('custom:mouseenter');
            if( stopOn ){
                stopOn.invoke('stopObserving', 'custom:mouseenter', stopEvent);
            }
        }
    });
})();




function dropDownMenu(container, starter) {
    var to = null;

    try{
    var containerObj = $(container);
    } catch(e){

    }
    if (! containerObj) {
        return false;
    }

    function showDropdown() {
        var dim = $(starter).getDimensions();

        var ofst = $(starter).cumulativeOffset();
        var top = ofst.top + dim.height;
        var left = ofst.top + dim.height;
        //containerObj.setStyle({top: (ofst.top + dim.height) + 'px', left: ofst.left + 'px'}).show();
        containerObj.style.display = 'block';

    }
    function hideDropdown() {
        containerObj.hide();

    }

    var clearTo = (function(to) {
        return function() {
        to = clearTimeout(to);
        }
    })(to);
    $(starter).observe('mouseover', function (event) {
       var p = event.fromElement || event.relatedTarget;
        while (p && p != containerObj) { try { p = p.parentNode; } catch (e) { p = element; } }
        if (p == containerObj) {return false;}
        clearTo();
    });
    $(starter).observe('click', function(event) {event.stop()});
    $(starter).hoverIntent(function(event) {
        clearTo();
        showDropdown();
    }, function(event) {
        clearTo();
        to = hideDropdown.delay(0.1);
    }, {timeout: 100});

    containerObj.observe('mouseover', function(event) {
        var p = event.fromElement || event.relatedTarget;
        while (p && p != containerObj) { try { p = p.parentNode; } catch (e) { p = element; } }
        if (p == containerObj) {return false;}
        $(starter).hoverTimer = clearTimeout($(starter).hoverTimer);
        $(starter).isHovering = false;
        clearTimeout(to);
    });
    containerObj.observe('mouseout', function(event) {
        var p = event.toElement || event.relatedTarget;
        while (p && p != containerObj) { try { p = p.parentNode; } catch (e) { p = element; } }
        if (p == containerObj) {return false;}
        clearTo();
        to = hideDropdown.delay(0.15);
    });

}

var modal = new Object();

function open_modal(url, back, w, h, msg, msg_type)
{
    document.domain = 'eva.ro';
    var url = url ? url : CFG.club_base_url+"/login_modal.php";
    url  = url+"?ref="+encodeURIComponent(window.location);
    url = back ? url + "&back="+back : url;
    url = msg ? url + "&message="+msg  : url;
    url = msg_type ? url + "&message_type="+msg_type : url;


    var w = w ? w : 615;
    var h = h ? h : 360;
    
    modal = new Control.Modal(false,{
        width:w,
        height:h,
        href:url,
        iframe:true,
        opacity: 0.5,
        overlayCloseOnClick : false,
        iframeTemplate: new Template('<iframe src="'+url+'" width="'+w+'" height="'+h+'" frameborder="0" id="modal_iframe"></iframe>')
			
    });
    
    modal.open();
}

function close_modal(reload)
{
    modal.close();
    if (reload) {
        window.location.reload();
    }
}

var myFusion = {
    onAvatarLoad : function(url, back, w, h, msg, msg_type, taget_obj){
        alert(back);
        myFusion.openModal(url, back, w, h, msg, msg_type, target_obj);

    
        
    },

    onAvatarClose : function()
    {
        alert (this.c);
    },

    openModal : function(url, back, w, h, msg, msg_type)
    {
        alert('ccc');
        document.domain = 'eva.ro';
        var url = url ? url : CFG.club_base_url+"/login_modal.php";
        url  = url+"?ref="+encodeURIComponent(window.location);
        url = back ? url + "&back="+back : url;
        url = msg ? url + "&message="+msg  : url;
        url = msg_type ? url + "&message_type="+msg_type : url;


        var w = w ? w : 615;
        var h = h ? h : 360;
    
        this.modal = new Control.Modal(false,{
            width:w,
            height:h,
            href:url,
            iframe:true,
            opacity: 0.5,
            overlayCloseOnClick : false,
            iframeTemplate: new Template('<iframe src="'+url+'" width="'+w+'" height="'+h+'" frameborder="0" id="modal_iframe"></iframe>')
			
        });
        alert(this.modal); 
        this.modal.open();
    
    
    }

    

};


