	function createCookie(name,value,days,hours) {
		//if (days>0) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000)+(hours*60*60*1000));
			var expires = "; expires="+date.toLocaleString();
		//}
		//	else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}
	function findObject(theObj, theDoc) {
	  var p, i, foundObj;

	  if(!theDoc) theDoc = document;
	  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	  {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	  }
	  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	  for (i=0; !foundObj && i < theDoc.forms.length; i++)
		foundObj = theDoc.forms[i][theObj];
	  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
		foundObj = findObj(theObj,theDoc.layers[i].document);
	  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

	  return foundObj;
	}

    //define functions for showing most viewed objects
    function asignCssClass(tab_name) {
		var e1 = findObject(tab_name);
		var e2 = null;
        if (tab_name == 'tab_today') {
            e2 = findObject('tab_last7days');
        } else {
            e2 = findObject('tab_today');
        }
		e1.className = 'most_viewed_tab';
        e2.className = 'most_viewed_tab not_selected';
    }

	function asignCssClassEv(tab_name) {
        var e1 = findObject(tab_name);
		var e2 = null;
        if (tab_name == 'tab_ultimele_adaugate') {
            e2 = findObject('tab_top_vizualizari');
        } else {
            e2 = findObject('tab_ultimele_adaugate');
        }
		e1.className = 'most_viewed_tab';
        e2.className = 'most_viewed_tab not_selected';
    }

    function mostViewedObjDisplay(objDispType, ajx_path){
        //display the loading animated gif
        $("#most_viewed_updating").css('display', 'block');

        $.post(_QBOX_WEB_ROOT + ajx_path, {obj_most_viewed_type: objDispType}, function(resp_data){
            mostViewedObjDisplayHandler(resp_data);
        });

	}

	function mostViewedObjDisplayHandler(resp_data) {
		var ldiv = $('#div_most_viewed_listing');

        //hide updating animation
        $("#most_viewed_updating").css('display', 'none');

        //update content
        if(typeof(resp_data) == 'string'){
            ldiv.html(resp_data);
        }
        else{
            ldiv.html( resp_data['html'] );

            //evaluate the eventual js code send from ajax as a response
            if(typeof(resp_data['js_code']) != 'undefined'){
                eval(resp_data['js_code']);
            }
        }
	}

    function displayClientMenu(){
        //var x = findObject('client_menu');//nu merge pe IE8!!!
        x = document.getElementById('client_menu');
        if(x) x.style.visibility ='visible';
    }

    function hideClientMenu(){
        //var x = findObject('client_menu'); //nu merge pe IE8!!!
        x = document.getElementById('client_menu');
        if(x) x.style.visibility ='hidden';
    }

    function toggleClientMenu(){
        //var x = findObject('client_menu'); //nu merge pe IE8!!!
        x = document.getElementById('client_menu');
        if(x){
            if(x.style.visibility == 'hidden' || x.style.visibility == ''){
                x.style.visibility ='visible';
            }
            else{
                x.style.visibility='hidden';
            }
        }
    }

    //17 Noi 2011 15:36 Cipri: functionality for switching tabs v3
    function changeTab(tabid, bgcolor){
        //compute the color of my idle tabs
        var idle_color = 'idle_';
        if((typeof bgcolor != 'undefined') && bgcolor != ''){
            idle_color += bgcolor
        }
        else{
            idle_color += 'green';
        }

        //get all the tabs
        var tabs = $('#'+tabid).parent('div').children('div');
        for(var i=0; i<tabs.length;i++){
            var x_tabid = $(tabs[i]).attr('id');
            if(x_tabid == tabid){
                $('#'+x_tabid).removeClass(idle_color).addClass('selected');
            }
            else{
                $('#'+x_tabid).removeClass('selected').addClass(idle_color);
            }
        }
    }

    //16 Nov 2010 15:01:15 - Cipri: add a functionality so I can call the onload for multiple functions
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }


    /*Modal box*/
    function show_modal_box() {
        //Openup my fancybox here
        $('#inline').trigger('click');
    }
    function hide_modal_box() {
        //close my fancybox
        $.fancybox.close();
    }

    //Abonare la newsletter (apelabil din diferite locatii din site)
    function do_abonare_newsletter() {
        // get the ajax parameters
        var daemail = $('#aboneaza_email').val();
        if (validateAboneazaEmail(daemail)) {
            //make an ajaxRequest
            $.post(_QBOX_WEB_ROOT+"users/ajx_user_abonare_newsletter_form.php", {aboneaza_email: daemail}, function(resp_data){
                //show notification in my modal window
                modalHandlerText(resp_data);

                //show modal window with my response
                show_modal_box();
            });
        }
        return false;
    }

    function do_footer_abonare_newsletter() {
        // get the ajax parameters
        var daemail = $('#subscribe_email').val();
        if (validateAboneazaEmail(daemail)) {
            //make an ajaxRequest
            $.post(_QBOX_WEB_ROOT+"users/ajx_user_abonare_newsletter_form.php", {aboneaza_email: daemail}, function(resp_data){
                //show notification in my modal window
                modalHandlerText(resp_data);

                //show modal window with my response
                show_modal_box();
            });
        }
        return false;
    }

    function modalHandlerText(resp_data){
        $('#modal_box').html(resp_data);
    }


    //global function for grabing data into a TABULAR infobox
    // canvas_content_id = ID of the div that will hold the response
    // url = relative path where the request goes, without leading / (ex: ajx_vocea_orasului.php)
    // params = if I need to send any params into my request (ex: 'id:1234;code:"bombonica"')
    function loadTabContent(canvas_content_id, url, params){
        //display the loading animated gif
        if($('#'+canvas_content_id+'_updating').length) $('#'+canvas_content_id+'_updating').css('display', 'block');
        var req_params = '{}';
        if(typeof(params) == 'object'){
            req_params = params;
        }
        else if(typeof(params) == 'string' && params != ''){
            //{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}
            req_params = eval('(' + params + ')');
            //alert(req_params);
        }

        $.post(_QBOX_WEB_ROOT + url, req_params, function(resp_data){
            //show response content into my given canvas
            ajxResponseHandler(resp_data, $('#'+canvas_content_id));

            //stop the loading icon
            if($('#'+canvas_content_id+'_updating').length) $('#'+canvas_content_id+'_updating').css('display', 'none');
        });
    }

    //resp_data = json encode or regular html data
    //ldiv - is a jQuery object here!
    function ajxResponseHandler(resp_data, ldiv){
        //evaluate the eventual js code send from ajax as a response
        //var myResp = eval('(' + resp_data + ')');
        var html_data = '';
        var resp_is_obj = 0;
        if(resp_data.length && typeof(resp_data) !== 'undefined'){
            var myResp = '';
            if(typeof(resp_data) == 'string'){

                //alert(resp_data);
                //test if my return is an JSON encoded string
                if(resp_data.search(/\{/) >= 0){
                    myResp = eval('(' + resp_data + ')');
                    resp_is_obj = 1;
                }
                else{
                    myResp = eval(resp_data);
                }

                if(myResp && typeof(myResp['html']) !== 'undefined'){
                    html_data = myResp['html'];
                }
                else{
                    html_data = myResp;
                }
            }
            
            //evaluate the JS code after updateting the content of my div
            if(resp_is_obj && myResp && typeof(myResp['js_code']) !== 'undefined'){
                eval(myResp['js_code']);
            }
        }

        //update content of my div with received data
        ldiv.html(html_data);
    }

    function checkEmail(inputvalue){
        var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        if (pattern.test(inputvalue)) {
            return true;
        } else {
            return false;
        }
    }

    function validateAboneazaEmail(da_email) {
        if (da_email.length <= 0) {
            alert("Nu ati introdus adresa de email.");
            return false;
        }
        // validate valid email
        if (!checkEmail(da_email)) {
            alert("Adresa de email introdusa nu are un format valid. Verificati daca este corecta.");
            return false;
        }
        return true;
    }



