var b_version = "na";
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=3)
  b_version=("FF3")
 else
  b_version=("FF2")
} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=8)
  b_version=("IE8")
 else if (version>=7)
  b_version=("IE7")
 else
  b_version=("IE6")
} else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=10)
  b_version=("Opera10")
 else
  b_version=("Opera9")
} else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var version=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (version>=530)
  b_version=("Safari4")
 else
  b_version=("Safari3")
}


$(document).ready(function(){
						   /*
	jQuery.fn.setup_menu = function(menu_selected, quick) {
		var this_menu = menu_selected;
		this_menu.parent().parent().find("ul").each(function(i) {
			if (quick) {
				$(this).filter(":visible").hide();
			} else {
				$(this).filter(":visible").hide();
			}
		});
		this_menu.parent().parent().find("h3").each(function(i) {
			$(this).removeClass().addClass('menu_off');
		});
		this_menu.parent().parent().find("a").each(function(i) {
			$(this).removeClass().addClass('link_off');
		});
		//alert($(this).parent().find("ul").eq(0).is(":hidden"));
		if (this_menu.parent().find("ul").eq(0).is(":hidden")) {
			this_menu.removeClass().addClass('menu_on');
		} else {
			//this_menu.removeClass().addClass('menu_off');
		}
		if (quick) {
			this_menu.parent().find("ul").eq(0).filter(":hidden").show();
		} else {
			this_menu.parent().find("ul").eq(0).show();
		}
	};
	
	jQuery.fn.press_menu = function() {
		jQuery.fn.setup_menu($(this),false);
	}
	jQuery.fn.reset_menu = function() {
		for (var i=0; i<nav_array.length; i++) {
			//$('#'+nav_array[i]).addClass('selected');
			//$('#'+nav_array[i]).each(function(i) {
				//jQuery.fn.setup_menu($(this),true);
				$('#'+nav_array[i]).addClass('link_on');
				$('#'+nav_array[i]).parent().find("ul").eq(0).show();
			//});
		}
	}
	 
	$('#mainmenu ul ul').hide();
	//$('#mainmenu ul h3').addClass('menu_off');
	$('#mainmenu ul a').addClass('link_off');
	//$('#mainmenu h3').bind("mouseenter",jQuery.fn.press_menu);
	jQuery.fn.reset_menu();
	
	*/
	
	/*
	jQuery.fn.setup_news_list = function() {
		var this_news = $(this);
		this_news.parent().parent().find(".body").slideUp("slow");
		if (this_news.parent().find(".body").eq(0).is(":hidden")) {
			this_news.parent().find(".body").eq(0).slideDown("slow");
		} else {
			//this_menu.removeClass().addClass('menu_off');
		}
	};
	$('.news_list .body').css('display', 'block');
	$('.news_list .body').hide();
	$('.news_list .title').bind("click",jQuery.fn.setup_news_list);
	
	*/
	/*
	
	
	var panelH = 0;
	jQuery.fn.move_panel = function() {
		var move_panel_t = window.setTimeout(function() {
		jQuery.fn.move_panel();
		}, 200);
		var targetH  = $(window).height()-240-40;
		
		targetH+=$(window).scrollTop();
		var minH  = $("#mainmenu").height()+40+20;
		if (targetH<minH) {
			targetH=minH;
		}
		if (targetH!=panelH) {
			panelH = targetH;
			//$("#panel").css("top",targetH+"px");
			//$("#panel").animate({top: targetH+"px"}, "fast", "linear");
			$("#panel").css("top",targetH+"px");
		}
	}
	
	*/
	
	$('#preloader').hide();
	var canvasW = $(window).width(); 
	var canvasH  = $(window).height();
	var winWidth = canvasW; 
	var winHeight  = canvasH;
	var imgW, imgH, imgW_init, imgH_init; 
	var img_margin = 40;
	var img_border = 20;
	var img_border_t = 60;
	var img_border_b = 60;
	var alpha = 0.7;
	var is_bg = false;
	var slideshow_speed = 15000;
	
	
	
	
	
	jQuery.fn.resize_bg = function() {	
	
			
			
			canvasW = $(window).width(); 
			canvasH  = $(window).height();
					
			if (canvasW<1160) {
				canvasW=1160;
			}
			if (canvasH<828) {
				canvasH=828;
			}
			
			var contentW = canvasW-180-(40*2);
			$("#content").css("width",contentW+"px");
			
			
			winWidth = canvasW; 
			winHeight  = canvasH;
			
			
			if (winWidth/winHeight>4/3) {
				winHeight = winWidth*3/4;
			} else if (winWidth/winHeight<4/3) {
				winWidth = winHeight*4/3;		
			}		
			$("#bg_img").css("width",winWidth+"px");
			$("#bg_img").css("height",winHeight+"px");
			$("#canvas").css("width",canvasW+"px");
			$("#content").css("display","inline");
			$("#content .bg").css("display","block");
			$("#panel").css("display","inline");
			$("#mainmenu").css("display","inline");	
			
			if (b_version!="IE6") {
				$("#bg").css("display","inline");
			}
			
			if ($("#content").height()+80+0<canvasH) {
			$("#content").css("padding-bottom",(canvasH-$("#content").height()-80)+"px");
			} else {
			$("#content").css("padding-bottom",0+"px");
			}
			
			if ($("#content .table_0").width()+178>$("#content").width()) {
				$("#content").css("width",($("#content .table_0").width()+178)+"px");
				
			}
			
			//$('#overlay').css('width',winWidth);
			//$('#overlay').css('height',winHeight);
			$('#overlay').css('width',$(document).width());
			$('#overlay').css('height',$(document).height());
			
			
			
			imgW = imgW_init;
			imgH = imgH_init;
			if (imgW_init>canvasW-img_margin*2-img_border*2) {
				imgW = canvasW-img_margin*2-img_border*2;
				imgH = imgW*imgH_init/imgW_init;
			}
			if (imgH_init>canvasH-img_margin*2-img_border_t-img_border_b) {
				imgH = canvasH-img_margin*2-img_border_t-img_border_b;
				imgW = imgH*imgW_init/imgH_init;
			}
			
			$('#overlay .overlay_img').css('width', imgW+'px');
			$('#overlay .overlay_img').css('height', imgH+'px');
			$('#overlay .overlay_info_box').css('width', imgW+'px');
			$('#overlay .overlay_info_box').css('height', imgH+'px');
			$('#overlay .overlay_container').css('left', (canvasW/2-imgW/2-img_border)+'px');
			$('#overlay .overlay_container').css('top', (canvasH/2-imgH/2-img_border_t)+'px');
			
			//$("#canvas").css("height",canvasH+"px");
			
			
			//if ($(document).width()>contentW+100) {
			//$("#content").css("width",($(document).width()-100)+"px");
			//}
			if (b_version==("IE6")) {
				$('#content .bg').each(function (i) {
					$(this).height($(this).parent().height()+Number($(this).parent().css('padding-top').replace('px',''))+Number($(this).parent().css('padding-bottom').replace('px','')));
					$(this).width($(this).parent().width()+Number($(this).parent().css('padding-left').replace('px',''))+Number($(this).parent().css('padding-right').replace('px','')));
				});
			}
			
			jQuery.fn.move_panel();
	};
	
	//jQuery.fn.move_panel();
	
	
	
	//$('.thumbbox .cell_2 .cell_but').bind("click",jQuery.fn.img_click);
	jQuery.fn.event_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_event_img(this.id.replace("img_", ""));
	};
	jQuery.fn.setup_event_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var query_common = $('#query_common').html();
		var page_id = $("#page_id").val();
		var event_id = $("#event_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_event_img', id:id, page_id:page_id, event_id:event_id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/event/'+event_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	jQuery.fn.news_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_news_img(this.id.replace("img_", ""));
	};
	jQuery.fn.setup_news_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var query_common = $('#query_common').html();
		var page_id = $("#page_id").val();
		var news_id = $("#news_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_news_img', id:id, page_id:page_id, news_id:news_id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/news/'+news_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	jQuery.fn.project_thumb_click = function() {	
		$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_project_img(this.id.replace("img_", ""));
		
	};
	jQuery.fn.setup_project_img = function(id) {
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		var page_id = $("#page_id").val();
		var project_id = $("#project_id").val();
		$('#overlay .overlay_container').hide();
		$('#overlay .overlay_box').load("incl/backend.php", {func:'setup_project_img', id:id, page_id:page_id, project_id:project_id, thumb_no:id},
			function() {
				$('#overlay .overlay_container').hide();
				var filename = $('#filename_'+id).html();
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', 'data/project/'+project_id+'/'+filename, 'overlay_img', '', jQuery.fn.loaded_img_data);
				//alert('data/event/'+event_id+'/'+filename);
				jQuery.fn.setup_alpha();
			}
		);
	}
	
	jQuery.fn.thumb_click = function() {	
		//if($('body').width()>canvasW) {
			//$('#overlay').css('width', $(window).innerWidth());
		//} else {
		//	$('#overlay').css('width', canvasW);
		//}
		//if($('body').height()>canvasH) {
		//	$('#img_big_box').css('height', $('body').height());
	//	} else {
			//$('#overlay').css('height', $(window).innerHeight());
			
			//$('#img_big_box').css('width', $('body').offset().width);
			is_bg = false;
			$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_img(this.id.replace("img_", ""),is_bg);
		//}
		//big_img = ($(this).parent().find("img").eq(0).attr('src')).replace("thumb_","big_");
	};
	jQuery.fn.thumb_bg_click = function() {	
			is_bg = true;
			$('#overlay').css('display', 'block').hide();
		jQuery.fn.setup_img(this.id.replace("img_", ""),is_bg);
	};
	jQuery.fn.thumb_rollover = function() {	
		$('.thumb_pop').css('display', 'none');
		$(this).parent().find(".thumb_pop").eq(0).css('display', 'block').css('left', '0px').css('top', '0px');
			//alert(($(this).offset().top+$(this).height())+"|"+($('#content').height()-40));
		if(($(this).offset().top+$(this).height())>($('#content').height())) {
			$(this).parent().find(".thumb_pop").eq(0).css('top', '-160px');
		}
		if(($(this).offset().left+$(this).width())>($('#content').width())) {
			$(this).parent().find(".thumb_pop").eq(0).css('left', '-180px');
		}
		$(this).parent().find(".thumb_pop").eq(0).hide().fadeIn("normal");
		//$('.thumbbox .cell_2').css('z-index', '1');
		$(this).parent().css('z-index', '100');
	};
	jQuery.fn.thumb_rollout = function() {	
		$('.thumb_pop').css('display', 'none');
		$(this).parent().css('z-index', '1');
	};
	
	jQuery.fn.setup_img = function(id, bg) {
		var my_id = id;
		$('#overlay').css('width',$(document).width());
		$('#overlay').css('height',$(document).height());
		$('#overlay').fadeIn("slow");
		jQuery.fn.show_loader('#overlay',null);
		if ($('#overlay_thumb_'+id).length > 0) {
			var thumb_no = $('#overlay_thumb_'+id).val();
		} else  {
			var thumb_no = $('#thumb_'+id).val();
		}
		if (bg) {
			my_id = $('#thumb_bg_id').html();
			var query_common = $('#query_common_bg').html();
			var thumb_no = $('#thumb_bg').html();
		} else {
			if (is_bg) {
				var query_common = $('#query_common_bg').html();
			} else {
				var query_common = $('#query_common').html();
			}
		}
		
		//alert(thumb_no+"|"+query_common);
		var page_id = $("#page_id").val();
		$('#overlay .overlay_container').hide();
		var my_func = 'setup_img';
		var my_path = 'data/location/big/';
		$('#overlay .overlay_box').load("incl/backend.php", {func:my_func, id:my_id, thumb_no:thumb_no, query_common:query_common, page_id:page_id},
			function() {
				$('#overlay .overlay_container').hide();
				//var filename = $('#filename_'+my_id).val().toLowerCase();
				var filename = $('#filename_'+my_id).html();
				//alert($('#filename_'+id).val());
				jQuery.fn.preload_img('#overlay .overlay_img_box', '#overlay', my_path+filename+'.jpg', 'overlay_img', '', jQuery.fn.loaded_img_data);
				jQuery.fn.setup_alpha();
			}
		);
	}
	
	jQuery.fn.preload_img = function(my_target, my_loader_target, my_src, my_class, my_alt, my_func) {
		jQuery.fn.show_loader(my_loader_target,null);		
		var img = $('<img />').attr('src', my_src).attr('alt', my_alt).attr('class', my_class).load(
			function() {			
				jQuery.fn.hide_loader(my_loader_target);
				$(my_target).append( $(this) );
				my_func();
				//$(my_target).hide().fadeIn("slow");
			}
		);
		
	}
			
	jQuery.fn.loaded_img_data = function() {
		//alert($('#overlay_img').height()+"|"+$('#overlay_img').width());
		$('#overlay .overlay_container').fadeIn("slow");
		imgW_init = $('#overlay .overlay_img').width();
		imgH_init = $('#overlay .overlay_img').height();
		imgW = imgW_init;
		imgH = imgH_init;
		if (imgW/imgH > canvasW/canvasH) {
			if (imgW<640) {
				imgW = 640;
				imgH = imgH_init/imgW_init*imgW;
			}
		} else {
			if (imgH<480) {
				imgH = 480;
				imgW = imgW_init/imgH_init*imgH;
				if (imgW<480) {
					imgW = 480;
					imgH = imgH_init/imgW_init*imgW;
				}	
			}		
		}
		if (imgW_init>canvasW-img_margin*2-img_border*2) {
			imgW = canvasW-img_margin*2-img_border*2;
			imgH = imgW*imgH_init/imgW_init;
		}
		if (imgH_init>canvasH-img_margin*2-img_border_t-img_border_b) {
			imgH = canvasH-img_margin*2-img_border_t-img_border_b;
			imgW = imgH*imgW_init/imgH_init;
		}
		var scrollH=$(window).scrollTop();
		$('#overlay .overlay_img').css('width', imgW+'px');
		$('#overlay .overlay_img').css('height', imgH+'px');
		$('#overlay .overlay_info_box').css('width', imgW+'px');
		$('#overlay .overlay_info_box').css('height', imgH+'px');
		$('#overlay .overlay_row_b').css('width', (imgW)-40+'px');
		$('#overlay .overlay_container').css('left', (canvasW/2-imgW/2-img_border)+'px');
		$('#overlay .overlay_container').css('top', (canvasH/2-imgH/2-img_border_t+scrollH)+'px');
		$('#overlay .overlay_container').css('width', imgW+'px');
		$('#overlay .overlay_info_box').hide();
		$('#overlay #overlay_but_info_close').hide();
		
		$('#overlay #overlay_but_close').bind("click",function() {$('#overlay').fadeOut("slow");});
		$('#overlay .bg').bind("click",function() {$('#overlay').fadeOut("slow");});
		
		
		$('#overlay #overlay_but_info_close').bind("click",function() {$('#overlay .overlay_info_box').fadeOut("slow");$('#overlay #overlay_but_info_close').hide();$('#overlay #overlay_but_info_open').show();});
		$('#overlay #overlay_but_info_open').bind("click",function() {$('#overlay .overlay_info_box').fadeIn("slow");$('#overlay #overlay_but_info_open').hide();$('#overlay #overlay_but_info_close').show();});
		if (is_bg) {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_page_", ""),false);});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_arrow_", ""),false);});
		} else if (template=="project_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_project_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_project_img(this.id.replace("overlay_arrow_", ""));});
		} else if (template=="event_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_event_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_event_img(this.id.replace("overlay_arrow_", ""));});
		} else if (template=="news_list") {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_news_img(this.id.replace("overlay_page_", ""));});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_news_img(this.id.replace("overlay_arrow_", ""));});
		} else {
			$('#overlay .overlay_page_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_page_", ""),false);});
			$('#overlay .overlay_arrow_but').bind("click",function() {jQuery.fn.setup_img(this.id.replace("overlay_arrow_", ""),false);});
		}
	}
	
	jQuery.fn.show_loader = function(my_target,my_template) {
		jQuery.fn.hide_loader(my_target);
		var target_w = $(my_target).width();
		var target_h = $(my_target).height();
		if (my_template) {
			$(my_target).append('<img src="images/'+my_template+'.gif" alt="" class="loader" width="16" height="16" style="left:'+(target_w*0.5-8)+'px;top:'+(target_h*0.5-8)+'px"/>');
		} else {
			$(my_target).append('<img src="images/loader_0.gif" alt="" class="loader" width="32" height="32" style="left:'+(target_w*0.5-16)+'px;top:'+(target_h*0.5-16)+'px"/>');
		}
	}
	jQuery.fn.hide_loader = function(my_target) {
		$(my_target+' .loader').remove();
	} 
	jQuery.fn.change_page = function() {
		var my_href = $(this).attr('href');
		if (my_href) {
			var page_no = my_href.split("page_no=")[1];
			$(this).attr('href', '#');		
			jQuery.fn.show_loader('#location_list',null);
			$('#location_page').load("incl/backend.php", {func:'change_page', page_no:page_no, page_tot:$('#page_tot').val(), page_max:$('#page_max').val(), url:$('#url').val(), thumb_max:$('#thumb_max').val(), result_no:$('#result_no').val()},function() {$('#location_page a').bind("click",jQuery.fn.change_page);});
			$('#location_list').load("incl/backend.php", {func:'change_list', page_no:page_no, page_tot:$('#page_tot').val(), thumb_max:$('#thumb_max').val(), query_common:$('#query_common').html()},
				function() {
					//alert($('.thumb_but').length);
					jQuery.fn.hide_loader('#location_list');
					$('.thumb_but').bind("mouseenter",jQuery.fn.thumb_rollover);
					$('.thumb_but').bind("mouseleave",jQuery.fn.thumb_rollout);
					$('.thumb_but').bind("click",jQuery.fn.thumb_click);
					jQuery.fn.setup_alpha();
					jQuery.fn.resize_bg();
				}
			);
		}
	}
	
	jQuery.fn.move_panel = function() {
		//var move_panel_t = window.setTimeout(function() {
		//jQuery.fn.move_panel();
		//}, 8);
		var targetH=$(window).scrollTop();
		if (($("#mainmenu").height())+$("#panel").height()>($("#content").height()+160)) {
			targetH=0;
		} else {
			
			if ((targetH+($("#mainmenu").height()))>($("#content").height())) {
				targetH=($("#content").height())-($("#mainmenu").height());
			}
		}
		//var menuT = ($("#mainmenu").offset().top-40);
		//menuT += (targetH-($("#mainmenu").offset().top-40))/4;
	//	$("#mainmenu").css("top",menuT);
		$("#mainmenu").css("top",targetH);
		
		var targetH = targetH+$("#mainmenu").height();
		if ($("#mainmenu").height()+$("#panel").height()+80<$(window).height()) {
			targetH = $(window).height()	-$("#panel").height()-80+$(window).scrollTop();
		}
		//var panelT = ($("#panel").offset().top-40);
		//panelT += Math.round((targetH-($("#panel").offset().top-40))/4);
		if (targetH<508) {
			targetH=508;
		}
		if ($("#panel").offset().top==40) {
			$("#panel").css("top",targetH);
		//$('#debug').html($("#panel").offset().top);
		} else {
			//$("#panel").css("top",panelT);
			$("#panel").css("top",targetH);
		}
		
		if (b_version==("IE6")) {
			if ($("#panel").offset().top+$("#panel").height()>$("#content").offset().top+$("#content").height()) {
				$('#footer').css('top',($("#panel").offset().top+$("#panel").height()-40)+'px');
			} else {
				$('#footer').css('top',($("#content").offset().top+$("#content").height()-40)+'px');
			}
		}
	}
	
	jQuery.fn.change_calendar = function() {
		var tDate = $(this).attr('id');
		jQuery.fn.show_loader('#calendar','loader_1');
		var page_id = $("#page_id").val();
		$('#calendar').load("incl/backend.php", {func:'change_calendar', tDate:tDate, page_id:page_id},function() {jQuery.fn.hide_loader('#calendar');$('.calendar_arrow').bind("click",jQuery.fn.change_calendar);jQuery.fn.calendar_cell_populated();});
	}
	jQuery.fn.change_event_calendar = function() {
		if ($(this).find("a").length>0) {
			if ($(this).attr('class')=="but_1") {
				$("#cal_type").val($(this).find("a").eq(0).attr('id').replace("cal_type_",""));
			} else {
				$("#cal_type").val("");
			}
		}
		var tDate = $(this).attr('id');
		jQuery.fn.show_loader('#calendar_event',false);
		var page_id = $("#page_id").val();
		var cal_type = $("#cal_type").val();
		$('#calendar_event').load("incl/backend.php", {func:'change_event_calendar', tDate:tDate, page_id:page_id, cal_type:cal_type},function() {jQuery.fn.hide_loader('#calendar_event');$('#calendar_event_but .but_1').bind("click",jQuery.fn.change_event_calendar);$('#calendar_event_but .but_1_selected').bind("click",jQuery.fn.change_event_calendar);jQuery.fn.setup_alpha();jQuery.fn.calendar_cell_populated();});
	}
	jQuery.fn.close_panel_up = function() {
		$('#panel_up table').hide();
		$('#panel_up_open').show();
	}
	jQuery.fn.open_panel_up = function() {
		$('#panel_up table').show();
		$('#panel_up_open').hide();
	}
	jQuery.fn.close_panel_dn = function() {
		$('#panel_up table').hide();
		$('#panel_dn_container').hide();
		$('#panel_dn_open').show();
		$('#panel_dn_close').hide();
		$('#news_scroll').cycle('stop');
	}
	jQuery.fn.open_panel_dn = function() {
		$('#panel_up table').show();
		$('#panel_dn_container').show();
		$('#panel_dn_open').hide();
		$('#panel_dn_close').show();
		$('#news_scroll').cycle({fx:'scrollLeft',startingSlide: 0, timeout:slideshow_speed});
	}
	jQuery.fn.initial_news_col = function(this_news) {
		if ($('#open_title').length==0) {
			var col_no = this_news.parent().find(".col_no").val();
			var row_no = this_news.parent().find(".row_no").val();
			this_news.parent().find(".body").show();
			this_news.parent().find(".title_long").show();
			this_news.parent().find(".title").hide();
			this_news.parent().find(".title").css('opacity', 1);
			this_news.parent().find(".status").val('y');
			$('#news_slideshow_'+col_no).cycle(Number(row_no));
		} else {
			if ($('#open_title').val()=="showall") {
				this_news.parent().parent().find(".body").show();
				this_news.parent().parent().find(".title_long").show();
				this_news.parent().parent().find(".title").hide();
				this_news.parent().parent().find(".title").css('opacity', 1);
				this_news.parent().parent().find(".status").val('y');
			} else if ($('#open_title').val()=="title_only") {
				
			}
			//this_news.parent().parent().find(".body").show();
			//this_news.parent().parent().find(".title_long").show();
			//this_news.parent().parent().find(".title").hide();
			//this_news.parent().parent().find(".title").css('opacity', 1);
			//this_news.parent().parent().find(".status").val('y');
		}
		jQuery.fn.resize_bg();
	};
	jQuery.fn.setup_news_col = function() {
		var this_news = $(this);
		
		if ($('#open_title').length==0) {
			var col_no = this_news.parent().find(".col_no").val();
			var row_no = this_news.parent().find(".row_no").val();
			var classname = this_news.parent().attr('class');
			this_news.parent().parent().find(".body").hide();
			this_news.parent().parent().find(".title_long").hide();
			this_news.parent().parent().find(".title").show();
			this_news.parent().parent().find(".title").css('opacity', alpha);
			if (classname!='selected') {
				this_news.parent().parent().find('li').removeClass();
				this_news.parent().find(".body").show();
				this_news.parent().find(".title_long").show();
				this_news.parent().find(".title").hide();
				this_news.parent().find(".title").css('opacity', 1);
				this_news.parent().addClass('selected');
			} else {
				this_news.parent().parent().find('li').removeClass();
			}
			$('#news_slideshow_'+col_no).cycle(Number(row_no));
		} else {
			if ($('#open_title').val()=="showall") {
				this_news.parent().parent().parent().find('li').removeClass();
				this_news.parent().parent().find(".body").show();
				this_news.parent().parent().find(".title_long").show();
				this_news.parent().parent().find(".title").hide();
				this_news.parent().parent().find(".title").css('opacity', 1);
				this_news.parent().parent().addClass('selected');
			} else if ($('#open_title').val()=="title_only") {
				
			} 		 	
		}
		
		
		jQuery.fn.resize_bg();
	};
	jQuery.fn.rollover_news_col = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_news_col = function() {
		var this_news = $(this);
		var classname = this_news.parent().attr('class');
		if (classname!='selected') {
			this_news.css('opacity', alpha);
		}
	};
	jQuery.fn.rollover_news_list = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_news_list = function() {
		var this_news = $(this);
		if (!this_news.is('.selected')) {
			this_news.css('opacity', alpha);
		}
	};
	jQuery.fn.initial_news_list = function() {
	}
	jQuery.fn.setup_news_list = function() {
		var this_news = $(this);
		var href = this_news.find("a").attr("href");
		window.location = href;
		/*
		var this_news = $(this);
		var news_id = this_news.find(".news_id").val();
		var page_id = this_news.find(".page_id").val();
		
		if (news_id) {	
			jQuery.fn.show_loader('#news_list',null);
			this_news.find('a').attr('href','#');
			if (!this_news.is('.selected')) {
				$('#news_list').load("incl/backend.php", {func:'change_news', page_id:page_id, news_id:news_id},
					function() {																																		  
					$('.news_list li').bind("mouseenter",jQuery.fn.rollover_news_list);
					$('.news_list li').bind("mouseleave",jQuery.fn.rollout_news_list);
					$('.news_list li').bind("click",jQuery.fn.setup_news_list);
					$('#news_page div').bind("click",jQuery.fn.setup_news_list);
					jQuery.fn.resize_bg();
					jQuery.fn.setup_alpha();
				});
			}
		}
		*/
	};
	
	jQuery.fn.calendar_cell_populated = function() {
		
		$('.events').parent().each(function () {
			if ($('.events ul', this).attr('class')!='loaded') {
				$('.events ul', this).attr('class','loaded');
				// options
				var distance = 0;
				var time = 150;
				var hideDelay = 50;
				var showDelay = 500;
		 
				var hideDelayTimer = null;
		 
				// tracker
				var beingShown = false;
				var shown = false;
		 		if ($('.but_area', this).length>0) {
				var popup = $('.events ul', this).css('opacity', 1);
					var trigger = $('.but_area', this);
					popup.mouseenter(function () {
						trigger.parent().css('zIndex',10);
						popup.hide(100);
					});
					trigger.mouseenter(function () {
							popup.css({
								bottom: 20,
								left: 0
							})
							trigger.parent().css('zIndex',10000);
							trigger.css('zIndex',10000);
							
						popup.show(100);
						
					}).mouseout(function () {
							trigger.parent().css('zIndex',10);
							trigger.css('zIndex',10);
						popup.hide(100);
						
					});
				} else {
				var popup = $('.events ul', this).css('opacity', 0);
					var trigger = $(this);		 
					// set the mouseover and mouseout on both element
					$([trigger.get(0), popup.get(0)]).mouseover(function () {
						// stops the hide event if we move from the trigger to the popup element
						if (hideDelayTimer) clearTimeout(hideDelayTimer);
							trigger.css('zIndex',10000);
							trigger.parent().css('zIndex',10000);
			 
						// don't trigger the animation again if we're being shown, or already visible
						//if (beingShown || shown) {
							//return;
						//} else {
							beingShown = true;
			 
							// reset position of popup box
							popup.css({
								bottom: 20,
								left: 0,
								display: 'block' // brings the popup back in to view
							})
			 
							// (we're using chaining on the popup) now animate it's opacity and position
							//.fadeTo(1000, 0)
							.animate({
								bottom: '+=' + distance + 'px'
								//opacity: 0
							}, 0, 'swing', function() {
								// once the animation is complete, set the tracker variables
								beingShown = false;
								shown = true;
								$(this).fadeTo(time, 1);
							});
						//}
						
					}).mouseout(function () {
						// reset the timer if we get fired again - avoids double animations
						if (hideDelayTimer) clearTimeout(hideDelayTimer);
			 
						// store the timer so that it can be cleared in the mouseover if required
						hideDelayTimer = setTimeout(function () {
							hideDelayTimer = null;
								trigger.css('zIndex',1);
							trigger.parent().css('zIndex',10);
								shown = false;
								beingShown = false;
							popup.animate({
								bottom: '-=' + distance + 'px',
								opacity: 0
							}, time, 'swing', function () {
								// once the animate is complete, set the tracker variables
								// hide the popup entirely after the effect (opacity alone doesn't do the job)
								popup.css('display','none');
							});
						}, hideDelay);
					});
				}
				
			}
		});
	}
	jQuery.fn.rollover_table_0 = function() {
		var this_row = $(this);
		var color1 = $('#color1').val();
		var color2 = $('#color2').val();
		this_row.not('.title').not('.selected').find('td').css("background-color",color2);
	};
	jQuery.fn.rollout_table_0 = function() {
		var this_row = $(this);
		var color1 = $('#color1').val();
		var color2 = $('#color2').val();
		this_row.not('.title').not('.selected').find('td').css("background-color",color1);
	};
	jQuery.fn.click_table_0 = function() {
		var this_row = $(this);
		var my_href = this_row.not('.title').find('a').eq(0).attr('href');
		if (this_row.not('.title').length>0 && my_href) {
			window.location = my_href;
		}
	};
	jQuery.fn.rollover_but_1 = function() {
		var this_news = $(this);
		this_news.css('opacity', 1);
	};
	jQuery.fn.rollout_but_1 = function() {
		var this_news = $(this);
		this_news.css('opacity', alpha);
	};
	
	
	jQuery.fn.view_list = function() {
		$('#but_view_list').attr('class','but_1_selected');
		$('#but_view_thumb').attr('class','but_1');
		$('#view_thumb').hide();
		$('#view_list').show();
		jQuery.fn.setup_alpha();
		
		$('#but_view_list img').load("incl/backend.php", {func:'change_project_view', status:"list"},function() {jQuery.fn.resize_bg();});		
	}
	jQuery.fn.view_thumb = function() {
		$('#but_view_list').attr('class','but_1');
		$('#but_view_thumb').attr('class','but_1_selected');
		$('#view_list').hide();
		$('#view_thumb').show();
		jQuery.fn.setup_alpha();
		
		$('#but_view_list img').load("incl/backend.php", {func:'change_project_view', status:"thumb"},function() {jQuery.fn.resize_bg();});		
	}
	jQuery.fn.view_map = function() {
			$('#but_view_map').hide();
			$('#but_view_info').show();
			$('#project_info').hide();
			$('#project_map').show();	
	}
	jQuery.fn.view_info = function() {
			$('#but_view_map').show();
			$('#but_view_info').hide();
			$('#project_info').show();
			$('#project_map').hide();
	}
	
	
	jQuery.fn.event_thumb_next = function() {
		jQuery.fn.setup_event_thumb(1);
	}
	jQuery.fn.event_thumb_prev = function() {
		jQuery.fn.setup_event_thumb(-1);
	}
	
	jQuery.fn.setup_event_thumb = function(page_diff) {
		var this_page = Number($('#event_thumb_no').val());
		var total_page = Number($('#event_thumb_total').val());
		var my_page = 0;
		if (page_diff) {
			my_page = (this_page)+(page_diff);
			if (my_page<=0) {
				my_page = 0;
			}
			if (my_page>=total_page-1-5) {
				my_page=total_page-1-5;
			}
			$('#event_thumb_no').val(my_page);
		}
		
		$('#event_thumb_next').show();
		$('#event_thumb_prev').show();
		if (my_page == 0) {
			$('#event_thumb_prev').hide();
		}
		if (my_page>=total_page-1-5) {
			$('#event_thumb_next').hide();
		}
		if (total_page<5) {
			$('#event_thumb_next').hide();
		}
		
		var i=0;
		while ($('#event_thumb #img_'+i).length>0) {
			if (i>=my_page && i<my_page+5) {
				$('#event_thumb #img_'+i).show();
			} else {
				$('#event_thumb #img_'+i).hide();
			}
			i++;
		}
		
		
	}
	
	
	jQuery.fn.news_thumb_next = function() {
		jQuery.fn.setup_news_thumb(1);
	}
	jQuery.fn.news_thumb_prev = function() {
		jQuery.fn.setup_news_thumb(-1);
	}
	
	jQuery.fn.setup_news_thumb = function(page_diff) {
		var this_page = Number($('#news_thumb_no').val());
		var total_page = Number($('#news_thumb_total').val());
		var my_page = 0;
		var max_page = 1;
		if (page_diff) {
			my_page = (this_page)+(page_diff);
			if (my_page<=0) {
				my_page = 0;
			}
			if (my_page>=total_page-1-max_page) {
				my_page=total_page-1-max_page;
			}
			$('#news_thumb_no').val(my_page);
		}
		
		$('#news_thumb_next').show();
		$('#news_thumb_prev').show();
		if (my_page == 0) {
			$('#news_thumb_prev').hide();
		}
		if (my_page>=total_page-1-max_page) {
			$('#news_thumb_next').hide();
		}
		if (total_page<max_page) {
			$('#news_thumb_next').hide();
		}
		
		var i=0;
		while ($('#news_thumb #img_'+i).length>0) {
			if (i>=my_page && i<my_page+max_page) {
				$('#news_thumb #img_'+i).show();
			} else {
				$('#news_thumb #img_'+i).hide();
			}
			i++;
		}
		
		
	}
	
	
	
	jQuery.fn.setup_alpha = function() {
		$('#overlay .bg').css('opacity', 0.8);
		$('.overlay_info_box .bg').css('opacity', 0.8);
		$('#content .bg').css('opacity', alpha);
		$('#content_bg').css('opacity', 0.4);
		$('.news_col .title').css('opacity', alpha);
		$('.news_col .title_a div').css('opacity', alpha);
		$('.news_list li').not('.selected').css('opacity', alpha);
		//$('#fund_submenu a').not('.selected').css('opacity', alpha);
		$('.but_0').css('opacity', alpha);
		$('.but_1').css('opacity', alpha);
		$('.but_1_selected').css('opacity', 1);
		$('.but_1_disabled').css('opacity', 0.2);
		$('.but_1_r').css('opacity', alpha);
		$('.but_1_l').css('opacity', alpha);
		$('.alpha').css('opacity', alpha);
		$('.textbox_2 .bg').css('opacity', alpha);
		$('.overlay_page_but').css('opacity', alpha);
		$('.overlay_arrow_but').css('opacity', alpha);
		$('.overlay_but').css('opacity', alpha);
		$('.calendar_event_cell_populated .grid').css('opacity', alpha);
		
		
		$('.overlay_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.overlay_page_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_page_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.overlay_arrow_but').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.overlay_arrow_but').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_r').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1_r').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_l').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_1_l').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_0').bind("mouseenter",jQuery.fn.rollover_but_1);
		$('.but_0').bind("mouseleave",jQuery.fn.rollout_but_1);
		$('.but_1_selected').unbind("mouseleave");
		$('.but_1_selected').unbind("mouseenter");
	}
	
	function slideshow_onBefore() { 
		var my_id = this.id.replace("img_","title_");
		$('#'+my_id).parent().parent().parent().parent().find("div").css('opacity', alpha);
		$('#'+my_id).parent().parent().parent().parent().find("object").removeClass();
		$('#'+my_id).css('opacity', 1);
		$('#'+my_id).parent().addClass('selected');
	}
	
	
	$(window).bind("resize", jQuery.fn.resize_bg);
	$(window).bind("scroll",jQuery.fn.move_panel);
	//alert(template);
	if (template!="section_1" && template!="section_2" && template!="home") {
		//jQuery.fn.close_panel_up();
		jQuery.fn.close_panel_dn();
	} else {
		//jQuery.fn.open_panel_up();
		if (b_version=='IE6') {
			jQuery.fn.close_panel_dn();
		} else {
			jQuery.fn.open_panel_dn();
		}
	}
	
	
	$('#location_list .thumb_but').bind("mouseenter",jQuery.fn.thumb_rollover);
	$('#location_list .thumb_but').bind("mouseleave",jQuery.fn.thumb_rollout);
	$('#location_list .thumb_but').bind("click",jQuery.fn.thumb_click);
	
	
	$('#img_bg').bind("click",jQuery.fn.thumb_bg_click);
	
	$('#submit_location_keyword').bind("click",jQuery.fn.search_location_keyword);
	$('#location_page a').bind("click",jQuery.fn.change_page);
	
	$('.slideshow').cycle({fx:'fade',startingSlide: 0,timeout: slideshow_speed,cleartype:false, cleartypeNoBg:true});	
	
	
	$('.calendar_arrow').bind("click",jQuery.fn.change_calendar);
	$('#calendar_event_but .but_1').bind("click",jQuery.fn.change_event_calendar);
	
	$('#panel_up_close').bind("click",jQuery.fn.close_panel_up);
	$('#panel_up_open').bind("click",jQuery.fn.open_panel_up);
	
	$('#panel_dn_close').bind("click",jQuery.fn.close_panel_dn);
	$('#panel_dn_open').bind("click",jQuery.fn.open_panel_dn);
	
	
	$('.news_col .body').css('display', 'block').hide();
	$('.news_col .title_long').css('display', 'block').hide();
	$('.news_col .title').bind("click",jQuery.fn.setup_news_col);
	$('.news_col .title_long').bind("click",jQuery.fn.setup_news_col);
	$('.news_col .title').bind("mouseenter",jQuery.fn.rollover_news_col);
	$('.news_col .title').bind("mouseleave",jQuery.fn.rollout_news_col);
	$('.news_col .title_a div').bind("mouseenter",jQuery.fn.rollover_news_col);
	$('.news_col .title_a div').bind("mouseleave",jQuery.fn.rollout_news_col);
	
	$('.news_list li').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('.news_list li').bind("mouseleave",jQuery.fn.rollout_news_list);
	$('.news_list li').bind("click",jQuery.fn.setup_news_list);
	//$('#news_page div').bind("click",jQuery.fn.setup_news_list);
	
	$('.table_0 tr').bind("mouseenter",jQuery.fn.rollover_table_0);
	$('.table_0 tr').bind("mouseleave",jQuery.fn.rollout_table_0);
	$('.table_0 tr').bind("click",jQuery.fn.click_table_0);

	$('#fund_submenu .alpha').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('#fund_submenu .alpha').bind("mouseleave",jQuery.fn.rollout_news_list);

	$('#people_chart .alpha').bind("mouseenter",jQuery.fn.rollover_news_list);
	$('#people_chart .alpha').bind("mouseleave",jQuery.fn.rollout_news_list);
	
	//$('.news_slideshow').cycle({timeout: 0, fx:'fade',startingSlide: 0});
	$('.news_slideshow').cycle({fx:'fade',timeout: slideshow_speed,startingSlide: 0,before:slideshow_onBefore});
	$('.project_slideshow').cycle({fx:'fade',timeout: slideshow_speed,startingSlide: 0,before:slideshow_onBefore});
	
	$('#but_view_list').bind("click",jQuery.fn.view_list);
	$('#but_view_thumb').bind("click",jQuery.fn.view_thumb);
	$('#but_view_map').bind("click",jQuery.fn.view_map);
	$('#but_view_info').bind("click",jQuery.fn.view_info);
	
	$('#event_thumb .but_0').eq(0).bind("click",jQuery.fn.event_thumb_prev);
	$('#event_thumb .but_0').eq(1).bind("click",jQuery.fn.event_thumb_next);
	$('#event_thumb .row_cell').bind("click",jQuery.fn.event_thumb_click);
	
	$('#news_thumb .but_0').eq(0).bind("click",jQuery.fn.news_thumb_prev);
	$('#news_thumb .but_0').eq(1).bind("click",jQuery.fn.news_thumb_next);
	$('#news_thumb .row_cell').bind("click",jQuery.fn.news_thumb_click);
	
	$('#project_thumb .row_cell').bind("click",jQuery.fn.project_thumb_click);
	
	
	//jQuery.fn.initial_news_col($('#fund_list .news_col').find('.title').eq(0));
	
	jQuery.fn.initial_news_col($('#fund_list .news_col').find('.title'));
	//jQuery.fn.initial_news_col($('#fund_list .news_col .test').find('.title'));
	jQuery.fn.initial_news_col($('#textpage_list .news_col').find('.title').eq(0));
	jQuery.fn.initial_news_col($('#news_list .news_col').find('#list_selected').eq(0));
		
	
	jQuery.fn.setup_event_thumb();
	jQuery.fn.setup_news_thumb();
	jQuery.fn.move_panel();	
	jQuery.fn.resize_bg();
	jQuery.fn.setup_alpha();
	jQuery.fn.calendar_cell_populated();
});
	
function print_page() {	
	//$(".news_col .body").show();
	//$(".news_col .title_long").show();
	//$(".news_col .title").hide();
	//$(".news_col .title").css('opacity', 1);
	//$(".news_col .status").val('y');
	print();
}

function validate_form() {
	if ($("#form_id")) {
		switch($("#form_id").val()) {
			case 'contact_general':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_fund':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_media':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_subscribe':
				var input_arr = new Array('email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_subscribe1':
				var input_arr = new Array('fname','lname','email','subscribe','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_unsubscribe':
				var input_arr = new Array('email');
				return validate_input(input_arr);
			break;
			case 'contact_unsubscribe1':
				var input_arr = new Array('email');
				return validate_input(input_arr);
			break;
			case 'contact_property':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'contact_feedback':
				var input_arr = new Array('fname','lname','email','privacy');
				return validate_input(input_arr);
			break;
			case 'search_keyword':
				var input_arr = new Array('search_keyword');
				return validate_input(input_arr);
			break;
			case 'location_search_quick':
				var input_arr = new Array('keyword');
				return validate_input(input_arr);
			break;
		}
		
	}
	return false;	
}

function validate_input(input_arr) {
	for (i=0; i<input_arr.length; i++) {
		switch (input_arr[i]) {
			case 'fname':			
				if (!validate_textbox("#fname",'Please fill in First Name')) {
					return false;
				}
			break;
			case 'lname':			
				if (!validate_textbox("#lname",'Please fill in Last Name')) {
					return false;
				}
			break;
			case 'email':			
				if (!validate_email("#email",'Invalid Email')) {
					return false;
				}
			break;
			case 'privacy':			
				if (!validate_checkbox("#privacy",'Please agree with the Privacy Policy')) {
					return false;
				}
			break;
			case 'subscribe':			
				if (!validate_checkbox("#subscribe",'Please agree to subscribe the newsletter')) {
					return false;
				}
			break;
			case 'search_keyword':			
				if (!validate_textbox("#search_keyword",'Please enter a keyword')) {
					return false;
				}
			break;
			case 'keyword':			
				if (!validate_textbox("#keyword",'Please enter a keyword')) {
					return false;
				}
			break;
		}
	}
	return true;
}

function validate_textbox(my_id,msg) {
	if ($(my_id).val()==null||$(my_id).val()=="") {
		$(my_id).focus();
		alert(msg);
		return false;
	}
	return true;
}
function validate_checkbox(my_id,msg) {
	if($(my_id+':checked').size() == 0){
		$(my_id).focus();
		alert(msg);
		return false;
	}
	return true;
}
function validate_email (my_id,msg) {
	var str = $(my_id).val();
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var check= true;
	if (str.indexOf(at)==-1){
		check = false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		check = false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		check = false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		check = false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		check = false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		check = false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		check = false;
	 }
	 if (check) {
		return true;
	 } else {
		$(my_id).focus();
		 alert (msg);
		return false;	
	 }
				
}