function isValidEmailAddress1(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function forward(url,store,id){
//	var hh = $("#holder").height();
//	var content = 'Forwarding to store\'s website...';
//	if (store!='') content = 'Forwarding to '+store+' website...';
	var my_id = '';
	if (id.indexOf("buylgi_")!=-1) my_id = id.replace("buylgi_","");
	if (id.indexOf("buylg_")!=-1) my_id = id.replace("buylg_","");
	if (id.indexOf("buyi_")!=-1) my_id = id.replace("buyi_","");
	if (id.indexOf("buy_")!=-1) my_id = id.replace("buy_","");
	if (id.indexOf("buyd_")!=-1) my_id = id.replace("buyd_","");
//	$("#fwd_content").html('<p><img src="images/logo.jpg" alt="10OrLess" /></p><p style="text-align:center;">'+content+'</p>');
//	$('#fwd').css("height",hh+"px");
	window.open('/forward.php?store='+encodeURIComponent(store)+'&url='+encodeURIComponent(url));
//	$('#fwd').fadeIn(function(){
		$.get("scripts/scr_recent.php?id="+my_id,function(){
			$.get("scripts/scr_click.php?id="+my_id,function(){
//				var fwt = setTimeout("document.location.href = '"+url+"';",2000);
			});
		});
//	});
}

function loadajaxuploader(){
	for (i=1;i<=5;i++){
		if ($('#poll_upload'+i).length>0){
			new AjaxUpload('#poll_upload'+i, {
				action: 'scripts/scr_lecafe_polls_upload.php',
				name: 'poll_image',
				data: {i:i},
				autoSubmit: true,
				responseType: false,
				onChange: function(file, extension){},
				onSubmit : function(file ,extension){
					is_ajax_upload = 1;
					extension = extension.toLowerCase();
					if (extension && /^(jpg|jpeg)$/.test(extension)){
						// uploading...	
					} else {
						alert('Only .jpg; .jpeg; .jpe files are accepted.\nThank you!.');
						return false;				
					}
			
				},
				onComplete: function(file, response) {
					is_ajax_upload = 0;
					var r = response.split('|');
					if (r[0]==0){
						alert(r[1]);
					}
					else{
						var id = r[1];
						$('#poll_option_image'+id).val(r[0]);
						$('#poll_upload'+id).parent().siblings('.poll_option_left').children('.poll_option_image').children('img').attr('src','uploads/'+r[0]);
						$('#poll_upload'+id).html('+ Change picture');
					}
				}
			});	
		}
	}
}
	
function change_vptd(value,to_parse,add){
	document.location.href = '?p=vouchers'+to_parse+'&ptd='+value+add;
}

function change_vsort(value,to_parse,add){
	document.location.href = '?p=vouchers'+to_parse+'&sort='+value+add;
}

function change_ptd(value,to_parse,add){
	document.location.href = '?p=store'+to_parse+'&ptd='+value+add;
}

function change_sort(value,to_parse,add){
	document.location.href = '?p=store'+to_parse+'&sort='+value+add;
}

var is_ajax_upload = 0;

$(document).ready(function(){
	var is_action = 0;


	$('.rpost_rate a').live('mouseover',function(){
		$(this).nextAll().addClass('rv');
		$(this).prevAll().addClass('rh');
	});

	$('.rpost_rate a').live('mouseout',function(){
		$('.rpost_rate a').removeClass('rv');
		$('.rpost_rate a').removeClass('rh');
	});

	$('#feedback .feedback_ratingh a').live('mouseover',function(){
		$(this).nextAll().addClass('rv');
		$(this).prevAll().addClass('rh');
	});

	$('#feedback .feedback_ratingh a').live('mouseout',function(){
		$('#feedback .feedback_ratingh a').removeClass('rv');
		$('#feedback .feedback_ratingh a').removeClass('rh');
	});

	$('#pdetail_rating_selh a').live('mouseover',function(){
		var rating = $(this).attr('id').replace('rating_','');
		$(this).nextAll().addClass('rv');
		$(this).prevAll().addClass('rh');
	});

	$('#pdetail_rating_selh a').live('mouseout',function(){
		$('#pdetail_rating_selh a').removeClass('rv');
		$('#pdetail_rating_selh a').removeClass('rh');
	});

	$('#pdetail_rating_sel a').live('click',function(){
		var auth = $(this).parent().attr('class').replace('auth_','');
		if (auth==0){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			var prod_id = $('#pdetail_rating_sel').attr('class').replace('prod_','');
			var rank = $(this).attr('id').replace('rating_','');
			$('#pdetail_rating_selh').fadeOut(function(){
				$.post('scripts/scr_rank.php',{id:prod_id,rank:rank},function(){
					$('#pdetail_rating_sel').append('<em>Thank you!</em>');
					$('#pdetail_rating_sel em').css({'display':'none','visibility':'visible'});
					$('#pdetail_rating_sel em').fadeIn(function(){
					
					});
				});
			});
		}
		return false;
	});
	
	$('.rpost_rate a').live('click',function(){
		var auth = $(this).parent().attr('class').replace('rpost_rate auth_','');
		var my_id = $(this).parent().attr('id').replace('rate_','');
		var parent = $(this).parent();
		if (auth==0){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			var rank = $(this).attr('class').replace('rating_','');
			parent.fadeOut(function(){
				parent.children('a').hide();
				parent.show();
				parent.append('<em>Thank you!</em>');
				parent.children('em').css({'display':'none','visibility':'visible'}).fadeIn();

				$.post('scripts/scr_lecafe_blogs_rate.php',{id:my_id,rank:rank},function(){

				});
				
			});
		}
		return false;
	});

	if(window.opera) {
        if ($("a.ico_bookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
            $("a.ico_bookmark").attr("rel","sidebar");
        }
    }

    $("a.ico_bookmark").live('click',function(event){
        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
        var url = this.href;
        var title = this.title;

        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url,"");
        } else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title);
        } else if(window.opera) { // Opera 7+
            return false; // do nothing - the rel="sidebar" should do the trick
        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
             alert('Press "Ctrl + D" or "CMD + D" (Mac), to add this page to your bookmarks.');
        }
    });

	$("#recent_empty").click(function(){
		if (confirm('Are you sure?')){
			return true;
		}
		else{
			return false;
		}
	
	});
	
	$("a.buy").live('click',function(){
		forward($(this).attr("href"),$(this).attr("title"),$(this).attr("id"));
		return false;
	});

	$("div.st_nav1 ul li a").click(function(){
		var page = $(this).attr("title");
		var my_link = $(this);
		var step = 600;
		var action_step = 0;
		if (is_action==0){
			is_action = 1;
			action_step = step*(page-1);
			$('div.prod_small_hc').animate({left:'-'+action_step},300,function(){
				$("div.st_nav1 ul li a").filter(".sel").removeClass("sel");
				my_link.addClass("sel");
				is_action = 0;
			});
			
		}
		return false;
	});

	$("a.ico_share").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("share_","");
			var name = $(this).attr("title");
			var share_form = '<form name="share_form" id="share_form" action="scripts/scr_share.php" method="post"><input type="hidden" name="id" value="'+my_id+'" /><div class="sfi"><label>To</label><div class="sfibg"><input type="text" name="share_to" id="share_to" value="" /></div></div><div class="sfi"><label>From</label><div class="sfibg"><input type="text" id="share_from" name="share_from" value="" /></div></div><div class="sfi"><label>Subject</label><div class="sfibg"><input type="text" id="share_subject" name="share_subject" value="Check out what I found at 10orLess!" /></div></div><div class="sfi" style="height:80px;"><label>Message</label><textarea name="share_message" id="share_message"></textarea></div><div class="btn_share"><a href="#" class="sshare">SUBMIT NOW</a></div></form>';
			tolalert('<h1>Share by email / '+name+'</h1><p id="tol_err">Enter one or more email addresses separated by commas.</p><div class="sh_form">'+share_form+'</div>',0);
			$("a.sshare").click(function(){
				$("#share_form").submit();
				return false;
			});
			$("#share_form").submit(function(){
				var error = 0;
				$("input#share_to").parent().removeClass("err");
				$("input#share_from").parent().removeClass("err");
				$("input#share_subject").parent().removeClass("err");
				if ($("input#share_to").val()==''){
					$("input#share_to").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_from").val()==''){
					$("input#share_from").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_subject").val()==''){
					$("input#share_subject").parent().addClass("err");
					error = 1;
				}
				if (error == 0){
					var my_form = document.share_form;
					var inputs = [];
					$(':input', my_form).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(this.value));
					})  
					jQuery.ajax({
						data: inputs.join('&'),
						url: my_form.action,
						timeout: 2000,
						error: function() {
							$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
							$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
						},
						success: function(r) {
							if (r==1){ 
								$("input#share_to").parent().removeClass("err");
								$("input#share_to").val('');
								$("input#share_from").val('');
								$("input#share_subject").val('Check out what I found at 10orLess!');
								$("textarea#share_message").val('');
								$("#tolalert_icontent p").html("Your message was succesfully sent.");
								$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',2000);

							}
							else{
								if (r==2){ 
									$("input#share_to").parent().addClass("err");
									$("#tolalert_icontent p").html("The email address is invalid.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								}
								else{
									$("input#share_to").val('');
									$("input#share_from").val('');
									$("input#share_subject").val('Check out what I found at 10orLess!');
									$("textarea#share_message").val('');
									$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});							
								}
							}
						}
					})						
				}
				return false; 
			});
		}
		return false;
	});
	
	
	
	$("a.ico_alert").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			alert('Inactive module');
		}
		return false;
	});
	$("a.ico_favourite").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("fav_","");
			var name = $(this).attr("title");
			$.post("scripts/scr_add_favourite.php", { id: my_id },
			  function(data){
			  	if (data=='1'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>Item added to your Favourites</p>',1);
			  	}
			  	if (data=='2'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>This item is already in your Favourites</p>',1);
			  	}
			  	if (data=='0'){
			  		tolalert('<h1>My Favourites / '+name+'</h1><p>Your request could not be processed.<br />Please try again later.</p>',0);
			  	}
			  });
		}
		return false;
	});
	$("a.ico_dfavourite").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
			return false;
		}
		else{
			if (confirm('Are you sure?')){
				return true;
			}
			else{
				return false;
			}
		}
	});
	$("a.ico_wish").live('click',function(){
		if ($(this).hasClass("lreq")){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("wish_","");
			var name = $(this).attr("title");
			$.post("scripts/scr_add_wish.php", { id: my_id },
			  function(data){
			  	if (data=='1'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>Item added to your Wish List</p>',1);
			  	}
			  	if (data=='2'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>This item is already in your Wish List</p>',1);
			  	}
			  	if (data=='0'){
			  		tolalert('<h1>My Wish List / '+name+'</h1><p>Your request could not be processed.<br />Please try again later.</p>',0);
			  	}
			  });
  		}
		return false;
	});

	var showDelay = 500;    
	var hideDelay = 250;    
	var hideTimer = null;  
	var showTimer = null;  
	var container = "";
	var ccontainer = "";
	var is_detail = 0;

	$('div.showdetail').mouseenter(function(){
      	if (hideTimer)  
        	clearTimeout(hideTimer);  
      	if (showTimer)  
        	clearTimeout(showTimer);  
		var my_elem = $(this);

		if (container && ccontainer!=my_elem.children("div.detail_info").html()){
			container.css('display', 'none');  
			container.remove();
			is_detail = 0;
		}
		if (is_detail == 0){
			showTimer = setTimeout(function(){  
				$("#content").append('<div id="detail"><div class="darrow">&nbsp;</div><div id="detail_top">&nbsp;</div><div id="detail_content"><a href="#" class="dclose" href="#">CLOSE</a><div id="detail_icontent">&nbsp;</div></div><div id="detail_bottom">&nbsp;</div></div>');
				container = $("#content").children('#detail');
				container.css({"visibility":"hidden","display":"block"});
				var detail_content = my_elem.children("div.detail_info");
				ccontainer = my_elem.children("div.detail_info").html();
				$("#detail_icontent").html(detail_content.html()); 
		
		
				var pos = my_elem.offset();
				var width = my_elem.width();
				var height = my_elem.height();
				var distance_top = (pos.top-$('body').scrollTop())+24;
				var distance_bottom = ($('body').height()-height-(pos.top-$('body').scrollTop()))+24;
		
				var distance_left = pos.left-$("#content").offset().left;
				var distance_right = $("#content").width()-distance_left-width;
				
				var pos_top = 0;
				var pos_left = 0;
				var fpos = 1;
				container.children("div.darrow").removeClass("dbl");
				container.children("div.darrow").removeClass("dbr");
				container.children("div.darrow").removeClass("dtl");
				container.children("div.darrow").removeClass("dtr");
				if (distance_top>distance_bottom){
					if (distance_left>distance_right){
						fpos = 1;
					}
					else{
						fpos = 2;
					}
				}
				else{
					if (distance_left>distance_right){
						fpos = 4;
					}
					else{
						fpos = 3;
					}
					container.children("div.darrow").addClass("dtl");
					container.children("div.darrow").css("display","block");
				}
				if (fpos==1){ // DONE
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top-container.height()-16;
					pos_left = (pos.left - $("#content").offset().left - container.width()-48)+my_elem.outerWidth()/2;
					container.children("div.darrow").addClass("dbr");
				
				}
				if (fpos==2){ // DONE !
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top-container.height()-16;
					pos_left = (pos.left - $("#content").offset().left)+my_elem.outerWidth()/2+47;
					container.children("div.darrow").addClass("dbl");
				}
				if (fpos==3){ // DONE !
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top+8;
					pos_left = (pos.left - $("#content").offset().left)+my_elem.outerWidth()/2+47;
					container.children("div.darrow").addClass("dtl");
				
				}
				if (fpos==4){ // DONE
					pos_top = pos.top+my_elem.outerHeight()/2-$("#content").offset().top+8;
					pos_left = (pos.left - $("#content").offset().left - container.width()-48)+my_elem.outerWidth()/2;
					container.children("div.darrow").addClass("dtr");		
				}
				container.children("div.darrow").css("display","block");
		
				container.css({  
					left: pos_left + 'px',  
					top: pos_top + 'px'  
				}); 
		
				container.css("z-index","10000");
				container.appendTo("#content");
				container.css({"display":"block","visibility":"visible"});  
				is_detail = 1;
			}, showDelay);  
		}
	});  

	$('div.showdetail').mouseleave(function(){  
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
		hideTimer = setTimeout(function(){  
			if (container){
				container.css('display', 'none');  
				container.remove();  
				is_detail = 0;
			}
		}, hideDelay);  
	});  
	
	// Allow mouse over of details without hiding details  
	$('#detail').live('mouseover', function(){ 
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
	});  
	
	// Hide after mouseout  
	$('#detail').live('mouseout', function(){  
		if (hideTimer)  
			clearTimeout(hideTimer);  
		if (showTimer)  
			clearTimeout(showTimer);  
		hideTimer = setTimeout(function(){  
			if (container){
				container.css('display', 'none');  
				container.remove();
				is_detail = 0;
			}
		}, hideDelay);  
	});  
	$('a.dclose').live('click',function(){
		var a = $(this).parent().parent();
		a.css('display', 'none');
		a.remove();
		is_detail = 0;
		return false;
	});
	$('a.taclose').live('click',function(){
		hide_tolalert();
		return false;
	});
	$('a.fbclose').live('click',function(){
		hide_feedback();
		return false;
	});
	$('a.tabclose').live('click',function(){
		hide_tolalert();
		return false;
	});

	var act_ta = 0;
	function tolalert(message,type){
		if (message!=''){
			var extra = '';
			if (type==0) extra = '<div id="ta_close"><a class="btn_close tabclose" href="#" title="Close">CLOSE</a></div>';
			$('body').append('<div id="tolalerth"><div id="tolalert"><div id="tolalert_top">&nbsp;</div><div id="tolalert_content"><a href="#" class="taclose" href="#">CLOSE</a><div id="tolalert_icontent">'+message+extra+'</div></div><div id="tolalert_bottom">&nbsp;</div></div></div>');
			$('#tolalerth').css({"visibility":"hidden","display":"block"});
			var hh = $(window).height();
			var hw = $(window).width();
			var left_pos = (hw-348)/2;
			var top_pos = ($('body').height()-$('#tolalert').height())/2;
			if (top_pos<0) top_pos = 0;
			if (left_pos<0) left_pos = 0;
			$('#tolalerth').css("width",$("#holder").width()+"px");
			$('#tolalerth').css("height",$("#holder").height()+"px");
			$('#tolalert').css("position","fixed");
			$('#tolalert').css("top",top_pos+"px");
			$('#tolalert').css("left",left_pos+"px");
			$('#tolalerth').css({"display":"none","visibility":"visible"});
			$('#tolalerth').fadeIn(function(){
				act_ta = 1;
				if (type == 1){
					var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',3000);
				}
			});
		}
	}
	
	function show_feedback(){
			var feedback = '<div id="feedbackh">'+
			'<div id="feedback">'+
				'<div id="feedback_top">&nbsp;</div>'+
				'<div id="feedback_content"><a href="#" class="fbclose" href="#">CLOSE</a>'+
					'<div id="feedback_icontent">'+
					'<h1>HELP US <strong>IMPROVE</strong></h1>'+
					'<form name="form_feedback" id="form_feedback" action="scripts/scr_feedback.php" method="post">'+
					'<input type="hidden" name="fb_rating_shopping" id="fb_rating_shopping" value="0" />'+
					'<input type="hidden" name="fb_rating_community" id="fb_rating_community" value="0" />'+
						'<div id="fb_top">'+
							'<p>We’re still new on the block, and we’d love to know how we can make things more helpful and user friendly. Please share your thoughts (good, bad and gushy).</p>'+
							'<div class="sfi"><label>Email</label><div class="sfibg"><input type="text" name="fb_email" id="fb_email" value="" /></div></div>'+
							'<div class="sfi" style="height:80px;margin-bottom:15px;"><label>Comment</label><textarea name="fb_comment" id="fb_comment"></textarea></div>'+
							'<div class="fb_action"><a href="#" class="fb_cancel">Cancel</a><a href="#" class="fb_ok">OK</a> </div>'+
						'</div>'+
						'<div id="fb_bottom">'+
						'<strong>Please rate your experience for (optional)</strong>'+
						'<em>Shopping</em> '+
						'<div class="feedback_rating" id="rating_shopping">'+
							'<div class="feedback_ratingh">'+
							'<a href="#1" class="rating_1">1</a>'+
							'<a href="#2" class="rating_2">2</a>'+
							'<a href="#3" class="rating_3">3</a>'+
							'<a href="#4" class="rating_4">4</a>'+
							'<a href="#5" class="rating_5">5</a>'+
							'</div>'+
						'</div>'+
						'<em>Community</em>'+
						'<div class="feedback_rating" id="rating_community">'+
							'<div class="feedback_ratingh">'+
							'<a href="#1" class="rating_1">1</a>'+
							'<a href="#2" class="rating_2">2</a>'+
							'<a href="#3" class="rating_3">3</a>'+
							'<a href="#4" class="rating_4">4</a>'+
							'<a href="#5" class="rating_5">5</a>'+
							'</div>'+
						'</div>'+
						'<div class="fb_radio clearer">'+
						'Would you recommend us to a friend  <input type="radio" name="fb_friend" style="margin-left:20px;" value="1" />Yes <input name="fb_friend" type="radio" value="0" />No'+
						'</div>'+
						'</div>'+
					'</form>'+
					'</div>'+
				'</div>'+
				'<div id="feedback_bottom">&nbsp;</div>'+
			'</div>'+
		'</div>';
		
		$('body').append(feedback);
		$('#feedbackh').css({"visibility":"hidden","display":"block"});
		var hh = $(window).height();
		var hw = $(window).width();
		var left_pos = (hw-348)/2;
		var top_pos = ($('body').height()-$('#feedback').height())/2;
		if (top_pos<0) top_pos = 0;
		if (left_pos<0) left_pos = 0;
		$('#feedbackh').css("width",$("#holder").width()+"px");
		$('#feedbackh').css("height",$("#holder").height()+"px");
		$('#feedback').css("position","fixed");
		$('#feedback').css("top",top_pos+"px");
		$('#feedback').css("left",left_pos+"px");
		$('#feedbackh').css({"display":"none","visibility":"visible"});
		$('#feedbackh').fadeIn(function(){
			act_ta = 1;
		});
	}

	function hide_tolalert(){
		if (act_ta == 1){
			$('#tolalerth').fadeOut(function(){
				act_ta = 0;
				$('#tolalerth').remove();
			});	
		}
	
	}

	function hide_feedback(){
		if (act_ta == 1){
			$('#feedbackh').fadeOut(function(){
				act_ta = 0;
				$('#feedbackh').remove();
			});	
		}
	
	}
	
	$('#add_poll_option').live('click',function(){
		var count = parseInt($('div.poll_option').size());
		if (count<5){
			var new_count = count+1;
			$('#poll_option_holder').append('<div class="poll_option clearer"><div class="poll_option_left"><div class="poll_option_image"><img src="images/poll.jpg" alt="" /></div></div><div class="poll_option_right"><label>Answer '+new_count+'</label><input type="text" name="poll_option'+new_count+'" id="poll_option'+new_count+'" value="" /><input type="hidden" name="poll_option_image'+new_count+'" id="poll_option_image'+new_count+'" value="" /><a href="#" class="poll_upload" id="poll_upload'+new_count+'">+ Add picture</a>&nbsp;&nbsp;<a href="#" class="remove_poll_option">- Remove option</a></div></div>');
			loadajaxuploader();
		}
		else{
			alert('You can add maximum 5 options.');
		}
		return false;
	});

	$('a.remove_poll_option').live('click',function(){
		var count = parseInt($(this).siblings('input').attr('id').replace('poll_option',''));
		if ($('#poll_option'+(count+1)).length>0){
			alert('Remove the last option first!');
		}
		else{
			$(this).parent().parent().hide().remove();
		}
		return false;
	});
	
	$('#check_expiration').live('click',function(){
		if ($(this).is(':checked')){
			$('#poll_expire').show();
		}
		else{
			$('#poll_expire').hide();		
		}
	});
	if ($('#promo_copy').length>0){
		$('#promo_copy a.more').live('click',function(){
			if ($('#promo_copyfull').is(':visible')){
				$('#promo_copyfull').slideUp();
				$('#promo_copyshort').slideDown();
			}
			else{
				$('#promo_copyfull').slideDown();
				$('#promo_copyshort').slideUp();
			}
			return false;
		});
	}

	$('#btn_feedback a').live('click',function(){
		show_feedback();
		$('#form_feedback').submit(function(){
			var error = 0;
			$("input#fb_email").parent().removeClass("err");
			$("textarea#fb_comment").removeClass("err");
			if (!isValidEmailAddress1($("input#fb_email").val())){
				$("input#fb_email").parent().addClass("err");
				error = 1;
			}
			if ($("textarea#fb_comment").val()==''){
				$("textarea#fb_comment").addClass("err");
				error = 1;
			}
			if (error == 0){
				var my_form = document.form_feedback;
				var inputs = [];
				$(':input', my_form).each(function() {
					inputs.push(this.name + '=' + encodeURIComponent(this.value));
				})  
				jQuery.ajax({
					data: inputs.join('&'),
					url: my_form.action,
					timeout: 2000,
					error: function() {
						hide_feedback();
						tolalert('<h1 style="text-align:center;">HELP US <strong>IMPROVE</strong></h1><p style="text-align:center">Error processing your request.<br />Please try again later.</p>',0);

					},
					success: function(r) {
						hide_feedback();
						if (r==1){ 
							tolalert('<h1 style="text-align:center;">HELP US <strong>IMPROVE</strong></h1><p style="text-align:center"><b>Thank you!</b></p>',1);
						}
						else{
							tolalert('<h1 style="text-align:center;">HELP US <strong>IMPROVE</strong></h1><p style="text-align:center">Error processing your request.<br />Please try again later.</p>',0);
						}
					}
				})						
			}
			return false;
		});
	
		return false;
	});
	
	$('#feedback .fb_cancel').live('click',function(){
		hide_feedback();
		return false;
	});

	$('#feedback .fb_ok').live('click',function(){
		$('#form_feedback').submit();
		return false;
	});
	
	$('#feedback .feedback_rating a').live('click',function(){
		$(this).removeClass('rvs');
		$(this).removeClass('rhs');
		$(this).siblings().removeClass('rvs');
		$(this).siblings().removeClass('rhs');
		$(this).nextAll().addClass('rvs');
		$(this).prevAll().addClass('rhs');
		$(this).addClass('rhs');
		var what = $(this).parent().parent().attr('id');
		var rating = $(this).attr('class').replace(/\D/g,'');
		$('#fb_'+what).val(rating);
		return false;
	});
	
	if ($('#poll_add').length>0){
		loadajaxuploader();
	}	
	
	$('a.admin_delete').live('click',function(){
		if (confirm('Are you sure?')){
			return true;
		}
		else{
			return false;
		}
	});
	
	$('a.ico_pfriend').live('click',function(){
		if ($(this).hasClass('lr')){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);		
		}
		else{
			var my_id = $(this).attr('id').replace('pfriend_','');
			$.post('scripts/scr_lecafe_friend.php',{friend:my_id},function(data){
				window.location.reload();
			});
		}
		return false;
	});
	$('a.ico_pshare').live('click',function(){
		if ($(this).hasClass('lr')){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);		
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("share_","");
			var name = $(this).attr("title");
			var share_form = '<form name="share_form" id="share_form" action="scripts/scr_lecafe_pshare.php" method="post"><input type="hidden" name="id" value="'+my_id+'" /><div class="sfi"><label>To</label><div class="sfibg"><input type="text" name="share_to" id="share_to" value="" /></div></div><div class="sfi"><label>From</label><div class="sfibg"><input type="text" id="share_from" name="share_from" value="" /></div></div><div class="sfi"><label>Subject</label><div class="sfibg"><input type="text" id="share_subject" name="share_subject" value="Check out '+name+'" /></div></div><div class="sfi" style="height:80px;"><label>Message</label><textarea name="share_message" id="share_message"></textarea></div><div class="btn_share"><a href="#" class="sshare">SUBMIT NOW</a></div></form>';
			tolalert('<h1>Share by email / '+name+'</h1><p id="tol_err">Enter one or more email addresses separated by commas.</p><div class="sh_form">'+share_form+'</div>',0);
			$("a.sshare").click(function(){
				$("#share_form").submit();
				return false;
			});
			$("#share_form").submit(function(){
				var error = 0;
				$("input#share_to").parent().removeClass("err");
				$("input#share_from").parent().removeClass("err");
				$("input#share_subject").parent().removeClass("err");
				if ($("input#share_to").val()==''){
					$("input#share_to").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_from").val()==''){
					$("input#share_from").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_subject").val()==''){
					$("input#share_subject").parent().addClass("err");
					error = 1;
				}
				if (error == 0){
					var my_form = document.share_form;
					var inputs = [];
					$(':input', my_form).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(this.value));
					})  
					jQuery.ajax({
						data: inputs.join('&'),
						url: my_form.action,
						timeout: 2000,
						error: function() {
							$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
							$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
						},
						success: function(r) {
							if (r==1){ 
								$("input#share_to").parent().removeClass("err");
								$("input#share_to").val('');
								$("input#share_from").val('');
								$("input#share_subject").val('Check out '+name);
								$("textarea#share_message").val('');
								$("#tolalert_icontent p").html("Your message was succesfully sent.");
								$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',2000);

							}
							else{
								if (r==2){ 
									$("input#share_to").parent().addClass("err");
									$("#tolalert_icontent p").html("The email address is invalid.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								}
								else{
									$("input#share_to").val('');
									$("input#share_from").val('');
									$("input#share_subject").val('Check out '+name);
									$("textarea#share_message").val('');
									$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});							
								}
							}
						}
					})						
				}
				return false; 
			});
		}
		return false;
	});
	$('a.ico_bshare').live('click',function(){
		if ($(this).hasClass('lr')){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);		
		}
		else{
			var id = $(this).attr("id");
			var my_id = id.replace("share_","");
			var name = $(this).attr("title");
			var share_form = '<form name="share_form" id="share_form" action="scripts/scr_lecafe_bshare.php" method="post"><input type="hidden" name="id" value="'+my_id+'" /><div class="sfi"><label>To</label><div class="sfibg"><input type="text" name="share_to" id="share_to" value="" /></div></div><div class="sfi"><label>From</label><div class="sfibg"><input type="text" id="share_from" name="share_from" value="" /></div></div><div class="sfi"><label>Subject</label><div class="sfibg"><input type="text" id="share_subject" name="share_subject" value="Check out '+name+'" /></div></div><div class="sfi" style="height:80px;"><label>Message</label><textarea name="share_message" id="share_message"></textarea></div><div class="btn_share"><a href="#" class="sshare">SUBMIT NOW</a></div></form>';
			tolalert('<h1>Share by email / '+name+'</h1><p id="tol_err">Enter one or more email addresses separated by commas.</p><div class="sh_form">'+share_form+'</div>',0);
			$("a.sshare").click(function(){
				$("#share_form").submit();
				return false;
			});
			$("#share_form").submit(function(){
				var error = 0;
				$("input#share_to").parent().removeClass("err");
				$("input#share_from").parent().removeClass("err");
				$("input#share_subject").parent().removeClass("err");
				if ($("input#share_to").val()==''){
					$("input#share_to").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_from").val()==''){
					$("input#share_from").parent().addClass("err");
					error = 1;
				}
				if ($("input#share_subject").val()==''){
					$("input#share_subject").parent().addClass("err");
					error = 1;
				}
				if (error == 0){
					var my_form = document.share_form;
					var inputs = [];
					$(':input', my_form).each(function() {
						inputs.push(this.name + '=' + encodeURIComponent(this.value));
					})  
					jQuery.ajax({
						data: inputs.join('&'),
						url: my_form.action,
						timeout: 2000,
						error: function() {
							$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
							$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
						},
						success: function(r) {
							if (r==1){ 
								$("input#share_to").parent().removeClass("err");
								$("input#share_to").val('');
								$("input#share_from").val('');
								$("input#share_subject").val('Check out '+name);
								$("textarea#share_message").val('');
								$("#tolalert_icontent p").html("Your message was succesfully sent.");
								$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								var tt = setTimeout('$("#tolalerth").fadeOut(function(){act_ta = 0;});',2000);

							}
							else{
								if (r==2){ 
									$("input#share_to").parent().addClass("err");
									$("#tolalert_icontent p").html("The email address is invalid.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});
								}
								else{
									$("input#share_to").val('');
									$("input#share_from").val('');
									$("input#share_subject").val('Check out '+name);
									$("textarea#share_message").val('');
									$("#tolalert_icontent p").html("Error processing your request. Please try again later.");
									$("#tolalert_icontent p").css({"color":"#fd0374","text-align":"center"});							
								}
							}
						}
					})						
				}
				return false; 
			});
		}
		return false;
	});
	$('a.ico_pblock').live('click',function(){
		if ($(this).hasClass('lr')){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);		
		}
		else{
			var my_id = $(this).attr('id').replace('pblock_','');
			$.post('scripts/scr_lecafe_block.php',{id:my_id},function(data){
				window.location.reload();
			});
		}
		return false;
	});

	$('a.delete_blog').live('click',function(){
		if (confirm('Are you sure ?\nThis action will delete all information related to your blog.\nThe operation is not reversible.')){
			return true;
		}
		else{
			return false;
		}
	});
	
	$("a.lr").live('click',function(){
		tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);
		return false;
	});

	$('a.pdelete').live('click',function(){
		if (confirm('Are you sure you want to delete the photo?')){
			return true;
		}
		else{
			return false;
		}
	});
	
	$('a.cafe_flag').live('click',function(){
		if ($(this).hasClass('lr')){
			tolalert('<h1>Login required</h1><p>In order to access this feature of our website you need to login with your username and password.<br />Click <a href="login.html">here</a> to login or go to the <a href="register.html">register page</a> to register for an account.</p>',0);		
		}
		else{
			if (confirm('Are you sure?\nA message will be sent to the administrator of the site.')){
				var flag = $(this).attr('id');
				$.post('scripts/scr_lecafe_flag.php',{flag:flag},function(){
					tolalert('<h1>Flag article</h1><p>Message sent succesfully.<br />Thank you!</p>',1);
				});
			}
		}
		return false;
	});
	
	$('a.ico_bfeature').live('click',function(){
		if (confirm('Are you sure?')){
			var my_id = $(this).attr('id').replace('feature_','');
			$.post('scripts/scr_lecafe_blogs_feature.php',{id:my_id},function(){
				window.location.reload();			
			});
		}
		return false;
	});
	
	$('#menu_cm li').mouseenter(function(){
		$(this).children('.menu_csm').show();
		$(this).addClass('selm');
	});
	$('#menu_cm li').mouseleave(function(){
		$(this).children('.menu_csm').hide();
		$(this).removeClass('selm');
	});
});