$(document).ready(function()
{  
  $(".template-img").hover(function()
  {
    $(this).addClass("hover");
  }, function()
  {
    $(this).removeClass("hover");
  });
  $(".template-img").click(function(e)
  {    
    $(".template-img").removeClass("selected");
    
    $(".template-cover").parent().find(':radio').removeAttr('checked');    
    $(this).addClass("selected").parent().parent().find(":radio").attr("checked", true);
    if ($(e.target).attr("id") == "template_classic")
    {
      $("#foreground, #divider, #button-on, #button-hover, #turn-off-box-shadow, #classic_template").show();
      $("#the_first_template, #turn-off-artwork-title").hide();
    }
    else if ($(e.target).attr("id") == "template_1")
    {
      $("#foreground, #divider, #button-on, #button-hover, #turn-off-box-shadow, #classic_template").hide();
      $("#the_first_template, #turn-off-artwork-title").show();
    }
  });
});

function check_availability (domain_name, hosting_name)
{	
  var domain1 = $("#"+domain_name).val() + $("#"+hosting_name).val();
  $("#is_available").css({display: "block", color: "blue"}).text("Searching ...");
  $.post('index.php?page=ajax_code', {
      domain: domain1,      
      mode: 'check_domain'
    }, onAjaxCheckAvailability);
}

function onAjaxCheckAvailability(data)
{
	var is_available = $("available", data).text(); 
	is_available = $.trim(is_available);
	var domain_name = $("domain", data).text();
	domain_name = $.trim(domain_name);
	if (is_available == "yes") 
	{
		$("#is_available").css("color", "red");
		$("#is_available").text("[" + domain_name + "] is not available!");		
		$("#after_domain").css("display", "none");				
	}
	else if (is_available == "miss")
	{
		$("#is_available").css("color", "red");
		$("#is_available").text("It's impossible to check [" + domain_name + "] now.");	
		$("#after_domain").css("display", "none");
	}
	else if ((is_available == "no") || (is_available == "unknown"))
	{
		$("#is_available").text("[" + domain_name + "] is available!");
		$("#is_available").css("color", "green");
		$("#after_domain").css("display", "block");
	}
}

// Add bookmark link

function addBookmark(title, url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) { //MSIE
		window.external.AddFavorite( url, title);
	} else {
		alert("Sorry, your browser doesn't support this");
	}
}

//color pop up window

Colors = function (objectId, inputTextId, styleColor, pallete)
// constuctor
{
	this._object = document.getElementById(objectId);
	this._objectId = objectId;

	this.inputText = document.getElementById(inputTextId);
	this.inputTextId = inputTextId;
	this.styleColor = styleColor;
	//eval('this.oldColor = Colors.rgb2hex(this._object.style.'+styleColor+')');
	//this.inputText.value = this.oldColor;
	eval('this._object.style.'+styleColor+' = "'+'#'+this.inputText.value+'"');
	//this._object.style.'+styleColor+'
	this.pallete = pallete;
}
Colors.prototype.show = function ()
// рисуем палитру
{
	var table = '<span id="allcolorselementsselect'+this.inputTextId+'" onclick="document.getElementById(\'allcolorselements'+this.inputTextId+'\').style.display=\'block\'; document.getElementById(\'allcolorselementslink'+this.inputTextId+'\').focus();" style="cursor: pointer;"><img src="'+this.outImage+'" title="Choose the color from palette" style="position:relative; top:2px;" onmouseover="this.src=\''+this.overImage+'\'" onmouseout="this.src=\''+this.outImage+'\'" /></span>';
	table += '<input id="setc'+this.inputTextId+'" type="hidden" value="0" />';
	table += '<input id="oldColor'+this.inputTextId+'" type="hidden" value="#'+this.oldColor+'" />';
	table += '<a id="allcolorselementslink'+this.inputTextId+'" href="#" onclick="return false;" onblur="document.getElementById(\'allcolorselements'+this.inputTextId+'\').style.display=\'none\'; if (document.getElementById(\'setc'+this.inputTextId+'\').value!=\'1\') Colors.changecolor(document.getElementById(\'oldColor'+this.inputTextId+'\').value, \''+this._objectId+'\', \''+this.inputTextId+'\', \''+this.styleColor+'\'); document.getElementById(\'setc'+this.inputTextId+'\').value=\'0\'; ">';
	table += '<div id="allcolorselements'+this.inputTextId+'" style="width: '+this.allwidth+'px; cursor: pointer; display: none; position: absolute; z-index:1000; background-color:#bbb; border:solid 1px #bbb;">';
	for (var i=1, c=0; i<=this.rows; i++)
	{
		//table += '<tr height="20">';
		for (var j=1; j<=this.cols; j++)
		{
			table += '<div style="background:'+this.pallete[c++]+'; float:left; width:'+this.width+'px; height:'+this.width+'px; margin:'+this.border+'px; border:solid '+this.border+'px #000;" onmousedown="document.getElementById(\'setc'+this.inputTextId+'\').value=\'1\'; document.getElementById(\'oldColor'+this.inputTextId+'\').value=this.style.backgroundColor;" onmousemove="Colors.changecolor(this.style.backgroundColor, \''+this._objectId+'\', \''+this.inputTextId+'\', \''+this.styleColor+'\');" onmouseover="this.style.border=\'solid '+this.border+'px #ffff00\'" onmouseout="this.style.border=\'solid '+this.border+'px #000\';"></div>';
		}
		table += '<div style="clear:both;"></div>';
	}
	table += '</div></a>';
	document.writeln(table);
}

Colors.rgb2hex = function (rgb) {
// вспомогательная функция преобразование из формата rgb(0,0,0) в hex
  if (!rgb)
  {
    return '000000';
  }
  if (rgb.substring(0,1)=="#")
  {
    return rgb.substring(1);
  }
  else
  {
	  var s,i,h='', x='0123456789abcdef';
	  var c = rgb.substring(4);
	  c = c.substring(0, c.length-1);
	  if(c){
	    s=c.split(',');
	    for (i=0; i < 3; i++){
	      n  = parseInt(s[i]);
	      h += x.charAt(n>>4) + x.charAt(n&15);
	    }
	  return h;
	  }
  }
}

Colors.changecolor = function (thiscolor, _object, inputText, styleColor)
{



	eval('document.getElementById(_object).style.'+styleColor+' = thiscolor');



	document.getElementById(inputText).value = Colors.rgb2hex(thiscolor);



}


Colors.setup = function (params) {



	function param_default(pname, def) 



	{ 



		if (typeof params[pname] == "undefined") 



		{ 



			params[pname] = def; 



		} 



	};



	param_default("rows",			5);



	param_default("cols",			12);



	param_default("width",			20);



	param_default("border",			1);



	param_default("styleColor",		"color");



	param_default("inputTextId",	null);



	param_default("objectId",		null);



	param_default("pallete",        new Array (



	'#FFFFCC',	'#FFFF66',	'#FFCC66',	'#F2984C',	'#E1771E',	'#B47B10',	'#A9501B',	'#6F3C1B',	'#804000',	'#CC0000',	'#940F04',	'#660000',



	'#C3D9FF',	'#99C9FF',	'#66B5FF',	'#3D81EE',	'#0066CC',	'#6C82B5',	'#32527A',	'#2D6E89',	'#006699',	'#215670',	'#003366',	'#000033',



	'#CAF99B',	'#80FF00',	'#00FF80',	'#78B749',	'#2BA94F',	'#38B63C',	'#0D8F63',	'#2D8930',	'#1B703A',	'#11593C',	'#063E3F',	'#002E3F',



	'#FFBBE8',	'#E895CC',	'#FF6FCF',	'#C94093',	'#9D1961',	'#800040',	'#800080',	'#72179D',	'#6728B2',	'#6131BD',	'#341473',	'#400058',



	'#FFFFFF',	'#E6E6E6',	'#CCCCCC',	'#B3B3B3',	'#999999',	'#808080',	'#7F7F7F',	'#666666',	'#4C4C4C',	'#333333',	'#191919',	'#000000'



	));



	param_default("outImage",		"../resources/img/rgb.gif");



	param_default("overImage", 		"../resources/img/on_rgb.gif");



	



	



	var col = new Colors(params.objectId, params.inputTextId, params.styleColor, params.pallete);







	col.rows = params.rows;



	col.cols = params.cols;



	col.width = params.width;



	col.border = params.border;



	col.allwidth = col.cols*(col.width+col.border*4)+col.border;



	col.outImage = params.outImage



	col.overImage = params.overImage







	col.show();



	



	return col;



}

//end color pop up window

function onAjaxAddGallerySuccess(data)
{

	$("div #g_err").remove();



	var is_successful = $("is_successful", data).text(); 



	if (is_successful)

	{

		is_successful = $.trim(is_successful);

		var gallery = $("gallery", data); 



	  if (gallery.length > 0)

	  {     

	 	  $("#gallery_list").remove();



	    var sel = $("<select></select>")

	      .attr({

	          id: 'gallery_list',

	          name: 'artwork[gallery_id]'          

	        })      

	      .prependTo("#gallery_container");  



	    var id_for_gallery;

	    var name_for_gallery;



	    for (var i=0; i<gallery.length; i++)

	    {

	      id_for_gallery = $("id", gallery[i]).text();

	      name_for_gallery = $("name", gallery[i]).text(); 



	      if (is_successful == id_for_gallery) 

	      	$("<option></option>").attr({value: id_for_gallery, selected: 'selected'}).html(name_for_gallery).appendTo(sel);

	      else $("<option></option>").attr("value", id_for_gallery).html(name_for_gallery).appendTo(sel);

	    }

	    $("#g_name").attr('value', "");

	    $('#new_gallery').css('display', 'none');

	  }

	}

	else 

	{

		var error = $("errorno", data).text();



		if (error)

		{

			$("<div id='g_err' class='error'>"+error+"</div>").appendTo("#new_gallery");

		}

	}

}

function EditSuccess (data)
{
	var is_success = $("is_success", data).text(); 
	is_success = $.trim(is_success);

	if (is_success == 1) 
	{
		var type = $("new_type", data).text();
		type = $.trim(type);
		var art_id = $("art_id", data).text();
		art_id = $.trim(art_id);

		if (type == "price")
		{
			var price = $("new_price", data).text();
			price = $.trim(price);
			$('#pr_'+art_id).css('display', 'block').html("$"+price); 
			$('#sale_'+art_id).css('display', 'none');//.attr("value", price); 
			$('#pr_edit_'+art_id).css('display', 'block'); 
			$('#pr_submit_'+art_id).css('display', 'none');
		}

		else if (type == "sold")
		{
			$('#pr_'+art_id).css('display', 'block').html("Sold"); 
			$('#sale_'+art_id).css('display', 'none'); 
			$('#pr_edit_'+art_id).css('display', 'block'); 
			$('#pr_submit_'+art_id).css('display', 'none');
		}
		else if (type == "not_for_sale")
		{
			$('#pr_'+art_id).css('display', 'block').html("Not For Sale"); 
			$('#sale_'+art_id).css('display', 'none'); 
			$('#pr_edit_'+art_id).css('display', 'block'); 
			$('#pr_submit_'+art_id).css('display', 'none');
		}
		else if (type == "contact_me")
		{
			$('#pr_'+art_id).css('display', 'block').html("Contact me"); 
			$('#sale_'+art_id).css('display', 'none'); 
			$('#pr_edit_'+art_id).css('display', 'block'); 
			$('#pr_submit_'+art_id).css('display', 'none');
		}

//		$('#'+art_id+' #pr').css('display', 'block').html("$"+price); 
//		$('#'+art_id+' #pr_input').css('display', 'none').attr("value", price); 
//		$('#'+art_id+' #pr_edit').css('display', 'block'); 
//		$('#'+art_id+' #pr_submit').css('display', 'none');
	}

	else 
	{
	}	
}

function onAjaxAddCategorySuccess(data)
{



	$("div #cat_err").remove();



	var is_successful = $("is_successful", data).text(); 



	if (is_successful)



	{



		is_successful = $.trim(is_successful);



	



		var category = $("category", data); 



	  



	  if (category.length > 0)



	  {     



	    $("#category_list").remove();



	     



	    var sel = $("<select></select>")



	      .attr({



	          id: 'category_list',



	          name: 'category'          



	        })      



	      .prependTo("#category_container");  



	          



	    var id_for_category;



	    var name_for_category;



	    



	    //$("<option></option>").attr("value", "").html("-Select category-").appendTo(sel);



	    for (var i=0; i<category.length; i++)



	    {



	      id_for_category = $("id", category[i]).text();



	      name_for_category = $("name", category[i]).text(); 



	      if (is_successful == id_for_category)      



	      	$("<option></option>").attr({value: id_for_category, selected: 'selected'}).html(name_for_category).appendTo(sel);



	      else $("<option></option>").attr("value", id_for_category).html(name_for_category).appendTo(sel);



	    }



	    $("#c_name").attr('value', "");



	    $('#new_category').css('display', 'none');



	  }



	}



	else 



	{



		var error = $("errorno", data).text();



		if (error)



		{



			$("<div id='cat_err' class='error'>"+error+"</div>").appendTo("#new_category");



		}



	}



}

function saveImportantSuccess (data)
{



	var result = $("saveresult", data).text(); 



	result = $.trim(result);



	



	if (result) $('#important').css('display', 'none');



}

function change_date (id)
{



	var d = $("#edit_date_"+id+" select[name='Day']").val();



	var m = $("#edit_date_"+id+" select[name='Month']").val();



	var y = $("#edit_date_"+id+" select[name='Year']").val();



	



	location.href = "index.php?page=payment&cmd=change_date&d="+d+"&m="+m+"&y="+y+"&p_id="+id;	



}

function onAjaxDelImgSuccess(data)
{



	var result = $("is_successful", data).text(); 



	result = $.trim(result);



	



	if (result == 1) 



	{



		$('#art_img').remove();



		$('#btn_del_img').remove();



		$(".warning").append("Once you've uploaded an image your artwork can be published.<br />");	



		$("#unpubl").remove();



		$("#is_publ").remove();



		//$("input:submit").attr({id: "publ", value: "Publish", onclick: "$('#art_cmd').attr('value', 'publish_artwork');"}).insertBefore("#del");



	}	



}

function text_length(input_elem, div_elem, count_chars)
{



  div_elem.style.display = "inline";



  var span_elem_1 = div_elem.getElementsByTagName('span')[0];



  var span_elem_2 = div_elem.getElementsByTagName('span')[1];



  var char_number = input_elem.value.length;



 



  span_elem_1.innerHTML = char_number;



  span_elem_2.innerHTML = count_chars - char_number;  



}

function verify_paypal_id(field_pp_id, user_id, addr, zip)
{



	var pp_id = $("#"+field_pp_id).val();



  



  $("#verify_response").css({display: "block", color: "blue"}).text("Verifying...");



  



  $.post('../admin/index.php?page=ajax_code', {



      pp_id: pp_id,  



      user_id: user_id,    



      addr: addr,



      zip: zip,



      mode: 'verify_pp_id'



    }, onAjaxVerifiedPP);



}

function onAjaxVerifiedPP (data)
{



	var verify_resp = $("verify_resp", data).text(); 



	verify_resp = $.trim(verify_resp);	



	



	if (verify_resp == "yes") 



	{



		var email = $("email", data).text(); 



		email = $.trim(email);



		var username = $("username", data).text(); 



		username = $.trim(username);



		



		$("#verify_response").css("color", "green");



		$("#verify_response").text("Account verified for "+username+" at "+email);		



	}



	



	else if (verify_resp == "no")



	{



		var errorno = $("errorno", data).text();alert(errorno);



		$("#verify_response").text(errorno+" Sorry, that PayPal ID didn't work. Please enter your number again.");



		$("#verify_response").css("color", "red");		



	}



}

function if1enter (ev)
{



	var code = ev.keyCode;



	if (!code) code = ev.which;



	



	if (code)



	{



		if (code == 13)



		{



			if ($('#d_name').attr('value')) check_availability('d_name', 'h_name');



			return false;



		}



	}



	else return true;



}

function send_new_price (art_id, u_id)
{

	var val = $("#sale_"+art_id+" :checked").val(); 

	if (val == "price")
	{
		price = $("#sale_"+art_id+" :text").val();

		if (price !== '')
		{
			$.post('index.php?page=ajax_code', 
					{
						art_id: art_id, 
						type: val,
						price: price, 
						cmd: 'edit_price',
						user_id: u_id
					}, 
				EditSuccess);
		}
	}
	else if (val == "sold")
	{
		$.post('index.php?page=ajax_code', 
			{
				art_id: art_id, 
				type: val,
				cmd: 'edit_price',
				user_id: u_id
			}, 
		EditSuccess);
	}

	else if (val == "not_for_sale")
	{
		$.post('index.php?page=ajax_code', 
			{
				art_id: art_id, 
				type: val,
				cmd: 'edit_price',
				user_id: u_id
			}, 
		EditSuccess);
	}
	
	else if (val == "contact_me")
	{
		$.post('index.php?page=ajax_code', 
			{
				art_id: art_id, 
				type: val,
				cmd: 'edit_price',
				user_id: u_id
			}, 
		EditSuccess);
	}
}

function character_counter(txt_id, max_count)
{
	if ($("#ch_counter").length == 0) 
	{
		$("#"+txt_id).after("<div id='ch_counter'><span id='len' style='color: red;'></span> characters left</div>");
	}
	input_obj = $("#"+txt_id+" textarea");
	txt_val = input_obj.val();
	n = txt_val.match(/[\n]/g);
	txt_len = txt_val.length;
	if (n) txt_len = txt_len + n.length;
	if (txt_len > max_count) 
	{	  
		txt_val = txt_val.substr(0, max_count-n.length);		
		n1 = txt_val.match(/[\n]/g);
	  txt_len = txt_val.length;
	  if (n1) txt_len = txt_len + n1.length; 
		input_obj.val(txt_val);
	}
	txt_rest = max_count - txt_len;
	$("#ch_counter #len").text(txt_rest);
}

function allow_input (event, input_obj, max_count)
{
  n = input_obj.val().match(/[\n]/g);
  c = input_obj.val().length+1;
  if (n) c = c + n.length;
  
	//if ((event.keyCode != 8) &&((input_obj.val().length+1) > max_count)) return false;
	if ((event.keyCode != 8) &&((c) > max_count)) return false;
	else return true;
}

function reload_image(image_url, alt, title)
{	
  $('#imgmask').css('display', 'block');
  $('#loading').css('display', 'block');
  
  var img = new Image();					
  $(img).load(function()
  {
    $('#artwork-image').css('display','none');
	  $('#imgmask').css('display', 'none');
	  $('#loading').css('display','none');
    $('#artwork-image').html(this);
    $(this).attr({alt: alt, title: title});
    $('#artwork-image').show();     
  }).attr('src', image_url);
}

function show_hide_links(count, num, a_name, div_name)
{
	for (i=1; i<=count; i++)
	{
		if (i != num)
		{
			$("#"+a_name+"_"+i).show();
			$("#"+div_name+"_"+i).hide();
		}
		else
		{
			$("#"+a_name+"_"+i).hide();
			$("#"+div_name+"_"+i).show();
		}
	}
}

var changetypefaces = function(event)
{
	typeface_id = $(this).val();
	var ajax_response_typefaces = function(data)
	{
		var typefaces = $("typefaces",data).text();
		if (typefaces != "no")
		{				
			div_tag = $($("div_id", data).text());
			div_tag.css("font-family", typefaces);
		}
	}	
	if ($(event.target).is("#site_design select[name*=title_typeface]")) div_tag = "#design_title, #design_subheader";			
	else if ($(event.target).is("#site_design select[name*=text_typeface]")) div_tag = "#right_box,#right_box_tpl_1";
	$.post("../admin/index.php?page=ajax_code", {mode: "get_typefaces", id: typeface_id, div_id: div_tag}, ajax_response_typefaces);
};

var changecolors = function(event)
{
	$color = $(this).val();
	colorStr = $color;
	new_color = colorStr.substr(1);
	
	if ($(event.target).is("#vtrColorPickerTitle"))
	{
		$("#design_title, #design_subheader").css("color", $color);		
	}
	else if ($(event.target).is("#vtrColorPickerText"))
	{
		$("#right_box p, #right_box_tpl_1 p, #right_box_tpl_1 span[class=prev-template-1-inactive], #right_box_tpl_1 span[class=design_subtitle]").css("color", $color);
		$("#right_box_tpl_1 span[class=prev-template-1-inactive]").css("background-image", "url(../resources/img/arrows/arr_l/arr_l_"+new_color+".png)");
	}	
	else if ($(event.target).is("#vtrColorPickerFormInputText"))
	{
		$("#right_box input, #right_box_tpl_1 input").css("color", $color);
	}	
	else if ($(event.target).is("#vtrColorPickerLink"))
	{	  
		$("#right_box a, #right_box_tpl_1 a").css("color", $color);
		$("#right_box #arrow_next").css("background-color", $color);
		$("#right_box div[class*=rb-link-color-200]").css("background-color", $color);
		$("#right_box_tpl_1 a[class=next-template-1]").css("background-image", "url(../resources/img/arrows/arr_r/arr_r_"+new_color+".png)");
	}
	else if ($(event.target).is("#vtrColorPickerBackground"))
	{
		$("#right_box, #right_box_tpl_1").css("background-color", $color);
	}
	else if ($(event.target).is("#vtrColorPickerForeground"))
	{
		$("#right_box div[class*=design_border_box]").css("background-color", $color);		
		//$("#right_box div[class*=round_button_inside]").css("background-image", "url(../resources/img/buttons/button-inside-"+new_color+".png)");
		$("#right_box div[class*=but-bg-l-n]").css("background-image", "url(../resources/img/buttons/but_bg_l_n/but_bg_l_n_"+new_color+".png)");
		$("#right_box div[class*=but-bg-r-y]").css("background-image", "url(../resources/img/buttons/but_bg_r_y/but_bg_r_y_"+new_color+".png)");
		$("#right_box div[class*=but-bg-m-200]").css("background-image", "url(../resources/img/buttons/but_bg_m/but_bg_m_"+new_color+".png)");
	}
	else if ($(event.target).is("#vtrColorPickerFormInput"))
	{
		$("#right_box input, #right_box_tpl_1 input").css("background-color", $color);
	}
	else if ($(event.target).is("#vtrColorPickerBorder"))
	{
		$("#right_box input, #right_box_tpl_1 input").css("border-color", $color);
		$("#right_box div[class*=design_border]").css("border-color", $color);		
		//$("#right_box div[class*=round_button_border]").css("background-image", "url(../resources/img/buttons/button-border-"+new_color+".png)");
		$("#right_box div[class*=but-bd-l]").css("background-image", "url(../resources/img/buttons/but_bd_l/but_bd_l_"+new_color+".png)");
		$("#right_box div[class*=but-bd-r]").css("background-image", "url(../resources/img/buttons/but_bd_r/but_bd_r_"+new_color+".png)");
		$("#right_box div[class*=but-bd-m-200]").css("background-image", "url(../resources/img/buttons/but_bd_m/but_bd_m_"+new_color+".png)");
	}
	else if ($(event.target).is("#vtrColorPickerDivider"))
	{
		$("#right_box div[class*=border_bottom]").css("border-color", $color);
	}
	else if ($(event.target).is("#vtrColorPickerButtonOn"))
	{
		$("#right_box div[class*=block_link_active]").css("background-color", $color);	
	}	
};

var changelogotype = function()
{
	var logo_id = $("#select_logo option:selected").val();
	if (logo_id) 
	{
		$.post("../admin/index.php?page=ajax_code",{mode:"get_sizes",id:logo_id},function(data)
		{
			if (!$("error_req",data).text())
			{
				$("#logo_uploader").show();						
				$("#logo_type").text("Upload a JPG, "+$("width",data).text()+"px x "+$("height",data).text()+"px");
				if (logo_id == $("db_id",data).text())
				{
					$("#logo_img").show();
					$("#del_logo").show();
				}
				else 
				{
					$("#logo_img").hide();
					$("#del_logo").hide();
				}
			}
		});						
	}
	else
	{
		$("#logo_img").hide();
		$("#del_logo").hide();
		$("#logo_uploader").hide();
	}
};

//atr gallery sorting
var onAjaxSuccessSorting = function(data)
{	
  error = parseFloat($("error_no", data).text()); 

  if (!error) 
  {
    featured_body = $table_featured.children('tbody');
    list_body = $table_list.children('tbody');
    			      
    featured_tr = $("tr", featured_body).eq(0).clone(true);
    list_tr = $("tr", list_body).eq(0).clone(true);			      
    
    featured_body.empty();
    list_body.empty(); 
    type = $("type", data).text();
    
    $("featured item", data).each(function (i, item){				      		      
      f_id = $(item).attr("id");
      f_title = $("title", item).text();
      f_order = $("order", item).text();
      if (type == "edit_artwork")
      {
        f_active = parseFloat($("active", item).text());
  
  		  featured_tr1 = featured_tr.clone(true);
  		  
  		  featured_tr1.attr("id", "featured_list_"+f_id).find("td.img_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_artwork&act=edit&art_id="+f_id).end().find("td.img_td img").attr({src: "../resources/img/artworks_small/"+f_id+".jpg", alt: f_title}).end().find("td.title_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_artwork&act=edit&art_id="+f_id).text("\""+f_title+"\"").end().find("td.position_td input").attr({name: f_id, value: f_order}).end().find("td.status_td").text(((f_active)?"published":"unpublished")).end().find("td.feature_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_artwork&cmd=unfeature&art_id="+f_id);
  		
  		  featured_body.append(featured_tr1);        			  			          
      }
      else if (type == "edit_galleries")
      {
        f_default = parseFloat($("default", item).text());	
        
        featured_tr1 = featured_tr.clone(true);		      	  			      	  
        
        featured_tr1.attr("id", "featured_list_"+f_id).find("td.gallery_td").empty().append("<a href='../admin/index.php?page=art_manager&mode=edit_galleries&act=edit&g_id="+f_id+"' title='click to edit'>&quot;"+f_title+"&quot;</a>"+((f_default)?"<span class='default'> - Default Gallery</span>":"")).end().find("td.position_td input").attr({name: f_id, value: f_order}).end().find("td.feature_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_galleries&cmd=unfeature_gallery&g_id="+f_id);
    	  
    	  featured_body.append(featured_tr1);			      	  			      	 
      }			        	       
    });
    
    $("list item", data).each(function (i, item){			     			      
      l_id = $(item).attr("id");
      l_title = $("title", item).text();
      l_order = $("order", item).text();
      
      if (type == "edit_artwork")
      {
        l_active = parseFloat($("active", item).text());
        
        list_tr1 = list_tr.clone(true);  			          			          			        
        
        list_tr1.attr("id", "art_list_"+l_id).find("td.img_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_artwork&act=edit&art_id="+l_id).find("img").attr({src: "../resources/img/artworks_small/"+l_id+".jpg", alt: l_title}).end().end().find("td.title_td a").attr("href", "../admin/index.php?page=art_manager&mode=edit_artwork&act=edit&art_id="+l_id).text("\""+l_title+"\"").end().find("td.position_td input").attr({name: l_id, value: l_order}).end().find("td.status_td").text(((l_active)?"published":"unpublished")).end().find("td.checkbox_td input").attr("name", "del_artworks["+l_id+"]");
        
        list_body.append(list_tr1);			      				      
      }
      else if (type == "edit_galleries")
      {
        l_default = parseFloat($("default", item).text());
        
        list_tr1 = list_tr.clone(true);
        
        list_tr1.attr("id", "art_list_"+l_id).find("td.gallery_td").empty().append("<a href='../admin/index.php?page=art_manager&mode=edit_galleries&act=edit&g_id="+l_id+"' title='click to edit'>&quot;"+l_title+"&quot;</a>"+((l_default)?"<span class='default'> - Default Gallery</span>":"")).end().find("td.position_td input").attr({name: l_id, value: l_order}).end().find("td.checkbox_td_2").html(((l_default)?"<div class='no_checkbox'></div>":"<input type='checkbox' name='del_galleries["+l_id+"]' value='1' />"));
        
        list_body.append(list_tr1);			      			     			      			          
      }			        		      			        
    });	
  }		      
};
	

	

//function addLoadEvent(func) {

//  var oldonload = window.onload;

//  if (typeof window.onload != 'function') {

//    window.onload = func;

//  } else {

//    window.onload = function() {

//      oldonload();

//      func();

//    }

//  }

//}

//

//function prepareInputsForHints() {

//

//	var inputs = document.getElementsByTagName("input"); for (var i=0; i<inputs.length; i++){

//		inputs[i].onfocus = function () {

//			document.getElementById("lasthint").value = this.id;

//			if(this.parentNode.getElementsByTagName("span")[0])this.parentNode.getElementsByTagName("span")[0].style.display = "inline";

//

//			var newinputs = document.getElementsByTagName("input");

//			for (var j=0; j<newinputs.length; j++)

//			{

//				if (newinputs[j].parentNode.getElementsByTagName("span")[0] && newinputs[j].type != "hidden")

//				{

//					if(document.getElementById("lasthint").value != newinputs[j].id)

//					{

//						newinputs[j].parentNode.getElementsByTagName("span")[0].style.display = "none";

//					}

//				}

//			}

//			var newtextareas = document.getElementsByTagName("textarea");

//			for (var m=0; m<newtextareas.length; m++)

//			{

//				if (newtextareas[m].parentNode.getElementsByTagName("span")[0] && newtextareas[m].type != "hidden")

//				{

//					if(document.getElementById("lasthint").value != newtextareas[m].id)

//					{

//						newtextareas[m].parentNode.getElementsByTagName("span")[0].style.display = "none";

//					}

//				}

//			}

//		}

//	}

//

//  var textareas = document.getElementsByTagName("textarea"); for (var k=0; k<textareas.length; k++){

//		textareas[k].onfocus = function () {

//			document.getElementById("lasthint").value = this.id;

//			if(this.parentNode.getElementsByTagName("span")[0])this.parentNode.getElementsByTagName("span")[0].style.display = "inline";

//			var newinputs2 = document.getElementsByTagName("input");

//			for (var l=0; l<newinputs2.length; l++)

//			{

//				if (newinputs2[l].parentNode.getElementsByTagName("span")[0] && newinputs2[l].type != "hidden")

//				{

//					if(document.getElementById("lasthint").value != newinputs2[l].id)

//					{

//						newinputs2[l].parentNode.getElementsByTagName("span")[0].style.display = "none";

//					}

//				}

//			}

//		}

//	}

//}

//	

//addLoadEvent(prepareInputsForHints);