// <![CDATA[

$(document).ready(function(){
// attach ajax on project page//
var path = $(".images img").attr('src');
$(".images").html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
$(".images").load( path, {}, function(){ //calling the ajax then with a callback afterwards
	
	//all functions must come in here //
	
	$("#imagecover").css({display:'none'})
	.fadeIn("slow");
	$(".controller").css({display:'none'});	
	$("#imagepreview li:first").addClass("currentimage");
	
	// attache mousever and mouseout events//
	$("#imagecover").mouseover(function(){
      $(".controller").css({display:'block'});	
    }).mouseout(function(){
      $(".controller").css({display:'none'});
    });
	// mousever and mouseout events end //

	// attach click event to the preview thunmbnails //
	$("#imagepreview li").click(function () {
		$("#imagepreview li").removeClass("currentimage");
		$(this).addClass("currentimage");
		var $this = $(this);
		var info = $this.find('img').attr("longdesc");
		var id = $this.find('a').attr("href");
		var height = $this.find('a').attr("title");
		var pg_id = $this.find('a').attr("name");
		
		$(".info").html(info);
		$("#imagecover").fadeOut('fast', function(){ // a callback
			$("#imagecover").html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
			});
			$("#imagecover").animate({height:height}, 500, function(){ // a callback
				$("#imagecover").load( "incl_templates.child.global/item.projects.images.cover.php?id=" + id  + "&pg_id=" + pg_id, {}, function(){ // a callback
					$("#imagecover").css({display:'none'})
					.fadeIn("slow");
					$(".controller").css({display:'none'});	
				});
			});				
		return false;
	});	
	// thunmbnails' click event ends //
	
	//all functions must come in here //
	
	});	
	// project page ajax ends
	
postsearch();
loadlogin();	
guide();
loadadd();
loadmanange();
loadedit();
loadcomments();
insertAfterCaption();

if ($('#home').length > 0) {
		slideShow();
	} 
		
}); 
//page ready ends

this.appendCaption = function(){
	$("#content img").each(function () {
	var imgwidth = $(this).width();
	var title = $(this).attr("alt");
	
	$(this).wrap("<div class=\"image_container\"></div>");
	$(this).parent().css({
		width: imgwidth
		});
	$(this).parent().append("<div class=\"image_description\">" + title + "</div>");
	
	});
}

this.insertAfterCaption = function(){
	$(".content img").each(function () {
	var imgwidth = $(this).width();
	var alt = $(this).attr("alt");
	//alert(alt);
	
	$("<div class='image_description'>"+ alt +"</div>").insertAfter(this);
	$('.image_description').css({
		color: '#666666',
		fontSize: '11px',
		margin: '0px 0px 0px 0px',
		width: imgwidth
		});
	
	});
}


this.afterCaption = function(){
	$("#content img").each(function () {
	var $this = $(this);
	var imgwidth = $this.width();
	var title = $this.attr("alt");
	
    var title = $this.attr("alt");
    $this.after('<div class="image_description">'+ title +'</div>');

	$('.image_description').css({
		margin: '-20px 0px 20px 0px',
		width: imgwidth
		});
	
	});
}

function slideShow() {

	//add a class the the first element
	$('.slide li:first').addClass('active');
	
	//Set the opacity of all images to 0
	$('.slide li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('.slide li:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('.slide .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('.slide .caption').css({width: $('.slide li').find('img').css('width')});
	
	var height = $('.slide li').find('img').css('height');
	$('.slide').css({height:height});
	
	//Get the caption of the first image from REL attribute and display it
	$('.caption .content').html($('.slide li:first').find('img').attr('rel'))
	.animate({opacity: 1.0}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',5000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('.slide li.active')?  $('.slide li.active') : $('.slide li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.slide li:first') :current.next()) : $('.slide li:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');
	//alert(caption);
	
	var height = next.find('img').css('height');
	
	//Set the fade in effect for the next image, show class has higher z-index
	current.addClass('last-active');
	
	next.css({opacity: 0.0})
	.addClass('active')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('active');
	
	/*next.css({opacity: 0.0})
	.addClass('active')
	.animate({opacity: 1.0}, 1000, function(){
	current.animate({opacity: 0.0}, 1000).removeClass('active last-active');
	});*/

	$('.caption')
	.animate({opacity: 0.0}, 500, function() {
	$('.slide').css({height:height});
	$('.caption').animate({opacity: 1.0}, 500);
	//Display the content
	$('.caption .content').html(caption);
	});
}

this.coverslide = function(){	
	$(".controller").click(function(){
		var $this = $(this);
		var id = $this.find('a').attr("href");
		var img_id = $this.find('img').attr("src");
		var pg_id = $this.find('img').attr("title");
		var info = $this.find('img').attr("alt");
		var height = $this.find('img').attr("name");
		
		$(".info").html(info);			
		$("#imagepreview li").removeClass("currentimage");
		$("#"+img_id).addClass("currentimage");
		
		$("#imagecover").fadeOut('fast', function(){ //a callback
			$("#imagecover").html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
			});
		$("#imagecover").animate({height:height}, 500, function(){
			$("#imagecover").load( "incl_templates.child.global/item.projects.images.cover.php?id=" + id + "&pg_id=" + pg_id, {}, function(){ //a callback
				$(".controller").css({display:'none'});	
				$("#imagecover").css({display:'none'})
				.fadeIn("slow");
				});
			});
		return false;
	});
}

this.guide = function(){	
$(".guide").click(function(){
	var path = $(this).attr("href");
	JDOM.popup(path,'guide','width=400,height=600, scrollbars=yes'); 
	return false;
	});
}

this.closepopup = function(target){	
$(".close").click(function(){
	target.fadeOut('fast', function(){
		target.remove();
		});
	return false;
	});
}

this.attachback = function(target){	
$(".back").click(function(){
	var path = $(this).attr("href");
	$(".popup").remove();
	document.location = path;
	return false;
	});
}

this.loadmanange = function(){
//JDOM.ajaxGet('incl_cms_contents/form_page_manage.php?pg_cat_id=2','bodycontent');	
$(".manange").click(function(){
	var path = $(this).attr("href");
	var target = $("#bodycontent");
	target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	target.load( path, {}, function(){
		loadedit();
		});
	return false;
	});
}

this.loadadd = function(){	
$(".add").click(function(){
	$(".popup").remove();
	var path = $(this).attr("href");
	$(document.body).prepend("<div id=\"popup_add\" class=\"popup\"></div>");
	
	var target = $('#popup_add');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 860;
	var top = 100;
	var marginLeft = "-"+((scrollLeft + width + 20)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px",
			zIndex:"10"
			});
	
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center"
				});
		
		target.load( path, {}, function(){
			$('#add')
			.css({
				padding:"20px", 
				backgroundColor:"#ffffff"
				});
			loadtinyMCEadvanced_add();
			closepopup(target);
			});	
		})
	return false;
	});
}

this.loadlogin = function(){	
$("#login").click(function(){
	$("#popup_login").remove();
	var path = $(this).attr("href");
	$(document.body).append("<div id=\"popup_login\" class=\"popup\"></div>");
	
	var target = $('#popup_login');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 380;
	var top = 200;
	var marginLeft = "-"+((scrollLeft + width)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px"
			});
	
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center"
				});
		target.load( path, {}, function(){
			target.hide();
			target.fadeIn('slow');
			closepopup(target);
			postlogin();
			});	
		})			
	return false;
	});
}

this.loadcomments = function(){		
$(".comments").click(function(){
	$(".popup").remove();
	var path = $(this).attr("href");
	$(document.body).append("<div id=\"popup_comments\" class=\"popup\"></div>");

	var target = $('#popup_comments');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 500;
	var top = 150;
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px"
			});

	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center"
				});
		target.load( path, {}, function(){
			//$(".popup").corner();
			$(".popup_content").hide();
			$(".popup_content").slideDown('slow');
			loadregister();
			loadreply();
			closepopup(target);
			postcomment();
			});	
		});
	return false;
	});
}

this.loadregister = function(){	
$(".register").click(function(){
	$("#popup_register").remove();
	var path = $(this).attr("href");
	$(document.body).append("<div id=\"popup_register\" class=\"popup\"></div>");
	
	var target = $('#popup_register');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 380;
	var top = 220;
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px"
			});
			
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center"
				});
		target.load( path, {}, function(){
			target.hide();
			target.fadeIn('slow');
			closepopup(target);
			postregister();
			});	
		})
	return false;
	});
}

this.loadreply = function(){	
$(".reply").click(function(){
	$("#popup_reply").remove();
	var path = $(this).attr("href");
	$(document.body).append("<div id=\"popup_reply\" class=\"popup\"></div>");
	
	var target = $('#popup_reply');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 400;
	var top = 200;
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px"
			});
			
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center"
				});
		target.load( path, {}, function(){
			target.hide();
			target.fadeIn('slow');
			closepopup(target);
			postreply();
			});	
		})
	return false;
	});
}

this.loadOlderEntries = function(){	
//JDOM.ajaxGet('incl_cms_contents/form_page_manage.php?pg_cat_id=2','bodycontent');	 
$("#olderentries li").click(function(){
	var path = $(this).find('a').attr("href");
	var target = $("#bodycontent");
	target.slideUp('fast', function(){
		target.fadeIn('fast').html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
			target.load(path, {}, function(){
				target.hide();
				target.slideDown('slow');
				loadcomments();
			});
		});
	return false;
	});
}

this.loadedit = function(){	
$(".edit").click(function(){
	var pg = $(this).attr("href");
	var target = $("#bodycontent");
	target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	target.load( "incl_cms/page_update_parent.php?pg="+pg, {}, function(){
		loadtinyMCEadvanced_update();
		attachback();
		//tinyMCE.execCommand('mceAddControl', false, 'content_update');	
		});
	return false;
	});
}

this.postsearch = function(){
$("#form_search").submit(function(){
	//JDOM.ajaxPost(this,'incl_layouts.global/search_mysql.php','bodycontent');
	var target = $("#bodycontent");
	target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	$.post("incl_templates.child.global/search_mysql.php",{input:$('#input').val()},function(data){
		target.html(data);
		});	
	return false;
	});
}

this.postupdate = function(){
//JDOM.ajaxPostXML(this,'incl_cms_contents/page_update_xml.php','results_update');
$("#popup_result").remove();
$(document.body).append("<div id=\"popup_process\" class=\"popup\"></div>");
var popupparent = $('#popup_process');
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
var width = 400;
var top = 250;
var marginLeft = "-"+ ((scrollLeft + width)/2);
popupparent
	.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:"11"
		//display:"none"
		});
popupparent.append("<div id=\"process\" class=\"popup_content\"></div>");	
var popupchild = $('#process');
popupchild
	.css({
		width:"95%"
		});
	
var hide = $('#pg_hide').val();
if ($('#pg_hide').attr('checked')) {
	hide = 1;
	}else{
	hide = 0;
	}

tinyMCE.triggerSave(true,true);	
popupchild.html('<div><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
$.post("incl_cms/page_update_xml.php",{
	pg_title:$('#pg_title').val(),
	pg_title_clean:$('#pg_title_clean').val(),
	pg_content:$('#content_update').val(),
	pg_hide:hide,
	//ps_cat_id:$('#ps_cat_id').val(),
	parent_id:$('#parent_id').val(),
	tmp_id:$('#tmp_id').val(),
	pg_id:$('#pg_id').val()
	},function(xml){		
		$("label").removeClass('error');
		$("form img").css({visibility:'hidden'});
		popupparent.remove();
		processupdate(xml);
	});
return false;
}

this.processupdate = function(xml){ //  ==  function addMessages(xml) { 	
$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
var target = $('#popup_result');
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
var width = 400;
var top = 250;
var marginLeft = "-"+ ((scrollLeft + width)/2);
target
	.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:"11",
		display:"none"
		});
target.load("incl_cms/result.php", {}, function(){
	$("error", xml).each(function(){
		var elementid = $(this).attr('elementid');
		var message = $(this).attr('message');
		$("#"+elementid+"_label").addClass('error');
		$("#"+elementid+"_img").css({visibility:'visible'});
		//$("#results_update div").remove();
		$(".result").append("<img src='img_icon/attention.png' /> <b>" + message + "</b> <br />");
		target.fadeIn('slow', function(){
			closepopup(target);
		});
	});
	
	$("result", xml).each(function(){
	var message = $(this).attr('message');
	//alert(message);
	//$("#results_update div").remove();
	$(".result").append("<img src='img_icon/info.png' /> <b>" + message + "</b> <br />");
	target.fadeIn('fast', function(){
		closepopup(target);
		});
    });	
});
	

}

this.postadd = function(){
//JDOM.ajaxPostXMLmultiTargets(this,'incl_cms_contents/page_add_xml.php','results_add','add');
$("#popup_result").remove();
$(document.body).append("<div id=\"popup_process\" class=\"popup\"></div>");
var popupparent = $('#popup_process');
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
var width = 400;
var top = 250;
var marginLeft = "-"+ ((scrollLeft + width)/2);
popupparent
	.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:"11"
		//display:"none"
		});
popupparent.append("<div id=\"process\" class=\"popup_content\"></div>");	
var popupchild = $('#process');
popupchild
	.css({
		width:"95%"
		});

var hide = $('#pg_hide').val();
if ($('#pg_hide').attr('checked')) {
	hide = 1;
	}else{
	hide = 0;
	}
tinyMCE.triggerSave(true,true);	
popupchild.html('<div><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
$.post("incl_cms/page_add_xml.php",{
	pg_title_add:$('#pg_title_add').val(),
	pg_title_clean_add:$('#pg_title_clean_add').val(),
	pg_content_add:$('#content_add').val(),
	pg_hide_add:hide,
	//ps_cat_id:$('#ps_cat_id').val(),
	pg_cat_id_add:$('#pg_cat_id_add').val(),
	parent_id_add:$('#parent_id_add').val(),
	tmp_id_add:$('#tmp_id_add').val()
	},function(xml){		
		$("label").removeClass('error');
		$("form img").css({visibility:'hidden'});
		popupparent.remove();
		processadd(xml);
	});
return false;
}

this.processadd = function(xml){ //  ==  function addMessages(xml) {
$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
var target = $('#popup_result');
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
var width = 400;
var top = 250;
var marginLeft = "-"+ ((scrollLeft + width)/2);
target
	.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:"11",
		display:"none"
		});
target.load("incl_cms/result.php", {}, function(){
	$("error", xml).each(function(){
		var elementid = $(this).attr('elementid');
		var message = $(this).attr('message');
		$("#"+elementid+"_label").addClass('error');
		$("#"+elementid+"_img").css({visibility:'visible'});
		$(".result").append("<img src='img_icon/attention.png' /> <b>" + message + "</b> <br />");
		target.fadeIn('slow', function(){	
			closepopup(target);
		});	
    });
});
	
$("result", xml).each(function(){
	var path = $(this).attr('path');
	$("#popup_add").slideUp('fast', function(){
		$(document.body).append("<div id=\"popup_completed\" class=\"popup\"></div>");
		var target = $('#popup_completed');
		var scrollTop = $(window).scrollTop();
		var scrollLeft = $(window).scrollLeft();
		var width = 400;
		var top = 200;
		var marginLeft = "-"+ ((scrollLeft + width)/2);
		target
			.css({
				top:(scrollTop + top) + "px", 
				left:"50%",
				marginLeft:marginLeft + "px",
				width:width + "px",
				display:"none"
				});
	
		target.load(path, {}, function(){
			target.fadeIn('slow', function(){
				closepopup(target);
				});		
			});
		});	
    });	
}
	
this.postcomment = function(){
//JDOM.ajaxPostXMLmultiTargets(this,'incl_layouts.blog/comment_add_xml.php', 'result_comment', 'popup_comments');
$("#form_comment").submit(function(){
	$("#result_comment").html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	$.post("incl_templates.child.blog/comment_add_xml.php",{
		cmt_email:$('#cmt_email').val(),
		cmt_content:$('#cmt_content').val(),
		pg_id:$('#pg_id').val()
		},function(xml){
			$("label").removeClass('error');
			$("form img").css({visibility:'hidden'});
			processcomment(xml);	
		});
	return false;
	});
}

this.processcomment = function(xml){ //  ==  function addMessages(xml) { 	
$("error", xml).each(function(){
	var elementid = $(this).attr('elementid');
	var message = $(this).attr('message');
	$("#"+elementid+"_label").addClass('error');
	$("#"+elementid+"_img").css({visibility:'visible'});
	$("#result_comment div").remove();
	$("#result_comment").append("<img src='img_icon/attention.png' /> <b>" + message + "</b> <br />");
    });	
	
$("url",xml).each(function() {
	var url = $(this).text();
	$("#result_comment div").hide();
	$("#latest").append("<li></li>");
	$("#latest li:last").css({float:'none'});
	$("#latest li:last").hide();
	$("#latest li:last").load(url, {}, function(){
		$("#latest li:last").slideDown("slow");
		clear_form_elements('form');
		});
	});	
}

this.postreply = function(){
//JDOM.ajaxPostXMLmultiTargets(this,'incl_layouts.blog/reply_add_xml.php', 'result_reply', 'reply'); return false;
$("#form_reply").submit(function(){
	var target = $("#result_reply");
	target.html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	var cmt_id = $("#cmt_id").val();
	var path = $("form[id=form_reply]").attr("action");
	$.post(path,{
		rpl_content:$('#rpl_content').val(),
		cmt_id:$('#cmt_id').val()
		},function(xml){
			$("label").removeClass('error');
			$("form img").css({visibility:'hidden'});
			processreply(xml, cmt_id);	
		});
	return false;
	});
}

this.processreply = function(xml, cmt_id){ //  ==  function addMessages(xml) { 	
$("error", xml).each(function(){
	var elementid = $(this).attr('elementid');
	var message = $(this).attr('message');
	$("#"+elementid+"_label").addClass('error');
	$("#"+elementid+"_img").css({visibility:'visible'});
	$("#result_reply div").remove();
	$("#result_reply").append("<img src='img_icon/attention.png' /> <b>" + message + "</b> <br />");
    });	
	
$("result",xml).each(function() {
	var url = $(this).attr('path');
	//alert(cmt_id);
	$("#popup_reply").fadeOut();
	$("#popup_reply").remove();
	
	var parent = $("#comment_"+cmt_id);
	parent.append("<li></li>");
	$("#comment_"+cmt_id+" li:last").css({float:'none'});
	$("#comment_"+cmt_id+" li:last").hide();
	$("#comment_"+cmt_id+" li:last").load(url+"?cmt_id="+cmt_id, {}, function(){
		$("#comment_"+cmt_id+" li:last").slideDown("slow");
		clear_form_elements('form');
		});
	});	
}

this.postregister = function(){
//JDOM.ajaxPostXMLmultiTargets(this,'incl_layouts.blog/register_xml.php', 'result_register', 'register'); 
$("#form_register").submit(function(){
	$("#result_register").html('<div class="ajaxloader"><p><img src="img_icon/loader_0.gif"/> loading...</p></div>');
	$.post("incl_templates.child.blog/register_xml.php",{
		mai_name:$('#mai_name').val(),
		mai_email:$('#mai_email').val()
		},function(xml){
			$("label").removeClass('error');
			$("form img").css({visibility:'hidden'});
			processregister(xml);	
		});
	return false;
	});
}

this.processregister = function(xml){ //  ==  function addMessages(xml) { 	
$("error", xml).each(function(){
	var elementid = $(this).attr('elementid');
	var message = $(this).attr('message');
	$("#"+elementid+"_label").addClass('error');
	$("#"+elementid+"_img").css({visibility:'visible'});
	$("#result_register div").remove();
	$("#result_register").append("<img src='img_icon/attention.png' /> <b>" + message + "</b> <br />");
    });	
	
$("result", xml).each(function(){
	var path = $(this).attr('path');
	$("#register").load(path, {}, function(){
		setTimeout("$('#popup_register').fadeOut()",5000);
		});
    });	
}

this.postlogin = function(){
$("#form_login").submit(function(){	
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating...').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("incl_cms/login_mysql.php",{ 
		username:$('#username').val(),
		password:$('#password').val(),
		rand:Math.random() 
		},function(data){
		if(data=='yes'){ //if correct login detail
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
				$(this).html('Logging in...').addClass('messageboxok').fadeTo(900,1,function(){  //add message and change the class of the box and start fading
				document.location='index.php'; //redirect to secure page
				});			  
			});
		}
		else if (data=='invalid') {
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
				$(this).html('Invalid login!').addClass('messageboxerror').fadeTo(900,1); //add message and change the class of the box and start fading
				});		
			}	
		else {
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
				$(this).html('Your login details are incorrect!').addClass('messageboxerror').fadeTo(900,1); //add message and change the class of the box and start fading
				});		
			}		
		});
	return false; //not to post the  form physically
	});
}

this.clear_form_elements = function(target){ //  ==  function clear_form_elements(target) {
    $(target).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}

this.loadtinyMCEadvanced_update = function(){
	tinyMCE.init({
		// General options
		mode : "exact",
		theme : "advanced",
		elements : "content_update", //id
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,pastetext,|,bold,italic,underline,strikethrough,|,undo,redo,|,link,unlink,image,media,|,help,code",
		theme_advanced_buttons2 : "tablecontrols,|,fullscreen",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		// Specifying an Absolute Image Path
		/*
		document_base_url : "http://localhost/deborah robinson 2009/",   
    	relative_urls : false,
        remove_script_host : false,
		*/
		
		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.php",
		external_image_list_url : "lists/image_list.php",
		media_external_list_url : "lists/media_list.php",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

this.loadtinyMCEadvanced_add = function(){
	tinyMCE.init({
		// General options
		mode : "exact",
		theme : "advanced",
		elements : "content_add", //id
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,pastetext,|,bold,italic,underline,strikethrough,|,undo,redo,|,link,unlink,image,media,|,help,code",
		theme_advanced_buttons2 : "tablecontrols,|,fullscreen",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		// Specifying an Absolute Image Path
		/*
		document_base_url : "http://localhost/deborah robinson 2009/",   
    	relative_urls : false,
        remove_script_host : false,
		*/
		
		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.php",
		external_image_list_url : "lists/image_list.php",
		media_external_list_url : "lists/media_list.php",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

// ]]>
