function loader_toggle(element_id, show_flag) {
	loader_id = element_id+"_loader"
	
	
	if(!$('#'+loader_id).length) {
		$('#'+element_id).append("<img id='"+loader_id+"' src='images/loader.gif' border='0' style='display:none'>");
	}
	
	if(show_flag) {
		$('#'+loader_id).show();
	} else {
		$('#'+loader_id).hide();
	}
	
}

function isValidEmailAddress(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 play_video(video_id) {
	window.location = 'video.php?id=' + video_id;
}

function stop_animated(use_this) {
	$(use_this).attr('animated',0);
	$(use_this).attr('src',$(use_this).attr('original_src'));
	clearTimeout(t);
	
}

function show_animated(use_this) {
	
	tcount = $(use_this).attr('tcount');
	guid = $(use_this).attr('guid');
	
	if(tcount > 1 && $(use_this).attr('animated') == 0) {
		$(use_this).attr('animated',1);
		disp_img(1, guid, tcount, use_this);
	
	}
}
c = 1;
use_this = '';
tcount = '';
guid = '';
t = '';
function disp_img(c, guid, tcount, use_this) {
	new_this = use_this;
	if($(new_this).attr('animated') == 0) {
		return;
	}
   var img_src = 'thumbnails/'+guid+"_thumbnail_0" + c + ".jpg";
   //alert(c + ' | ' + tcount + ' | ' + guid + ' | ' + img_src + ' | ' + use_this);
   $(use_this).attr('src',img_src);
   
   if (c == tcount - 1) {
      c = 0;
   }   
   counter = c + 1;
   
   
   if($(new_this).attr('animated') == 1) {
   	t = setTimeout("disp_img(counter, guid, tcount, new_this)", 500);
	}
}



function check_alerts() {
		$.ajax({
			type: "POST",
			url: "ajax.php?cmd=get_alerts",
			cache: false,
			dataType: "xml",
			error: function() {
			},
			success: function(xml) {
				$(xml).find('alert').each(function(){
					//$('CategoryID',this).text();
					//$('CategoryName',this).text();
					alert_msg = $('alert_msg',this).text();
					//alert(alert_msg);
		                jQuery.noticeAdd({
		                        text: alert_msg,
		                        stay: true
		                });
				});
				setTimeout(check_alerts,30000);
				/*
				loader_toggle('submit_status', false);
				
				if($('main_response',xml).text() == '0') {
					$('#submit_status').html("<span class='error'>"+$('main_response',xml).text()+"</span>");
					
				} else {
					$('#submit_status').html("<span class='success'>Success! Redirecting you to the member's page...</span>");
					loader_toggle('submit_status', true);
					
					window.location = 'register_confirm.php';
					
				}
				*/
			}
			
		});
}

