
// IE flicker fix - DPO
$(document).ready(function(){
    try {
      document.execCommand("BackgroundImageCache", false, true);
    } catch(e) {}
});

// attach confirmations to links
$(document).ready(function(){
    if (jQuery("a.delete-link").length > 0) {
        $("a.delete-link").bind("click", function(){
            return confirm("Sunteti sigur ca doriti sa stergeti?");
        });
    }
    
    if (jQuery("a.activate-link").length > 0) {
        $("a.activate-link").bind("click", function(){
            return confirm("Sunteti sigur ca doriti sa activati?");
        });
    }
    
    if (jQuery("a.deactivate-link").length > 0) {
        $("a.deactivate-link").bind("click", function(){
            return confirm("Sunteti sigur ca doriti sa dezactivati?");
        });
    }
});
// overlay div with custom message / html 
function alertDiv (boxTitle, html, show_close) {
    var close_div = "";
    if (typeof show_close == "undefined" || show_close != false) {
        close_div = '<div class="x_inchide"><a href="javascript:void(0);" onclick="$.unblockUI();"><img src="/theme/images/x.gif" alt="Inchide" /></a></div>';
    }
    
    var form = '<div class="pop_login_trans"><div class="pop_login_tabel"><div class="head_pop_up"><strong style="float: left;">'+ boxTitle +'</strong>'+ close_div +'</div><div class="separator_20px"></div>'+ html +'</div></div>';
    
    var width = $(window).width();
    var height = $(window).height();
    var left = parseInt((width - 700) / 2);
    var top = parseInt((height - 500) / 2);
    
    $.blockUI({
        css: { width: "700px", height: "500px", left: left+"px", top: top+"px", cursor: "auto" },
        overlayCSS: { cursor: "auto" },
        message: form
    });
    
    if ($("#autentificate_te").parents("form").find("input:submit").length == 0) {
        $("#autentificate_te").parents("form").append('<div style="width:0;height:0;overflow:hidden;"><input style="width:0;height:0;overflow:hidden;" type="submit" /></div>');
    }
    $("#autentificate_te").click(function(){
        $(this).parents("form").trigger("submit");
        return false;
    });
}

function alertCustomisable (html, show_close) {
        
    var close_div = "";
    if (typeof show_close == "undefined" || show_close != false) {
        close_div = '<div class="x_inchide"><a href="javascript:void(0);" onclick="$.unblockUI();"><img src="/theme/images/x.gif" alt="Inchide" /></a></div>';
    }
    
    var form = html;    
    var width = $(window).width();
    var height = $(window).height();
    var left = parseInt((width - 700) / 2);
    var top = parseInt((height - 500) / 2);
    
    $.blockUI({
        css: { width: "400px", height: "300px", left: left+"px", backgroundColor: '', border: 'none', top: top+"px", cursor: "auto"},
        overlayCSS: { cursor: "auto" },
        message: form
    });
}



function alertLogin (destination_url, show_close) {
    var close_div = "";
    if (typeof show_close == "undefined" || show_close != false) {
        close_div = '<div class="x_inchide"><a href="javascript:void(0);" onclick="$.unblockUI();"><img src="/theme/images/x.gif" alt="Inchide" /></a></div>';
    }
    
    
    if (typeof destination_url != "undefined" && destination_url != "") {
        destination_url = '<input type="hidden" name="destination_url" value="'+ destination_url +'"/>';
    } else {
        destination_url = "";
    }
    
    var form = '<div class="pop_login_trans"><div class="pop_login_tabel"><div class="head_pop_up"><strong style="float: left;">Intra in contul tau</strong>'+ close_div +'</div><div class="separator_20px"></div><div class="separator_60px"></div><p style="margin:0 auto;width:490px;font-size:120%;color:#000;padding:5px;background:#fff2d0;border:1px solid #efbd5e;">Paginamedicala.ro este un site adresat <strong>exclusiv</strong> profesionistilor din domeniul medical.<br/>Pentru a vizualiza aceasta pagina este obligatoriu sa aveti cont.</p><div class="separator_50px"></div><form action="http://www.paginamedicala.ro/utilizator/login/" method="post">'+ destination_url +'<table class="padd_tabel_5px" border="0" style="width:450px;margin:0 auto;"><tr><td width="150" align="right">Utilizator:</td><td colspan="2" align="left"><input type="text" id="pesuname" name="pesuname" maxlength="25" style="width:170px;"/></td></tr><tr><td align="right">Parola:</td><td align="left"><input type="password" id="pesupass" name="pesupass" maxlength="20" style="width:170px;"/></td><td width="150"><a style="padding-top:2px;" href="/utilizator/am-uitat-parola/">Ai uitat parola?</a></td></tr><tr><td align="right">Tine-ma minte</td><td colspan="2" align="left"><input type="checkbox" checked="" value="1" name="remembe_me_status"/></td></tr><tr class="white"><td>&nbsp;</td><td colspan="2"><table><tr><td><a href="javascript:void(0);"  class="formSubmit" id="autentificate_te" >autentifica-te</a></td><td>&nbsp;sau&nbsp;</td><td><a href="/utilizator/ContNou/" id="autentificate_te" >inscrie-te</a></td></tr></table></td></tr></table></form></div></div>';
    
    var width = $(window).width();
    var height = $(window).height();
    var left = parseInt((width - 700) / 2);
    var top = parseInt((height - 500) / 2);
    
    $.blockUI({
        css: { width: "700px", height: "500px", left: left+"px", top: top+"px", cursor: "auto" },
        overlayCSS: { cursor: "auto" },
        message: form
    });
    
    if ($("#autentificate_te").parents("form").find("input:submit").length == 0) {
        $("#autentificate_te").parents("form").append('<div style="width:0;height:0;overflow:hidden;"><input style="width:0;height:0;overflow:hidden;" type="submit" /></div>');
    }
    $("#autentificate_te").click(function(){
        $(this).parents("form").trigger("submit");
        return false;
    });
}


function alertLoginRanking (destination_url, show_close) {
    var close_div = "";
    if (typeof show_close == "undefined" || show_close != false) {
        close_div = '<div class="x_inchide"><a href="javascript:void(0);" onclick="$.unblockUI();"><img src="/theme/images/x.gif" alt="Inchide" /></a></div>';
    }
    
    
    if (typeof destination_url != "undefined" && destination_url != "") {
        destination_url = '<input type="hidden" name="destination_url" value="'+ destination_url +'"/>';
    } else {
        destination_url = "";
    }
    
    var form = '<div class="container" id="slide_1"><div style="z-index: 1001; position: fixed; padding: 0pt; margin: 0pt; width: 700px; text-align: center; color: rgb(0, 0, 0); border: 3px solid rgb(170, 170, 170); background-color: rgb(255, 255, 255); cursor: auto; height: 500px;" class="blockUI blockMsg blockPage"><div class="pop_login_trans"><div class="pop_login_tabel"><div class="head_pop_up"><strong style="float: left;">Intra in contul tau</strong></div><div class="separator_20px"></div><div class="separator_60px"></div><p style="margin: 0pt auto; width: 490px;  color: rgb(0, 0, 0); padding: 5px; background: none repeat scroll 0% 0% rgb(255, 242, 208); border: 1px solid rgb(239, 189, 94);">spitalele pot fi votate exclusiv de catre medici.</p><div class="separator_20px"></div><div class="wid_butoane"><a style="cursor:pointer;" onclick="$(\'#slide_1\').hide();$(\'#slide_2\').show();"><img src="/theme/images/topspitale/medic.gif"  class="float_right" alt="" /></a><a style="cursor:pointer;" onclick="history.back();"><img src="/theme/images/topspitale/non_medic.gif" class="float_left" alt="" /> </a><strong class="float_left" style="margin-left: 31px; margin-top: 20px; display: inline">sau</strong></div><div  style="display: none"><p style="margin: 0pt auto; width: 490px;  color: rgb(0, 0, 0); padding: 5px; background: none repeat scroll 0% 0% rgb(255, 242, 208); border: 1px solid rgb(239, 189, 94);">spitalele pot fi votate exclusiv de catre medici.</p><div class="separator_50px"></div><table border="0" style="width: 450px; margin: 0pt auto;" class="padd_tabel_5px"><tbody><tr><td width="150" align="right">Utilizator:</td><td align="left" colspan="2"><input type="text" style="width: 170px;" maxlength="25" name="pesuname" id="pesuname" /></td></tr><tr><td align="right">Parola:</td><td align="left"><input type="password" style="width: 170px;" maxlength="20" name="pesupass" id="pesupass" /></td><td width="150"><a href="/utilizator/am-uitat-parola/" style="padding-top: 2px;">Ai uitat parola?</a></td></tr><tr><td align="right">Tine-ma minte</td><td align="left" colspan="2"><input type="checkbox" name="remembe_me_status" value="1" checked=""></td></tr><tr class="white"><td>&nbsp;</td><td colspan="2"><table><tbody><tr><td><a id="autentificate_te" href="javascript:void(0);"  class="formSubmit">autentifica-te</a></td><td>&nbsp;sau&nbsp;</td><td><a id="autentificate_te" href="/utilizator/ContNou/">inscrie-te</a></td></tr></tbody></table></td></tr></tbody></table><div style="width: 0pt; height: 0pt; overflow: hidden;"><input type="submit" style="width: 0pt; height: 0pt; overflow: hidden;"></div></div></div></div></div></div><div class="container" id="slide_2" style="display:none;"><div style="z-index: 1001; position: fixed; padding: 0pt; margin: 0pt; width: 700px; text-align: center; color: rgb(0, 0, 0); border: 3px solid rgb(170, 170, 170); background-color: rgb(255, 255, 255); cursor: auto; height: 500px;" class="blockUI blockMsg blockPage"><div class="pop_login_trans"><div class="pop_login_tabel"><div class="head_pop_up"><strong style="float: left;">Intra in contul tau</strong></div><div class="separator_20px"></div><div class="separator_60px"></div><p style="margin: 0pt auto; width: 490px;  color: rgb(0, 0, 0); padding: 5px; background: none repeat scroll 0% 0% rgb(255, 242, 208); border: 1px solid rgb(239, 189, 94);">spitalele pot fi votate exclusiv de catre medici.</p><div class="separator_20px"></div><div class="wid_butoane"><a href=""><img src="/theme/images/topspitale/medic.gif"  class="float_right" alt="" />	</a><a style="cursor:pointer;" onclick="history.back();"><img src="/theme/images/topspitale/non_medic.gif" class="float_left" alt="" /> </a><strong class="float_left" style="margin-left: 31px; margin-top: 20px; display: inline">sau</strong><div class="cont_box_autent_container"><div class="cont_box_autent"></div><div class="cont_box_autent_midd"><div  style="display: "><div class="separator_20px"></div><form method="post" name="formlogin" id="formlogin" action="http://www.paginamedicala.ro/utilizator/login/">'+ destination_url +'<table border="0" style="width: 450px; margin: 0pt auto;" class="padd_tabel_5px"><tbody><tr><td width="150" align="right">Utilizator:</td><td align="left" colspan="2"><input type="text" style="width: 170px;" maxlength="25" name="pesuname" id="pesuname" /></td></tr><tr><td align="right">Parola:</td><td align="left"><input type="password" style="width: 170px;" maxlength="20" name="pesupass" id="pesupass" /></td><td width="150"><a href="/utilizator/am-uitat-parola/" style="padding-top: 2px;">Ai uitat parola?</a></td></tr><tr><td align="right">Tine-ma minte</td><td align="left" colspan="2"><input type="checkbox" name="remembe_me_status" value="1" checked=""></td></tr><tr class="white"><td>&nbsp;</td><td colspan="2"><table><tbody><tr><td><a id="autentificate_te" style="cursor:pointer;" onclick="$(\'#formlogin\').submit();" class="formSubmit">autentifica-te</a></td><td>&nbsp;sau&nbsp;</td><td><a id="autentificate_te" href="/utilizator/ContNou/">inscrie-te</a></td></tr></tbody></table></td></tr></tbody></table><div style="width: 0pt; height: 0pt; overflow: hidden;"><input type="submit" style="width: 0pt; height: 0pt; overflow: hidden;"></div></form></div></div><div class="cont_box_autent_bott"></div></div></div></div></div></div></div>';
    
    var width = $(window).width();
    var height = $(window).height();
    var left = parseInt((width - 700) / 2);
    var top = parseInt((height - 500) / 2);
    
    $.blockUI({
        css: { width: "703px", height: "503px", left: left+"px", top: top+"px", cursor: "auto" },
        overlayCSS: { cursor: "auto" },
        message: form
    });
    
    if ($("#autentificate_te").parents("form").find("input:submit").length == 0) {
        $("#autentificate_te").parents("form").append('<div style="width:0;height:0;overflow:hidden;"><input style="width:0;height:0;overflow:hidden;" type="submit" /></div>');
    }
    $("#autentificate_te").click(function(){
        $(this).parents("form").trigger("submit");
        return false;
    });
}


function mouseOver(id, img) {
	$("#"+ id).attr("src", "/theme/images/butoane/" + img);
}

function mouseOut(id, img) {
	$("#"+ id).attr("src", "/theme/images/butoane/" + img);
}

//from http://techpatterns.com/downloads/javascript_cookies.php
function Set_Cookie( name, value, expires, path, domain, secure ) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    
    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
        
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//

(function($) {
	/**
	 * attaches a character counter to each textarea element in the jQuery object
	 * usage: $("#myTextArea").charCounter(max, settings);
	 */

	$.fn.charCounter = function (max, settings) {		
		
		max = this.attr('maxlength') || 100;
		settings = $.extend({
			container: "<div class='clear_both'></div>",
			classname: "charcounter",
			format: "(%1 caractere ramase)",
			pulse: true,
			delay: 0
		}, settings);
		var p, timeout;

		function count(el, container) {
			el = $(el);
			if (el.val().length > max) {
			    el.val(el.val().substring(0, max));
			    if (settings.pulse && !p) {
			    	pulse(container, true);
			    };
			};
			if (settings.delay > 0) {
				if (timeout) {
					window.clearTimeout(timeout);
				}
				timeout = window.setTimeout(function () {
					container.html(settings.format.replace(/%1/, (max - el.val().length)));
				}, settings.delay);
			} else {
				container.html(settings.format.replace(/%1/, (max - el.val().length)));
			}
		};

		function pulse(el, again) {
			if (p) {
				window.clearTimeout(p);
				p = null;
			};
			el.animate({ opacity: 0.1 }, 100, function () {
				$(this).animate({ opacity: 1.0 }, 100);
			});
			if (again) {
				p = window.setTimeout(function () { pulse(el) }, 200);
			};
		};

		return this.each(function () {
			var container;
			if (!settings.container.match(/^<.+>$/)) {
				// use existing element to hold counter message
				container = $(settings.container);
			} else {
				// append element to hold counter message (clean up old element first)
				$(this).next("." + settings.classname).remove();
				container = $(settings.container)
								.insertAfter(this)
								.addClass(settings.classname);
			}
			$(this)
				.unbind(".charCounter")
				.bind("keydown.charCounter", function () { count(this, container); })
				.bind("keypress.charCounter", function () { count(this, container); })
				.bind("keyup.charCounter", function () { count(this, container); })
				.bind("focus.charCounter", function () { count(this, container); })
				.bind("mouseover.charCounter", function () { count(this, container); })
				.bind("mouseout.charCounter", function () { count(this, container); })
				.bind("paste.charCounter", function () {
					var me = this;
					setTimeout(function () { count(me, container); }, 10);
				});
			if (this.addEventListener) {
				this.addEventListener('input', function () { count(this, container); }, false);
			};
			count(this, container);
		});
	};

})(jQuery);

$(document).ready(function(){	
	$('.textarea_max_chars').each(function(){
		$(this).charCounter($(this).attr('maxlength'));
	});
	
});

